開始使用免費開始

為餐廳評論建立嵌入向量

嵌入向量很適合用在常見的分類任務,其中之一就是情緒分析。接下來這個練習與下一個練習,會帶你走過使用嵌入向量進行情緒分析的工作流程。

你已獲得一小筆餐廳評論樣本,存在 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!"]

你將使用 zero-shot 分類,透過對評論與類別標籤建立嵌入向量,來判定這些評論的情緒。

你先前建立的 create_embeddings() 函式也可以在這裡使用。

本練習屬於課程

Introduction to Embeddings with the OpenAI API

檢視課程

練習說明

  • 使用串列生成式,從 sentiments 字典中的標籤建立一個類別說明的清單 class_descriptions
  • 使用 create_embeddings() 函式為 class_descriptionsreviews 建立嵌入向量。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Create a list of class descriptions from the sentiment labels
class_descriptions = ____

# Embed the class_descriptions and reviews
class_embeddings = ____
review_embeddings = ____
編輯並執行程式碼