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.
This exercise is part of the course
Natural Language Processing (NLP) in Python
Exercise instructions
- Create a
pos_pipeline
using the"vblagoje/bert-english-uncased-finetuned-pos"
model. - Apply the pipeline on the provided
sentence
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
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']}")