CN-122019693-A - Answer generation method and device
Abstract
The method comprises the steps of obtaining query text and N documents, determining input data, wherein the input data comprises N+2 prompts, the N+2 prompts comprise a first prompt generated based on the query text, a second prompt generated based on the query text and the N documents and N third prompts generated based on the query text and each document in the N documents, inputting the input data into a large language model, generating N+2 logarithmic probabilities, wherein the N+2 logarithmic probabilities comprise a first logarithmic probability generated by the first prompt of the large language model, a second logarithmic probability generated based on the second prompt and N third logarithmic probabilities generated based on each third prompt in the N third prompts, obtaining target probability distribution based on the N+2 logarithmic probabilities, and decoding the target probability distribution to obtain answers corresponding to the query text. The application enhances the capability of integrating various knowledge in the answer generation process of the large language model, and improves the quality of generating the answer by the large language model.
Inventors
- JIN JING
- WANG HOUFENG
- LI XIAOGUANG
- Kuang Chuqiao
- GUO ZHIJIANG
Assignees
- 华为技术有限公司
- 北京大学
Dates
- Publication Date
- 20260512
- Application Date
- 20241111
Claims (14)
- 1. An answer generation method, comprising: Acquiring a query text and N documents, wherein the N documents are obtained by searching based on the query text, and N is a positive integer greater than 1; Determining input data based on the query text and the N documents, wherein the input data comprises N+2 prompts, and the N+2 prompts comprise a first prompt generated based on the query text, a second prompt generated based on the query text and the N documents and N third prompts generated based on the query text and each of the N documents respectively; Inputting the input data into a large language model to generate N+2 logarithmic probabilities, wherein the N+2 logarithmic probabilities comprise a first logarithmic probability generated by the large language model based on the first prompt, a second logarithmic probability generated based on the second prompt and N third logarithmic probabilities generated based on each third prompt in the N third prompts; obtaining target probability distribution based on the n+2 logarithmic probabilities; And decoding the target probability distribution to obtain an answer corresponding to the query text.
- 2. The method of claim 1, wherein the deriving a target probability distribution based on the n+2 log probabilities comprises: Evaluating each logarithmic probability in the N+2 logarithmic probabilities to obtain a score of each logarithmic probability; Selecting the logarithmic probability with the highest score and the logarithmic probability with the lowest score from the N third logarithmic probabilities based on the scores of each logarithmic probability; obtaining the target logarithmic probability based on the second logarithmic probability, the first logarithmic probability, the logarithmic probability with the highest score and the logarithmic probability with the lowest score; And obtaining the target probability distribution based on the target logarithmic probability.
- 3. The method of claim 2, wherein the deriving the target logarithmic probability based on the second logarithmic probability, the first logarithmic probability, the highest scoring logarithmic probability, and the lowest scoring logarithmic probability comprises: determining a fourth logarithmic probability based on the difference between the second logarithmic probability and the first logarithmic probability; Determining a fifth logarithmic probability based on the difference between the lowest and highest scoring logarithmic probabilities; And carrying out weighted summation on the second logarithmic probability, the fourth logarithmic probability and the fifth logarithmic probability to obtain the target logarithmic probability.
- 4. A method according to claim 3, wherein the score determining the first logarithmic probability is less than an order of magnitude than the score determining the second logarithmic probability, and wherein the weighted weighting parameter of the fourth logarithmic probability is set to 0.
- 5. The method of any one of claims 2-4, wherein evaluating each log probability in the n+2 probability distributions to obtain a score for each log probability comprises: calculating entropy aiming at the first K lemmas with the maximum probability in each logarithmic probability to obtain an entropy calculation result corresponding to each logarithmic probability, wherein K is a positive integer; And obtaining the score of each logarithmic probability based on the entropy calculation result corresponding to each logarithmic probability.
- 6. The method of any of claims 3-5, wherein the weighting parameters for the fourth logarithmic probability and the weighting parameters for the fifth logarithmic probability are adjusted in steps at each decoding time.
- 7. The method of claim 6, wherein the weighted weight parameter of the fourth logarithmic probability is determined based on the confidence level of the first logarithmic probability and the confidence level of the second logarithmic probability in the current decoding time step; the weighted weight parameter of the fifth logarithmic probability is determined based on the confidence of the logarithmic probability with the lowest score and the confidence of the logarithmic probability with the highest score in the current decoding time step; The confidence of each logarithmic probability is determined based on the difference between the highest two probabilities of the each logarithmic probability.
- 8. An answer generation device, comprising: the acquisition module is used for acquiring query texts and N documents, wherein the N documents are obtained by searching based on the query texts, and N is a positive integer greater than 1; A hint module, configured to determine input data based on the query text and the N documents, where the input data includes n+2 hints, the n+2 hints including a first hint generated based on the query text, a second hint generated based on the query text and the N documents, and N third hints generated based on the query text and each of the N documents; The reasoning module is used for inputting the input data into a large language model to generate N+2 logarithmic probabilities, wherein the N+2 logarithmic probabilities comprise a first logarithmic probability generated by the large language model based on the first prompt, a second logarithmic probability generated based on the second prompt and N third logarithmic probabilities generated based on each third prompt in the N third prompts; The decoding module is used for obtaining target probability distribution based on the N+2 logarithmic probabilities and decoding the target probability distribution to obtain answers corresponding to the query text.
- 9. The apparatus of claim 8, wherein the decoding module is specifically configured to: Evaluating each logarithmic probability in the N+2 logarithmic probabilities to obtain a score of each logarithmic probability; Selecting the logarithmic probability with the highest score and the logarithmic probability with the lowest score from the N third logarithmic probabilities based on the scores of each logarithmic probability; obtaining the target logarithmic probability based on the second logarithmic probability, the first logarithmic probability, the logarithmic probability with the highest score and the logarithmic probability with the lowest score; And obtaining target probability distribution based on the target logarithmic probability.
- 10. The apparatus of claim 9, wherein the deriving the target logarithmic probability based on the second logarithmic probability, the first logarithmic probability, the highest scoring logarithmic probability, and the lowest scoring logarithmic probability comprises: determining a fourth logarithmic probability based on the difference between the second logarithmic probability and the first logarithmic probability; Determining a fifth logarithmic probability based on the difference between the lowest and highest scoring logarithmic probabilities; And carrying out weighted summation on the second logarithmic probability, the fourth logarithmic probability and the fifth logarithmic probability to obtain the target logarithmic probability.
- 11. The apparatus of claim 10, wherein the weighting parameters for the fourth logarithmic probability and the weighting parameters for the fifth logarithmic probability are adjusted at each decoding time step.
- 12. The apparatus of claim 11, wherein the weighted weight parameter of the fourth logarithmic probability is determined based on the confidence level of the first logarithmic probability and the confidence level of the second logarithmic probability in the current decoding time step; the weighted weight parameter of the fifth logarithmic probability is determined based on the confidence of the logarithmic probability with the lowest score and the confidence of the logarithmic probability with the highest score in the current decoding time step; The confidence of each logarithmic probability is determined based on the difference between the highest two probabilities of the each logarithmic probability.
- 13. A computing device comprising a memory and a processor, wherein the memory has instructions stored therein that when executed by the processor cause the method of any of claims 1-7 to be implemented.
- 14. A computer readable storage medium, on which a computer program is stored which, when being executed by a processor, causes the method according to any one of claims 1-7 to be implemented.
Description
Answer generation method and device Technical Field The application relates to the technical field of artificial intelligence (ARTIFICIAL INTELLIGENCE, AI), in particular to an answer generation method and device. Background The advent of large language models (large language model, LLM) has significantly driven the development of various natural language processing tasks. However, despite the extensive knowledge base and language capabilities of large language models, they often encounter difficulties in handling new knowledge and are prone to outdated content and illusions. One straightforward solution is to update LLMs's knowledge by continuous training, but this process typically requires a significant amount of time and computational resources. Retrieval enhancement generation (RAG) provides an alternative solution that effectively alleviates the illusion problem by introducing external knowledge. After document retrieval, the RAG may be considered a multi-document question-and-answer (multi-document question answering, MDQA) task. Recent studies have shown that differences in document quality can lead to interference and reduce the quality of the production. Furthermore, knowledge conflicts, such as discrepancies between the retrieved documents and contradictions between parameterized knowledge and external non-parameterized knowledge, may hamper LLMs performance. Thus, efficient integration of diverse knowledge in the generation process remains an important challenge for LLMs. Disclosure of Invention The embodiment of the application provides an answer generation method and device, which can enhance the capability of integrating multiple knowledge (including multiple external knowledge of multiple documents and internal knowledge of a model) in the answer generation process of a large language model, and effectively improve the quality of generating answers by the large language model. In a first aspect, the application provides an answer generation method, which comprises the steps of obtaining query text and N documents, wherein N is a positive integer larger than 1, obtained by searching the query text, determining input data based on the query text and the N documents, wherein the input data comprises N+2 prompts, the N+2 prompts comprise a first prompt generated based on the query text, a second prompt generated based on the query text and the N documents and N third prompts generated based on the query text and each document in the N documents respectively, inputting the input data into a large language model, generating N+2 logarithmic probabilities (logits), wherein the N+2 logarithmic probabilities comprise a first logits generated based on the first prompt, a second logarithmic probability generated based on the second prompt and N third logarithmic probabilities generated based on each third prompt in the N third prompts, obtaining a target probability distribution based on the N+2 logarithmic probabilities, and decoding the target probability distribution to obtain answers corresponding to the query text. According to the answer generation method provided by the application, the first logits obtained by reasoning the large language model based on the self parameter knowledge, the second logits obtained by reasoning the knowledge provided by the external N documents and the N third logits obtained by reasoning the knowledge provided by the single document in the external N documents are respectively processed to obtain the target probability distribution, and the target probability distribution is used for decoding to obtain the response output, so that the integration of multiple kinds of knowledge is realized, the capability of integrating multiple kinds of knowledge in the answer generation process of the large language model is enhanced, and the quality of the answer generated by the large language model is effectively improved. In one possible implementation, the target probability distribution is obtained based on the n+2 logarithmic probabilities, and the specific implementation is that each logarithmic probability of the n+2 logarithmic probabilities is evaluated to obtain a score of each logarithmic probability, the logarithmic probability with the highest score and the logarithmic probability with the lowest score are selected from the N third logarithmic probabilities based on the score of each logarithmic probability, the target logarithmic probability is obtained based on the second logarithmic probability, the first logarithmic probability, the logarithmic probability with the highest score and the logarithmic probability with the lowest score, and the target probability distribution is obtained based on the target logarithmic probability. By evaluating the highest-scoring log probability and the lowest-scoring log probability from the N third log probabilities, the answer generated by the improved model is realized by considering the sum influence of a single document and en