I have some trouble with the initialization of a tok2vec Transformer with a custom spacy ner model. How do I use tok2vec properly before the ner step starts in the pipeline?
Init:
nlp = spacy.load("./output_training_11.11")
ner = nlp.get_pipe("ner")
config = {"model": DEFAULT_TOK2VEC_MODEL}
nlp.add_pipe("tok2vec", before='ner')
Training:
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()`?