MulaiMulai sekarang secara gratis

Identifying named entities in news headlines

News organizations often tag named entities like people, locations, and organizations in headlines to improve search, indexing, and recommendations. Your job is to use a Hugging Face pipeline to automatically detect and group these entities in a news headline.

Latihan ini adalah bagian dari kursus

Natural Language Processing (NLP) in Python

Lihat Kursus

Petunjuk latihan

  • Create a ner_pipeline using the "dslim/bert-base-NER" model.
  • Extract the named entities from the given headline.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

from transformers import pipeline
# Create the NER pipeline
ner_pipeline = pipeline(
    task="____",
    model="____",
    grouped_entities=True
)
headline = "Apple is planning to open a new office in San Francisco next year."

# Get named entities
entities = ____

for entity in entities:
    print(f"{entity['entity_group']}: {entity['word']}")
Edit dan Jalankan Kode