1

我在使用自定义 spacy ner 模型初始化 tok2vec Transformer 时遇到了一些麻烦。在管道中的 ner 步骤开始之前,如何正确使用 tok2vec?

在里面:

    nlp = spacy.load("./output_training_11.11")
    ner = nlp.get_pipe("ner")
    config = {"model": DEFAULT_TOK2VEC_MODEL}
    nlp.add_pipe("tok2vec",  before='ner')

训练:

with nlp.disable_pipes(*other_pipes):

  optimizer = nlp.begin_training()

  for i in range(100):
    random.shuffle(TRAIN_DATA)
    for text, annotation in TRAIN_DATA:
        doc = nlp.make_doc(text)
        #print(annotation)
        try:
            example = Example.from_dict(doc, annotation)
            #print(example)
        except ValueError as e:
            print(e)
            print("Text: " , doc[0:50])
            print("------")
        nlp.update([example], 
                   sgd=optimizer, drop=dropout)```


nlp("random text")


ValueError: [E109] Component 'tok2vec' could not be run. Did you forget to call `initialize()`?
4

0 回答 0