原文:我是如何赢得GPT-4提示工程大赛冠军的
原文的原文: How I Won Singapore’s GPT-4 Prompt Engineering Competition
分隔符是一种特殊 token,可帮助 LLM 分辨 prompt 的哪些部分应被视为单个含义单元。这很重要,因为输入 LLM 的整个 prompt 是单个的 token 长序列。分隔符能将 prompt 中不同部分隔离开,从而为这个 token 序列提供结构,让其中各个部分能被区别对待(重点对待)。
- 任务很简单,那么分隔符对 LLM 的响应质量的影响不大。
- 任务越复杂,使用分隔符分节对 LLM 响应的影响就越大。
1. 用特殊字符当分隔符
分隔符可以使用任何通常不会同时出现的特殊字符序列,举些例子:###、===、>>>
特殊字符的数量和类型并不重要,只要它们足够独特即可,这样才能让 LLM 将它们理解成内容分隔符,而不是普通的标点符号。
下面通过一个例子说明如何在 prompt 中使用分隔符(中文翻译只是帮助理解,原文是不存在的):
Classify the sentiment of each conversation in <<<CONVERSATIONS>>> as ‘Positive’ or ‘Negative’. Give the sentiment classifications without any other preamble text.
'''
将<<<CONVERSATIONS>>>中每次对话的情绪分类为“积极”或“消极”。在没有任何其他序言文本的情况下给出情感分类。
'''
###
EXAMPLE CONVERSATIONS
[Agent]: Good morning, how can I assist you today?
[Customer]: This product is terrible, nothing like what was advertised!
[Customer]: I’m extremely disappointed and expect a full refund.
[Agent]: Good morning, how can I help you today?
[Customer]: Hi, I just wanted to say that I’m really impressed with your product. It exceeded my expectations!
'''
###
示例对话
[代理人]:早上好,今天我能为您做些什么?
[顾客]:这个产品太糟糕了,和广告上的完全不一样!
[顾客]:我非常失望,希望能全额退款。
[经纪人]:早上好,今天有什么能帮你的吗?
[顾客]:嗨,我只是想说你的产品给我留下了深刻的印象。它超出了我的预期!
'''
EXAMPLE OUTPUTS
Negative
Positive
###
'''
示例输出
消极的
积极乐观的
###
'''
<<<
[Agent]: Hello! Welcome to our support. How can I help you today?
[Customer]: Hi there! I just wanted to let you know I received my order, and it’s fantastic!
[Agent]: That’s great to hear! We’re thrilled you’re happy with your purchase.Is there anything else I can assist you with?
[Customer]: No, that’s it. Just wanted to give some positive feedback. Thanks for your excellent service!
'''
[经纪人]:你好!欢迎加入我们的支持。今天我能帮你什么忙?
[顾客]:嗨!我只是想让你知道我收到了订单,这太棒了!
[经纪人]:很高兴听到!我们很高兴您对您的购买感到满意。还有什么我可以帮你的吗?
[客户]:没有,就是这样。只是想给一些积极的反馈。感谢您的优质服务!
'''
[Agent]: Hello, thank you for reaching out. How can I assist you today?
[Customer]: I’m very disappointed with my recent purchase. It’s not what I expected at all.
[Agent]: I’m sorry to hear that. Could you please provide more details so I can help?
[Customer]: The product is of poor quality and it arrived late. I’m really unhappy with this experience.
>>>
'''
[经纪人]:你好,谢谢你伸出援手。今天我能为您提供什么帮助?
[顾客]:我对最近购买的东西很失望。这根本不是我所期望的。
[经纪人]:听到这个消息我很抱歉。你能提供更多的细节吗?这样我就可以帮忙了?
[客户]:产品质量不好,到货晚了。我对这次经历很不满意。
>>>
'''
- 上面例子中使用的分隔符是
###,同时每一节都带有完全大写的标题以示区分,如EXAMPLE CONVERSATIONS和EXAMPLE OUTPUTS。 - 前置说明部分陈述了要分类的对话是在
<<<CONVERSATIONS>>>中,这些对话是在 prompt 末尾提供,也不带任何解释说明文本,但由于有了<<<和>>>这样的分隔符,LLM 就能理解这就是要分类的对话。
GPT-4 对此 prompt 给出的输出如下,其给出的情感分类结果不带任何附加文本,这符合我们的要求:
Positive
Negative
2. 用 XML 标签当分隔符
另一种方法是使用 XML 标签作为分隔符。XML 标签是使用尖括号括起来的成对标签,包括开始和结束标签。比如 <tag> 和 </tag>。这很有效,因为 LLM 在训练时就看过了大量用 XML 标注的网络内容,已经学会了理解其格式。
下面用 XML 标签作为分隔符重写上面的 prompt:
Classify the sentiment of the following conversations into one of two classes, using the examples given. Give the sentiment classifications without any other preamble text.
<classes>
Positive
Negative
</classes>
<example-conversations>
[Agent]: Good morning, how can I assist you today?
[Customer]: This product is terrible, nothing like what was advertised!
[Customer]: I’m extremely disappointed and expect a full refund.
[Agent]: Good morning, how can I help you today?
[Customer]: Hi, I just wanted to say that I’m really impressed with your product. It exceeded my expectations!
</example-conversations>
<example-classes>
Negative
Positive
</example-classes>
<conversations>
[Agent]: Hello! Welcome to our support. How can I help you today?
[Customer]: Hi there! I just wanted to let you know I received my order, and it’s fantastic!
[Agent]: That’s great to hear! We’re thrilled you’re happy with your purchase.Is there anything else I can assist you with?
[Customer]: No, that’s it. Just wanted to give some positive feedback. Thanks for your excellent service!
[Agent]: Hello, thank you for reaching out. How can I assist you today?
[Customer]: I’m very disappointed with my recent purchase. It’s not what I expected at all.
[Agent]: I’m sorry to hear that. Could you please provide more details so I can help?
[Customer]: The product is of poor quality and it arrived late. I’m really unhappy with this experience.
</conversations>
以下是上面prompt的翻译,可以忽略
使用给出的例子,将以下对话的情绪分为两类。在没有任何其他序言文本的情况下给出情感分类。
<classes>
积极乐观的
消极的
</classes>
<example-conversations>
[代理人]:早上好,今天我能为您做些什么?
[顾客]:这个产品太糟糕了,和广告上的完全不一样!
[顾客]:我非常失望,希望能全额退款。
[经纪人]:早上好,今天有什么能帮你的吗?
[顾客]:嗨,我只是想说你的产品给我留下了深刻的印象。它超出了我的预期!
</example-conversations>
<example-classes>
消极的
积极乐观的
</example-classes>
<conversations>
[经纪人]:你好!欢迎加入我们的支持。今天我能帮你什么忙?
[顾客]:嗨!我只是想让你知道我收到了订单,这太棒了!
[经纪人]:很高兴听到!我们很高兴您对您的购买感到满意。还有什么我可以帮你的吗?
[客户]:没有,就是这样。只是想给一些积极的反馈。感谢您的优质服务!
[经纪人]:你好,谢谢你伸出援手。今天我能为您提供什么帮助?
[顾客]:我对最近购买的东西很失望。这根本不是我所期望的。
[经纪人]:听到这个消息我很抱歉。你能提供更多的细节吗?这样我就可以帮忙了?
[客户]:产品质量不好,到货晚了。我对这次经历很不满意。
</conversations>
为了达到更好的效果,在 XML 标签中使用的名词应该与prompt中用于描述它们的名词一样。在上面的 prompt 中,我们给出的指令为:
Classify the sentiment of the following conversations into one of two classes, using the examples given. Give the sentiment classifications without any other preamble text.
'''
使用给出的例子,将以下对话的情绪分为两类。在没有任何其他序言文本的情况下给出情感分类。
'''
其中使用的名词有 conversations、classes 和 examples。也因此,后面的分隔 XML 标签就对应为 <conversations>、<classes>、<example-conversations> 和 <example-classes>。这能确保 LLM 理解指令与 XML 标签的关联。
同样的,使用这样的分隔符能以清晰的结构化方式对 prompt 进行分节,从而确保 GPT-4 输出的内容就刚好是你想要的结果:
Positive
Negative










