I tried to train datasets :
[('text data text data text data text data text data text data text data text data.', {'entities': [(7, 19, 'PERSON'), (89, 91, 'PERSON'), (98, 101, 'PERSON')]}), ('"text data text data text data text data text data text data text data text data text data text data text data text data.', {'entities': [(119, 137, 'PERSON')]}),]
n_iter = 8
nlp = spacy.blank('en')
ner = nlp.create_pipe('ner')
for _, annotations in TRAIN_DATA:
for _s, _e, label in annotations.get('entities', []) :
print('Adding label - "', label, '"')
ner.add_label(label)
from spacy.training.example import Example
from spacy.util import minibatch, compounding
other_pipes = [pipe for pipe in nlp.pipe_names if pipe != 'ner']
with nlp.disable_pipes(*other_pipes):
optimizer = nlp.begin_training()
for itn in range(n_iter):
random.shuffle(TRAIN_DATA)
losses = {}
for batch in spacy.util.minibatch(TRAIN_DATA, size=compounding(4.0, 32.0, 1.001)):
for text, annotations in batch:
doc = nlp.make_doc(text)
example = Example.from_dict(doc, annotations)
nlp.update([example], drop=0.35,losses=losses, sgd=optimizer)
print('losses -', losses)
The result was losses - {}
till so many iterations
Does anyone know which one is wrong?