批量分类多条评论
您的情感分析 pipeline 在单条评论上运行良好。现在请在一个批次中处理多条评论。这是在大规模分析用户反馈前的重要一步。
本练习是课程的一部分
Python 中的自然语言处理(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)