Aan de slagGa gratis aan de slag

Part of Speech tagging for text analysis

A language learning app wants to help users understand sentence structure by highlighting the grammatical role of each word. Your task is to use a Hugging Face pipeline to label each word in a given sentence with its corresponding PoS tag.

Deze oefening maakt deel uit van de cursus

Natural Language Processing (NLP) in Python

Cursus bekijken

Oefeninstructies

  • Create a pos_pipeline using the "vblagoje/bert-english-uncased-finetuned-pos" model.
  • Apply the pipeline on the provided sentence.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

from transformers import pipeline
# Create the PoS tagging pipeline
pos_pipeline = pipeline(
    task="____",
    model="____",
    grouped_entities=True
)

sentence = "I am meeting my friends for coffee this afternoon."

# Get PoS tags
pos_tags = ____
for token in pos_tags:
    print(f"{token['word']}: {token['entity_group']}")
Code bewerken en uitvoeren