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.
This exercise is part of the course
Natural Language Processing with spaCy
Exercise instructions
- Compile
documents, a list of allDoccontainers for each text in thetextsusing list comprehension. - For each
doccontainer, print each entity's text and corresponding label by iterating throughdoc.ents. - Print the sixth token's text, and the entity type of the second
Doccontainer.
Hands-on interactive exercise
Have a go at this exercise by completing this sample 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].____)