批次分類多則評論
你的情緒分析 pipeline 在單一評論上運作良好。現在要一次處理多則評論,將它們放入同一個批次。這是在大規模分析使用者回饋前的重要一步。
本練習屬於課程
Python 的 Natural Language Processing(NLP)
練習說明
- 使用
"distilbert-base-uncased-finetuned-sst-2-english"初始化sentiment-analysis的pipeline。 - 使用該
pipeline來分類review_batch清單中的所有評論。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
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)