How to create NER pipeline with multiple models in Spacy 3.x version? #10674
-
I am loading these two models as follows:
Now I want to use both of their ner components and have them both in a single pipeline.
gives me output with just the ner of nlp_xx model and not a combination of both nlp_en and nlp_xx model which is what I wanted. Please help me correct this, and suggest the best and maybe the easiest way to do this? Basically I need to use ner components of both the xx model and the en model and then package them as a single model to use in production for my enterprise. Kindly help urgently. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
You don't need a custom component to do this, you just need to add the import spacy
nlp_en = spacy.load("en_core_web_sm")
nlp_xx = spacy.load("xx_ent_wiki_sm")
nlp_en.add_pipe("ner", name="ner_xx", source=nlp_xx)
doc = nlp_en(text)
print(doc.ents) # (Jane, Brussels, Santos Carlos, Brasil) You have to give the new component a custom name because there's already a pipeline component named Note that the order of the There's a demo project |
Beta Was this translation helpful? Give feedback.
You don't need a custom component to do this, you just need to add the
ner
component from one pipeline to another, which you can do withnlp.add_pipe(source=)
:You have to give the new component a custom name because there's already a pipeline component named
ner
in the pipeline.Note that the order of the
ner
components matters. The secondner
component will only add entities where the first component has not added any entities.There's a demo project
tutorials/ner_double
…