始める無料で始める

レストランレビューの埋め込み

埋め込みが得意とする代表的な分類タスクの一つが、感情分析です。この演習と次の演習では、埋め込みを使って感情分析を行う一連の流れを体験します。

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 classification によりこれらのレビューの感情を分類します。

以前に作成した create_embeddings() 関数も使用できます。

この演習はコースの一部です

OpenAI API ではじめる Embeddings 入門

コースを見る

演習の手順

  • リスト内包表記を使って、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 = ____
コードを編集して実行