Few-shot プロンプトによる感情分析
あなたは市場調査に取り組んでおり、few-shot プロンプトを使って顧客レビューの感情分析を行うことが目標です。与えられた顧客の会話に対して、感情がネガティブなら -1、ポジティブなら 1 を割り当てます。モデルが学習できるように、以下の例を過去の会話として提示します。
- The product quality exceeded my expectations -> 1
- I had a terrible experience with this product's customer service -> -1
OpenAI パッケージはすでに読み込まれています。
この演習はコースの一部です
OpenAI API で学ぶプロンプトエンジニアリング
演習の手順
- 例を過去の会話として用意し、テキストは
userロールのコンテキスト、数値はassistantロールのコンテキストとして割り当ててください。 - 次のテキストをモデルに分類させ、適切なロールを使用してください:
The price of the product is really fair given its features.
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
client = OpenAI(api_key="")
response = client.chat.completions.create(
model = "gpt-4o-mini",
# Provide the examples as previous conversations
messages = [{"role": "____", "content": "____"},
{"role": "____", "content": "____"},
{"role": "____", "content": "____"},
{"role": "____", "content": "____"},
# Provide the text for the model to classify
{"role": "____", "content": "____"}
],
temperature = 0
)
print(response.choices[0].message.content)