Knowledge reasoning method and device, electronic equipment and storage medium
By constructing triples and using preset templates to score candidate knowledge, and combining this with a reasoning model for knowledge reasoning, the problems of low knowledge relevance and low pre-training efficiency in common sense reasoning tasks are solved, achieving more efficient and accurate knowledge reasoning.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- IFLYTEK CO LTD
- Filing Date
- 2022-12-29
- Publication Date
- 2026-06-09
Smart Images

Figure CN115965083B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of knowledge reasoning technology, and in particular to a knowledge reasoning method, apparatus, electronic device, and storage medium. Background Technology
[0002] Commonsense Reasoning aims to help machines acquire common-sense knowledge and utilize existing relevant knowledge to perform deeper semantic understanding and logical reasoning.
[0003] In existing technologies, compared to extractive reading comprehension tasks, commonsense reasoning tasks do not provide any background knowledge about the questions or the original text containing the answers. Machines can only use their own knowledge learned from pre-training tasks to perform reasoning based on the questions. For example, CommonsenseQA1.0 is a multiple-choice commonsense question answering task, where the questions and their answer candidates come from subgraphs extracted from the knowledge graph ConceptNet. CommonsenseQA2.0, on the other hand, is a yes / no commonsense question answering task, which collects error-prone questions through crowdsourcing and adversarial interaction with the model. Compared to CommonsenseQA1.0, the questions are more difficult and open-ended.
[0004] However, existing technologies for common sense reasoning tasks suffer from low knowledge relevance and inefficient model pre-training due to the fusion of large amounts of knowledge for reasoning. Summary of the Invention
[0005] This invention provides a knowledge reasoning method, apparatus, electronic device, and storage medium to address the shortcomings of existing technologies in common sense reasoning tasks, such as low knowledge relevance and low efficiency in model pre-training when integrating a large amount of knowledge for reasoning.
[0006] This invention provides a knowledge reasoning method, comprising:
[0007] Based on the problem to be reasoned, as well as the relevant knowledge and candidate answers to the problem, a triplet is constructed;
[0008] The triples are scored, and candidate knowledge is determined from the relevant knowledge based on the scores of the triples.
[0009] Based on the problem to be reasoned and the candidate knowledge, knowledge reasoning is performed.
[0010] According to a knowledge reasoning method provided by the present invention, scoring the triples includes:
[0011] Fill the triplet into a preset template to obtain the logical statement corresponding to the triplet;
[0012] The logical statements are scored;
[0013] The preset template is used to connect the logical relationship between the question to be reasoned, the relevant knowledge, and the candidate answers.
[0014] According to a knowledge reasoning method provided by the present invention, the knowledge reasoning based on the problem to be reasoned and the candidate knowledge includes:
[0015] Based on the reasoning model, knowledge reasoning is performed using the problem to be reasoned and the candidate knowledge.
[0016] The reasoning model is trained based on the sample question, the candidate knowledge of the sample question, and the labeled answer of the sample question.
[0017] According to a knowledge reasoning method provided by the present invention, the training steps of the reasoning model include:
[0018] Based on knowledge-question pairs, a question-knowledge association model is trained, wherein the knowledge-question pairs include related knowledge and questions;
[0019] Based on the sample question, the candidate knowledge of the sample question, and the labeled answer of the sample question, the question knowledge association model is trained to obtain the reasoning model.
[0020] According to a knowledge reasoning method provided by the present invention, the step of training a question knowledge association model based on the sample question, candidate knowledge of the sample question, and labeled answers of the sample question to obtain the reasoning model includes:
[0021] Based on the question knowledge association model, target knowledge is determined from the candidate knowledge of the sample question, and a predicted answer is generated based on the sample question and the target knowledge.
[0022] Based on the predicted answer and the labeled answer, the first relevance between the target knowledge and the sample question, and the second relevance between the candidate knowledge (excluding the target knowledge) and the sample question, the parameters of the question knowledge association model are iterated to obtain the inference model.
[0023] According to a knowledge reasoning method provided by the present invention, the method involves iterating parameters of a question knowledge association model based on a first correlation between the predicted answer and the labeled answer, the target knowledge and the sample question, and a second correlation between candidate knowledge (excluding the target knowledge) and the sample question, to obtain the reasoning model, comprising:
[0024] The inference loss is determined based on the difference between the predicted answer and the labeled answer;
[0025] The ranking loss is determined based on the differences between the first relevance and the second relevance, the differences between the first relevance and the third relevance, and the differences between the second relevance and the third relevance; the third relevance is the relevance between irrelevant knowledge of the sample question and the sample question.
[0026] Based on the inference loss and the ranking loss, the parameters of the problem knowledge association model are iterated to obtain the inference model.
[0027] According to a knowledge reasoning method provided by the present invention, the knowledge question pair includes a first knowledge question pair and a second knowledge question pair, wherein the first knowledge question pair includes the sample question and the target knowledge of the sample question, and the target knowledge is the candidate knowledge most relevant to the sample question;
[0028] The second knowledge problem pair includes recommendation problems similar to the sample problem, as well as the target knowledge of the sample problem.
[0029] The present invention also provides a knowledge reasoning device, comprising:
[0030] Construct triplet units to build triplets based on the problem to be reasoned, as well as the relevant knowledge and candidate answers to the problem to be reasoned;
[0031] A determining unit is used to score the triples and, based on the scores of the triples, determine candidate knowledge from the relevant knowledge;
[0032] The knowledge reasoning unit is used to perform knowledge reasoning based on the problem to be reasoned and the candidate knowledge.
[0033] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the knowledge reasoning method as described above.
[0034] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the knowledge reasoning method as described above.
[0035] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the knowledge reasoning method as described above.
[0036] The knowledge reasoning method, apparatus, electronic device, and storage medium provided by this invention construct triples based on the problem to be reasoned, as well as related knowledge and candidate answers to the problem. The triples are scored, and candidate knowledge is determined from the related knowledge based on the scores of the triples. Thus, the candidate knowledge obtained is knowledge that is highly relevant to the problem to be reasoned. Then, based on the problem to be reasoned and the candidate knowledge, knowledge reasoning is performed, which reduces the amount of computation in subsequent knowledge reasoning, improves the efficiency of knowledge reasoning, and further improves the accuracy and reliability of knowledge reasoning. Attached Figure Description
[0037] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0038] Figure 1 This is a flowchart illustrating the knowledge reasoning method provided by the present invention;
[0039] Figure 2 This is a schematic diagram of the process for scoring triples provided by the present invention;
[0040] Figure 3 This is a flowchart illustrating the training steps of the inference model provided by the present invention;
[0041] Figure 4 This is a flowchart illustrating step 320 in the knowledge reasoning method provided by the present invention;
[0042] Figure 5 This is a flowchart illustrating step 322 in the knowledge reasoning method provided by the present invention;
[0043] Figure 6 This is a schematic diagram of the knowledge reasoning device provided by the present invention;
[0044] Figure 7 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0045] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0046] The terms "first," "second," etc., used in the specification and claims of this invention are used to distinguish similar objects and are not used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and that the objects distinguished by "first," "second," etc., are generally of the same class.
[0047] Among related technologies, the emergence of the Transformer neural network has led to a surge of pre-trained models. Its unique self-attention mechanism and self-supervised learning tasks on large-scale corpora offer more efficient reasoning performance in language understanding compared to traditional RNNs (Recurrent Neural Networks). Furthermore, the scale of pre-trained models has expanded from millions of parameters in BERT (Bidirectional Encoder Representations from Transformer) models to hundreds of billions of parameters in GPT-3 (Generative Pre-trained Transformer 3) models. Researchers have found that the models' knowledge reserves and reasoning abilities have also improved accordingly. Therefore, methods such as expanding the scale of pre-trained models and pre-training on large-scale relevant corpora or tasks are highly favored in the field of commonsense reasoning.
[0048] Existing commonsense reasoning tasks are implemented using pre-trained models based on knowledge fusion. In CommonsenseQA 1.0, based on the characteristics of the problem constructed using ConceptNet, relevant triples were extracted from the graph and noun definitions from wikis as relevant background knowledge, and a BERT pre-trained model was used for knowledge fusion reasoning. In CommonsenseQA 2.0, the implicit knowledge and reasoning ability of small models could not achieve satisfactory results. Therefore, existing technologies all choose large-scale models with hundreds of billions of parameters, such as T5 (Text-to-Text Transfer Transformer), for reasoning. However, relying solely on the implicit knowledge of the model still yields unsatisfactory results. Therefore, fusing knowledge retrieved from multiple knowledge sources for fusion reasoning is currently the mainstream approach.
[0049] In related technologies, due to the diversity and complexity of knowledge sources, the relevance of knowledge to the question and whether the knowledge can answer the question are all worth considering. Because of the limited coverage of knowledge sources and the limited capabilities of retrieval and matching algorithms, especially since CommonsenseQA2.0 includes some open-ended and even long-tailed questions, it is difficult to retrieve relevant information from conventional knowledge graphs or dictionaries. For example, the question "The hole in a sponge is larger than the hole in a needle" cannot be retrieved by relevant knowledge graphs or even search engines; often, very low-relevance knowledge is retrieved. When fusing such knowledge, it obviously interferes with model inference. Furthermore, supervised training based on a large-scale pre-trained model requires significant computational resources and time, and fusing a large number of complex knowledge-related questions will obviously consume even more training resources, resulting in low training and inference efficiency.
[0050] To address the above problems, this invention provides a knowledge reasoning method. Figure 1 This is a flowchart illustrating the knowledge reasoning method provided by the present invention, as shown below. Figure 1 As shown, the method includes:
[0051] Step 110: Construct triples based on the problem to be reasoned, the relevant knowledge of the problem to be reasoned, and the candidate answers.
[0052] Specifically, triples can be constructed based on the question to be reasoned, as well as related knowledge and candidate answers to the question. The question to be reasoned here refers to the question that requires subsequent knowledge reasoning. The question to be reasoned can be directly input by the user, or it can be obtained by transcribing the collected audio, or it can be obtained by capturing images through image acquisition devices such as scanners, mobile phones, cameras, and tablets and performing OCR (Optical Character Recognition) on the images. This embodiment of the invention does not specifically limit this.
[0053] The relevant knowledge of the problem to be reasoned refers to the knowledge related to the problem to be reasoned. The relevant knowledge of the problem to be reasoned can be obtained based on common sense knowledge bases and dictionaries, or it can be obtained based on the results of the problem to be reasoned and the corresponding answers of similar problems to the problem to be reasoned ... based on common sense knowledge bases, dictionaries, and the results of the problem to be reasoned and the corresponding answers of similar problems to the problem to be reasoned. The embodiments of the present invention do not make specific limitations in this regard.
[0054] The relevant knowledge for the problem to be reasoned here can be one or more, and the embodiments of the present invention do not specifically limit this.
[0055] Here, based on common sense knowledge base and dictionary, relevant knowledge of the problem to be reasoned is obtained. First, lexical analysis tools can be used to extract keywords from the problem to be reasoned. For example, verbs, nouns and phrases in the problem to be reasoned can be extracted. The lexical analysis tool here can be Spacy, Stanford CoreNLP, or Analyzer, etc. The embodiments of the present invention do not make specific limitations on this.
[0056] After extracting keywords from the reasoning problem using lexical analysis tools, the corresponding knowledge subgraphs can be extracted by custom mapping to the relation types of the common sense knowledge base, thereby obtaining the relevant knowledge of the reasoning problem.
[0057] Here, candidate answers refer to multiple candidate answers corresponding to the question to be reasoned. Based on the question to be reasoned, as well as the relevant knowledge and candidate answers, the constructed triple can be <question to be reasoned q, relevant knowledge of the question to be reasoned k, candidate answer a>.
[0058] It is understandable that, since there may be multiple pieces of relevant knowledge about the problem to be reasoned about, and multiple candidate answers, there may be multiple triples constructed.
[0059] Step 120: Score the triples and determine candidate knowledge from the relevant knowledge based on the scores of the triples.
[0060] Specifically, after constructing triples, the triples can be scored, and candidate knowledge can be determined from relevant knowledge based on the scores of the triples.
[0061] Here, based on a preset template, the logical statements corresponding to the triples can be obtained, and the logical statements can be scored.
[0062] The preset template here can be presented in prompt format. The preset template here can be <question to be reasoned>, the answer is <candidate answer> because <relevant knowledge>, or it can be <relevant knowledge>, according to the above context, the answer of <question to be reasoned> is <candidate answer>, or it can be <relevant knowledge>, and we know the answer is <candidate answer>, so the question is <question to be reasoned>. This embodiment of the invention does not make specific limitations on this.
[0063] Here, the triples can be scored using an unsupervised scoring method using a language model. The language model can be the GPT-NeoX-20B model or the GPT-3 (Generative Pre-trained Transformer 3) model, etc. This embodiment of the invention does not specifically limit the specific language model used.
[0064] Here, based on the scores of the triples, candidate knowledge is identified from the relevant knowledge. The scores of the triples can be sorted from high to low, and the relevant knowledge in the top k triples with the highest scores is identified as candidate knowledge. This candidate knowledge is the relevant knowledge used for subsequent knowledge reasoning.
[0065] The formula for determining candidate knowledge from relevant knowledge based on the scores of triples is as follows:
[0066] K i =Topk(Score) i )
[0067] Among them, Score i Topk(Score) represents the score of the triple. i This means sorting the scores of triples from highest to lowest, and identifying the relevant knowledge in the top k triples as candidate knowledge.
[0068] It is understandable that by scoring the triples and determining candidate knowledge from relevant knowledge based on the scores of the triples, the resulting candidate knowledge is highly relevant to the problem to be reasoned, which reduces the amount of computation in subsequent knowledge reasoning, improves the efficiency of knowledge reasoning, and further improves the accuracy and reliability of knowledge reasoning.
[0069] Step 130: Based on the problem to be reasoned and the candidate knowledge, perform knowledge reasoning.
[0070] Specifically, after identifying candidate knowledge from relevant knowledge, knowledge reasoning can be performed based on the problem to be reasoned and the candidate knowledge.
[0071] The purpose of knowledge reasoning here is to help machines acquire common-sense knowledge and to use existing relevant knowledge to perform deep semantic understanding and logical reasoning.
[0072] For example, knowledge reasoning can be performed based on the reasoning model, applying the problem to be reasoned and candidate knowledge. The reasoning model here can be the T5 (Text-to-Text Transfer Transformer) model, the BERT model, or the GPT-3 (Generative Pre-trained Transformer 3) model, etc. The embodiments of the present invention do not specifically limit this.
[0073] The method provided in this invention constructs triples based on the problem to be reasoned, related knowledge of the problem, and candidate answers. The triples are scored, and candidate knowledge is determined from the related knowledge based on the scores of the triples. The candidate knowledge obtained is knowledge that is highly relevant to the problem to be reasoned. Then, based on the problem to be reasoned and the candidate knowledge, knowledge reasoning is performed, which reduces the amount of computation in subsequent knowledge reasoning, improves the efficiency of knowledge reasoning, and further improves the accuracy and reliability of knowledge reasoning.
[0074] Based on the above embodiments, Figure 2 This is a schematic diagram of the scoring process for triples provided by the present invention, as follows: Figure 2 As shown, scoring the triplet includes:
[0075] Step 210: Fill the triplet into a preset template to obtain the logical statement corresponding to the triplet;
[0076] Step 220: Score the logical statements;
[0077] The preset template is used to connect the logical relationship between the question to be reasoned, the relevant knowledge, and the candidate answers.
[0078] Specifically, after obtaining the triples, they can be filled into a preset template to obtain the corresponding logical statements. These logical statements reflect the logical information corresponding to the triples, and the preset template is used to connect the logical relationships between the problem to be reasoned, relevant knowledge, and candidate answers.
[0079] The preset template here can be presented in prompt format. The preset template here can be <question to be reasoned>, the answer is <candidate answer> because <relevant knowledge>, or it can be <relevant knowledge>, according to the above context, the answer of <question to be reasoned> is <candidate answer>, or it can be <relevant knowledge>, and we know the answer is <candidate answer>, so the question is <question to be reasoned>. This embodiment of the invention does not make specific limitations on this.
[0080] After obtaining the logical statement, the logical statement can be scored. Here, a language model can be used to score the logical statement. The language model can be the GPT-NeoX-20B model, or the GPT-3 model, etc. This embodiment of the invention does not make specific limitations on this.
[0081] The formula for scoring logical statements is as follows:
[0082]
[0083] Where, q i Let k represent the i-th problem to be reasoned. j Let a represent the j-th related knowledge. r Let represent the r-th candidate answer, n represent the number of candidate answers, s represent the s-th preset template, m represent the total number of preset templates, and P I (prompted s (q i ,k j ,a r () represents the score of the s-th preset template. i,j This represents the relevance score between the i-th question to be reasoned and its corresponding j-th related knowledge.
[0084] Understandably, filling triples into a preset template to obtain the corresponding logical statements, and then scoring the logical statements, can ensure the logical coherence of the statements while eliminating the influence of candidate answers on the importance of related knowledge. Furthermore, by combining different reasoning perspectives in the preset template, the accuracy and reliability of scoring the logical statements are further guaranteed.
[0085] The method provided in this invention involves filling triples into a preset template to obtain logical statements corresponding to the triples, and then scoring the logical statements. The preset template is used to connect the logical relationship between the question to be reasoned, related knowledge, and candidate answers. It can ensure the logical coherence of the statements while eliminating the influence of the importance of candidate answers on related knowledge. Furthermore, by combining different reasoning perspectives in the preset template, it further ensures the accuracy and reliability of scoring the logical statements.
[0086] Based on the above embodiments, step 130 includes:
[0087] Step 131: Based on the reasoning model, apply the problem to be reasoned and the candidate knowledge to perform knowledge reasoning;
[0088] The reasoning model is trained based on the sample question, the candidate knowledge of the sample question, and the labeled answer of the sample question.
[0089] Specifically, in order to apply the problem to be reasoned and the candidate knowledge to perform knowledge reasoning, the reasoning model needs to be obtained through the following steps before step 131:
[0090] Sample questions, candidate knowledge for sample questions, and labeled answers for sample questions can be collected in advance. An initial inference model can also be built in advance. The parameters of the initial inference model can be randomly generated or pre-set. The initial inference model can be a T5 model, a BERT model, a GPT-3 model, etc., and this embodiment of the invention does not specifically limit it.
[0091] After obtaining the initial inference model, the pre-collected sample questions, candidate knowledge of the sample questions, and labeled answers of the sample questions can be used to train the initial inference model:
[0092] First, the sample question and its candidate knowledge can be input into the initial inference model. The initial inference model then applies the sample question and its candidate knowledge to perform knowledge reasoning, and obtains and outputs the predicted answer to the sample question.
[0093] After obtaining the predicted answer to the sample question based on the initial inference model, the predicted answer to the sample question can be compared with the labeled answers to the sample questions collected in advance. The first loss function value is calculated based on the degree of difference between the two, and the parameters of the initial inference model are iterated based on the first loss function value. The initial inference model after parameter iteration is denoted as the inference model.
[0094] Understandably, the greater the difference between the predicted answer to the sample question and the labeled answer to the pre-collected sample questions, the larger the value of the first loss function; conversely, the smaller the difference between the predicted answer to the sample question and the labeled answer to the pre-collected sample questions, the smaller the value of the first loss function.
[0095] Here, the reasoning model is the trained model that can perform knowledge reasoning by applying the problem to be reasoned and candidate knowledge.
[0096] That is, during the training process of the reasoning model, it learns the function of applying the problem to be reasoned and candidate knowledge to perform knowledge reasoning.
[0097] Here, the Cross Entropy Loss Function, the Mean Squared Error (MSE) Loss Function, or the Stochastic Gradient Descent Method can be used to update the parameters of the initial inference model. This embodiment of the invention does not impose specific limitations on these methods.
[0098] After training and obtaining the reasoning model, knowledge reasoning can be performed using the problem to be reasoned and candidate knowledge.
[0099] The method provided in this invention is based on a reasoning model and applies the problem to be reasoned and candidate knowledge to perform knowledge reasoning. The reasoning model is trained based on the sample problem, the candidate knowledge of the sample problem, and the labeled answer of the sample problem, thereby improving the accuracy and reliability of the reasoning model in performing knowledge reasoning.
[0100] Based on the above embodiments, Figure 3 This is a flowchart illustrating the training steps of the inference model provided by the present invention, as shown below. Figure 3 As shown, the training steps of the inference model include:
[0101] Step 310: Based on knowledge-question pairs, train a question-knowledge association model, wherein the knowledge-question pairs include related knowledge and questions;
[0102] Step 320: Based on the sample question, the candidate knowledge of the sample question, and the labeled answer of the sample question, train the question knowledge association model to obtain the reasoning model.
[0103] Specifically, before obtaining the reasoning model, the problem knowledge association model can be trained in advance. Sample knowledge question pairs and labeled answers of sample knowledge question pairs can be collected in advance. Here, sample knowledge question pairs can include related sample knowledge and sample questions. For example, they can include sample questions and target knowledge of sample questions. Here, target knowledge is the candidate knowledge most relevant to the sample questions.
[0104] An initial problem knowledge association model can also be pre-constructed. The parameters of this initial problem knowledge association model can be randomly generated or pre-set. This initial problem knowledge association model can be a T5 model, a BERT model, a GPT-3 model, etc., and this embodiment of the invention does not specifically limit it.
[0105] After obtaining the initial question knowledge association model, the model can be trained using pre-collected sample knowledge question pairs and their labeled answers.
[0106] First, the sample knowledge question pairs can be input into the initial question knowledge association model. The initial question knowledge association model then applies the sample knowledge question pairs to learn the relevance between knowledge and questions, and obtains and outputs the predicted answers to the sample knowledge question pairs.
[0107] After obtaining the predicted answers to sample knowledge question pairs based on the initial question knowledge association model, the predicted answers to the sample knowledge question pairs can be compared with the labeled answers to the pre-collected sample knowledge question pairs. The second loss function value is calculated based on the degree of difference between the two, and the parameters of the initial question knowledge association model are iterated based on the second loss function value. The initial question knowledge association model after parameter iteration is denoted as the question knowledge association model.
[0108] Understandably, the greater the difference between the predicted answer of the sample knowledge question pair and the labeled answer of the pre-collected sample knowledge question pair, the larger the value of the second loss function; conversely, the smaller the difference between the predicted answer of the sample knowledge question pair and the labeled answer of the pre-collected sample knowledge question pair, the smaller the value of the second loss function.
[0109] In other words, during the training process of the question knowledge association model, it learns the function of associating the relevance between questions and knowledge in knowledge question pairs. This improves the training rate of the inference model obtained by training the question knowledge association model based on sample questions, candidate knowledge of sample questions, and labeled answers of sample questions, and further improves the accuracy and reliability of the inference model.
[0110] For example, you can input "Frozen bread grows mold after a while" into the problem knowledge association model, and the problem knowledge association model will output "Mould prefers a warm environment but can continue to grow slowly in colder tempertures".
[0111] After training the problem knowledge association model, you can train the problem knowledge association model again to obtain the reasoning model.
[0112] It can collect sample questions, candidate knowledge of sample questions, and labeled answers to sample questions in advance.
[0113] After obtaining the question knowledge association model, the model can be trained using pre-collected sample questions, candidate knowledge of the sample questions, and labeled answers to the sample questions.
[0114] First, the sample question and its candidate knowledge can be input into the question knowledge association model. The question knowledge association model then applies the sample question and its candidate knowledge to perform knowledge reasoning, and obtains and outputs the predicted answer to the sample question.
[0115] After obtaining the predicted answer to the sample question based on the question knowledge association model, the predicted answer to the sample question can be compared with the pre-collected labeled answers to the sample questions. The third loss function value is calculated based on the degree of difference between the two, and the question knowledge association model is iterated based on the third loss function value. The question knowledge association model after parameter iteration is denoted as the inference model.
[0116] Understandably, the greater the difference between the predicted answer to the sample question and the labeled answer to the pre-collected sample questions, the larger the value of the third loss function; conversely, the smaller the difference between the predicted answer to the sample question and the labeled answer to the pre-collected sample questions, the smaller the value of the third loss function.
[0117] That is, during the training process of the reasoning model, it learns the function of applying the problem to be reasoned and candidate knowledge to perform knowledge reasoning.
[0118] Here, the Cross Entropy Loss Function, the Mean Squared Error (MSE) Loss Function, or the Stochastic Gradient Descent Method can be used to update the parameters of the problem knowledge association model. This embodiment of the invention does not specifically limit the specific methods used.
[0119] The method provided in this invention trains a question-knowledge association model based on knowledge-question pairs. Each knowledge-question pair includes related knowledge and questions. Thus, during the training process of the question-knowledge association model, the function of associating the relevance between questions and knowledge in the knowledge-question pairs is learned. This improves the training rate of the subsequent training of the reasoning model based on sample questions, candidate knowledge of sample questions, and labeled answers of sample questions, and further improves the accuracy and reliability of the reasoning model.
[0120] Based on the above embodiments, Figure 4 This is a flowchart illustrating step 320 of the knowledge reasoning method provided by the present invention, as shown below. Figure 4 As shown, step 320 includes:
[0121] Step 321: Based on the question knowledge association model, determine the target knowledge from the candidate knowledge of the sample question, and generate a predicted answer based on the sample question and the target knowledge;
[0122] Step 322: Based on the predicted answer and the labeled answer, the first correlation between the target knowledge and the sample question, and the second correlation between the candidate knowledge other than the target knowledge and the sample question, the parameters of the question knowledge association model are iterated to obtain the inference model.
[0123] Specifically, the target knowledge can be determined from the candidate knowledge of the sample problem based on the problem knowledge association model. Here, the target knowledge is the candidate knowledge most relevant to the sample problem.
[0124] After obtaining the target knowledge, a predicted answer can be generated based on the sample question and the target knowledge. Here, the sample question and the target knowledge can be concatenated using natural language templates, for example, question start: Q, question end. knowledge 1 start: K1, knowledge 1 end.… Then, the concatenated template statement can be input into the question knowledge association model, which will then obtain and output the predicted answer.
[0125] After obtaining the predicted answer, the predicted answer can be compared with the pre-collected labeled answers, and the value of the fourth loss function can be determined based on the degree of difference between the two.
[0126] Furthermore, the fifth loss function value can be determined based on the first relevance between the target knowledge and the sample question, and the second relevance between the candidate knowledge (excluding the target knowledge) and the sample question. The first relevance between the target knowledge and the sample question can be obtained by unsupervised scoring using a language model. The language model can be the GPT-NeoX-20B model, or the GPT-3 model, etc. The embodiments of this invention do not specifically limit this.
[0127] The second relevance between the candidate knowledge (excluding the target knowledge) and the sample question can be obtained by unsupervised scoring using a language model. The language model can be the GPT-NeoX-20B model, the GPT-3 model, etc., and this embodiment of the invention does not specifically limit it.
[0128] After obtaining the fourth and fifth loss function values, the problem knowledge association model can be iterated based on the fourth and fifth loss function values, or based on the weighted sum of the fourth and fifth loss function values, and the problem knowledge association model after parameter iteration can be determined as the inference model.
[0129] Based on the above embodiments, Figure 5 This is a flowchart illustrating step 322 of the knowledge reasoning method provided by the present invention, as shown below. Figure 5 As shown, step 322 includes:
[0130] Step 3221: Determine the inference loss based on the difference between the predicted answer and the labeled answer;
[0131] Step 3222: Based on the differences between the first relevance and the second relevance, the differences between the first relevance and the third relevance, and the differences between the second relevance and the third relevance, determine the ranking loss; the third relevance is the relevance between irrelevant knowledge of the sample question and the sample question;
[0132] Step 3223: Based on the inference loss and the ranking loss, perform parameter iteration on the problem knowledge association model to obtain the inference model.
[0133] Specifically, after obtaining the predicted answer, the inference loss can be determined based on the difference between the predicted answer and the labeled answer. Here, the inference loss L... CE The formula is as follows:
[0134]
[0135] r k =logp I (a|q,k k )
[0136] Among them, K m K represents the target knowledge set, where target knowledge is the candidate knowledge most relevant to the sample problem. u K represents the set of candidate knowledge excluding the target knowledge, i.e., knowledge that is generally relevant to the sample problem. o Let |K| represent irrelevant knowledge related to the sample problem, i.e., knowledge unrelated to the sample problem. Let |K| represent the number of candidate knowledge items, and r k To combine the probabilities of predicted answers to individual knowledge and sample questions, This represents the probability of the predicted answer by combining the target knowledge and the sample question.
[0137] Understandably, the greater the difference between the predicted answer and the labeled answer, the greater the inference loss; conversely, the smaller the difference between the predicted answer and the labeled answer, the smaller the inference loss.
[0138] Then, the ranking loss can be determined based on the differences between the first and second relevance, the differences between the first and third relevance, and the differences between the second and third relevance, where the third relevance is the relevance between irrelevant knowledge of the sample question and the sample question.
[0139] Wherein, the sorting loss L RRL The formula is as follows:
[0140]
[0141] +log(σ(s u -s o )))
[0142] s i =f(k) i ,q)
[0143] Among them, s m s represents the first degree of relevance between the target knowledge and the sample question. u s represents the second relevance between candidate knowledge (excluding target knowledge) and the sample question. o K represents the third relevance between irrelevant knowledge about the sample question and the sample question. m K represents the target knowledge set, where target knowledge is the candidate knowledge most relevant to the sample problem. u K represents the set of candidate knowledge excluding the target knowledge, i.e., knowledge that is generally relevant to the sample problem. o Let |K| represent irrelevant knowledge related to the sample problem, i.e., knowledge unrelated to the sample problem, and let σ(s) represent the number of candidate knowledge items. m -s u ) represents the difference between the first and second relevance, σ(s) m -s o ) represents the difference between the first and third relevance scores, σ(s) u -s o The ) indicates the difference between the second and third relevance levels.
[0144] The ranking loss here can be a sigmoid loss function, a cross-entropy loss function, or a mean squared error loss function, etc., and this embodiment of the invention does not specifically limit it.
[0145] Understandably, the greater the difference between the first and second relevance, the difference between the first and third relevance, and the difference between the second and third relevance, the greater the ranking loss; conversely, the smaller the difference between the first and second relevance, the difference between the first and third relevance, and the difference between the second and third relevance, the smaller the ranking loss.
[0146] Understandably, ranking loss leverages the idea that knowledge with higher relevance to the sample question is more capable of generating correct answers through knowledge reasoning than knowledge with lower relevance to the sample question. Knowledge with high relevance to the sample question should have higher relevance than knowledge with low relevance to the sample question, enabling the reasoning model to focus on more relevant knowledge for reasoning, rather than simply learning superficial linguistic biases.
[0147] After obtaining the inference loss and ranking loss, the problem knowledge association model can be iterated based on the inference loss and ranking loss, or based on the weighted sum of the inference loss and ranking loss, and the problem knowledge association model after parameter iteration can be determined as the inference model.
[0148] Here, based on the weighted sum of inference loss and ranking loss, the formula for parameter iteration of the problem knowledge association model is as follows:
[0149] min(1-α)L CE +αL RRL
[0150] Among them, L CE L represents the inference loss. RRL Let α represent the ranking loss, and let α represent the weight coefficient, i.e., the hyperparameter.
[0151] The method provided in this invention iterates the parameters of a problem knowledge association model based on inference loss and ranking loss to obtain an inference model. The ranking loss utilizes the idea that knowledge with higher relevance to the sample problem is more likely to lead to the correct answer than knowledge with lower relevance. Knowledge with high relevance to the sample problem should have higher relevance than knowledge with low relevance, enabling the inference model to focus on more relevant knowledge for inference, rather than just learning superficial language biases, thereby improving the accuracy and reliability of the obtained inference model.
[0152] Based on the above embodiments, the knowledge question pair includes a first knowledge question pair and a second knowledge question pair. The first knowledge question pair includes the sample question and the target knowledge of the sample question. The target knowledge is the candidate knowledge most relevant to the sample question.
[0153] The second knowledge problem pair includes recommendation problems similar to the sample problem, as well as the target knowledge of the sample problem.
[0154] Specifically, the knowledge question pair may include a first knowledge question pair and a second knowledge question pair. Here, the first knowledge question pair may include a sample question and the target knowledge of the sample question. Here, the target knowledge is the candidate knowledge most relevant to the sample question.
[0155] The second knowledge problem pair here may include a recommendation problem similar to the sample problem, as well as the target knowledge of the sample problem.
[0156] The recommendation question here, which is similar to the sample question, can be a question obtained through a search engine. The search engine here can be Baidu, Google, Sogou, etc. This embodiment of the invention does not specifically limit this.
[0157] The method provided in this embodiment of the invention includes a first knowledge question pair and a second knowledge question pair. The first knowledge question pair includes a sample question and the target knowledge of the sample question. The second knowledge question pair includes a recommendation question similar to the sample question and the target knowledge of the sample question. Thus, the second knowledge question pair can serve as a supplementary knowledge question pair, enriching the knowledge question pair and improving its richness.
[0158] Based on any of the above embodiments, a knowledge reasoning method comprises the following steps:
[0159] The first step is to construct triples based on the problem to be reasoned about, as well as the relevant knowledge and candidate answers to the problem.
[0160] The second step is to score the triples and, based on the scores of the triples, identify candidate knowledge from the relevant knowledge.
[0161] The steps for scoring the triples are as follows:
[0162] The triples are filled into a preset template to obtain the corresponding logical statements, which are then scored. The preset template serves to connect the logical relationships between the problem to be reasoned, relevant knowledge, and candidate answers.
[0163] The third step is to apply the reasoning model to perform knowledge reasoning using the question to be reasoned and candidate knowledge. The reasoning model here is trained based on the sample question, the candidate knowledge of the sample question, and the labeled answer of the sample question.
[0164] The training steps for the inference model here include:
[0165] Based on knowledge question pairs, a question knowledge association model is trained. Here, the knowledge question pairs may include a first knowledge question pair and a second knowledge question pair. Here, the first knowledge question pair includes a sample question and the target knowledge of the sample question. Here, the target knowledge is the candidate knowledge most relevant to the sample question. Here, the second knowledge question pair includes recommendation questions similar to the sample question and the target knowledge of the sample question.
[0166] Based on the question knowledge association model, target knowledge can be determined from the candidate knowledge of the sample question, and a predicted answer can be generated based on the sample question and the target knowledge.
[0167] Inference loss can be determined based on the difference between the predicted answer and the labeled answer;
[0168] The ranking loss can be determined based on the differences between the first and second relevance, the differences between the first and third relevance, and the differences between the second and third relevance. Here, the third relevance is the relevance between irrelevant knowledge of the sample question and the sample question.
[0169] Finally, the reasoning model can be obtained by iterating the parameters of the problem knowledge association model based on the inference loss and ranking loss.
[0170] The knowledge reasoning apparatus provided by the present invention is described below. The knowledge reasoning apparatus described below and the knowledge reasoning method described above can be referred to in correspondence.
[0171] Based on any of the above embodiments, the present invention provides a knowledge reasoning device. Figure 6 This is a schematic diagram of the knowledge reasoning device provided by the present invention, as shown below. Figure 6 As shown, the knowledge reasoning device includes:
[0172] A triplet unit 610 is constructed to construct triples based on the problem to be reasoned, as well as the relevant knowledge and candidate answers of the problem to be reasoned.
[0173] The determining unit 620 is used to score the triples and determine candidate knowledge from the relevant knowledge based on the scores of the triples;
[0174] The knowledge reasoning unit 630 is used to perform knowledge reasoning based on the problem to be reasoned and the candidate knowledge.
[0175] The device provided in this embodiment of the invention fills triples into a preset template to obtain logical statements corresponding to the triples, and then scores the logical statements. The preset template is used to connect the logical relationship between the question to be reasoned, related knowledge and candidate answers. It can eliminate the influence of the importance of candidate answers on related knowledge while ensuring the logical coherence of the statements. Furthermore, by combining different reasoning perspectives in the preset template, it further ensures the accuracy and reliability of scoring the logical statements.
[0176] Based on any of the above embodiments, the scoring of the triples is specifically used for:
[0177] Fill the triplet into a preset template to obtain the logical statement corresponding to the triplet;
[0178] The logical statements are scored;
[0179] The preset template is used to connect the logical relationship between the question to be reasoned, the relevant knowledge, and the candidate answers.
[0180] Based on any of the above embodiments, the knowledge reasoning unit is specifically used for:
[0181] Based on the reasoning model, knowledge reasoning is performed using the problem to be reasoned and the candidate knowledge.
[0182] The reasoning model is trained based on the sample question, the candidate knowledge of the sample question, and the labeled answer of the sample question.
[0183] Based on any of the above embodiments, the training steps of the inference model include:
[0184] A training question knowledge association model unit is used to train a question knowledge association model based on knowledge question pairs, wherein the knowledge question pairs include related knowledge and questions;
[0185] A reasoning model unit is determined, which is used to train the question knowledge association model based on the sample question, the candidate knowledge of the sample question, and the labeled answer of the sample question, so as to obtain the reasoning model.
[0186] Based on any of the above embodiments, the inference model unit is specifically used for:
[0187] A predictive answer generation unit is used to determine target knowledge from candidate knowledge of the sample question based on the question knowledge association model, and generate a predictive answer based on the sample question and the target knowledge;
[0188] The parameter iteration unit is used to perform parameter iteration on the question knowledge association model based on the predicted answer and the labeled answer, the first relevance between the target knowledge and the sample question, and the second relevance between the candidate knowledge other than the target knowledge and the sample question, to obtain the inference model.
[0189] Based on any of the above embodiments, the parameter iteration unit is specifically used for:
[0190] A reasoning loss unit is defined to determine the reasoning loss based on the difference between the predicted answer and the labeled answer.
[0191] A ranking loss determination unit is used to determine the ranking loss based on the difference between the first relevance and the second relevance, the difference between the first relevance and the third relevance, and the difference between the second relevance and the third relevance; the third relevance is the relevance between irrelevant knowledge of the sample question and the sample question;
[0192] The parameter iteration subunit is used to perform parameter iteration on the problem knowledge association model based on the inference loss and the ranking loss to obtain the inference model.
[0193] Based on any of the above embodiments, the knowledge question pair includes a first knowledge question pair and a second knowledge question pair, wherein the first knowledge question pair includes the sample question and the target knowledge of the sample question, and the target knowledge is the candidate knowledge most relevant to the sample question;
[0194] The second knowledge problem pair includes recommendation problems similar to the sample problem, as well as the target knowledge of the sample problem.
[0195] Figure 7 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 7 As shown, the electronic device may include a processor 710, a communications interface 720, a memory 730, and a communication bus 740, wherein the processor 710, communications interface 720, and memory 730 communicate with each other via the communication bus 740. The processor 710 can call logical instructions in the memory 730 to execute a knowledge reasoning method, which includes: constructing triples based on the question to be reasoned, relevant knowledge about the question, and candidate answers; scoring the triples and determining candidate knowledge from the relevant knowledge based on the scores of the triples; and performing knowledge reasoning based on the question to be reasoned and the candidate knowledge.
[0196] Furthermore, the logical instructions in the aforementioned memory 730 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, 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 a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0197] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer is able to execute the knowledge reasoning method provided by the above methods. The method includes: constructing triples based on the problem to be reasoned, as well as the relevant knowledge and candidate answers to the problem to be reasoned; scoring the triples and determining candidate knowledge from the relevant knowledge based on the scores of the triples; and performing knowledge reasoning based on the problem to be reasoned and the candidate knowledge.
[0198] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements a knowledge reasoning method provided by the above methods. The method includes: constructing triples based on a problem to be reasoned, as well as relevant knowledge and candidate answers to the problem to be reasoned; scoring the triples and determining candidate knowledge from the relevant knowledge based on the scores of the triples; and performing knowledge reasoning based on the problem to be reasoned and the candidate knowledge.
[0199] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0200] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0201] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A knowledge reasoning method, characterized in that, include: Based on the question to be reasoned, the relevant knowledge of the question to be reasoned, and the candidate answers to the question to be reasoned, a triplet is constructed; The triples are scored, and candidate knowledge is determined from the relevant knowledge based on the scores of the triples. The candidate knowledge is knowledge that is highly relevant to the problem to be reasoned. Based on the problem to be reasoned and the candidate knowledge, knowledge reasoning is performed.
2. The knowledge reasoning method according to claim 1, characterized in that, The scoring of the triples includes: Fill the triplet into a preset template to obtain the logical statement corresponding to the triplet; The logical statements are scored; The preset template is used to connect the logical relationship between the question to be reasoned, the relevant knowledge, and the candidate answers.
3. The knowledge reasoning method according to claim 1, characterized in that, The knowledge reasoning based on the problem to be reasoned and the candidate knowledge includes: Based on the reasoning model, knowledge reasoning is performed using the problem to be reasoned and the candidate knowledge. The reasoning model is trained based on the sample question, the candidate knowledge of the sample question, and the labeled answer of the sample question.
4. The knowledge reasoning method according to claim 3, characterized in that, The training steps for the inference model include: Based on knowledge-question pairs, a question-knowledge association model is trained, wherein the knowledge-question pairs include related knowledge and questions; Based on the sample question, the candidate knowledge of the sample question, and the labeled answer of the sample question, the question knowledge association model is trained to obtain the reasoning model.
5. The knowledge reasoning method according to claim 4, characterized in that, The step of training the question knowledge association model based on the sample question, the candidate knowledge of the sample question, and the labeled answer of the sample question to obtain the inference model includes: Based on the question knowledge association model, target knowledge is determined from the candidate knowledge of the sample question, and a predicted answer is generated based on the sample question and the target knowledge. Based on the predicted answer and the labeled answer, the first relevance between the target knowledge and the sample question, and the second relevance between the candidate knowledge (excluding the target knowledge) and the sample question, the parameters of the question knowledge association model are iterated to obtain the inference model.
6. The knowledge reasoning method according to claim 5, characterized in that, The inference model is obtained by iterating the parameters of the question knowledge association model based on the predicted answer and the labeled answer, the first relevance between the target knowledge and the sample question, and the second relevance between the candidate knowledge (excluding the target knowledge) and the sample question, including: The inference loss is determined based on the difference between the predicted answer and the labeled answer; The ranking loss is determined based on the differences between the first relevance and the second relevance, the differences between the first relevance and the third relevance, and the differences between the second relevance and the third relevance; the third relevance is the relevance between irrelevant knowledge of the sample question and the sample question. Based on the inference loss and the ranking loss, the parameters of the problem knowledge association model are iterated to obtain the inference model.
7. The knowledge reasoning method according to claim 4, characterized in that, The knowledge question pair includes a first knowledge question pair and a second knowledge question pair. The first knowledge question pair includes the sample question and the target knowledge of the sample question. The target knowledge is the candidate knowledge most relevant to the sample question. The second knowledge problem pair includes recommendation problems similar to the sample problem, as well as the target knowledge of the sample problem.
8. A knowledge reasoning device, characterized in that, include: Construct a triplet unit to build triples based on the problem to be reasoned, the relevant knowledge of the problem to be reasoned, and the candidate answers to the problem to be reasoned. A determining unit is used to score the triples and, based on the scores of the triples, determine candidate knowledge from the relevant knowledge; The candidate knowledge is knowledge that is highly relevant to the problem to be reasoned. The knowledge reasoning unit is used to perform knowledge reasoning based on the problem to be reasoned and the candidate knowledge.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the knowledge reasoning method as described in any one of claims 1 to 7.
10. A non-transitory 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 knowledge reasoning method as described in any one of claims 1 to 7.