以零範例提示進行情緒分類
除了能回答問題、轉換文字與產生新內容之外,DeepSeek 模型也能用於分類任務,例如類別歸納與情緒分析。
在這個練習中,你會用聊天模式的 DeepSeek,針對一家名為 Toe-Tally Comfortable 的線上鞋店評論做情緒分類。理想的輸出格式如下:
1. Review text = <1-5 rating>
2. Review text = <1-5 rating>
3. ...
本練習屬於課程
使用 Python 操作 DeepSeek
練習說明
- 定義一個
prompt,要求使用數字1到5為提供的句子進行情緒分類(正向到負向)— 先不要提供任何範例! - 建立一個請求,將此提示傳送給
deepseek-ai/DeepSeek-V4.1-Flash。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
client = OpenAI(api_key="", base_url="https://api.together.xyz/v1")
# Define a multi-line prompt to classify sentiment
prompt = """____. Return no explanations:
1. Unbelievably good!
2. Shoes fell apart on the second use.
3. The shoes look nice, but they aren't very comfortable.
4. Can't wait to show them off!"""
# Create a request to the chat model
response = client.chat.completions.create(
model="deepseek-ai/DeepSeek-V4.1-Flash",
messages=[{"role": "user", "content": ____}],
max_tokens=500
)
print(response.choices[0].message.content)