Exercise

Complex components

In this exercise, you'll be writing a custom component that uses the PhraseMatcher to find animal names in the document and adds the matched spans to the doc.ents.

A PhraseMatcher with the animal patterns has already been created as the variable matcher. The small English model is available as the variable nlp. The Span object has already been imported for you.

Instructions 1/3

undefined XP
    1
    2
    3
  • Define the custom component and apply the matcher to the doc.
  • Create a Span for each match, assign the label ID for 'ANIMAL' and overwrite the doc.ents with the new spans.