custom component does not initialize #10644
-
I have the following custom component in its own package. It is supposed to take a file of json patterns and then match these patterns with the DependencyMatcher
This component is exposed to the conda environment as an entry point:
Then in my spacy.cfg I have:
Unfortunately, when I run the pipeline with the train command, it appears that the initialize method of the component is not run/triggered. Therefore, the patterns attribute is always the empty dictionary. I am not sure what's going on as the code I have seems identical to the examples on how to do this e.g. at https://spacy.io/usage/processing-pipelines#custom-components, and also similar to how the entity ruler is implemented (https://github.com/explosion/spaCy/blob/master/spacy/pipeline/entityruler.py), which in the above pipeline loads the patterns just fine. I'm not sure what's going on so any help is appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
I think the problem is that your |
Beta Was this translation helpful? Give feedback.
I think the problem is that your
initialize
method is only storing the patterns as an attribute and not processing them further. For a cleaner design with v3 (some of the entity ruler design is a holdover from v2), I'd recommend removingpatterns
as a kwarg from__init__
and moving the pattern loading to a separateadd_patterns
-type method that you can call withinitialize
. Or if you never need to support adding more patterns later, you can put the pattern loading directly ininitialize
if you want.