spaczz icon indicating copy to clipboard operation
spaczz copied to clipboard

UserWarning: [W036] The component 'matcher' does not have any patterns defined. matches = matcher(doc)

Open kormilitzin opened this issue 2 years ago • 2 comments

Thanks a lot for your fabulous package; it is really helpful. However, when I tried to reproduce your results, I run into this error:

"UserWarning: [W036] The component 'matcher' does not have any patterns defined. matches = matcher(doc)"

Specifically, I used this code snippet:

import spacy
from spacy.pipeline import EntityRuler
from spaczz.pipeline import SpaczzRuler
nlp = spacy.load("en_core_web_sm")

entity_ruler = nlp.add_pipe("entity_ruler", before="ner")
entity_ruler.add_patterns(
    [{"label": "GPE", "pattern": "Nashville"}, 
     {"label": "GPE", "pattern": "TN"}]
)

spaczz_ruler = nlp.add_pipe("spaczz_ruler", before="ner") #spaCy v3 syntax
spaczz_ruler.add_patterns(
    [
        {
            "label": "NAME",
            "pattern": "Grant Andersen",
            "type": "fuzzy",
            "kwargs": {"fuzzy_func": "token_sort"},
        },
    ]
)

When I add patterns to the spaCy's EntityRuler, it works OK, when I add patters to SpaczzRuler, it throws the error I specified in above.

I am using Python 3.9, spaCy 3.2.2 on Ubuntu 16.04.

Any help will be highly appreciated.

kormilitzin avatar Apr 02 '22 13:04 kormilitzin

Hi @kormilitzin, thanks for your interest in spaczz! The warning you are seeing normally happens because of the way I have implemented the TokenMatcher (which is part of the SpaczzRuler) which will sometimes result in an empty spaCy Matcher being called on text. This is an inefficiency and something I need to fix but it shouldn't actually affect the results of the EntityRuler or the TokenMatcher.

In the example above, I'm not entirely sure at the moment why the warning is coming up while adding patterns but the same principle applies. All the patterns you added should be there when you look at spaczz_ruler.patterns.

If however, you are seeing incorrect results from running the SpaczzRuler or in SpaczzRuler.patterns please update me here.

gandersen101 avatar Apr 09 '22 18:04 gandersen101

@gandersen101 Thanks a lot for your details response; that totally makes sense to me. This warning was a bit puzzling as your implementation did work as a charm (i.e. it identified fuzzy matches), but I was surprised to see this warning. I will keep trying and report if I find anything not right. Thanks again for your amazing package!

kormilitzin avatar Apr 09 '22 22:04 kormilitzin

I believe this should be fixed by #81.

gandersen101 avatar May 01 '23 12:05 gandersen101