Sentiment Classification

使用LLMs进行情感分类

背景

此提示通过提示LLM对一段文本进行分类来测试其文本分类能力。

提示

Classify the text into neutral, negative, or positive
Text: I think the food was okay.
Sentiment:

提示模板

Classify the text into neutral, negative, or positive
Text: {input}
Sentiment:

代码 / API

from openai import OpenAI
client = OpenAI()
 
response = client.chat.completions.create(
    model="gpt-4",
    messages=[
        {
        "role": "user",
        "content": "Classify the text into neutral, negative, or positive\nText: I think the food was okay.\nSentiment:\n"
        }
    ],
    temperature=1,
    max_tokens=256,
    top_p=1,
    frequency_penalty=0,
    presence_penalty=0
)

参考