IniziaInizia gratis

Sentiment analysis with few-shot prompting

You're working on market research and your goal is to use few-shot prompting to perform sentiment analysis on customer reviews. You are assigning a number for a given customers conversation: -1 if the sentiment is negative, 1 if positive. You provide the following examples as previous conversations for the model to learn from.

  • The product quality exceeded my expectations -> 1
  • I had a terrible experience with this product's customer service -> -1

The OpenAI package has been pre-loaded for you.

Questo esercizio fa parte del corso

Prompt Engineering with the OpenAI API

Visualizza il corso

Istruzioni dell'esercizio

  • Provide the examples as previous conversations assigning the text as context for the user role and the number as context for the assistant role.
  • Provide the following text for the model to classify and use the appropriate role: The price of the product is really fair given its features.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

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)
Modifica ed esegui il codice