Closed AshishRanjan-004 closed 5 years ago
It sounds like what you're experiencing is the "catastrophic forgetting" problem – as your model learns about the new entities, it's "forgetting" what it had previously learned.
Here are some resources and threads with more information and possible solutions:
thanks for the quick reply. but don't you think this should be fixed?
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
I followed all the instruction of the documentation to update my existing model but when I update the model, all previous entities vanished and only new entities were recognized by the model. here is the code with output
` from future import unicode_literals, print_function import plac import random from pathlib import Path import spacy from spacy.util import minibatch, compounding
TRAIN_DATA = [ ("Who is Shaka Khan?", {"entities": [(7, 17, "PERSON")]}), ("I like London and Berlin.", {"entities": [(7, 13, "LOC"), (18, 24, "LOC")]}), ]
@plac.annotations( model=("Model name. Defaults to blank 'en' model.", "option", "m", str), output_dir=("Optional output directory", "option", "o", Path), n_iter=("Number of training iterations", "option", "n", int), )
def trainModel(model=None, output_dir=None, n_iter=100): if model is not None: nlp = spacy.load(model) # load existing spaCy model print("Loaded model '%s'" % model) else: nlp = spacy.blank("en") # create blank Language class print("Created blank 'en' model")
trainModel()
output:- Entities [('Shaka Khan', 'PERSON')] Tokens [('Who', '', 2), ('is', '', 2), ('Shaka', 'PERSON', 3), ('Khan', 'PERSON', 1), ('?', '', 2)] Entities [('London', 'LOC'), ('Berlin', 'LOC')] Tokens [('I', '', 2), ('like', '', 2), ('London', 'LOC', 3), ('and', '', 2), ('Berlin', 'LOC', 3), ('.', '', 2)]
`
LABEL = "ANIMAL"
TRAIN_DATA = [ ( "Horses are too tall and they pretend to care about your feelings", {"entities": [(0, 6, LABEL)]}, ), ("Do they bite?", {"entities": []}), ( "horses are too tall and they pretend to care about your feelings", {"entities": [(0, 6, LABEL)]}, ), ("horses pretend to care about your feelings", {"entities": [(0, 6, LABEL)]}), ( "they pretend to care about your feelings, those horses", {"entities": [(48, 54, LABEL)]}, ), ("horses?", {"entities": [(0, 6, LABEL)]}), ]
@plac.annotations( model=("Model name. Defaults to blank 'en' model.", "option", "m", str), new_model_name=("New model name for model meta.", "option", "nm", str), output_dir=("Optional output directory", "option", "o", Path), n_iter=("Number of training iterations", "option", "n", int), ) def main(model="C:\Users\Ashish\Desktop\model", new_model_name="animal", output_dir=None, n_iter=70): """Set up the pipeline and entity recognizer, and train the new entity.""" random.seed(0) if model is not None: nlp = spacy.load(model) # load existing spaCy model print("Loaded model '%s'" % model) else: nlp = spacy.blank("en") # create blank Language class print("Created blank 'en' model")
Add entity recognizer to model if it's not in the pipeline
main()
output;- Entities in 'who is shaka khan? this is my horse' ANIMAL horse `
so, in the above code, we getting horse as ANIMAL but unable to recognize shaka khan as a person.
So how can void this situation and get all the entities?
ENVIRONMENT:-
THANKS