Data constraint method, device, electronic equipment and computer storage medium

By acquiring the question to be answered and the current context, the target path generated by the large language model is dynamically selected, and target constraints are generated, which solves the problem of inconsistent results generated by the large language model and improves the accuracy and reliability of the output content.

CN123180366APending Publication Date: 2026-11-27AISINO CORPORATION
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611442050.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-16
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

Large language models may produce results that are inconsistent with the facts, lack evidence, or are inconsistent with the facts, creating illusions. Existing retrieval-enhanced generation methods cannot dynamically adjust constraints based on specific problems and the real-time generation context, resulting in a low degree of matching between constraints and generation requirements.

Method used

By acquiring the question to be answered and the current context generated by the large language model, the target path is determined from multiple preset paths, and target constraints are generated, including rigid paths, flexible paths and logical paths. The constraint method is dynamically adjusted to improve the matching degree between constraints and generation requirements, and realize the linkage between constraint mechanism and generation process.

Benefits of technology

It effectively suppresses the illusion of large language models, improves the accuracy and reliability of output content, and ensures the self-consistency and consistency of generated content in terms of facts, semantics, and logic.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123180366A_ABST
    Figure CN123180366A_ABST
Patent Text Reader

Abstract

The present disclosure provides a data constraint method, device, electronic equipment and computer storage medium, belonging to the technical field of artificial intelligence. The data constraint method comprises: obtaining a question to be answered and a current context generated by a large language model according to the question to be answered; determining a target path from a plurality of preset paths according to the question to be answered and the current context, wherein different preset paths are used to generate different properties of constraints; and generating a target constraint according to the target path, wherein the target constraint is used to constrain the output content generated by the large language model based on the question to be answered and the current context. The scheme provided by the present disclosure can dynamically adjust the constraint mode according to the specific problem attribute and the real-time generation state, improve the matching degree of the constraint and the generation demand, thereby helping to improve the accuracy and reliability of the output content of the large language model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of artificial intelligence technology, and in particular to a data constraint method, apparatus, electronic device, and computer storage medium. Background Technology

[0002] With the development of artificial intelligence and natural language processing technologies, large language models (LLMs) are widely used in scenarios such as intelligent question answering, text generation, and content analysis. However, due to factors such as model capabilities, training data, and the reasoning process, the results generated by large language models may exhibit phenomena such as inconsistencies with reality, lack of evidence, or inconsistencies, thus affecting the accuracy and reliability of the output.

[0003] Currently, to reduce the illusion of large language models, a retrieval-enhanced generation method is usually adopted. This method involves first retrieving and matching relevant reference knowledge based on the user's input question, and then injecting the reference knowledge into the large language model to constrain the content generation process in a knowledge-guided manner.

[0004] However, in retrieval-enhanced generation methods, the retrieval and generation stages are independent of each other, making it impossible to dynamically adjust the constraint methods based on the specific problem and the real-time generation context. This results in a low degree of matching between the constraints and the current generation requirements, and a limited effect on suppressing the illusion of large language models. Summary of the Invention

[0005] In view of the above, embodiments of this disclosure provide a data constraint method, apparatus, electronic device, and computer storage medium to at least partially solve the above problems.

[0006] According to a first aspect of the present disclosure, a data constraint method is provided, comprising: obtaining an unanswered question and a current context generated by a large language model based on the unanswered question; determining a target path from a plurality of preset paths based on the unanswered question and the current context, wherein different preset paths are used to generate constraints of different natures; generating a target constraint based on the target path, wherein the target constraint is used to constrain the output content generated by the large language model based on the unanswered question and the current context.

[0007] According to a second aspect of the present disclosure, a data constraint apparatus is provided, comprising: an acquisition unit, configured to acquire an unanswered question and a current context generated by a large language model based on the unanswered question; a determination unit, configured to determine a target path from a plurality of preset paths based on the unanswered question and the current context, wherein different preset paths are used to generate constraints of different natures; and a generation unit, configured to generate a target constraint based on the target path, wherein the target constraint is used to constrain the output content generated by the large language model based on the unanswered question and the current context.

[0008] According to a third aspect of the present disclosure, an electronic device is provided, including: a processor, a memory, a communication interface, and a communication bus, wherein the processor, the memory, and the communication interface communicate with each other through the communication bus; the memory is used to store at least one executable instruction, which causes the processor to execute the data constraint method of the first aspect.

[0009] According to a fourth aspect of the present disclosure, a computer storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the data constraint method of the first aspect.

[0010] According to the data constraint method provided in this disclosure, by obtaining the question to be answered and the current context generated by the large language model based on the question to be answered, a target path is determined from multiple preset paths for generating constraints of different natures based on the question to be answered and the current context. Based on the target path, target constraints are generated to constrain the content generated by the large language model based on the question to be answered and the current context. The constraint method can be dynamically adjusted according to the specific question attributes and the real-time generation status, improving the matching degree between constraints and generation requirements. The constraint mechanism and the large language model generation process are linked, so that the generation constraints of the large language model can iterate synchronously with the generation process, thereby helping to suppress the illusion of the large language model and improve the accuracy and reliability of the output content of the large language model. Attached Figure Description

[0011] To more clearly illustrate the technical solutions in the embodiments of this disclosure or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings.

[0012] Figure 1 This is a flowchart of a data constraint method provided in an embodiment of this disclosure; Figure 2 This is a schematic diagram of a data constraint device provided in an embodiment of this disclosure; Figure 3This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. Detailed Implementation

[0013] To enable those skilled in the art to better understand the technical solutions in the embodiments of this disclosure, the technical solutions in the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this disclosure, and not all embodiments. Based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art should fall within the protection scope of this disclosure.

[0014] The terminology used in this disclosure is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The singular forms “a,” “the,” and “the” as used in this disclosure and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.

[0015] It should be understood that although the terms first, second, third, etc., may be used in this disclosure to describe various information, such information should not be limited to these terms. These terms are used only to distinguish information of the same type from one another. For example, without departing from the scope of this disclosure, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."

[0016] As mentioned earlier, with the development of artificial intelligence and natural language processing technologies, large language models are widely used in scenarios such as intelligent question answering, text generation, and content analysis. Influenced by factors such as model capabilities, training data, and the reasoning process, the results generated by large language models may exhibit illusions such as inconsistencies with facts, lack of evidence, or inconsistencies, thus affecting the accuracy and reliability of the output. Currently, to reduce large language model illusions, retrieval-enhanced generation methods are commonly used. This involves first retrieving and matching corresponding reference knowledge based on the user's input question, and then injecting the reference knowledge into the large language model to constrain the content generation process in a knowledge-guided manner. However, in retrieval-enhanced generation methods, the retrieval and generation stages are independent, making it impossible to dynamically adjust the constraints based on the specific question and the real-time generation context. This results in a low degree of matching between the constraints and the current generation requirements, limiting the effectiveness of suppressing large language model illusions.

[0017] This disclosure provides a data constraint method. It obtains the question to be answered and the current context generated by a large language model based on the question. Based on the question and the current context, a target path is determined from multiple preset paths used to generate constraints of different natures. Based on the target path, target constraints are generated to constrain the content generated by the large language model based on the question and the current context. This method can dynamically adjust the constraint method according to specific question attributes and real-time generation status, improving the matching degree between constraints and generation requirements. It achieves linkage between the constraint mechanism and the large language model generation process, allowing the generation constraints of the large language model to iterate synchronously with the generation process. This helps to suppress large language model illusions and improve the accuracy and reliability of the large language model's output content.

[0018] The data constraint method provided in this disclosure is illustrated below through examples.

[0019] Figure 1 This is a flowchart of a data constraint method provided in an embodiment of this disclosure. Figure 1 As shown, the data constraint method includes the following steps 101 to 103: Step 101: Obtain the question to be answered and the current context generated by the large language model based on the question to be answered.

[0020] The question to be answered is the original query request input by the user into the large language model, containing interactive information such as the user's question and query goal. The current context refers to the text information related to the current generation scenario, such as intermediate answer fragments and historical interaction records of this dialogue, that the large language model has generated in the process of responding to the question to be answered.

[0021] Understandably, in the initial stage of large language model generation, if the large language model has not yet output any intermediate response content, the current context may only contain historical interaction records. If there are no historical interaction records, the current context is empty, and the judgment is based solely on the question to be answered. As the generation process progresses, the generated intermediate response content, dialogue interaction information, etc., gradually accumulate, forming a real-time updated current context.

[0022] It should be noted that the question to be answered can be obtained once in the initial stage. The acquisition or update of the current context can be performed cyclically along with the generation process at the granularity of token level or sentence level. That is, every time content of the corresponding granularity is generated, the updated current context is obtained synchronously, which together with the question to be answered constitutes a complete judgment basis, ensuring that the constraint decision can keep up with the latest generation progress, rather than relying solely on the static initial input.

[0023] Step 102: Based on the question to be answered and the current context, determine the target path from multiple preset paths, where different preset paths are used to generate constraints of different properties.

[0024] Based on the obtained question to be answered and the current context, the path with the highest adaptability to the current scenario is determined from multiple preset paths as the target path. Different preset paths correspond to different types of constraint generation logic, generating constraints of varying natures to suit different types of query needs and content scenarios. Preset paths can include multiple constraint dimensions to meet the constraint requirements at different levels of content generation.

[0025] Step 103: Generate target constraints based on the target path. The target constraints are used to constrain the output content generated by the large language model based on the question to be answered and the current context.

[0026] After determining the target path, corresponding target constraints are generated based on the constraint generation rules for that path. These constraints are used to regulate the output generated by the large language model based on the question to be answered and the current context. For example, target constraints can be applied to the generation process of the large language model through methods such as prompt word injection, decoding control, post-generation verification, or rewriting, ensuring that the final output of the large language model meets the requirements and expectations. When iterating through the current context at the token or sentence level, the target path can be synchronously redefined and the target constraints updated, allowing the constraints to iterate along with the generation process.

[0027] In this embodiment, by acquiring the question to be answered and the current context generated by the large language model based on the question to be answered, a target path is determined from multiple preset paths for generating constraints of different natures based on the question to be answered and the current context. Based on the target path, target constraints are generated to constrain the content generated by the large language model based on the question to be answered and the current context. The constraint method can be dynamically adjusted according to the specific question attributes and the real-time generation status, improving the matching degree between constraints and generation requirements. This realizes the linkage between the constraint mechanism and the large language model generation process, allowing the generation constraints of the large language model to iterate synchronously with the generation process. This helps to suppress the illusion of the large language model and improve the accuracy and reliability of the output content of the large language model.

[0028] In one possible implementation, when determining the target path from multiple preset paths based on the question to be answered and the current context, the selection probability of each preset path can be determined according to the question to be answered and the current context. The preset paths include rigid paths, flexible paths, and logical paths. Rigid paths are used to generate factual constraints, flexible paths are used to generate semantic constraints, and logical paths are used to generate logical reasoning constraints. Based on the selection probability of each preset path, the preset path with the highest selection probability is determined as the target path.

[0029] Using the acquired question and current context as input, the suitability of each preset path is evaluated, and the evaluation result is quantified as a selection probability. The selection probability reflects the degree of matching between the corresponding preset path and the current query requirement and generation scenario. The higher the probability, the more suitable the constraint generation logic corresponding to the path is for constraining the content generation process of the current large language model. By calculating the selection probability for each of the three types of paths, the path selection process is transformed into a quantifiable and comparable evaluation process, avoiding the subjectivity and limitations caused by relying on a single rule or manual judgment, and enabling the path selection results to more accurately reflect the actual constraint requirements of the current scenario.

[0030] The preset paths specifically include three categories: rigid paths, flexible paths, and logical paths. These three types of paths correspond to different types of constraint generation directions. Rigid paths are used to generate factual constraints, focusing on constraining the objective facts and definitive information involved in the content to ensure the accuracy and rigor of the output content at the factual level. Flexible paths are used to generate semantic constraints, focusing on constraining the semantic expression and meaning of the content to ensure that the output content is consistent and coordinated with the query intent and context at the semantic level. Logical paths are used to generate logical reasoning constraints, focusing on constraining the reasoning process, causal relationships, and argumentation chains in the content to ensure the logical consistency and rationality of the output content.

[0031] After obtaining the selection probability of each preset path, the path with the highest probability is selected as the target path by comparing the probabilities of each path. This means selecting the path whose constraint properties best match the current question and context, allowing the constraints generated by this path to more effectively influence the content generation process of the large language model. This approach ensures the determinism and reproducibility of the path selection results while enabling adaptive adaptation to different scenarios through dynamic changes in probability values. When the query requirements or context change, the selection probabilities of each path are adjusted accordingly, and the final selected target path also changes dynamically, thus achieving dynamic matching of constraint-generated paths.

[0032] In one example, a gating router dynamically determines the optimal preset path for the current generation step based on the real-time generation state during the step-by-step generation of the large language model, and outputs a normalized path selection probability distribution, making the path selection process computable and adaptively adjustable.

[0033] The gating router is a decision-making module integrated into the large language model generation process. Its input includes the question information to be answered for the current generation step and the currently generated context content. Its output consists of the selection probabilities for three preset paths: rigid path, flexible path, and logical path. The sum of the selection probabilities of all paths is 1, forming a complete path selection probability distribution. By transforming path selection into a probability distribution output based on the real-time generation state, the gating router enables path decisions to be dynamically updated as the generation process progresses, rather than making a single global judgment at the beginning of generation. This allows it to adapt to the differentiated constraints at different stages of the generation process.

[0034] In one example, the formal definition of a gated router is as follows: G(u_t,c_t)=softmax(W_g·[E(u_t)⊕h_t]+b_g) Where t represents the current generation step; u_t represents the question to be answered corresponding to the current generation step; c_t represents the current context; E(·) represents the encoding operation, used to uniformly map the question to be answered into a fixed-dimensional question encoding vector; E(u_t) represents the question encoding vector; h_t represents the hidden state of the large language model at the t-th generation step; ⊕ represents the vector concatenation operation; W_g represents the learnable weight matrix of the gated router; b_g represents the learnable bias vector of the gated router; softmax represents the normalized exponential function, used to convert the original scores of the three paths into probability values ​​that sum to 1, and finally output the probability distribution.

[0035] E(·) can be implemented through a text encoder, a linear projection layer, or the encoding module of the large language model itself. When u_t is given in vector representation, E(·) can be implemented as an identity mapping or dimension-adaptive projection, in which case the question encoding vector is the vector representation itself. h_t is calculated by the large language model based on the question to be answered and the current context c_t, and naturally carries contextual information. It is equivalent to inputting the information of c_t into the gated router in the form of a hidden state. h_t can be the hidden vector at the last generation position of the last layer of the large language model, or it can be the hidden representation of a specified layer or the hidden representation after pooling. W_g and b_g can be learned through the training process and can be jointly trained with the large language model or trained separately.

[0036] The decision-making process of the gated router is based on feature fusion and learnable parameter calculation. The specific execution logic is as follows: First, the user-input question is encoded to obtain a corresponding question encoding vector, which represents the core intent and semantic features of the user's query. Simultaneously, the hidden state vector of the large language model at the current generation step is extracted to represent the current content generation progress, semantic features of the generated content, and other real-time states. Second, the question encoding vector and the current hidden state vector are concatenated to obtain a joint feature vector that simultaneously contains the query intent and generation state, enabling path decision-making to consider both the user's original needs and the current generation progress. Finally, the joint feature vector is linearly transformed using preset learnable weight parameters and learnable bias parameters, and after normalization, the selection probabilities (P_rigid, P_elastic, P_logic) for each of the three preset paths are output. Through training and optimization of the learnable parameters, the gated router can continuously improve the matching degree of path selection based on business scenario data, making the decision results more aligned with the constraints of actual business requirements.

[0037] The gated router ultimately outputs the selection probabilities of three preset paths: the rigid path selection probability P_rigid, the elastic path selection probability P_elastic, and the logical path selection probability P_logic. Due to the normalization property of softmax, these three probabilities satisfy P_rigid + P_elastic + P_logic = 1, collectively forming the path selection probability distribution for the current generation step. Based on this probability distribution, the preset path suitable for the current step can be selected, completing the single-step routing decision.

[0038] In this embodiment, by evaluating the adaptability of rigid paths, flexible paths, and logical paths based on the question to be answered and the current context, and quantifying them into selection probabilities, the path with the highest selection probability is selected as the target path. This transforms path selection into a quantifiable and comparable process. Based on different query needs and generation scenarios, it can determine the constraint generation path with the highest adaptability under the current probability distribution among three different types of constraint directions: factual constraints, semantic constraints, and logical reasoning constraints. This improves the adaptability and reproducibility of constraint generation path selection, thereby enhancing the adaptability of constraints generated by the large language model and the quality of content generation.

[0039] In one possible implementation, before obtaining the question to be answered and the current context generated by the large language model based on the question to be answered, a policy data set can be obtained. Based on the policy data set, the policy text, policy text association data, and inter-policy relationships can be generated. The policy text is used to generate factual constraints, the policy text association data is used to generate semantic constraints, and the inter-policy relationships are used to generate logical reasoning constraints.

[0040] The process involves collecting, aggregating, and organizing policy data sets. These sets can include policy-related materials at different levels of effectiveness, across different business areas, and during different effective periods. This includes, but is not limited to, various formal policy texts, industry standards and guidelines, and officially released rules and documents relevant to the target application scenarios. Target application scenarios include, but are not limited to, taxation, finance, medical insurance, and customs. By aggregating these basic policy data sources, the process provides policy information for the subsequent generation of various constraints.

[0041] The policy data set that has been collected is analyzed, extracted and linked in multiple dimensions. According to the rigidity of knowledge representation, it is decomposed into three different levels of data output: policy text, policy text related data and inter-policy relationships, which correspond to the generation needs of different types of constraints.

[0042] The rigid layer of knowledge representation corresponds to the original policy text. This is the standardized text content formed after standardizing, cleaning, formatting, and identifying core clauses of the original policy text in the policy dataset. It retains the original wording, clear definitions, and applicable boundaries of the policy clauses, specifically including precise information such as legal provision number, clause number, effective date, repeal date, and policy document number. This layer of data requires exact matching and does not allow semantic approximation or fuzzy reasoning. It is used to generate factual constraints and provides the original text reference for content verification at the factual level. In one example, each knowledge node in the rigid layer is represented as N in structured tuple form. rigid =(id,text,valid_from,valid_to,document_id,article_no), which includes fields such as node identifier, original text, effective start time, effective end time, document identifier, and clause number, so that each piece of original text information can be located and traced.

[0043] The policy text-related data corresponds to the elastic layer knowledge representation, which is extended information extracted after semantic extension and correlation analysis based on the policy text. This includes policy interpretations, official explanations, typical case studies, and explanations of core concepts—knowledge content that can be used for semantic approximate matching. This layer of data allows for similarity calculation using vector matching for retrieval and matching, used to subsequently generate semantic constraints and provide a reference dimension for semantic content matching. In one example, a vector database and vector retrieval model are used to vectorize and store elastic layer knowledge and calculate similarity to support semantic retrieval and approximate matching.

[0044] The inter-policy relationships correspond to a logical layer knowledge representation, which is a logical relationship network formed after sorting out the inherent connections between different policy texts and clauses. This includes citation relationships, hierarchical subordinate relationships, conditional dependencies, and supplementary explanation relationships between clauses. This layer of data is used to generate logical reasoning constraints, providing association rules to support the derivation of content at the logical level. In one example, the inter-policy relationships are represented in the form of structured rules as Rule: IF condition_set THEN consequence [WITH EXCEPTION exception_set], where the condition set, exception set, and conclusion set are all mapped to corresponding nodes in the rigid and flexible layers.

[0045] It should be noted that existing large language models encode factual knowledge (such as the original text of legal provisions) and semantic knowledge (such as explanations) in the same parameter space. During generation, they prioritize the fluency of the contextual language, which risks a decrease in factual accuracy and can lead to factual illusions at the cognitive level. In contrast, this disclosed embodiment decomposes the original policy data set into three different dimensions: a rigid layer, a flexible layer, and a logical layer. It constructs a layered and decoupled policy knowledge graph architecture, ensuring that the generation of constraints of different natures can correspond to suitable data sources. This alleviates the problem of insufficient adaptation of a single data format to the needs of generating diverse constraints, and also mitigates the potential decrease in factual accuracy caused by the mixed encoding of factual and semantic knowledge at the knowledge representation level.

[0046] In this embodiment, by pre-collecting a policy data set and performing three-layer parsing on the policy data set based on knowledge representation and hierarchical decoupling, three different types of basic data are generated: the original policy text, related data of the original policy text, and relationships between policies. This provides corresponding data source support for the generation of constraints for different paths, thereby enabling the standardization, structuring, and decoupling of policy basis. This not only helps to improve the authority of the constraint basis, but also, through multi-dimensional data layering, adapts to the constraint generation needs of different natures. It can alleviate the problem of decreased factual accuracy caused by the mixed encoding of factual knowledge and semantic knowledge, and provide support for improving the reliability and scenario adaptability of constraint generation basis.

[0047] In one possible implementation, when generating target constraints based on the target path, if the target path is a rigid path, then precise matching is performed based on the original policy text to generate factual constraints. If the target path is a flexible path, then semantic matching is performed based on the policy text and associated data to generate semantic constraints. If the target path is a logical path, then forward reasoning is performed based on the relationships between policies to generate logical reasoning constraints.

[0048] After the target path is determined, the processing logic corresponding to the target path is invoked to extract constraint basis from the policy knowledge of the corresponding level, so as to generate a target constraint applied to the content generation process of the large language model.

[0049] If the target path is a rigid path, that is, the selection probability of the rigid path is the maximum among all preset paths, an exact matching is performed in the rigid layer through a subgraph matching algorithm, and the current question to be answered and the current context are used as retrieval basis to locate and match in the rigid layer data storing the original text of policies and regulations, so as to return the corresponding original content of legal provisions, thereby generating a factual constraint. The rigid path adopts an exact matching rule, which does not allow semantic approximate replacement or fuzzy derivation, so that the generated factual constraint is consistent with the expression of the original policy text.

[0050] The formal expression of the factual constraint acting on the generation process of the large language model is as follows: when P_rigid is maximum: P(y_t|y_<t,x)=P_LLM(y_t|y_<t,x,M_rigid), where P_rigid is the selection probability of the rigid path, x is the question to be answered input by the user, y_<t is the historical output content of the large language model before the current time, M_rigid is the knowledge constraint condition corresponding to the rigid path, and P_LLM is the generation probability distribution of the large language model itself. Through the factual constraint, the generation range of the large language model involving legal provision citation can be limited within the expression range of the original policy text, reducing the risk of tampering with the original legal provisions.

[0051] If the target path is an elastic path, that is, the selection probability of the elastic path is the maximum among all preset paths, a similarity matching is performed in the elastic layer through vector semantic retrieval, the question to be answered and the current context are converted into semantic vectors, and the semantic similarity is calculated in the elastic layer vector library storing extended content such as policy interpretation, official definitions, and typical cases, so as to recall the relevant policy interpretation content with the highest matching degree, thereby generating a semantic constraint. The elastic path supports semantic-level approximate matching, which can cover extended interpretations and applicable scenario descriptions beyond the original policy text, and adapt to the generation requirements of policy interpretation content.

[0052] The formal expression of the semantic constraint acting on the generation process of the large language model is as follows: when P_elastic is maximum: P(y_t|y_<t,x)=P_LLM(y_t|y_<t,x,M_elastic), where P_elastic is the selection probability of the elastic path, and M_elastic is the knowledge constraint condition corresponding to the elastic path. Through the semantic constraint, the generation content of the large language model can be guided to fit the official definitions and actual applicable scenarios of the policy.

[0053] If the target path is a logical path, that is, when the selection probability of the logical path is the maximum among all preset paths, forward reasoning is performed in the logic layer through a rule engine. Taking the current question to be answered and the current context as input conditions, and based on the conditional dependencies between policy clauses and structured rules stored in the logic layer, the corresponding condition set, exception set, and conclusion set are matched. After rule derivation, the corresponding reasoning conclusion is output, thereby generating a logical reasoning constraint. The logical path completes derivation based on the inherent logical association between policies, and can be used to handle scenarios involving cross-application of multiple policies.

[0054] The formal expression of the logical reasoning constraint acting on the generation process of the large language model is: when P_logic is the maximum: P(y_t|y_<t,x)=P_LLM(y_t|y_<t,x,M_logic), where P_logic is the selection probability of the logical path, and M_logic is the knowledge constraint condition corresponding to the logical path. The logical reasoning constraint can guide the large language model to perform derivation in accordance with the logical association of policy rules, avoiding logical contradictions or incorrect rule application.

[0055] In an example, during the generation process of the large language model, the gating router can perform dynamic path switching at the Token level or the sentence level. When the generated content involves the citation of the original text of legal provisions, switch to the rigid path to impose factual constraints. When the generated content involves policy interpretation and scenario description, switch to the flexible path to impose semantic constraints. When the generated content involves cross-derivation of multiple clauses and multiple policies, switch to the logical path to impose logical reasoning constraints.

[0056] In the embodiment of the present disclosure, by configuring three differentiated constraint generation mechanisms: subgraph exact matching for the rigid path, vector semantic retrieval for the flexible path, and rule engine forward reasoning for the logical path, factual constraints can be generated based on the original policy text, semantic constraints can be generated based on data associated with the original policy text, and logical reasoning constraints can be generated based on the relationships between policies. Further, in generation scenarios involving legal provision citations, the generated content of the large language model can be limited to the expression scope of the original policy text; in generation scenarios involving policy interpretation and scenario description, the generated content can be kept semantically consistent with official interpretations and applicable scenarios; in generation scenarios involving cross-derivation of multiple clauses and multiple policies, the generated content can be made to follow the citation, dependency, and exception relationships between policy clauses. The three types of constraint generation mechanisms complement each other and work synergistically, which can provide hierarchical and scenario-based constraints for the large language model, and help improve the factual consistency, semantic adaptability, and logical self-consistency of the large language model in policy-related content generation.

[0057] In one possible implementation, the data constraint method can also obtain the output content generated by the large language model based on the question to be answered and the current context. Counterfactual inference is then performed on the output content to generate a consistency score. If the consistency score is lower than a preset threshold, the output content is corrected.

[0058] After the large language model completes reasoning and generates corresponding content for the question to be answered, the output content of the large language model is collected. For scenarios requiring logical deduction, such as policy reasoning, rule determination, and condition matching, the output content usually includes the reasoning process from the premises to the corresponding conclusion. The output content is logically verified through counterfactual reasoning to generate a consistency score, which can quantitatively reflect the causal consistency of the reasoning logic in the output content.

[0059] If the consistency score is lower than a preset threshold, the output content is corrected. The preset threshold is a pre-set scoring threshold used to determine the validity of the logic. When the generated consistency score is lower than this threshold, it indicates that the reasoning logic of the output content has a causal consistency defect, and / or the derivation process may contain unverified hidden assumptions. In this case, the reasoning chain, implicit assumptions, and / or final conclusion of the output content are corrected, and corrected output content is generated to remedy logical flaws and improve the reliability of the derivation conclusion.

[0060] In applications involving cross-policy reasoning, the reasoning chains generated by large language models often implicitly contain numerous unverified presuppositions, making it difficult to effectively guarantee the causal consistency of the reasoning logic. For example, when a large language model derives the conclusion that "a company meets conditions A and B, therefore it can enjoy preferential treatment X," its reasoning process does not automatically perform counterfactual verification; that is, it does not verify whether "if condition A is not met but condition B is met, does the aforementioned conclusion still hold?" This lack of causal consistency verification capability is one of the reasons why large language models generate reasoning illusions and have insufficient credibility in their output conclusions. This embodiment introduces a counterfactual reasoning mechanism to conduct full-link consistency verification on the output reasoning chain of the large language model, generates a quantitative consistency score, and triggers targeted logical correction when the score falls below a preset threshold, forming a logical closed loop of "generation-verification-correction," which can alleviate the reasoning illusion phenomenon in cross-policy reasoning scenarios.

[0061] By applying counterfactual reasoning methods from the field of causal inference to the detection of reasoning illusions in large language models, causal consistency verification can be achieved during the reasoning process. Compared to existing post-verification methods (such as manual review and fact-checking application programming interfaces), this embodiment has real-time detection capabilities. It does not require waiting for a complete answer to be generated before performing the verification operation. It can perform verification synchronously with the reasoning generation process of the large language model, promptly identifying logical flaws in reasoning. Furthermore, it has a proactive discovery mechanism, completing inference verification by autonomously constructing counterfactual scenarios. It does not rely on the completeness of external knowledge bases, reducing dependence on external data resources. At the same time, this embodiment has strong interpretability. Counterfactual assumptions can clearly define the boundary conditions for the validity of reasoning conclusions, clearly presenting the applicable scope of reasoning logic, and improving users' awareness and understanding of the system's output boundaries.

[0062] In this embodiment of the disclosure, by performing counterfactual reasoning verification on the output content of the large language model, generating a consistency score, and triggering correction when the score is insufficient, it is possible to identify the implicit logical assumption bias in the reasoning process of the large language model, reduce the probability of reasoning illusion, improve the accuracy and credibility of the output content in rigorous logical reasoning scenarios, and thus optimize the reasoning quality of the large language model.

[0063] In one possible implementation, when performing counterfactual reasoning on the output content to generate a consistency score, a reasoning chain corresponding to the output content can be generated. This reasoning chain includes a condition set, reasoning rules, and an original reasoning conclusion. The condition set includes at least one condition. Counterfactual conditions are constructed for the conditions included in the reasoning chain. Based on the reasoning rules and a pre-defined causal graph, forward reasoning is performed on the counterfactual conditions to generate a counterfactual conclusion corresponding to the counterfactual conditions. A consistency score is generated based on the original reasoning conclusion and the counterfactual conclusion.

[0064] The output content is structured and parsed to extract the reasoning chain. The reasoning chain includes a condition set, reasoning rules, and the original reasoning conclusion. The condition set contains at least one condition, representing the premise facts upon which the reasoning is based. The reasoning rules represent the logical connection between the conditions and the conclusion. The original reasoning conclusion is the result derived by the large language model based on the aforementioned conditions and reasoning rules.

[0065] Construct counterfactual conditions for one or more conditions included in the inference chain. For a condition c_i contained in the condition set in the inference chain, construct a counterfactual condition ¬c_i that contradicts its factual state. The counterfactual condition satisfies the following expression: CF(c_i)={¬c_i(if binary)|c_i'(if continuous,|c_i'-c_i|>δ)} Here, ¬c_i represents the negation of the original condition under binary conditions, c_i' represents the alternative value under continuous conditions, and δ is a preset deviation boundary threshold used to ensure that the counterfactual value deviates significantly from the original condition. By constructing counterfactual conditions, the hypothetical scenario when the premise changes is simulated, providing a comparative basis for verifying the causal consistency of the original inference conclusion.

[0066] Using the constructed counterfactual conditions as new input, combined with the reasoning rules extracted from the reasoning chain and the pre-constructed causal graph, forward deduction is performed according to the causal direction to obtain the corresponding counterfactual conclusion when the counterfactual conditions are true.

[0067] A pre-constructed causal graph is generated. This graph can include conditions and corresponding conclusions from the original policy text, as well as derived nodes generated based on rules and corresponding conclusions under different combinations of conditions. In one example, the pre-constructed causal graph uses decision conditions as nodes and causal directions as directed edges. The nodes in the pre-constructed causal graph are divided into three categories: Condition Nodes, which represent specific preconditions in the policy or reasoning rules, such as "annual taxable income not exceeding 3 million yuan"; Conclusion Nodes, which represent the output conclusions or policy effects corresponding to the reasoning, such as "applicable tax rate of 20% for micro and small enterprises"; and Mediation Nodes, which represent intermediate quantities in the reasoning process between conditions. The causal edges in the causal graph are defined as follows: E_causal=(c_i—[rule_id]→c_j,verification_condition) Where c_i and c_j represent the starting node and the target node, respectively, [rule_id] represents the inference rule identifier of the corresponding intermediary node, and verification_condition represents the verification condition required for the causal edge to be valid.

[0068] The counterfactual conditions are substituted into the pre-defined causal graph for forward inference, yielding a counterfactual conclusion Con_cf. Con_cf is then compared with the original conclusion Con_orig. If they are consistent or only slightly different, the original conclusion remains stable under the counterfactual conditions, indicating strong causal consistency in the original inference. If they are inconsistent or significantly different, the original conclusion is sensitive to the condition, which may be related to the validity of the original conclusion or may indicate an unverified implicit hypothesis in the original inference. A consistency score S_causal is generated based on the degree of difference between the two conditions, calculated using the following formula: S_causal=1 / (1+|Con_cf-Con_orig|·I(Con_cf≠Con_orig)) Where I(·) is an indicator function, taking a value of 1 when the counterfactual conclusion is inconsistent with the original conclusion, and a value of 0 when they are consistent. The consistency score can quantitatively reflect the stability of the original reasoning conclusion when the given conditions change.

[0069] A preset scoring threshold θ is used to determine the validity of the logic. When S_causal < θ, a correction process is triggered. In one example, θ is set to 1, meaning that if the counterfactual conclusion is inconsistent with the original conclusion, the correction process is triggered.

[0070] In this embodiment of the disclosure, by extracting a structured reasoning chain from the output content of a large language model, constructing counterfactual hypotheses for the conditions, performing forward deduction by combining reasoning rules and a preset causal graph, and generating a consistency score by comparing the original conclusion with the counterfactual conclusion, the causal consistency test can be transformed into a quantifiable and traceable calculation process, thereby improving the objectivity and operability of the reasoning logic verification and providing a clear quantitative basis for subsequent judgment on whether the output content needs to be adjusted.

[0071] In one possible implementation, when the consistency score falls below a preset threshold and the output content needs to be corrected, problematic nodes in the forward inference process of the counterfactual condition can be identified. Based on a preset causal graph, a reasoning path is determined to correct the problematic nodes, thereby correcting the output content.

[0072] When the consistency score falls below a preset threshold, it indicates a causal consistency defect in the original reasoning logic. In this case, a backtracking analysis is performed on the forward reasoning process based on the counterfactual conditions to pinpoint the problem nodes that lead to deviations in the reasoning conclusions or breaks in the causal chain. Problem nodes indicate situations such as the assumption that a certain condition in the reasoning chain is false, the applicability of a certain reasoning rule is limited, or the verification condition of a certain causal edge in the causal graph not being met.

[0073] Based on locating the problem node, and relying on the structured causal relationship network provided by the pre-defined causal graph, alternative reasoning paths that can bypass or repair the problem node are determined. The selection of alternative reasoning paths satisfies the following optimal condition: Path_revised = argmax ΣS_causal(e). The path with the highest sum of edge scores among all connected paths is selected as the alternative reasoning path to correct the problem node. The alternative reasoning path must have causal connectivity in the causal graph, and the verification conditions of each causal edge must be satisfied, thus providing causal support for the corrected reasoning process. Based on the determined alternative reasoning path, the reasoning process and corresponding conclusions in the output content are adjusted.

[0074] In one example, the counterfactual consistency verification result is fed back to the gated router of the large language model, forming a "generation-verification-correction" loop. When the large language model repeatedly triggers counterfactual inconsistency judgments at a certain inference node, that node is marked as a low-confidence interval node. In subsequent inference generation processes, rigid paths are preferentially selected for low-confidence interval nodes, realizing the perception and dynamic adaptation to changes in the model's knowledge boundaries.

[0075] In this embodiment of the disclosure, by tracing back to locate the problem node in the forward reasoning process when the consistency score is lower than the threshold, and determining the corrected reasoning path for the problem node based on the preset causal graph to adjust the output content, it is possible to locate and specifically repair the reasoning defects, improve the accuracy and effectiveness of the output content correction, and make the corrected reasoning process have traceable causal basis, thereby enhancing the reliability of the output content of the large language model in the logical deduction scenario.

[0076] Figure 2 This is a schematic diagram of a data constraint device provided in an embodiment of this disclosure, such as... Figure 2 As shown, the data constraint device 200 includes: The acquisition unit 201 is used to acquire the question to be answered and the current context generated by the large language model based on the question to be answered; The determining unit 202 is used to determine the target path from multiple preset paths based on the question to be answered and the current context, wherein different preset paths are used to generate constraints of different properties; The generation unit 203 is used to generate target constraints based on the target path, wherein the target constraints are used to constrain the output content generated by the large language model based on the question to be answered and the current context.

[0077] In this embodiment of the disclosure, the acquisition unit 201 can be used to execute step 101 in the above method embodiment, the determination unit 202 can be used to execute step 102 in the above method embodiment, and the generation unit 203 can be used to execute step 103 in the above method embodiment.

[0078] In one possible implementation, the determining unit 202 can also be used to determine the selection probability of each preset path based on the question to be answered and the current context, wherein the preset paths include rigid paths, flexible paths and logical paths, the rigid paths are used to generate factual constraints, the flexible paths are used to generate semantic constraints, and the logical paths are used to generate logical reasoning constraints; based on the selection probability of each preset path, the preset path with the highest selection probability is determined as the target path.

[0079] In one possible implementation, the data constraint device 200 can also be used to obtain a policy data set before acquiring the question to be answered and the current context generated by the large language model based on the question to be answered; based on the policy data set, policy text, policy text-related data, and inter-policy relationships are generated, with the policy text used to generate factual constraints, the policy text-related data used to generate semantic constraints, and the inter-policy relationships used to generate logical reasoning constraints.

[0080] In one possible implementation, the generation unit 203 can also be used to generate factual constraints by performing precise matching based on the original policy text if the target path is a rigid path; to generate semantic constraints by performing semantic matching based on the policy text and associated data if the target path is a flexible path; and to generate logical reasoning constraints by performing forward reasoning based on the relationship between policies if the target path is a logical path.

[0081] In one possible implementation, the data constraint device 200 can also be used to obtain the output content generated by the large language model based on the question to be answered and the current context; perform counterfactual inference on the output content to generate a consistency score; and if the consistency score is lower than a preset threshold, then the output content is corrected.

[0082] In one possible implementation, the data constraint device 200 can also be used to generate an inference chain corresponding to the output content based on the output content, wherein the inference chain includes a condition set, inference rules, and an original inference conclusion, and the condition set includes at least one condition; construct counterfactual conditions for the conditions included in the inference chain; perform forward inference on the counterfactual conditions based on the inference rules and a preset causal graph to generate a counterfactual conclusion corresponding to the counterfactual conditions; and generate a consistency score based on the original inference conclusion and the counterfactual conclusion.

[0083] In one possible implementation, the data constraint device 200 can also be used to identify problem nodes in the forward inference process of counterfactual conditions if the consistency score is lower than a preset threshold; and to determine the inference path to correct the problem nodes according to the preset causal graph, so as to correct the output content.

[0084] Reference Figure 3 This diagram illustrates the structure of an electronic device according to an embodiment of the present disclosure. The specific embodiments of the present disclosure do not limit the specific implementation of the electronic device.

[0085] like Figure 3 As shown, the electronic device may include: a processor 302, a communications interface 304, a memory 306, and a communications bus 308.

[0086] in: The processor 302, communication interface 304, and memory 306 communicate with each other via communication bus 308.

[0087] Communication interface 304 is used to communicate with other electronic devices or servers.

[0088] The processor 302 is used to execute program 310, specifically to perform the relevant steps in the above-described data constraint method embodiment.

[0089] Specifically, program 310 may include program code that includes computer operation instructions.

[0090] Processor 302 may be a central processing unit (CPU), a graphics processing unit (GPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement embodiments of the present disclosure. The electronic device may include one or more processors of the same type, such as one or more CPUs; one or more GPUs; or it may include processors of different types, such as one or more CPUs, one or more GPUs, and one or more ASICs.

[0091] Memory 306 is used to store program 310. Memory 306 may include high-speed RAM memory, and may also include non-volatile memory, such as at least one disk storage device.

[0092] Specifically, program 310 can be used to cause processor 302 to execute the data constraint method in any of the foregoing embodiments.

[0093] The specific implementation of each step in program 310 can be found in the corresponding steps and units described in any of the aforementioned data constraint method embodiments, and will not be repeated here. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the devices and modules described above can be referred to the corresponding process descriptions in the aforementioned method embodiments, and will not be repeated here.

[0094] In this embodiment, by acquiring the question to be answered and the current context generated by the large language model based on the question to be answered, a target path is determined from multiple preset paths for generating constraints of different natures based on the question to be answered and the current context. Based on the target path, target constraints are generated to constrain the content generated by the large language model based on the question to be answered and the current context. The constraint method can be dynamically adjusted according to the specific question attributes and the real-time generation status, improving the matching degree between constraints and generation requirements. This realizes the linkage between the constraint mechanism and the large language model generation process, allowing the generation constraints of the large language model to iterate synchronously with the generation process. This helps to suppress the illusion of the large language model and improve the accuracy and reliability of the output content of the large language model.

[0095] This disclosure also provides a computer program product, including computer instructions that instruct a computing device to perform an operation corresponding to any of the methods in the above-described plurality of method embodiments.

[0096] It should be noted that, depending on the implementation needs, the various components / steps described in the embodiments of this disclosure can be broken down into more components / steps, or two or more components / steps or parts of the operation of components / steps can be combined into new components / steps to achieve the purpose of the embodiments of this disclosure.

[0097] The methods described above according to embodiments of this disclosure can be implemented in hardware, firmware, or as software or computer code that can be stored in a recording medium (such as a CD-ROM, RAM, floppy disk, hard disk, or magneto-optical disk), or as computer code originally stored on a remote recording medium or a non-transitory machine-readable medium and subsequently stored on a local recording medium, downloaded over a network. Thus, the methods described herein can be processed by software stored on a recording medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware (such as an ASIC or FPGA). It is understood that the computer, processor, microprocessor controller, or programmable hardware includes storage components (e.g., RAM, ROM, flash memory, etc.) capable of storing or receiving software or computer code, which, when accessed and executed by the computer, processor, or hardware, implements the data constraint methods described herein. Furthermore, when a general-purpose computer accesses code used to implement the data constraint methods shown herein, the execution of the code transforms the general-purpose computer into a dedicated computer for executing the data constraint methods shown herein.

[0098] Those skilled in the art will recognize that the units and method steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the embodiments disclosed herein.

[0099] It should be noted that the user-related information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to sample data used for training the model, data used for analysis, stored data, displayed data, etc.) involved in the embodiments of this disclosure are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.

[0100] The above embodiments are only used to illustrate the embodiments of this disclosure, and are not intended to limit the embodiments of this disclosure. Those skilled in the art can make various changes and modifications without departing from the spirit and scope of the embodiments of this disclosure. Therefore, all equivalent technical solutions also fall within the scope of the embodiments of this disclosure, and the patent protection scope of the embodiments of this disclosure should be defined by the claims.

Claims

1. A data constraint method, characterized in that, The method includes: Obtain the unanswered question and the current context generated by the large language model based on the unanswered question; Based on the question to be answered and the current context, a target path is determined from multiple preset paths, wherein different preset paths are used to generate constraints of different properties; Based on the target path, target constraints are generated, wherein the target constraints are used to constrain the output content generated by the large language model based on the question to be answered and the current context.

2. The method according to claim 1, characterized in that, The step of determining the target path from multiple preset paths based on the question to be answered and the current context includes: Based on the question to be answered and the current context, the selection probability of each preset path is determined, wherein the preset path includes a rigid path, a flexible path and a logical path, the rigid path is used to generate factual constraints, the flexible path is used to generate semantic constraints, and the logical path is used to generate logical reasoning constraints; Based on the selection probability of each preset path, the preset path with the highest selection probability is determined as the target path.

3. The method according to claim 2, characterized in that, Before obtaining the question to be answered and the current context generated by the large language model based on the question to be answered, the method further includes: Obtain policy data sets; Based on the policy data set, policy texts, policy text association data, and inter-policy relationships are generated. The policy texts are used to generate the factual constraints, the policy text association data are used to generate the semantic constraints, and the inter-policy relationships are used to generate the logical reasoning constraints.

4. The method according to claim 3, characterized in that, The step of generating target constraints based on the target path includes: If the target path is the rigid path, then a precise match is performed based on the original policy text to generate the factual constraints; If the target path is the elastic path, then semantic matching is performed based on the policy text-related data to generate the semantic constraints; If the target path is the logical path, then forward reasoning is performed based on the policy relationships to generate the logical reasoning constraints.

5. The method according to claim 1, characterized in that, The method further includes: Obtain the output content generated by the large language model based on the question to be answered and the current context; Perform counterfactual analysis on the output to generate a consistency score; If the consistency score is lower than a preset threshold, the output content will be corrected.

6. The method according to claim 5, characterized in that, The step of performing counterfactual reasoning on the output content to generate a consistency score includes: Based on the output content, a reasoning chain corresponding to the output content is generated, wherein the reasoning chain includes a condition set, reasoning rules, and original reasoning conclusion, and the condition set includes at least one condition; Construct counterfactual conditions for the conditions included in the inference chain; Based on the inference rules and the preset causal graph, forward inference is performed on the counterfactual conditions to generate counterfactual conclusions corresponding to the counterfactual conditions; The consistency score is generated based on the original reasoning conclusion and the counterfactual conclusion.

7. The method according to claim 6, characterized in that, If the consistency score is lower than a preset threshold, the output content is corrected, including: If the consistency score is lower than the preset threshold, then a problem node in the forward reasoning process of the counterfactual condition is identified; Based on the preset cause-effect graph, a reasoning path is determined to correct the problem node, thereby correcting the output content.

8. A data constraint device, characterized in that, include: The acquisition unit is used to acquire the question to be answered and the current context generated by the large language model based on the question to be answered; A determining unit is configured to determine a target path from multiple preset paths based on the question to be answered and the current context, wherein different preset paths are used to generate constraints of different natures; The generation unit is used to generate target constraints based on the target path, wherein the target constraints are used to constrain the output content generated by the large language model based on the question to be answered and the current context.

9. An electronic device, characterized in that, include: The processor, memory, communication interface, and communication bus are provided, wherein the processor, memory, and communication interface communicate with each other via the communication bus. The memory is used to store at least one executable instruction that causes the processor to perform the data constraint method as described in any one of claims 1-7.

10. A computer storage medium, characterized in that, It stores a computer program that, when executed by a processor, implements the data constraint method as described in any one of claims 1-7.