Atlas question and answer method and device, equipment, storage medium
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA MOBILE COMM LTD RES INST
- Filing Date
- 2022-01-24
- Publication Date
- 2026-08-07
AI Technical Summary
[0004]知识图谱有专门的结构,需要特定化的查询语言进行搜索,对于普通用户来说,掌握这些查询语言的成本太高,不易于获取知识图谱中的知识
[0010] In this embodiment, the first query question and various candidate K-tuples are directly input into the K-gram matching model. The first query question is vectorized as a whole to obtain a first vector, which is then matched with a second vector obtained by pre-vectorizing each candidate K-tuple as a whole through the K-gram matching model (the similarity between the vectors is calculated) to determine the target K-tuple. This graph question answering method does not require vectorizing each element in the first query question and candidate K-tuples separately, nor does it require matching each vector obtained after vectorization. That is, it does not require multiple processing modules. Only one vector conversion module is needed to obtain the corresponding overall vector, and then the overall vector is matched. The number of processing modules involved is small, the operation steps are simple and direct, and the processing speed is fast, thereby improving the search efficiency.
Smart Images

Figure CN116521829B_ABST
Abstract
Description
Technical Field
[0001] This application relates to information processing technology, including but not limited to a graph question-and-answer method, apparatus, device, and storage medium. Background Technology
[0002] The digital information age has accumulated a large amount of structured and unstructured information. With the development of Internet technology and information digitization, the knowledge base of structured information is growing larger and larger.
[0003] Knowledge graphs (KGs), serving as the infrastructure for next-generation search engines, question-answering systems, and other intelligent applications, contain a vast amount of facts. For example, a certain knowledge graph might contain nearly a hundred billion facts; their sheer number and complex data structures make it difficult for ordinary users to access this wealth of valuable knowledge. Therefore, how to fully utilize the knowledge within knowledge graphs has become a hot topic.
[0004] Knowledge graphs have specialized structures that require specific query languages for searching. For ordinary users, mastering these query languages is too costly, making it difficult to access the knowledge within the knowledge graph. To address this issue, Knowledge Graph-based Question Answering (KGQA) has been proposed. Its goal is to handle natural language questions from end-users by semantically understanding and parsing the questions, converting them into structured queries (such as SPARQL), and then using a knowledge base for query reasoning. The results return entities and / or predicates from the knowledge graph as the answer. Among these, how to determine the answer to the question more quickly is a key challenge. Summary of the Invention
[0005] In view of this, the graph question-answering method, apparatus, device, and storage medium provided in this application can determine the answer to the question more quickly and have higher search efficiency.
[0006] According to one aspect of the embodiments of this application, a graph question answering method is provided, comprising: vectorizing a first query question as a whole using a trained K-gram matching model to obtain a first vector; wherein K is greater than 0; determining a first similarity between the first vector and a second vector of each candidate K-gram using the K-gram matching model; wherein the second vector is obtained by pre-vectorizing the candidate K-grams as a whole using the K-gram matching model; selecting candidate K-grams that satisfy the first similarity condition from each candidate K-gram as a target K-gram; and outputting the entities in the target K-gram as the answer.
[0007] The graph question-answering device provided in this application includes: a K-gram vector conversion module, used to vectorize the first query question as a whole to obtain a first vector; and to vectorize the candidate K-grams as a whole to obtain a second vector; a K-gram matching module, used to determine a first similarity between the first vector and the second vectors of each of the candidate K-grams; and to select candidate K-grams that satisfy the first similarity condition from each of the candidate K-grams as target K-grams that match the first query question; wherein K is greater than 0; and an output module, used to output the entities in the target K-grams as answers.
[0008] The electronic device provided in this application includes a memory and a processor. The memory stores a computer program that can run on the processor. When the processor executes the program, it implements the method described in this application.
[0009] The computer-readable storage medium provided in this application embodiment stores a computer program thereon, which, when executed by a processor, implements the method described in this application embodiment.
[0010] In this embodiment, the first query question and various candidate K-tuples are directly input into the K-gram matching model. The first query question is vectorized as a whole to obtain a first vector, which is then matched with a second vector obtained by pre-vectorizing each candidate K-tuple as a whole through the K-gram matching model (the similarity between the vectors is calculated) to determine the target K-tuple. This graph question answering method does not require vectorizing each element in the first query question and candidate K-tuples separately, nor does it require matching each vector obtained after vectorization. That is, it does not require multiple processing modules. Only one vector conversion module is needed to obtain the corresponding overall vector, and then the overall vector is matched. The number of processing modules involved is small, the operation steps are simple and direct, and the processing speed is fast, thereby improving the search efficiency.
[0011] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description
[0012] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the specification, serve to explain the technical solutions of this application. Obviously, the drawings described below are merely some embodiments of this application, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort.
[0013] The flowcharts shown in the accompanying drawings are merely illustrative and do not necessarily include all content and operations / steps, nor do they necessarily need to be performed in the described order. For example, some operations / steps can be broken down, while others can be combined or partially combined; therefore, the actual execution order may change depending on the specific circumstances.
[0014] Figure 1 A schematic diagram illustrating the implementation process of a graph-based question-answering method provided in this application embodiment;
[0015] Figure 2 A flowchart illustrating a K-ary matching model training method provided in an embodiment of this application;
[0016] Figure 3 A flowchart illustrating a K-ary matching model training method provided in an embodiment of this application;
[0017] Figure 4 A flowchart illustrating a K-ary matching model training method provided in an embodiment of this application;
[0018] Figure 5 A schematic diagram of a graph question-answering model training method provided in an embodiment of this application;
[0019] Figure 6 This is a schematic diagram of the structure of the graph question-and-answer device according to an embodiment of this application;
[0020] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0021] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the specific technical solutions of this application will be further described in detail below with reference to the accompanying drawings of the embodiments of this application. The following embodiments are used to illustrate this application, but are not intended to limit the scope of this application.
[0022] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein is for the purpose of describing embodiments of this application only and is not intended to limit this application.
[0023] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0024] This application provides a graph-based question-answering method applied to an electronic device. This electronic device can be of various types with information processing capabilities, such as a terminal or a server. The terminal can include various hardware devices with operating systems, such as mobile phones, tablets, and laptops. The server can be a standalone server, a distributed server, or a server cluster composed of multiple servers. The functionality achieved by this method can be implemented by a processor in the electronic device calling program code. The program code can be stored in a computer storage medium. Therefore, the electronic device includes at least a processor and a storage medium.
[0025] Figure 1 This is a schematic diagram illustrating the implementation process of the graph question-answering method provided in the embodiments of this application, such as... Figure 1 As shown, the method may include the following steps 101 to 104:
[0026] Step 101: Vectorize the first query problem as a whole using the trained K-gram matching model to obtain the first vector; where K is greater than 0.
[0027] In this application, there is no limitation on the specific number of grammars in the K-gram matching model; K can be 3, 4, 5, or any other arbitrary value. In some embodiments, the value of K is 3.
[0028] In some embodiments, the transformer module can be used to vectorize the first query question as a whole.
[0029] Here, we explain the concept of triples: knowledge exists in the knowledge base in the form of triples (S, P, O), where S represents the head entity, O represents the tail entity, and P represents the predicate relation between the head and tail entities. For example, for the first query "Who is Zhang San's wife?", the answer can be derived from the triple data <Zhang San, wife, Li Si> stored in the knowledge graph: "Li Si"; where "Zhang San" is the head entity, "wife" is the relation, and "Li Si" is the tail entity.
[0030] Step 102: Determine the first similarity between the first vector and the second vector of each candidate K-tuple using the K-gram matching model; wherein the second vector is obtained by pre-vectorizing the candidate K-tuples as a whole using the K-gram matching model.
[0031] It should be noted that in this embodiment, when the first query question of the input K-gram matching model fails, it is not necessary to vectorize each candidate K-gram as a whole every time the first query question is vectorized as a whole; instead, each candidate K-gram is vectorized as a whole in advance, and its corresponding second vector is stored. In this way, when the first query question changes, it is only necessary to vectorize the first query question as a whole, thereby reducing resource waste.
[0032] Step 103: Select the candidate K-tuple that satisfies the first similarity condition from all candidate K-tuples as the target K-tuple.
[0033] In some embodiments, when implementing graph-based question answering for the first query question, it is necessary to extract the entities and relations from the first query question and then calculate their similarity with the entities and relations in the K-tuples. Specifically, it is necessary to vectorize each element (head entity, relation, and tail entity) in the K-tuples and identify the K-tuple element content (entities and relations) in the first query question. Using the above graph-based question answering method involves many modules, resulting in relatively high operational complexity and a tendency to accumulate errors.
[0034] In view of this, in this embodiment, the first query question and each different candidate K-tuple are directly input into the K-gram matching model. The first query question is vectorized as a whole to obtain a first vector, which is then matched with a second vector obtained by pre-vectorizing each candidate K-tuple as a whole through the K-gram matching model (the similarity between the vectors is calculated) to determine the target K-tuple. This graph question answering method does not require vectorizing each element in the first query question and candidate K-tuple separately, nor does it require matching each vector obtained after vectorization of each element. That is, it does not require multiple processing modules; only a vector conversion module is needed to obtain the corresponding overall vector, and then the overall vector is matched. The number of processing modules involved is small, the operation steps are simple and direct, and the processing speed is fast, thereby improving the search efficiency.
[0035] For example, in a trained K-gram matching model, the candidate K-gram 1 corresponding to the first query question, such as <Xiaoming, place of residence, China>, is vectorized as a whole to obtain the corresponding second vector. The candidate K-tuple 2 corresponding to the first query question, such as <Li Ming, birthplace, China>, is vectorized as a whole to obtain the corresponding second vector. …; When the user inputs the first query question "Where was Xiaoming born?" into the trained K-gram matching model, the first query question "Where was Xiaoming born?" is vectorized as a whole to obtain the corresponding first vector. Then, the first similarity between the first vector corresponding to the first query question and the second vector corresponding to each candidate K-tuple is calculated, and the candidate K-tuples that meet the conditions are selected as the target K-tuples based on the first similarity. In some embodiments, the condition can be the maximum first similarity; in another embodiment, the condition can be the first similarity being greater than a specific threshold.
[0036] Step 104: Output the entities in the target K-tuple as the answer.
[0037] Here, the entity in the target K-tuple is used as the answer, that is, the tail entity "China" in the target K-tuple is output to the user as the answer.
[0038] Figure 2 This is a schematic diagram illustrating the implementation process of the K-gram matching model training method provided in the embodiments of this application, as follows: Figure 2 As shown, the method may include the following steps 201 to 202:
[0039] Step 201: Perform data augmentation on the second query problem to obtain N extended query problems; wherein the second query problem and the N extended query problems have the same semantics; N is greater than 0.
[0040] Understandably, during the training process of a K-gram matching model, if the training samples are too few, the resulting K-gram matching model is prone to overfitting. User query questions can be expressed in diverse ways. In this embodiment, data augmentation is used to expand the user query questions, thereby enhancing the K-gram matching model's ability to represent user query questions in sentences.
[0041] In some embodiments, the second query problem can be expanded using the dropout mechanism to obtain N expanded query problems.
[0042] Dropout can be viewed as a form of model averaging, which involves averaging estimates or predictions from different models using certain weights. Expanding the second query question using dropout involves discarding different hidden neurons from the second query question, thus achieving a function similar to training different networks (manifested as generating expanded query questions based on the second query question). Randomly discarding some hidden neurons from the second query question ensures that the generated expanded query questions are different.
[0043] For example, suppose the second query question is "Where does Li Ming live?". This second query question is input into the initial K-gram matching model. The dropout mechanism set in the model is used to augment the second query question, resulting in N expanded query questions, such as "Where does Li Ming live?", "Where does Li Ming live?", etc. It is clear that the expanded query questions have the same semantics as the second query question.
[0044] Step 202: Treat the second query problem and the N extended query problems as different sample query problems. Based on the sample K-tuples corresponding to each sample query problem and the second query problem, train the initial K-gram matching model to obtain the trained K-gram matching model.
[0045] It should be noted that when training the initial K-gram matching model based on the sample K-tuples corresponding to each sample query question and the second query question, the initial K-gram matching model is trained based on the second query question and the sample K-tuples. Then, the initial K-gram matching model is trained N times based on the sample K-tuples corresponding to N extended query questions and the second query question respectively. The results of multiple (N+1) trainings are summarized to obtain the trained K-gram matching model. Here, the training order of the second query question and the extended query question is not restricted.
[0046] The sample K-tuples include positive sample K-tuples and negative sample K-tuples; the similarity between the positive sample K-tuples and the second query question is greater than the first threshold; the similarity between the negative sample K-tuples and the second query question is less than the second threshold; the first threshold is greater than or equal to the second threshold.
[0047] For example, suppose the second query question is "Where does Li Ming live?", then the positive sample K-tuple corresponding to the second query question can be [Li Ming, lives in, China], [Xiao Ming, was born in, China], etc.; the negative sample K-tuple corresponding to the second query question can be [Xiao Hong, likes, dancing], [Bacon, belongs to, meat], etc.
[0048] In some embodiments, step 202 can be achieved by performing the following steps 2021 to 2024:
[0049] Step 2021: The sample query problem, the positive sample K-tuples, and the negative sample K-tuples are treated as a whole and vectorized separately to obtain their respective K-tuple vectors.
[0050] Here, the sample query problem can be vectorized as a whole to obtain the K-ary vector corresponding to the sample query problem; the positive sample K-ary can be vectorized as a whole to obtain the K-ary vector corresponding to the positive sample K-ary; and the negative sample K-ary can be vectorized as a whole to obtain the K-ary vector corresponding to the negative sample K-ary.
[0051] For example, the second query question, "Where does Li Ming live?", is vectorized as a whole to obtain the corresponding K-element vector. The positive sample K-tuple 1 [Li Ming, residing in, China] is vectorized as a whole to obtain the corresponding K-tuple vector. The negative sample K-tuple [Xiaohong, likes, dances] is vectorized as a whole to obtain the corresponding K-tuple vector.
[0052] Step 2022: Determine the second similarity between the K-gram vector of the sample query problem and the K-gram vector of the positive sample K-gram, and the third similarity between the K-gram vector of the sample query problem and the K-gram vector of the negative sample K-gram.
[0053] Step 2023: Determine the first loss function of the initial K-ary matching model based on the second and third similarities.
[0054] Here, sim(q1,a1) is used. + The second similarity is represented by sim(q1,a1). - The third similarity is represented by ). Here, q1 is the K-ary vector corresponding to the sample query question, and a1... + Let a1 be the K-ary vector corresponding to the K-tuple of positive samples. - This represents the K-gram vector corresponding to the K-tuples of negative samples. In some embodiments, the first loss function can be determined as follows:
[0055] Understandably, in some embodiments, the similarity is evaluated using the maximum likelihood loss function. This method is difficult to distinguish between correct and incorrect candidate answers to the greatest extent possible and has insufficient generalization ability.
[0056] In this embodiment, positive and negative sample K-tuples are introduced. Considering that the similarity between the sample query problem and the positive sample K-tuples is much greater than the similarity between the sample query problem and the negative sample K-tuples, the difference between the positive and negative sample K-tuples can be widened. That is, the distance between the sample query problem and the correct candidate K-tuples is brought as close as possible, while the distance between the sample query problem and the incorrect candidate K-tuples is made as far as possible, thereby improving the generalization ability of the K-gram matching model for candidate K-tuples.
[0057] Step 2024: Based on the first loss function, the initial K-ary matching model is back-trained; this process is iterated until the cutoff condition is met, and the trained K-ary matching model is obtained.
[0058] In this embodiment of the application, after training the initial K-gram matching model according to the second query question and N extended query questions, it is considered that the cutoff condition has been met.
[0059] Figure 3 This is a schematic diagram illustrating the implementation process of the K-gram matching model training method provided in the embodiments of this application, as follows: Figure 3 As shown, the method may include the following steps 301 to 308:
[0060] Step 301: Vectorize the sample query problem as a whole, the positive sample K-tuple as a whole, and the negative sample K-tuple as a whole to obtain their respective K-tuple vectors.
[0061] Step 302: Determine the second similarity between the K-gram vector of the sample query problem and the K-gram vector of the positive sample K-gram, and the third similarity between the K-gram vector of the sample query problem and the K-gram vector of the negative sample K-gram.
[0062] Step 303: Determine the first loss function of the initial K-gram matching model based on the second and third similarities;
[0063] Step 304: Vectorize the first head entity and the first relation in the sample query problem to obtain their respective third vectors; vectorize the second head entity, the second relation, and the first tail entity in the positive sample K-tuple to obtain their respective fourth vectors; and vectorize the third head entity, the third relation, and the second tail entity in the negative sample K-tuple to obtain their respective fifth vectors.
[0064] It should be noted that the above processing steps share the same input data, for example, all of them process the second query question "Where does Li Ming live?".
[0065] For example, in the second query question, the first entity is "Li Ming", and the corresponding third vector is
[10101] , the first relation is "where to live", and the corresponding third vector is
[01101] ; in the positive sample K-tuple 1, the second head entity is [Li Ming], and the corresponding fourth vector is
[10101] , the second relation [lives in], and the corresponding fourth vector is
[01100] , the first tail entity [China], and the corresponding fourth vector is
[10110] ; in the negative sample K-tuple 1, the second head entity is [Xiao Hong], and the corresponding fifth vector is
[10111] , the second relation [likes], and the corresponding fifth vector is
[10100] , the first tail entity [dances], and the corresponding fifth vector is
[11100] .
[0066] Step 305: Enhance the third vector corresponding to the first relation in the sample query problem, the fourth vector corresponding to the second relation in the positive sample K-tuple, and the fifth vector corresponding to the third relation in the negative sample K-tuple, respectively, to obtain the unary vectors of the sample query problem, the positive sample K-tuple, and the negative sample K-tuple.
[0067] Understandably, sample K-tuples are structured data, while query questions are expressed in natural language. Semantically aligning structured data with natural language expressions helps improve the matching accuracy of vector space representations for sample K-tuple matching and graph question answering.
[0068] Here, semantic alignment between structured data and natural language representations can be achieved by semantically aligning the first relation in the sample query problem with the second relation in the positive sample K-tuple and the third relation in the negative sample K-tuple.
[0069] For example, in some embodiments, the method in step 305 can be implemented by performing the following steps 3051 to 3052 to achieve partial semantic alignment between structured data and natural language representation:
[0070] Step 3051: Add noise to the third vector corresponding to the first head entity, the fourth vector corresponding to the second head entity, the fourth vector corresponding to the first tail entity, the fifth vector corresponding to the third head entity, and the fifth vector corresponding to the second tail entity to obtain their respective first update vectors.
[0071] Here, by adding noise to the vectors corresponding to elements other than the first relation in the sample query problem, as well as elements other than the second relation in the positive sample K-tuple and elements other than the third relation in the negative sample K-tuple, the presence of elements other than the relation is weakened, thereby strengthening the presence of the relation element, and thus achieving alignment between the structured data and the natural language expression.
[0072] In some embodiments, determining the first update vector can be implemented as follows:
[0073] Determine the gradients of the third vector corresponding to the first head entity, the fourth vector corresponding to the second head entity, the fifth vector corresponding to the third head entity, the fourth vector corresponding to the first tail entity, and the fifth vector corresponding to the second tail entity, respectively, and obtain their respective gradient values; and
[0074] The gradient values are added as noise to the third vector corresponding to the first head entity, the fourth vector corresponding to the second head entity, the fifth vector corresponding to the third head entity, the fourth vector corresponding to the first tail entity, and the fifth vector corresponding to the second tail entity, respectively, to obtain the corresponding first update vector.
[0075] Step 3052: Combine the first update vector corresponding to the first head entity and the third vector corresponding to the first relation to obtain the unary vector of the sample query problem; combine the first update vector corresponding to the second head entity, the fourth vector corresponding to the second relation, and the first update vector corresponding to the first tail entity to obtain the unary vector of the positive sample K-tuple; and combine the first update vector corresponding to the third head entity, the fifth vector corresponding to the third relation, and the first update vector corresponding to the second tail entity to obtain the unary vector of the negative sample K-tuple.
[0076] In some embodiments, the second update vector obtained after processing each element is used to replace each vector before processing, thereby obtaining a binary vector of the sample query question, positive sample K-tuple, and negative sample K-tuple.
[0077] By performing steps 3051 to 3052 above, the relationship between the sample query question and the positive and negative sample K-tuples can be aligned, thereby improving the accuracy of the vector space representation of sample K-tuple matching and the graph question answering.
[0078] Step 306: Determine the fourth similarity between the unary vector of the sample query problem and the unary vector of the positive sample K-tuple, and the fifth similarity between the unary vector of the sample query problem and the unary vector of the negative sample K-tuple.
[0079] Step 307: Determine the second loss function of the initial K-ary matching model based on the fourth and fifth similarities.
[0080] Here, sim(q2,a2) is used. + The fourth similarity is represented by sim(q2,a2). - () represents the fifth similarity. Here, q2 is the unary vector corresponding to the sample query question, and a2... + Let a2 be the unary vector corresponding to the K tuples of positive samples. -This is the unary vector corresponding to the K tuples of negative samples. In some embodiments, the second loss function can be determined as follows:
[0081] Step 308: Based on the first loss function and the second loss function, the initial K-ary matching model is back-trained; this process is iterated until the cutoff condition is met to obtain the trained K-ary matching model.
[0082] In some embodiments, different weights can be assigned to the first loss function and the second loss function respectively to obtain a weighted loss function, and the initial K-ary matching model can be back-trained based on the weighted loss function.
[0083] Figure 4 This is a schematic diagram illustrating the implementation process of the K-gram matching model training method provided in the embodiments of this application, as follows: Figure 4 As shown, the method may include steps 401 to 411:
[0084] Step 401: Vectorize the sample query problem as a whole, the positive sample K-tuple as a whole, and the negative sample K-tuple as a whole to obtain their respective K-tuple vectors.
[0085] Step 402: Determine the second similarity between the K-gram vector of the sample query problem and the K-gram vector of the positive sample K-gram, and the third similarity between the K-gram vector of the sample query problem and the K-gram vector of the negative sample K-gram.
[0086] Step 403: Determine the first loss function of the initial K-gram matching model based on the second and third similarities;
[0087] Step 404: Vectorize the first head entity and the first relation in the sample query problem to obtain their respective third vectors; vectorize the second head entity, the second relation, and the first tail entity in the positive sample K-tuple to obtain their respective fourth vectors; and vectorize the third head entity, the third relation, and the second tail entity in the negative sample K-tuple to obtain their respective fifth vectors.
[0088] Step 405: Enhance the third vector corresponding to the first relation in the sample query problem, the fourth vector corresponding to the second relation in the positive sample K-tuple, and the fifth vector corresponding to the third relation in the negative sample K-tuple respectively to obtain the unary vector of the sample query problem, the unary vector of the positive sample K-tuple, and the unary vector of the negative sample K-tuple.
[0089] Step 406: Determine the fourth similarity between the unary vector of the sample query problem and the unary vector of the positive sample K-tuple, and the fifth similarity between the unary vector of the sample query problem and the unary vector of the negative sample K-tuple.
[0090] Step 407: Determine the second loss function of the initial K-gram matching model based on the fourth and fifth similarities;
[0091] Step 408: The fourth vector corresponding to the first tail entity in the positive sample K-tuple and the fifth vector corresponding to the second tail entity in the negative sample K-tuple are weakened respectively to obtain the binary vector of the sample query problem, the binary vector of the positive sample K-tuple, and the binary vector of the negative sample K-tuple.
[0092] It should be noted that the above implementation steps share the same input data, for example, all of them process the second query question "Where does Li Ming live?".
[0093] The sample K-tuples are structured data, while the query question is expressed in natural language. Here, we can further use the binary vector transformation module to perform semantic alignment between the structured sample K-tuples and the query question expressed in natural language, thereby improving the matching accuracy of the vector space representation of the sample K-tuple matching and the graph question answering.
[0094] In some embodiments, step 408 can be achieved by performing the following steps 4081 to 4082:
[0095] Step 4081: Set the fourth vector corresponding to the second tail entity and the fifth vector corresponding to the third tail entity to zero respectively to obtain their respective second update vectors.
[0096] Here, by setting the fourth vector corresponding to the second tail entity in the positive sample K-tuple and the fifth vector corresponding to the third tail entity in the negative sample K-tuple to zero (if there is no tail entity in the sample query problem, its corresponding fifth vector is defaulted to 0), the presence of the tail entity is weakened, thereby strengthening the presence of the relationship and the head entity, and thus achieving semantic alignment between the relationship and the head entity between the sample query problem and the positive and negative sample K-tuples.
[0097] Step 4082: Combine the third vector corresponding to the first head entity and the third vector corresponding to the first relation to obtain the binary vector of the sample query problem; combine the fourth vector corresponding to the second head entity, the fourth vector corresponding to the second relation, and the second update vector corresponding to the first tail entity to obtain the binary vector of the positive sample K-tuple; and combine the fifth vector corresponding to the third head entity, the fifth vector corresponding to the third relation, and the second update vector corresponding to the second tail entity to obtain the binary vector of the negative sample K-tuple.
[0098] In some embodiments, the second update vector obtained after processing each element is used to replace each vector before processing, thereby obtaining a binary vector of the sample query question, positive sample K-tuple, and negative sample K-tuple.
[0099] Step 409: Determine the sixth similarity between the binary vector of the sample query problem and the binary vector of the positive sample K-tuple, and the seventh similarity between the binary vector of the sample query problem and the binary vector of the negative sample K-tuple.
[0100] Step 410: Determine the third loss function of the initial K-ary matching model based on the sixth and seventh similarities.
[0101] Here, we use sim(q3,a3) + The sixth similarity is represented by sim(q3,a2). - () represents the seventh similarity. Here, q3 is the binary vector corresponding to the sample query question, and a3... + Let a3 be the binary vector corresponding to the K tuples of positive samples. - This represents the binary vector corresponding to the K tuples of negative samples. In some embodiments, the third loss function can be determined as follows:
[0102] Step 411: Based on the first loss function, the second loss function, and the third loss function, the initial K-ary matching model is back-trained; this process is iterated until the cutoff condition is met to obtain the trained K-ary matching model.
[0103] In some embodiments, the first loss function, the second loss function, and the third loss function can be weighted to obtain the target loss function; the initial K-ary matching model can then be back-trained based on the target loss function.
[0104] Depending on the implementation method, in some embodiments, knowledge graph question answering systems can be divided into the following four methods: methods based on preset template matching, methods based on semantic parsing, methods based on information extraction, and methods based on vector space modeling.
[0105] The pre-defined template matching method requires manual rule setting, which incurs high maintenance costs when dealing with large datasets. This new method first defines templates based on the knowledge graph structure and the sentence structures of potential questions. It manually summarizes the number of possible questions and, based on the element information in different questions, converts the question representation into a corresponding database query template, such as a SPARQL template or SQL. After obtaining the query template, it performs template matching queries in the corresponding database, mapping the natural language question to the entity relationships in the knowledge graph. Finally, it outputs the retrieved entities as the answer.
[0106] Semantic parsing-based methods are more linguistically inclined. The main idea is to transform natural language into a series of formalized logical expressions called syntax trees. Then, by parsing the logical forms of the syntax trees from the bottom up, a logical form that can express the semantics of the entire question is obtained. The answer is then obtained by querying the knowledge base with the corresponding query statement.
[0107] Information extraction-based methods extract entities from the question, query the entity in the knowledge graph to obtain a knowledge base subgraph centered on the entity node, and each node or edge in the subgraph can be a candidate answer. Information is then extracted through certain rules or sentence word features to obtain the question feature vector. A classifier is built to filter the candidate answers to obtain the final answer. The method generally includes steps such as word segmentation, part-of-speech tagging, entity recognition, entity linking, relationship prediction, and answer reasoning.
[0108] The vector space-based modeling approach uses vector spaces to describe natural language questions and entities and relations in a knowledge base, and trains automatically to answer the input question by comparing the distance between the question and candidate answers in the vector space. Currently, the main specific methods include: extracting entities from the question, representing other nodes and edges corresponding to the entities in the knowledge graph using vector spaces, then vectorizing the question sentence and calculating similarity to filter for the answer; or calculating the similarity scores between multiple candidate subject entities and multiple candidate relations in the question as the prediction target, and using the predicted subject entities and relations to find the object entity in the knowledge base as the answer.
[0109] The drawbacks of template-based matching methods are quite obvious. This method has certain limitations; when a user's question does not match a template in the template library, the question-answering system will not be able to provide an answer. Therefore, this method has low coverage of the diversity of question expressions and poor flexibility. Manually defined templates are based on symbol matching, requiring the rule template designer to consider all situations as much as possible, resulting in high manual maintenance costs. Syntax tree-based methods require strong linguistic knowledge and the model must be able to process tree structure information, making implementation difficult. Information extraction-based methods are pipelined methods, including steps such as word segmentation, part-of-speech tagging, entity recognition, entity linking, relation prediction, and answer reasoning. Errors at each step in this method accumulate as the pipeline progresses, and each error leads to an incorrect final answer.
[0110] In vector space-based modeling methods, entity recognition and relation extraction are performed on the question sentence, and then entities and relations are vectorized separately. Similarity is then calculated between these vectorized representations and the entities and relations in the graph knowledge representation. While this approach utilizes sentence vectorization, it still requires identifying entity and relation elements in the graph triples (an example of K-tuples), resulting in relatively high complexity. Furthermore, the cost function after similarity calculation is often the maximum likelihood loss function, leading to small differences in calculated similarity and a lack of discriminative power. Therefore, a method is needed to directly search and match question sentences with graph triple knowledge, while modifying the loss function to a contrastive learning loss function. Contrastive learning ensures that similar things are close in the encoded representation space, while dissimilar things are as far apart as possible, maximizing data differentiation.
[0111] In summary, the graph-based question-answering method for vector space modeling mainly suffers from the following problems:
[0112] Vectorizing each element in the knowledge graph triples and identifying the triple elements in the question sentence involves a large number of modules, resulting in relatively high operational complexity and a tendency to accumulate errors.
[0113] The graph question-answering scheme in the above embodiments uses the maximum likelihood similarity calculation method to search for and evaluate answers. This method results in very high similarity in the search calculations, low distinguishability between the question sentence and each candidate answer, and insufficient generalization ability.
[0114] In this application embodiment, instead of the multi-module approach of vectorizing entity relation elements in graph triples, a modeling method is adopted that performs vectorized matching between the user's natural question and the entire triple. Simultaneously, to align the element knowledge information in the graph triple with the vector space representation of natural language in the pre-trained language model, the alignment of entity relation triple elements with their natural language representations and the overall triple matching model are jointly trained. This joint training allows for information sharing among the unary, binary, and ternary components of the triple, improving the accuracy of the overall triple matching question answering.
[0115] To address the issue that the maximum likelihood loss function struggles to effectively distinguish between correct and incorrect candidate answers, resulting in insufficient generalization ability, this application introduces a contrastive learning loss function. The core idea is that sim(q, a+) >> sim(q, a-), meaning the similarity of positive examples should be significantly greater than that of negative examples, thus widening the gap between them. This approach aims to minimize the distance between the user's natural question and the correct candidate, while simultaneously maximizing the distance between the natural question and the incorrect candidate, thereby improving the model's generalization ability in matching candidate answers.
[0116] Furthermore, users express questions in a variety of ways using natural language. To enhance the model's ability to represent user questions in sentences, this embodiment employs data augmentation to expand user queries and improve the model's ability to represent the diversity of user natural language sentences. When designing the contrastive learning training data, dropout is directly applied to the model to augment the natural language data.
[0117] In this embodiment, to address the issues of numerous content modules in the triplet of the identification question and the low distinguishability between the question and each candidate answer due to the use of maximum likelihood similarity calculation to search and evaluate answers, a graph question answering method based on contrastive learning and triplet matching is proposed. The overall triplet matching method avoids the accumulation of errors caused by separately identifying each element of the triplet, simplifying the operation steps and reducing complexity. Contrastive learning maximizes the distinction between the question and correct and incorrect candidates by making similar sentences closer together and different sentences farther apart, thereby improving the model's generalization ability.
[0118] To achieve the above objectives, such as Figure 5 As shown, the core idea of the entire algorithm is as follows: First, construct data corresponding to user questions and candidate triples (i.e., an example of candidate K-tuples) based on user questions and candidate answers, and randomly sample negative triples to generate training data for matching user questions and triples; then, use the Transformer module (i.e., an example of a K-gram vector transformation module) to represent the matching of user questions and triples, and use the dropout technique to augment the input user questions and triples to improve the model's ability to represent the diversity of user expressions; while performing triple model matching, use the transformer model to jointly train binary matching of head entities and relations and unary matching of relations; finally, use the contrastive learning loss function to jointly optimize the model.
[0119] The jointly trained models share the same data input: user query and triples. In the example above, the model input is [Bill Burrud was born in California]. <sep> Bill Burrud place_of_birthHollywood, California The triple `[]` represents the head entity of the triple `Bill burrud`, `place_of_birth` represents the relation in the triple `place_of_birth`, and `hollywood, california` represents the tail entity in the triple `hollywood, california`. The input data in the example above achieves a direct match between the user's query and the entire triple `[]`.
[0120] Unary Matching: Unary matching aims to semantically align the natural language relation representation of a user query with the relations in the triples, thereby achieving knowledge fusion of natural language semantic information. The main implementation method involves decoupling the relation representation in natural language with the relation elements in the triples by adding noise to the phrases corresponding to other elements in the triples.
[0121] The specific steps are as follows: The user query and the triples are processed by the transformer model to obtain the vector representation of all word tokens. Then, the gradient corresponding to each word token is calculated through backpropagation. The gradient is regularized and added as noise to the tokens corresponding to the head and tail entities as input to the unary matching model. Finally, the contrastive loss function of the unary relation is calculated as shown in Formula 1:
[0122]
[0123] Where q is the vector corresponding to the user's query statement, and a + Let a be the vector corresponding to the positive sample triplet. - This is the vector corresponding to the negative sample triplet.
[0124] Binary Matching: Binary matching aims to semantically align the natural language entities and relation representations in the user query with the head entities and relations in the triples, achieving natural language semantic fusion of binary knowledge. The main implementation involves masking the tail entities in the natural language and triples to a certain extent, inputting this mask into the binary matching function to calculate the binary contrastive loss function, such as...
[0125] As shown in Equation 2:
[0126]
[0127] The binary matching model can complete the knowledge information of triples by extracting knowledge based on context, which helps to improve the semantic representation of triple matching.
[0128] Ternary Matching: Ternary matching, also known as triplet matching, aligns the entire triplet structure knowledge with the semantic representation of natural language, achieving direct triplet matching for candidate lookup in graph question answering and simplifying the question answering process. The shared data from the joint model is input into the transformer ternary matching model to obtain the ternary information representation and the representation of the triplet structure knowledge of the user query, respectively. The ternary contrastive loss function is then calculated, as shown in Equation 3.
[0129]
[0130] Finally, the loss functions of the univariate, binary, and ternary models are weighted and used as the loss function of the joint training model, as shown in Equation 4:
[0131] Final_loss=alpha*unary_loss+beta*binary-loss+ternary-loss (formula 4);
[0132] The training and optimization of each module model are completed by training and optimizing the joint model based on backpropagation.
[0133] After the model is trained, when a user has a query question, the system constructs the user's query question and graph triple information based on the graph information. Using the triple matching model, the system directly matches the search query to obtain the triple content with the highest similarity. The entity of the triple is then returned to the user as a candidate answer, which is the user's query answer.
[0134] In this embodiment of the application, (1) contrastive learning is introduced into graph question answering: contrastive learning can make similar things close in the encoded representation space, and different things should be as far apart as possible, so that the data can be distinguished to the greatest extent. This makes the distance between the user's question and the correct candidate answer as close as possible, and the distance between the user's natural language question and the incorrect candidate answer as far as possible, thus improving the distinguishability and recognition between answers.
[0135] (2) Matching user natural language questions with the overall triple: In some embodiments, the graph question-answering method requires extracting entity relations and then performing similarity search calculations with the elements in the graph triple, while the method of directly matching with the overall triple in this application embodiment is simple and direct.
[0136] (3) Triple matching, alignment of univariate and binary knowledge information of graph elements and information sharing: Graph triples are structured data, while user questions are expressed in natural language. Aligning structured knowledge with natural language representation and sharing information helps to improve the vector space representation of triple matching and the accuracy of graph question answering.
[0137] (4) Data augmentation and positive / negative example construction method: The embodiments of this application use the dropout method to augment and expand the data of natural language sentences, and use the augmented and expanded data to simulate the diversity of the user's natural language question expression methods to enhance the model's ability to represent the user's natural language sentences; the generated diverse data is treated equally with the original data to expand the overall training data, rather than constructing a combination of augmented data and original data as positive examples as in some embodiments.
[0138] It should be noted that although the steps of the method in this application are described in a specific order in the accompanying drawings, this does not require or imply that the steps must be performed in that specific order, or that all the steps shown must be performed to achieve the desired result. Additional or alternative steps may be omitted, multiple steps may be combined into one step, and / or one step may be broken down into multiple steps; or steps from different embodiments may be combined into a new technical solution.
[0139] Based on the foregoing embodiments, this application provides a graph-based question-and-answer device, which includes various modules and units included in each module, and can be implemented by a processor; of course, it can also be implemented by specific logic circuits; in the implementation process, the processor can be a central processing unit (CPU), microprocessor (MPU), digital signal processor (DSP) or field programmable gate array (FPGA), etc.
[0140] Figure 6 This is a schematic diagram of the structure of the graph question-and-answer device according to an embodiment of this application, as shown below. Figure 6 As shown, the device 600 includes a K-ary vector conversion module 601, a K-ary matching module 602, and an output module, wherein:
[0141] K-gram vector conversion module 601 is used to vectorize the first query question as a whole using a trained K-gram matching model to obtain a first vector, where K is greater than 0; and to vectorize the candidate K-grams as a whole to obtain a second vector; K-gram matching module 602 is used to determine the first similarity between the first vector and the second vector of each candidate K-gram; and to select the candidate K-grams that meet the first similarity condition from each candidate K-gram as the target K-grams that match the first query question, where K is greater than 0; output module 603 is used to output the entities in the target K-grams as the answer.
[0142] In some embodiments, the apparatus further includes a data augmentation module; the data augmentation module is used to augment the second query question to obtain N extended query questions; wherein the second query question and the N extended query questions have the same semantics; N is greater than 0; the second query question and the N extended query questions are all treated as different sample query questions, and an initial K-gram matching model is trained based on the sample K-tuples corresponding to each of the sample query questions and the second query question to obtain the trained K-gram matching model.
[0143] In some embodiments, the sample K-tuples include positive sample K-tuples and negative sample K-tuples; wherein the similarity between the positive sample K-tuples and the second query question is greater than a first threshold; the similarity between the negative sample K-tuples and the second query question is less than a second threshold; the first threshold is greater than or equal to the second threshold; the K-gram vector conversion module 601 vectorizes the sample query question as a whole, the positive sample K-tuples as a whole, and the negative sample K-tuples as a whole to obtain their respective corresponding K-gram vectors; the K-gram matching module 602 determines the second similarity between the K-gram vector of the sample query question and the K-gram vector of the positive sample K-tuples, and the third similarity between the K-gram vector of the sample query question and the K-gram vector of the negative sample K-tuples; determines the first loss function of the initial K-gram matching model based on the second similarity and the third similarity; performs reverse training on the initial K-gram matching model based on the first loss function; iterates in this way until the cutoff condition is reached to obtain the trained K-gram matching model.
[0144] In some embodiments, the apparatus further includes a unary vector conversion module; the unary vector conversion module is used to vectorize the first head entity and the first relation in the sample query problem to obtain their respective third vectors; to vectorize the second head entity, the second relation, and the first tail entity in the positive sample K-tuple to obtain their respective fourth vectors; and to vectorize the third head entity, the third relation, and the second tail entity in the negative sample K-tuple to obtain their respective fifth vectors; to enhance the third vector corresponding to the first relation in the sample query problem, the fourth vector corresponding to the second relation in the positive sample K-tuple, and the fifth vector corresponding to the third relation in the negative sample K-tuple to obtain the unary vector of the sample query problem, the unary vector of the positive sample K-tuple, and the unary vector of the negative sample K-tuple; to perform reverse training on the initial K-gram matching model based on the unary vector of the sample query problem, the unary vector of the positive sample K-tuple, and the unary vector of the negative sample K-tuple; and to iterate in this way until the cutoff condition is reached to obtain the trained K-gram matching model.
[0145] In some embodiments, the apparatus further includes a unary matching module, which is configured to determine a fourth similarity between the unary vector of the sample query question and the unary vector of the positive sample K-tuple, and a fifth similarity between the unary vector of the sample query question and the unary vector of the negative sample K-tuple; determine a second loss function of the initial K-gram matching model based on the fourth and fifth similarities; and perform reverse training on the initial K-gram matching model based on the first and second loss functions.
[0146] In some embodiments, the unary vector transformation module is used to add noise to the third vector corresponding to the first head entity, the fourth vector corresponding to the second head entity, the fourth vector corresponding to the first tail entity, the fifth vector corresponding to the third head entity, and the fifth vector corresponding to the second tail entity respectively to obtain their respective first update vectors; combine the first update vector corresponding to the first head entity and the third vector corresponding to the first relation to obtain the unary vector of the sample query problem; combine the first update vector corresponding to the second head entity, the fourth vector corresponding to the second relation, and the first update vector corresponding to the first tail entity to obtain the unary vector of the positive sample K-tuple; and combine the first update vector corresponding to the third head entity, the fifth vector corresponding to the third relation, and the first update vector corresponding to the second tail entity to obtain the unary vector of the negative sample K-tuple.
[0147] In some embodiments, the unary vector transformation module is used to determine the gradients of the third vector corresponding to the first head entity, the fourth vector corresponding to the second head entity, the fifth vector corresponding to the third head entity, the fourth vector corresponding to the first tail entity, and the fifth vector corresponding to the second tail entity, respectively, to obtain their respective gradient values; and to add the gradient values as noise to the third vector corresponding to the first head entity, the fourth vector corresponding to the second head entity, the fifth vector corresponding to the third head entity, the fourth vector corresponding to the first tail entity, and the fifth vector corresponding to the second tail entity, respectively, to obtain their respective first update vectors.
[0148] In some embodiments, the apparatus further includes a binary vector transformation module and a binary matching module; the binary vector transformation module is used to weaken the fourth vector corresponding to the first tail entity in the positive sample K-tuple and the fifth vector corresponding to the second tail entity in the negative sample K-tuple respectively, to obtain the binary vector of the sample query question, the binary vector of the positive sample K-tuple, and the binary vector of the negative sample K-tuple; the binary matching module is used to determine the sixth similarity between the binary vector of the sample query question and the binary vector of the positive sample K-tuple, and the seventh similarity between the binary vector of the sample query question and the binary vector of the negative sample K-tuple; determine the third loss function of the initial K-gram matching model based on the sixth similarity and the seventh similarity; perform reverse training on the initial K-gram matching model based on the first loss function, the second loss function, and the third loss function; iterate in this way until the cutoff condition is reached to obtain the trained K-gram matching model.
[0149] In some embodiments, the binary vector transformation module is used to set the fourth vector corresponding to the second tail entity and the fifth vector corresponding to the third tail entity to zero respectively to obtain their respective second update vectors; combine the third vector corresponding to the first head entity and the third vector corresponding to the first relation to obtain the binary vector of the sample query problem; combine the fourth vector corresponding to the second head entity, the fourth vector corresponding to the second relation, and the second update vector corresponding to the first tail entity to obtain the binary vector of the positive sample K-tuple; and combine the fifth vector corresponding to the third head entity, the fifth vector corresponding to the third relation, and the second update vector corresponding to the second tail entity to obtain the binary vector of the negative sample K-tuple.
[0150] In some embodiments, the apparatus further includes a weighting module, which is used to weight the first loss function, the second loss function, and the third loss function to obtain a target loss function; the binary matching module is used to perform reverse training on the initial K-ary matching model according to the target loss function.
[0151] The descriptions of the above device embodiments are similar to those of the above method embodiments, and have similar beneficial effects. For technical details not disclosed in the device embodiments of this application, please refer to the descriptions of the method embodiments of this application for understanding.
[0152] It should be noted that, in the embodiments of this application... Figure 6 The module division of the illustrated question-and-answer device is illustrative and represents only one logical functional division; in actual implementation, other division methods may be used. Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, exist as separate physical units, or be integrated into one unit with two or more units. The integrated units can be implemented in hardware, as software functional units, or a combination of both.
[0153] It should be noted that, in the embodiments of this application, if the above-described methods are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, or the parts that contribute to related technologies, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause an electronic device to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), magnetic disks, or optical disks. Thus, the embodiments of this application are not limited to any specific hardware and software combination.
[0154] This application provides an electronic device. Figure 7 This is a schematic diagram of the hardware entity of the electronic device according to an embodiment of this application, such as... Figure 7 As shown, the electronic device 700 includes a memory 701 and a processor 702. The memory 701 stores a computer program that can run on the processor 702. When the processor 702 executes the program, it implements the steps in the method provided in the above embodiments.
[0155] It should be noted that the memory 701 is configured to store instructions and applications executable by the processor 702, and can also cache data to be processed or already processed (e.g., image data, audio data, voice communication data and video communication data) in the processor 702 and various modules in the electronic device 700. It can be implemented by flash memory or random access memory (RAM).
[0156] This application provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the method provided in the above embodiments.
[0157] This application provides a computer program product containing instructions that, when run on a computer, cause the computer to perform the steps in the method provided in the above-described method embodiments.
[0158] It should be noted that the descriptions of the storage medium and device embodiments above are similar to the descriptions of the method embodiments above, and have similar beneficial effects. For technical details not disclosed in the storage medium, storage medium, and device embodiments of this application, please refer to the descriptions of the method embodiments of this application for understanding.
[0159] It should be understood that the phrases "one embodiment," "an embodiment," or "some embodiments" throughout the specification mean that a specific feature, structure, or characteristic related to an embodiment is included in at least one embodiment of this application. Therefore, "in one embodiment," "in one embodiment," or "in some embodiments" appearing throughout the specification do not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. It should be understood that in the various embodiments of this application, the sequence numbers of the above-described processes do not imply a sequential order of execution; the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application. The sequence numbers of the above-described embodiments are merely for descriptive purposes and do not represent the superiority or inferiority of the embodiments. The descriptions of the various embodiments above tend to emphasize the differences between the various embodiments; their similarities or commonalities can be referred to mutually, and for the sake of brevity, they will not be repeated here.
[0160] In this article, the term "and / or" is merely a description of the relationship between related objects, indicating that there can be three kinds of relationships. For example, object A and / or object B can represent three situations: object A exists alone, object A and object B exist simultaneously, and object B exists alone.
[0161] It should be noted that, in this document, 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 a 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.
[0162] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The embodiments described above are merely illustrative. For example, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple modules or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, and the indirect coupling or communication connection between devices or modules can be electrical, mechanical, or other forms.
[0163] The modules described above as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules. They may be located in one place or distributed across multiple network units. Some or all of the modules may be selected to achieve the purpose of this embodiment according to actual needs.
[0164] In addition, each functional module in the various embodiments of this application can be integrated into one processing unit, or each module can be a separate unit, or two or more modules can be integrated into one unit; the integrated modules can be implemented in hardware or in the form of hardware plus software functional units.
[0165] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media that can store program code, such as mobile storage devices, read-only memory (ROM), magnetic disks, or optical disks.
[0166] Alternatively, if the integrated units described above are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, or the parts that contribute to related technologies, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause an electronic device to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, ROMs, magnetic disks, or optical disks.
[0167] The methods disclosed in the several method embodiments provided in this application can be arbitrarily combined without conflict to obtain new method embodiments.
[0168] The features disclosed in the several product embodiments provided in this application can be arbitrarily combined without conflict to obtain new product embodiments.
[0169] The features disclosed in the several method or device embodiments provided in this application can be arbitrarily combined without conflict to obtain new method or device embodiments.
[0170] The above description is merely an embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.< / sep>
Claims
1. A graph-based question-and-answer method, characterized in that, The method includes: Using the trained K-gram matching model, the first query question is vectorized as a whole to obtain the first vector; where K equals 3; The first similarity between the first vector and the second vector of each candidate K-tuple is determined by the K-gram matching model; wherein the second vector is obtained by pre-vectorizing the candidate K-tuples as a whole using the K-gram matching model. And select the candidate K-tuples that satisfy the first similarity condition from each of the candidate K-tuples as the target K-tuple; Output the entities in the target K-tuple as the answer; The sample K-tuples include positive sample K-tuples and negative sample K-tuples; the method further includes: Data augmentation is performed on the second query question to obtain N extended query questions; wherein the second query question and the N extended query questions have the same semantics; N is greater than 0; the similarity between the second query question and the positive sample K-tuple is greater than a first threshold; the similarity between the second query question and the negative sample K-tuple is less than a second threshold; the first threshold is greater than or equal to the second threshold; The second query question and the N extended query questions are all treated as different sample query questions; The sample query problem, the positive sample K-tuple, and the negative sample K-tuple are treated as a whole and vectorized respectively to obtain their corresponding K-tuple vectors. Determine the second similarity between the K-gram vector of the sample query problem and the K-gram vector of the positive sample K-gram, and the third similarity between the K-gram vector of the sample query problem and the K-gram vector of the negative sample K-gram; Based on the second similarity and the third similarity, determine the first loss function of the initial K-gram matching model; Based on the first loss function, the initial K-gram matching model is back-trained; this process is iterated until a cutoff condition is met, resulting in the trained K-gram matching model; the back-training of the initial K-gram matching model based on the first loss function includes: The first head entity and the first relation in the sample query problem are vectorized to obtain their respective third vectors; the second head entity, the second relation, and the first tail entity in the positive sample K-tuple are vectorized to obtain their respective fourth vectors; and the third head entity, the third relation, and the second tail entity in the negative sample K-tuple are vectorized to obtain their respective fifth vectors. The third vector corresponding to the first relation in the sample query problem, the fourth vector corresponding to the second relation in the positive sample K-tuple, and the fifth vector corresponding to the third relation in the negative sample K-tuple are respectively enhanced to obtain the unary vector of the sample query problem, the unary vector of the positive sample K-tuple, and the unary vector of the negative sample K-tuple. Based on the unary vector of the sample query problem, the unary vector of the positive sample K-tuple, and the unary vector of the negative sample K-tuple, the initial K-gram matching model is trained in reverse; this process is iterated until the cutoff condition is met to obtain the trained K-gram matching model. The step of back-training the initial K-gram matching model based on the unary vector of the sample query question, the unary vector of the positive sample K-gram, and the unary vector of the negative sample K-gram includes: Determine the fourth similarity between the unary vector of the sample query problem and the unary vector of the positive sample K-tuple, and the fifth similarity between the unary vector of the sample query problem and the unary vector of the negative sample K-tuple; Based on the fourth and fifth similarities, the second loss function of the initial K-gram matching model is determined; The initial K-gram matching model is back-trained based on the first loss function and the second loss function; The enhancement processing performed on the third vector corresponding to the first relation in the sample query problem, the fourth vector corresponding to the second relation in the positive sample K-tuple, and the fifth vector corresponding to the third relation in the negative sample K-tuple, respectively, to obtain the unary vectors of the sample query problem, the positive sample K-tuple, and the negative sample K-tuple, includes: Noise is added to the third vector corresponding to the first head entity, the fourth vector corresponding to the second head entity, the fourth vector corresponding to the first tail entity, the fifth vector corresponding to the third head entity, and the fifth vector corresponding to the second tail entity to obtain their respective first update vectors. By combining the first update vector corresponding to the first head entity and the third vector corresponding to the first relation, a unary vector for the sample query problem is obtained; by combining the first update vector corresponding to the second head entity, the fourth vector corresponding to the second relation, and the first update vector corresponding to the first tail entity, a unary vector for the positive sample K-tuple is obtained; and by combining the first update vector corresponding to the third head entity, the fifth vector corresponding to the third relation, and the first update vector corresponding to the second tail entity, a unary vector for the negative sample K-tuple is obtained.
2. The method according to claim 1, characterized in that, The step of adding noise to the third vector corresponding to the first head entity, the fourth vector corresponding to the second head entity, the fourth vector corresponding to the first tail entity, the fifth vector corresponding to the third head entity, and the fifth vector corresponding to the second tail entity to obtain their respective first update vectors includes: The gradients of the third vector corresponding to the first head entity, the fourth vector corresponding to the second head entity, the fifth vector corresponding to the third head entity, the fourth vector corresponding to the first tail entity, and the fifth vector corresponding to the second tail entity are determined respectively, and their respective gradient values are obtained. The gradient values are added as noise to the third vector corresponding to the first head entity, the fourth vector corresponding to the second head entity, the fifth vector corresponding to the third head entity, the fourth vector corresponding to the first tail entity, and the fifth vector corresponding to the second tail entity, respectively, to obtain the corresponding first update vectors.
3. The method according to claim 1, characterized in that; The step of back-training the initial K-gram matching model based on the first loss function and the second loss function includes: The fourth vector corresponding to the first tail entity in the positive sample K-tuple and the fifth vector corresponding to the second tail entity in the negative sample K-tuple are weakened respectively to obtain the binary vector of the sample query problem, the binary vector of the positive sample K-tuple and the binary vector of the negative sample K-tuple. Determine the sixth similarity between the binary vector of the sample query problem and the binary vector of the positive sample K-tuple, and the seventh similarity between the binary vector of the sample query problem and the binary vector of the negative sample K-tuple; Based on the sixth similarity and the seventh similarity, the third loss function of the initial K-gram matching model is determined; The initial K-gram matching model is back-trained based on the first loss function, the second loss function, and the third loss function; this process is iterated until the cutoff condition is met to obtain the trained K-gram matching model.
4. The method according to claim 3, characterized in that, The step of weakening the fourth vector corresponding to the first tail entity in the positive sample K-tuple and the fifth vector corresponding to the second tail entity in the negative sample K-tuple to obtain the binary vector of the sample query problem, the binary vector of the positive sample K-tuple, and the binary vector of the negative sample K-tuple includes: Set the fourth vector corresponding to the first tail entity and the fifth vector corresponding to the second tail entity to zero respectively to obtain their respective second update vectors; By combining the third vector corresponding to the first head entity and the third vector corresponding to the first relation, a binary vector for the sample query problem is obtained; By combining the fourth vector corresponding to the second head entity, the fourth vector corresponding to the second relation, and the second update vector corresponding to the first tail entity, a binary vector of the positive sample K-tuple is obtained. Furthermore, by combining the fifth vector corresponding to the third head entity, the fifth vector corresponding to the third relation, and the second update vector corresponding to the second tail entity, the binary vector of the negative sample K tuple is obtained.
5. The method according to claim 3, characterized in that, The step of back-training the initial K-gram matching model based on the first loss function, the second loss function, and the third loss function includes: The first loss function, the second loss function, and the third loss function are weighted to obtain the target loss function; The initial K-ary matching model is back-trained based on the target loss function.
6. A graph-based question-and-answer device, characterized in that, include: The K-ary vector transformation module is used to vectorize the first query question as a whole to obtain the first vector. The K-gram matching module is used to determine the first similarity between the first vector and the second vector of each candidate K-gram; and to select candidate K-grams that satisfy the first similarity condition from each candidate K-gram as target K-grams that match the first query question; where K equals 3. The output module is used to output the entities in the target K-tuple as the answer; The sample K-tuples include positive sample K-tuples and negative sample K-tuples; the device is also used for: Data augmentation is performed on the second query question to obtain N extended query questions; wherein the second query question and the N extended query questions have the same semantics; N is greater than 0; the similarity between the second query question and the positive sample K-tuple is greater than a first threshold; the similarity between the second query question and the negative sample K-tuple is less than a second threshold; the first threshold is greater than or equal to the second threshold; The second query question and the N extended query questions are all treated as different sample query questions; The sample query problem, the positive sample K-tuple, and the negative sample K-tuple are treated as a whole and vectorized respectively to obtain their corresponding K-tuple vectors. Determine the second similarity between the K-gram vector of the sample query problem and the K-gram vector of the positive sample K-gram, and the third similarity between the K-gram vector of the sample query problem and the K-gram vector of the negative sample K-gram; Based on the second similarity and the third similarity, determine the first loss function of the initial K-gram matching model; Based on the first loss function, the initial K-gram matching model is back-trained; this process is iterated until the cutoff condition is met, resulting in a trained K-gram matching model. The step of back-training the initial K-gram matching model based on the first loss function includes: The first head entity and the first relation in the sample query problem are vectorized to obtain their respective third vectors; the second head entity, the second relation, and the first tail entity in the positive sample K-tuple are vectorized to obtain their respective fourth vectors; and the third head entity, the third relation, and the second tail entity in the negative sample K-tuple are vectorized to obtain their respective fifth vectors. The third vector corresponding to the first relation in the sample query problem, the fourth vector corresponding to the second relation in the positive sample K-tuple, and the fifth vector corresponding to the third relation in the negative sample K-tuple are respectively enhanced to obtain the unary vector of the sample query problem, the unary vector of the positive sample K-tuple, and the unary vector of the negative sample K-tuple. Based on the unary vector of the sample query problem, the unary vector of the positive sample K-tuple, and the unary vector of the negative sample K-tuple, the initial K-gram matching model is trained in reverse; this process is iterated until the cutoff condition is met to obtain the trained K-gram matching model. The step of back-training the initial K-gram matching model based on the unary vector of the sample query question, the unary vector of the positive sample K-gram, and the unary vector of the negative sample K-gram includes: Determine the fourth similarity between the unary vector of the sample query problem and the unary vector of the positive sample K-tuple, and the fifth similarity between the unary vector of the sample query problem and the unary vector of the negative sample K-tuple; Based on the fourth and fifth similarities, the second loss function of the initial K-gram matching model is determined; The initial K-gram matching model is back-trained based on the first loss function and the second loss function; The enhancement processing performed on the third vector corresponding to the first relation in the sample query problem, the fourth vector corresponding to the second relation in the positive sample K-tuple, and the fifth vector corresponding to the third relation in the negative sample K-tuple, respectively, to obtain the unary vectors of the sample query problem, the positive sample K-tuple, and the negative sample K-tuple, includes: Noise is added to the third vector corresponding to the first head entity, the fourth vector corresponding to the second head entity, the fourth vector corresponding to the first tail entity, the fifth vector corresponding to the third head entity, and the fifth vector corresponding to the second tail entity to obtain their respective first update vectors. By combining the first update vector corresponding to the first head entity and the third vector corresponding to the first relation, a unary vector for the sample query problem is obtained; by combining the first update vector corresponding to the second head entity, the fourth vector corresponding to the second relation, and the first update vector corresponding to the first tail entity, a unary vector for the positive sample K-tuple is obtained; and by combining the first update vector corresponding to the third head entity, the fifth vector corresponding to the third relation, and the first update vector corresponding to the second tail entity, a unary vector for the negative sample K-tuple is obtained.
7. An electronic device comprising a memory and a processor, the memory storing a computer program executable on the processor, characterized in that, When the processor executes the program, it implements the method according to any one of claims 1 to 5.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Response method and device
CN109359182A
Question and answer set extension method and device, electronic equipment and readable storage medium
CN111737399A