英文:
How to train ChatGPT with custom data
问题
I want to create a chatbot on my website with ChatGPT. I have some pre-defined question-answers like the below:
Question: What is the price of ...?
Answer: $100
Question: How this help ..?
Answer: 1) Improve... 2) Better... 3) More...
When the customer asks a question related to the pre-defined questions, it should grab the answer from the pre-defined questions and use natural language to answer the customer.
But I don't know the logic to implement this. There are three roles for chat completion (system, user, assistant).
Do I insert all these pre-defined questions and answers in the system role like:
[
'role' => 'system',
'content' => 'I write all the information here'
],
Or do I write it all in a single user prompt like:
[
'role' => 'system',
'content' => 'You're a helpful assistant'
],
[
'role' => 'user',
'content' => 'I write all the information here'
]
Or do I separate it into different user prompts like:
[
'role' => 'system',
'content' => 'You're a helpful assistant'
],
[
'role' => 'user',
'content' => 'First pre-defined question and answer...'
],
[
'role' => 'user',
'content' => 'Second pre-defined question and answer...'
],
[
'role' => 'user',
'content' => 'Third pre-defined question and answer...'
]
Is this the correct way of training a chatbot?
英文:
I want to create a chatbot on my website with ChatGPT. I have some pre-defined question-answers like the below:
Question: What is the price of ...?
Answer: $100
Question: How this help ..?
Anwer: 1) Improve... 2) Better... 3) More...
When the customer ask a questoin related to the pre-defined question, it should grab the answer from the pre-defined question and use natural language to answer the customer.
But I don't know the logic to implement this. There are three roles for chat completion ( system, user, assistant ).
Do I insert all thiese pre-defined question and answer in the system role like:
[
'role' => 'system',
'content' => 'I write all the information here'
],
Or I write it all in a single user prompt like:
[
'role' => 'system',
'content' => 'You're are a helpful assistant'
],
[
'role' => 'user',
'content' => 'I write all the information here'
]
Or I separate it into different user prompmt like:
[
'role' => 'system',
'content' => 'You're are a helpful assistant'
],
[
'role' => 'user',
'content' => 'First pre-defined question and answer...'
],
[
'role' => 'user',
'content' => 'Second pre-defined question and answer...'
],
[
'role' => 'user',
'content' => 'Third pre-defined question and answer...'
]
Is this the correct way of training a chatbot?
答案1
得分: 3
这不是使用较新的OpenAI GPT模型的特别好用例,因为它们目前尚不支持微调。如果您在提示中指定信息,很可能会很快超过GPT模型的标记限制。然后,不能保证GPT会遵循您的提示,而是会基于其预训练知识回答用户的问题。
如果您仍然想要使用OpenAI的最新GPT模型,有两种选择:
- 您在“用户”消息中输入所有问题-答案对,并在“系统”消息中告诉GPT这是您想要使用的上下文。这被称为“提供参考文本策略”。
- 您将每个问题-答案对作为单独的消息提供,问题在“用户”消息中,答案在“助手”消息中。这被称为“提供示例策略”或通常称为“少样本学习”。
第一种方法在某种程度上会起作用,比第二种方法更有效。第二种方法是GPT训练的方式,因此可能会产生更好的结果。没有办法知道,您必须尝试一下。
对于您的用例,可能有更好的方法。以下是三种替代方案:
- 使用允许微调的模型(来自OpenAI、其他供应商或开源模型),并将其与您的数据匹配。
- 使用嵌入模型(再次来自OpenAI、其他供应商或开源模型)来计算查询的嵌入向量,并将结果存储在向量数据库中。这被称为“使用基于嵌入的搜索来实现高效的知识检索策略”。
- 使用OpenAI API的新功能调用功能,允许GPT请求更多信息,并将其与第2种方法结合使用。这可能会产生最佳结果,但成本和复杂性较高(2倍全API + 1倍嵌入API)。这是“使用代码执行来执行更准确的计算或调用外部API策略”。
OpenAI有一个不错的教程,您可能想要阅读《如何构建一个可以回答关于您的网站的问题的AI》。
英文:
This is not a particularly good use case for the newer OpenAI GPT models because they do not yet allow fine tuning. If you specify the information in the prompt, you will probably exceed the token limit of the GPT model quite soon. And then there is no guarantee that GPT will heed your prompt, but will answer the user's question based on its pre-trained knowledge.
If you still want to use an up-to-date GPT model from OpenAI, you have two alternatives:
- you enter all question-answer pairs in a
user
message and tell GPT in thesystem
message that this is the context you want to work with. This is called the "Provide Reference Text Strategy". - you feed each question-answer pair in individual messages, with the question in a
user
message and the answer in anassistant
message. This is called the "Provide examples tactic" or commonly "few-shot learning".
The first approach will work to some degree and is more efficient than the second approach. The second approach is the way GPT was trained, so this might give better results. There is no way to know, you have to try it out.
For your use case, there are probably better methods. Here are three alternatives:
- use a model that allows fine-tuning (from OpenAI, another vendor, or an open-source model) and match it to your data.
- use an embedding model (again from OpenAI, another vendor, or an open source model) to compute an embedding vector for the query and store the results in a vector database. This is called the "Use embeddings-based search to implement efficient knowledge retrieval tactic".
- use the new function calling feature of the OpenAI API to allow GPT to ask for more information, and combine this with the embedding method from (2). This will probably give the best results, but at a higher cost and complexity (2x full API + 1x embedding API). This is the "Use code execution to perform more accurate calculations or call external APIs tactic".
OpenAI has a good tutorial that you may want to read "How to build an AI that can answer questions about your website".
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论