开始使用免费开始使用

零样本提示:评论分类

除了回答问题、转换文本和生成新文本,DeepSeek 模型也可用于分类任务,例如归类与情感分析。

在本练习中,您将探索在聊天模式下使用 DeepSeek 对一家名为 Toe-Tally Comfortable 的网上鞋店的评论进行情感分类。理想情况下,您希望输出为以下形式:

1. Review text = <1-5 rating>
2. Review text = <1-5 rating>
3. ...

本练习是课程的一部分

在 Python 中使用 DeepSeek

查看课程

练习说明

  • 定义一个 prompt,使用数字 15(正面到负面)对给定语句的情感进行分类——先不要提供任何示例!
  • 创建一个请求,将该提示发送给 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)
编辑并运行代码