Question and answer method and device
By constructing a knowledge base containing multiple groups of question and answer pairs and using large language models for matching, the problem of poor matching effects in existing intelligent question and answer systems is solved, and more accurate and humanized answers are achieved.
Patent Information
- Application Number
- CN202410764425.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-13
- Publication Date
- 2024-10-11
AI Technical Summary
When building a knowledge base, the existing intelligent question answering system divides the document into several corpus blocks, resulting in poor matching results and low accuracy of output answers.
Build a question and answer knowledge base, which contains multiple groups of question and answer pairs. Each group of question and answer pairs includes at least one answer and multiple similar questions. By vectorizing the questions and answers, using a large language model for matching and generation, it finally returns accurate and humanized Answer.
The accuracy of question and answer matching and the accuracy of output answers are improved, and the user experience is improved.
Smart Images

Figure CN118760748A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of artificial intelligence technology, and in particular, to a question-answering method, apparatus, computer device, computer-readable storage medium, and computer program product. Background Art
[0002] In the related art, intelligent question-answering systems generally answer questions input by users by pre-building a knowledge base. When building a knowledge base, the document is divided into several corpus blocks, and then the corpus blocks are vectorized to obtain a vectorized corpus. Then, the vector of the input question is matched with the vector of the corpus to obtain the corresponding answer.
[0003] However, this method of dividing the document into several corpus blocks will result in poor matching effect and low accuracy of the output answers.
[0004] It should be noted that the above content is not necessarily prior art, nor is it intended to limit the scope of patent protection of this application. Summary of the invention
[0005] The embodiments of the present application provide a question-answering method, apparatus, computer device, computer-readable storage medium, and computer program product to solve or alleviate one or more of the technical problems raised above.
[0006] One aspect of an embodiment of the present application provides a question-answering method, the method comprising:
[0007] Constructing a question-answer knowledge base, wherein the question-answer knowledge base includes multiple groups of question-answer pairs, each group of the question-answer pairs includes at least one answer and N similar questions, where N is greater than 1;
[0008] Vectorizing the question in the question-answer pair to obtain a first vector;
[0009] Obtaining an input question from a client, and vectorizing the input question to obtain a second vector;
[0010] determining a target vector from the first vector based on the second vector;
[0011] Determine a first answer according to the question-answer pair where the target vector is located;
[0012] A second answer is determined according to the first answer by using a pre-built large language model, and the second answer is returned to the client.
[0013] Optionally, determining the second answer according to the first answer by using a pre-built large language model includes:
[0014] Obtain at least one context corresponding to the input question;
[0015] The preceding context and the first answer are input into the large language model, and a second answer is determined according to the first answer and the preceding context by the large language model.
[0016] Optionally, determining the second answer according to the first answer by using a pre-built large language model includes:
[0017] Using a search enhancement generation method to search according to the input question to obtain search data;
[0018] The first answer and the search data are input into the large language model, and a second answer is determined according to the first answer and the search data by the large language model.
[0019] Optionally, the constructing a question-answer knowledge base includes:
[0020] Obtaining original question-answer pairs, each of which includes an original question and an original answer;
[0021] Constructing a plurality of similar questions corresponding to the original question according to the original answer in each of the original question-answer pairs to obtain the question-answer pairs;
[0022] The question-answer knowledge base is formed according to the question-answer pairs.
[0023] Optionally, constructing a plurality of similar questions corresponding to the original question according to the original answer in each of the original question-answer pairs to obtain the question-answer pairs includes:
[0024] Each of the original question-answer pairs is input into the target large model, and the target large model is used to construct and output a number of similar questions corresponding to the original question based on the original answer in each of the original question-answer pairs.
[0025] Optionally, the method further comprises:
[0026] When the client inputs multiple questions in sequence, determining the sequence of the multiple questions;
[0027] The corresponding answers are returned according to the order described.
[0028] Optionally, the method further comprises:
[0029] When an answer is returned to the client and the returned answer is not outputted completely, the progress of the answer is returned to the client so that the client can display a prompt related to the progress at a target location in the client.
[0030] Another aspect of an embodiment of the present application provides a question-answering device, the device comprising:
[0031] A construction module, used to construct a question-answer knowledge base, wherein the question-answer knowledge base includes multiple groups of question-answer pairs, each group of the question-answer pairs includes at least one answer and N similar questions, where N is greater than 1;
[0032] A first vector module, used for vectorizing the question in the question-answer pair to obtain a first vector;
[0033] A second vector module, used to obtain an input question from a client, and vectorize the input question to obtain a second vector;
[0034] a first determining module, configured to determine a target vector from the first vector according to the second vector;
[0035] A second determination module, configured to determine a first answer according to the question-answer pair where the target vector is located;
[0036] The third determination module is used to determine a second answer according to the first answer by using a pre-built large language model, and return the second answer to the client.
[0037] Another aspect of an embodiment of the present application provides a computer device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein: the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the method described above.
[0038] Another aspect of an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a processor, the method described above is implemented.
[0039] Another aspect of an embodiment of the present application provides a computer program product, including a computer program, which implements the method described above when executed by a processor.
[0040] The above technical solution adopted in the embodiment of the present application may have the following advantages:
[0041] By constructing a question-and-answer knowledge base, the questions in the question-and-answer pairs in the question-and-answer knowledge base are vectorized to obtain a first vector; the input questions of the client are vectorized to obtain a second vector, and the target vector is determined from the first vector according to the second vector, and the first answer is determined according to the question-and-answer pair where the target vector is located, and then the first answer is input into a large language model, and the large language model is used to output and return a second answer. By matching similar questions in the knowledge base with the user's input questions, the matching accuracy can be effectively improved, thereby improving the matching effect and the accuracy of the output answer; at the same time, by inputting the initial answer into the large language model and using the large language model to output the final answer, the large language model can also be used to output a more accurate and more humane answer, thereby improving the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] The accompanying drawings exemplarily illustrate the embodiments and constitute a part of the specification, and together with the text description of the specification, are used to explain the exemplary implementation of the embodiments. The embodiments shown are for illustrative purposes only and do not limit the scope of the claims. In all drawings, the same reference numerals refer to similar but not necessarily identical elements.
[0043] Figure 1 The operating environment diagram of the question-answering method according to the first embodiment of the present application is schematically shown;
[0044] Figure 2 The flowchart of the question-answering method according to the first embodiment of the present application is schematically shown;
[0045] Figure 3 Schematically shows Figure 2 Flow chart of sub-steps of step S200;
[0046] Figure 4 A set of question-answer pairs is schematically shown;
[0047] Figure 5 Schematically shows Figure 2 Flow chart of sub-steps of step S210;
[0048] Figure 6 Schematically shows Figure 2 Another sub-step flow chart of step S210;
[0049] Figure 7 The newly added process of the question-answering method according to the first embodiment of the present application is schematically shown;
[0050] Figure 8 The schematic diagram shows the prompt information related to the answer progress displayed on the client;
[0051] Fig. 9 The application diagram of the question-answering method of the first embodiment of the present application is schematically shown;
[0052] Fig.10 A block diagram of a question-answering device according to Embodiment 2 of the present application is schematically shown; and
[0053] Fig.11 The hardware architecture diagram of the computer device according to the third embodiment of the present application is schematically shown. DETAILED DESCRIPTION
[0054] In order to make the purpose, technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.
[0055] It should be noted that the descriptions involving "first", "second", etc. in the embodiments of the present application are only for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in the field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by this application.
[0056] In the description of the present application, it should be understood that the numerical labels before the steps do not indicate the order in which the steps are executed, but are only used to facilitate the description of the present application and to distinguish each step, and therefore should not be understood as a limitation on the present application.
[0057] First, the following terms are explained:
[0058] Large Language Model (LLM) refers to a deep learning model trained on massive text data. It can not only generate natural language text, but also deeply understand the meaning of the text and handle various natural language tasks such as text summarization, question answering, translation, etc.
[0059] Large models refer to machine learning models with large-scale parameters and complex computational structures. These models are usually built with deep neural networks and have billions or even hundreds of billions of parameters. Large models are designed to improve the expressiveness and predictive performance of the model and to handle more complex tasks and data. Large models are widely used in various fields, including natural language processing, computer vision, speech recognition, and recommendation systems.
[0060] Retrieval-Augmented Generation (RAG) is a technology that combines information retrieval and natural language generation. Specifically, when the model needs to generate text or answer questions, it first retrieves relevant information from a large collection of documents, and then uses the retrieved information to guide the generation of text, thereby improving the quality and accuracy of predictions.
[0061] A multi-turn conversation refers to multiple exchanges between humans and machines to complete a specific task or obtain the required information. This type of interaction usually involves multiple aspects of a question, so the machine needs to be able to understand natural language and have sufficient contextual knowledge to answer the user's questions.
[0062] Secondly, in order to facilitate those skilled in the art to understand the technical solutions provided in the embodiments of the present application, the relevant technologies are described below:
[0063] In the related art, when building a knowledge base, the intelligent question-answering system divides the document into several corpora, vectorizes the divided corpora to obtain a vectorized corpus, and then matches the vector of the input question with the vector of the corpus to obtain the corresponding answer. However, this method will result in poor matching effect, resulting in low accuracy of the output answer.
[0064] To this end, the embodiment of the present application provides a question-answering technical solution. In this technical solution, the matching effect between the question input by the user and the knowledge base can be improved, thereby improving the accuracy of the output answer. See below for details.
[0065] Finally, for ease of understanding, an exemplary operating environment is provided below.
[0066] like Figure 1 As shown, the operating environment diagram includes: a service platform 2, and clients (4A, 4B, ..., 4N).
[0067] The service platform 2 can be connected to the client terminals (4A, 4B, ..., 4N) via the network.
[0068] The service platform 2 may be a single server, a server cluster or a cloud computing service center.
[0069] The service platform 2 can provide the client with login service, question-and-answer service, etc. Among them, the question-and-answer service can be a question input by the user of the client, and the service platform 2 outputs the corresponding answer according to the question.
[0070] The service platform 2 may be located in a data center such as a single location, or distributed in different geographical locations (e.g., in multiple locations). The service platform 2 may provide services via a network. The network includes various network devices such as routers, switches, multiplexers, hubs, modems, bridges, repeaters, firewalls, proxy devices, and / or the like. The network may include physical links such as coaxial cable links, twisted pair cable links, optical fiber links, combinations thereof, and the like, or wireless links such as cellular links, satellite links, Wi-Fi links, and the like.
[0071] The client (4A, 4B, ..., 4N) can be configured to access the content and services of the service platform 2. The client (4A, 4B, ..., 4N) can include an electronic device carrying or externally connected to a display panel, such as a mobile device, a tablet device, a laptop computer, a workstation, a virtual reality device, a gaming device, a digital streaming device, a vehicle terminal, a smart TV, a set-top box, etc., and can also include a virtualized computing instance. The virtualized computing instance can include a virtual machine, such as a simulation of a computer system, an operating system, a server, etc. The computing device can load a virtual machine by the computing device based on a virtual image and / or other data defining specific software (e.g., an operating system, a dedicated application, a server) for simulation. As the demand for different types of processing services changes, different virtual machines can be loaded and / or terminated on one or more computing devices.
[0072] The client (4A, 4B, ..., 4N) may be associated with one or more users. A single user may also use one or more of the clients (4A, 4B, ..., 4N) to access the service platform 2. The client (4A, 4B, ..., 4N) may travel to various locations and use different networks to access the service platform 2.
[0073] The client (4A, 4B, ..., 4N) may include an interface. The interface may include a touch pad, a touch screen, a mouse, a keyboard, or other sensing elements. For example, the input element may be configured to receive user instructions, and the user instructions may enable the client (4A, 4B, ..., 4N) to perform various operations, such as inputting questions to be asked, etc.
[0074] It should be noted that the above devices are exemplary, and the number and type of devices are adjustable in different scenarios or according to different needs.
[0075] The following uses the service platform as the execution subject to introduce the technical solution of the present application through multiple embodiments. It should be noted that these embodiments can be implemented in a variety of different forms and should not be interpreted as being limited to the embodiments described here.
[0076] Embodiment 1
[0077] Figure 2 The flowchart of the question-answering method according to the first embodiment of the present application is schematically shown.
[0078] like Figure 2 As shown, the question-answering method may include steps S200 to S212, wherein:
[0079] Step S200, constructing a question-answer knowledge base, wherein the question-answer knowledge base includes multiple groups of question-answer pairs, each group of question-answer pairs includes at least one answer and N similar questions, where N is greater than 1.
[0080] Step S202, vectorize the question in the question-answer pair to obtain a first vector.
[0081] Step S204: obtaining an input question from the client, and vectorizing the input question to obtain a second vector.
[0082] Step S206, determining a target vector from the first vector according to the second vector.
[0083] Step S208, determining a first answer according to the question-answer pair where the target vector is located.
[0084] Step S210: input the first answer into a pre-built large language model, and determine and output a second answer based on the first answer through the large language model.
[0085] Step S212: Return the second answer to the client.
[0086] The question-answering method provided in this embodiment constructs a question-answering knowledge base, vectorizes the questions in the question-answering pairs in the question-answering knowledge base to obtain a first vector; vectorizes the input question of the client to obtain a second vector, determines the target vector from the first vector according to the second vector, determines the first answer according to the question-answering pair where the target vector is located, and then inputs the first answer into a large language model, uses the large language model to output and return the second answer, and matches similar questions in the knowledge base with the input question of the user, which can effectively improve the matching accuracy, thereby improving the matching effect and the accuracy of the output answer; at the same time, by inputting the initial answer into the large language model and using the large language model to output the final answer, the large language model can also be used to output a more accurate and more humane answer, thereby improving the user experience.
[0087] The following combination Figure 2 , each step in step S200 to step S212 and other optional steps are explained in detail.
[0088] Step S200 , construct a question-answering knowledge base, where the question-answering knowledge base includes multiple sets of question-answer pairs, each set of question-answer pairs includes at least one answer and N similar questions, where N is greater than 1.
[0089] In an optional embodiment, if Figure 3 As shown, step S200 may include steps S500 to S504:
[0090] Step S500, obtaining original question-answer pairs, each original question-answer pair including an original question and an original answer.
[0091] Step S502, constructing a number of similar questions corresponding to the original question according to the original answer in each original question-answer pair to obtain a question-answer pair.
[0092] Step S504: forming a question-answer knowledge base based on the question-answer pairs.
[0093] Specifically, crawlers or automated tools can be used to obtain original question-answer pairs from forums, communities, social media, or public datasets.
[0094] When constructing similar questions based on the original question-answer pair, multiple questions similar to the questions in the original question-answer pair can be manually sorted out. For example, if the original question in the original question-answer pair is "When was Bilibili founded?", since users usually call "Bilibili" "B Station" or "A B", similar questions can be sorted out as "When was Bilibili founded?" or "When was A B founded?"; in addition, since users usually only pay attention to the year of the founding time and ask more colloquial questions, similar questions can also be sorted out as "When was Bilibili founded?"; in addition, for some places, the questions may also have some local characteristics, so similar questions can also be sorted out according to the corresponding local characteristics. For example, similar questions can be sorted out as "When was Bilibili founded?", which is sorted out based on the characteristic questioning method of "When" that is usually used when asking about time in some places.
[0095] Please refer to Figure 4 , which is an example of a question-answer pair. As shown in the figure, multiple similar questions can be sorted out based on the standard question (original question) and the standard answer (original answer), where the similar questions correspond to questions that the user may input.
[0096] When constructing similar questions based on the original question-answer pairs, they can also be automatically sorted through certain tools or models. In an optional embodiment, step S502 can also include: inputting each original question-answer pair into the target large model, using the target large model to construct and output a number of similar questions corresponding to the original question based on the original answer in each original question-answer pair.
[0097] When using the target large model to output similar questions, you can input similar instructions such as "please construct several similar questions" to the target large model to make the target large model output several similar questions of the original question. The target large model can be pre-trained first, so that it can generate several similar questions of the original question according to the corresponding instructions and the original question-answer pair. During pre-training, you can also train according to the ideas used in manual sorting, such as training the large model based on the usual or colloquial expressions or aliases of a noun, the user's usual questions, the user's omitted questions, the user's main concerns or local characteristics, so that the large model can combine these factors to generate a variety of similar questions.
[0098] It is understandable that compared with manually organizing similar questions, using a large model to construct and output several similar questions of the original question can effectively improve the efficiency of organizing similar questions, thereby effectively improving the efficiency of building the question-answering knowledge base.
[0099] In step S504, all question-answer pairs may be stored in a database in a unified or specified format, thereby obtaining a question knowledge base.
[0100] In the embodiment corresponding to step S500 to step S504, by obtaining the original question-answer pairs, constructing several similar questions corresponding to the original questions based on the original answers in each original question-answer pair, obtaining question-answer pairs, and forming a question-answer knowledge base based on the question-answer pairs, the question-answer knowledge base can be effectively constructed, which facilitates improving the matching accuracy based on similar questions.
[0101] Step S202 , vectorize the question in the question-answer pair to obtain the first vector.
[0102] Before receiving questions input by the client user, the service platform can pre-vectorize the questions in the question-answer pair to obtain a first vector corresponding to each question (including similar questions).
[0103] Step S204 , obtain the client's input question, vectorize the input question, and obtain a second vector.
[0104] The user of the client can input questions through the client. After the user inputs the question, the service platform can obtain the input question of the client, and then vectorize the input question to obtain a second vector corresponding to the input question.
[0105] Step S206 , determine the target vector from the first vector based on the second vector.
[0106] The service platform can calculate the similarity between the second vector corresponding to the input question and the first vector corresponding to each question in the knowledge base, and determine several vectors with the highest similarity as target vectors based on the similarity.
[0107] Step S208 , determine the first answer based on the question-answer pair where the target vector is located.
[0108] After determining the target vector, the service platform can obtain the question-answer pair where the target vector is located, and use the answer in the question-answer pair as the first answer that is preliminarily determined.
[0109] Step S210 , determine the second answer based on the first answer through a pre-built large language model, and return the second answer to the client.
[0110] The service platform can input the first answer into a pre-built large language model, and the large language model will adjust, polish or modify the first answer to a certain extent, and then output it as a second answer that can be returned to the client. The adjustment, polish or modification can be, for example, making the first answer colloquial, obtaining the part corresponding to the user's question from the first answer, or deleting the part of the first answer that is not related to the user's question.
[0111] In an optional embodiment, if Figure 5 As shown, step S210 may further include steps S300 to S302:
[0112] Step S300, obtaining at least one context corresponding to the input question.
[0113] Step S302: input the above context and the first answer into a large language model, and determine and output a second answer based on the first answer and the above context through the large language model.
[0114] When obtaining at least one context corresponding to the input question, the service platform can directly use the previous context or previous contexts as the context corresponding to the input question. Optionally, the service platform can also perform semantic analysis on the previous input question based on the current input question. If the two have obvious semantic connection or similarity, the previous input question can be used as the corresponding context. For example, if the service platform determines that the previous input question contains the same keywords as the current input question, it can be considered that the two have obvious semantic connection or similarity, and the previous input question can be used as the context corresponding to the current input question.
[0115] When the previous text and the first answer are input into the large language model, the large language model can synthesize the first answer and the previous text, and finally output a second answer that combines the first answer and the previous text. For example, if the current input question is a follow-up to the previous input question, the previous text and the first answer corresponding to the current input question are input into the large language model, so that the large language model can understand the context and output a more accurate final answer.
[0116] In the above optional embodiment, by obtaining at least one context corresponding to the input question, the context and the first answer are input into the large language model, and the second answer is determined and output by the large language model based on the first answer and the context. The large language model can then be used to integrate the context to output a more accurate answer, thereby improving the accuracy of the output answer.
[0117] In an optional embodiment, if Figure 6 As shown, step S210 may further include steps S400 to S402:
[0118] Step S400: Using a search enhancement generation method to search according to an input question to obtain search data.
[0119] Step S402: input the first answer and the search data into the large language model, and determine and output the second answer based on the first answer and the search data through the large language model.
[0120] Specifically, the service platform uses a search enhancement generation method to search external data sources (such as document databases, network resources, etc.) according to the input question to find information or documents related to the input question, and use these related information or documents as search data corresponding to the input question. Optionally, when using the search enhancement generation method to search according to the input question, the construction time of the question and answer knowledge base can be obtained first, and then the construction time of the question and answer knowledge base to the current time is used as the target search time range, thereby narrowing the search range and improving the search efficiency.
[0121] After obtaining the search data, the service platform can perform certain processing on the search data (such as format preprocessing) and then input the search data and the first answer into the large language model, and output the second answer based on the comprehensive first answer and the search data through the large language model.
[0122] Optionally, while obtaining at least one context corresponding to the input question, a retrieval enhancement generation method is used to perform a search based on the input question. On the basis of the retrieval data, at least one context corresponding to the input question, the retrieval data and the first answer can be input into a large language model. The large language model can output a second answer based on the first answer while understanding the context and obtaining more real-time relevant retrieval information. This can further improve the accuracy of the second answer that is finally output.
[0123] In the above optional embodiment, by using the retrieval enhancement generation method to search according to the input question, the retrieval data is obtained, the first answer and the retrieval data are input into the large language model, and the large language model determines and outputs the second answer based on the first answer and the retrieval data. This allows the large language model to output a more accurate answer based on the relevant knowledge in the retrieval data and the first answer, thereby improving the accuracy of the output answer.
[0124] In an optional embodiment, if Figure 7 As shown, the question-answering method may further include steps S600 to S602:
[0125] Step S600, when the client inputs multiple questions in sequence, determining the sequence of the multiple questions.
[0126] Step S602, returning the corresponding answer in order.
[0127] When multiple questions are entered in sequence on the client, such as "Hello", "Are you there?", "Who are you?" and other questions, since the time required to answer each question is different, the first question may be answered last, and the later question may be answered first, thus disrupting the order of questions and answers.
[0128] In step S600, when determining the sequence of multiple questions, each question input by the client may be sequentially identified, so that the service platform determines the sequence of each input question according to the sequence identification. Accordingly, when returning the corresponding answer according to the sequence, the service platform does not answer the subsequent input question before the answer to the previous input question is completely returned, thereby ensuring that the order in which the answers are returned corresponds to the order in which the client inputs the questions.
[0129] In the above optional embodiment, by determining the order of multiple questions when multiple questions are input in sequence on the client, and returning corresponding answers based on the order of the multiple questions, it can be ensured that the order in which the answers are returned corresponds to the order in which the questions are input, making it convenient for the client user to determine the answers corresponding to the questions and avoiding the problem of disorder.
[0130] In an optional embodiment, the question-and-answer method may further include: when an answer is returned to the client and the returned answer is not output completely, returning the progress of the answer to the client so that the client can display prompts related to the progress at a target location in the client.
[0131] The service platform can obtain the answer outputted by the client, compare the answer currently outputted by the client with the second answer obtained by the service platform, and determine whether the output is complete; if the output is not complete, the progress of the answer can be determined by comparing the answer currently outputted with the second answer, and then the progress of the answer can be returned to the client, so that the client can display a prompt related to the progress at the target location in the client. The progress of the answer can be specific percentage information, or it can be status information related to the incompleteness, such as Figure 8 As shown, a prompt "inputting" may be displayed above the question and answer page of the client. Optionally, the client may obtain the currently output answer and return the currently output answer to the service platform, so that the service platform determines the corresponding progress according to the client's reported data combined with the second answer as a whole.
[0132] In the above optional embodiment, by returning the answer to the client and when the returned answer is not completely output, the progress of the answer is returned to the client, so that the client can display prompts related to the progress at the target location in the client, which can facilitate the user of the client to understand the current progress of the answer and improve the user experience.
[0133] In order to make this application easier to understand, the following Fig. 9 An exemplary application is provided.
[0134] like Fig. 9 As shown, the question-answering method may include the following:
[0135] 1. Extract the original question-answer pairs from the trusted data source, sort out several similar questions based on the questions in the original question-answer pairs using manual and / or large models, and construct question-answer pairs with the similar questions, original questions, and original answers to form a question-answer knowledge base, where the questions and answers can be stored in the target database;
[0136] 2. Vectorize the questions in the question-answer pair. The vectorized questions can be trained to form a vector matching model so that two vectors that are actually similar in the model have a higher similarity, and two vectors that are actually dissimilar have a lower similarity;
[0137] 3. When receiving the user's input question, the input question is vectorized, and the vectorized input question is matched with the vector in the question-answering knowledge base in the model. At the same time, the vectorized input question is retrieved through the retrieval enhancement generation method, and the TopN (most matching N) matching questions and corresponding answers and the retrieved information are returned to the pre-built large language model.
[0138] 4. Get the context of the current conversation, input the context of the current conversation together with the result of step 3 into the large language model, and get the final answer through prompt and comprehensive processing.
[0139] 5. Output the final answer and return it to the user.
[0140] Embodiment 2
[0141] Fig.10 The block diagram of the question-answering device according to the second embodiment of the present application is schematically shown. The device can be divided into one or more program modules, one or more program modules are stored in a storage medium, and are executed by one or more processors to complete the embodiment of the present application. The program module referred to in the embodiment of the present application refers to a series of computer program instruction segments that can complete specific functions. The following description will specifically introduce the functions of each program module in this embodiment. Fig.10 As shown, the apparatus 700 may include: a construction module 710, a first vector module 720, a second vector module 730, a first determination module 740, a second determination module 750 and a third determination module 760, wherein:
[0142] A construction module 710 is used to construct a question-answer knowledge base, wherein the question-answer knowledge base includes multiple groups of question-answer pairs, each group of the question-answer pairs includes at least one answer and N similar questions, where N is greater than 1;
[0143] A first vector module 720, configured to vectorize the question in the question-answer pair to obtain a first vector;
[0144] The second vector module 730 is used to obtain an input question from the client, and vectorize the input question to obtain a second vector;
[0145] A first determination module 740, configured to determine a target vector from the first vector according to the second vector;
[0146] A second determination module 750, configured to determine a first answer according to the question-answer pair where the target vector is located;
[0147] The third determination module 760 is used to determine a second answer according to the first answer by using a pre-built large language model, and return the second answer to the client.
[0148] In an optional embodiment, the third determining module 760 is further configured to:
[0149] Obtain at least one context corresponding to the input question;
[0150] The preceding context and the first answer are input into the large language model, and a second answer is determined according to the first answer and the preceding context by the large language model.
[0151] In an optional embodiment, the third determining module 760 is further configured to:
[0152] Using a search enhancement generation method to search according to the input question to obtain search data;
[0153] The first answer and the search data are input into the large language model, and a second answer is determined according to the first answer and the search data by the large language model.
[0154] In an optional embodiment, the construction module 710 is further configured to:
[0155] Obtaining original question-answer pairs, each of which includes an original question and an original answer;
[0156] Constructing a plurality of similar questions corresponding to the original question according to the original answer in each of the original question-answer pairs to obtain the question-answer pairs;
[0157] The question-answer knowledge base is formed according to the question-answer pairs.
[0158] In an optional embodiment, the construction module 710 is further configured to:
[0159] Each of the original question-answer pairs is input into the target large model, and the target large model is used to construct and output a number of similar questions corresponding to the original question based on the original answer in each of the original question-answer pairs.
[0160] In an optional embodiment, the device 700 is further used for:
[0161] When the client inputs multiple questions in sequence, determining the sequence of the multiple questions;
[0162] The corresponding answers are returned according to the order described.
[0163] In an optional embodiment, the device 700 is further used for:
[0164] When an answer is returned to the client and the returned answer is not outputted completely, the progress of the answer is returned to the client so that the client can display a prompt related to the progress at a target location in the client.
[0165] Embodiment 3
[0166] Fig.11 The schematic diagram of the hardware architecture of a computer device 10000 suitable for implementing the question-answering method according to the third embodiment of the present application is shown schematically. In some embodiments, the computer device 10000 may be a terminal device such as a smart phone, a wearable device, a tablet computer, a personal computer, a vehicle-mounted terminal, a game console, a virtual device, a workbench, a digital assistant, a set-top box, a robot, etc. In other embodiments, the computer device 10000 may be a rack server, a blade server, a tower server, or a cabinet server (including an independent server, or a server cluster composed of multiple servers), etc. Fig.11 As shown, the computer device 10000 includes but is not limited to: a memory 10010, a processor 10020, and a network interface 10030 that can communicate with each other through a system bus. Among them:
[0167] The memory 10010 includes at least one type of computer-readable storage medium, and the readable storage medium includes a flash memory, a hard disk, a multimedia card, a card-type memory (such as an SD or DX memory), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the memory 10010 may be an internal storage module of the computer device 10000, such as a hard disk or a memory of the computer device 10000. In other embodiments, the memory 10010 may also be an external storage device of the computer device 10000, such as a plug-in hard disk equipped on the computer device 10000, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. Of course, the memory 10010 may also include both the internal storage module of the computer device 10000 and its external storage device. In this embodiment, the memory 10010 is generally used to store the operating system and various application software installed in the computer device 10000, such as the program code of the question-answering method, etc. In addition, the memory 10010 can also be used to temporarily store various data that have been output or are to be output.
[0168] In some embodiments, the processor 10020 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other chips. The processor 10020 is generally used to control the overall operation of the computer device 10000, such as performing control and processing related to data interaction or communication with the computer device 10000. In this embodiment, the processor 10020 is used to run the program code stored in the memory 10010 or process data.
[0169] The network interface 10030 may include a wireless network interface or a wired network interface, and the network interface 10030 is generally used to establish a communication link between the computer device 10000 and other computer devices. For example, the network interface 10030 is used to connect the computer device 10000 to an external terminal through a network, and to establish a data transmission channel and a communication link between the computer device 10000 and the external terminal. The network may be a wireless or wired network such as an intranet, the Internet, the Global System of Mobile communication (GSM), Wideband Code Division Multiple Access (WCDMA), 4G network, 5G network, Bluetooth, Wi-Fi, etc.
[0170] It should be pointed out that Fig.11 Only a computer device having components 10010 - 10030 is shown, but it should be understood that implementation of all of the components shown is not a requirement, and more or fewer components may alternatively be implemented.
[0171] In this embodiment, the question-answering method stored in the memory 10010 can also be divided into one or more program modules and executed by one or more processors (such as processor 10020) to complete the embodiment of the present application.
[0172] Embodiment 4
[0173] An embodiment of the present application also provides a computer-readable storage medium, on which a computer program is stored, wherein when the computer program is executed by a processor, the steps of the question-and-answer method in the embodiment are implemented.
[0174] In this embodiment, the computer-readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEP ROM), programmable read-only memory (PROM), magnetic memory, disk, optical disk, etc. In some embodiments, the computer-readable storage medium can be an internal storage unit of a computer device, such as a hard disk or memory of the computer device. In other embodiments, the computer-readable storage medium can also be an external storage device of a computer device, such as a plug-in hard disk equipped on the computer device, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. Of course, the computer-readable storage medium can also include both the internal storage unit of the computer device and its external storage device. In this embodiment, the computer-readable storage medium is generally used to store the operating system and various application software installed on the computer device, such as the program code of the question-answering method in the embodiment. In addition, the computer-readable storage medium can also be used to temporarily store various types of data that have been output or are to be output.
[0175] Embodiment 5
[0176] An embodiment of the present application also provides a computer program product, including a computer program, which implements the method in the above embodiment when executed by a processor.
[0177] Obviously, those skilled in the art should understand that the modules or steps of the above-mentioned embodiments of the present application can be implemented by general-purpose computer devices, they can be concentrated on a single computer device, or distributed on a network composed of multiple computer devices, optionally, they can be implemented by executable program codes of computer devices, so that they can be stored in a storage device and executed by the computer device, and in some cases, the steps shown or described can be executed in a different order from that herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the embodiments of the present application are not limited to any specific combination of hardware and software.
[0178] It should be noted that the above are only preferred embodiments of the present application, and the patent protection scope of the present application is not limited thereto. Any equivalent structure or equivalent process transformation made using the contents of the specification and drawings of the present application, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A question-answering method, characterized in that: The method comprises: Constructing a question-answer knowledge base, wherein the question-answer knowledge base includes multiple groups of question-answer pairs, each group of the question-answer pairs includes at least one answer and N similar questions, where N is greater than 1; Vectorizing the question in the question-answer pair to obtain a first vector; Obtaining an input question from a client, and vectorizing the input question to obtain a second vector; determining a target vector from the first vector based on the second vector; Determine a first answer according to the question-answer pair where the target vector is located; A second answer is determined according to the first answer by using a pre-built large language model, and the second answer is returned to the client.
2. The method according to claim 1, characterized in that The determining the second answer according to the first answer by using a pre-built large language model includes: Obtain at least one context corresponding to the input question; The preceding context and the first answer are input into the large language model, and a second answer is determined according to the first answer and the preceding context by the large language model.
3. The method according to claim 1, characterized in that The determining the second answer according to the first answer by using a pre-built large language model includes: Using a search enhancement generation method to search according to the input question to obtain search data; The first answer and the search data are input into the large language model, and a second answer is determined according to the first answer and the search data by the large language model.
4. The method according to claim 1, characterized in that: The step of constructing a question-answer knowledge base includes: Obtaining original question-answer pairs, each of which includes an original question and an original answer; Constructing a plurality of similar questions corresponding to the original question according to the original answer in each of the original question-answer pairs to obtain the question-answer pairs; The question-answer knowledge base is formed according to the question-answer pairs.
5. The method according to claim 4, characterized in that The step of constructing a plurality of similar questions corresponding to the original question according to the original answer in each of the original question-answer pairs to obtain the question-answer pairs includes: Each of the original question-answer pairs is input into the target large model, and the target large model is used to construct and output several similar questions corresponding to the original question according to the original answer in each of the original question-answer pairs.
6. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: When the client inputs multiple questions in sequence, determining the sequence of the multiple questions; The corresponding answers are returned according to the order described.
7. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: When an answer is returned to the client and the returned answer is not output completely, the progress of the answer is returned to the client so that the client can display a prompt related to the progress at a target location in the client.
8. A question-answering device, characterized in that: The device comprises: A construction module, used to construct a question-answer knowledge base, wherein the question-answer knowledge base includes multiple groups of question-answer pairs, each group of the question-answer pairs includes at least one answer and N similar questions, where N is greater than 1; A first vector module, used for vectorizing the question in the question-answer pair to obtain a first vector; A second vector module, used to obtain an input question from a client, and vectorize the input question to obtain a second vector; a first determining module, configured to determine a target vector from the first vector according to the second vector; A second determination module, configured to determine a first answer according to the question-answer pair where the target vector is located; The third determination module is used to determine a second answer according to the first answer by using a pre-built large language model, and return the second answer to the client.
9. A computer device, characterized in that: include: at least one processor; and a memory communicatively connected to the at least one processor; wherein: The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 8.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a processor, the method according to any one of claims 1 to 8 is implemented.
11. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to claims 1 to 8 are implemented.
Citation Information
Patent Citations
Method and device for automatically replying questions, computer readable storage medium and terminal
CN116340481A
Medical auxiliary question and answer method and system based on knowledge calibration and retrieval enhancement
CN117573843A
Intelligent question and answer method and device and computer readable medium
CN117972038A
Question answering method and device based on vector database
CN118093808A
