Get startedGet started for free

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.

This exercise is part of the course

Advanced NLP with spaCy

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Register the Token extension attribute 'is_country' with the default value False
____.____(____, ____=____)

# Process the text and set the is_country attribute to True for the token "Spain"
doc = nlp("I live in Spain.")
____ = True

# Print the token text and the is_country attribute for all tokens
print([(____, ____) for token in doc])
Edit and Run Code