PhraseMatcher and EntityRuler
Explore how to apply spaCy's PhraseMatcher to match long lists of phrases efficiently and use EntityRuler to add custom named entities to NLP pipelines. This lesson helps you handle domain-specific entities and improve entity recognition beyond statistical models.
We'll cover the following...
PhraseMatcher
While processing financial, medical, or legal text, often we have long lists and dictionaries, and we want to scan the text against our lists. As we saw in the previous section, Matcher patterns are quite handcrafted; we coded each token individually. If we have a long list of phrases, Matcher is not very handy. It's not possible to code all the terms one by one.
spaCy offers a solution for comparing text against long dictionaries—the PhraseMatcher class. The PhraseMatcher class helps us match long dictionaries. Let's get started with an example:
Here's what we did:
First, we imported
spacy, then we imported thePhraseMatcherclass. ...