A large model counterfactual reasoning method and system based on a structural causal model

By employing a counterfactual reasoning method based on a structural causal model, the problem of large language models being unable to perform counterfactual reasoning is solved, enabling quantitative counterfactual reasoning and decision support, and enhancing the interpretability and verifiability of the model.

CN122635535APending Publication Date: 2026-08-25DONGGUAN XUANYUXI INTELLIGENT TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610723072.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-05-25
Publication Date
2026-08-25

AI Technical Summary

Technical Problem

Existing large language models cannot perform counterfactual reasoning, cannot answer the question "what would have happened if things had been different?", and existing methods cannot handle complex text scenarios, resulting in unreliable outputs and a lack of verifiability and interpretability.

Method used

We employ a counterfactual reasoning method based on a structural causal model, which combines abductive reasoning, intervention modification, and predictive computation with causal graphs and Bayes' theorem to output counterfactual results in natural language interpretation.

Benefits of technology

It enables large models to 'imagine another possibility', outputs quantitative comparisons of the differences in results from different choices, enhances decision support capabilities, and provides verifiable and explainable counterfactual reasoning.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122635535A_ABST
    Figure CN122635535A_ABST
Patent Text Reader

Abstract

The application discloses a kind of big model counterfactual reasoning method and system based on structural causal model, including the following steps: receiving the fact that user input has occurred;According to the input content of user, obtain causal diagram;The fact that has occurred is encoded mapping into causal diagram, forms the evidence of structural causal model;Trace back to reason, according to evidence counterfactual reasoning calculates the real value of exogenous variable;Intervention modifies target variable value, synchronously modifies causal diagram;Based on exogenous variable and modified causal diagram, predict and calculate counterfactual result;Compare output actual result and counterfactual result, and carry out natural language explanation.The application provides quantifiable counterfactual reasoning, outputs numerical result+confidence interval, provides verifiable causal relationship, based on structural causal model, expands the decision support capability of AI, enhances the counterfactual reasoning capability of big language model, can evaluate the hypothesis of "if different initially", outputs the decision support information of quantitative comparison different selection result difference.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of artificial intelligence technology, and in particular relates to a large-scale counterfactual reasoning method and system based on structural causal models. Background Technology

[0002] Current large-scale language model reasoning often only "sees" and doesn't "think." Models can make predictions based on existing data, but they can't make hypothetical inferences about "what if things were different." For example, a model can answer "This patient got better after taking the medication," but it can't answer "What would have happened if this patient hadn't taken the medication?" Even some models that can perform causal reasoning remain at the level of "A causes B," failing to engage in counterfactual thinking like "What would have happened if A hadn't been like this?" The final mile of causal reasoning remains unbridged. This deficiency in decision support is particularly evident in key areas such as healthcare, finance, and policymaking. Decision-makers need not only "What will happen?" but also "What would have been different if different actions had been taken?" For example, in a medical diagnostic system, doctors need to know "What would have happened if the patient hadn't taken the medication?" Existing models cannot provide quantitative answers based on causal models, nor can they offer such comparative analysis, nor can they answer "what if" questions, such as, "What would have happened if I had chosen a different path?" The model either cannot answer or provides unreliable guesses.

[0003] The following technical solutions are generally used in the prior art to overcome this deficiency: Pure statistical counterfactual estimation: using statistical methods (such as matching method, difference-in-differences) to estimate counterfactual results.

[0004] Limitations: It can only process structured data, cannot understand complex text scenarios, and the output is numerical, not natural language interpretation.

[0005] Counterfactual calculation based on structural causal model: using the three-step method of SCM: Abduction → Action → Prediction, to calculate counterfactual results.

[0006] Limitations: It requires manual definition of the cause-effect graph, cannot learn automatically from data, and cannot be integrated with large models.

[0007] Large model cue word method: Add "Please consider the counterfactual situation" or "Please imagine another possibility" to the cue words.

[0008] Drawbacks: Unreliable; the model merely "pretends" to reason, and is essentially still pattern matching, which can easily lead to illusions.

[0009] Counterfactual reasoning is the highest level of causal reasoning. Turing Award winner Judea Pearl's causal ladder theory consists of three levels: first, "relationship" (what we see); second, "intervention" (what happens if we do something); and third, "counterfactual" (what would have happened if things had been different). Current large-scale models suffer from the following specific technical shortcomings in counterfactual reasoning: It is impossible to perform abductive reasoning. Given observed facts (such as Y=y), the existing model cannot deduce the value of the exogenous variable U, and lacks a computational framework for inferring the cause from the result.

[0010] The existing models cannot separate random factors, cannot distinguish between causal effects and random noise, and lack technical means to quantify uncertainty.

[0011] The history cannot be precisely modified, existing models cannot be recalculated under the condition of "severing causal edges", and there is a lack of technical implementation for intervention operations.

[0012] Counterfactual results are unreliable; counterfactual conclusions generated by the cue word method lack repeatability and verifiability, and there is a lack of structured counterfactual calculation processes. Summary of the Invention

[0013] The purpose of this invention is to provide a large-scale counterfactual reasoning method and system based on a structural causal model to solve the technical problems in the prior art. The core idea is: given a fact that has already occurred, the system "backtracks" to the state before the fact occurred, modifies a variable, and then "replays" it, observing the changes in the result.

[0014] To address the aforementioned technical problems, this invention provides a large-scale counterfactual reasoning method based on a structural causal model, comprising the following steps: S1. Receive user input regarding the facts that have already occurred; S2. Obtain the cause-effect graph based on the user input; S3. Encode and map the facts that have occurred to the variables in the causal graph, X=x, Y=y, to form evidence for a structural causal model; S4. Abductive reasoning: Based on the evidence, infer the true value of the exogenous variable, which is influenced by random factors. S5. Intervene to modify the target variable value X, and simultaneously modify the causal graph; S6. Based on the exogenous variables and the modified causal graph, predict and calculate the counterfactual result Y; S7. Compare the actual output with the counterfactual output and provide a natural language explanation.

[0015] Preferably, the sources for obtaining the causal graph include: User-provided, expert-informed, and user-input cause-effect graphs are suitable for specialized fields. Learning from data, automatically learning from historical data using causal graph learning algorithms, is suitable for scenarios with sufficient historical data; It has a pre-built knowledge base and a built-in cause-effect graph for general domains, making it suitable for rapid application in common scenarios.

[0016] Preferably, the abductive reasoning is performed by inferring and calculating the posterior distribution P(U|X=x,Y=y) of the exogenous variable U using Bayes' theorem.

[0017] Preferably, the intervention modification is to change the target variable to a counterfactual value, X=x', and the modification of the causal graph is to delete all incoming edges pointing to the target variable X.

[0018] Preferably, step S6 includes: substituting the exogenous variable U value into the modified causal graph, recalculating the expected value of Y, and obtaining the counterfactual result: Y=y'.

[0019] Preferably, the comparison output in step S7 includes absolute difference, relative difference, and confidence interval.

[0020] This invention also provides a large-scale counterfactual reasoning system based on a structural causal model, comprising: The causal graph module is used to obtain causal graphs through three methods: causal graphs provided by experts directly input by the user, causal graphs automatically learned by the model from historical data through a causal graph learning algorithm, and built-in causal graphs for general domains. The fact encoding module is used to encode and map the facts that have occurred onto the causal graph, forming evidence for the structural causal model; The abductive reasoning module is used to infer the true value of the exogenous variable based on the evidence, where the exogenous variable is influenced by random factors. The intervention and modification module is used to intervene and modify the target variable value X, and simultaneously modify the causal graph. The counterfactual prediction module is used to predict and calculate the counterfactual outcome Y based on exogenous variables and the modified causal graph. The comparison output module is used to compare the actual output results with the counterfactual results and provide natural language interpretation.

[0021] Preferably, the cause-effect graph module also includes: The causal discovery module is used to automatically learn causal relationships from training data or user-input data, output causal graphs, support numerical and text data, and be compatible with linear and non-linear relationships; The causal graph encoding module is used to encode the causal graph into a form usable by large models, including causal attention masks and causal path encoding; The causal reinforcement model is used to add causal attention bias to the standard Transformer, so that tokens on causal paths receive higher attention weights and non-causal paths are suppressed.

[0022] The present invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the large model counterfactual reasoning method based on a structural causal model as described in any of the preceding claims.

[0023] The present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the large model counterfactual reasoning method based on the structural causal model as described in any of the preceding claims.

[0024] Compared with the prior art, the beneficial effects of the present invention are: This invention provides a large-scale counterfactual reasoning method and system based on a structural causal model, which enhances the counterfactual reasoning ability of large language models, enabling large models to "imagine another possibility", answer counterfactual questions such as "what would have happened if things had been different", and output decision support information that quantitatively compares the differences in the results of different choices.

[0025] This invention adopts a three-step framework for counterfactual reasoning: abduction → action → prediction, providing a complete counterfactual reasoning process.

[0026] This invention employs abductive reasoning to infer the posterior distribution of exogenous variables from observed facts, thereby separating out unobservable random factors.

[0027] This invention employs counterfactual intervention and prediction, and after modifying the target variable, re-predicts the result based on the exogenous variable.

[0028] This invention employs a counterfactual outcome comparison output, which quantitatively compares actual results with counterfactual results to output differentiated decision support information.

[0029] This invention employs seamless integration with causal reasoning systems, adding counterfactual capabilities to causal reasoning to form a complete causal + counterfactual reasoning system.

[0030] This invention employs interpretable counterfactual explanation generation, outputting the counterfactual reasoning process in natural language, allowing users to understand "why different choices lead to different results".

[0031] This invention provides quantifiable counterfactual reasoning, whereas existing technologies can only make qualitative guesses; this invention outputs numerical results plus confidence intervals. This invention provides a traceable reasoning process, whereas existing technologies are black boxes; this invention outputs a complete chain of attribution → intervention → prediction. This invention provides verifiable causal relationships, whereas existing technologies are prone to creating illusions; this invention is based on a structural causal model, and its conclusions are verifiable. This invention expands the decision support capabilities of AI, whereas existing technologies can only predict the future; this invention can evaluate hypotheses of "what if things were different." Attached Figure Description

[0032] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.

[0033] Figure 1 A schematic diagram of the overall architecture of a large-scale counterfactual reasoning system based on a structural causal model, provided for embodiments of this application; Figure 2 One of the flowcharts for a large-scale counterfactual reasoning method based on a structural causal model provided in this application embodiment; Figure 3 A second flowchart illustrating a large-scale counterfactual reasoning method based on a structural causal model provided in this application embodiment; Figure 4 This is a schematic diagram of the abductive reasoning process provided in the embodiments of this application; Figure 5 This is a schematic diagram of the structure of a storage medium provided in an embodiment of this application; Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0034] In the description of this application, "multiple" means at least two, such as two, three, etc., unless otherwise explicitly specified. All directional indications (such as up, down, left, right, front, back, top, bottom, etc.) in the embodiments of this application are only used to explain the relative positional relationships and movement of the components in a specific posture (as shown in the figures). If the specific posture changes, the directional indication will also change accordingly. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or IoT terminal that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or IoT terminals.

[0035] Furthermore, the reference to "embodiment" herein means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.

[0036] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0037] like Figure 2-4 As shown, this invention provides a method for large-scale counterfactual reasoning (hypothetical reasoning about "what would have happened if things had been different") based on a structural causal model, comprising the following steps: S1. Receive user input regarding the facts that have already occurred; S2. Obtain the cause-effect graph based on the user input (the cause-effect graph is a directed acyclic graph that represents the causal relationship between variables). S3. Encode the facts that have occurred and map them to the variables in the causal graph, X=x, Y=y, to form evidence of a structural causal model (a mathematical model of causal relationship represented by a directed graph); for example: if a user inputs "the patient took drug A and his blood pressure dropped from 160 to 130", map the facts that have occurred to the variables in the causal graph: X=drug A (value 1), Y=blood pressure (change to -30). S4. Abductive reasoning (the process of inferring unobserved causes from observed facts): Based on the evidence, infer the true value of exogenous variables (variables in the causal diagram that are not affected by other variables and are determined by external factors). The exogenous variables are influenced by random factors. S5. Intervene to modify the target variable value X, and simultaneously modify the causal graph; S6. Based on the exogenous variables and the modified causal graph, predict and calculate the counterfactual result Y; S7. Compare the actual output with the counterfactual output and provide a natural language explanation.

[0038] Counterfactual reasoning is based on a structural causal model, with the structural equation being: Y=f(X,U), where Y is the outcome variable; X is the causal variable; U is the exogenous variable (an unobservable random factor); and f is the structural function.

[0039] The counterfactual calculation formula is: P(Y|do(X=x))=Σ_Z P(Y|X=x,Z×P(Z), where do(X=x): intervention operation (force X=x); Z: set of confounding variables; P(Y\|do(X=x)): distribution of outcomes after intervention.

[0040] In one specific embodiment provided in this application, the sources for obtaining the cause-effect graph include: User-provided, expert-informed, and user-input cause-effect graphs are applicable to professional fields such as medicine and finance. Learning from data, automatically learning from historical data using causal graph learning algorithms (such as PC algorithms), is suitable for scenarios with sufficient historical data; It has a pre-built knowledge base and a built-in cause-effect graph for general domains, making it suitable for rapid application in common scenarios.

[0041] For example: The user provided a cause-and-effect diagram with the following information when asking a question: "Drug A → Blood Pressure, Age → Blood Pressure".

[0042] By learning from data, the system learns and analyzes 1 million medical records from historical records to derive causal structures.

[0043] The system includes a pre-built knowledge base, a medical causal graph, and a pre-loaded medical knowledge graph.

[0044] Furthermore, causal graph learning algorithms include PC algorithm, FCI (for handling hidden variables), NOTEARS (for high-dimensional data), and GraN-DAG (for non-linear relationships). The detailed steps of the PC algorithm are as follows: Input: Historical dataset D (e.g., 1 million sales records, including three variables: advertising investment, sales volume, and price) 1. Construct a complete graph: Connect the three variables in pairs (advertisement-sales, advertisement-price, price-sales).

[0045] 2. Conditional Independence Test: Are test ads and sales independent? Correlation coefficient 0.6, not independent → retain the edge; Are the test ad and price independent? A correlation coefficient of 0.1 indicates independence → remove the edge. Are price and sales volume independent? Correlation coefficient -0.5, not independent → retain the edge.

[0046] 3. Determine the direction: It was found that "advertising" and "sales volume" are related, "price" and "sales volume" are related, but "advertising" and "price" are not related.

[0047] Direction determination: Advertising → Sales volume, Price → Sales volume.

[0048] Output a cause-and-effect graph: Advertisement → Sales, Price → Sales.

[0049] In one specific embodiment provided in this application, abductive reasoning calculates the posterior distribution P(U|X=x,Y=y) of the exogenous variable U using Bayes' theorem, and infers the true value of the exogenous variable (unobserved random factors) based on observed facts. Bayesian inference uses probability distributions to represent uncertainty and outputs confidence intervals. In practical applications, reasonable assumptions are made about the exogenous variable U: assuming U follows a known distribution (such as Gaussian or uniform distribution); assuming U is conditionally independent of X; and verifying the robustness of the assumptions through sensitivity analysis. For example, a patient's blood pressure drops by 30, which, in addition to the effect of drug A, may also be affected by random factors such as whether the patient rested well that day and measurement errors. Unobserved factors affecting drug decisions (such as patient preferences) and unobserved factors affecting blood pressure (such as the patient's rest status that day) can be separated out through abductive reasoning to isolate the contributions of these random factors.

[0050] Specific implementation methods of abductive reasoning: Suppose that in the causal graph there is X→Y, and Y is also affected by the exogenous variable U.

[0051] Structural equation: Y = f(X) + U.

[0052] Given that Y=y and X=x, we need to calculate the value of U.

[0053] Calculation method: U=yf(x) Example: Cause-and-effect diagram: Drug A (X) → Blood pressure (Y), and blood pressure is also affected by rest factor U.

[0054] Structural equation: Y = -20 × X + U.

[0055] Observational facts: X=1 (medication taken), Y=-30 (blood pressure decreased by 30). Calculate U: U=Y-(-20×X)=-30+20=-10 Conclusion: Rest factor U contributed to the blood pressure reduction of -10 mmHg.

[0056] For multivariate cases, the posterior distribution of the exogenous variable U is calculated using Bayes' theorem. The standard Bayesian inference formula is P(U|X=x,Y=y)=P(Y=y|X=x,U)×P(U) / P(Y=y|X=x), which calculates the most probable value by enumerating the possible values ​​of U.

[0057] Accuracy verification methods include: synthetic data testing, which verifies the accuracy of counterfactual calculations on synthetic data with known causal relationships; A / B testing, which compares the difference between counterfactual predictions and actual results in real-world scenarios; and cross-validation, which uses a portion of the data for training and another portion of the data for validation of the confidence interval output, outputting a 95% confidence interval using a probability distribution rather than a single point estimate. For example, assuming the rest factor U follows a Gaussian distribution N(0,10), the posterior distribution is calculated using Bayes' theorem, yielding a 95% confidence interval [-15,-5] for U. Substituting this into the prediction formula, the output is a blood pressure decrease of 5-15 mmHg instead of a single point of 10 mmHg.

[0058] Example in a medical scenario: Blood pressure drops by 30 mmHg after medication. Output: "Expected decrease of 10 mmHg without medication (95% CI: 8-12 mmHg)". The confidence interval tells the user that the actual value has a 95% probability of falling between 8-12 mmHg, which is a quantitative expression of accuracy.

[0059] In one specific embodiment provided in this application, the intervention modification is to modify the value of the target variable to a counterfactual value, X=x'. For example, if a user asks "What would happen to the blood pressure if the patient did not take the medication?", then X=0 (no medication).

[0060] Modifying a causal graph involves deleting all incoming edges pointing to the target variable X. For example, before modification, the causal graph was "Age → Drug A, Drug A → Blood Pressure". The modification operation is "delete incoming edges pointing to Drug A", and after modification, the causal graph is "Drug A → Blood Pressure (no incoming edges)". The reason for the modification is that the intervention operation do(X=x) requires severing all causal relationships pointing to X, meaning "forcibly setting the value of X, unaffected by other factors".

[0061] In one specific embodiment provided in this application, step S6 includes: substituting the value of the exogenous variable U into the modified causal graph, recalculating the expected value of Y, and obtaining the counterfactual result: Y=y'.

[0062] In one specific embodiment provided in this application, the comparison output of step S7 includes absolute difference, relative difference, and confidence interval.

[0063] Complete Implementation Example: The user entered: "After taking medication A, the patient's blood pressure dropped from 160 to 130. What would his blood pressure be if he hadn't taken the medication?" Step 1: The system receives the following facts: Drug A = 1, blood pressure change = -30.

[0064] Step 2: Obtain the cause-effect graph (choose one of the three methods) Method A: The user directly provides: "Medication A → Blood Pressure, Age → Medication A, Age → Blood Pressure"; Method B: Learning from historical data (PC algorithm); Method C: Loading the pre-built knowledge base.

[0065] Step 3: Fact encoding, mapping facts to a cause-and-effect graph: Drug A=1, blood pressure change=-30.

[0066] Step 4: Abductive reasoning, calculate exogenous variables: Drug A contributes -20, good rest on the day (rest factor U_bp) contributes -10.

[0067] Step 5: Intervene and modify, delete the incoming edge pointing to drug A (age → drug A), and set drug A = 0 (no medication taken).

[0068] Step 6: Predictive calculation: Under the conditions of U_bp=-10 and drug A=0, the blood pressure change is -10.

[0069] Step 7: Output the result "If the patient had not taken the medication, the blood pressure would have decreased by 10 mmHg (actual decrease was 30 mmHg)". The comparison results include: absolute difference: 20 mmHg; relative difference: 66% (20 / 30); net effect of the medication: 20 mmHg; 95% confidence interval: [18, 22].

[0070] like Figure 1 As shown, the present invention also provides a large-scale counterfactual reasoning system based on a structural causal model, comprising: The causal graph module is used to obtain causal graphs through three methods: causal graphs provided by experts directly input by the user, causal graphs automatically learned by the model from historical data through a causal graph learning algorithm, and built-in causal graphs for general domains. The fact encoding module is used to encode and map the facts that have occurred onto the causal graph, forming evidence for the structural causal model; The abductive reasoning module is used to infer the true value of the exogenous variable based on the evidence, where the exogenous variable is influenced by random factors. The intervention and modification module is used to intervene and modify the target variable value X, and simultaneously modify the causal graph. The counterfactual prediction module is used to predict and calculate the counterfactual outcome Y based on exogenous variables and the modified causal graph. The comparison output module is used to compare the actual output results with the counterfactual results and provide natural language interpretation.

[0071] The cause-effect graph module also includes: The causal discovery module is used to automatically learn causal relationships from training data or user-input data, output causal graphs, support numerical and text data, and be compatible with linear and non-linear relationships; The causal graph encoding module is used to encode the causal graph into a form usable by large models, including causal attention masks and causal path encoding; The causal reinforcement model is used to add causal attention bias to the standard Transformer, so that tokens on causal paths receive higher attention weights and non-causal paths are suppressed.

[0072] The causal graph module is described in detail in the prior application "A Large-Scale Causal Reasoning Method and System Based on Structural Causal Model", and the description is omitted here.

[0073] The description of this system and the large-scale counterfactual reasoning method based on structural causal model provided by this invention are partially omitted here.

[0074] like Figure 5 As shown, the present invention also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the large model counterfactual reasoning method based on the structural causal model as described in any of the preceding claims.

[0075] like Figure 6 As shown, the present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the large model counterfactual reasoning method based on the structural causal model as described in any of the preceding claims.

[0076] This invention can be implemented in three versions to suit different application scenarios, as follows: Lightweight version: It does not perform complete abductive reasoning, but directly uses causal diagrams and simple assumptions (such as assuming that exogenous variables remain unchanged), which is suitable for scenarios where high precision is not required.

[0077] Enhanced version: Adds Monte Carlo sampling, outputting the probability distribution of counterfactual results instead of single-point estimates.

[0078] Real-time version: Optimizes the calculation speed of abductive reasoning for online decision-making scenarios, achieving millisecond-level counterfactual response.

[0079] The following detailed application scenario examples further illustrate the solution of the present invention: Specific scenario examples: Scenario 1: Medical Decision Making A user asked: "The patient's blood pressure dropped after taking medication A. What would his blood pressure be if he hadn't taken the medication?" Counterfactual reasoning process: Fact: Drug A=1 (after taking the medication), blood pressure decreased by 30 mmHg.

[0080] The cause-and-effect diagram shows that drug A leads to blood pressure (effect -20 mmHg), and there are also random factors U such as rest and measurement error.

[0081] Cause analysis: The patient had a good rest that day, and random factors contributed to the -10 mmHg.

[0082] Intervention: Set drug A=0 (no medication taken).

[0083] Prediction: Without medication, the rest factor will still be present, and blood pressure will drop by approximately 10 mmHg.

[0084] Output: "If the patient had not taken drug A, the blood pressure would have decreased by 10 mmHg (instead of the actual decrease of 30 mmHg). The net effect of drug A is 20 mmHg." Scenario 2: Business Decisions A user asked, "We increased our advertising spending by 20%, and sales increased by 15%. What would have happened to sales if we hadn't increased advertising?" Counterfactual reasoning process: Fact: Advertising = +20%, Sales = +15%.

[0085] Cause-and-effect diagram: Advertising → Sales (direct), and market trends → Sales (confusion).

[0086] Cause: Market trends contributed to the +5% sales growth.

[0087] Intervention: Set advertising = 0.

[0088] Forecast: Market trends will still contribute +5% even without advertising.

[0089] Output: "Without increased advertising investment, sales were projected to increase by 5% (instead of the actual increase of 15%). The net effect of the advertising investment is 10 percentage points." In addition to providing decision support in the above application scenarios, this invention is also applicable to the following application scenarios:

[0090] The advantages of this invention compared to the prior art are shown in the table below:

[0091] This invention outputs quantifiable counterfactual comparative analysis, specifically demonstrating its value and significance in the following aspects: Evaluate historical decisions: quantify "what would have happened if option B had been chosen", review the gains and losses of the decision, and accumulate experience.

[0092] Optimize future decisions: Simulate the differences in outcomes of different choices, select the optimal path, and avoid trial-and-error costs.

[0093] Defining responsibility: Distinguish between "causal effects" and "random factors" to clarify the true contribution of the decision.

[0094] Risk warning: Predict "what consequences will occur if X happens" and avoid risks in advance.

[0095] This invention employs a three-step counterfactual reasoning framework: Abduction → Action → Prediction, providing a complete counterfactual reasoning process. It utilizes abductive reasoning to infer the posterior distribution of exogenous variables from observed facts, separating unobservable random factors. It employs counterfactual intervention and prediction, re-predicting results based on exogenous variables after modifying the target variable. It uses counterfactual result comparison output, quantitatively comparing actual and counterfactual results to output differentiated decision support information. It seamlessly integrates with causal reasoning systems, adding counterfactual capabilities to causal reasoning to form a complete causal + counterfactual reasoning system. It uses interpretable counterfactual explanation generation, outputting the counterfactual reasoning process in natural language, allowing users to understand "why different choices lead to different results."

[0096] The basic principles of this application have been described above with reference to specific embodiments. However, it should be noted that the advantages, benefits, and effects mentioned in this application are merely examples and not limitations, and should not be considered as essential features of each embodiment of this application. Furthermore, the specific details disclosed above are for illustrative and facilitative purposes only, and are not limitations. These details do not limit the application to the necessity of employing the specific details described above. The above description is provided to enable any person skilled in the art to make or use this application. Various modifications to these aspects will be readily apparent to those skilled in the art, and the general principles defined herein can be applied to other aspects without departing from the scope of this application. Therefore, this application is not intended to be limited to the aspects shown herein, but rather to be accorded the widest scope consistent with the principles and novel features of this application.

[0097] The above are merely preferred embodiments of this application and are not intended to limit the scope of this application. Any modifications or equivalent substitutions made within the spirit and principles of this application shall be included within the protection scope of this application.

[0098] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.

Claims

1. A large-scale counterfactual reasoning method based on a structural causal model, characterized in that, Including the following steps: S1. Receive user input regarding the facts that have already occurred; S2. Obtain the cause-effect graph based on the user input; S3. Encode and map the facts that have occurred to the variables in the causal graph, X=x, Y=y, to form evidence for a structural causal model; S4. Abductive reasoning: Based on the evidence, infer the true value of the exogenous variable, which is influenced by random factors. S5. Intervene to modify the target variable value X, and simultaneously modify the causal graph; S6. Based on the exogenous variables and the modified causal graph, predict and calculate the counterfactual result Y; S7. Compare the actual output with the counterfactual output and provide a natural language explanation.

2. The large-scale counterfactual reasoning method based on a structural causal model according to claim 1, characterized in that, The sources for obtaining the cause-effect graph include: User-provided, expert-informed, and user-input cause-effect graphs are suitable for specialized fields. Learning from data, automatically learning from historical data using causal graph learning algorithms, is suitable for scenarios with sufficient historical data; It has a pre-built knowledge base and a built-in cause-effect graph for general domains, making it suitable for rapid application in common scenarios.

3. The large-scale counterfactual reasoning method based on a structural causal model according to claim 1, characterized in that, The abductive reasoning is to infer and calculate the posterior distribution P(U|X=x,Y=y) of the exogenous variable U using Bayes' theorem.

4. The large-scale counterfactual reasoning method based on a structural causal model according to claim 1, characterized in that, The intervention modification involves changing the target variable to a counterfactual value, X=x', and the modification of the causal graph involves deleting all incoming edges pointing to the target variable X.

5. The large-scale counterfactual reasoning method based on a structural causal model according to claim 1, characterized in that, Step S6 includes: substituting the exogenous variable U value into the modified causal graph, recalculating the expected value of Y, and obtaining the counterfactual result: Y=y'.

6. The large-scale counterfactual reasoning method based on a structural causal model according to claim 1, characterized in that, The comparison output of step S7 includes absolute difference, relative difference, and confidence interval.

7. A large-scale counterfactual reasoning system based on a structural causal model, characterized in that, include: The causal graph module is used to obtain causal graphs through three methods: causal graphs provided by experts directly input by the user, causal graphs automatically learned by the model from historical data through a causal graph learning algorithm, and built-in causal graphs for general domains. The fact encoding module is used to encode and map the facts that have occurred onto the causal graph, forming evidence for the structural causal model; The abductive reasoning module is used to infer the true value of the exogenous variable based on the evidence, where the exogenous variable is influenced by random factors. The intervention and modification module is used to intervene and modify the target variable value X, and simultaneously modify the causal graph. The counterfactual prediction module is used to predict and calculate the counterfactual outcome Y based on exogenous variables and the modified causal graph. The comparison output module is used to compare the actual output results with the counterfactual results and provide natural language interpretation.

8. A large-scale counterfactual reasoning system based on a structural causal model according to claim 7, characterized in that, The cause-effect graph module includes: The causal discovery module is used to automatically learn causal relationships from training data or user-input data, output causal graphs, support numerical and text data, and be compatible with linear and non-linear relationships; The causal graph encoding module is used to encode the causal graph into a form usable by large models, including causal attention masks and causal path encoding; The causal reinforcement model is used to add causal attention bias to the standard Transformer, so that tokens on causal paths receive higher attention weights and non-causal paths are suppressed.

9. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the large model counterfactual reasoning method based on a structural causal model as described in any one of claims 1 to 7.

10. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the large model counterfactual reasoning method based on the structural causal model as described in any one of claims 1 to 7.