MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Natural Language Processing (NLP) in Python

Lihat Kursus

Petunjuk latihan

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

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

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']}")
Edit dan Jalankan Kode