Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Natural Language Processing (NLP) in Python

Cursus bekijken

Oefeninstructies

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

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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']}")
Code bewerken en uitvoeren