def read_file(filename):
  """Read the contents of filename (str) and split into documents by chapter."""

  all_documents = []
  document = []
  with tf.gfile.GFile(filename, "r") as reader:
    for line in reader:
      line = line.strip()
      if not line:
        continue
      if line.lower()[:7] == "chapter":
        if document:
          all_documents.append(document)
          document = []
      else:
        document.append(line)
    if document:
      all_documents.append(document)

  return all_documents
Read the contents of filename (str) and split into documents by chapter.
language/conpono/create_pretrain_data/books_preproc_pipeline.py