使用大型语言模型(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:Code / 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
)参考
- Prompt Engineering Guide (opens in a new tab) (2023年3月16日)