I have descriptions from which I want to extract colours. Hence I thought I would use NER by spacy. I have data like this for 8000 lines
import spacy
nlp=spacy.load('en_core_web_sm')
# Getting the pipeline component
ner=nlp.get_pipe("ner")
Train_data =
[
("Bermuda shorts anthracite/black",{"entities" : [(15,31,"COL")]}),
("Acrylic antique white",{"entities" : [(8,22,"COL")]}),
("Pincer black",{"entities" : [(8,13,"COL")]}),
("Cable tie black",{"entities" : [(10,15,"COL")]}),
("Water pump pliers blue",{"entities" : [(18,22,"COL")]})
]
My code is
for _, annotations in Train_data:
for ent in annotations.get("entities"):
ner.add_label(ent[2])
pipe_exceptions = ["ner", "trf_wordpiecer", "trf_tok2vec"]
unaffected_pipes = [pipe for pipe in nlp.pipe_names if pipe not in pipe_exceptions]
from spacy.training.example import Example
for batch in spacy.util.minibatch(Train_data, size=2):
for text, annotations in batch:
# create Example
doc = nlp.make_doc(text)
example = Example.from_dict(doc, annotations)
# Update the model
nlp.update([example], losses=losses, drop=0.3)
WHen I test the model I get nothing.
doc = nlp("Bill Gates has a anthracite house worth 10 EUR.")
print("Entities", [(ent.text, ent.label_) for ent in doc.ents])
Why am I doing wrong? Please help...