Prompt-based knowledge question and answer first-order reasoning method and device

CN118227764BActive Publication Date: 2026-11-03PING AN TECH (SHENZHEN) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410427219.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-10
Publication Date
2026-11-03
Estimated Expiration
2044-04-10

AI Technical Summary

Technical Problem

Existing medical knowledge question answering models lack accuracy when reasoning about related questions, especially the logic construction method based on the BERT model, which cannot effectively guarantee the accuracy of the answers.

Method used

By constructing knowledge graph triples and learning template pairs, the logical foundation of the medical knowledge question-answering model is optimized. Cross-entropy loss, consistency loss, and overall loss are used for model training to ensure the accuracy of reasoning answers.

Benefits of technology

It improves the accuracy of the medical knowledge question-answering model in reasoning questions and avoids erroneous logical answers, such as answering "the center is an organ of the human body" instead of "what part of the human body is the heart".

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118227764B_ABST
    Figure CN118227764B_ABST
Patent Text Reader

Abstract

The present application relates to the field of voice semantics and the field of digital medicine, and discloses a prompt-based knowledge question and answer first-order reasoning method and device, electronic equipment and storage medium, the method comprising: constructing a knowledge graph triple of a text to be trained, performing entity extraction on a question to obtain extracted entities; constructing a learning template pair of the extracted entities, splicing the text to be trained and the learning template pair to obtain a spliced sample; inputting the spliced sample into a reasoning model to be trained, outputting a reasoning answer of the spliced sample by using the reasoning model to be trained, performing answer screening on the reasoning answer by using the knowledge graph triple, obtaining a screened answer, calculating a cross-entropy loss, a consistency loss and an overall loss of the screened answer; according to the cross-entropy loss, the consistency loss and the overall loss, model training is performed on the reasoning model to be trained to obtain a trained reasoning model; and the trained reasoning model is used to identify a text reasoning result of a text to be reasoned. The present application can guarantee accurate reasoning of knowledge question and answer.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of speech semantics and digital healthcare, and particularly to a first-order reasoning method, apparatus, electronic device, and computer-readable storage medium based on prompt-based knowledge question answering. Background Technology

[0002] With the rise of AI-powered interactive technologies, knowledge-based question answering in the medical industry can support functions such as disease-assisted diagnosis, health management, and remote consultation. Generally, medical knowledge-based question answering consists of three parts: a text paragraph containing medical background knowledge, a medical question, and a medical answer. The input consists of the medical knowledge paragraph and the medical question. The model learns to find the corresponding medical answer within the medical knowledge paragraph. The industry typically uses an attention mechanism approach for medical knowledge-based question answering. This involves encoding the medical background knowledge and the medical question, then calculating the attention weight between the encoded vector of the medical question and the vector of each word in the medical background knowledge, and identifying the word with the highest weight as the medical answer. This method works well when the medical answer and the medical question appear in the same sentence, but it performs poorly when dealing with inference-related medical questions. For example, consider the following medical background text: "The human organ is the center of the blood circulation, and the heart, as an organ, plays a vital role." The question is: "Where is the heart located in the human body?" Because the question is primarily in the first sentence, while the answer, the heart, is in the second, and traditional industry techniques, such as the BERT knowledge-answering model built on the logic of "A is B," the BERT model might incorrectly answer that the "center" is a human organ, when in fact it is the heart, by finding the organ in the background text as the center. Therefore, the logical foundation of the medical knowledge-answering reasoning model cannot guarantee accurate reasoning in medical knowledge-answering. Summary of the Invention

[0003] This invention provides a prompt-based first-order reasoning method, device, electronic device, and computer-readable storage medium for knowledge question answering. Its main purpose is to ensure accurate reasoning in medical knowledge question answering by optimizing the logical foundation of the medical knowledge question answering reasoning model.

[0004] To achieve the above objectives, this invention provides a first-order reasoning method for knowledge question answering based on prompts, comprising:

[0005] Obtain the text to be trained, construct the knowledge graph triples of the text to be trained, and extract entities from the question to obtain the extracted entities.

[0006] Based on the knowledge graph triples, the learning template pairs for the extracted entities are constructed, and the text to be trained is concatenated with the learning template pairs to obtain the concatenated sample.

[0007] Input the spliced sample into the inference model to be trained, use the inference model to be trained to output an inference response of the spliced sample, screen the inference response by using the knowledge graph triple and the learning template pair to obtain a screened response, and calculate the cross-entropy loss, consistency loss, and overall loss of the screened response;

[0008] Perform model training on the inference model to be trained according to the cross-entropy loss, the consistency loss and the overall loss, to obtain a trained inference model;

[0009] Use the trained inference model to identify a text inference result of a text to be inferred.

[0010] Optionally, the performing entity extraction on the question to obtain an extracted entity comprises:

[0011] Determine a to-be-extracted entity category of the question;

[0012] Input the question into a preset bidirectional recurrent memory model, and use the bidirectional recurrent memory model to calculate the entity category probability that each word in the question belongs to the to-be-extracted entity category;

[0013] Identify the extracted entity of the question by using a preset named entity recognition model based on the entity category probability.

[0014] Optionally, the constructing the learning template pair of the extracted entity based on the knowledge graph triple comprises:

[0015] Construct the learning template pair of the extracted entity based on the knowledge graph triple by using the following format:

[0016] <X, has, A>, [sep], <A, is, Y>

[0017] <X, is, A>, [sep], <A, has, Y>

[0018] <Y, has, A>, [sep], <A, is, X>

[0019] <Y, is, A>, [sep], <A, has, X>

[0020] <Y, is, A>, [sep], <A, is, Y>

[0021] <Y, has, A>, [sep], <A, has, Y>

[0022] <X, is, A>, [sep], <A, is, X>

[0023] <X, has, A>, [sep], <A, has, X>

[0024] Wherein, <X / Y, have / be, A>, [sep], <A, be / have, X / Y> represents the learning template pair, X and Y represent two different entities in the extracted entities, A represents the corresponding response that the subsequent BERT model needs to make according to the extracted entities, "be" represents the definition of the relationship in the knowledge graph triple, "have" represents the definition of the attribute in the knowledge graph triple, and [sep] represents a special label, which is used to separate the symmetric template pairs on the left and right sides.

[0025] Optionally, the splicing the to-be-trained text and the learning template pair to obtain a spliced sample includes:

[0026] Acquire the background knowledge text, question text and response text in the to-be-trained text, and based on the background knowledge text, the question text and the response text, splice the to-be-trained text and the learning template pair using the following format to obtain a spliced sample:

[0027] [CLS], P, [sep], Q, [sep], A, [sep], T

[0028] Wherein, [CLS], P, [sep], Q, [sep], A, [sep], T represent the spliced sample, [CLS] and [sep] represent special labels, P represents the background knowledge text, Q represents the question text, A represents the response text, and T represents the learning template pair.

[0029] Optionally, the inputting the spliced sample into the to-be-trained reasoning model includes:

[0030] Extracting the to-be-responded text in the spliced sample;

[0031] Performing hiding processing on the to-be-responded text to obtain a hidden text;

[0032] Inputting the spliced sample containing the hidden text into the to-be-trained reasoning model.

[0033] Optionally, the performing response screening on the reasoning response by using the knowledge graph triple and the learning template pair to obtain a screened response includes:

[0034] Extracting responses that are consistent with the response text in the learning template pair from the reasoning responses to obtain a first screened response;

[0035] When the reasoning response is consistent with the response text in the learning template pair, constructing a non-logical template pair corresponding to the learning template pair using the following format:

[0036] <Y, have, A>, [sep], <A, have, X>

[0037] <Y, is, A>, [sep], <A, is, X>

[0038] <X, has, A>, [sep], <A, has, Y>

[0039] <X, is, A>, [sep], <A, is, Y>

[0040] wherein, <X / Y, is / has, A>, [sep], <A, is / has, X / Y> represents the non-logical template pair, X and Y represent two different entities in the extracted entities, A represents the corresponding response that the subsequent BERT model needs to make according to the extracted entities, "is" represents the definition of the relation in the knowledge graph triple, "has" represents the definition of the attribute in the knowledge graph triple, and [sep] represents a special label, configured to split the symmetric template pairs on the left and right sides;

[0041] removing responses that do not conform to the non-logical template pair from the first filtered response to obtain a second filtered response;

[0042] extracting responses that conform to the knowledge graph triple from the second filtered response to obtain the filtered response.

[0043] Optionally, the calculating the cross-entropy loss, consistency loss, and overall loss of the filtered response includes:

[0044] calculating the cross-entropy loss using the following formula:

[0045]

[0046] wherein, L1(θ i ,θ1) represents the cross-entropy loss, θ1 represents the one-hot encoding of the true category corresponding to the filtered response, m=m i contains two types of values, 0 and 1, where 1 represents the probability of being predicted as the true category, 0 represents the probability of not being predicted as the true category, θ i represents the distribution after passing through softmax, that is, the 0~1 distribution corresponding to the filtered response, i represents the serial number of each distribution in the 0~1 distribution corresponding to the filtered response, M represents the total number of all distributions in the 0~1 distribution corresponding to the filtered response, p(m=m i ∣θ i ,θ1) represents the probability when m=m i is 1 and the probability when m=m i is 0;

[0047] calculating the consistency loss using the following formula:

[0048]

[0049] Where, L2(θ) j θ2) represents the consistency loss, n = n j The value contains two types: 0 and 1. 1 indicates that the predicted selected answer matches the actual result, and 0 indicates that the predicted selected answer does not match the actual result. p(n=n) j |θ j ,θ2) in n=n j When the probability of the selected answer being consistent with the true result is 1, in n = n j The probability that the selected answer is inconsistent with the actual result when the value is 0, j represents the sequence number of the predicted selected answer, N represents the total number of predicted selected answers, and θ j θ2 represents the predicted filtered answer, and θ2 represents the actual answer;

[0050] The overall loss is calculated using the following formula, based on the cross-entropy loss and the consistency loss:

[0051] L(θ,θ1,θ2)=-L1(θ,θ1)-L2(θ,θ2)

[0052] Where L(θ,θ1,θ2) represents the overall loss, that is, the loss value of the entire BERT model, L1(θ i L2(θ1) represents the cross-entropy loss, where θ1 represents the one-hot encoding of the true category corresponding to the filtered answer, and L2(θ1) represents the cross-entropy loss. j θ2) represents the consistency loss, where θ2 represents the true answer, and θ includes θ i With θ j θ i Let θ represent the distribution after softmax. i The predicted filtered answer.

[0053] To address the aforementioned problems, the present invention also provides a first-order reasoning device for knowledge question answering based on prompt, the device comprising:

[0054] The entity extraction module is used to acquire the text to be trained, construct the knowledge graph triples of the text to be trained, extract entities from the question, and obtain the extracted entities.

[0055] The sample splicing module is used to construct the learning template pair of the extracted entities based on the knowledge graph triples, and splice the text to be trained with the learning template pair to obtain the spliced ​​sample;

[0056] The loss calculation module is used to input the spliced ​​sample into the inference model to be trained, use the inference model to be trained to output the inference answer of the spliced ​​sample, use the knowledge graph triple and the learning template to filter the inference answer to obtain the filtered answer, and calculate the cross-entropy loss, consistency loss and overall loss of the filtered answer.

[0057] The model training module is used to train the inference model to be trained based on the cross-entropy loss, the consistency loss, and the overall loss, so as to obtain a trained inference model.

[0058] The text reasoning module is used to identify the text reasoning result of the text to be reasoned using the trained reasoning model.

[0059] To address the above problems, the present invention also provides an electronic device, the electronic device comprising:

[0060] At least one processor; and,

[0061] A memory communicatively connected to the at least one processor; wherein,

[0062] The memory stores a computer program that can be executed by the at least one processor to implement the prompt-based first-order reasoning method for knowledge answering described above.

[0063] To address the aforementioned problems, the present invention also provides a computer-readable storage medium storing at least one computer program, which is executed by a processor in an electronic device to implement the above-described prompt-based first-order reasoning method for knowledge-based question answering.

[0064] As can be seen, this embodiment of the invention extracts entities from the question to determine the subject within the question, facilitating subsequent responses based on the subject of the question. Furthermore, this embodiment constructs learning template pairs for the extracted entities based on the knowledge graph triples, enabling the construction of correct logical relationships between the extracted entities within these learning template pairs. This avoids erroneous logic, such as answering "The heart is a part of the human body" for a question like "What part of the human body is the heart?". Therefore, the prompt-based first-order reasoning method, apparatus, electronic device, and computer-readable storage medium proposed in this embodiment can ensure accurate reasoning in knowledge question answering by optimizing the logical foundation of the knowledge question answering reasoning model. Attached Figure Description

[0065] Figure 1A flowchart illustrating a first-order reasoning method for knowledge-based question answering provided in an embodiment of the present invention;

[0066] Figure 2 This is a schematic diagram of a module of a first-order reasoning device for knowledge question answering based on prompt, provided in an embodiment of the present invention.

[0067] Figure 3 This is a schematic diagram of the internal structure of an electronic device that implements a prompt-based first-order reasoning method for knowledge question answering, according to an embodiment of the present invention.

[0068] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0069] It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.

[0070] This invention provides a prompt-based first-order reasoning method for knowledge question answering. The execution entity of this prompt-based first-order reasoning method includes, but is not limited to, at least one of the following electronic devices that can be configured to execute the method provided in this invention: a server, a terminal, etc. In other words, the prompt-based first-order reasoning method can be executed by software or hardware installed on a terminal device or a server device, and the software can be a blockchain platform. The server includes, but is not limited to, a single server, a server cluster, a cloud server, or a cloud server cluster. The server can be an independent server or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms.

[0071] Reference Figure 1 The diagram shown is a flowchart illustrating a prompt-based first-order reasoning method for knowledge question answering provided in an embodiment of the present invention. In this embodiment, the prompt-based first-order reasoning method for knowledge question answering includes the following steps S1-S5:

[0072] S1. Obtain the text to be trained, construct the knowledge graph triples of the text to be trained, and extract entities from the question to obtain the extracted entities.

[0073] In the embodiments of the present invention, the to-be-trained text includes background knowledge text, question text and answer text, and the content of the to-be-trained text varies in different scenarios. For example, in the field of digital healthcare, the content of the to-be-trained text is related to medical consultation. For instance, the background knowledge text may be Electronic Healthcare Record, which is an electronic personal health record including a series of electronic records with preservation and reference value such as medical records, electrocardiograms, and medical images, the question text may be "Does the patient have a headache?", and the answer text may be "Headache". In the field of national geography, the content of the to-be-trained text is related to geographic content. For example, the background knowledge text paragraph P: The human organ is the center of human blood circulation, and the heart as an organ undertakes an important mission, the question Q: What part of a human is the heart?, the answer A: An organ.

[0074] Optionally, the knowledge graph triplet of the to-be-trained text is constructed in the following format: <Entity, Relationship, Attribute>, where the attribute is defined as "has", and the relationship is defined as "is".

[0075] Further, the embodiments of the present invention perform entity extraction on the question to determine the medical subject in the medical question, which facilitates subsequent medical response to the medical question with reference to the medical subject of the medical question.

[0076] In an embodiment of the present invention, the performing entity extraction on the question to obtain an extracted entity includes: determining the category of the to-be-extracted entity of the question; inputting the question into a preset bidirectional recurrent memory model, and using the bidirectional recurrent memory model to calculate the entity category probability of each word in the question belonging to the to-be-extracted entity category; based on the entity category probability, using a preset named entity recognition model to identify the extracted entity of the question.

[0077] Optionally, each sentence is input into the bidirectional LSTM one by one in word order, and the probability of each word belonging to each entity category label is obtained by combining the forward and backward hidden layer outputs, which is input into the CRF model (the named entity recognition model) to optimize the objective function, so as to obtain the entity category to which each word belongs. By using the combined model of LSTM+CRF to perform entity extraction on the text sentence of Q, for example, the two entities <Entity: Beijing> and <Entity: China> are obtained.

[0078] S2. Construct a learning template pair of the extracted entity based on the knowledge graph triplet, and splice the to-be-trained text and the learning template pair to obtain a spliced sample.

[0079] In the embodiment of the present invention, a learning template pair of the extracted entities is constructed based on the knowledge graph triples, so as to construct correct logical relationships of the extracted entities in the learning template pair, and avoid erroneous logic where the question is "What part of a person is the heart" and the answer is "The center is an organ of the human body".

[0080] In one embodiment of the present invention, the learning template pair of the extracted entities is constructed using the following format based on the knowledge graph triples:

[0081] <X, have, A>, [sep], <A, be, Y>

[0082] <X, be, A>, [sep], <A, have, Y>

[0083] <Y, have, A>, [sep], <A, be, X>

[0084] <Y, be, A>, [sep], <A, have, X>

[0085] <Y, be, A>, [sep], <A, be, Y>

[0086] <Y, have, A>, [sep], <A, have, Y>

[0087] <X, be, A>, [sep], <A, be, X>

[0088] <X, have, A>, [sep], <A, have, X>

[0089] Herein, <X / Y, have / be, A>, [sep], <A, be / have, X / Y> represents the learning template pair, X and Y represent two different entities among the extracted entities, A represents the corresponding answer that the subsequent BERT model needs to make according to the extracted entities, "be" represents the definition of the relationship in the knowledge graph triples, "have" represents the definition of the attribute in the knowledge graph triples, and [sep] represents a special label for separating the symmetrical template pairs on the left and right sides.

[0090] In one embodiment of the present invention, the splicing the text to be trained and the learning template pair to obtain a spliced sample includes: acquiring the background knowledge text, the question text and the answer text in the text to be trained, and splicing the text to be trained and the learning template pair using the following format based on the background knowledge text, the question text and the answer text to obtain the spliced sample:

[0091] [CLS], P, [sep], Q, [sep], A, [sep], T

[0092] Wherein, , <[BOS_never_used_51bce0c785ca2f68081bfa7d91973934]>, P, [sep], Q, [sep], A, [sep], T represent the spliced sample, <[BOS_never_used_51bce0c785ca2f68081bfa7d91973934]> and [sep] represent special tags, P represents the background knowledge text, Q represents the question text, A represents the answer text, and T represents the learning template pair.

[0093] S3. Input the spliced sample into the reasoning model to be trained, use the reasoning model to be trained to output the reasoning answer of the spliced sample, use the knowledge graph triplet and the learning template pair to perform answer screening on the reasoning answer to obtain a screened answer, and calculate the cross-entropy loss, consistency loss, and overall loss of the screened answer.

[0094] In the embodiment of the present invention, the reasoning model to be trained refers to a conventional BERT model, whose full name is Bidirectional Encoder Representations from Transformers. Compared with the original RNN and LSTM, the BERT model can execute in parallel, extract the relationship features of words in sentences at the same time, and can extract relationship features at multiple different levels, thereby more comprehensively reflecting the sentence semantics.

[0095] In an embodiment of the present invention, said inputting the spliced sample into the reasoning model to be trained includes: extracting the to-be-answered text in the spliced sample; performing hiding processing on the to-be-answered text to obtain a hidden text; inputting the spliced sample containing the hidden text into the reasoning model to be trained.

[0096] Optionally, when inputting the spliced sample into the reasoning model to be trained, the part A of the spliced sample needs to be masked, so that the BERT model will predict the masked part, so as to achieve the purpose of training the reasoning model to be trained.

[0097] In an embodiment of the present invention, said using the knowledge graph triplet and the learning template pair to perform answer screening on the reasoning answer to obtain a screened answer includes: extracting answers that are consistent with the answer text in the reasoning answer and the learning template pair to obtain a first screened answer; when the reasoning answer is consistent with the answer text in the learning template pair, constructing a non-logical template pair corresponding to the learning template pair using the following format:

[0098] <Y, have, A>, [sep], <A, have, X>

[0099] <Y, is, A>, [sep], <A, is, X>

[0100] <X, have, A>, [sep], <A, have, Y>

[0101] <X, is, A>, [sep], <A, is, Y>

[0102] Here, <X / Y, is / has, A>, [sep], <A, is / has, X / Y> represents the non-logical template pair, X and Y denote two different entities in the extracted entities, A denotes the corresponding response that the subsequent BERT model needs to make according to the extracted entities, "is" denotes the definition of the relationship in the knowledge graph triple, "has" denotes the definition of the attribute in the knowledge graph triple, and [sep] denotes a special tag for separating the symmetric template pairs on the left and right sides;

[0103] Removing responses that do not conform to the non-logical template pair from the first filtered response to obtain a second filtered response; extracting responses that conform to the knowledge graph triple from the second filtered response to obtain the filtered response.

[0104] It should be noted that the template setting rule for the non-logical template pair is that the same A cannot belong to the same relationship or attribute with two different entities.

[0105] In an embodiment of the present invention, said calculating the cross-entropy loss, consistency loss, and overall loss of the filtered response includes: calculating the cross-entropy loss using the following formula:

[0106]

[0107] Wherein, L1(θ i ,θ1) represents the cross-entropy loss, θ1 represents the one-hot encoding of the true category corresponding to the filtered response, m=m i Contains values of two types, 0 and 1, where 1 represents the probability of being predicted as the true category, 0 represents the probability of being predicted not to be the true category, θ i Represents the distribution after passing through softmax, that is, the 0~1 distribution corresponding to the filtered response, i represents the serial number of each distribution in the 0~1 distribution corresponding to the filtered response, M represents the total number of all distributions in the 0~1 distribution corresponding to the filtered response, p(m=m i |θ i ,θ1) represents the probability when m=m i is 1 and the probability when m=m i is 0;

[0108] The consistency loss is calculated using the following formula:

[0109]

[0110] Wherein, L2(θ j ,θ2) represents the consistency loss, n=n j Contains values of two types, 0 and 1, where 1 represents that the predicted filtered response is consistent with the true result, 0 represents that the predicted filtered response is inconsistent with the true result, p(n=nj |θ j ,θ2) in n=n j When the probability of the selected answer being consistent with the true result is 1, in n = n j The probability that the selected answer is inconsistent with the actual result when the value is 0, j represents the sequence number of the predicted selected answer, N represents the total number of predicted selected answers, and θ j θ2 represents the predicted filtered answer, and θ2 represents the actual answer;

[0111] The overall loss is calculated using the following formula, based on the cross-entropy loss and the consistency loss:

[0112] L(θ,θ1,θ2)=-L1(θ,θ1)-L2(θ,θ2)

[0113] Where L(θ,θ1,θ2) represents the overall loss, that is, the loss value of the entire BERT model, L1(θ i L2(θ1) represents the cross-entropy loss, where θ1 represents the one-hot encoding of the true category corresponding to the filtered answer, and L2(θ1) represents the cross-entropy loss. j θ2) represents the consistency loss, where θ2 represents the true answer, and θ includes θ i With θ j θ i Let θ represent the distribution after softmax. j The predicted filtered answer.

[0114] S4. Based on the cross-entropy loss, the consistency loss, and the overall loss, train the inference model to be trained to obtain a trained inference model.

[0115] Optionally, the inference model to be trained is trained based on the cross-entropy loss, the consistency loss, and the overall loss. The trained inference model is gradually optimized by continuously reducing the loss values ​​of the cross-entropy loss, the consistency loss, and the overall loss, and finally a trained model is obtained.

[0116] S5. Use the trained reasoning model to identify the text reasoning result of the text to be reasoned.

[0117] As can be seen, this embodiment of the invention extracts entities from the question to determine the subject within the question, facilitating subsequent responses based on the subject of the question. Furthermore, this embodiment constructs learning template pairs for the extracted entities based on the knowledge graph triples, enabling the construction of correct logical relationships between the extracted entities within these learning template pairs. This avoids erroneous logic, such as answering "The heart is a part of the human body" for a question like "What part of the human body is the heart?". Therefore, the prompt-based first-order reasoning method for knowledge-based question answering proposed in this embodiment can ensure accurate reasoning by optimizing the logical foundation of the knowledge-based question answering reasoning model.

[0118] like Figure 2 The diagram shown is a functional block diagram of the first-order reasoning device for knowledge question answering based on prompt according to the present invention.

[0119] The prompt-based first-order reasoning device 100 for knowledge answering described in this invention can be installed in an electronic device. Depending on the functions implemented, the prompt-based first-order reasoning device may include an entity extraction module 101, a sample assembly module 102, a loss calculation module 103, a model training module 104, and a text reasoning module 105. The module described in this invention can also be referred to as a unit, which refers to a series of computer program segments that can be executed by the processor of an electronic device and can perform a fixed function, and which are stored in the memory of the electronic device.

[0120] In this embodiment, the functions of each module / unit are as follows:

[0121] The entity extraction module 101 is used to acquire the text to be trained, construct the knowledge graph triplet of the text to be trained, extract entities from the question, and obtain the extracted entities.

[0122] The sample splicing module 102 is used to construct the learning template pair of the extracted entities based on the knowledge graph triples, and splice the text to be trained with the learning template pair to obtain spliced ​​samples.

[0123] The loss calculation module 103 is used to input the spliced ​​sample into the inference model to be trained, use the inference model to be trained to output the inference answer of the spliced ​​sample, use the knowledge graph triple and the learning template to filter the inference answer to obtain the filtered answer, and calculate the cross-entropy loss, consistency loss and overall loss of the filtered answer.

[0124] The model training module 104 is used to train the inference model to be trained based on the cross-entropy loss, the consistency loss, and the overall loss, so as to obtain a trained inference model.

[0125] The text reasoning module 105 is used to identify the text reasoning result of the text to be reasoned using the trained reasoning model.

[0126] In detail, the modules in the prompt-based first-order reasoning device 100 described in this embodiment of the invention employ the same methods as described above. Figure 1 The technique used is the same as the prompt-based first-order reasoning method for knowledge-based question answering described in the article, and it can produce the same technical effect, so it will not be repeated here.

[0127] like Figure 3 The diagram shown is a structural schematic of an electronic device 1 that implements a first-order reasoning method for knowledge question answering based on prompt according to the present invention.

[0128] The electronic device 1 may include a processor 10, a memory 11, a communication bus 12, and a communication interface 13. It may also include a computer program stored in the memory 11 and capable of running on the processor 10, such as a prompt-based knowledge-answering first-order reasoning program.

[0129] In some embodiments, the processor 10 may be composed of integrated circuits, such as a single packaged integrated circuit or multiple integrated circuits with the same or different functions, including combinations of one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and various control chips. The processor 10 is the control unit of the electronic device 1, connecting various components of the electronic device 1 via various interfaces and lines. It executes programs or modules stored in the memory 11 (e.g., executing a prompt-based first-order reasoning program for knowledge answering) and calls data stored in the memory 11 to perform various functions and process data of the electronic device 1.

[0130] The memory 11 includes at least one type of readable storage medium, including flash memory, portable hard drive, multimedia card, card-type memory (e.g., SD or DX memory), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 11 can be an internal storage unit of the electronic device 1, such as a portable hard drive of the electronic device 1. In other embodiments, the memory 11 can be an external storage device of the electronic device 1, such as a plug-in portable hard drive, Smart Media Card (SMC), Secure Digital (SD) card, Flash Card, etc., equipped on the electronic device 1. Furthermore, the memory 11 can include both internal and external storage units of the electronic device 1. The memory 11 can be used not only to store application software and various types of data installed on the electronic device 1, such as the code of a prompt-based knowledge-answering first-order inference program, but also to temporarily store data that has been output or will be output.

[0131] The communication bus 12 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. This bus can be divided into an address bus, a data bus, a control bus, etc. The bus is configured to enable communication between the memory 11 and at least one processor 10, etc.

[0132] The communication interface 13 is used for communication between the aforementioned electronic device 1 and other devices, including a network interface and an employee interface. Optionally, the network interface may include a wired interface and / or a wireless interface (such as a Wi-Fi interface, Bluetooth interface, etc.), typically used to establish a communication connection between the electronic device 1 and other electronic devices 1. The employee interface may be a display, an input unit (such as a keyboard), or, optionally, a standard wired or wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, or an OLED (Organic Light-Emitting Diode) touchscreen, etc. The display may also be appropriately referred to as a screen or display unit, used to display information processed in the electronic device 1 and to display a visual employee interface.

[0133] Figure 3 Only electronic device 1 with components is shown; those skilled in the art will understand that... Figure 3The structure shown does not constitute a limitation on the electronic device 1, and may include fewer or more components than shown, or combine certain components, or have different component arrangements.

[0134] For example, although not shown, the electronic device 1 may also include a power supply (such as a battery) to power various components. Preferably, the power supply can be logically connected to the at least one processor 10 through a power management device, thereby enabling functions such as charging management, discharging management, and power consumption management. The power supply may also include one or more DC or AC power supplies, recharging devices, power fault detection circuits, power converters or inverters, power status indicators, and other arbitrary components. The electronic device 1 may also include various sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be described in detail here.

[0135] It should be understood that the embodiments described are for illustrative purposes only and are not limited to this structure in terms of the scope of the patent invention.

[0136] The prompt-based knowledge-answering first-order reasoning program stored in the memory 11 of the electronic device 1 is a combination of multiple computer programs. When run in the processor 10, it can achieve the following:

[0137] Obtain the text to be trained, construct the knowledge graph triples of the text to be trained, and extract entities from the question to obtain the extracted entities.

[0138] Based on the knowledge graph triples, the learning template pairs for the extracted entities are constructed, and the text to be trained is concatenated with the learning template pairs to obtain the concatenated sample.

[0139] The spliced ​​sample is input into the inference model to be trained, and the inference model to be trained outputs the inference answer of the spliced ​​sample. The knowledge graph triple and the learning template are used to filter the inference answer to obtain the filtered answer. The cross-entropy loss, consistency loss and overall loss of the filtered answer are calculated.

[0140] The training model is obtained by training the inference model to be trained based on the cross-entropy loss, the consistency loss, and the overall loss.

[0141] The trained reasoning model is used to identify the text reasoning results of the text to be reasoned.

[0142] Specifically, the processor 10's implementation method of the above-mentioned computer program can be found in [reference needed]. Figure 1 The descriptions of the relevant steps in the corresponding embodiments are not repeated here.

[0143] Furthermore, if the modules / units integrated in the electronic device 1 are implemented as software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium. The computer-readable storage medium can be volatile or non-volatile. For example, the computer-readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a portable hard drive, a magnetic disk, an optical disk, a computer memory, or a read-only memory (ROM).

[0144] The present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor of an electronic device 1, can perform the following:

[0145] Obtain the text to be trained, construct the knowledge graph triples of the text to be trained, and extract entities from the question to obtain the extracted entities.

[0146] Based on the knowledge graph triples, the learning template pairs for the extracted entities are constructed, and the text to be trained is concatenated with the learning template pairs to obtain the concatenated sample.

[0147] The spliced ​​sample is input into the inference model to be trained, and the inference model to be trained outputs the inference answer of the spliced ​​sample. The knowledge graph triple and the learning template are used to filter the inference answer to obtain the filtered answer. The cross-entropy loss, consistency loss and overall loss of the filtered answer are calculated.

[0148] The training model is obtained by training the inference model to be trained based on the cross-entropy loss, the consistency loss, and the overall loss.

[0149] The trained reasoning model is used to identify the text reasoning results of the text to be reasoned.

[0150] In the several embodiments provided by this invention, it should be understood that the disclosed devices, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and other division methods may be used in actual implementation.

[0151] The modules described as separate components may or may not be physically separate. The components shown as modules 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.

[0152] Furthermore, the functional modules in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or in the form of hardware plus software functional modules.

[0153] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential characteristics of the present invention.

[0154] Therefore, the embodiments should be considered exemplary and non-limiting in all respects, and the scope of the invention is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be embraced within the invention. No appended diagram markings in the claims should be construed as limiting the scope of the claims.

[0155] The embodiments of this invention can acquire and process relevant data based on artificial intelligence technology. Artificial intelligence (AI) refers to the theories, methods, technologies, and application systems that utilize digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use that knowledge to obtain optimal results.

[0156] Furthermore, it is clear that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices recited in a system claim may also be implemented by a single unit or device through software or hardware. The term "second class" is used to indicate names and does not indicate any specific order.

[0157] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.

Claims

1. A first-order reasoning method for knowledge question answering based on prompts, characterized in that, The method comprises: acquiring a to-be-trained text, constructing a knowledge graph triple of the to-be-trained text, performing entity extraction on a question to obtain an extracted entity; constructing a learning template pair for the extracted entity based on the knowledge graph triple, and splicing the to-be-trained text and the learning template pair to obtain a spliced sample; inputting the spliced sample into a to-be-trained inference model, outputting a plurality of inference answers of the spliced sample by using the to-be-trained inference model, extracting answers that are consistent with the answer text in the learning template pair from the inference answers to obtain first filtered answers, and when the inference answers are consistent with the answer text in the learning template pair, constructing a non-logical template pair corresponding to the learning template pair using the following format: <Y, has, A>, [sep], <A, has, X> <Y, is, A>, [sep], <A, is, X> <X, has, A>, [sep], <A, has, Y> <X, is, A>, [sep], <A, is, Y> wherein X and Y represent two different entities in the extracted entity, A represents the corresponding answer that a subsequent BERT model needs to make according to the extracted entity, "is" represents the definition of a relationship in the knowledge graph triple, "has" represents the definition of an attribute in the knowledge graph triple, and [sep] represents a special label for separating the symmetric template pairs on the left and right sides; removing answers that do not conform to the non-logical template pair from the first filtered answers to obtain second filtered answers, extracting answers that conform to the knowledge graph triple from the second filtered answers to obtain filtered answers, calculating the cross-entropy loss of the filtered answers according to the 0~1 distribution corresponding to the filtered answers and the true category corresponding to the filtered answers, calculating the consistency loss of the filtered answers according to the filtered answers and the corresponding true answers, and calculating the overall loss according to the cross-entropy loss and the consistency loss; performing model training on the to-be-trained inference model according to the cross-entropy loss, the consistency loss and the overall loss to obtain a trained inference model; identifying a text inference result of a to-be-inferred text by using the trained inference model.

2. The first-order reasoning method for knowledge question answering based on prompt as described in claim 1, characterized in that, The step of performing entity extraction on a question to obtain an extracted entity comprises: determining the to-be-extracted entity category of the question; inputting the question into a preset bidirectional recurrent memory model, and calculating the entity category probability of each word in the question belonging to the to-be-extracted entity category by using the bidirectional recurrent memory model; identifying the extracted entity of the question by using a preset named entity recognition model based on the entity category probability.

3. The first-order reasoning method for knowledge question answering based on prompt as described in claim 1, characterized in that, The step of constructing a learning template pair for the extracted entity based on the knowledge graph triple comprises: constructing the learning template pair for the extracted entity using the following format based on the knowledge graph triple: <X, has, A>, [sep], <A, is, Y> <X, is, A>, [sep], <A, has, Y> <Y, has, A>, [sep], <A, is, X> <Y, is, A>, [sep], <A, has, X> <Y, is, A>, [sep], <A, is, Y> <Y, have, A>, [sep], <A, have, Y> <X, be, A>, [sep], <A, be, X> <X, have, A>, [sep], <A, have, X>.

4. The first-order reasoning method for knowledge question answering based on prompt as described in claim 1, characterized in that, The splicing the to-be-trained text and the learning template pair to obtain a spliced sample includes: Acquire the background knowledge text, the question text and the answer text in the to-be-trained text, and splice the to-be-trained text and the learning template pair using the following format based on the background knowledge text, the question text and the answer text, to obtain the spliced sample: [CLS], P, [sep], Q, [sep], A, [sep], T Wherein, [CLS] and [sep] represent special labels, P represents the background knowledge text, Q represents the question text, A represents the answer text, and T represents the learning template pair.

5. The first-order reasoning method for knowledge question answering based on prompt as described in claim 1, characterized in that, The inputting the spliced sample into the to-be-trained inference model includes: Extracting the to-be-answered text in the spliced sample; Performing masking processing on the to-be-answered text to obtain a masked text; Inputting the spliced sample containing the masked text into the to-be-trained inference model.

6. The first-order reasoning method for knowledge question answering based on prompt as described in claim 1, characterized in that, The method includes: Calculating the cross-entropy loss using the following formula according to the 0~1 distribution corresponding to the filtered answer and the true category corresponding to the filtered answer: in, This represents the cross-entropy loss. This represents the one-hot encoding of the true category corresponding to the filtered answer. It contains two types of values: 0 and 1. 1 represents the probability of predicting the true class, and 0 represents the probability of predicting the false class. Let represent the distribution after softmax, i.e., the 0~1 distribution corresponding to the selected answer; ... Indicates in The probability of being 1 and in The probability of it being 0; Calculating the consistency loss using the following formula according to the filtered answer and the corresponding true answer: in, This represents the consistency loss. The value can be either 0 or 1. 1 indicates that the predicted filtered answer matches the actual result, while 0 indicates that the predicted filtered answer does not match the actual result. exist When is 1, the probability that the selected answer matches the true result is in The probability that the selected answer is inconsistent with the actual result when the value is 0, where j represents the predicted sequence number of the selected answer, and N represents the total number of predicted selected answers. The predicted filtered answer, This indicates a truthful answer; Calculating the overall loss using the following formula according to the cross-entropy loss and the consistency loss: in, This represents the overall loss, i.e., the loss value of the entire BERT model. Include and .

7. A first-order reasoning device for knowledge question answering based on prompt, characterized in that, The apparatus includes: An entity extraction module, configured to acquire a to-be-trained text, construct a knowledge graph triple of the to-be-trained text, perform entity extraction on a question, and obtain an extracted entity; A sample splicing module, configured to construct a learning template pair of the extracted entity based on the knowledge graph triple, and splice the to-be-trained text and the learning template pair to obtain a spliced sample; A loss calculation module, configured to input the spliced sample into a to-be-trained inference model, output multiple inference answers of the spliced sample using the to-be-trained inference model, extract an answer that is consistent with the answer text in the inference answers and the learning template pair to obtain a first filtered answer, and when the inference answer is consistent with the answer text in the learning template pair, construct a non-logical template pair corresponding to the learning template pair using the following format: <Y, have, A>, [sep], <A, have, X> <Y, be, A>, [sep], <A, be, X> <X, have, A>, [sep], <A, have, Y> <X, be, A>, [sep], <A, be, Y> Where X and Y represent two different entities in the extracted entities, A represents the corresponding answer that the BERT model needs to make based on the extracted entities, "is" represents the definition of the relation in the knowledge graph triple, "have" represents the definition of the attribute in the knowledge graph triple, [sep] represents a special label used to segment symmetrical template pairs on the left and right sides, remove answers in the first filtering answer that do not conform to the no-logic template pair to obtain the second filtering answer, extract answers in the second filtering answer that conform to the knowledge graph triple to obtain the filtering answer, calculate the cross-entropy loss of the filtering answer based on the 0~1 distribution corresponding to the filtering answer and the true category corresponding to the filtering answer, calculate the consistency loss of the filtering answer based on the filtering answer and the corresponding true answer, and calculate the overall loss based on the cross-entropy loss and the consistency loss. The model training module is used to train the inference model to be trained based on the cross-entropy loss, the consistency loss, and the overall loss, so as to obtain a trained inference model. The text reasoning module is used to identify the text reasoning result of the text to be reasoned using the trained reasoning model.

8. An electronic device, characterized in that, The electronic device includes: At least one processor; and, A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the prompt-based first-order reasoning method for knowledge answering as described in any one of claims 1 to 6.

9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the prompt-based first-order reasoning method for knowledge answering as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Information extraction method, and method and device for training question and answer processing model

    CN116662496A

  • Question and answer method and device for knowledge in field of literature and blog, equipment and medium

    CN117216194A