CommencerCommencer gratuitement

NER with spaCy

Named entity recognition (NER) helps you to easily identify key elements of a given document, like names of people and places. It helps sort unstructured data and detect important information, which is crucial if you are dealing with large datasets. In this exercise, you will practice Named Entity Recognition.

en_core_web_sm has been loaded for you as nlp. Three comments from the Airline Travel Information System (ATIS) dataset have been provided for you in a list called texts.

Cet exercice fait partie du cours

Natural Language Processing with spaCy

Afficher le cours

Instructions

  • Compile documents, a list of all Doc containers for each text in the texts using list comprehension.
  • For each doc container, print each entity's text and corresponding label by iterating through doc.ents.
  • Print the sixth token's text, and the entity type of the second Doc container.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Compile a list of all Doc containers of texts
documents = [____ for text in texts]

# Print the entity text and label for the entities in each document
for doc in documents:
    print([(____, ____) for ent in ____])
    
# Print the 6th token's text and entity type of the second document
print("\nText:", documents[1][5].____, "| Entity type: ", documents[1][5].____)
Modifier et exécuter le code