Question answer determination method and device, electronic equipment and computer storage medium
By transforming knowledge into formal logical rules and building constraint graphs for real-time constraint decoding, the problem of insufficient accuracy of generated answers in the prior art is solved, and answer generation with high accuracy and logical consistency is achieved.
Patent Information
- Application Number
- CN202510648620.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-20
- Publication Date
- 2025-08-19
AI Technical Summary
The existing technology relies on the parameterization knowledge and decoding strategies of language models, and cannot guarantee that the generated results strictly follow the retrieved facts, resulting in insufficient accuracy of generated answers.
Transform knowledge into formal logical rules, build a constraint graph and perform real-time constraint decoding during the language model generation stage, and logically constrain the generation process through formal logical rule base and constraint graph to ensure that the answer is in line with the facts.
It significantly improves the accuracy and logical consistency of generated answers, ensures that the generated content meets factual requirements in the generation stage, and is post-processed and verified through the probabilistic logic network, enhancing the robustness and credibility of the system.
Smart Images

Figure CN120508625A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a method, device, electronic device, and computer storage medium for determining answers to questions. Background Art
[0002] With the rise of Large Language Models (LLMs) and Retrieval-Augmented Generation (RAG) technologies, the capabilities and application scope of natural language generation systems have been greatly improved. Current mainstream methods rely on the following mechanisms to ensure factual accuracy:
[0003] 1. Retrieval-augmented generation (RAG): Retrieving relevant documents from the knowledge base to provide information for generation;
[0004] 2. Back-end verification: Post-verification of generated results based on text matching or natural language inference (NLI) models;
[0005] 3. In-Context Learning: Provide examples to guide the model to generate answers that are consistent with the facts.
[0006] However, these methods still have significant limitations. In particular, RAG systems, while providing factual evidence through retrieval, still rely heavily on the parameterized knowledge and decoding strategies of the language model during the actual generation phase, and cannot guarantee that generation strictly adheres to the retrieved facts. Summary of the Invention
[0007] In view of this, the present application provides a method, device, electronic device and computer storage medium for determining the answer to a question, which converts knowledge into formalized logical rules, directly constrains the decoding process in the generation stage, and thus achieves high-accuracy answer generation.
[0008] The first aspect of the present application provides a method for determining an answer to a question, comprising:
[0009] Receive user query information;
[0010] Extracting knowledge fragments related to the query information from the knowledge base;
[0011] For each knowledge fragment, extract the first-order logic rules corresponding to the knowledge fragment from the formal logic rule library;
[0012] Constructing a constraint graph according to all the first-order logic rules;
[0013] The user's query information is input into the language model, and a set of candidate answers is output; wherein, the language model uses the constraint graph to perform real-time constraints during the decoding process to generate candidate answers that meet the constraint graph.
[0014] Optionally, the method for constructing the formal logic rule base includes:
[0015] Generate multiple entity relationships based on the knowledge graph;
[0016] For each of the entity relationships, convert the entity relationship into a first-order logic rule;
[0017] Combining the frequency of entity relationships and text co-occurrence statistics, assigning a confidence weight to each of the first-order logic rules and establishing a rule index;
[0018] A formalized logic rule library is established based on all the first-order logic rules and their corresponding confidence weights and indexes.
[0019] Optionally, constructing a constraint graph according to all the first-order logic rules includes:
[0020] For each first-order logic rule, the syntax parser is used to parse the first-order logic rule into an abstract syntax tree;
[0021] Performing conjunction normal form conversion and variable normalization on the abstract syntax tree to obtain a standardized logical expression structure;
[0022] Creating a predicate node for each predicate in the normalized logical expression structure, creating an entity node for each entity, and adding a type constraint tag to the variable;
[0023] Determining edges between nodes according to the logical relationships in the first-order logic rules;
[0024] Generate edge weights using the frequency of entity relationships and text co-occurrence statistics;
[0025] Generate a constraint graph based on all nodes, edges between nodes, and edge weights.
[0026] Optionally, the language model uses the constraint graph to perform real-time constraints during the decoding process to generate candidate answers that satisfy the constraint graph, including:
[0027] During the decoding process, the language model calculates the probability distribution of candidate tokens based on the currently generated partial sequence;
[0028] For each candidate token, use the constraint graph to perform constraint satisfaction check on the candidate token to obtain a constraint satisfaction check result;
[0029] The candidate sequence paths that meet all the constraints are retained until the termination condition is reached; wherein, the candidate sequence path is the complete sequence formed by adding a valid candidate token to the current generated sequence.
[0030] Optionally, for each token, performing a constraint satisfaction check on the token using a constraint graph to obtain a constraint satisfaction check result includes:
[0031] Add the candidate token to the current sequence to form an extended sequence;
[0032] Converting the natural language content of the extended sequence into a structured triple form to obtain triple data of the extended sequence;
[0033] It is detected whether the triple data of the extended sequence has a logical conflict with the active path in the constraint graph, and a constraint satisfaction check result is obtained.
[0034] Optionally, after inputting the user's query information into the language model and outputting a set of candidate answers, the method further includes:
[0035] For each candidate answer in the candidate answer list, calculate the comprehensive probability score of the candidate answer;
[0036] The candidate answer with the highest comprehensive probability score is selected as the target answer.
[0037] Optionally, calculating the comprehensive probability score of each candidate answer in the candidate answer list includes:
[0038] For each candidate answer in the candidate answer list, perform proposition decomposition on the candidate answer to obtain a proposition analysis result;
[0039] For each independent proposition in the proposition analysis result, convert the independent proposition into a structured triple form to obtain triple data of the independent proposition;
[0040] Calculating the rationality probability of the independent proposition based on the triple data of the independent proposition;
[0041] Based on the rationality probabilities of all the independent propositions, the comprehensive probability scores of the candidate answers are calculated.
[0042] A second aspect of the present application provides a device for determining an answer to a question, comprising:
[0043] A receiving unit, configured to receive query information from a user;
[0044] A query unit, configured to extract knowledge fragments related to the query information from the knowledge base;
[0045] An extraction unit, configured to extract, for each knowledge fragment, a first-order logic rule corresponding to the knowledge fragment from a formal logic rule base;
[0046] A constraint graph construction unit, configured to construct a constraint graph according to all the first-order logic rules;
[0047] The analysis unit is used to input the user's query information into the language model and output a set of candidate answers; wherein, the language model uses the constraint graph to perform real-time constraints during the decoding process to generate candidate answers that meet the constraint graph.
[0048] Optionally, the construction unit of the formal logic rule base includes:
[0049] An entity relationship generation unit, used to generate multiple entity relationships based on the knowledge graph;
[0050] a conversion unit, configured to convert each entity relationship into a first-order logic rule;
[0051] A weight index assignment unit, configured to assign a confidence weight to each of the first-order logic rules and establish a rule index based on the frequency of entity relationships and text co-occurrence statistics;
[0052] The rule base establishing unit is used to establish a formal logic rule base based on all the first-order logic rules and their corresponding confidence weights and indexes.
[0053] Optionally, the constraint graph construction unit includes:
[0054] A parsing unit is used to parse each first-order logic rule into an abstract syntax tree through a syntax parser;
[0055] a normalization processing unit, configured to perform conjunction normal form conversion and variable normalization on the abstract syntax tree to obtain a normalized logical expression structure;
[0056] a creation unit, configured to create a predicate node for each predicate in the normalized logical expression structure, create an entity node for each entity, and add a type constraint tag to a variable;
[0057] an edge determination unit, configured to determine edges between nodes according to the logical relationship in the first-order logic rule;
[0058] A weight generation unit, which is used to generate edge weights using the frequency of entity relationships and text co-occurrence statistics;
[0059] The constraint graph generation unit is used to generate a constraint graph according to all nodes, edges between nodes, and edge weights.
[0060] Optionally, the language model includes:
[0061] The first calculation unit is used to calculate the probability distribution of candidate tokens based on the currently generated partial sequence during the decoding process of the language model;
[0062] A constraint unit, configured to perform a constraint satisfaction check on each candidate token using a constraint graph to obtain a constraint satisfaction check result;
[0063] The path retention unit is used to retain candidate sequence paths that meet all constraints until the termination condition is reached; wherein the candidate sequence path is a complete sequence formed by adding a valid candidate token to the current generated sequence.
[0064] Optionally, the constraint unit includes:
[0065] The add unit is used to add the candidate token to the current sequence to form an extended sequence;
[0066] a first triple conversion unit, configured to convert the natural language content of the extended sequence into a structured triple form to obtain triple data of the extended sequence;
[0067] The conflict detection unit is used to detect whether the triple data of the extended sequence has a logical conflict with the active path in the constraint graph, and obtain a constraint satisfaction check result.
[0068] Optionally, the device for determining the answer to the question further includes:
[0069] a second calculation unit, configured to calculate a comprehensive probability score of each candidate answer in the candidate answer list;
[0070] The target answer determination unit is used to select the candidate answer with the highest comprehensive probability score as the target answer.
[0071] Optionally, the second computing unit includes:
[0072] A proposition decomposition unit is used to perform proposition decomposition on each candidate answer in the candidate answer list to obtain a proposition analysis result;
[0073] A second triple conversion unit is configured to convert each independent proposition in the proposition analysis result into a structured triple form to obtain triple data of the independent proposition;
[0074] A third calculation unit is used to calculate the rationality probability of the independent proposition according to the triple data of the independent proposition;
[0075] The fourth calculation unit is used to calculate the comprehensive probability score of the candidate answer based on the rationality probability of all the independent propositions.
[0076] A third aspect of the present application provides an electronic device, including:
[0077] one or more processors;
[0078] a storage device having one or more programs stored thereon;
[0079] When the one or more programs are executed by the one or more processors, the one or more processors implement the method for determining the answer to the question as described in any one of the first aspects.
[0080] A fourth aspect of the present application provides a computer storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the method for determining the answer to the question as described in any one of the first aspects is implemented.
[0081] As can be seen from the above scheme, the present application provides a method, device, electronic device and computer storage medium for determining the answer to a question. After receiving the user's query information, the knowledge fragments related to the query information are extracted from the knowledge base; for each knowledge fragment, the first-order logic rules corresponding to the knowledge fragment are extracted from the formal logic rule base; then, a constraint graph is constructed based on all the first-order logic rules; finally, the user's query information is input into the language model, and a set of candidate answers is output. By converting knowledge into formal logic rules, the decoding process is directly constrained in the language model generation stage, thereby achieving high-accuracy answer generation. BRIEF DESCRIPTION OF THE DRAWINGS
[0082] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are merely embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0083] Figure 1 A specific flow chart of a method for determining an answer to a question provided in an embodiment of the present application;
[0084] Figure 2 A specific flow chart of a method for constructing a formal logic rule base provided in another embodiment of the present application;
[0085] Figure 3 A specific flow chart of a method for constructing a constraint graph provided in another embodiment of the present application;
[0086] Figure 4 A specific flow chart of a method for generating candidate answers that satisfy a constraint graph provided in another embodiment of the present application;
[0087] Figure 5 A specific flow chart of a method for checking constraint satisfaction of candidate tokens using a constraint graph provided in another embodiment of the present application;
[0088] Figure 6 A flowchart of a method for determining an answer to a question provided in another embodiment of the present application;
[0089] Figure 7 A flowchart of a method for calculating a comprehensive probability score of a candidate answer provided in another embodiment of the present application;
[0090] Figure 8 A schematic diagram of a device for determining an answer to a question provided in another embodiment of the present application;
[0091] Figure 9 A schematic diagram of an electronic device for implementing a method for determining an answer to a question provided in another embodiment of the present application. DETAILED DESCRIPTION
[0092] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0093] As used herein, the term "including" and its variations are open-ended, i.e., "including but not limited to." The term "based on" means "based, at least in part, on." The term "one embodiment" means "at least one embodiment," the term "another embodiment" means "at least one additional embodiment," and the term "some embodiments" means "at least some embodiments." Other terms are defined in the following description.
[0094] It should be noted that the information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions.
[0095] It should be noted that the concepts of "first" and "second" mentioned in this application are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0096] It should be noted that the modifications of "one" and "multiple" mentioned in this application are illustrative rather than restrictive. Those skilled in the art should understand that unless otherwise clearly indicated in the context, they should be understood as "one or more".
[0097] The present application embodiment provides a method for determining the answer to a question, such as Figure 1 As shown, the specific steps include:
[0098] S101: Receive user query information.
[0099] In the actual application process of this application, users can input query messages through mobile phones, laptops, etc. in text, voice, etc., which is not limited here.
[0100] S102: Extract knowledge fragments related to the query information from the knowledge base.
[0101] Continuing with the above example, when the user inputs voice information, if the knowledge base does not support voice search, the voice is converted into text before searching. There is no limitation here.
[0102] It is understandable that the user's query information can be classified first. For example, if the user queries for medical-related information, then the medical-related knowledge base will be called. This is not limited here.
[0103] In the actual application of this application, multi-level search can be performed in the knowledge base to obtain knowledge fragments related to the query information. Taking the medical knowledge base as an example, assuming that the user's query information is "I am a 60-year-old male patient with hypertension and type 2 diabetes. I now have shoulder pain. Can I take ibuprofen?", then a multi-level search is performed to obtain knowledge fragments related to the query information from the medical knowledge base: Ibuprofen belongs to the class of non-steroidal anti-inflammatory drugs (NSAIDs); NSAIDs may increase the cardiovascular risk of patients with hypertension, especially when used in large doses for a long time; NSAIDs may affect renal function and require additional monitoring for diabetic patients; for short-term treatment of mild to moderate pain, low-dose ibuprofen (such as no more than 1200 mg per day) may be an acceptable treatment option. The system also retrieved clinical guidelines that recommend that patients over 60 years old should reduce the dose and shorten the duration of use of NSAIDs.
[0104] S103. For each knowledge fragment, extract the first-order logic rules corresponding to the knowledge fragment from the formal logic rule library.
[0105] Optionally, in the actual application process of this application, an implementation method of constructing a formal logic rule base is as follows: Figure 2 Shown, including:
[0106] S201. Generate multiple entity relationships based on the knowledge graph.
[0107] In the specific implementation process of this application, named entity recognition and relationship extraction can be performed on unstructured text through but not limited to prompt engineering and large models; association rule mining algorithms can be used to perform statistical analysis on entity relationships in the knowledge base, automatically discover high-frequency co-occurrence patterns and conditional probability relationships, and generate a preliminary set of rule candidates, which is not limited here.
[0108] S202: For each entity relationship, convert the entity relationship into a first-order logic rule.
[0109] Continuing with the above example, the present invention can automatically convert the extracted relation triples (subject, relation, object) into first-order logic expressions based on a large model, which is not limited here.
[0110] For example, "Drug A belongs to category B" is converted to the predicate form Category(A, B), and "Symptom X causes disease Y" is converted to p(HasSymptom(p,X)→RiskOf(p,Y)).
[0111] S203 : Based on the frequency of entity relationships and text co-occurrence statistics, assign a confidence weight to each first-order logic rule and establish a rule index.
[0112] For example: the higher the relationship frequency, the greater the confidence weight assigned to the first-order logic rule; the higher the text co-occurrence statistics, the greater the confidence weight assigned to the first-order logic rule, etc.
[0113] S204: Establish a formal logic rule library based on all first-order logic rules and their corresponding credibility weights and indexes.
[0114] It can be understood that a rule index is established to support fast retrieval.
[0115] S104. Construct a constraint graph based on all first-order logic rules.
[0116] Optionally, in another embodiment of the present application, an implementation of step S104 is as follows: Figure 3 Shown, including:
[0117] S301. For each first-order logic rule, parse the first-order logic rule into an abstract syntax tree through a syntax parser.
[0118] First, define the token type, for example: atomic propositions: capital letters such as P and Q; logical operators: ∧ (and), ∨ (or), ¬ (not), → (implication); quantifiers: (full name), (exists); auxiliary symbols: brackets (), commas, etc. Then, regular expressions are used to match tokens. For example, the rule for identifying variable names is [A-Z][0-9]*. Operators match fixed strings. Grammar rules are then designed, such as a definition scheme for Chinese grammar rules based on Backus-Naur Form (BNF). Finally, the nodes of the abstract syntax tree are constructed.
[0119] Among them, token is the smallest processing unit.
[0120] S302: Perform conjunction normal form conversion and variable normalization on the abstract syntax tree to obtain a standardized logical expression structure.
[0121] The standardized logical expression structure is specifically characterized by the following core features:
[0122] Conjunctive Normal Form Expression: All logical formulas are converted to Conjunctive Normal Form (CNF), which consists of a conjunction (∧) of several clauses, each of which is a disjunction (∨) of literals. For example, the AST (Abstract Syntax Tree) of the original formula (A∨B)∧C will be reconstructed into a multi-level conjunction-disjunction structure. Nested logical operators in the original abstract syntax tree (such as implication→, double implication) ) are eliminated and converted into equivalent disjunctive and conjunctive combinations.
[0123] Variable standardization: All variables are uniquely named, eliminating naming conflicts (such as through Alpha replacement) and ensuring the uniqueness of the same variable within the scope. For example x(P(x)→ x(Q(x))) will be normalized to x(P(x)→ y(Q(y))). Variable nodes in the AST carry a unified identifier to facilitate subsequent logical reasoning or constraint solving.
[0124] S303: Create a predicate node for each predicate in the normalized logical expression structure, create an entity node for each entity, and add a type constraint tag for the variable.
[0125] S304: Determine the edges between the nodes according to the logical relationship in the first-order logic rules.
[0126] For example, the implication relation (A→B) in the logic rule is converted into a directed edge from node A to node B, the conjunction relation (A∧B) is represented as an edge connected to the shared dependency node, the disjunction relation (A∨B) is represented as an edge connected to the selection node, and a special inversion node is created for negation (¬A). For rules containing quantification, the system creates a special quantification node, which is called quantification ( x) is transformed into a constraint edge for all relevant predicates, while existential quantification ( x) generates a selection structure that requires at least one condition to be met.
[0127] S305: Generate edge weights using the frequency of entity relationships and text co-occurrence statistics.
[0128] S306: Generate a constraint graph based on all nodes, edges between nodes, and edge weights.
[0129] Based on logical rules Taking x(Person(x)∧CEO_of(x,CompanyA)→HasRole(x,"CEO")) as an example, we will demonstrate a specific constraint graph construction process. The following is the process of constructing a constraint graph for the rule " The constraint graph construction process of "x(Person(x)∧CEO_of(x,CompanyA)→HasRole(x,"CEO"))" is as follows:
[0130] First, we use a parser to parse this rule into an abstract syntax tree. The rule is identified as a universally quantified structure, with an implicational subject and a conjunction-form antecedent. This processing creates the following node structure: a node representing the "Person" predicate, a node representing the "CEO_of" relation, and a node representing the "HasRole" relation. The variable x is labeled as a person type and shared across the relevant nodes.
[0131] In the edge construction phase, the system identifies the conjunction relation “Person(x)∧CEO_of(x, CompanyA)” and creates an AND dependency node to connect the “Person” and “CEO_of” nodes. Then, the system identifies the implication relation “→” and creates an IMPLIES type directed edge from the AND dependency node to the “HasRole” node. x", the system adds quantization constraint tags to all nodes involving variable x.
[0132] Regarding weight assignment, the system analysis found that this rule has a high-frequency occurrence pattern in the enterprise knowledge base. Statistical analysis showed that the co-occurrence probability of "CEO_of" and "HasRole(CEO)" reached 98%. Therefore, the system assigned a high confidence weight of 0.98 to the IMPLIES edge.
[0133] The resulting constraint graph consists of five main nodes (Person, CEO_of, CompanyA, HasRole, and CEO) and the edges connecting them, forming an inference network that can be used for constraint decoding. When the generation system attempts to describe the CEO of CompanyA, this constraint graph ensures that the generated content follows the logical rule that "if someone is the CEO of CompanyA, then they have the CEO role."
[0134] S105: Input the user's query information into the language model, and output a set of candidate answers.
[0135] Among them, the language model uses the constraint graph to perform real-time constraints during the decoding process and generates candidate answers that meet the constraint graph.
[0136] It should be noted that the language model can be but is not limited to Beam Search, and is not limited here.
[0137] Optionally, in the actual application process of this application, the language model uses the constraint graph to perform real-time constraints during the decoding process to generate a candidate answer that satisfies the constraint graph, such as Figure 4 Shown, including:
[0138] S401: During the decoding process, the language model calculates the probability distribution of candidate tokens based on the currently generated partial sequence.
[0139] Among them, the candidate token is all possible next words in the model vocabulary.
[0140] It is understandable that the language model needs to be initialized before decoding. Taking Beam Search as an example, the Beam set is initialized, including the start marker as the initial sequence, which is not limited here.
[0141] Taking the constraint graph constructed above as an example, when the system is generating a description of CompanyA's management, if the current sequence contains content indicating that "someone is the CEO of CompanyA," the constraint state tracker will mark the "Person" and "CEO_of" nodes in the constraint graph as activated. At this point, if any of the high-probability tokens predicted by the language model would result in content that violates the "HasRole(x, 'CEO')" constraint (for example, incorrectly describing someone as "CFO"), the system will detect this violation.
[0142] S402: For each candidate token, perform constraint satisfaction check on the candidate token using the constraint graph to obtain a constraint satisfaction check result.
[0143] Optionally, in another embodiment of the present application, an implementation of step S402 is as follows: Figure 5 Shown, including:
[0144] S501: Add the candidate token to the current sequence to form an extended sequence.
[0145] S502: Convert the natural language content of the extended sequence into a structured triple form to obtain triple data of the extended sequence.
[0146] In the specific implementation process of this application, a sequence semantic parser can be used but is not limited to converting the natural language content of the extended sequence into a structured triple form (for example, converting "Zhang San is the CEO of CompanyA" into <Zhang San, CEO_of, CompanyA>), which is not limited here.
[0147] S503: Check whether the triple data of the extended sequence has a logical conflict with the active path in the constraint graph, and obtain a constraint satisfaction check result.
[0148] For example, if the constraint graph stipulates that "CompanyA's CEO must have the CEO role", but the extended sequence implies that "Zhang San is CompanyA's CEO but holds the CFO position", the system will immediately identify this logical contradiction and mark the corresponding candidate token as violating the constraint, thereby proactively avoiding factual errors during the generation process.
[0149] S403: retain candidate sequence paths that meet all constraints until a termination condition is reached.
[0150] The candidate sequence path is the complete sequence formed by adding a valid candidate token to the current generated sequence.
[0151] After each decoding step, the system prunes and retains only the top-k optimal paths for further expansion based on the comprehensive score of sequence probability and constraint satisfaction.
[0152] Specifically, termination conditions include but are not limited to: reaching a complete answer (indicated by the model generating the end marker); reaching the preset maximum generation length; all paths are pruned due to constraint violations (in this case, triggering the fallback strategy), etc., which are not limited here.
[0153] Ultimately, the system outputs a complete sequence of candidate answers to the question, each of which is guaranteed to conform to the logical rules encoded in the constraint graph.
[0154] The present invention prevents content that conflicts with facts directly at the generation source, thereby significantly improving the factual accuracy of the generated text.
[0155] Even with constraint decoding, local constraints may still not guarantee the logical consistency of the overall content, especially for complex facts that require multi-step reasoning. To solve this problem, in another embodiment of the present application, after the user's query information is input into the language model and a set of candidate answers is output, an implementation method of determining the answer to the question is as follows: Figure 6 As shown, it also includes:
[0156] S601: Calculate the comprehensive probability score of each candidate answer in the candidate answer list.
[0157] S602: The candidate answer with the highest comprehensive probability score is selected as the target answer.
[0158] Optionally, in another embodiment of the present application, an implementation of step S601 is as follows: Figure 7 Shown, including:
[0159] S701. For each candidate answer in the candidate answer list, perform proposition decomposition on the candidate answer to obtain a proposition analysis result.
[0160] During the specific implementation of the application, the generated answers can be accurately split using, but not limited to, a proposition decomposition algorithm based on semantic structure analysis, which is not limited here.
[0161] Specifically, the algorithm first uses dependency parsing to identify the subject-verb-object structure, then extracts the core assertions of each sentence. Complex compound sentences are broken down into multiple simple declarative sentences, with conjunctions and subordinate clauses identified as independent logical relationships.
[0162] For example: For a text like "Zhang San is the CEO of CompanyA. He took over the position in 2020 and promoted the company's digital transformation", the system can automatically split it into three independent propositions: 1) "Zhang San is the CEO of CompanyA"; 2) "Zhang San took over the CEO position in 2020"; 3) "Zhang San promoted the digital transformation of CompanyA".
[0163] S702. For each independent proposition in the proposition analysis result, convert the independent proposition into a structured triple form to obtain triple data of the independent proposition.
[0164] In the specific implementation process of the application, independent propositions can be converted into structured triples through but not limited to a sequence semantic parser, which is not limited here.
[0165] For example, "Zhang San is the CEO of Company A" is converted into two associated logical representations: <Zhang San, CEO_of, Company A> and HasRole(Zhang San, "CEO").
[0166] S703. Calculate the probability of rationality of the independent proposition based on the triple data of the independent proposition.
[0167] S704. Calculate the comprehensive probability score of the candidate answers based on the rationality probabilities of all independent propositions.
[0168] In the specific implementation process of the application, the following can be done, but not limited to: After completing the proposition conversion, the system constructs a probabilistic logic network (PLN) to evaluate the overall logical consistency of the generated content. For the transformed proposition set P = {p1, ..., p m}, the system calculates each independent proposition p i The probability of rationality, and the joint probability distribution of the entire proposition set P: P r (P|KG,Rules)=(1 / Z)·exp(∑w i ·1_{KG p i}).
[0169] Where Z is a normalization constant used to ensure the validity of the probability distribution; w i i indicates support or opposition to proposition p i Rule weight; indicator function 1_{KG p i} Determine whether the knowledge graph KG supports a specific proposition p i .
[0170] If the calculated probability value exceeds the preset threshold τ, the content is considered to have passed the fact verification; otherwise, the degradation or regeneration strategy is triggered.
[0171] By introducing the PLN mechanism, the present invention realizes global and quantitative verification of generated content, forming a dual protection mechanism of "generation constraint + verification and validation".
[0172] To this end, the present invention has significantly improved the factual accuracy and logical consistency of natural language generation results by innovatively introducing formalized first-order logic rules into the generation stage and combining the constraint decoding algorithm and the probabilistic logic network posterior verification mechanism.
[0173] The core advantage of this invention lies in its proposed triple-coordinated technical framework of "formal logic rule constraints + constraint decoding algorithms + probabilistic logic network verification." By deeply analyzing the entity relationships in the knowledge base and automatically extracting first-order logic expressions, this system implements real-time logical constraints on the generation process. The system adopts an overall technical approach of "knowledge retrieval + logical rule construction + constraint decoding + probabilistic logic verification." By constructing a constraint graph (Constraint Graph) for real-time constraint decoding paths, the generated content meets factual requirements during the generation phase. Furthermore, the system innovatively employs a probabilistic logic network (PLN) for post-processing and global consistency quantitative evaluation of the generated results, further enhancing the system's robustness and credibility.
[0174] Taking the query "I am a 60-year-old male patient with hypertension and type 2 diabetes, and I have shoulder pain. Can I take ibuprofen?" as an example, the steps of the present invention are exemplified as follows:
[0175] 1. Knowledge Retrieval: The system performs a multi-level search, extracting key information from the medical knowledge base: ibuprofen belongs to the class of nonsteroidal anti-inflammatory drugs (NSAIDs); NSAIDs may increase cardiovascular risk in patients with hypertension, especially when used in high doses over a long period of time; NSAIDs may affect renal function, requiring additional monitoring in patients with diabetes; and for the short-term treatment of mild to moderate pain, low-dose ibuprofen (e.g., no more than 1200 mg per day) may be an acceptable treatment option. The system also retrieved clinical guidelines recommending a lower dose and shorter duration of NSAID use in patients over 60 years of age.
[0176] 2. Logical rule extraction: The system extracts and constructs formal logical rules from the search content, including:
[0177] p,m(Patient(p) ∧HasCondition(p, "Hypertension") ∧Medication(m) ∧Type(m, "NSAID") ∧LongTermUse(p,m)→IncreasedRisk(p, "Cardiovascular Events"))
[0178] p,m(Patient(p)∧HasCondition(p,"Diabetes")∧Medication(m)∧Type(m,"NSAID")→MonitorRequired(p,"Renal Function"))
[0179] p,m,d(Patient(p)∧Medication(m)∧Type(m,"NSAID")∧Dosage(d)∧LessThan(d,"Maximum Recommended Dose")∧ShortTermUse(p,m)→PotentiallyAppropriate(p,m))
[0180] p,m(Patient(p)∧Age(p,a)∧GreaterThan(a,60)∧Medication(m)∧Type(m,"NSAID")→ReducedDosageRecommended(p,m))
[0181] 3. Constraint Graph Construction: The system converts the extracted logical rules into a constraint graph. Taking the first rule as an example, the system creates the "Patient," "HasCondition," "Medication," "Type," "LongTermUse," and "IncreasedRisk" nodes and establishes corresponding edge connections. Based on the user's situation, the system activates constraint paths related to "hypertension," "diabetes," "age 60," and "NSAIDs." This constraint graph provides real-time guidance for subsequent generation, ensuring that generated content adheres to medical facts.
[0182] 4. Constraint decoding: The system applies the constraint graph to real-time checks during answer generation. For example, when a candidate sequence such as "Ibuprofen is completely safe for you" appears during decoding, the constraint checker identifies this as a violation of the risk rule for NSAID use in patients with hypertension and immediately prunes the generated path.
[0183] 5. Generate candidate answers: The system generates multiple candidate answers that meet the constraints, mainly including:
[0184] Candidate 1: "As a 60-year-old patient with hypertension and type 2 diabetes, you need to be extremely cautious when using ibuprofen. Short-term, low-dose use may relieve shoulder pain, but there are potential risks. Due to your age and underlying conditions, it is recommended that you consult a doctor before use, and you need to regularly monitor changes in kidney function and blood pressure."
[0185] Candidate 2: "Ibuprofen is an NSAID and may increase cardiovascular risk in patients with hypertension, especially with long-term use. Considering your history of diabetes, the effects of ibuprofen on renal function should also be a concern. If use is necessary, it is recommended to choose the lowest effective dose and limit use to short-term periods (no more than 7-10 days). It is best to consult your doctor for personalized advice before using this medication."
[0186] Candidate 3: "Ibuprofen is not the ideal pain reliever for your condition, but short-term, low-dose use under a doctor's guidance may be acceptable. As a 60-year-old with hypertension and diabetes, you will need to reduce your usual dose of NSAIDs such as ibuprofen. Consider first trying non-drug treatments such as physical therapy or topical analgesics."
[0187] 6. PLN Verification: The system performs proposition decomposition and logic verification on each candidate answer. Taking candidate 2 as an example, the system extracts the following propositions: (1) Ibuprofen is an NSAID drug; (2) NSAIDs may increase cardiovascular risk in patients with hypertension; (3) Long-term use of NSAIDs is more risky; (4) NSAIDs may affect the renal function of patients with diabetes; (5) The lowest effective dose should be selected; (6) Use should be limited to short-term use; (7) A doctor should be consulted before use. The system matches and infers these propositions with the knowledge graph and rule base, and calculates the comprehensive probability score of each candidate answer:
[0188] Candidate 1: 0.87;
[0189] Candidate 2: 0.92;
[0190] Candidate 3: 0.89.
[0191] 7. Final Answer: The system selects candidate 2, which has the highest score, as the final answer. This answer not only aligns with medical facts but also comprehensively addresses the key considerations in the user's situation, providing specific and balanced medication recommendations while avoiding absolutes and embodying the principle of personalized medical consultation.
[0192] As can be seen from the above scheme, the present application provides a method for determining the answer to a question. After receiving the user's query information, knowledge fragments related to the query information are extracted from the knowledge base; for each knowledge fragment, the first-order logic rules corresponding to the knowledge fragment are extracted from the formal logic rule base; then, a constraint graph is constructed based on all the first-order logic rules; finally, the user's query information is input into the language model, and a set of candidate answers is output. By converting knowledge into formal logic rules, the decoding process is directly constrained in the language model generation stage, thereby achieving high-accuracy answer generation.
[0193] Another embodiment of the present application provides a device for determining the answer to a question, such as Figure 8 As shown, specifically including:
[0194] The receiving unit 801 is configured to receive query information from a user.
[0195] The query unit 802 is used to extract knowledge fragments related to the query information from the knowledge base.
[0196] The extraction unit 803 is used to extract the first-order logic rules corresponding to each knowledge fragment from the formal logic rule base.
[0197] Optionally, in another embodiment of the present application, an implementation of a construction unit of a formalized logic rule base includes:
[0198] The entity relationship generation unit is used to generate multiple entity relationships based on the knowledge graph.
[0199] The conversion unit is used to convert the entity relationship into a first-order logic rule for each entity relationship.
[0200] The weight index assignment unit is used to assign a confidence weight to each first-order logic rule and establish a rule index based on the frequency of entity relationships and text co-occurrence statistics.
[0201] The rule base building unit is used to build a formal logic rule base based on all first-order logic rules and their corresponding confidence weights and indexes.
[0202] For the specific working process of the units disclosed in the above embodiments of the present application, please refer to the corresponding method embodiments, such as Figure 2 As shown, no further details are given here.
[0203] The constraint graph construction unit 804 is configured to construct a constraint graph according to all first-order logic rules.
[0204] Optionally, in another embodiment of the present application, an implementation of the constraint graph construction unit 804 includes:
[0205] The parsing unit is used to parse each first-order logic rule into an abstract syntax tree through a syntax parser.
[0206] The normalization processing unit is used to perform conjunction normal form conversion and variable normalization on the abstract syntax tree to obtain a normalized logical expression structure.
[0207] The creation unit is used to create a predicate node for each predicate in the normalized logical expression structure, create an entity node for the entity, and add a type constraint tag for the variable.
[0208] The edge determination unit is used to determine the edges between nodes according to the logical relationship in the first-order logic rules.
[0209] The weight generation unit is used to generate edge weights using the frequency of entity relationships and text co-occurrence statistics.
[0210] The constraint graph generation unit is used to generate a constraint graph according to all nodes, edges between nodes, and edge weights.
[0211] For the specific working process of the units disclosed in the above embodiments of the present application, please refer to the corresponding method embodiments, such as Figure 3 As shown, no further details are given here.
[0212] The analysis unit 805 is used to input the user's query information into the language model and output a set of candidate answers.
[0213] Among them, the language model uses the constraint graph to perform real-time constraints during the decoding process and generates candidate answers that meet the constraint graph.
[0214] For the specific working process of the units disclosed in the above embodiments of the present application, please refer to the corresponding method embodiments, such as Figure 1 As shown, no further details are given here.
[0215] Optionally, in another embodiment of the present application, an implementation of the language model includes:
[0216] The first calculation unit is used to calculate the probability distribution of candidate tokens based on the currently generated partial sequence during the decoding process of the language model.
[0217] The constraint unit is used to perform a constraint satisfaction check on each candidate token using a constraint graph to obtain a constraint satisfaction check result.
[0218] The path retaining unit is used to retain the candidate sequence paths that meet all the constraints until the termination condition is reached.
[0219] The candidate sequence path is the complete sequence formed by adding a valid candidate token to the current generated sequence.
[0220] For the specific working process of the units disclosed in the above embodiments of the present application, please refer to the corresponding method embodiments, such as Figure 4 As shown, no further details are given here.
[0221] Optionally, in another embodiment of the present application, an implementation of the constraint unit includes:
[0222] The add unit is used to add the candidate token to the current sequence to form an extended sequence.
[0223] The first triple conversion unit is used to convert the natural language content of the extended sequence into a structured triple form to obtain triple data of the extended sequence.
[0224] The conflict detection unit is used to detect whether the triple data of the extended sequence has a logical conflict with the active path in the constraint graph, and obtain the constraint satisfaction check result.
[0225] For the specific working process of the units disclosed in the above embodiments of the present application, please refer to the corresponding method embodiments, such as Figure 5 As shown, no further details are given here.
[0226] Optionally, in another embodiment of the present application, an implementation of the device for determining the answer to a question further includes:
[0227] The second calculation unit is configured to calculate a comprehensive probability score of each candidate answer in the candidate answer list.
[0228] The target answer determination unit is used to select the candidate answer with the highest comprehensive probability score as the target answer.
[0229] For the specific working process of the units disclosed in the above embodiments of the present application, please refer to the corresponding method embodiments, such as Figure 6 As shown, no further details are given here.
[0230] Optionally, in another embodiment of the present application, an implementation of the second computing unit further includes:
[0231] The proposition decomposition unit is used to perform proposition decomposition on each candidate answer in the candidate answer list to obtain a proposition analysis result.
[0232] The second triple conversion unit is used to convert each independent proposition in the proposition analysis result into a structured triple form to obtain triple data of the independent proposition.
[0233] The third calculation unit is used to calculate the rationality probability of the independent proposition based on the triple data of the independent proposition.
[0234] The fourth calculation unit is used to calculate the comprehensive probability score of the candidate answers based on the rationality probabilities of all independent propositions.
[0235] For the specific working process of the units disclosed in the above embodiments of the present application, please refer to the corresponding method embodiments, such as Figure 7 As shown, no further details are given here.
[0236] As can be seen from the above scheme, the present application provides a device for determining the answer to a question. After receiving the user's query information, the device extracts knowledge fragments related to the query information from the knowledge base; for each knowledge fragment, the first-order logic rules corresponding to the knowledge fragment are extracted from the formal logic rule base; then, a constraint graph is constructed based on all the first-order logic rules; finally, the user's query information is input into the language model, and a set of candidate answers is output. By converting knowledge into formal logic rules, the decoding process is directly constrained in the language model generation stage, thereby achieving high-accuracy answer generation.
[0237] The functions described above herein may be performed, at least in part, by one or more hardware logic components. For example, and without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0238] Another embodiment of the present application provides an electronic device, such as Figure 9 Shown, including:
[0239] One or more processors 901.
[0240] The storage device 902 stores one or more programs.
[0241] When the one or more programs are executed by the one or more processors 901 , the one or more processors 901 implement the method for determining the answer to the question as described in the above embodiment.
[0242] Another embodiment of the present application provides a computer storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the method for determining the answer to the question as described in the above embodiment is implemented.
[0243] In the context of this application, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or apparatus. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of machine-readable storage media may include an electrical connection based on one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), optical fibers, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0244] It should be noted that the computer-readable medium referred to in this application may be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. Computer-readable storage media may include, but are not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or components, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection having one or more conductors, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device, or component. In this application, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. This propagated data signal may take a variety of forms, including, but not limited to, electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wire, optical cable, RF (radio frequency), or any suitable combination thereof.
[0245] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.
[0246] Another embodiment of the present application provides a computer program product, which, when executed, is used to perform the above-mentioned method for determining the answer to the question.
[0247] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via a communication device, or installed from a storage device, or installed from a ROM. When the computer program is executed by a processing device, the above-mentioned functions defined in the method of the embodiment of the present application are performed.
[0248] Although the subject matter has been described in terms of structural features and / or method logic actions, it should be understood that the subject matter defined in this application is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing this application.
[0249] Although several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of this application. Certain features described in the context of separate embodiments may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented in multiple embodiments individually or in any suitable sub-combination.
[0250] The above description is merely a preferred embodiment of the present application and an illustration of the technical principles employed. Those skilled in the art should understand that the scope of application of this application is not limited to technical solutions formed by a specific combination of the aforementioned technical features. It also encompasses other technical solutions formed by any combination of the aforementioned technical features or their equivalents, without departing from the aforementioned application concept. For example, a technical solution formed by replacing the aforementioned features with (but not limited to) technical features with similar functions claimed in this application.
Claims
1. A method for determining an answer to a question, characterized in that: include: Receive user query information; Extracting knowledge fragments related to the query information from the knowledge base; For each knowledge fragment, extract the first-order logic rules corresponding to the knowledge fragment from the formal logic rule library; Constructing a constraint graph according to all the first-order logic rules; The user's query information is input into the language model, and a set of candidate answers is output; wherein, the language model uses the constraint graph to perform real-time constraints during the decoding process to generate candidate answers that meet the constraint graph.
2. The method for determining the answer to a question according to claim 1, wherein: The method for constructing the formal logic rule base includes: Generate multiple entity relationships based on the knowledge graph; For each of the entity relationships, convert the entity relationship into a first-order logic rule; Combining the frequency of entity relationships and text co-occurrence statistics, assigning a confidence weight to each of the first-order logic rules and establishing a rule index; A formalized logic rule library is established based on all the first-order logic rules and their corresponding confidence weights and indexes.
3. The method for determining the answer to a question according to claim 1, wherein: The constraint graph constructed according to all the first-order logic rules includes: For each first-order logic rule, the syntax parser is used to parse the first-order logic rule into an abstract syntax tree; Performing conjunction normal form conversion and variable normalization on the abstract syntax tree to obtain a standardized logical expression structure; Creating a predicate node for each predicate in the normalized logical expression structure, creating an entity node for each entity, and adding a type constraint tag to the variable; Determining edges between nodes according to the logical relationships in the first-order logic rules; Generate edge weights using the frequency of entity relationships and text co-occurrence statistics; Generate a constraint graph based on all nodes, edges between nodes, and edge weights.
4. The method for determining the answer to a question according to claim 1, wherein: The language model uses the constraint graph to perform real-time constraints during the decoding process to generate candidate answers that satisfy the constraint graph, including: During the decoding process, the language model calculates the probability distribution of candidate tokens based on the currently generated partial sequence; For each candidate token, use the constraint graph to perform constraint satisfaction check on the candidate token to obtain a constraint satisfaction check result; The candidate sequence paths that meet all the constraints are retained until the termination condition is reached; wherein, the candidate sequence path is the complete sequence formed by adding a valid candidate token to the current generated sequence.
5. The method for determining the answer to a question according to claim 4, wherein: For each token, the constraint satisfaction check is performed on the token using the constraint graph to obtain the constraint satisfaction check result, including: Add the candidate token to the current sequence to form an extended sequence; Converting the natural language content of the extended sequence into a structured triple form to obtain triple data of the extended sequence; It is detected whether the triple data of the extended sequence has a logical conflict with the active path in the constraint graph, and a constraint satisfaction check result is obtained.
6. The method for determining the answer to a question according to claim 1, wherein: After inputting the user's query information into the language model and outputting a set of candidate answers, the method further includes: For each candidate answer in the candidate answer list, calculate the comprehensive probability score of the candidate answer; The candidate answer with the highest comprehensive probability score is selected as the target answer.
7. The method for determining the answer to a question according to claim 6, wherein: Calculating the comprehensive probability score of each candidate answer in the candidate answer list includes: For each candidate answer in the candidate answer list, perform proposition decomposition on the candidate answer to obtain a proposition analysis result; For each independent proposition in the proposition analysis result, convert the independent proposition into a structured triple form to obtain triple data of the independent proposition; Calculating the rationality probability of the independent proposition based on the triple data of the independent proposition; Based on the rationality probabilities of all the independent propositions, the comprehensive probability scores of the candidate answers are calculated.
8. A device for determining an answer to a question, characterized in that: include: A receiving unit, configured to receive query information from a user; A query unit, configured to extract knowledge fragments related to the query information from the knowledge base; An extraction unit, configured to extract, for each knowledge fragment, a first-order logic rule corresponding to the knowledge fragment from a formal logic rule base; A constraint graph construction unit, configured to construct a constraint graph according to all the first-order logic rules; The analysis unit is used to input the user's query information into the language model and output a set of candidate answers; wherein, the language model uses the constraint graph to perform real-time constraints during the decoding process to generate candidate answers that meet the constraint graph.
9. An electronic device, characterized in that: include: one or more processors; a storage device having one or more programs stored thereon; When the one or more programs are executed by the one or more processors, the one or more processors are enabled to implement the method for determining an answer to a question as claimed in any one of claims 1 to 7.
10. A computer storage medium, characterized in that A computer program is stored thereon, wherein when the computer program is executed by a processor, the method for determining the answer to a question as claimed in any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Question answering method and device based on knowledge graph, storage medium and question answering robot
CN114357137A
Intelligent processing method and platform for recruitment information based on cloud service
CN119228335A
Intelligent questioning and answering method, system and equipment for electric power safety knowledge and storage medium
CN119311818A
Vertical domain document question and answer method and system based on knowledge graph enhanced large model
CN119646026A
Incremental analysis-based limited autoregressive decoding method and system, and medium
CN119669268A