Jawad Murad
Jawad Murad

Reputation: 11

How to add a custom tag to spacy NER

I would like to add some tags to "en_core_web_sm" For example: I want the Spacy NER model to tag "16GB" as a RAM and "Intel core i7" as a CPU How can I do this?

I tried the following:

nlp = spacy.load("en_core_web_sm") 
ruler = EntityRuler(nlp)
patterns = [{"label": "RAM", "pattern": "16gb ram"}]


ruler = nlp.add_pipe("entity_ruler")
ruler.add_patterns(patterns)
doc = nlp("16gb ram is my order")
for ent in doc.ents:
    print(ent.text,ent.label_)

and the output was: 16 CARDINAL

Upvotes: 1

Views: 991

Answers (1)

polm23
polm23

Reputation: 15593

If you just want to add new tags with the EntityRuler you can do that by setting overwrite_ents = True. See here in the docs, but it looks something like this:

config = {"overwrite_ents": True}
nlp.add_pipe("entity_ruler", config=config)

Upvotes: 2

Related Questions