add multiple entity rulers with spacy 3 #9456
Replies: 4 comments 4 replies
-
What is the use case, would it be possible to provide some details? It might be the case that you don't need to Entity Rulers, but rather several patterns and add the patterns. |
Beta Was this translation helpful? Give feedback.
-
The use case for this is that I create 2 set of patterns from two different sources and I use different "loader" from each source. I then have a service that, for each of these folders create a new entity-ruler. Initially i tried to run In the end, I solved it with the following solution: @Language.factory("my_component")
def create_my_component(nlp, name):
return EntityRuler(nlp)
[...]
ner = spacy.load("en_core_web_sm", disable=["parser", "textcat", "ner"])
print("Loading space groups patterns...")
entity_ruler = ner.add_pipe("entity_ruler")
entity_ruler.from_disk(configuration['space-groups'])
print("Loading crystal structure patterns...")
er_crystal_structure = ner.add_pipe("my_component")
er_crystal_structure.from_disk(configuration['crystal-structure']) Indeed, probably two entity rulers are a bit overkilling, I agree. |
Beta Was this translation helpful? Give feedback.
-
You can add as many entity rulers as you want. nlp = spacy.load("en_core_web_sm")
spacy_groups_ruler = nlp.add_pipe("entity_ruler", "spacy_groups_ruler")
crystal_structure_ruler = nlp.add_pipe("entity_ruler", "crystal_structure_ruler") The first argument to See Language.add_pipe for the full documentation. |
Beta Was this translation helpful? Give feedback.
-
For reference, there's an example project that includes multiple NER components here. NER components are slightly different, but this still covers:
|
Beta Was this translation helpful? Give feedback.
-
Hi, my question is basically the same as here, but how to do it with spacy 3?
Additionally, does it make sense to have two entity rulers or it's better to mix pattern into a single one?
Thank you
Beta Was this translation helpful? Give feedback.
All reactions