NLP Error:]NameError:未定义名称'PIPE'

这是一个代码,我得到的错误是名称错误:未定义名称"管道"

选择 | 换行 | 行号
  1. nlp = spacy.blank('en')
  2.  
  3. def train_model(train_data):
  4.   if 'ner' not in nlp.pipe_names:
  5.     ner = nlp.create_pipe('ner')
  6.     nlp.add_pipe(ner, last=True)
  7.  
  8.   for _, annotation in train_data:
  9.     for ent in annotation['entities']:
  10.       ner.add_label(ent[2])
  11.  
  12.  
  13.     other_pipes = [pipe for pipe in nlp.pipe_names is pipe!='ner']
  14.     with nlp.disable_pipes(*other_pipes):
  15.       optimizer = nlp.begin_training()
  16.       for itn in range(10):
  17.         print("starting iteration " + str(itn))
  18.         random.shuffle(train_data)
  19.         losses = {}
  20.         index = 0
  21.         for text,annotations in train_data:
  22.           try:
  23.             nlp.update(
  24.                 [text], [annotations],drop=0.2,sgd=optimizer,
  25.                 losses=losses)
  26.           except Exception as e:
  27.             pass
  28.             print(text)
  29.  
  30.       print(losses)
  31.  
  32.  

标签: python

添加新评论