Query method, device and storage medium for reply content
By using vector representation and iterative computation, the problem of low accuracy in matching answers to predefined templates was solved, enabling accurate determination of answers to complex question-and-answer problems within knowledge graphs.
Patent Information
- Application Number
- CN202310436904.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-21
- Publication Date
- 2026-02-10
- Estimated Expiration
- 2043-04-21
AI Technical Summary
Existing methods that match answers using predefined templates have low accuracy when dealing with complex question-and-answer questions and cannot accurately determine the answers to questions involving multiple layers of relationships.
The system uses vectors to represent user questions and text information in a knowledge graph. It iteratively calculates relevance, uses a weighted sum of candidate text vectors to update the question vector, and continues this process until the number of iterations reaches a preset value. Finally, it reverses the process to obtain the answer.
Through multiple iterative calculations, the answers to questions in the knowledge graph are accurately determined, thus improving the accuracy of the answers.
Smart Images

Figure CN116414963B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence, and more specifically, to a method, apparatus, and storage medium for querying response content. Background Technology
[0002] KBQA (Knowledge Base Question Answering) is an intelligent question-answering method based on a structured knowledge base. The financial industry, due to its high correlation with data, is a field where knowledge graph technology is deeply applied. As financial institutions expand their businesses and increase their user base, the demand for question-answering services is rising sharply, while customer service labor costs are also gradually increasing. Therefore, knowledge graph question-answering systems are widely used to provide users with deeper information analysis and mining capabilities.
[0003] However, the current process for handling questions typically involves parsing natural language and matching the results with predefined templates to determine the answer through simple KBQA. But in real-world scenarios, users sometimes tend to express complex question-and-answer reasoning questions, such as multi-hop questions containing multiple relationships or entities: "Which branches in District T of City A are open on Saturdays?" In such cases, using predefined template matching to determine the answer is inaccurate because the question contains multiple layers of relationships, thus affecting the accuracy of customer service staff's work.
[0004] There is currently no effective solution to the problem of low accuracy in matching answers using predefined templates in related technologies. Summary of the Invention
[0005] This application provides a method, apparatus, and storage medium for querying response content, in order to solve the problem of low accuracy in related technologies that use predefined templates to match answers.
[0006] According to one aspect of this application, a method for querying response content is provided. The method includes: acquiring text information of a target question and converting the text information into a vector to obtain an initial text vector; searching for multiple candidate text information associated with the text information in a knowledge base and acquiring a vector for each candidate text information to obtain multiple candidate text vectors; calculating the relevance between the initial text vector and each candidate text vector to obtain multiple relevance scores; performing a weighted summation of the multiple relevance scores and their corresponding candidate text vectors to obtain a target text vector, and adding the target text vector to the initial text vector to obtain an updated initial text vector; iteratively performing the steps of calculating the relevance between the initial text vector and each candidate text vector to obtain multiple relevance scores, and performing a weighted summation of the multiple relevance scores and their corresponding candidate text vectors to obtain a target text vector, and adding the target text vector to the initial text vector to obtain an updated initial text vector, until the number of iterations reaches a preset value; and when the number of iterations reaches the preset value, converting the current initial text vector into text information to obtain the response content of the target question.
[0007] Optionally, converting text information into vectors to obtain an initial text vector includes: identifying each character in the text information to obtain multiple characters; obtaining the encoding vector corresponding to each character from the dictionary to obtain multiple encoding vectors; and combining the multiple encoding vectors according to the order of the multiple characters in the text information to obtain the initial text vector.
[0008] Optionally, the knowledge base stores multiple preset text information, which includes keywords. Searching for multiple candidate text information associated with the text information in the knowledge base includes: segmenting the text information into words to obtain multiple words; inputting each word into the knowledge base for querying to obtain multiple sets of query results, where each set of query results includes multiple preset text information, and the keyword in each preset text information is the same as any one of the multiple words; obtaining all preset text information from the multiple sets of query results, and deduplicating all preset text information to obtain multiple candidate text information associated with the text information.
[0009] Optionally, the preset text information includes keywords and key values, the key values include tail entities, and the keywords include head entities and relationships. Before inputting each word into the knowledge base for querying and obtaining multiple sets of query results, the method further includes: swapping the head entities and tail entities in each preset text information to obtain multiple first text information; adding the multiple first text information to the knowledge base to obtain an updated knowledge base; and performing the step of inputting each word into the knowledge base for querying and obtaining multiple sets of query results based on the updated knowledge base.
[0010] Optionally, the candidate text vectors include keyword vectors. The relevance between the initial text vector and each candidate text vector is calculated to obtain multiple relevances, including: multiplying the initial text vector by a first preset matrix to obtain a first matrix; multiplying each keyword vector by the first preset matrix to obtain multiple second matrices; grouping each first matrix and multiple second matrices into a group to obtain multiple groups of matrices; and substituting each group of matrices into a first function to obtain multiple relevances, wherein the first function is a normalized exponential function.
[0011] Optionally, the candidate text vector includes a key value vector. The target text vector is obtained by weighted summation of multiple relevance values with the corresponding candidate text vectors, including: multiplying each key value vector with a second preset matrix to obtain multiple third matrices; determining the relevance corresponding to each third matrix based on the association between the key value vector and the keyword vector, and multiplying each third matrix with the corresponding relevance to obtain multiple fourth matrices; and adding the multiple fourth matrices to obtain the target text vector.
[0012] Optionally, before acquiring the text information of the target question and converting it into a vector to obtain an initial text vector, the method further includes: acquiring first sample text information of the sample question and converting it into a vector to obtain a first sample text vector; searching for multiple second sample text information related to the first sample text information in the knowledge base and acquiring the vector of each second sample text information to obtain multiple second sample text vectors; calculating the correlation between the first sample text vector and each second sample text vector to obtain multiple sample correlations; weighting and summing the multiple sample correlations with the corresponding second sample text vectors to obtain a third sample text vector, and then combining the first sample text vector with the third sample text vector. The first sample text vector is obtained by adding the first sample text vectors together. The correlation between the first sample text vector and each second sample text vector is calculated iteratively using the updated first sample text vector to obtain multiple sample correlations. The multiple sample correlations are then weighted and summed with the corresponding second sample text vectors to obtain a third sample text vector. The first sample text vector is then added to the third sample text vector to obtain the updated first sample text vector. This process continues until the number of iterations reaches a preset value. When the number of iterations reaches the preset value, the current first sample text vector is input into a third function for calculation to obtain the sample results. Based on the sample results, the first preset matrix and the second preset matrix are determined.
[0013] Optionally, determining the first and second preset matrices based on the sample results includes: determining whether the sample results are preset results associated with the sample problem; if the sample results are not preset results, changing the first and second initial matrices to obtain updated first and second initial matrices, and redetermining the sample results based on the updated first and second initial matrices until the sample results are preset results; if the sample results are preset results, determining the first initial matrix at the current time as the first preset matrix, and determining the second initial matrix at the current time as the second preset matrix.
[0014] According to another aspect of this application, a query device for answer content is provided. The device includes: a first acquisition unit, configured to acquire text information of a target question and convert the text information into a vector to obtain an initial text vector; a first search unit, configured to search for multiple candidate text information associated with the text information in a knowledge base and acquire a vector of each candidate text information to obtain multiple candidate text vectors; a first calculation unit, configured to calculate the relevance between the initial text vector and each candidate text vector to obtain multiple relevances; a second calculation unit, configured to perform a weighted summation of the multiple relevances with the corresponding candidate text vectors to obtain a target text vector, and add the target text vector to the initial text vector to obtain an updated initial text vector; a first iteration unit, configured to iteratively execute the steps of calculating the relevance between the initial text vector and each candidate text vector to obtain multiple relevances, and the steps of performing a weighted summation of the multiple relevances with the corresponding candidate text vectors to obtain a target text vector, and adding the target text vector to the initial text vector to obtain an updated initial text vector, until the number of iterations reaches a preset value; and a conversion unit, configured to convert the current initial text vector into text information to obtain the answer content of the target question when the number of iterations reaches the preset value.
[0015] According to another aspect of the present invention, a computer storage medium is also provided for storing a program, wherein the program, when running, controls the device where the computer storage medium is located to execute a query method for reply content.
[0016] According to another aspect of the present invention, an electronic device is also provided, comprising one or more processors and a memory; the memory stores computer-readable instructions, and the processor is configured to execute the computer-readable instructions, wherein the computer-readable instructions, when executed, perform a query method for responding to content.
[0017] This application employs the following steps: obtaining text information of the target question and converting it into a vector to obtain an initial text vector; searching for multiple candidate text information associated with the text information in a knowledge base and obtaining a vector for each candidate text information to obtain multiple candidate text vectors; calculating the relevance between the initial text vector and each candidate text vector to obtain multiple relevance scores; weighted summing of the multiple relevance scores with the corresponding candidate text vectors to obtain the target text vector, and adding the target text vector to the initial text vector to obtain an updated initial text vector; iteratively performing the steps of calculating the relevance between the initial text vector and each candidate text vector to obtain multiple relevance scores, and weighted summing of the multiple relevance scores with the corresponding candidate text vectors to obtain the target text vector, and adding the target text vector to the initial text vector to obtain an updated initial text vector, until the number of iterations reaches a preset value; when the number of iterations reaches the preset value, converting the current initial text vector into text information to obtain the answer to the target question. This solves the problem of low accuracy in related technologies that use predefined templates to match answers. First, vectors are used to represent user questions and multiple textual pieces of information in the knowledge graph. Textual information is retrieved from the knowledge graph based on the user question, resulting in candidate text vectors, which serve as key-value memory slots. Then, a relevance score between each candidate text vector and the question is calculated. The candidate text vectors are then weighted and summed based on their scores. Finally, the question vector is updated using the resulting vector values. After these N iterations, the question vector is reverse-transformed to obtain the textual information, which is then identified as the answer to the question. This achieves the goal of accurately determining the answer to a question within the knowledge graph through multiple iterations of computation. Attached Figure Description
[0018] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:
[0019] Figure 1 This is a flowchart of a query method for the response content provided in the embodiments of this application;
[0020] Figure 2 This is a flowchart of a vector conversion method provided according to an embodiment of this application;
[0021] Figure 3 This is a schematic diagram of a query device for the response content provided in the embodiments of this application;
[0022] Figure 4 This is a schematic diagram of an electronic device provided according to an embodiment of this application. Detailed Implementation
[0023] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0024] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0025] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0026] It should be noted that all information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for display, data used for analysis, etc.) involved in this disclosure are information and data authorized by the user or fully authorized by all parties. For example, this system has an interface with relevant users or organizations. Before obtaining relevant information, it is necessary to send an acquisition request to the aforementioned user or organization through the interface, and obtain the relevant information after receiving consent information from the aforementioned user or organization.
[0027] It should be noted that the query methods, devices, and storage media for the response content determined in this disclosure can be used in the field of artificial intelligence, or in any field other than artificial intelligence. The application fields of the query methods, devices, and storage media for the response content determined in this disclosure are not limited.
[0028] According to an embodiment of this application, a method for querying response content is provided.
[0029] Figure 1 This is a flowchart of a query method for the response content provided in an embodiment of this application. For example... Figure 1 As shown, the method includes the following steps:
[0030] Step S101: Obtain the text information of the target question and convert the text information into a vector to obtain the initial text vector.
[0031] Specifically, after obtaining the text information of the target question, the text information of the target question can be encoded according to the bag-of-words model to obtain a vector or vector matrix, and the vector or vector matrix can be determined as the initial text vector.
[0032] It's important to note that the bag-of-words model assumes that for a text, word order, syntax, and grammar are ignored, and it is simply viewed as a collection of words, where each word is independent. In short, each document is considered a bag containing words, hence the name "bag of words." All the words form a dictionary, and we can map the text to a vector. The length of the vector is the size of the dictionary, each row represents a word in the dictionary, and each bit in the row vector represents the word's position in the dictionary.
[0033] For example, suppose the text of the question is: “Who am I”, then the bag of words consists of these 3 Chinese characters, and there are 10 words in the dictionary. Then “Who am I” can be encoded as: [[1 0 0 0 0 0 0 0 0 0]、[0 1 0 0 0 0 0 000]、[0 0 1 0 0 0 0 0 0 0]], thus obtaining the initial text vector.
[0034] Step S102: Search for multiple candidate text information associated with the text information in the knowledge base, and obtain the vector of each candidate text information to obtain multiple candidate text vectors.
[0035] Specifically, when querying candidate text information, one can determine the content duplication of each text in the knowledge base with the text information of the target question, and determine whether to identify a certain text in the knowledge base as candidate text information based on the content duplication.
[0036] For example, the textual repetition between the textual information of the target question and each text in the knowledge base can be determined, and texts with a textual repetition greater than 60% can be identified as candidate textual information.
[0037] It should be noted that the method used to convert candidate text information into candidate text vectors is also the bag-of-words method described above. Each candidate text information consists of a triple (Subject, Predicate, Object), where the Subject and Predicate of each triple are the key, and the Object is the value. For question x, M key-value pairs are selected from the knowledge base as memory slots, resulting in: (k1, v1), (k2, v2), (k3, v3), ..., (kM ,v M ).
[0038] Step S103: Calculate the correlation between the initial text vector and each candidate text vector to obtain multiple correlation scores.
[0039] Specifically, when calculating relevance, it is necessary to calculate the key in the initial text vector and the candidate text vector to obtain the relevance between the initial text vector and the candidate text vector.
[0040] Step S104: The multiple relevance values are weighted and summed with the corresponding candidate text vectors to obtain the target text vector. The target text vector is then added to the initial text vector to obtain the updated initial text vector.
[0041] Specifically, after obtaining the relevance scores, each relevance score needs to be multiplied by the value in the corresponding candidate text vector, and the multiple products are summed to obtain the target text vector. Here, the relevance score is also the weight in the weighted summation. The resulting target text vector is also the updated initial text vector.
[0042] Step S105 involves iteratively calculating the correlation between the updated initial text vector and each candidate text vector to obtain multiple correlations, and then weighting and summing the multiple correlations with the corresponding candidate text vectors to obtain the target text vector. Finally, the target text vector is added to the initial text vector to obtain the updated initial text vector. This process continues until the number of iterations reaches a preset value.
[0043] Specifically, after obtaining the updated initial text vector, the representation has completed one iteration update of the initial text vector. At this point, it is necessary to repeat the above iteration process multiple times based on the current initial text vector until the number of iterations reaches the preset number.
[0044] Step S106: When the number of iterations reaches a preset value, the current initial text vector is converted into text information to obtain the answer to the target question.
[0045] Specifically, after obtaining the preset number of attempts, the current initial text vector can be processed through the output layer parameter matrix, that is, input into Formula 5, to obtain the probability value between it and each answer. The higher the probability, the closer it is to the required question and answer. Therefore, after inputting the current initial text vector into Formula 5, the probability value 'a' between the initial text vector and each answer is calculated through Formula 5. Thus, the candidate answer corresponding to the maximum output value obtained by the argmax function is determined as the answer to the target question, thereby achieving the effect of accurately determining the answer to the target question.
[0046] The method for querying response content provided in this application involves: acquiring the text information of the target question and converting it into a vector to obtain an initial text vector; searching for multiple candidate text information associated with the text information in a knowledge base and obtaining the vector of each candidate text information to obtain multiple candidate text vectors; calculating the relevance between the initial text vector and each candidate text vector to obtain multiple relevance scores; weighted summing of the multiple relevance scores with the corresponding candidate text vectors to obtain the target text vector, and adding the target text vector to the initial text vector to obtain an updated initial text vector; iteratively performing the steps of calculating the relevance between the initial text vector and each candidate text vector to obtain multiple relevance scores, and weighted summing of the multiple relevance scores with the corresponding candidate text vectors to obtain the target text vector, and adding the target text vector to the initial text vector to obtain an updated initial text vector, until the number of iterations reaches a preset value; when the number of iterations reaches the preset value, converting the current initial text vector into text information to obtain the response content of the target question. This solves the problem of low accuracy in related technologies that use predefined templates to match answers. First, vectors are used to represent user questions and multiple textual pieces of information in the knowledge graph. Textual information is retrieved from the knowledge graph based on the user question, resulting in candidate text vectors, which serve as key-value memory slots. Then, a relevance score between each candidate text vector and the question is calculated. The candidate text vectors are then weighted and summed based on their scores. Finally, the question vector is updated using the resulting vector values. After these N iterations, the question vector is reverse-transformed to obtain the textual information, which is then identified as the answer to the question. This achieves the goal of accurately determining the answer to a question within the knowledge graph through multiple iterations of computation.
[0047] Optionally, Figure 2 This is a flowchart of a vector conversion method provided according to an embodiment of this application, such as... Figure 2 As shown, in the query method for response content provided in this application embodiment, step S101, converting text information into a vector to obtain an initial text vector, includes:
[0048] Step S201: Identify each character in the text information to obtain multiple characters; Step S202: Obtain the encoding vector corresponding to each character from the dictionary to obtain multiple encoding vectors; Step S203: Combine the multiple encoding vectors according to the order of the multiple characters in the text information to obtain the initial text vector.
[0049] Specifically, when generating the initial text vector, the text information of the target question can be encoded according to the bag-of-words model to obtain a vector or vector matrix, and this vector or vector matrix can be determined as the initial text vector.
[0050] It's important to note that the bag-of-words model assumes that for a text, word order, syntax, and grammar are ignored, and it is simply viewed as a collection of words, where each word is independent. In short, each document is considered a bag containing words, hence the name "bag of words." All the words form a dictionary, and we can map the text to a vector. The length of the vector is the size of the dictionary, each row represents a word in the dictionary, and each bit in the row vector represents the word's position in the dictionary.
[0051] For example, suppose the text of the question is: “Who am I”, then the bag of words consists of these 3 Chinese characters, and there are 10 words in the dictionary. Then “Who am I” can be encoded as: [[1 0 0 0 0 0 0 0 0 0]、[0 1 0 0 0 0 0 000]、[0 0 1 0 0 0 0 0 0 0]], thus obtaining the initial text vector.
[0052] Optionally, in the query method for response content provided in this application embodiment, the knowledge base stores multiple preset text information, which includes keywords. Searching for multiple candidate text information associated with the text information in the knowledge base includes: segmenting the text information into words to obtain multiple words; inputting each word into the knowledge base for querying to obtain multiple sets of query results, wherein each set of query results includes multiple preset text information, and the keywords in each preset text information are the same as any one of the multiple words; obtaining all preset text information from the multiple sets of query results, and deduplicating all preset text information to obtain multiple candidate text information associated with the text information.
[0053] Specifically, when determining candidate text information, the question text information can first be segmented into multiple words. Then, each word is searched in the knowledge base to obtain multiple sets of preset text information. In each set of preset text information, the keywords contain one of these words. For example, after segmenting the text information, if the two words are "weather" and "sunny," then in the two sets of preset text information, each candidate text information in one set will contain the word "weather," and each candidate text information in the other set will contain the word "sunny," thus obtaining multiple sets of candidate text information.
[0054] Furthermore, after obtaining multiple sets of preset text information, since there may be duplicate candidate text information in the multiple sets of preset text information, it is necessary to remove duplicates to obtain multiple candidate text information associated with the text information.
[0055] Optionally, in the query method for response content provided in the embodiments of this application, the preset text information includes keywords and key values, the key values include tail entities, and the keywords include head entities and relationships. Before inputting each word into the knowledge base for querying and obtaining multiple sets of query results, the method further includes: swapping the head entities and tail entities in each preset text information to obtain multiple first text information; adding the multiple first text information to the knowledge base to obtain an updated knowledge base; and performing the step of inputting each word into the knowledge base for querying and obtaining multiple sets of query results based on the updated knowledge base.
[0056] Specifically, in order to expand the amount of candidate text information, the head entity Subject and the tail entity Object of each preset text information in the knowledge base can be interchanged to obtain new preset text information with the same number of texts as the original knowledge base. A large number of new preset text information are then added to the knowledge base, doubling the text data in the knowledge base and further improving the accuracy of answer query.
[0057] Optionally, in the query method for response content provided in the embodiments of this application, the candidate text vector includes a keyword vector. Calculating the relevance between the initial text vector and each candidate text vector to obtain multiple relevances includes: multiplying the initial text vector by a first preset matrix to obtain a first matrix; multiplying each keyword vector by the first preset matrix to obtain multiple second matrices; grouping each first matrix and multiple second matrices into a group to obtain multiple groups of matrices; and substituting each group of matrices into a first function to obtain multiple relevances, wherein the first function is a normalized exponential function.
[0058] Specifically, the relevance between the initial text vector and each candidate text vector can be calculated using Formula 1:
[0059] p i =Softmax(AФ X (x)·AФ K (k i (1)
[0060] Where, p i Let Φ be the relevance between the i-th candidate text vector and the initial text vector, where Φ is the relevance between the i-th candidate text vector and the initial text vector. X and Ф K These are D-dimensional vector matrices of x and key, respectively, and k i Let A be the keyword vector of the i-th candidate text vector, and let A be a d×D embedding matrix, which is also the first preset matrix. The softmax function is also the normalization exponential function.
[0061] Optionally, in the query method for response content provided in the embodiments of this application, the candidate text vector includes a key value vector. The method for obtaining the target text vector by weighted summation of multiple relevance values with the corresponding candidate text vectors includes: multiplying each key value vector by a second preset matrix to obtain multiple third matrices; determining the relevance corresponding to each third matrix based on the association between the key value vector and the keyword vector, and multiplying each third matrix by the corresponding relevance value to obtain multiple fourth matrices; and adding the multiple fourth matrices to obtain the target text vector.
[0062] Specifically, after calculating the i relevance scores, a weighted sum can be performed using Formula 2 to obtain the target text vector:
[0063] o = ∑ i p i BФ V (v i (2)
[0064] Where o is the target text vector, Ф V (v i Let A be a D-dimensional vector matrix containing the key value vectors of the i-th candidate text vector, and let B be a d×D embedding matrix that can be the same as or different from matrix A.
[0065] It should be noted that after calculating the target text vector, the representation has completed one iteration update of the initial text vector. At this point, before repeating the above iteration process multiple times based on the current initial text vector, it is necessary to update the target text vector using Formula 3 to obtain the updated target text vector, and then redetermine the correlation between the updated target text vector and multiple candidate text vectors. Formula 3 is shown below:
[0066] q i+1 =R i *(q i +o i (3)
[0067] Where, q i For the i-th relevance in the previous iteration period, o i Let R be the target text vector calculated at the end of the previous iteration cycle, and q be a random d×d matrix. i+1 This is the initial text vector for the current iteration cycle.
[0068] After obtaining q i+1 After that, q needs to be... i+1 Perform transpose calculation to obtain And The updated target text vector is used to calculate the new relevance. At this time, the relevance calculation formula in the new iteration cycle is as shown in Formula 4:
[0069]
[0070] Optionally, in the query method for the response content provided in this application embodiment, before obtaining the text information of the target question and converting the text information into a vector to obtain an initial text vector, the method further includes: obtaining first sample text information of the sample question and converting the first sample text information into a vector to obtain a first sample text vector; searching for multiple second sample text information associated with the first sample text information in the knowledge base and obtaining the vector of each second sample text information to obtain multiple second sample text vectors; calculating the relevance between the first sample text vector and each second sample text vector to obtain multiple sample relevances; and performing a weighted summation of the multiple sample relevances and the corresponding second sample text vectors to obtain a third sample text vector, and then converting the first sample text information into a vector. The text vector is added to the third sample text vector to obtain the updated first sample text vector. The correlation between the first sample text vector and each second sample text vector is calculated iteratively using the updated first sample text vector to obtain multiple sample correlations. The multiple sample correlations are then weighted and summed with the corresponding second sample text vectors to obtain the third sample text vector. The first sample text vector is then added to the third sample text vector to obtain the updated first sample text vector. This process continues until the number of iterations reaches a preset value. When the number of iterations reaches the preset value, the current first sample text vector is input into a third function for calculation to obtain the sample result. Based on the sample result, the first preset matrix and the second preset matrix are determined.
[0071] Specifically, before querying the answer to the question, it is necessary to determine the first and second preset matrices in the above process. Therefore, the above process needs to be executed through sample text information until the number of iterations reaches the preset value. At this time, the first sample text vector calculated based on the sample text information will be obtained. After obtaining the first sample text vector, it is necessary to calculate the current first sample text vector according to the third function to determine whether the current first sample text vector is correct, and determine whether the first and second preset matrices used in this calculation are usable matrices based on the calculation results.
[0072] It should be noted that the calculation of the current first sample text vector can be performed using Formula 5, as shown below:
[0073]
[0074] in, Let C be the transpose of the current first sample text vector, and let Ф be a random d×d matrix. Y (y i Let be any answer entity in the answer set, a be the probability value between each answer entity and the current first sample text vector, and argmax be the maximum value of the point set function.
[0075] Optionally, in the query method for the response content provided in this application embodiment, determining the first preset matrix and the second preset matrix based on the sample result includes: determining whether the sample result is a preset result associated with the sample question; if the sample result is not a preset result, changing the first initial matrix and the second initial matrix to obtain an updated first initial matrix and an updated second initial matrix, and re-determining the sample result based on the updated first initial matrix and the updated second initial matrix until the sample result is a preset result; if the sample result is a preset result, determining the first initial matrix at the current time as the first preset matrix, and determining the second initial matrix at the current time as the second preset matrix.
[0076] Specifically, after obtaining multiple probability values, the answer entity with the highest probability value can be identified as the sample result of the target question. It is then determined whether the sample result is the preset result corresponding to the target question. If the sample result is the preset result, the first initial matrix at the current time is determined as the first preset matrix, and the second initial matrix at the current time is determined as the second preset matrix. If the sample result is not the preset result, it indicates that the first and second preset matrices have not reached their optimal values. In this case, the first and second preset matrices at the current time need to be changed and recalculated until the sample result is the same as the preset result.
[0077] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.
[0078] This application also provides a device for querying response content. It should be noted that this device can be used to execute the response content querying method provided in this application. The response content querying device provided in this application is described below.
[0079] Figure 3 This is a schematic diagram of a query device for the response content provided according to an embodiment of this application. For example... Figure 3As shown, the device includes: a first acquisition unit 31, a first search unit 32, a first calculation unit 33, a second calculation unit 34, a first iteration unit 35, and a conversion unit 36.
[0080] The first acquisition unit 31 is used to acquire text information of the target question and convert the text information into a vector to obtain an initial text vector;
[0081] The first search unit 32 is used to search for multiple candidate text information associated with the text information in the knowledge base, and obtain the vector of each candidate text information to obtain multiple candidate text vectors.
[0082] The first calculation unit 33 is used to calculate the correlation between the initial text vector and each candidate text vector to obtain multiple correlations.
[0083] The second calculation unit 34 is used to perform a weighted summation of multiple relevance values and corresponding candidate text vectors to obtain the target text vector, and to add the target text vector to the initial text vector to obtain the updated initial text vector;
[0084] The first iteration unit 35 is used to iteratively perform the steps of calculating the correlation between the initial text vector and each candidate text vector to obtain multiple correlations, and to perform a weighted summation of the multiple correlations with the corresponding candidate text vectors to obtain the target text vector, and to add the target text vector to the initial text vector to obtain the updated initial text vector, until the number of iterations reaches a preset value.
[0085] The conversion unit 36 is used to convert the current initial text vector into text information when the number of iterations reaches a preset value, so as to obtain the answer to the target question.
[0086] The query device for answer content provided in this application embodiment includes a first acquisition unit 31 for acquiring text information of the target question and converting the text information into a vector to obtain an initial text vector; a first search unit 32 for searching multiple candidate text information associated with the text information in a knowledge base and acquiring the vector of each candidate text information to obtain multiple candidate text vectors; a first calculation unit 33 for calculating the relevance between the initial text vector and each candidate text vector to obtain multiple relevances; and a second calculation unit 34 for weighted summation of the multiple relevances with the corresponding candidate text vectors to obtain the target text vector, and then converting the target text vector into a vector. The initial text vector is added to the updated initial text vector to obtain the updated initial text vector. The first iteration unit 35 iterates through the updated initial text vector, calculating the relevance between the initial text vector and each candidate text vector, obtaining multiple relevance scores, and then weighted summing these multiple relevance scores with the corresponding candidate text vectors to obtain the target text vector. The target text vector is then added to the initial text vector to obtain the updated initial text vector, until the number of iterations reaches a preset value. The conversion unit 36, when the number of iterations reaches the preset value, converts the current initial text vector into text information to obtain the answer to the target question. This solves the problem of low accuracy in related technologies that use predefined templates to match answers. First, vectors are used to represent user questions and multiple text information in the knowledge graph. Text information in the knowledge graph is retrieved through the user question to obtain candidate text vectors, which are used as key-value memory slots. Then, the relevance score between each candidate text vector and the question is calculated. The candidate text vectors are weighted and summed based on the score, and finally, the obtained vector value is used to update the question vector. After the above N iterations, the question vector is reverse-converted to obtain text information, which is then determined as the answer to the question. This achieves the effect of accurately determining the answer to a question within a knowledge graph through multiple iterations of computation.
[0087] Optionally, in the query device for the response content provided in the embodiments of this application, the first acquisition unit 31 includes: an identification module, used to identify each character in the text information to obtain multiple characters; a first acquisition module, used to obtain the encoding vector corresponding to each character from the dictionary to obtain multiple encoding vectors; and a combination module, used to combine the multiple encoding vectors according to the arrangement order of the multiple characters in the text information to obtain an initial text vector.
[0088] Optionally, in the query device for the response content provided in this application embodiment, the knowledge base stores multiple preset text information, which includes keywords. The first search unit 32 includes: a word segmentation module for segmenting the text information into multiple words; a query module for inputting each word into the knowledge base for querying to obtain multiple sets of query results, wherein each set of query results includes multiple preset text information, and the keyword in each preset text information is the same as any one of the multiple words; and a second acquisition module for acquiring all the preset text information in the multiple sets of query results and deduplicating all the preset text information to obtain multiple candidate text information associated with the text information.
[0089] Optionally, in the query device for response content provided in the embodiments of this application, the preset text information includes keywords and key values, the key values include tail entities, and the keywords include head entities and relationships. The device further includes: an exchange unit, used to exchange the head entities and tail entities in each preset text information to obtain multiple first text information; and an adding unit, used to add the multiple first text information to a knowledge base to obtain an updated knowledge base, and perform the step of inputting each word into the knowledge base for querying based on the updated knowledge base to obtain multiple sets of query results.
[0090] Optionally, in the query device for response content provided in the embodiments of this application, the candidate text vector includes a keyword vector, and the first calculation unit 33 includes: a first calculation module, used to multiply the initial text vector with a first preset matrix to obtain a first matrix; a second calculation module, used to multiply each keyword vector with the first preset matrix to obtain multiple second matrices; a grouping module, used to sequentially group each first matrix with multiple second matrices to obtain multiple groups of matrices; and a substitution module, used to sequentially substitute each group of matrices into a first function to obtain multiple relevances, wherein the first function is a normalized exponential function.
[0091] Optionally, in the query device for response content provided in this application embodiment, the candidate text vector includes a key value vector, and the second calculation unit 34 includes: a third calculation module, used to multiply each key value vector by a second preset matrix to obtain multiple third matrices; a first determination module, used to determine the relevance corresponding to each third matrix according to the association relationship between the key value vector and the keyword vector, and multiply each third matrix by the corresponding relevance to obtain multiple fourth matrices; and a fourth calculation module, used to add the multiple fourth matrices to obtain the target text vector.
[0092] Optionally, in the query device for response content provided in the embodiments of this application, the device further includes: a second acquisition unit, configured to acquire first sample text information of the sample question and convert the first sample text information into a vector to obtain a first sample text vector; a second search unit, configured to search for multiple second sample text information associated with the first sample text information in a knowledge base and acquire a vector of each second sample text information to obtain multiple second sample text vectors; a third calculation unit, configured to calculate the relevance between the first sample text vector and each second sample text vector to obtain multiple sample relevances; and a fourth calculation unit, configured to perform a weighted summation of the multiple sample relevances and the corresponding second sample text vectors to obtain a third sample text vector, and to sum the first sample text vector with the third sample text vector. The sample text vectors are added together to obtain the updated first sample text vector; the second iteration unit is used to iteratively perform the steps of calculating the correlation between the first sample text vector and each second sample text vector to obtain multiple sample correlations, and to perform a weighted sum of multiple sample correlations with the corresponding second sample text vectors to obtain a third sample text vector, and then add the first sample text vector and the third sample text vector to obtain the updated first sample text vector, until the number of iterations reaches a preset value; the determination unit is used to input the current first sample text vector into a third function for calculation when the number of iterations reaches the preset value, to obtain the sample result, and to determine the first preset matrix and the second preset matrix based on the sample result.
[0093] Optionally, in the query device for the response content provided in the embodiments of this application, the determining unit includes: a judging module, used to judge whether the sample result is a preset result associated with the sample question; a changing module, used to change the first initial matrix and the second initial matrix when the sample result is not a preset result, to obtain an updated first initial matrix and an updated second initial matrix, and to redetermine the sample result based on the updated first initial matrix and the updated second initial matrix, until the sample result is a preset result; and a second determining module, used to determine the first initial matrix at the current time as the first preset matrix and the second initial matrix at the current time as the second preset matrix when the sample result is a preset result.
[0094] The above-mentioned query device for the response content includes a processor and a memory. The first acquisition unit 31, the first search unit 32, the first calculation unit 33, the second calculation unit 34, the first iteration unit 35, the conversion unit 36, etc. are all stored in the memory as program units. The processor executes the above-mentioned program units stored in the memory to realize the corresponding functions.
[0095] The processor contains a kernel, which retrieves the corresponding program unit from memory. One or more kernels can be configured; adjusting kernel parameters addresses the low accuracy issue of matching answers using predefined templates in related technologies.
[0096] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0097] This invention provides a computer-readable storage medium storing a program thereon, which, when executed by a processor, implements a method for querying the response content.
[0098] This invention provides a processor for running a program, wherein the program executes a query method for the response content during runtime.
[0099] like Figure 4 As shown, this embodiment of the invention provides an electronic device 40, which includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs the following steps: acquiring text information of a target question and converting the text information into a vector to obtain an initial text vector; searching for multiple candidate text information associated with the text information in a knowledge base and acquiring the vector of each candidate text information to obtain multiple candidate text vectors; calculating the relevance between the initial text vector and each candidate text vector to obtain multiple relevances; performing a weighted sum of the multiple relevances and the corresponding candidate text vectors to obtain a target text vector, and adding the target text vector to the initial text vector to obtain an updated initial text vector; iteratively executing the steps of calculating the relevance between the initial text vector and each candidate text vector to obtain multiple relevances, and performing a weighted sum of the multiple relevances and the corresponding candidate text vectors to obtain a target text vector, and adding the target text vector to the initial text vector to obtain an updated initial text vector, until the number of iterations reaches a preset value; when the number of iterations reaches the preset value, converting the current initial text vector into text information to obtain the answer to the target question. The devices mentioned in this article can be servers, PCs, tablets, mobile phones, etc.
[0100] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program with the following method steps: obtaining text information of a target question and converting the text information into a vector to obtain an initial text vector; searching for multiple candidate text information associated with the text information in a knowledge base and obtaining a vector for each candidate text information to obtain multiple candidate text vectors; calculating the relevance between the initial text vector and each candidate text vector to obtain multiple relevances; performing a weighted summation of the multiple relevances with the corresponding candidate text vectors to obtain a target text vector, and adding the target text vector to the initial text vector to obtain an updated initial text vector; iteratively executing the steps of calculating the relevance between the initial text vector and each candidate text vector to obtain multiple relevances, and performing a weighted summation of the multiple relevances with the corresponding candidate text vectors to obtain a target text vector, and adding the target text vector to the initial text vector to obtain an updated initial text vector, until the number of iterations reaches a preset value; when the number of iterations reaches the preset value, converting the current initial text vector into text information to obtain the answer to the target question.
[0101] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0102] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0103] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0104] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0105] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0106] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0107] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0108] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0109] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A method for querying response content, characterized in that, include: Obtain the text information of the target question and convert the text information into a vector to obtain the initial text vector; Search the knowledge base for multiple candidate text information associated with the text information, and obtain the vector of each candidate text information to obtain multiple candidate text vectors; Calculate the correlation between the initial text vector and each candidate text vector to obtain multiple correlation scores; The multiple relevance scores are weighted and summed with the corresponding candidate text vectors to obtain the target text vector. The target text vector is then added to the initial text vector to obtain the updated initial text vector. The process involves iteratively performing the steps of calculating the relevance between the initial text vector and each candidate text vector to obtain multiple relevances, and then weighting and summing the multiple relevances with the corresponding candidate text vectors to obtain the target text vector, and finally adding the target text vector to the initial text vector to obtain the updated initial text vector, until the number of iterations reaches a preset value. When the number of iterations reaches the preset value, the current initial text vector is converted into text information to obtain the answer to the target question; The candidate text vectors include keyword vectors. Calculating the relevance between the initial text vector and each candidate text vector to obtain multiple relevances includes: multiplying the initial text vector by a first preset matrix to obtain a first matrix; multiplying each keyword vector by the first preset matrix to obtain multiple second matrices; grouping each first matrix with the multiple second matrices to obtain multiple sets of matrices; and substituting each set of matrices into a first function to obtain the multiple relevances, wherein the first function is a normalized exponential function. The candidate text vector includes a key value vector. The process of weighted summation of the multiple relevance values with the corresponding candidate text vectors to obtain the target text vector includes: multiplying each key value vector by a second preset matrix to obtain multiple third matrices; determining the relevance corresponding to each third matrix based on the association between the key value vectors and keyword vectors, and multiplying each third matrix by its corresponding relevance value to obtain multiple fourth matrices; and summing the multiple fourth matrices to obtain the target text vector.
2. The method according to claim 1, characterized in that, Converting the text information into a vector yields the initial text vector, which includes: Each character in the text information is identified to obtain multiple characters; The encoding vector for each character in the dictionary is obtained, resulting in multiple encoding vectors; The multiple encoded vectors are combined according to the order in which the multiple characters are arranged in the text information to obtain the initial text vector.
3. The method according to claim 1, characterized in that, The knowledge base stores multiple preset text information, which includes keywords. Searching for multiple candidate text information associated with the preset text information in the knowledge base includes: The text information is segmented into multiple words; Each word is input into the knowledge base for querying, resulting in multiple sets of query results. Each set of query results includes multiple preset text information, and the keyword in each preset text information is the same as any one of the multiple words. Obtain all preset text information from the multiple sets of query results, and remove duplicates from all preset text information to obtain multiple candidate text information associated with the text information.
4. The method according to claim 3, characterized in that, The preset text information includes keywords and key values, the key values include tail entities, and the keywords include head entities and relationships. Before inputting each word into the knowledge base for querying and obtaining multiple sets of query results, the method further includes: By swapping the head and tail entities in each preset text message, multiple first text messages are obtained. The multiple first text information is added to the knowledge base to obtain an updated knowledge base, and the step of inputting each word into the knowledge base for querying is performed according to the updated knowledge base to obtain multiple sets of query results.
5. The method according to claim 1, characterized in that, Before acquiring the text information of the target question and converting the text information into a vector to obtain the initial text vector, the method further includes: Obtain the first sample text information of the sample question, and convert the first sample text information into a vector to obtain the first sample text vector; Search the knowledge base for multiple second sample text information associated with the first sample text information, and obtain the vector of each second sample text information to obtain multiple second sample text vectors; Calculate the correlation between the first sample text vector and each second sample text vector to obtain multiple sample correlations; The relevance of the multiple samples is weighted and summed with the corresponding second sample text vector to obtain the third sample text vector. The first sample text vector is then added to the third sample text vector to obtain the updated first sample text vector. The steps of calculating the correlation between the first sample text vector and each second sample text vector to obtain multiple sample correlations are performed iteratively through the updated first sample text vector, and the steps of weighted summation of the multiple sample correlations with the corresponding second sample text vector to obtain a third sample text vector, and adding the first sample text vector to the third sample text vector to obtain the updated first sample text vector are performed until the number of iterations reaches the preset value. When the number of iterations reaches the preset value, the current first sample text vector is input into the third function for calculation to obtain the sample result, and the first preset matrix and the second preset matrix are determined based on the sample result.
6. The method according to claim 5, characterized in that, Determining the first preset matrix and the second preset matrix based on the sample results includes: Determine whether the sample result is a preset result associated with the sample question; If the sample result is not the preset result, the first initial matrix and the second initial matrix are changed to obtain an updated first initial matrix and an updated second initial matrix. The sample result is then re-determined based on the updated first initial matrix and the updated second initial matrix until the sample result is the preset result. If the sample result is the preset result, the first initial matrix at the current time is determined as the first preset matrix, and the second initial matrix at the current time is determined as the second preset matrix.
7. A device for querying response content, characterized in that, include: The first acquisition unit is used to acquire text information of the target question and convert the text information into a vector to obtain an initial text vector; The first search unit is used to search for multiple candidate text information associated with the text information in the knowledge base, and obtain the vector of each candidate text information to obtain multiple candidate text vectors; The first calculation unit is used to calculate the correlation between the initial text vector and each candidate text vector to obtain multiple correlations. The second calculation unit is used to perform a weighted summation of the multiple relevances and the corresponding candidate text vectors to obtain the target text vector, and to add the target text vector to the initial text vector to obtain the updated initial text vector; The first iteration unit is used to iteratively execute the steps of calculating the correlation between the initial text vector and each candidate text vector to obtain multiple correlations, and the steps of weighted summing of the multiple correlations with the corresponding candidate text vectors to obtain the target text vector, and adding the target text vector to the initial text vector to obtain the updated initial text vector, until the number of iterations reaches a preset value. The conversion unit is used to convert the current initial text vector into text information when the number of iterations reaches the preset value, so as to obtain the answer to the target question; The candidate text vectors include keyword vectors. The first calculation unit includes: a first calculation module, used to multiply the initial text vectors by a first preset matrix to obtain a first matrix; a second calculation module, used to multiply each keyword vector by the first preset matrix to obtain multiple second matrices; a grouping module, used to sequentially group each first matrix with the multiple second matrices to obtain multiple groups of matrices; and a substitution module, used to sequentially substitute each group of matrices into a first function to obtain the multiple relevances, wherein the first function is a normalized exponential function. The candidate text vector includes a key value vector. The second calculation unit includes: a third calculation module, used to multiply each key value vector by a second preset matrix to obtain multiple third matrices; a first determination module, used to determine the relevance of each third matrix according to the correlation between the key value vector and the keyword vector, and multiply each third matrix by the corresponding relevance to obtain multiple fourth matrices; and a fourth calculation module, used to add the multiple fourth matrices to obtain the target text vector.
8. A computer storage medium, characterized in that, The computer storage medium is used to store a program, wherein the program, when running, controls the device where the computer storage medium is located to execute the query method for the response content as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Information retrieval method and device, storage medium and electronic equipment
CN115114418A
Question intention recognition method and apparatus, computer device, and storage medium
WO2020237869A1