澄清歧义信息
我们如何识别和澄清提示中的歧义信息?
假设我们收到以下查询:Ed Sheeran 是不是出生在一个“奇数”月份?
模型可能会以多种方式解释一个“奇数”月份
- 二月是“奇数”,因为它的天数不固定。
- 如果一个月有奇数天,它就是“奇数”月。
- 如果一个月在一年中的顺序是奇数(例如,一月是第 1st 个月),它就是“奇数”月。
注意
歧义不总是如此明显!
为了帮助模型更好地从歧义提示中推断人类意图,我们可以要求模型进行“改述并响应”(Rephrase and Respond, RaR)。
实现¶
from pydantic import BaseModel
import instructor
from openai import OpenAI
client = instructor.from_openai(OpenAI())
class Response(BaseModel):
rephrased_question: str
answer: str
def rephrase_and_respond(query):
return client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "user",
"content": f"""{query}\nRephrase and expand the question, and respond.""", # (1)!
}
],
response_model=Response,
)
if __name__ == "__main__":
query = "Take the last letters of the words in 'Edgar Bob' and concatinate them."
response = rephrase_and_respond(query)
print(response.rephrased_question)
"""
What are the last letters of each word in the name 'Edgar Bob', and what do you get when you concatenate them?
"""
print(response.answer)
"""
To find the last letters of each word in the name 'Edgar Bob', we look at 'Edgar' and 'Bob'. The last letter of 'Edgar' is 'r' and the last letter of 'Bob' is 'b'. Concatenating these letters gives us 'rb'.
"""
- 这个提示模板来自这篇论文。
这也可以作为两步 RaR 来实现
- 要求模型改述问题。
- 将改述后的问题传回给模型以生成最终响应。