Causal graph optimization and inference method based on counterfactual reasoning
By generating context-consistent counterfactual samples and constructing a fact-counterfact graph, and utilizing mask training and graph attention networks, the problem of inaccurate identification of causal structures in causal relationship recognition models is solved, achieving high accuracy and interpretability in causal relationship discrimination.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- GUANGDONG UNIV OF TECH
- Filing Date
- 2026-02-28
- Publication Date
- 2026-07-03
AI Technical Summary
Existing methods struggle to generate context-consistent counterfactual samples, causing causal relationship identification models to learn superficial correlations rather than true causal structures, resulting in a lack of interpretability and accuracy.
By generating context-consistent counterfactual samples through a large language model, a fact-counterfact graph is constructed. Mask training and graph attention networks are used to improve the ability to distinguish causal mechanisms. Heterogeneous graph structures are dynamically constructed and causal relationships are distinguished.
It improves the accuracy and interpretability of causal relationship identification. By generating counterfactual samples and optimizing the graph, it enhances the model's ability to identify causal relationships, eliminates noise, and improves the accuracy of causal relationship judgment.
Smart Images

Figure CN122334459A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of natural language processing technology, and in particular to a method for causal graph optimization and inference based on counterfactual reasoning. Background Technology
[0002] Event Causality Identification (ECI) aims to automatically detect causal relationships between events in text and is a key technology for downstream tasks such as knowledge graph construction and question answering systems. In real text, causal relationships often appear implicitly, and traditional methods relying on lexical rules and hand-crafted features struggle to capture deep semantic connections.
[0003] Existing methods typically model based on global context and semantic features. However, these methods often over-rely on statistical correlation signals unrelated to true causal relationships, such as certain keywords, event co-occurrence patterns, or semantic similarities. This leads the model to learn superficial correlations rather than true causal structures. With the development of large language models, event causal recognition has gained new semantic understanding capabilities. However, how to generate context-consistent counterfactual samples and construct interpretable causal graphs remains a challenge in current research. Summary of the Invention
[0004] To address the aforementioned shortcomings, the present invention aims to propose a causal graph optimization and inference method based on counterfactual reasoning. This method utilizes a large language model to generate context-consistent counterfactual samples, and through explicit comparison of factual and counterfactual graphs, enhances the ability to discriminate causal mechanisms and improves the accuracy and interpretability of causal relationship identification.
[0005] To achieve this objective, the present invention adopts the following technical solution: A causal graph optimization and inference method based on counterfactual reasoning, wherein the causal inference method includes the following steps: S1: Given a target event and its text, retrieve events similar to the target event from an external knowledge base, extract keywords using a large language model (LLM) and generate similar sentences consistent with the context of the target event; then, recall and filter relevant causal knowledge, generate causal knowledge sentences based on keywords, and perform counterfactual reasoning perturbation on them to generate counterfactual causal sentences; S2: Based on the causal knowledge sentences obtained in step S1, construct factual causal templates and counterfactual causal templates, and train BERT through masking to automatically determine the type of input template; for the target event, extract its event-level features, context features of the sentence in which it is located, and global features of the whole text, and fuse them to obtain a comprehensive semantic representation of the target event; for similar events, based on the extracted event features and sentence features, introduce the corresponding causal knowledge features and masked state features, and fuse them through similarity weighting to generate causal enhanced representations of similar events, thereby forming factual and counterfactual causal node representations; S3: Based on the causal nodes obtained in step S2, establish connections between the target event and similar events, and fuse features through a graph attention network; classify the target event, determine whether it has a causal relationship, and label it as a "core event" or "background event"; S4: Based on the core events and background events in step S3, dynamically construct a heterogeneous graph structure; connect the core events and background events in text order, divide the background events into two parts, and establish weighted connections with the core events through dot product attention and additive attention mechanisms respectively; the core events are connected in a fully connected manner; the counterfactual heterogeneous graph directly reuses the topological structure of the factual heterogeneous graph, only replacing the node features; S5: On the heterogeneous graph constructed in step S4, a graph attention mechanism is used to fuse features between background events and between background events and core events; the causal correlation strength between core events is calculated through the attention mechanism, the causal score in the counterfactual causal graph is introduced into the fact graph, and the attention weights between core events and the penalty are adjusted, while the features between core events are fused; counterfactual orthogonal projection is applied to the node features of the fact graph to remove noise in the counterfactual direction; finally, a cosine similarity loss function is introduced to separate the node representations of the fact graph and the counterfactual graph in the feature space, and event pairs are constructed based on the optimized node representations for discrimination, and the judgment result of whether there is a causal relationship between the event pairs is output.
[0006] Preferably, step S1 includes: Given a target event and its text, retrieve semantically similar events from the external knowledge base ConceptNet. One event; use a large language model (LLM) to extract topic information from the target text, including topic words or topic sentences; Based on this topic information, LLM is used in conjunction with the context of the target event to embed similar events into the target event sentence, generating semantically consistent and context-aware similar sentences; Simultaneously, causal knowledge similar to the target event is retrieved from the external knowledge base ConceptNet. LLM is used to filter relevant entries, and causal knowledge sentences associated with the target event are generated by matching extracted keywords. Based on this, the following counterfactual reasoning rules are applied to slightly perturb the causal knowledge sentences, satisfying the following rules: (1) Switching of causal subjects: swapping the subjects of cause and effect in a causal relationship while keeping other contents consistent; (2) Introduction of negative structure: Insert the smallest negative or restrictive element into the same sentence structure to destroy the necessity or sufficiency of the causal relationship; (3) Weakening of causal mechanism: retain the causal subject and event, weaken the "causal mechanism term", and reduce the causal relationship to a co-occurrence or correlation description.
[0007] Preferably, in step S2, the causal template is:
[0008]
[0009]
[0010]
[0011] in Indicates the target event, The sentence containing the target event; Indicates the first A similar event, Indicates the first Similar sentences about similar events These respectively represent causal knowledge sentences; the counterfactual causal template will... The cause item of each causal knowledge sentence and results Replace them with counterfactual causal sentences after counterfactual reasoning perturbation; the mask training involves inputting the causal template into BERT and predicting... The semantic category label of the location is used to determine whether the causal knowledge sentence belongs to the fact type "FACT" or the counterfactual type "CF". The target event features of the input template are fused to satisfy the following relation:
[0012] in, For the first [CLS] features of a text target event For the target event Features For the target event In the sentence Features in , For learnable parameter matrix, The characteristics of the target event after fusion; The similarity features of the input template are fused based on the similarity between causal knowledge sentences and similar sentences, satisfying the following relation:
[0013]
[0014]
[0015]
[0016] in, These are characteristics of causal or result sentences. For the first Similar events Sentence features, The similarity between sentences containing causal or result information and similar sentences. and The learnable parameter matrix; The similarity weight for the cause or result clause; As a characteristic of causal knowledge, For the first Similar events Event characteristics, causal state feature, Features of similar events after fusion.
[0017] Preferably, step S3 includes: Let the text sequence be The text is then fed into the pre-trained language model BERT to obtain the semantic representations of each target event in the global context. , and The final text target event node features are obtained by fusion through a feedforward network. ; A local subgraph is constructed, centered on the target event node and connecting its n similar event neighbors. A graph attention network is used to aggregate neighbor features and update node representations. Then, binary classification is performed on the target event node to determine its probability score indicating a causal relationship within the text. A probability threshold of 0.4 is set. When the predicted probability is greater than or equal to this threshold, the event is classified as a "core event"; otherwise, it is classified as a "background event," satisfying the following relationship:
[0018]
[0019]
[0020] in For learnable parameter matrix, For learnable attention vectors, For the target event to the first Attention weights for similar events, To integrate the characteristics of the target event after fusing similar events, and These are the classification weight vector and the classification bias term, respectively. This is the predicted probability that the target event belongs to the "core event".
[0021] Preferably, step S4 includes: An event sequence is constructed by sequentially connecting core event nodes and background event nodes according to the original text order. The features of the background events and core events are linearly mapped and then split into two attention heads. Dot product attention and additive attention mechanisms are used to calculate the attention weights between the background events and each core event. Based on these attention weights, the core event with the highest weight is selected and connected to its corresponding background event. Simultaneously, fully connected edges are constructed between the core event nodes, resulting in a fact heterogeneous graph. The antifactual heterogeneous graph directly reuses the topology of the fact heterogeneous graph, only replacing the node features. The dot product attention and additive attention mechanisms satisfy the following relationship:
[0022]
[0023]
[0024] in, Indicates background events eigenvectors, Indicates the core event eigenvectors; , These represent the background event query mapping matrices in the first and second attention heads, respectively. , These represent the background event key mapping matrices in the first and second attention heads, respectively. It is a bias term in the additive attention mechanism; Indicates the first attention-grabbing event in the background. With core events Attention weights; This indicates the second attention-grabbing event in the background. With core events Compatibility score between them; This represents the attention weight of the second attention head.
[0025] Preferably, step S5 includes: A graph attention mechanism is employed to fuse node features between background events and between background events and core events in the fact graph and counterfactual graph. The causal weights between core events are calculated using the attention mechanism, and the causal scores from the counterfactual causal graph are introduced into the fact graph to adjust and penalize the attention weights between core events. This ensures that attention is more focused on neighbor connections with genuine causal relationships, satisfying the following relation:
[0026]
[0027]
[0028]
[0029]
[0030] in This indicates counterfactual punishment gate control. and This represents the attention score between core event pairs; Indicates the core event and Standardized attention weights between them; This represents the standardized attention weights after adjusting for counterfactual penalties; , Representing nodes respectively exist Layered fact graph and counterfactual graph feature representation, Represents the learnable weight matrix; This indicates that the features of the current layer are orthogonally projected onto the counterfactual graph to remove counterfactual interference components.
[0031] Preferably, in step S3, the probability of whether a causal relationship exists in the text is estimated through feature representation learning; in step S5, by minimizing the similarity between the node features of the fact graph and the counterfactual graph, the two are made as independent as possible in terms of information, thereby eliminating non-causal common noise, and determining whether a causal relationship exists on the finally constructed event pairs, satisfying the following relationship:
[0032]
[0033]
[0034]
[0035]
[0036]
[0037] in This represents the cross-entropy loss during mask training; Cross-entropy loss represents the initial prediction of whether there is a causal relationship between events in the text. This indicates the loss of similarity between factual and counterfactual features; This indicates the causal probability between pairs of events. The cross-entropy loss represents the final prediction of whether there is a causal relationship between event pairs.
[0038] The beneficial effects of this invention are: (1) Counterfactual sample generation and type discrimination: The large language model is used to generate counterfactual causal samples based on the context and topic information of the target event. The mask training mechanism enables the model to automatically distinguish between factual and counterfactual sample categories, thereby improving the model's ability to identify different causal situations.
[0039] (2) Heterogeneous graph structure construction and attention fusion: Dynamically construct heterogeneous graphs containing core events and background events, introduce a fusion strategy of dot product attention and additive attention mechanism, comprehensively capture the relationship between different types of nodes, and effectively model the temporal dependency and global association of document-level events.
[0040] (3) Counterfactual penalty gating and causal strength correction: Combine the counterfactual penalty gating module to adjust the attention distribution between core events, punish edges with high counterfactual scores, and remove counterfactual noise through causal orthogonal projection, so that the features more purely reflect the true causal relationship. Attached Figure Description
[0041] Figure 1 This is an implementation framework diagram of the causal graph optimization and inference method based on counterfactual reasoning provided in the embodiments of the present invention. Detailed Implementation
[0042] To make the technical means, creative features, objectives and effects of this invention easier to understand, the invention will be further described below with reference to specific illustrations.
[0043] like Figure 1 As shown, this invention proposes a causal graph optimization and inference method based on counterfactual reasoning. The following is an example from the input document: According to the US Geological Survey, the quake hit at a depth of 10kilometers in the Northern Province of Aceh. The epicenter was situated 55kilometers west of the town of Bireun on the western tip of Sumatra Island. Eyewitnesses and local residents say many homes and properties have collapsed or been damaged. "I see many houses were damaged and theirs roof fell ontosome people," said Bensu Elianita, a 22 year-old resident in Bukit Samavillage in Central Aceh district, adding, "Many people were injured but itis difficult to evacuate them due to traffic jams. "Omit some text.
[0044] In step S1, based on the given target event and its text, semantically similar events are retrieved from the external knowledge base ConceptNet. One event; use a large language model (LLM) to extract topic information from the target text, including topic words or topic sentences.
[0045] Based on this topical information, LLM is used in conjunction with the context of the target event to embed similar events into the target event sentence, generating semantically consistent and context-appropriate similar sentences.
[0046] Simultaneously, causal knowledge similar to the target event is retrieved from the external knowledge base ConceptNet. LLM is used to filter relevant entries, and causal knowledge sentences associated with the target event are generated by matching extracted topic terms. Based on this, the following counterfactual reasoning rules are applied to slightly perturb the causal knowledge sentences, satisfying the following rules: (1) Switching of causal subjects: swapping the subjects of cause and effect in a causal relationship while keeping other contents consistent; (2) Introduction of negative structure: Insert the smallest negative or restrictive element into the same sentence structure to destroy the necessity or sufficiency of the causal relationship; (3) Weakening of causal mechanism: retain the causal subject and event, weaken the "causal mechanism words" (such as "cause", "lead to", etc.), and degenerate them into co-occurrence descriptive words such as "coincided with", so that the causal relationship degenerates into co-occurrence or correlation description.
[0047] Specifically, in this embodiment, taking the target event "quake" as an example, its original text is: "According to the US Geological Survey, the quake hit at a depth of 10 kilometers in the Northern Province of Aceh." Events semantically similar to the target event are recalled through an external knowledge base. The obtained similar events include "earthquake," "tremor," and "seismic event."
[0048] The original text containing the target event is input into a Large Language Model (LLM) to extract topic information, resulting in keywords including "quake," "Aceh Province," "damage," and "injured people." Based on these keywords, the LLM, combined with the context of the sentence containing the target event, semantically rewrites the sentence to generate similar sentences that are semantically consistent with the original and fit the context. For example, in the original sentence, the target event "quake" is the subject, the predicate is "hit," and the epicenter of the earthquake is mentioned. To generate semantically consistent similar sentences, the target event "quake" can be replaced while maintaining the sentence structure, resulting in similar sentences such as: "According to the US Geological Survey, the earthquake struck at a depth of 10 kilometers in the Northern Province of Aceh." or "The seismic event occurred at a depth of 10 kilometers in the Northern Province of Aceh."
[0049] Next, causal relationships related to similar events are retrieved from an external knowledge base, such as "earthquake causes damage," "earthquake leads to injuries," and "earthquake is caused by tectonic shifts." Using a large language model, combined with the keywords and context of the text, corresponding causal knowledge sentences are generated. For causal relationships where "earthquake" is the cause, sentences such as "the earthquake caused widespread damage to buildings and infrastructure" or "the earthquake led to injuries and loss of life in the affected areas" can be generated. For causal relationships where "earthquake" is the effect, sentences such as "the earthquake was caused by tectonic shifts beneath the Earth's surface" or "the earthquake resulted from the movement of tectonic plates" can be generated. In this way, the generated causal knowledge sentences not only conform to the context but also enhance the accuracy and comprehensiveness of causal reasoning.
[0050] Based on this, the following counterfactual reasoning rules are applied to randomly causal knowledge sentences to generate counterfactual causal sentences by making slight perturbations: Causal subject swapping: This involves exchanging the cause and effect subjects in a causal relationship while maintaining consistency in other aspects. For example, in the causal statement "the earthquake caused widespread damage to buildings and infrastructure" with "earthquake" as the cause, swapping the causal subjects generates the counterfactual statement: "widespread damage to buildings and infrastructure caused the earthquake."
[0051] Introducing a negative structure: Inserting a minimal negative or restrictive element into the same sentence structure to undermine the necessity or sufficiency of the causal relationship. For example, rewriting "the earthquake caused widespread damage to buildings and infrastructure" as "the earthquake did not cause widespread damage to buildings and infrastructure" or "the earthquake only caused partial damage to buildings and infrastructure".
[0052] Weakening of causal mechanisms: While retaining the causal subjects and events, the "causal mechanism terms" are weakened, reducing the causal relationship to a description of co-occurrence or correlation. For example, "the earthquake caused widespread damage to buildings and infrastructure" can be rewritten as "the earthquake was associated with widespread damage to buildings and infrastructure" or "the earthquake coincided with widespread damage to buildings and infrastructure".
[0053] Preferably, in step S2, the causal template is:
[0054]
[0055]
[0056]
[0057] in Indicates the target event, The sentence containing the target event; Indicates the first A similar event, Indicates the first Similar sentences about similar events These represent causal knowledge sentences, respectively. The counterfactual causal template will... The cause item of each causal knowledge sentence and results Replace them with counterfactual causal sentences after counterfactual reasoning perturbation; the mask training involves inputting the causal template into BERT and predicting... The semantic category label of the location is used to determine whether the causal knowledge sentence belongs to the fact type "FACT" or the counterfactual type "CF".
[0058] Specifically, in this embodiment, for the target event "quake", in step S2, factual causal templates and counterfactual causal templates are constructed. The causal knowledge sentences obtained from step S1 are filled into each template, and the templates are input into the BERT model for mask training. When predicting the semantic label at the [MASK] position in the template, BERT determines whether the causal sentence belongs to the factual or counterfactual type based on the causal knowledge sentence information of the template, thereby improving the causal relationship discrimination effect. The factual causal templates are as follows: [CLS] [ET]quake [ / ET] According to the US Geological Survey, the quake hit at a depth of 10 kilometers in the Northern Province of Aceh. [SEP] [ES] earthquake [ / ES]According to the US Geological Survey, the earthquake struck at a depth of 10 kilometers in the Northern Province of Aceh. [MASK] Cause: The earthquake caused widespread damage to buildings and infrastructure. Effect: The earthquake resulted in injuries and loss of life in the affected areas. [SEP] (Several similar event lines omitted) In the input template, features directly related to the target event include the semantic representation of the event words, the contextual features of the sentence containing the event, and the global semantic representation corresponding to [CLS]. These features are fused to obtain a comprehensive semantic representation of the target event, satisfying the following relation:
[0059] in, For the first The global semantic features corresponding to the [CLS] of each text target event, For the target event Features For the target event In the sentence Features in , For learnable parameter matrix, The characteristics of the target event after fusion.
[0060] To characterize the main causal attributes inherent in similar events, by calculating and The semantic similarity with similar sentences is used to measure their semantic closeness, and causal knowledge features are then weighted and fused accordingly. Subsequently, the fused causal knowledge features are jointly integrated with event features, sentence context features, and causal state features of similar events to generate a comprehensive table of similar events, satisfying the following relation:
[0061]
[0062]
[0063]
[0064] in, These are characteristics of causal or result sentences. For the first Similar events Sentence features, The similarity between sentences containing causal or result information and similar sentences. and The learnable parameter matrix; The similarity weight for the cause or result clause; As a characteristic of causal knowledge, For the first Similar events Event characteristics, causal state feature, Features of similar events after fusion.
[0065] Preferably, step S3 includes: Let the text sequence be The text is then fed into the pre-trained language model BERT to obtain the semantic representations of each target event in the global context. , and The final text target event node features are obtained by fusion through a feedforward network. .
[0066] A local subgraph is constructed, centered on the target event node and connecting its n similar event neighbors. A graph attention network is used to aggregate neighbor features and update node representations. Then, binary classification is performed on the target event node to determine its probability score indicating a causal relationship within the text. A probability threshold of 0.4 is set. When the predicted probability is greater than or equal to this threshold, the event is classified as a "core event"; otherwise, it is classified as a "background event," satisfying the following relationship:
[0067]
[0068]
[0069] in For learnable parameter matrix, For learnable attention vectors, For the target event to the first Attention weights for similar events, To integrate the characteristics of the target event after fusing similar events, and These are the classification weight vector and the classification bias term, respectively. This is the predicted probability that the target event belongs to the "core event".
[0070] Specifically, in the given text, core events include "quake," "collapsed," "damaged," and "fellonto," which directly describe the occurrence of the earthquake, the damage it caused, and the injuries sustained. These are important events that may constitute a causal chain. Events such as "adding" and "evacuate," however, are only used to supplement the narrative or describe changes in context and do not constitute key nodes in the causal chain; therefore, they are considered background events. Core events often play the role of cause or effect in causal relationships, while background events only provide contextual information and do not participate in causal inference. In this step, each event obtains a semantic representation using the pre-trained language model BERT, and feature aggregation is performed in the local subgraph using a graph attention network. Finally, a binary classification model is used to determine whether it is a core event or a background event.
[0071] Preferably, step S4 includes: An event sequence is constructed by sequentially connecting core event nodes and background event nodes according to the original text order. The features of the background events and core events are then linearly mapped and split into two attention heads. Dot-product attention and additive attention mechanisms are used to calculate the attention weights between the background events and each core event. Based on these attention weights, the core event with the highest weight is selected and connected to its corresponding background event. Simultaneously, fully connected edges are constructed between the core event nodes, resulting in a fact heterogeneous graph. The counterfactual heterogeneous graph directly reuses the topology of the fact heterogeneous graph, replacing only the node features. The dot-product attention and additive attention mechanisms satisfy the following relationship:
[0072]
[0073]
[0074] in, Indicates background events eigenvectors, Indicates the core event eigenvectors; , These represent the background event query mapping matrices in the first and second attention heads, respectively. , These represent the background event key mapping matrices in the first and second attention heads, respectively. It is a bias term in the additive attention mechanism; Indicates the first attention-grabbing event in the background. With core events Attention weights; This indicates the second attention-grabbing event in the background. With core events Compatibility score between them; This represents the attention weight of the second attention head.
[0075] Specifically, in this embodiment, based on the event classification results obtained in step S3, events in the text are constructed into an event sequence according to their order of appearance. "quake", "collapsed", and "damaged" are core events, while "adding" and "evacuate" are background events. In step S4, two attention heads are input for each background event. The attention weights between the background event and each core event are calculated using scaled dot product attention and additive attention. The core event with the highest attention is then connected to the background event. Simultaneously, a core event subgraph is constructed using a fully connected approach for all core event nodes, forming the topology of the fact heterogeneous graph. The antifactual heterogeneous graph reuses this topology, replacing only the node features.
[0076] Preferably, step S5 includes: A graph attention mechanism is employed to fuse node features between background events and between background events and core events in the fact graph and counterfactual graph. The causal weights between core events are calculated using the attention mechanism, and the causal scores from the counterfactual causal graph are introduced into the fact graph to adjust and penalize the attention weights between core events. This ensures that attention is more focused on neighbor connections with genuine causal relationships, satisfying the following relation:
[0077]
[0078]
[0079]
[0080]
[0081] in This indicates counterfactual punishment gate control. and This represents the attention score between core event pairs; Indicates the core event and Standardized attention weights between them; This represents the standardized attention weights after adjusting for counterfactual penalties; , Representing nodes respectively exist Layered fact graph and counterfactual graph feature representation, Represents the learnable weight matrix; This indicates that the features of the current layer are orthogonally projected onto the counterfactual graph to remove counterfactual interference components.
[0082] Specifically, in this embodiment, for core event nodes, semantic information is aggregated from their neighboring core event nodes using a graph attention mechanism. Simultaneously, a penalty gating γ is constructed using the attention scores in the corresponding counterfactual graph, ensuring that only neighbor connections more relevant to the true causal structure are retained in the fact graph. After attention aggregation, orthogonal projection along the counterfactual direction is used to remove interfering features that may be introduced by common background or spurious correlations, thereby obtaining an updated node representation that is more consistent with the causal relationship.
[0083] Preferably, in step S3, the probability of whether a causal relationship exists in the text is estimated through feature representation learning; in step S5, by minimizing the similarity between the node features of the fact graph and the counterfactual graph, the two are made as independent as possible in terms of information, thereby eliminating non-causal common noise, and determining whether a causal relationship exists on the finally constructed event pairs, satisfying the following relationship:
[0084]
[0085]
[0086]
[0087]
[0088]
[0089] in This represents the cross-entropy loss during mask training; Cross-entropy loss represents the initial prediction of whether there is a causal relationship between events in the text. This indicates the loss of similarity between factual and counterfactual features; This indicates the causal probability between pairs of events. The cross-entropy loss represents the final prediction of whether there is a causal relationship between event pairs.
Claims
1. A method for causal graph optimization and inference based on counterfactual reasoning, characterized in that, The causal inference method includes the following steps: S1: Given a target event and its text, retrieve events similar to the target event from an external knowledge base, extract keywords using a large language model (LLM) and generate similar sentences consistent with the context of the target event; then, recall and filter relevant causal knowledge, generate causal knowledge sentences based on keywords, and perform counterfactual reasoning perturbation on them to generate counterfactual causal sentences; S2: Based on the causal knowledge sentences obtained in step S1, construct factual causal templates and counterfactual causal templates, and train BERT through masking to automatically determine the type of input template; for the target event, extract its event-level features, context features of the sentence in which it is located, and global features of the whole text, and fuse them to obtain a comprehensive semantic representation of the target event; for similar events, based on the extracted event features and sentence features, introduce the corresponding causal knowledge features and masked state features, and fuse them through similarity weighting to generate causal enhanced representations of similar events, thereby forming factual and counterfactual causal node representations; S3: Based on the causal nodes obtained in step S2, establish connections between the target event and similar events, and fuse features through a graph attention network; classify the target events, determine whether they have a causal relationship, and label them as "core events" or "background events"; S4: Based on the core events and background events in step S3, dynamically construct a heterogeneous graph structure; connect the core events and background events in text order, divide the background events into two parts, and establish weighted connections with the core events through dot product attention and additive attention mechanisms respectively; the core events are connected in a fully connected manner; the counterfactual heterogeneous graph directly reuses the topological structure of the factual heterogeneous graph, only replacing the node features; S5: On the heterogeneous graph constructed in step S4, a graph attention mechanism is used to fuse features between background events and between background events and core events; the causal correlation strength between core events is calculated through the attention mechanism, the causal score in the counterfactual causal graph is introduced into the fact graph, and the attention weights between core events and the penalty are adjusted, while the features between core events are fused; counterfactual orthogonal projection is applied to the node features of the fact graph to remove noise in the counterfactual direction; finally, a cosine similarity loss function is introduced to separate the node representations of the fact graph and the counterfactual graph in the feature space, and event pairs are constructed based on the optimized node representations for discrimination, and the judgment result of whether there is a causal relationship between the event pairs is output.
2. The causal inference method of claim 1, wherein, In step S1, on the basis of a given target event and its text, events similar in semantics to the target event are recalled from an external knowledge base ConceptNet ; subject information, including subject words or subject sentences, in the target text is extracted using a large language model (LLM); Based on this topic information, LLM is used in conjunction with the context of the target event to embed similar events into the target event sentence, generating semantically consistent and context-aware similar sentences; Simultaneously, causal knowledge similar to the target event is retrieved from the external knowledge base ConceptNet. LLM is used to filter relevant entries, and causal knowledge sentences associated with the target event are generated by matching extracted keywords. Based on this, the following counterfactual reasoning rules are applied to slightly perturb the causal knowledge sentences, satisfying the following rules: (1) Switching of causal subjects: swapping the subjects of cause and effect in a causal relationship while keeping other contents consistent; (2) Introduction of negative structure: Insert the smallest negative or restrictive element into the same sentence structure to destroy the necessity or sufficiency of the causal relationship; (3) Weakening of causal mechanism: retain the causal subject and event, weaken the "causal mechanism term", and reduce the causal relationship to a co-occurrence or correlation description; By applying the above method, counterfactual causal knowledge sentences that are consistent with the context of the target event are generated.
3. The causal inference method of claim 1, wherein, In step S2, the causal template is: in Indicates the target event, The sentence containing the target event; Indicates the first A similar event, Indicates the first Similar sentences about similar events These sentences respectively represent causal knowledge sentences; The counterfactual causality template will be the first The cause item of the causal knowledge sentence and results Replace them with counterfactual causal sentences after counterfactual reasoning perturbation; the mask training involves inputting the causal template into BERT and predicting... The semantic category label of the location is used to determine whether the causal knowledge sentence belongs to the fact type "FACT" or the counterfactual type "CF". The target event features of the input template are fused to satisfy the following relation: in, For the first [CLS] features of a text target event For the target event Features For the target event In the sentence Features in , For learnable parameter matrix, The characteristics of the target event after fusion; The similarity features of the input template are fused based on the similarity between causal knowledge sentences and similar sentences, satisfying the following relation: in, These are characteristics of causal or result sentences. For the first Similar events Sentence features, The similarity between sentences containing causal or result information and similar sentences. and The learnable parameter matrix; The similarity weight for the cause or result clause; As a characteristic of causal knowledge, For the first Similar events Event characteristics, causal state feature, Features of similar events after fusion.
4. The causal inference method according to claim 1, characterized in that, Step S3 includes: The text sequence is Input into the pre-trained language model BERT to obtain semantic representations of each target event of the text in a global context And The final text target event node features are obtained by fusion through the feedforward network ; A local subgraph is constructed, centered on the target event node and connecting its n similar event neighbors. A graph attention network is used to aggregate neighbor features and update node representations. Then, binary classification is performed on the target event node to determine its probability score indicating a causal relationship within the text. A probability threshold of 0.4 is set. When the predicted probability is greater than or equal to this threshold, the event is classified as a "core event"; otherwise, it is classified as a "background event," satisfying the following relationship: in For learnable parameter matrix, For learnable attention vectors, For the target event to the first Attention weights for similar events, To integrate the characteristics of the target event after fusing similar events, and These are the classification weight vector and the classification bias term, respectively. This is the predicted probability that the target event belongs to the "core event".
5. The causal inference method according to claim 1, characterized in that, Step S4 includes: By sequentially connecting the core event nodes and background event nodes in step S3 according to the original text order, an event sequence is constructed. The features of the background events and core events are linearly mapped and then split into two attention heads. Dot product attention and additive attention mechanisms are used to calculate the attention weights between the background events and each core event. Based on these attention weights, the core event with the highest weight is selected and connected to its corresponding background event. Simultaneously, fully connected edges are constructed between the core event nodes, thus obtaining a fact heterogeneous graph. The antifactual heterogeneous graph directly reuses the topology of the fact heterogeneous graph, only replacing the node features. The dot product attention mechanism and the additive attention mechanism satisfy the following relationship: in, Indicates background events eigenvectors, Indicates the core event eigenvectors; , These represent the background event query mapping matrices in the first and second attention heads, respectively. , These represent the background event key mapping matrices in the first and second attention heads, respectively. It is a bias term in the additive attention mechanism; Indicates the first attention-grabbing event in the background. With core events Attention weights; This indicates the second attention-grabbing event in the background. With core events Compatibility score between them; This represents the attention weight of the second attention head.
6. The heterogeneous graph of claim 5, wherein, Step S5 includes: A graph attention mechanism is employed to fuse node features between background events and between background events and core events in the fact graph and counterfactual graph. The causal weights between core events are calculated using the attention mechanism, and the causal scores from the counterfactual causal graph are introduced into the fact graph to adjust and penalize the attention weights between core events. This ensures that attention is more focused on neighbor connections with genuine causal relationships, satisfying the following relation: in This indicates counterfactual punishment gate control. and This represents the attention score between core event pairs; Indicates the core event and Standardized attention weights between them; This represents the standardized attention weights after adjusting for counterfactual penalties; , Representing nodes respectively exist Layered fact graph and counterfactual graph feature representation, Represents the learnable weight matrix; This indicates that the features of the current layer are orthogonally projected onto the counterfactual graph to remove counterfactual interference components.
7. The causal inference method of claim 1, wherein, In step S3, the probability of whether a causal relationship exists in the text is estimated through feature representation learning; while in step S5, the similarity between the node features of the fact graph and the counterfactual graph is minimized to make them as independent as possible in terms of information, thereby eliminating non-causal common noise, and the existence of a causal relationship is determined on the finally constructed event pairs, satisfying the following relationship: wherein represents a cross-entropy loss of mask training; represents a cross-entropy loss of preliminary prediction on whether there is a causal relationship between events in the text; represents a fact and counter-fact feature similarity loss; represents a causal probability between event pairs, represents a cross-entropy loss of final prediction on whether there is a causal relationship between event pairs.