跳至内容

使用情感语言

语言模型是否对情感刺激做出反应?

添加对人类具有情感意义的短语有助于提高语言模型的性能。这包括以下短语:

  • 这对我的职业生涯非常重要。
  • 为你的工作感到自豪。
  • 你确定吗?

信息

要了解更多可在提示中使用的情感刺激示例,请参考 EmotionPrompt -- 一组受已建立的人类心理现象启发的提示。

实现

import openai
import instructor
from pydantic import BaseModel
from typing import Iterable


class Album(BaseModel):
    name: str
    artist: str
    year: int


client = instructor.from_openai(openai.OpenAI())


def emotion_prompting(query, stimuli):
    return client.chat.completions.create(
        model="gpt-4o",
        response_model=Iterable[Album],
        messages=[
            {
                "role": "user",
                "content": f"""
                {query}
                {stimuli}
                """,
            }
        ],
    )


if __name__ == "__main__":
    query = "Provide me with a list of 3 musical albums from the 2000s."
    stimuli = "This is very important to my career."  # (1)!

    albums = emotion_prompting(query, stimuli)

    for album in albums:
        print(album)
        #> name='Kid A' artist='Radiohead' year=2000
        #> name='The Marshall Mathers LP' artist='Eminem' year=2000
        #> name='The College Dropout' artist='Kanye West' year=2004
  1. 短语 这对我的职业生涯非常重要 在提示中用作情感刺激。

参考资料

1: 大型语言模型理解并可受情感刺激增强