IniziaInizia gratis

Batch classifying multiple reviews

Your sentiment analysis pipeline works well on one review. Now it's time to handle multiple reviews in one batch. This is a key step before analyzing user feedback at scale.

Questo esercizio fa parte del corso

Natural Language Processing (NLP) in Python

Visualizza il corso

Istruzioni dell'esercizio

  • Initialize a pipeline for sentiment-analysis using "distilbert-base-uncased-finetuned-sst-2-english".
  • Use the pipeline to classify all reviews in the review_batch list.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

from transformers import pipeline

classifier = pipeline(task="sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")

review_batch = [
    "Absolutely love the new design!",
    "The app crashes every time I open it.",
    "Customer support was helpful and quick.",
    "Too many ads make it unusable.",
    "Everything works fine, but it’s a bit slow."
]

# Classify sentiments
results = ____
print(results)
Modifica ed esegui il codice