1. 学习
  2. /
  3. 课程
  4. /
  5. Advanced NLP with spaCy

Connected

练习

Components with extensions

Extension attributes are especially powerful if they're combined with custom pipeline components. In this exercise, you'll write a pipeline component that finds country names and a custom extension attribute that returns a country's capital, if available.

The nlp object has already been created and the Span class is already imported. A phrase matcher with all countries is available as the variable matcher. A dictionary of countries mapped to their capital cities is available as the variable capitals.

说明 1 / 共 3 个

undefined XP
    1
    2
    3
  • Complete the countries_component and create a Span with the label 'GPE' (geopolitical entity) for all matches.
  • Add the component to the pipeline.