MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Natural Language Processing with spaCy

Lihat Kursus

Petunjuk latihan

  • 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.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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].____)
Edit dan Jalankan Kode