为餐厅评论创建嵌入向量
嵌入向量非常适合的一类常见分类任务是情感分析。在本练习和后续练习中,您将按照工作流程,使用嵌入向量完成情感分析。
我们为您提供了一小部分餐厅评论,保存在 reviews 中;以及对应的情感标签,保存在 sentiments 中:
sentiments = [{'label': 'Positive'},
{'label': 'Neutral'},
{'label': 'Negative'}]
reviews = ["The food was delicious!",
"The service was a bit slow but the food was good",
"The food was cold, really disappointing!"]
您将使用零样本分类,通过对评论和类别标签进行嵌入,来判定这些评论的情感。
您之前创建的 create_embeddings() 函数也可在此处使用。
本练习是课程的一部分
使用 OpenAI API 的 Embeddings 入门
练习说明
- 使用列表推导式,从
sentiments字典中的标签创建类描述列表。 - 使用
create_embeddings()函数分别对class_descriptions和reviews进行嵌入。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create a list of class descriptions from the sentiment labels
class_descriptions = ____
# Embed the class_descriptions and reviews
class_embeddings = ____
review_embeddings = ____