Knowledge question and answer processing method and device, equipment and storage medium
By obtaining target questions and external data, generating reply information, retrieving background information, and determining relevance scores, it solves the problem of large language model answers not being based on external data sources and improves the accuracy of knowledge question and answer.
Patent Information
- Application Number
- CN202410758917.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-12
- Publication Date
- 2024-08-30
AI Technical Summary
When using a large language model combined with retrieval-enhanced generation technology to answer questions and answers, the answers may not be based on external data sources, resulting in low accuracy.
By obtaining the target question and its corresponding external data, the reply information is generated, retrieved with the background information, and the relevance score is determined. The source of the answer is determined based on the score to ensure that the answer is relevant to the external data.
Improved the accuracy of knowledge questions and answers based on external data sources to ensure that answers are highly relevant to external data sources.
Smart Images

Figure CN118568237A
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence, and in particular to a knowledge question and answer processing method, device, equipment and storage medium. Background Art
[0002] Retrieval-augmented Generation (RAG) is a technology that uses information from private or proprietary data sources to assist in text generation. It improves the output of a large language model by obtaining background information from external data sources to supplement the original knowledge base of the large language model. A large language model combined with retrieval-augmented generation technology can answer user questions based on external data sources.
[0003] At present, when a large language model combined with retrieval-enhanced generation technology is used for knowledge question answering, the answer given by the large language model may not be based on the knowledge of the external data source, resulting in low accuracy of knowledge question answering based on the external data source. Summary of the invention
[0004] The embodiments of the present application provide a knowledge question and answer processing method, device, equipment and storage medium to improve the accuracy of knowledge questions and answers.
[0005] In a first aspect, an embodiment of the present application provides a knowledge question answering processing method, including:
[0006] Acquire a target question and external data corresponding to the target question; wherein the external data corresponding to the target question is used to indicate an answer to the target question;
[0007] Generate first reply information based on the target question, external data corresponding to the target question, and a preset large language model;
[0008] Based on the external data corresponding to the target question, the first reply information is searched to obtain first background information;
[0009] Determine a relevance score according to the first reply information and the first background information; wherein the relevance score is used to describe the relevance degree between the first reply information and the first background information;
[0010] An answer to the target question is determined based on the relevance score.
[0011] In some possible implementations, determining the answer to the target question according to the relevance score includes:
[0012] If it is determined that the relevance score is greater than a first threshold and less than a second threshold, generating second prompt information according to the first reply information and the first background information, inputting the second prompt information into the large language model, and outputting an answer to the target question;
[0013] If it is determined that the relevance score is greater than or equal to the second threshold, the first reply information is used as the answer to the target question.
[0014] In some possible implementations, the method further includes:
[0015] If it is determined that the relevance score is less than or equal to the first threshold, the steps of generating a first reply message based on the target question, external data corresponding to the target question and a preset large language model are re-executed; the first reply message is retrieved based on the external data corresponding to the target question to obtain first background information; the relevance score is determined based on the first reply message and the first background information; and the answer to the target question is determined based on the relevance score.
[0016] In some possible implementations, determining a relevance score according to the first reply information and the first background information includes:
[0017] Determine a first keyword set according to the first reply information; wherein the first keyword set includes M first keywords in the first reply information; M is an integer greater than or equal to 1;
[0018] Determine a second keyword set according to the first background information; wherein the second keyword set includes N second keywords in the first background information; N is an integer greater than or equal to 1;
[0019] A relevance score is determined based on the first keyword set and the second keyword set.
[0020] In some possible implementations, determining a relevance score according to the first keyword set and the second keyword set includes:
[0021] For the i-th first keyword in the first keyword set, determine a similarity value between the i-th first keyword and a second keyword in the second keyword set; wherein i is an integer greater than or equal to 1 and less than or equal to M;
[0022] If it is determined that there is a second keyword whose similarity value is greater than or equal to the preset threshold, determine the i-th first keyword as the marked first keyword; and determine that the value of i is increased by one; until it is determined that the value of i is greater than M, determine the number of marked first keywords in the first keyword set;
[0023] If it is determined that there is no second keyword whose similarity value is greater than or equal to the preset threshold, the value of i is determined to be increased by one; until it is determined that the value of i is greater than M, the number of marked first keywords in the first keyword set is determined;
[0024] The quotient of the number of the marked first keywords and the number N of the second keywords in the second keyword set is determined as the relevance score.
[0025] In some possible implementations, generating first reply information based on the target question, external data corresponding to the target question, and a preset large language model includes:
[0026] According to the target problem, determining a first eigenvector of the target problem;
[0027] According to the first feature vector, searching in the external data corresponding to the target question to obtain second background information;
[0028] The second background information and the target question are combined to obtain first prompt information;
[0029] The first prompt information is input into a preset large language model to obtain first reply information.
[0030] In some possible implementations, the external data corresponding to the target question includes multiple partitions; each partition includes background information of a preset length; the partition has a third feature vector; based on the external data corresponding to the target question, the first reply information is retrieved to obtain the first background information, including:
[0031] Determining a second feature vector of the first reply information according to the first reply information;
[0032] Determine a partition corresponding to the second eigenvector according to the second eigenvector and the third eigenvector;
[0033] The first background information is obtained according to the partition corresponding to the second feature vector.
[0034] In a second aspect, an embodiment of the present application provides a knowledge question and answer processing device, including:
[0035] An acquisition module, used to acquire a target question and external data corresponding to the target question; wherein the external data corresponding to the target question is used to indicate an answer to the target question;
[0036] A generation module, configured to generate first reply information based on the target question, external data corresponding to the target question, and a preset large language model;
[0037] A retrieval module, configured to retrieve the first reply information based on external data corresponding to the target question to obtain first background information;
[0038] A first determination module, configured to determine a relevance score according to the first reply information and the first background information; wherein the relevance score is used to describe the relevance between the first reply information and the first background information;
[0039] The second determination module is used to determine the answer to the target question according to the relevance score.
[0040] In a third aspect, an embodiment of the present application provides an electronic device, including: a memory, a processor;
[0041] The memory stores computer-executable instructions;
[0042] The processor executes the computer-executable instructions stored in the memory, so that the processor executes the above first aspect and / or various possible implementations of the first aspect.
[0043] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the first aspect above and / or various possible implementations of the first aspect.
[0044] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the above first aspect and / or various possible implementation methods of the first aspect.
[0045] The knowledge question and answer processing method, device, equipment and storage medium provided in the embodiment of the present application determine the correlation score between the first reply information and the first background information through the first reply information given by the large language model and the first background information in the external data corresponding to the first reply information, and then obtain the answer corresponding to the target question according to the correlation score. In this way, the server can ensure that the answer with strong correlation with the external data is given based on the first reply information and the correlation score, thereby improving the accuracy of the knowledge question and answer based on the external data. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0047] Figure 1 A schematic diagram of an application scenario provided for this application;
[0048] Figure 2 Schematic diagram of the process of the knowledge question answering method provided for this application Figure 1 ;
[0049] Figure 3 Schematic diagram of the process of the knowledge question answering method provided for this application Figure 2 ;
[0050] Figure 4 A schematic diagram of the structure of the knowledge question and answer processing device provided in this application;
[0051] Figure 5 A schematic diagram of the structure of the electronic device provided in this application.
[0052] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0053] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0054] First, the terms involved in this application are explained:
[0055] Large Language Model (LLM): 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.
[0056] The large language model combined with retrieval enhancement generation technology can retrieve context information from external knowledge sources, so that the large language model can generate answers based on the context information of the external knowledge source to enhance the performance of the large language model.
[0057] At present, when a large language model combined with retrieval-enhanced generation technology is used for knowledge question answering, the answer given by the large language model may not be based on knowledge from an external data source. Instead, the large language model obtains the answer based on its own training content, that is, the answer is not based on the answer obtained from the external data source, resulting in low accuracy of knowledge question answering based on external data sources.
[0058] In view of this, an embodiment of the present application provides a knowledge question and answer processing method, which determines background information from an external knowledge source based on the answer to the target question, and determines the degree of correlation between the answer and the background information to verify whether the answer is related to the external data source, thereby improving the accuracy of knowledge questions based on the external data source.
[0059] Figure 1 A schematic diagram of an application scenario provided by this application. Figure 1 As shown, the knowledge question answering system includes a server and a client.
[0060] The above-mentioned knowledge question answering system can generate answers to questions based on questions input by users.
[0061] The above-mentioned server is used to generate answers to questions based on questions sent by the client. The server can be a server or a server cluster. The server can be deployed in any environment, such as a cloud environment, or it can be deployed in a distributed manner in different environments, such as partially deployed in an edge environment and partially deployed in a cloud environment. It should be noted that the embodiment of the present application does not limit the architecture of the server. The executor of the embodiment of the present application can be the server.
[0062] In a possible implementation, the server is deployed with a large language model. It should be noted that the embodiment of the present application does not limit the type of the large language model.
[0063] The client is used to display the front-end display interface of the knowledge question-answering system to the user, receive questions input by the user, and display the answers to the questions. The client can be a client of the World Wide Web (WEB) version or an application (APP) version, which is not limited in this application. The client can be deployed on electronic devices, such as mobile phones, computers, tablets, etc.
[0064] In a possible implementation, the above-mentioned knowledge question and answer system may include an external knowledge source. The external data source includes external data. The embodiment of the present application does not limit the storage form of the external data in the external data source. For example, it can be in the form of a knowledge tree, or in the form of a knowledge graph, or in the form of a partition, that is, the external data is divided into multiple partitions for storage. The external knowledge source can be integrated with the above-mentioned server, or it can be set separately, for example, it can be set separately in the form of a database in the knowledge question and answer system.
[0065] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0066] Figure 2 Schematic diagram of the process of the knowledge question answering method provided for this application Figure 1 .like Figure 2 As shown, the method includes:
[0067] S101. Obtain a target problem and external data corresponding to the target problem.
[0068] The target question is a question to be answered that is input by the user. It should be noted that the embodiment of the present application does not limit the content of the target question. The external data corresponding to the target question is used to indicate the answer to the target question.
[0069] The target question is received by the client of the knowledge question answering system and sent to the server. It should be noted that the embodiment of the present application does not limit how the user inputs the target question on the client. For example, it can be input through the input device of the client device (such as a keyboard), or it can be input through the voice collection device of the client device (such as a microphone).
[0070] The external data corresponding to the above-mentioned target question may be input by the user when inputting the target question, or may be pre-stored by the above-mentioned server. When pre-stored on the server, a possible implementation method is that the external data source of the server may include multiple external data, each external data has a fourth feature vector, and the fourth feature vector is the semantic feature vector of the external data. The server may first determine the first feature vector of the target question, and then determine the external data corresponding to the target question based on the similarity value between the first feature vector and the fourth feature vector. Among them, the first feature vector is the semantic feature vector of the target question. It should be noted that the embodiment of the present application does not limit the calculation method of the similarity value, for example, it may be cosine similarity. It should be noted that the embodiment of the present application does not limit the method for determining the semantic feature vector, for example, it may be based on the BERT model, or other deep learning neural network models that can perform feature vector calculations.
[0071] In another possible implementation, the target question has an identifier of external data, and the server can determine the external data corresponding to the target question according to the identifier of the external data indicated by the target question.
[0072] S102: Generate first reply information based on the target question, external data corresponding to the target question, and a preset large language model.
[0073] Exemplarily, the first reply information may be a preliminary answer given by the large language model to the target question.
[0074] In some possible implementations, the first feature vector of the target question is first determined, and then, based on the first feature vector, a search is performed in the external data corresponding to the target question to obtain second background information, and then the second background information and the target question are concatenated to obtain first prompt information, and the first prompt information is input into the large language model to output the first reply information. The second background information is part of the external data.
[0075] S103: Based on the external data corresponding to the target question, the first reply information is searched to obtain the first background information.
[0076] Exemplarily, the first background information is part of the data in the external data source corresponding to the target question. It should be understood that the first background information is obtained based on the first reply information, and the first reply information is an answer to the target question based on the large language model. The amount of information included in the first reply information is greater than the amount of information included in the target question. Therefore, the content included in the first background information is richer than the content included in the second background information.
[0077] In some possible implementations, the external data includes multiple partitions; each partition includes background information of a preset length; the partition has a third feature vector, and the third feature vector refers to a semantic feature vector of the background information included in the partition. The second feature vector of the first reply information is first determined, and then the partition corresponding to the second feature vector is determined according to the similarity value between the second feature vector and the third feature vector, and the background information included in the partition corresponding to the second feature vector is used as the first background information.
[0078] S104: Determine a relevance score according to the first reply information and the first background information.
[0079] Exemplarily, the above relevance score is used to describe the relevance between the first reply information and the first background information.
[0080] In some possible implementations, the server may input the first reply information and the first background information into a preset computing model and output a correlation score. The computing model may be, for example, a convolutional neural network model or other deep learning network model, which is not limited in the embodiments of the present application. The server may also preset a mapping relationship between the first reply information, the first background information and the correlation score, and determine the correlation score based on the mapping relationship.
[0081] S105. Determine the answer to the target question based on the relevance score.
[0082] In some possible implementations, if the server determines that the correlation score is greater than a first threshold and less than a second threshold, it means that the first reply information has a low correlation with the first background information in the external data. Then, a second prompt information is generated based on the first reply information and the first background information, and the second prompt information is input into the large language model to output the answer to the target question. If the server determines that the correlation score is greater than or equal to the second threshold, it means that the first reply information has a high correlation with the first background information in the external data. Then, the first reply information is used as the answer to the target question.
[0083] Exemplarily, the first threshold value may be, for example, 0.6, and the second threshold value may be, for example, 0.8, that is, when 0.6 < correlation score < 0.8, the server may generate a second prompt message based on the first reply message and the first background information, and input the second prompt message into the large language model to output the answer to the target question. For example, the first reply message and the first background information may be filled into a preset template to generate a second prompt message. The preset template may be, for example, "Please give an answer to [target question] based on [first reply message] and [first background information]." When the correlation score is ≥ 0.8, the server uses the first reply message as the answer to the target question. It should be noted that the embodiment of the present application does not limit the content of the template, as well as the content of the first threshold and the second threshold, and can be set specifically according to actual needs.
[0084] In this way, when the server determines that the first reply information has a low correlation with the first background information in the external data, it can generate second prompt information based on the first reply information and the first background information, and input the second prompt information into the large language model, so as to supplement the background information not involved in the large language model and obtain a more accurate answer.
[0085] In some possible implementations, if the server determines that the relevance score is less than or equal to the first threshold, it indicates that the first reply information has a low relevance to the first background information in the external data, and then outputs a third prompt message, which is used to prompt the user that the target question cannot be answered by the large language model. It should be noted that the embodiment of the present application does not limit the content of the third prompt message.
[0086] In some possible implementations, if the server determines that the relevance score is less than or equal to the first threshold, it means that the first reply information has a low correlation with the first background information in the external data. Then, the steps of generating the first reply information based on the target question, the external data corresponding to the target question, and the preset large language model are re-executed; the first reply information is retrieved based on the external data corresponding to the target question to obtain the first background information; the relevance score is determined based on the first reply information and the first background information; and the answer to the target question is determined based on the relevance score, that is, returning to execute steps S102-S105 to redetermine the answer to the target question.
[0087] It should be understood that the first reply information given by the large language model each time is not necessarily the same. Therefore, the aforementioned steps can be repeated multiple times based on the first reply information and the relevance score given by the large language model until the first reply information with a relevance score that meets the conditions is determined, and then the answer to the target question is obtained, thereby ensuring the relevance of the answer to the external data and improving the accuracy of the answer.
[0088] The knowledge question and answer processing method provided in the embodiment of the present application determines the correlation score between the first reply information and the first background information through the first reply information given by the large language model and the first background information in the external data corresponding to the first reply information, and then obtains the answer corresponding to the target question according to the correlation score. In this way, the server can ensure that the answer with strong correlation with the external data is given based on the first reply information and the correlation score, thereby improving the accuracy of the knowledge question and answer based on the external data.
[0089] Figure 3 Schematic diagram of the process of the knowledge question answering method provided for this application Figure 2 ,like Figure 3 As shown, in this embodiment Figure 2 Based on the embodiment, the knowledge question answering processing method is described in detail, and the method includes:
[0090] S201. Obtain a target problem and external data corresponding to the target problem.
[0091] It should be noted that this step is similar to the aforementioned step S101, and reference may be made to the description of the aforementioned step S101.
[0092] S202: Determine a first eigenvector of the target problem according to the target problem.
[0093] Exemplarily, the first feature vector is a semantic feature vector of the target question. For example, the target question can be input into a preset BERT model to output the first feature vector of the target question.
[0094] S203: Search external data corresponding to the target question according to the first feature vector to obtain second background information.
[0095] Exemplarily, the external data includes a plurality of partitions; each partition includes background information of a preset length; the partition has a third feature vector, and the third feature vector refers to a semantic feature vector of the background information included in the partition. According to the similarity value between the first feature vector and the third feature vector, the partition corresponding to the first feature vector is determined, and the background information included in the partition corresponding to the first feature vector is used as the second background information.
[0096] S204: Combine the second background information and the target question to obtain first prompt information.
[0097] Exemplarily, the target question and the second background information can be filled into a preset template to obtain a first prompt information (Prompt). The preset template can be, for example, "Please give an answer to [the target question] based on [the second background information]." It should be noted that the embodiment of the present application does not limit the content of the template.
[0098] S205: Input the first prompt information into a preset large language model to obtain first reply information.
[0099] Exemplarily, the first prompt information is input into a preset large language model, and the answer output by the large language model is used as the first reply information.
[0100] S206: Determine a second feature vector of the first reply information according to the first reply information.
[0101] Exemplarily, the second feature vector is a semantic feature vector of the first reply information. For example, the first reply information can be input into a preset BERT model to output the second feature vector of the first reply information.
[0102] S207: Determine a partition corresponding to the second eigenvector according to the second eigenvector and the third eigenvector.
[0103] Exemplarily, according to the similarity values between the second eigenvector and the third eigenvector, it is determined that the partition corresponding to the third eigenvector with the highest similarity value is the partition corresponding to the second eigenvector.
[0104] S208. Obtain first background information according to the partition corresponding to the second eigenvector.
[0105] Exemplarily, the background information included in the partition corresponding to the second eigenvector is used as the first background information.
[0106] S209: Determine a first keyword set according to the first reply information.
[0107] Exemplarily, the first keyword set includes M first keywords in the first reply information, and M is an integer greater than or equal to 1. The first keyword is used to describe the main content of the first reply information.
[0108] In some possible implementations, the server may input the first reply information into a keyword extraction model to obtain M keywords of the first reply information, thereby forming the first keyword set. The keyword extraction model is used to extract keywords from text. The embodiment of the present application does not limit the type of the keyword extraction model, which only needs to be able to complete the keyword extraction task, such as a KeyBERT model.
[0109] S210: Determine a second keyword set according to the first background information.
[0110] Exemplarily, the second keyword set includes N second keywords in the first background information, where N is an integer greater than or equal to 1. The second keywords are used to describe the main content of the first background information.
[0111] In some possible implementations, the server may input the first background information into a keyword extraction model to obtain N keywords of the first background information, and then form the second keyword set.
[0112] It should be noted that the embodiment of the present application does not limit the execution order of steps S209 and S210, which may be executed in parallel or sequentially. The embodiment of the present application only uses sequential execution as an illustration.
[0113] S211. Determine a relevance score according to the first keyword set and the second keyword set.
[0114] Exemplarily, the server may determine the similarity between each first keyword in the first keyword combination and each second keyword in the second keyword set, and determine the relevance score based on the similarity.
[0115] For example, this step may include the following steps:
[0116] S2111. For the ith first keyword in the first keyword set, determine a similarity value between the ith first keyword and a second keyword in the second keyword set.
[0117] Wherein, i is an integer greater than or equal to 1, and less than or equal to M. For example, the cosine similarity value between the ith first keyword and the jth second keyword in the second keyword set may be calculated. If it is determined that the similarity value is greater than or equal to the preset threshold, it indicates that there is a second keyword in the second keyword set whose similarity value is greater than or equal to the preset threshold, that is, there is a second keyword in the second keyword set whose correlation with the ith first keyword is relatively high, and step S2112 is executed; if it is determined that the similarity value is less than the preset threshold, the value of j is determined to be increased by one until j is greater than N, indicating that there is no second keyword in the second keyword set whose similarity value is greater than or equal to the preset threshold, that is, there is no second keyword in the second keyword set whose correlation with the ith first keyword is relatively high, and step S2113 is executed.
[0118] S2112. If it is determined that there is a second keyword whose similarity value is greater than or equal to the preset threshold, determine the i-th first keyword as the marked first keyword; and determine the value of i plus one; until it is determined that the value of i is greater than M, determine the number of marked first keywords in the first keyword set.
[0119] Exemplarily, the above-mentioned marked first keyword is used to describe a first keyword whose similarity value with the second keyword is greater than or equal to a preset threshold. For example, the first keyword can be added to the third keyword set, and the first keyword included in the third keyword set is used as the marked first keyword.
[0120] After determining that the i-th first keyword is the marked first keyword, determine that the value of i is increased by 1, and return to step S2111, until it is determined that the value of i is greater than M, and determine the number of marked first keywords in the first keyword set. For example, the number of marked first keywords can be determined by counting the number of first keywords in the third keyword set.
[0121] S2113: If it is determined that there is no second keyword whose similarity value is greater than or equal to the preset threshold, determine that the value of i is increased by one; until it is determined that the value of i is greater than M, determine the number of marked first keywords in the first keyword set.
[0122] Exemplarily, when it is determined that there is no second keyword with a similarity value greater than or equal to a preset threshold, it means that there is no second keyword with a high degree of relevance to the i-th first keyword in the second keyword set, then the similarity value between the second keyword set and the i+1-th first keyword is determined, and the number of marked first keywords in the first keyword set is determined until i is greater than M.
[0123] S2114: Determine a quotient of the number of marked first keywords and the number N of second keywords in the second keyword set as a relevance score.
[0124] For example, the relevance score can be calculated by the following formula:
[0125]
[0126] The above f represents the relevance score, num represents the number of marked first keywords, and N represents the number of second keywords in the second keyword set.
[0127] S212. Determine the answer to the target question based on the relevance score.
[0128] For example, if the server determines that the correlation score is greater than the first threshold and less than the second threshold, it means that the first reply information has a low correlation with the first background information in the above-mentioned external data, and then the second prompt information is generated according to the above-mentioned first reply information and the above-mentioned first background information, and the second prompt information is input into the large language model to output the answer to the target question; if the server determines that the correlation score is greater than or equal to the second threshold, it means that the first reply information has a high correlation with the first background information in the above-mentioned external data, and the first reply information is used as the answer to the target question.
[0129] If the server determines that the correlation score is less than or equal to the first threshold, it means that the first reply information has a low correlation with the first background information in the external data, and then the server returns to execute steps S201-S212 to redetermine the answer to the target question.
[0130] The knowledge question and answer processing method provided in the embodiment of the present application uses the first feature vector of the target question to search in the external data to obtain the second background information, and based on the second background information and the preset large language model, obtain the first reply information, and then based on the second feature vector of the first reply information, search again in the external data to obtain the first background information with richer background information, and finally determine the relevance score based on the first keyword of the first reply information and the second keyword of the first background information to obtain the answer to the target question. In this way, the server can search again in the external data based on the first reply information to obtain the first background information with richer background information, and accurately determine the relevance score, and determine whether it is necessary to supplement the background information that the large language model is not aware of based on the relevance score, to ensure that the answer is highly correlated with the external data, and to improve the accuracy of the knowledge question and answer based on the external data.
[0131] Figure 4 A schematic diagram of the structure of the knowledge question answering processing device provided in this application, such as Figure 4 As shown, the knowledge question answering processing device 30 provided in this embodiment includes:
[0132] An acquisition module 31 is used to acquire a target question and external data corresponding to the target question; wherein the external data corresponding to the target question is used to indicate an answer to the target question;
[0133] A generating module 32, configured to generate first reply information based on the target question, external data corresponding to the target question, and a preset large language model;
[0134] A retrieval module 33, configured to retrieve the first reply information based on the external data corresponding to the target question to obtain first background information;
[0135] A first determination module 34, configured to determine a relevance score according to the first reply information and the first background information; wherein the relevance score is used to describe the degree of relevance between the first reply information and the first background information;
[0136] The second determination module 35 is used to determine the answer to the target question according to the relevance score.
[0137] In some possible implementations, the second determination module 35 is specifically used to generate second prompt information based on the first reply information and the first background information if it is determined that the relevance score is greater than the first threshold and less than the second threshold, and input the second prompt information into the large language model to output the answer to the target question; if it is determined that the relevance score is greater than or equal to the second threshold, use the first reply information as the answer to the target question.
[0138] In some possible implementations, the second determination module 35 is specifically used to re-execute the steps of generating a first reply message based on the target question, external data corresponding to the target question, and a preset large language model if it is determined that the relevance score is less than or equal to a first threshold; retrieving the first reply message based on the external data corresponding to the target question to obtain first background information; determining a relevance score based on the first reply message and the first background information; and determining an answer to the target question based on the relevance score.
[0139] In some possible implementations, the first determination module 34 is specifically configured to determine a first keyword set according to the first reply information; wherein the first keyword set includes M first keywords in the first reply information; M is an integer greater than or equal to 1;
[0140] Determine a second keyword set according to the first background information; wherein the second keyword set includes N second keywords in the first background information; N is an integer greater than or equal to 1;
[0141] A relevance score is determined based on the first keyword set and the second keyword set.
[0142] In some possible implementations, the first determination module 34 is specifically used to determine, for the ith first keyword in the first keyword set, a similarity value between the ith first keyword and the second keyword in the second keyword set; wherein i is an integer greater than or equal to 1 and less than or equal to M; if it is determined that there is a second keyword whose similarity value is greater than or equal to a preset threshold, the ith first keyword is determined to be a marked first keyword; and the value of i is determined to be plus one; until it is determined that the value of i is greater than M, the number of marked first keywords in the first keyword set is determined; if it is determined that there is no second keyword whose similarity value is greater than or equal to the preset threshold, the value of i is determined to be plus one; until it is determined that the value of i is greater than M, the number of marked first keywords in the first keyword set is determined; the quotient of the number of marked first keywords and the number N of second keywords in the second keyword set is determined as the correlation score.
[0143] In some possible implementations, the generation module 32 is specifically used to determine a first feature vector of the target question based on the target question; based on the first feature vector, search in external data corresponding to the target question to obtain second background information; concatenate the second background information and the target question to obtain first prompt information; input the first prompt information into a preset large language model to obtain first reply information.
[0144] In some possible implementations, the external data corresponding to the target question includes multiple partitions; each partition includes background information of a preset length; the partition has a third feature vector; the retrieval module 33 is specifically used to determine the second feature vector of the first reply information based on the first reply information; determine the partition corresponding to the second feature vector based on the second feature vector and the third feature vector; and obtain the first background information based on the partition corresponding to the second feature vector.
[0145] The knowledge question and answer processing device provided in this embodiment can execute the method provided in the above method embodiment. Its implementation principle and technical effect are similar, and this embodiment will not be described in detail here.
[0146] Figure 5 This is a schematic diagram of the structure of the electronic device provided in this application. Figure 5 As shown, the electronic device 40 provided in this embodiment includes: at least one processor 401 and a memory 402. Optionally, the device 40 also includes a communication component 403. The processor 401, the memory 402 and the communication component 403 are connected via a bus 404.
[0147] In a specific implementation process, at least one processor 401 executes the computer-executable instructions stored in the memory 402, so that at least one processor 401 executes the above method.
[0148] The specific implementation process of the processor 401 can be found in the above method embodiment, and its implementation principle and technical effect are similar, so this embodiment will not be repeated here.
[0149] In the above embodiments, it should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the invention may be directly implemented as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.
[0150] The memory may include a high-speed memory (Random Access Memory, RAM), and may also include a non-volatile memory (Non-volatile Memory, NVM), such as at least one disk memory.
[0151] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.
[0152] The present application also provides a computer program product, including a computer program, which implements the above method when executed by a processor.
[0153] The present application also provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, the above method is implemented.
[0154] The above-mentioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The readable storage medium can be any available medium that can be accessed by a general or special-purpose computer.
[0155] An exemplary readable storage medium is coupled to a processor so that the processor can read information from the readable storage medium and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can be located in an application specific integrated circuit (Application Specific Integrated Circuits, referred to as: ASIC). Of course, the processor and the readable storage medium can also exist in the device as discrete components.
[0156] The division of units is only a logical function division, and there may be other divisions in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interface, device or unit, which can be electrical, mechanical or other forms.
[0157] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0158] In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0159] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to perform all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0160] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0161] Finally, it should be noted that those skilled in the art will readily conceive of other embodiments of the present invention after considering the specification and practicing the invention disclosed herein. The present invention is intended to cover any variations, uses or adaptations of the present invention, which follow the general principles of the present invention and include common knowledge or customary technical means in the art not disclosed by the present invention, are not limited to the precise structure described above and shown in the drawings, and may be modified and changed in various ways without departing from the scope thereof. The scope of the present invention is limited only by the appended claims.
Claims
1. A knowledge question answering method, characterized in that: The method comprises: Acquire a target question and external data corresponding to the target question; wherein the external data corresponding to the target question is used to indicate an answer to the target question; Generate first reply information based on the target question, external data corresponding to the target question, and a preset large language model; Based on the external data corresponding to the target question, the first reply information is searched to obtain first background information; Determine a relevance score according to the first reply information and the first background information; wherein the relevance score is used to describe the relevance degree between the first reply information and the first background information; An answer to the target question is determined based on the relevance score.
2. The method according to claim 1, characterized in that: Determining the answer to the target question according to the relevance score includes: If it is determined that the relevance score is greater than a first threshold and less than a second threshold, generating second prompt information according to the first reply information and the first background information, inputting the second prompt information into the large language model, and outputting an answer to the target question; If it is determined that the relevance score is greater than or equal to the second threshold, the first reply information is used as the answer to the target question.
3. The method according to claim 2, characterized in that The method further comprises: If it is determined that the relevance score is less than or equal to the first threshold, the steps of generating a first reply message based on the target question, external data corresponding to the target question and a preset large language model are re-executed; the first reply message is retrieved based on the external data corresponding to the target question to obtain first background information; the relevance score is determined based on the first reply message and the first background information; and the answer to the target question is determined based on the relevance score.
4. The method according to claim 1, characterized in that: Determining a relevance score according to the first reply information and the first background information includes: Determine a first keyword set according to the first reply information; wherein the first keyword set includes M first keywords in the first reply information; M is an integer greater than or equal to 1; Determine a second keyword set according to the first background information; wherein the second keyword set includes N second keywords in the first background information; N is an integer greater than or equal to 1; A relevance score is determined based on the first keyword set and the second keyword set.
5. The method according to claim 4, characterized in that Determining a relevance score according to the first keyword set and the second keyword set includes: For the i-th first keyword in the first keyword set, determine a similarity value between the i-th first keyword and a second keyword in the second keyword set; wherein i is an integer greater than or equal to 1 and less than or equal to M; If it is determined that there is a second keyword whose similarity value is greater than or equal to the preset threshold, determine the i-th first keyword as the marked first keyword; and determine that the value of i is increased by one; until it is determined that the value of i is greater than M, determine the number of marked first keywords in the first keyword set; If it is determined that there is no second keyword whose similarity value is greater than or equal to the preset threshold, the value of i is determined to be increased by one; until it is determined that the value of i is greater than M, the number of marked first keywords in the first keyword set is determined; The quotient of the number of the marked first keywords and the number N of the second keywords in the second keyword set is determined as the relevance score.
6. The method according to claim 1, characterized in that Based on the target question, external data corresponding to the target question, and a preset large language model, generating first reply information includes: According to the target problem, determining a first eigenvector of the target problem; According to the first feature vector, searching in the external data corresponding to the target question to obtain second background information; The second background information and the target question are combined to obtain first prompt information; The first prompt information is input into a preset large language model to obtain first reply information.
7. The method according to any one of claims 1 to 6, characterized in that: The external data corresponding to the target problem includes multiple partitions; each partition includes background information of a preset length; The partition has a third eigenvector; Based on the external data corresponding to the target question, the first reply information is retrieved to obtain first background information, including: Determining a second feature vector of the first reply information according to the first reply information; Determine a partition corresponding to the second eigenvector according to the second eigenvector and the third eigenvector; The first background information is obtained according to the partition corresponding to the second feature vector.
8. A knowledge question answering processing device, characterized in that: The device comprises: An acquisition module, used to acquire a target question and external data corresponding to the target question; wherein the external data corresponding to the target question is used to indicate an answer to the target question; A generation module, configured to generate first reply information based on the target question, external data corresponding to the target question, and a preset large language model; A retrieval module, configured to retrieve the first reply information based on external data corresponding to the target question to obtain first background information; A first determination module, configured to determine a relevance score according to the first reply information and the first background information; wherein the relevance score is used to describe the relevance between the first reply information and the first background information; The second determination module is used to determine the answer to the target question according to the relevance score.
9. An electronic device, characterized in that: include: Memory, processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory, so that the processor performs the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 7 when executed by a processor.
Citation Information
Patent Citations
Information output method and device, electronic equipment and storage medium
CN111581336A
Model generation method and device, conversation generation method and device and electronic equipment
CN115238052A
Retrieval method and device of knowledge base and storage medium
CN116756295A
Question and answer model-based answer generation method and device, electronic equipment and storage medium
CN117648982A
Knowledge enhancement-based large model question and answer method, apparatus and device, and medium
CN117669717A
Cited By
User request processing method, user request processing device and computing device cluster
CN120670462A
