始める無料で始める

Zero-shot prompting with reviews

As well as answering questions, transforming text, and generating new text, DeepSeek models can also be used for classification tasks, such as categorization and sentiment analysis.

In this exercise, you'll explore using DeepSeek in chat mode for sentiment classification using reviews from an online shoe store called Toe-Tally Comfortable. Ideally, you're looking for outputs in the form of:

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

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

Working with DeepSeek in Python

コースを見る

演習の手順

  • Define a prompt to classify the sentiment of the statements provided using the numbers 1 to 5 (positive to negative)— don't provide any example just yet!
  • Create a request to send this prompt to deepseek-ai/DeepSeek-V4-Pro.

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

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-Pro",
  messages=[{"role": "user", "content": ____}],
  max_tokens=500
)

print(response.choices[0].message.content)
コードを編集して実行