code: def gen_paper_content(
      InFile_PaperTitleAbs_bySentence,
      OutFileName,
      word2idx,
      entity2idx,
      field=["Title"],
      doc_len=10,
  ):
      if len(word2idx) == 0:
          word2idx["NULL"] = 0
      if len(entity2idx) == 0:
          entity2idx["NULL"] = 0
  
      paper2content = {}
      print(
          "loading file {0}...".format(
              os.path.basename(InFile_PaperTitleAbs_bySentence)
          )
      )
      with codecs.open(
          InFile_PaperTitleAbs_bySentence, "r", "utf-8"
      ) as rd:
          _cnt = 0
          _t0 = time.time()
          while True:
              line = rd.readline()
              if not line:
                  break
              _cnt += 1
              if _cnt % 10000 == 0:
                  print(
                      "\rloading line: {0}, time elapses: {1:.1f}s".format(
                          _cnt, time.time() - _t0
                      ),
                      end=" ",
                  )
              words = line.strip("\r\n").split("\t")
              paperid, category, position, sentence, fieldOfStudy = (
                  words[0],
                  words[1],
                  int(words[2]),
                  words[3],
                  words[4],
              )
              if category not in field:
                  continue
              if paperid not in paper2content:
                  paper2content[paperid] = []
              if category == "Abstract":
                  position += 1000
  
              words, entities = convert2id(
                  sentence, fieldOfStudy, word2idx, entity2idx
              )
              paper2content[paperid].append(
                  (
                      position,
                      list2string(words, ","),
                      list2string(entities, ","),
                  )
              )
      print(" ")
  
      print("parsing into feature file  ...")
      with open(OutFileName, "w") as wt:
          _cnt = 0
          _t0 = time.time()
          for paperid, info in paper2content.items():
              _cnt += 1
              if _cnt % 10000 == 0:
                  print(
                      "\rparsed paper count: {0}, time elapses: {1:.1f}s".format(
                          _cnt, time.time() - _t0
                      ),
                      end=" ",
                  )
  
              words = []
              entities = []
              info.sort(key=lambda x: x[0])
              for clip in info:
                  words.extend(clip[1].split(","))
                  entities.extend(clip[2].split(","))
              if len(words) > doc_len:
                  words = words[0:doc_len]
                  entities = entities[0:doc_len]
              elif len(words) < doc_len:
                  for _ in range(doc_len - len(words)):
                      words.append("0")
                      entities.append("0")
              wt.write(
                  "{0} {1} {2}\n".format(
                      paperid, ",".join(words), ",".join(entities)
                  )
              )
      print()
      return word2idx, entity2idx
  
imports: import codecs
  import pickle
  import time
  import os
  from datetime import datetime
  import random
  import numpy
  import math
  from multiprocessing import Process
  from utils.general import *
  from utils.data_helper import *
label_desc: Use image node_id 1 for calling a global function with example usage: gen_paper_content(InFile_PaperTitleAbs_bySentence, OutFileName, word2idx, entity2idx, field, doc_len) and returns: word2idx,  entity2idx