NLP Error:]NameError:未定义名称'PIPE'
这是一个代码,我得到的错误是名称错误:未定义名称"管道"
选择 | 换行 | 行号
- nlp = spacy.blank('en')
- def train_model(train_data):
- if 'ner' not in nlp.pipe_names:
- ner = nlp.create_pipe('ner')
- nlp.add_pipe(ner, last=True)
- for _, annotation in train_data:
- for ent in annotation['entities']:
- ner.add_label(ent[2])
- other_pipes = [pipe for pipe in nlp.pipe_names is pipe!='ner']
- with nlp.disable_pipes(*other_pipes):
- optimizer = nlp.begin_training()
- for itn in range(10):
- print("starting iteration " + str(itn))
- random.shuffle(train_data)
- losses = {}
- index = 0
- for text,annotations in train_data:
- try:
- nlp.update(
- [text], [annotations],drop=0.2,sgd=optimizer,
- losses=losses)
- except Exception as e:
- pass
- print(text)
- print(losses)