Étiquetage morpho-syntaxique (PoS) pour l’analyse de texte
Une application d’apprentissage des langues souhaite aider les utilisateurs à comprendre la structure des phrases en mettant en évidence le rôle grammatical de chaque mot. Votre objectif est d’utiliser une pipeline Hugging Face pour étiqueter chaque mot d’une phrase donnée avec sa catégorie PoS correspondante.
Cet exercice fait partie du cours
Natural Language Processing (NLP) in Python
Instructions
- Créez une
pos_pipelineen utilisant le modèle"vblagoje/bert-english-uncased-finetuned-pos". - Appliquez la pipeline à la
sentencefournie.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de 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']}")