Question and answer method, device, storage medium and electronic device
By identifying target knowledge quadruples from temporal knowledge graphs and integrating temporal information, the accuracy of complex temporal questions in knowledge graph question answering is insufficient, thus improving the accuracy of response results.
Patent Information
- Application Number
- CN202210892480.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-27
- Publication Date
- 2025-11-21
- Estimated Expiration
- 2042-07-27
AI Technical Summary
When faced with complex time-series problems, existing technologies, such as knowledge graph question answering, struggle to obtain accurate answers.
By identifying target knowledge quadruples from a temporal knowledge graph, extracting temporal information and integrating it with the question, a question representation is generated to output response information.
It improves the accuracy of response results and enhances the precision of answer search by providing time references.
Smart Images

Figure CN115329056B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the technical field of information search, in particular, to a question answering method and device, a storage medium and an electronic device. BACKGROUND
[0002] A time sequence knowledge graph is a multi-relation knowledge graph. Compared with a conventional knowledge graph, a relation in the time sequence knowledge graph can also be associated with a time period. For example, there is a triple relation of “head entity-relation-tail entity” in the conventional knowledge graph, and in the time sequence knowledge graph, a time when the relation exists can also be included, thereby forming a knowledge quadruple of “head entity-relation-tail entity-time stamp”. Therefore, the time sequence knowledge graph can be composed of a plurality of knowledge quadruples.
[0003] A knowledge graph question answering task (KGQA) is to use a KG (Knowledge Graph) as a knowledge base to answer a natural language question. However, in the related art, when facing a complex time sequence question, the knowledge graph question answering can be difficult to obtain an accurate answer. SUMMARY
[0004] The purpose of the present disclosure is to provide a question answering method, device, storage medium and electronic device to solve the above-mentioned related technical problems.
[0005] To achieve the above-mentioned purpose, according to a first aspect of an embodiment of the present disclosure, a question answering method is provided, comprising:
[0006] In response to receiving a target question, determining a target knowledge quadruple from a time sequence knowledge graph according to the target question, a matching degree of the target knowledge quadruple and the target question satisfies a preset matching degree condition;
[0007] Extracting time information included in the target knowledge quadruple;
[0008] Fusing the target question and the time information to obtain a question representation;
[0009] Based on the question representation and the time sequence knowledge graph, outputting answer information of the target question.
[0010] Optionally, the step of determining a target knowledge quadruple from a time sequence knowledge graph according to the target question in response to receiving the target question comprises:
[0011] Obtaining a plurality of candidate knowledge quadruples from the time sequence knowledge graph;
[0012] Calculating a matching degree of each of the candidate knowledge quadruples and the target question;
[0013] The candidate knowledge quadruple with the highest matching degree is taken as the target knowledge quadruple.
[0014] Optionally, the obtaining of the candidate knowledge quadruples from the time sequence knowledge graph comprises:
[0015] determining a first encoding vector according to the target question;
[0016] determining a second encoding vector of each knowledge quadruple in the time sequence knowledge graph;
[0017] calculating the similarity between the first encoding vector and each second encoding vector;
[0018] taking the knowledge quadruple corresponding to the target second encoding vector with a higher similarity as the candidate knowledge quadruple.
[0019] Optionally, the calculating of the matching degree between each candidate knowledge quadruple and the target question comprises:
[0020] for each word in the target question, the following operations are performed:
[0021] obtaining a third encoding vector of the word and a target second encoding vector of a target candidate knowledge quadruple, wherein the target candidate knowledge quadruple is any one of the candidate knowledge quadruples;
[0022] calculating the gradient value between the third encoding vector and the target second encoding vector to obtain a first gradient value of the word;
[0023] The calculating of the matching degree between each candidate knowledge quadruple and the target question further comprises: performing weighted summation on the first gradient value of each word to obtain a second gradient value of the target question and the target candidate knowledge quadruple.
[0024] determining the matching degree between the target question and the target candidate knowledge quadruple according to the second gradient value.
[0025] Optionally, the determining of the matching degree between the target question and the target candidate knowledge quadruple according to the second gradient value comprises:
[0026] normalizing each calculated second gradient value;
[0027] taking the normalized result of the second gradient value of the target candidate knowledge quadruple as the matching degree between the target candidate knowledge quadruple and the target question.
[0028] Optionally, the fusing of the target question and the time information to obtain a question representation comprises:
[0029] extracting information from the target question and the target knowledge quadruple through an attention module to obtain a fourth encoding vector;
[0030] determining a target word in the target question that has the highest matching degree with the target knowledge quadruple;
[0031] setting a weight value for the target word and the time information, the weight value of the target word being less than the weight value of the time information;
[0032] adding the weight value and the time information to the fourth encoding vector to obtain the question representation.
[0033] Optionally, the extracting information from the target question and the target knowledge quadruple through an attention module to obtain a fourth encoding vector comprises:
[0034] for each word in the target question, the following operations are performed:
[0035] obtaining a third encoding vector of the word and a fifth encoding vector of the target knowledge quadruple;
[0036] extracting information from the third encoding vector and the fifth encoding vector based on an attention module to obtain a sixth encoding vector;
[0037] The extracting information from the target question and the target knowledge quadruple through an attention module further comprises: performing weighted summation on the sixth encoding vectors of the respective words to obtain the fourth encoding vector.
[0038] Optionally, the attention module comprises a connection attention module, a dot product attention module and a subtraction attention module, and the extracting information from the third encoding vector and the fifth encoding vector based on an attention module to obtain a sixth encoding vector comprises:
[0039] extracting information from the third encoding vector and the fifth encoding vector based on the connection attention module to obtain a first candidate encoding vector;
[0040] extracting information from the third encoding vector and the fifth encoding vector based on the dot product attention module to obtain a second candidate encoding vector;
[0041] extracting information from the third encoding vector and the fifth encoding vector based on the subtraction attention module to obtain a third candidate encoding vector;
[0042] performing weighted summation on the first candidate encoding vector, the second candidate encoding vector and the third candidate encoding vector to obtain the sixth encoding vector.
[0043] According to a second aspect of the embodiments of the present disclosure, a question answering device is provided, comprising:
[0044] A first determining module is configured to determine a target knowledge quadruple from the time sequence knowledge graph according to the target question in response to receiving the target question, wherein the matching degree of the target knowledge quadruple to the target question meets a preset matching degree condition;
[0045] A first extracting module is configured to extract time information included in the target knowledge quadruple;
[0046] A first fusing module is configured to fuse the target question and the time information to obtain a question representation;
[0047] An output module is configured to output answer information of the target question based on the question representation and the time sequence knowledge graph.
[0048] Optionally, the first determining module comprises:
[0049] A first obtaining sub-module is configured to obtain a plurality of candidate knowledge quadruples from the time sequence knowledge graph;
[0050] A first calculating sub-module is configured to calculate the matching degree of each candidate knowledge quadruple to the target question;
[0051] A first executing sub-module is configured to take the candidate knowledge quadruple with the highest matching degree as the target knowledge quadruple.
[0052] Optionally, the first obtaining sub-module comprises:
[0053] A first determining sub-unit is configured to determine a first encoding vector according to the target question;
[0054] A second determining sub-unit is configured to determine a second encoding vector of each knowledge quadruple in the time sequence knowledge graph;
[0055] A first calculating sub-unit is configured to calculate the similarity of the first encoding vector and each second encoding vector;
[0056] A first executing sub-unit is configured to take the knowledge quadruple corresponding to the target second encoding vector with higher similarity as the candidate knowledge quadruple.
[0057] Optionally, the first calculating sub-module comprises:
[0058] A second executing sub-module is configured to perform the following operation on each word in the target question:
[0059] obtaining a third encoding vector of the word and a target second encoding vector of a target candidate knowledge quadruple, wherein the target candidate knowledge quadruple is any knowledge quadruple in the plurality of candidate knowledge quadruples; calculating a gradient value of the third encoding vector and the target second encoding vector to obtain a first gradient value of the word;
[0060] The second calculation submodule is configured to perform weighted summation on the first gradient values of the respective words to obtain a second gradient value of the target question and the target candidate knowledge quadruple.
[0061] The first determination submodule is configured to determine a matching degree of the target question and the target candidate knowledge quadruple according to the second gradient value.
[0062] Optionally, the first determination submodule comprises:
[0063] The second calculation subunit is configured to perform normalization processing on the calculated respective second gradient values.
[0064] The second execution subunit is configured to take the normalization result of the second gradient value of the target candidate knowledge quadruple as the matching degree of the target candidate knowledge quadruple and the target question.
[0065] Optionally, the first fusion module comprises:
[0066] The information extraction submodule is configured to perform information extraction on the target question and the target knowledge quadruple by using an attention module to obtain a fourth encoding vector.
[0067] The second determination submodule is configured to determine a target word in the target question that has the highest matching degree with the target knowledge quadruple.
[0068] The third execution submodule is configured to set a weight value for the target word and the time information, wherein the weight value of the target word is less than the weight value of the time information.
[0069] The fusion submodule is configured to add the weight value and the time information to the fourth encoding vector to obtain the question representation.
[0070] Optionally, the information extraction submodule comprises:
[0071] The third execution subunit is configured to perform the following operations on each word in the target question:
[0072] obtaining a third encoding vector of the word and a fifth encoding vector of a target knowledge quadruple; and performing information extraction on the third encoding vector and the fifth encoding vector by using an attention module to obtain a sixth encoding vector.
[0073] The third calculation sub-unit performs weighted summation on the sixth encoding vectors of the respective words to obtain the fourth encoding vector.
[0074] Optionally, the attention module comprises a connection attention module, a point multiplication attention module and a subtraction attention module, and the third execution sub-unit is configured to:
[0075] perform information extraction on the third encoding vector and the fifth encoding vector based on the connection attention module to obtain a first candidate encoding vector;
[0076] perform information extraction on the third encoding vector and the fifth encoding vector based on the point multiplication attention module to obtain a second candidate encoding vector;
[0077] perform information extraction on the third encoding vector and the fifth encoding vector based on the subtraction attention module to obtain a third candidate encoding vector;
[0078] perform weighted summation on the first candidate encoding vector, the second candidate encoding vector and the third candidate encoding vector to obtain the sixth encoding vector.
[0079] According to a third aspect of the embodiments of the present disclosure, a computer readable storage medium is provided, which stores a computer program. The program is executed by a processor to implement the steps of the method according to any one of the first aspect.
[0080] According to a fourth aspect of the embodiments of the present disclosure, an electronic device is provided, which comprises:
[0081] a memory storing a computer program;
[0082] a processor configured to execute the computer program in the memory to implement the steps of the method according to any one of the first aspect.
[0083] The above technical solution, when receiving a target question, can obtain a target knowledge quadruple matched with the target question from a time sequence knowledge graph, and extract time information of the target knowledge quadruple. Since the target knowledge quadruple is matched with the target question, the time information in the target knowledge quadruple can be used as a time reference of the target question. In this way, the time information can be fused with the target question to obtain a question representation including time information, and according to the question representation and the time sequence knowledge graph, response information of the target question is output. That is, the above technical solution can extract time information implied in the target question and fuse the time information into the question representation, thereby providing a time reference for answer search. In this way, the accuracy of the response result can be improved.
[0084] Other features and advantages of the present disclosure will be made apparent from the following detailed description of the application. BRIEF DESCRIPTION OF DRAWINGS
[0085] The accompanying drawings are included to provide a further understanding of the present disclosure and constitute a part of the specification, illustrate embodiments of the present disclosure and together with the detailed description help to explain the present disclosure. In the drawings:
[0086] Figure 1 is a flowchart of a question and answer method according to an example embodiment of the present disclosure.
[0087] Figure 2 is a flowchart of determining a target knowledge quadruple according to an example embodiment of the present disclosure.
[0088] Figure 3 is an architecture diagram of a candidate knowledge quadruple selection model according to an example embodiment of the present disclosure.
[0089] Figure 4 is a flowchart of calculating a matching degree of a candidate knowledge quadruple and a target question according to an example embodiment of the present disclosure.
[0090] Figure 5 is a flowchart of fusing a target question and time information according to an example embodiment of the present disclosure.
[0091] Figure 6 is a flowchart of information extraction according to an example embodiment of the present disclosure.
[0092] Figure 7 is a block diagram of a question and answer device according to an example embodiment of the present disclosure.
[0093] Figure 8 is a block diagram of an electronic device 800 according to an example embodiment of the present disclosure. DETAILED DESCRIPTION
[0094] The detailed description of the present disclosure will be described below with reference to the accompanying drawings. It should be understood that the detailed description described herein is only used to explain and describe the present disclosure, and is not used to limit the present disclosure.
[0095] Before introducing the question and answer method, device, storage medium and electronic device of the present disclosure, the application scenario of the present disclosure is introduced first. The embodiments provided by the present disclosure can be used in various knowledge graph question and answer scenarios, such as customer service robots, voice assistants, search engines, recommendation systems, etc.
[0096] In a related scenario, the answer to a question can be searched through a knowledge graph. For example, for the question "Who was the captain of the Brazil football team before Neymar", the question can be informationally fused with the knowledge graph to obtain a search result. However, the present inventors have found that the accuracy of the result obtained by this processing manner is still low due to the fact that the question does not include time information. For example, the search result of the above question can be related to the entity in the question, such as "Neymar's time of taking office, the captain of the Brazil football team is XX", and the like, but it is difficult to obtain an accurate answer.
[0097] To this end, the present disclosure provides a question and answer method. The question and answer method can be applied to various stationary or mobile computing devices, such as servers, notebook computers, various wearable devices (wristbands, watches, glasses), and the like. Figure 1 is a flowchart of a question and answer method shown by the present disclosure, with reference to Figure 1 , the method comprises:
[0098] In step S11, in response to receiving a target question, a target knowledge quadruple is determined from a time sequence knowledge graph according to the target question.
[0099] The matching degree of the target knowledge quadruple and the target question meets a preset matching degree condition. For example, in some implementation scenarios, the preset matching degree condition can include that the matching degree of the target knowledge quadruple and the target question is the highest.
[0100] In this case, with reference to the determination flowchart of a target knowledge quadruple shown in Figure 2 , the determination of the target knowledge quadruple from the time sequence knowledge graph according to the target question (step S11) comprises:
[0101] Step S111, a plurality of candidate knowledge quadruples are obtained from the time sequence knowledge graph.
[0102] Exemplarily, in a possible implementation, the plurality of candidate knowledge quadruples are obtained from the time sequence knowledge graph (step S111), which comprises:
[0103] According to the target question, a first encoding vector is determined; a second encoding vector of each knowledge quadruple in the time sequence knowledge graph is determined; and the similarity of the first encoding vector and each second encoding vector is calculated.
[0104] The knowledge quadruple corresponding to the target second encoding vector with higher similarity is taken as the candidate knowledge quadruple.
[0105] As an example, the target question can be subjected to embedding processing to obtain the first encoding vector. Each knowledge quadruple in the time-series knowledge graph can also be subjected to embedding processing to obtain the second encoding vector. In this way, the similarity between the first encoding vector and each second encoding vector can be calculated, and the knowledge quadruple corresponding to the target second encoding vector with higher similarity can be selected as the candidate knowledge quadruple.
[0106] Here, the number of candidate knowledge quadruples can be set based on application requirements. As an example, 10 target second encoding vectors with higher similarity can be selected, and the knowledge quadruples corresponding to the 10 target second encoding vectors can be selected as the candidate knowledge quadruples.
[0107] In some implementation scenarios, the candidate knowledge quadruple selection model can also be used to obtain multiple candidate knowledge quadruples from the time-series knowledge graph. For example, referring to the architecture diagram of a candidate knowledge quadruple selection model shown in Figure 3 The candidate knowledge quadruple selection model can be a double-tower architecture, including network 1 and network 2.
[0108] Here, network 1 can be used to calculate the first encoding vector of the target question, and network 2 can be used to calculate the second encoding vector of each knowledge quadruple in the time-series knowledge graph. In network 1 and network 2, a DNN (Deep Neural Networks) module is also included to process the input data and obtain the corresponding representation vector. As an example, the DNN can use a BERT model. In this way, when processing the target question, the [CLS] and [SEP] symbols can be inserted at the beginning and end of the target question, respectively, and the processed target question can be input into network 1 to obtain the first encoding vector of the target question. In addition, the second encoding vector of the knowledge quadruple can also be obtained through network 2.
[0109] After obtaining the first encoding vector and the second encoding vector, the similarity between the first encoding vector and the second encoding vector can be calculated. For example, in the example of Figure 3 the similarity between the first encoding vector and the second encoding vector can be determined by cosine similarity calculation. Continuing with the above example, the 10 knowledge quadruples with higher similarity can be selected as the candidate knowledge quadruples.
[0110] In addition, it is worth noting that the similarity calculation process is exemplarily described in the above embodiments by means of cosine similarity calculation, but any feasible similarity calculation method can be applied in the candidate knowledge quadruple selection model, and the present disclosure does not limit this.
[0111] Still refer to Figure 2 In the case where multiple candidate knowledge quadruples are identified, in step S112, the matching degree between each candidate knowledge quadruple and the target problem is calculated.
[0112] Figure 4 This disclosure presents a flowchart illustrating the calculation of the matching degree between a candidate knowledge quadruple and the target problem, with reference to... Figure 4 The calculation process includes:
[0113] In step S41, for each word in the target question, the third encoding vector of the word and the target second encoding vector of the target candidate knowledge quadruple are obtained; the gradient values of the third encoding vector and the target second encoding vector are calculated to obtain the first gradient value of the word.
[0114] The target candidate knowledge quadruple is any one of the plurality of candidate knowledge quadruples.
[0115] Here, step S41 is illustrated with an example. The target question is "Who was the captain of the Brazil football team before Neymar?", and the candidate knowledge quadruple is:
[0116] 1.<Neymar,awarded,South American footballer,2012>
[0117] 2.<Brazil nationalteam,awarded,World Cupchampion,1970>
[0118] 3.<Miranda,joined,Brazil nationalteam,2007>
[0119] 4.<Neymar,awarded,FIFA Ference Puskas Award,2012>
[0120] 5.<Neymar,positionheld,captainof Brazil nationalteam,2014>
[0121] 6.<Dunga,coach,Brazil nationalteam,2014>
[0122] 7.<Neymar,joined,Barcelona,2013>
[0123] 8, <Brazil national team, awarded, World Cup champion, 1994>
[0124] 9, <Brazil national team, awarded, Confederations Cup, 2005>
[0125] 10, <Pimenta, coach, Brazil national team, 1937>
[0126] 11, <Neymar, joined, Paris Saint-Germain, 2017>
[0127] Take the target candidate knowledge quadruple as the candidate knowledge quadruple 1 as an example, when calculating the similarity between the target question and the candidate knowledge quadruple 1, the third encoding vector of each word in the target question can be calculated, and the target second encoding vector A of the candidate knowledge quadruple. For example, the third encoding vector of the word Neymar in the target question can be calculated, and the gradient value of the third encoding vector and the second encoding vector A is calculated to obtain the first gradient value corresponding to the word Neymar. In this way, the first gradient value of other words in the target question can also be calculated, and the present disclosure does not repeat it.
[0128] In step S42, the first gradient values of each word are weighted and summed to obtain the second gradient value of the target question and the target candidate knowledge quadruple.
[0129] Here, the weight values of each word can be equal, for example. In some implementation scenarios, those skilled in the art can also adjust the weight according to the application requirements, and the present disclosure does not limit it. Using the above example, by weighting and summing the first gradient values of each word, the second gradient value t1 of the target question "Who was the captain of the Brazil football team before Neymar" and the candidate knowledge quadruple <Neymar, awarded, South American footballer, 2012> can be obtained.
[0130] In addition, it should be understood that based on the method in the above example, the second gradient values of the target question and other candidate knowledge quadruples 2-11 can also be calculated respectively, and the corresponding second gradient values t2 to t11 can be obtained, and the present disclosure does not repeat it.
[0131] In step S43, the matching degree of the target question and the target candidate knowledge quadruple is determined according to the second gradient value.
[0132] For example, in a possible implementation, the calculated second gradient values can be normalized, and the normalized result of the second gradient value of the target candidate knowledge quadruple is taken as the matching degree of the target candidate knowledge quadruple and the target question.
[0133] Taking the above example, the second gradient values t1-t11 can be normalized, and the matching degrees of the target question and the candidate knowledge quadruples obtained are shown in Table 1:
[0134] Number Candidate knowledge quadruple Matching degree 1 <Neymar, awarded, South American footballer, 2012> 0 2 <Brazil national team, awarded, World Cup champion, 1970> 0.02 3 <Miranda, joined, Brazil national team, 2007> 0 4 <Neymar, awarded, FIFA Ference Puskas Award, 2012> 0.01 5 <Neymar, position held, captain of Brazil national team, 2014> 0.84 6 Dunga, coach, Brazil national team, 2014 0 7 <Neymar, joined, Barcelona, 2013> 0 8 <Brazil national team, awarded, World Cup champion, 1994> 0.11 9 <Brazil national team, awarded, Confederations Cup, 2005> 0.01 10 <Pimenta, coach, Brazil national team, 1937> 0 11 <Neymar, joined, Paris Saint-Germain, 2017> 0.01
[0135] Table 1
[0136] Please refer to Figure 2 After obtaining the matching degrees of the candidate knowledge quadruples and the target question, in step S113, the candidate knowledge quadruple with the highest matching degree is taken as the target knowledge quadruple.
[0137] Taking the above example of Table 1, the candidate knowledge quadruple <Neymar, position held, captain of Brazil national team, 2014> can be taken as the target knowledge quadruple.
[0138] It is worth noting that in the present disclosure, the preset matching degree condition satisfied by the matching degree of the target knowledge quadruple and the target question can be set according to application requirements. In some possible implementation scenarios, other candidate knowledge quadruples with higher matching degrees can also be selected as the target knowledge quadruple. In some possible implementation scenarios, a matching degree threshold can also be set, so that the candidate knowledge quadruple with a matching degree greater than the matching degree threshold is selected as the target candidate knowledge quadruple, and the present disclosure does not limit this.
[0139] Still referring to Figure 1 In step S12, the time information included in the target knowledge quadruple is extracted.
[0140] In step S13, the target question and the time information are fused to obtain a question representation.
[0141] Figure 5 is a fusion process diagram of a target question and time information shown in the present disclosure, as Figure 5 As shown, the fusion of the target question and the time information to obtain a question representation (step S13) includes:
[0142] In step S131, information extraction is performed on the target question and the target knowledge quadruple by the attention module to obtain a fourth encoding vector.
[0143] Here, referring to the flowchart of information extraction shown in FIG. 13, the information extraction performed on the target question and the target knowledge quadruple by the attention module to obtain a fourth encoding vector (step S131) can include: Figure 6
[0144] S61, for each word in the target question, obtaining a third encoding vector of the word and a fifth encoding vector of the target knowledge quadruple; and performing information extraction on the third encoding vector and the fifth encoding vector by the attention module to obtain a sixth encoding vector.
[0145] In the example of Table 1, when calculating the similarity between the target question and the target knowledge quadruple (i.e., the candidate knowledge quadruple 5), the third encoding vector of each word in the target question and the fifth encoding vector of the candidate knowledge quadruple 5 can be calculated. For example, the third encoding vector of the word Neymar can be calculated, and the third encoding vector of the word Neymar and the fifth encoding vector can be extracted by the dot product attention module to obtain the sixth encoding vector of the word Neymar.
[0146] Correspondingly, the third encoding vector of other words in the target question and the fifth encoding vector can also be extracted in this way to obtain the sixth encoding vector of the word.
[0147] It should be noted that in the above example, the dot product attention module is taken as an example to illustrate the information extraction manner of the third encoding vector and the fifth encoding vector. However, those skilled in the art should know that in specific implementation, the attention module can also be other attention modules, such as connection attention module, subtraction attention module, etc. In some implementation scenarios, multiple attention modules can also be combined for use.
[0148] For example, in a possible implementation, the attention module includes a connection attention module, a dot product attention module, and a subtraction attention module. In this case, the information extraction performed on the third encoding vector and the fifth encoding vector by the attention module to obtain a sixth encoding vector includes:
[0149] The connection attention module is used for information extraction on the third encoding vector and the fifth encoding vector to obtain a first candidate encoding vector; the point multiplication attention module is used for information extraction on the third encoding vector and the fifth encoding vector to obtain a second candidate encoding vector; and the subtraction attention module is used for information extraction on the third encoding vector and the fifth encoding vector to obtain a third candidate encoding vector.
[0150] The first candidate encoding vector, the second candidate encoding vector and the third candidate encoding vector are weighted and summed to obtain the sixth encoding vector.
[0151] For example, the third encoding vector of the word Neymar and the fifth encoding vector can be subjected to information extraction by the connection attention module to obtain a first candidate encoding vector of the word Neymar; the third encoding vector of the word Neymar and the fifth encoding vector can be subjected to information extraction by the point multiplication attention module to obtain a second candidate encoding vector of the word Neymar; and the third encoding vector of the word Neymar and the fifth encoding vector can be subjected to information extraction by the subtraction attention module to obtain a third candidate encoding vector of the word Neymar. In this way, the first candidate encoding vector, the second candidate encoding vector and the third candidate encoding vector can be weighted and summed to obtain the sixth encoding vector. The weights of the respective attention modules can be equal. In this way, information extraction can be performed in combination of the respective attention modules, which helps to improve the accuracy of information extraction. In some possible implementation scenarios, the weights of the respective attention modules can also be unequal based on the requirements of an application scenario. Those skilled in the art can select and set the weights based on application requirements, and the present disclosure does not limit this.
[0152] S62, the sixth encoding vectors of the respective words are weighted and summed to obtain the fourth encoding vector.
[0153] Feature extraction by the attention module can filter out interference information in the target question and the target knowledge quadruple, and reduce the proportion of the interference information in the fourth encoding vector.
[0154] Referring to Figure 5 In step S132, the target word in the target question that has the highest matching degree with the target knowledge quadruple is determined.
[0155] Here, for example, the matching degrees of each word in the target question and the target knowledge quadruple can be calculated, and the word with the highest matching degree can be taken as the target word. When determining the matching degree of a word and the target knowledge quadruple, the gradient of the third encoding vector of the word and the fifth encoding vector of the target knowledge quadruple can be calculated, and the matching degree of the word and the target knowledge quadruple can be determined according to the calculated gradient value. In some embodiments, the gradient values of each word calculated can also be normalized, and the normalized result of the gradient value of each word can be taken as the matching degree of the word and the target knowledge quadruple.
[0156] In step S133, a weight value is set for the target word and the time information, and the weight value of the target word is less than the weight value of the time information.
[0157] Here, the weight value can be determined based on the matching degree of the target word and the target knowledge quadruple, for example. In the example of Table 1, the target word is Neymar, and the matching degree of Neymar and the target knowledge quadruple <Neymar, position held, captain of Brazil national team, 2014> is 91%. When setting the weight, the weight value of the time information can be set to 91%, and the weight value of the target word Neymar in the target question can be set to 9%.
[0158] In step S134, the weight value and the time information are added to the fourth encoding vector to obtain the question representation.
[0159] Here, for example, information fusion can be performed in combination with a gating mechanism, so that the time information in the target knowledge quadruple can be fused into the question representation, and the integration of interference information can be reduced. In this way, the weight of the word Neymar in the target question is reduced, and the time information with a higher weight is introduced. In this way, the focus of the search target is changed from “Who was the captain of the Brazil football team before Neymar” to “Who was the captain of the Brazil football team before 2014”.
[0160] In step S14, the answer information of the target question is output based on the question representation and the time sequence knowledge graph.
[0161] For example, the question representation and the time sequence knowledge graph can be input into a Multilayer Perceptron (MLP) module to obtain the answer information of the target question and output the answer information of the target question. For the way of generating the question and answer result by the Multilayer Perceptron, please refer to the description in the related art, and the present disclosure will not repeat it for the sake of brevity of the description.
[0162] The above technical solution can obtain the target knowledge quadruple matched with the target question from the time sequence knowledge graph and extract the time information of the target knowledge quadruple when receiving the target question. Since the target knowledge quadruple is matched with the target question, the time information in the target knowledge quadruple can be used as the time reference of the target question. In this way, the time information can be fused with the target question to obtain a question representation including time information, and the answer information of the target question can be output according to the question representation and the time sequence knowledge graph. That is, the above technical solution can extract the time information implied in the target question and fuse the time information into the question representation to provide a time reference for answer search. In this way, the accuracy of the answer result can be improved.
[0163] Based on the same inventive concept, the present disclosure further provides a question and answer device. Figure 7 is a block diagram of a question and answer device shown by the present disclosure, referring to Figure 7 , the question and answer device comprises:
[0164] The first determination module 701 is configured to determine a target knowledge quadruple from a time sequence knowledge graph according to a target question in response to receiving the target question, and the matching degree of the target knowledge quadruple with the target question meets a preset matching degree condition.
[0165] The first extraction module 702 is configured to extract time information included in the target knowledge quadruple.
[0166] The first fusion module 703 is configured to fuse the target question with the time information to obtain a question representation.
[0167] The output module 704 is configured to output the answer information of the target question based on the question representation and the time sequence knowledge graph.
[0168] The technical solution can obtain a target knowledge quadruple matched with the target question from the time sequence knowledge graph and extract time information of the target knowledge quadruple when receiving the target question. Since the target knowledge quadruple is matched with the target question, the time information in the target knowledge quadruple can be used as a time reference of the target question. In this way, the time information can be fused with the target question to obtain a question representation including the time information, and the answer information of the target question can be output according to the question representation and the time sequence knowledge graph. That is, the technical solution can extract the time information implied in the target question and fuse the time information into the question representation, thereby providing a time reference for answer searching. In this way, the accuracy of the answer result can be improved.
[0169] Optionally, the first determining module 701 comprises:
[0170] a first obtaining sub-module, configured to obtain a plurality of candidate knowledge quadruples from the time sequence knowledge graph;
[0171] a first calculating sub-module, configured to calculate a matching degree of each of the candidate knowledge quadruples with the target question;
[0172] a first executing sub-module, configured to take the candidate knowledge quadruple with the highest matching degree as the target knowledge quadruple.
[0173] Optionally, the first obtaining sub-module comprises:
[0174] a first determining sub-unit, configured to determine a first encoding vector according to the target question;
[0175] a second determining sub-unit, configured to determine a second encoding vector of each knowledge quadruple in the time sequence knowledge graph;
[0176] a first calculating sub-unit, configured to calculate a similarity between the first encoding vector and each second encoding vector;
[0177] a first executing sub-unit, configured to take the knowledge quadruple corresponding to the target second encoding vector with a higher similarity as the candidate knowledge quadruple.
[0178] Optionally, the first calculating sub-module comprises:
[0179] a second executing sub-module, configured to perform the following operation on each word in the target question:
[0180] obtaining a third encoding vector of the word and a target second encoding vector of a target candidate knowledge quadruple, wherein the target candidate knowledge quadruple is any knowledge quadruple in the plurality of candidate knowledge quadruples; calculating a gradient value of the third encoding vector and the target second encoding vector to obtain a first gradient value of the word;
[0181] The second calculation submodule is configured to perform weighted summation on the first gradient values of the respective words to obtain a second gradient value of the target question and the target candidate knowledge quadruple.
[0182] The first determination submodule is configured to determine a matching degree of the target question and the target candidate knowledge quadruple according to the second gradient value.
[0183] Optionally, the first determination submodule comprises:
[0184] The second calculation subunit is configured to perform normalization processing on the calculated respective second gradient values.
[0185] The second execution subunit is configured to take the normalization result of the second gradient value of the target candidate knowledge quadruple as the matching degree of the target candidate knowledge quadruple and the target question.
[0186] Optionally, the first fusion module 703 comprises:
[0187] The information extraction submodule is configured to perform information extraction on the target question and the target knowledge quadruple by using an attention module to obtain a fourth encoding vector.
[0188] The second determination submodule is configured to determine a target word in the target question that has the highest matching degree with the target knowledge quadruple.
[0189] The third execution submodule is configured to set a weight value for the target word and the time information, wherein the weight value of the target word is less than the weight value of the time information.
[0190] The fusion submodule is configured to add the weight value and the time information to the fourth encoding vector to obtain the question representation.
[0191] Optionally, the information extraction submodule comprises:
[0192] The third execution subunit is configured to perform the following operations on each word in the target question:
[0193] obtaining a third encoding vector of the word and a fifth encoding vector of a target knowledge quadruple; and performing information extraction on the third encoding vector and the fifth encoding vector by using an attention module to obtain a sixth encoding vector.
[0194] The third calculation sub-unit performs weighted summation on the sixth encoding vectors of the respective words to obtain the fourth encoding vector.
[0195] Optionally, the attention module comprises a connection attention module, a point multiplication attention module, and a subtraction attention module, and the third execution sub-unit is configured to:
[0196] perform information extraction on the third encoding vector and the fifth encoding vector based on the connection attention module to obtain a first candidate encoding vector;
[0197] perform information extraction on the third encoding vector and the fifth encoding vector based on the point multiplication attention module to obtain a second candidate encoding vector;
[0198] perform information extraction on the third encoding vector and the fifth encoding vector based on the subtraction attention module to obtain a third candidate encoding vector;
[0199] perform weighted summation on the first candidate encoding vector, the second candidate encoding vector, and the third candidate encoding vector to obtain the sixth encoding vector.
[0200] As to the device in the above-mentioned embodiments, the specific manner in which each module performs operations has been described in detail in the embodiments related to the method, and thus will not be described in detail here.
[0201] The present disclosure also provides a computer readable storage medium having stored thereon a computer program, which, when executed by a processor, implements the steps of the question and answer method provided by the present disclosure.
[0202] The present disclosure also provides an electronic device comprising:
[0203] a memory having stored thereon a computer program;
[0204] a processor configured to execute the computer program in the memory to implement the steps of the question and answer method provided by the present disclosure.
[0205] Figure 8 is a block diagram of an electronic device 800 according to an exemplary embodiment. As shown, the electronic device 800 can include a processor 801 and a memory 802. The electronic device 800 can also include one or more of a multimedia component 803, an input / output (I / O) interface 804, and a communication component 805. Figure 8
[0206] The processor 801 is configured to control overall operations of the electronic device 800 to complete all or part of the steps of the above-described question and answer method. The memory 802 is configured to store various types of data to support operations of the electronic device 800, which can include, for example, instructions for any application or method operating on the electronic device 800, and application-related data, such as contact data, transmitted and received messages, pictures, audio, video, and the like. The memory 802 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as a static random access memory (SRAM), an electrically erasable programmable read-only memory (EEPROM), an erasable programmable read-only memory (EPROM), a programmable read-only memory (PROM), a read-only memory (ROM), a magnetic storage, a flash memory, a magnetic disk, or an optical disk. The multimedia component 803 can include a screen and an audio component. The screen can be, for example, a touch screen, and the audio component is configured to output and / or input audio signals. For example, the audio component can include a microphone configured to receive external audio signals. The received audio signals can be further stored in the memory 802 or transmitted through the communication component 805. The audio component further includes at least one speaker configured to output audio signals. The I / O interface 804 provides an interface between the processor 801 and other interface modules, which can be a keyboard, a mouse, a button, and the like. The buttons can be virtual buttons or physical buttons. The communication component 805 is configured to perform wired or wireless communication between the electronic device 800 and other devices. The wireless communication, such as Wi-Fi, Bluetooth, near field communication (NFC), 2G, 3G, 4G, NB-IOT, eMTC, or other 5G, and the like, or a combination of one or more of them, is not limited herein. Therefore, the communication component 805 can include, for example, a Wi-Fi module, a Bluetooth module, an NFC module, and the like.
[0207] In an exemplary embodiment, the electronic device 800 can be implemented by one or more Application Specific Integrated Circuits (ASICs), Digital Signal Processors (DSPs), Digital Signal Processing Devices (DSPDs), Programmable Logic Devices (PLDs), Field Programmable Gate Arrays (FPGAs), controllers, micro-controllers, microprocessors, or other electronic elements for performing the above-described question and answer method.
[0208] In another exemplary embodiment, a computer-readable storage medium including program instructions is also provided, which, when executed by a processor, implement the steps of the above-described question and answer method. For example, the computer-readable storage medium can be the above-described memory 802 including program instructions, which can be executed by the processor 801 of the electronic device 800 to complete the above-described question and answer method.
[0209] In another exemplary embodiment, a computer program product is also provided, which contains a computer program capable of being executed by a programmable device, and the computer program has code portions for executing the above-described question and answer method when executed by the programmable device.
[0210] The preferred embodiments of the present disclosure are described in detail above with reference to the accompanying drawings, but the present disclosure is not limited to the specific details in the above-described embodiments. Within the technical concept scope of the present disclosure, various simple modifications can be made to the technical solutions of the present disclosure, and all these simple modifications shall be considered as falling within the protection scope of the present disclosure.
[0211] In addition, it should be noted that each specific technical feature described in the above-described specific embodiments can be combined in any appropriate manner without contradiction, and in order to avoid unnecessary repetition, the present disclosure will not further describe various possible combination manners.
[0212] Furthermore, any combination of various different embodiments of the present disclosure can also be made, as long as it does not deviate from the idea of the present disclosure, and it shall be considered as disclosed by the present disclosure.
Claims
1. A question and answer method, characterized by, The method comprises the following steps: in response to receiving a target question, determining a target knowledge quadruple from a time sequence knowledge graph according to the target question, the matching degree of the target knowledge quadruple with the target question meeting a preset matching degree condition; extracting time information included in the target knowledge quadruple; fusing the target question and the time information to obtain a question representation; outputting response information of the target question based on the question representation and the time sequence knowledge graph; the step of fusing the target question and the time information to obtain a question representation comprises: extracting information of the target question and the target knowledge quadruple through an attention module to obtain a fourth encoding vector; determining a target word in the target question with the highest matching degree with the target knowledge quadruple; setting weight values for the target word and the time information, the weight value of the target word being less than the weight value of the time information; adding the weight values and the time information to the fourth encoding vector to obtain the question representation; the step of extracting information of the target question and the target knowledge quadruple through an attention module to obtain a fourth encoding vector comprises: for each word in the target question, the following operations are performed: obtaining a third encoding vector of the word and a fifth encoding vector of the target knowledge quadruple; extracting information of the third encoding vector and the fifth encoding vector based on an attention module to obtain a sixth encoding vector; the step of extracting information of the target question and the target knowledge quadruple through an attention module further comprises: performing weighted summation on the sixth encoding vectors of the words to obtain the fourth encoding vector.
2. The method of claim 1, wherein, the step of determining a target knowledge quadruple from a time sequence knowledge graph according to a target question in response to receiving the target question comprises: obtaining a plurality of candidate knowledge quadruples from the time sequence knowledge graph; calculating the matching degree of each candidate knowledge quadruple with the target question; taking the candidate knowledge quadruple with the highest matching degree as the target knowledge quadruple.
3. The method of claim 2, wherein, the step of obtaining a plurality of candidate knowledge quadruples from the time sequence knowledge graph comprises: determining a first encoding vector according to the target question; determining a second encoding vector of each knowledge quadruple in the time sequence knowledge graph; calculating the similarity of the first encoding vector and each second encoding vector; taking the knowledge quadruple corresponding to the target second encoding vector with higher similarity as the candidate knowledge quadruple.
4. The method of claim 2, wherein, the step of calculating the matching degree of each candidate knowledge quadruple with the target question comprises: for each word in the target question, the following operations are performed: obtaining a third encoding vector of the word and a target second encoding vector of a target candidate knowledge quadruple, wherein the target candidate knowledge quadruple is any knowledge quadruple in the plurality of candidate knowledge quadruples; calculating the gradient value of the third encoding vector and the target second encoding vector to obtain a first gradient value of the word; The calculating the matching degree of each candidate knowledge quadruple and the target question further includes: performing weighted summation on the first gradient values of each word to obtain a second gradient value of the target question and the target candidate knowledge quadruple; The matching degree of the target question and the target candidate knowledge quadruple is determined according to the second gradient value.
5. The method of claim 4, wherein, The determining the matching degree of the target question and the target candidate knowledge quadruple according to the second gradient value includes: performing normalization processing on each calculated second gradient value; the normalization result of the second gradient value of the target candidate knowledge quadruple is taken as the matching degree of the target candidate knowledge quadruple and the target question.
6. The method of claim 1, wherein, The attention module includes a connection attention module, a point multiplication attention module, and a subtraction attention module. The information extraction of the third encoding vector and the fifth encoding vector based on the attention module obtains a sixth encoding vector, including: information extraction of the third encoding vector and the fifth encoding vector based on the connection attention module obtains a first candidate encoding vector; information extraction of the third encoding vector and the fifth encoding vector based on the point multiplication attention module obtains a second candidate encoding vector; information extraction of the third encoding vector and the fifth encoding vector based on the subtraction attention module obtains a third candidate encoding vector; weighted summation of the first candidate encoding vector, the second candidate encoding vector, and the third candidate encoding vector obtains the sixth encoding vector.
7. A question and answer apparatus characterized by comprising: including: The first determination module is configured to determine a target knowledge quadruple from the time sequence knowledge graph according to the target question in response to receiving the target question, and the matching degree of the target knowledge quadruple and the target question satisfies a preset matching degree condition. The first extraction module is configured to extract time information included in the target knowledge quadruple. The first fusion module is configured to fuse the target question and the time information to obtain a question representation. The fusion of the target question and the time information to obtain a question representation includes: information extraction of the target question and the target knowledge quadruple through an attention module obtains a fourth encoding vector; determining a target word in the target question with the highest matching degree with the target knowledge quadruple; setting a weight value for the target word and the time information, and the weight value of the target word is less than the weight value of the time information; adding the weight value and the time information to the fourth encoding vector to obtain the question representation. The information extraction of the target question and the target knowledge quadruple through an attention module to obtain a fourth encoding vector includes: for each word in the target question, the following operations are performed: obtaining a third encoding vector of the word and a fifth encoding vector of the target knowledge quadruple; information extraction of the third encoding vector and the fifth encoding vector based on an attention module obtains a sixth encoding vector; The information extraction of the target question and the target knowledge quadruple through an attention module further includes: performing weighted summation on the sixth encoding vectors of the respective words to obtain the fourth encoding vector; an output module, configured to output response information of the target question based on the question representation and the time knowledge graph.
8. A computer-readable storage medium having stored thereon a computer program, characterized in that, The program, when executed by a processor, implements the steps of the method of any one of claims 1 to 6.
9. An electronic device, comprising: comprising: a memory having stored thereon a computer program; a processor configured to execute the computer program in the memory to implement the steps of the method of any one of claims 1 to 6.
Citation Information
Patent Citations
Method and equipment for constructing intelligent question-answering system through question generation data set
CN112100351A
Time knowledge graph inference method based on representation learning
CN113742491A