MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Advanced NLP with spaCy

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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 dan Jalankan Kode