LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Advanced NLP with spaCy

Kurs anzeigen

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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])
Code bearbeiten und ausführen