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

Questo esercizio fa parte del corso

Natural Language Processing (NLP) in Python

Visualizza il corso

Istruzioni dell'esercizio

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

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

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']}")
Modifica ed esegui il codice