1. Learn
  2. /
  3. Courses
  4. /
  5. Advanced NLP with spaCy

Connected

Exercise

Setting extension attributes (1)

Let's practice setting some extension attributes. The nlp object has already been created for you and the Doc, Token and Span classes are already imported.

Remember that if you run your code more than once, you might see an error message that the extension already exists. That's because DataCamp will re-run your code in the same session. To solve this, you can set force=True on set_extension, or reload to start a new Python session. None of this will affect the answer you submit.

Instructions 1/2

undefined XP
  • 1
    • Use Token.set_extension to register is_country (default False).
    • Update it for "Spain" and print it for all tokens.
  • 2
    • Use Token.set_extension to register 'reversed' (getter function get_reversed).
    • Print its value for each token.