Method for improving question answering accuracy based on context and LLM
Through multiple rewrites and enhancement methods based on context and LLM, the problem of inaccurate LLM answers caused by unclear user input problems, ambiguity, and typos was solved, and more accurate and diverse answers to the problem are achieved, enhancing the adaptability of the model and universality.
Patent Information
- Application Number
- CN202411290613.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-14
- Publication Date
- 2025-01-07
AI Technical Summary
In the prior art, the LLM output results are inaccurate due to user input problems, ambiguity, typos, and semantic ambiguity.
Using a context-based and LLM method, a question word embedding, context retrieval, problem rewriting and enhancement is generated by generating multiple rewriting and enhancement, forming the problem after the Nth rewrite enhancement, and combining the user prompt words to generate answers.
It significantly improves the accuracy and diversity of question answers, enhances the adaptability and versatility of the model, and allows more accurate understanding of user intentions and generates high-quality answers.
Smart Images

Figure CN119271776A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method for improving the accuracy of question answers based on context and LLM. Background Art
[0002] LLM is an AI technology based on deep learning. By learning massive text data, it has mastered knowledge in vocabulary, grammar, semantics and other aspects, and can be used for various language tasks, such as text generation, translation, summarization, question answering, etc. Based on the large language model (LLM) retrieval-augmented generation (RAG) question answering technology, the traditional method is to directly use the knowledge base to retrieve the context, and then use LLM to directly generate the answer to the original question and context. Because the user's questions are sometimes diverse, semantically vague, ambiguous, and have typos, the traditional RAG method sometimes cannot find the accurate context in the knowledge base, so that the LLM answer is inaccurate.
[0003] Therefore, the present application develops a method for improving the accuracy of question answering based on context and LLM to solve the problems existing in the prior art. Summary of the invention
[0004] The purpose of the present invention is to provide a method for improving the accuracy of question answers based on context and LLM, so as to solve the problem in the prior art that the LLM output results are inaccurate due to unclear, ambiguous, typos, and semantic ambiguity of user input questions.
[0005] The technical solution of the present invention is: a method for improving the accuracy of question answers based on context and LLM, comprising the following steps:
[0006] S1: User asks a question;
[0007] S2: Generate question word embedding: Generate data vectors using the word embedding model based on the text of the question asked by the user;
[0008] S3: Context retrieval: Compare the data vector in step S2 with the knowledge vector library, and retrieve the context related to the question through word embedding slices based on the similarity with the question;
[0009] S4: Question rewriting and enhancement: The question raised by the user and the context in step S3 are used as the input of LLM, and the question rewriting prompts are used to generate the rewritten and enhanced question;
[0010] S5: Multi-level rewriting and enhancement: The rewritten and enhanced question in step S4 is used as the input of the word embedding model in step S2, and steps S2, S3, and S4 are repeated N times to finally form the question after the Nth rewriting and enhancement;
[0011] S6: Question answering: The question after the Nth rewriting and enhancement formed in step S5, the context of the N+1th retrieval, and the user's prompt words are used as inputs of LLM to form the result of the question.
[0012] Preferably, the question rewriting prompt in step S4 includes the following sub-steps:
[0013] S4.1: Understand the semantic content and intent of user input questions and search context;
[0014] S4.2: Analyze ambiguity and typos in user input questions and select rewriting strategies;
[0015] S4.3: Generate question rewriting prompts for users to edit;
[0016] S4.4: Rewrite prompts to form new questions based on user edited questions.
[0017] Preferably, in step S4.3, the user edits different question rewriting prompts according to different needs, so as to expand the rewritten questions and enhance the diversity of input questions.
[0018] Preferably, in step S5, the number of loops N is set according to the user's question, and each loop rewrites the previous question to form a new question while ensuring that the semantics of the question does not change, until after N loops, the question rewritten after the Nth time is obtained and the next step is entered.
[0019] Preferably, step S6 includes the following sub-steps:
[0020] S6.1: prompt words for the user to enter instructions or questions for completing tasks or generating content;
[0021] S6.2: parsing the prompt word input by the user;
[0022] S6.3: Reason and calculate the question result in text form based on the prompt word, the Nth rewritten question, and the N+1th retrieval context.
[0023] Compared with the prior art, the advantages of the present invention are:
[0024] (1) After rewriting and recycling the questions raised by users multiple times, the diversity of the original questions is enhanced, semantic ambiguity and ambiguity are reduced, and typos are eliminated;
[0025] (2) The user's prompt words are used to answer questions in different scenarios, which greatly improves the adaptability and versatility of the model. There is no need to retrain the entire model, and different functions can be achieved by simply adjusting the input prompts.
[0026] (3) Based on the user's prompt words, it can more accurately understand the user's intention and quickly generate high-quality and high-accuracy answers. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The present invention will be further described below in conjunction with the accompanying drawings and embodiments:
[0028] Figure 1 A flowchart of a method for improving the accuracy of answering questions based on context and LLM according to the present invention;
[0029] Figure 2 This is a schematic diagram of a program flow of a method for improving the accuracy of answering questions based on context and LLM according to the present invention. DETAILED DESCRIPTION
[0030] The present invention is further described in detail below in conjunction with specific embodiments:
[0031] like Figure 1 As shown, a method for improving the accuracy of question answering based on context and LLM includes the following steps:
[0032] S1: The user asks a question and inputs the question into LLM in text form.
[0033] S2: Generate question word embedding: Generate data vectors based on the text of the question asked by the user using the word embedding model, mapping words or phrases into a continuous vector space. Each word is represented as a real number vector of fixed dimension. These vectors retain the semantic relationship between words in the vector space, so that semantically similar words are closer in position in the vector space.
[0034] By converting question text into word embeddings, LLM can capture the semantic relationship between words and thus understand the user's true intention. When answering complex questions, LLM needs to retrieve relevant information from the internal knowledge base or external data source. By converting questions into word embeddings, LLM can more efficiently search and filter content related to the question, improve the accuracy and speed of information retrieval, and because word embeddings are trained on a large-scale corpus, they contain rich semantic information, which can help LLM better handle unseen words and sentence structures, such as sentence ambiguity, typos, etc., enhance the generalization ability of the model, and improve the accuracy of question answering.
[0035] S3: Context retrieval: Based on the comparison between the data vector in step S2 and the knowledge vector library, the context related to the question is retrieved through word embedding slices according to the similarity with the question, which is used to improve the accuracy and relevance of the model when understanding and generating text. By combining the context information in the external knowledge base or internal database, LLM can understand the user's questions more comprehensively and generate more accurate and useful answers.
[0036] Word embedding slicing technology can capture the semantic relationship between words, so that the retrieval process is not only based on keyword matching, but also goes deep into the semantic level, which helps to more accurately find contextual information that is highly relevant to the problem. Traditional retrieval methods may return a large number of results that are not directly related to the problem, increasing the difficulty of user screening. However, through word embedding slicing retrieval, most of the irrelevant content can be filtered out, and the purity and relevance of the returned results can be improved. Word embedding can handle problems where the vocabulary is not completely matched but the semantics are similar, and help the model find relevant context. Even if the user's problem is not clearly stated, the word embedding method can be flexibly applied to different fields and tasks, thereby supporting context retrieval in various application scenarios and extracting context related to the problem.
[0037] S4: Question rewriting and enhancement: The question raised by the user and the context in step S3 are used as the input of LLM, and the question rewriting prompts are used to generate rewritten and enhanced questions. The question raised by the user is modified, expanded or reconstructed to improve its clarity, specificity and relevance, and the original question is converted into one or more semantically identical but formally different questions, making the question clearer, easier to understand and handle. The rewritten question can more directly reflect the user's real needs, can more specifically clarify the meaning of the question, reduce misunderstandings of the model in the understanding process, make the answer more accurate, and reduce incorrect answers.
[0038] The question rewriting prompt in step S4 includes the following steps:
[0039] S4.1: Understand the semantic content and intent of user input questions and search context;
[0040] By using natural language processing technology to parse and understand the questions input by users and by deeply analyzing the semantic content and intent of user questions, we can ensure that the generated answers are directly targeted at the user's actual needs, reducing the possibility of misunderstanding and ambiguity, thereby improving the accuracy and relevance of the answers, and users can get the information or solutions they really need more quickly.
[0041] S4.2: Analyze ambiguity and typos in user input questions and select rewriting strategies;
[0042] The model determines whether the user's question is correct by comparing semantics and glyphs, and adjusts the user's question through rewriting strategies such as direct correction, replacing homophones, adjusting sentences, and adding explanations. By identifying and correcting ambiguities and typos, the model can more accurately understand the user's true intentions and reduce misunderstandings. Correcting errors in input helps generate more relevant and targeted answers, improve the quality and effectiveness of answers, and can handle various input errors to make the system more robust when facing non-standard input in actual use and adapt to different user input patterns.
[0043] S4.3: Generate question rewriting prompts for users to edit;
[0044] Before rewriting the question, the model optimizes the user's question by allowing the user to specify the goal or select the background for the question that has been adjusted in step S4.2, so as to better adapt to the query habits and needs of different users, so that LLM can play a role in a wider range of scenarios and meet the diverse needs of different users. LLM can expand in different directions according to different prompts from users to enhance the diversity of answers, and also perform further error correction and correction in the prompts to achieve an understanding of the semantics of user questions and improve the accuracy of answers.
[0045] S4.4: Rewrite the questions edited by the user to form new questions. The rewriting prompts can eliminate the ambiguity, ambiguity or unnecessary complexity of the original questions, so that the new questions more accurately reflect the actual needs of the users, and enable LLM to correctly understand the semantics of the questions, which helps to improve the accuracy of LLM's answers.
[0046] S5: Multi-level rewriting and enhancement: The rewritten and enhanced question in step S4 is used as the input of the word embedding model in step S2, and steps S2, S3, and S4 are repeated N times to finally form the question after the Nth rewriting and enhancement. The number of loops N is set according to the user's question. Each loop rewrites the previous question to form a new question and ensures that the semantics of the question does not change. After N loops, the Nth rewritten question is obtained to enter the next step. Each loop obtains a rewritten question as a new input to the word embedding model, and then rewrites and enhances the question. Through multiple loops, the original question is continuously expanded, and LLM can provide feedback and adjustments based on the previous results, thereby gradually approaching the user's true intention. This iterative approach can significantly reduce misunderstandings and ambiguities, and improve the accuracy and depth of the final generated content. In contrast, a single processing may not fully capture the complexity and diversity of user questions, resulting in the generated answers or content being inaccurate or incomplete.
[0047] S6: Question answering: The question after the Nth rewriting and enhancement formed in step S5, the context of the N+1th search, and the user's prompt words are used as the input of LLM to form the result of the question. After the last cycle, the Nth rewritten question and the N+1th search context are obtained, and the answer to the corresponding question is generated according to the user's prompt words.
[0048] The implementation principle of this embodiment:
[0049] After the user enters the question in text form, the word embedding model converts the text into a data vector, and then compares the data vector with the knowledge vector library. According to the similarity with the question, the context related to the question is retrieved through word embedding slices, and the user's question and the retrieved context are used as the input of LLM. LLM modifies, expands or reconstructs the question based on the user's question and the retrieved context and the prompts entered by the user. Through the rewriting prompt of the question, a question that better reflects the semantics of the question is generated. Then the rewritten and enhanced question is used as a new input, and word embedding and context retrieval are performed again, and the new question is rewritten and enhanced again, until the cycle is repeated N times, and finally the answer closest to the user's question is generated through the user's prompt word.
[0050] The above embodiments are only for illustrating the technical concept and features of the present invention, and their purpose is to enable people familiar with this technology to understand the content of the present invention and implement it accordingly, and they cannot be used to limit the scope of protection of the present invention. For those skilled in the art, it is obvious that the present invention is not limited to the details of the above exemplary embodiments, and the present invention can be implemented in other specific forms without departing from the spirit or basic features of the present invention. Therefore, no matter from which point of view, the embodiments should be regarded as exemplary and non-restrictive. The scope of the present invention is limited by the attached claims rather than the above description, and it is intended to include all changes within the meaning and scope of the equivalent elements of the claims in the present invention.
Claims
1. A method for improving the accuracy of question answering based on context and LLM, characterized in that: The following steps are involved: S1: User asks a question; S2: Generate question word embedding: Generate data vectors using the word embedding model based on the text of the question asked by the user; S3: Context retrieval: Compare the data vector in step S2 with the knowledge vector library, and retrieve the context related to the question through word embedding slices based on the similarity with the question; S4: Question rewriting and enhancement: The question raised by the user and the context in step S3 are used as the input of LLM, and the question rewriting prompts are used to generate the rewritten and enhanced question; S5: Multi-level rewriting and enhancement: The rewritten and enhanced question in step S4 is used as the input of the word embedding model in step S2, and steps S2, S3, and S4 are repeated N times to finally form the question after the Nth rewriting and enhancement; S6: Question answering: The question after the Nth rewriting and enhancement formed in step S5, the context of the N+1th retrieval, and the user's prompt words are used as inputs of LLM to form the result of the question.
2. A method for improving the accuracy of question answering based on context and LLM according to claim 1, characterized in that: The question rewriting prompt in step S4 includes the following sub-steps: S4.1: Understand the semantic content and intent of user input questions and search context; S4.2: Analyze ambiguity and typos in user input questions and select rewriting strategies; S4.3: Generate question rewriting prompts for users to edit; S4.4: Rewrite prompts to form new questions based on user edited questions.
3. A method for improving the accuracy of answering questions based on context and LLM according to claim 2, characterized in that: In step S4.3, the user edits different question rewriting prompts according to different needs, so as to expand the rewritten questions and enhance the diversity of input questions.
4. The method for improving the accuracy of answering questions based on context and LLM according to claim 1, characterized in that: In step S5, the number of loops N is set according to the user's question. In each loop, the previous question is rewritten to form a new question and the semantics of the question is guaranteed not to change. After N loops, the rewritten question after the Nth time is obtained and the next step is entered.
5. The method for improving the accuracy of question answering based on context and LLM according to claim 1, characterized in that: Step S6 includes the following sub-steps: S6.1: prompt words for the user to enter instructions or questions for completing tasks or generating content; S6.2: parsing the prompt word input by the user; S6.3: Reason and calculate the question result in text form based on the prompt word, the Nth rewritten question, and the N+1th retrieval context.
Citation Information
Cited By
Psychological support question and answer generation method and system based on two-stage retrieval enhanced LLM
CN119760102A
Two-Stage Retrieval-Enhanced LLM-Based Psychological Support Q&A Generation Method and System
CN119760102B
Method and system for realizing query rewriting based on llm and context
CN121166890A