Medical question and answer method and system based on causal diagram and counterfactual reasoning distillation
Patent Information
- Application Number
- CN202611546143.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-08
- Publication Date
- 2026-11-03
AI Technical Summary
Existing medical question-answering systems lack generalization ability when faced with novel cases, lack explicit modeling and verification of the causal relationship between symptoms, diseases and treatments, make inference conclusions difficult to interpret, and incur significant computational costs.
By constructing a directed acyclic causal graph, a pre-trained language model is used to identify medical entities and their causal dependencies. Combined with dual encoders to retrieve knowledge-enhanced documents, counterfactual questions are generated and causal reasoning is performed. Backdoor adjustments and causal consistency verification are introduced to generate a causal reasoning report.
It reduces the computational overhead of system deployment, improves the ability to identify novel cases and the accuracy of causal reasoning, and enhances the interpretability of inference conclusions for novel cases.
Smart Images

Figure CN123033766A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence, in particular to a medical question answering method and system based on causal graphs and counterfactual reasoning distillation. BACKGROUND
[0002] Medical Question Answering (Medical QA) is one of the core applications of natural language processing in the medical and health field, aiming to accurately answer clinical questions based on medical knowledge. With the development of deep learning technology, question and answer systems based on pre-trained language models have made significant progress in medical benchmark tests (such as MedQA-USMLE). However, medical reasoning not only involves the retrieval and matching of factual knowledge, but also requires a deep understanding of the causal dependence relationship between symptoms, diseases and treatments. For example, to determine whether a certain treatment is effective, not only does it need to identify the association between symptoms and diseases, but it also needs to understand the causal mechanism of the intervention on disease progression. In recent years, large language models (LLM) have shown strong knowledge understanding and reasoning ability, but their large parameter size and high computational overhead limit their practical deployment in clinical scenarios. Knowledge distillation (Knowledge Distillation) technology has emerged, which migrates the reasoning ability of large models to smaller language models (Small Language Model, SLM), reducing deployment costs while preserving reasoning quality.
[0003] Current knowledge distillation methods for medical question answering can be roughly divided into the following categories: the first category is the standard distillation scheme based on chain-of-thought (CoT), which uses a large language model to generate a step-by-step reasoning chain for the questions in the training set, and then uses the "question-reasoning chain-answer" triplet as a supervision signal to fine-tune the small model. The second category is the distillation scheme based on counterfactual data augmentation, the counterfactual distillation (Counterfactual Distillation) framework uses a large language model to automatically generate counterfactual samples, i.e. modifying the key conditions in the original question to generate a reasoning chain again, so that the small model learns more robust reasoning patterns in the process of comparing the original sample and the counterfactual sample. The third category is an analysis scheme based on causal reasoning evaluation, by constructing the CLadder benchmark dataset, the causal reasoning ability of large language models is systematically evaluated, it is found that even models with large parameter sizes have obvious shortcomings in questions involving causal intervention and counterfactual queries, revealing the limitations of existing language models in causal reasoning.
[0004] However, existing distillation methods primarily rely on correlation patterns rather than causal structures. When faced with novel case combinations or scenarios requiring causal intervention prediction, models based solely on correlation learning lack generalization ability. Medical knowledge contains rich causal chains (e.g., "infection → inflammation → fever"), but current methods do not automatically construct structured causal graph representations from text, preventing small models from performing multi-step reasoning along causal paths. Although counterfactual distillation introduces counterfactual data augmentation, its goal is to improve the robustness of reasoning rather than test the model's understanding of causal mechanisms. When causal contradictions appear in the reasoning chain, there is a lack of automatic detection and correction methods. Furthermore, the core of clinical decision-making is predicting the effect of specific treatment interventions on disease progression, but current methods cannot effectively answer counterfactual intervention questions such as "how would the condition change if option A were used instead of option B?" The reasoning ability obtained by small models after distillation lacks interpretability guarantees.
[0005] Therefore, traditional medical question-and-answer knowledge distillation methods, which only transmit correlation-based reasoning patterns and lack explicit modeling and verification of causal relationships between symptoms, diseases, and treatments, often suffer from insufficient generalization ability when faced with novel cases, and the reasoning conclusions are difficult to trace and interpret. Summary of the Invention
[0006] Therefore, in order to solve the above-mentioned technical problems, a medical question-answering method and system based on causal graphs and counterfactual reasoning distillation is provided, which can reduce deployment computational overhead and improve the generalization robustness to novel cases and the interpretability of reasoning conclusions.
[0007] A medical question-answering method based on causal graphs and counterfactual reasoning distillation, the method comprising:
[0008] Obtain medical question text, use a pre-trained language model to perform medical entity recognition on the medical question text, extract medical entities and their type labels, calculate the causal dependency score between the medical entities, and construct a directed acyclic causal graph based on the causal dependency score.
[0009] The candidate documents corresponding to the medical question text are retrieved from an external medical knowledge base using a dual encoder, and the candidate documents are reordered to obtain knowledge-enhanced documents.
[0010] Value intervention is performed on key nodes in the directed acyclic causal graph to generate counterfactual questions. The teacher model is then used in conjunction with the knowledge-enhanced document to generate the counterfactual reasoning chain and counterfactual answer corresponding to the counterfactual questions. The joint distillation loss is calculated based on the original samples and counterfactual samples to update the parameters of the student model, resulting in a student model with causal reasoning ability.
[0011] Based on the directed acyclic causal graph, the causal effect of the treatment plan is estimated by backdoor adjustment to obtain the average intervention effect and conditional average intervention effect of the treatment plan.
[0012] The generated inference chain is subjected to causal consistency verification. If the verification fails, an inconsistency signal is fed back to the link that generated the inference chain, and the inference chain is regenerated or adjusted until the causal consistency verification is passed. Then, the causal relationship in the verified inference chain is extracted to obtain the causal mechanism description and causal strength index.
[0013] Based on the average intervention effect and the conditional average intervention effect, the candidate treatment options are prioritized to generate a final answer and treatment recommendations. The reasoning chain verified by causal consistency, the description of the causal mechanism, and the causal strength index are integrated to generate a causal reasoning report.
[0014] In one embodiment, medical question text is acquired, a pre-trained language model is used to perform medical entity recognition on the medical question text, medical entities and their type labels are extracted, and causal dependency scores between the medical entities are calculated. A directed acyclic causal graph is constructed based on the causal dependency scores, including:
[0015] The process involves acquiring medical question text, performing word segmentation and standardization on the medical question text, mapping the processed text to standardized medical terms, determining the question type, and generating a structured text representation.
[0016] The structured text representation is encoded using a pre-trained language model to obtain a contextual semantic representation, which is then input into a conditional random field sequence labeling classifier to identify medical entities in the text and assign type labels to each medical entity.
[0017] For each medical entity, a causal dependency score from the first entity to the second entity is calculated using a causal dependency score network. The causal dependency score is used to characterize the probability that one medical entity has a causal influence on another medical entity. The positive causal dependency score of the first entity to the second entity and the negative causal dependency score of the second entity to the first entity are calculated respectively to distinguish the direction of causal association.
[0018] All medical entities are treated as nodes. Directed edges are established between entity pairs whose causal dependency scores are greater than a preset threshold to construct an adjacency matrix, and an acyclic constraint is imposed on the adjacency matrix. During training, the acyclic constraint is transformed into a penalty term and added to the loss function using the augmented Lagrange method. The penalty term is constructed based on the square of the difference between the matrix exponent trace of the adjacency matrix and the number of entities. Finally, a directed acyclic causal graph is output.
[0019] In one embodiment, candidate documents corresponding to the medical question text are retrieved from an external medical knowledge base using a dual encoder, and the candidate documents are reordered to obtain knowledge-enhanced documents, including:
[0020] The query encoder in the dual encoder is used to encode the medical question text, extract semantic features, and perform pooling to obtain a query vector; the context encoder in the dual encoder is used to encode candidate documents in an external medical knowledge base, extract semantic features, and perform pooling to obtain a document vector.
[0021] The inner product is used to calculate the retrieval relevance score between the query vector and the document vector, and a set of candidate documents is selected from the external medical knowledge base based on the retrieval relevance score.
[0022] A cross-attention reorderer is used to calculate the interaction representation between the medical question text and each candidate document through a multi-head cross-attention function, capturing the semantic association between each word in the query and each word in the document. The cross-attention output is then transformed nonlinearly by a feedforward network and the reordering score is obtained through linear projection and activation function.
[0023] The candidate document set is sorted according to the re-sorting score, and knowledge-enhanced documents are selected based on the sorted candidate document set.
[0024] In one embodiment, value intervention is performed based on key nodes in the directed acyclic causal graph to generate counterfactual questions. The teacher model, combined with the knowledge-enhanced document, generates the counterfactual reasoning chain and counterfactual answer corresponding to the counterfactual questions. A joint distillation loss is calculated based on the original samples and counterfactual samples to update the parameters of the student model, resulting in a student model with causal reasoning capabilities, including:
[0025] Select the causal path corresponding to the medical question text from the directed acyclic causal graph, perform value intervention operations on the key nodes in the causal path, and generate a counterfactual question;
[0026] The counterfactual question and the knowledge-enhanced document are input into the teacher model. The teacher model, in combination with the knowledge-enhanced document, generates the counterfactual reasoning chain and counterfactual answer corresponding to the counterfactual question. The teacher model also generates the original reasoning chain and original answer for the original question.
[0027] The counterfactual reasoning chain and the counterfactual answer, along with the original reasoning chain and the original answer, are used together as distillation supervision signals. Based on the original samples and counterfactual samples, the original reasoning chain loss, the original answer loss, the counterfactual reasoning chain loss, and the counterfactual answer loss are calculated respectively to obtain the joint distillation loss.
[0028] The gradient signal of the combined distillation loss is calculated, the gradient of each parameter of the student model is calculated through backpropagation, and the parameters of the student model are updated using the gradient descent algorithm to obtain a student model with causal reasoning ability.
[0029] In one embodiment, based on the directed acyclic causal graph, a backdoor adjustment is used to estimate the causal effect of the treatment plan, obtaining the average intervention effect and conditional average intervention effect of the treatment plan, including:
[0030] Based on the directed acyclic causal graph, intervention variables that simultaneously point to treatment plan nodes and outcome variables that point to disease progression nodes are identified as confounding variables, forming a candidate confounding variable set;
[0031] Based on the directed acyclic causal graph, all backdoor paths between treatment plans and disease progression are identified, and a backdoor adjustment set is obtained from the candidate confounding variable set according to the backdoor criterion.
[0032] For each value of the confounding variable in the backdoor adjustment set, the conditional probability of the intervention variable and the outcome variable is calculated. The conditional probabilities of each layer are weighted and summed according to the marginal distribution of the confounding variable to obtain the distribution of disease progression after intervention.
[0033] Based on the distribution of disease progression after the intervention, the difference between the expected value of disease progression with treatment and the expected value of disease progression without treatment is calculated as the average intervention effect; for patient subgroups with target patient feature vectors, the difference between the expected value of disease progression with treatment and the expected value of disease progression without treatment is calculated as the conditional average intervention effect.
[0034] In one embodiment, the generated inference chain is subjected to causal consistency verification. If the verification fails, an inconsistency signal is fed back to the link that generated the inference chain, and the inference chain is regenerated or adjusted until the causal consistency verification passes. After that, the causal relationships in the verified inference chain are extracted to obtain a causal mechanism description and a causal strength index, including:
[0035] The reasoning chain is structured and analyzed, and the reasoning chain is divided into various reasoning steps. The causal triples in each reasoning step are identified and then summarized to obtain a set of causal triples.
[0036] The inference chain is subjected to transit consistency, directional consistency, and evidentiary consistency checks respectively. If all three checks pass, the causal consistency verification is deemed successful; otherwise, the verification is deemed unsuccessful, and an inconsistency signal is generated.
[0037] The inconsistency signal is added as an additional constraint to the input of the student model. The student model regenerates the inference chain and performs causal consistency verification again, forming an iterative correction loop until the causal consistency verification is passed.
[0038] The causal mechanism is extracted from the inference chain that has passed the causal consistency verification, the described causal action path is extracted, and the causal action path is summarized and integrated to generate a structured causal mechanism description.
[0039] Based on the causal relationship description of each reasoning step in the reasoning chain, and combining the average intervention effect and the conditional average intervention effect, a causal strength index is calculated.
[0040] In one embodiment, the candidate treatment options are prioritized based on the average intervention effect and the conditional average intervention effect to generate a final answer and treatment recommendation, including:
[0041] Extract all candidate treatment plan nodes related to the current disease from the directed acyclic causal graph, and traverse the treatment plan nodes pointing to the disease progression nodes in the directed acyclic causal graph.
[0042] The treatment plan nodes are combined with the treatment plans in the knowledge-enhanced document to supplement the directed acyclic causal graph, forming a candidate treatment plan list;
[0043] The candidate treatment options in the candidate treatment option list are ranked as a whole based on the average intervention effect; for patient subgroups with target feature vectors, the ranking is personalized based on the conditional average intervention effect.
[0044] A multi-objective ranking is generated based on the results of the overall ranking and the personalized ranking. The candidate treatment plan ranked first in the multi-objective ranking is selected as the recommended treatment plan. Combined with the reasoning chain that has been verified by causal consistency, the final answer and treatment suggestions are generated.
[0045] In one embodiment, the reasoning chain verified for causal consistency, the description of the causal mechanism, and the causal strength index are integrated to generate a causal reasoning report, including:
[0046] Construct a causal reasoning report template, and fill the knowledge enhancement document, directed acyclic causal graph, average intervention effect and conditional average intervention effect, causal mechanism description and causal strength index, final answer and treatment suggestions into the structured fields corresponding to the causal reasoning report template to generate a causal reasoning report;
[0047] The causal reasoning report will be output in a structured document format.
[0048] A medical question-answering system based on causal graphs and counterfactual reasoning distillation, the system comprising:
[0049] The causal graph construction module is used to acquire medical question text, perform medical entity recognition on the medical question text using a pre-trained language model, extract medical entities and their type labels, calculate the causal dependency score between the medical entities, and construct a directed acyclic causal graph based on the causal dependency score.
[0050] The knowledge enhancement module is used to retrieve candidate documents corresponding to the medical question text from an external medical knowledge base through dual encoders, and to reorder the candidate documents to obtain knowledge-enhanced documents;
[0051] The counterfact generation module is used to intervene in the key nodes of the directed acyclic causal graph, generate counterfactual questions, and use the teacher model in combination with the knowledge-enhanced document to generate the counterfactual reasoning chain and counterfactual answer corresponding to the counterfactual questions; calculate the joint distillation loss based on the original sample and the counterfactual sample, update the parameters of the student model, and obtain a student model with causal reasoning ability.
[0052] The causal intervention reasoning module is used to estimate the causal effect of the treatment plan based on the directed acyclic causal graph and through backdoor adjustment, so as to obtain the average intervention effect and conditional average intervention effect of the treatment plan.
[0053] The causal consistency verification and mechanism extraction module is used to verify the causal consistency of the generated inference chain. If the verification fails, an inconsistency signal is fed back to the link that generated the inference chain, and the inference chain is regenerated or adjusted until the causal consistency verification passes. Then, the mechanism is extracted from the causal relationship in the verified inference chain to obtain the causal mechanism description and causal strength index.
[0054] The report output module is used to prioritize each candidate treatment plan based on the average intervention effect and the conditional average intervention effect, generate a final answer and treatment recommendations, and integrate the reasoning chain verified by causal consistency, the description of the causal mechanism, and the causal strength index to generate a causal reasoning report.
[0055] The aforementioned medical question-answering method and system based on causal graphs and counterfactual reasoning distillation can explicitly model the true causal dependencies between symptoms, diseases, and treatments by extracting medical entities from medical question texts and constructing a directed acyclic causal graph. Knowledge-enhanced documents obtained through dual encoder retrieval and reordering provide reliable external medical knowledge support for subsequent inference chain generation and logical verification. Counterfactual samples are generated by value intervention based on key nodes of the causal graph, and combined with the original samples to construct a joint distillation loss to train student models. This allows small-scale student models to learn causal and counterfactual reasoning capabilities without requiring large-scale online inference models, reducing the computational cost of system deployment. Adjusting the average intervention effect and conditional average intervention effect of estimated treatment plans through backdoors can eliminate the interference of confounding variables. A causal consistency closed-loop verification mechanism is introduced to perform multi-dimensional causal logic checks on the inference chain, automatically feeding back and regenerating when inferences are contradictory, ensuring the logical self-consistency of the inference chain. Furthermore, causal mechanism descriptions and causal strength indicators are extracted, and finally, treatment plans are ranked by combining intervention effects, integrating multiple types of information to output a causal reasoning report. This can reduce deployment computational costs and improve generalization robustness to novel cases and the interpretability of inference conclusions. Attached Figure Description
[0056] Figure 1 This is an application environment diagram of a medical question-answering method based on causal graphs and counterfactual reasoning distillation in one embodiment;
[0057] Figure 2 This is a flowchart illustrating a medical question-answering method based on causal graphs and counterfactual reasoning distillation in one embodiment.
[0058] Figure 3 This is a block diagram of a medical question-answering system based on causal graphs and counterfactual reasoning distillation in one embodiment;
[0059] Figure 4 This is a schematic diagram of the overall architecture and core data flow of a medical question-answering method and system based on causal graphs and counterfactual reasoning distillation in one embodiment;
[0060] Figure 5 This is a schematic diagram illustrating the internal processing flow and interaction relationships between key components of the counterfactual generation and causal intervention reasoning module in one embodiment.
[0061] Figure 6 This is a complete interactive timing diagram of a medical question-answering method based on causal graphs and counterfactual reasoning distillation in one embodiment during the training and inference phases.
[0062] Figure 7 This is a flowchart of the causal reasoning distillation deployment for intelligent assisted diagnosis in a tertiary hospital, as shown in one embodiment.
[0063] Figure 8This is a flowchart of an edge-end causal reasoning question-answering service for primary healthcare institutions in one embodiment.
[0064] Figure 9 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0065] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0066] The medical question-answering method based on causal graphs and counterfactual reasoning distillation provided in this application can be applied to, for example... Figure 1 The application environment shown. For example... Figure 1 As shown, the application environment includes computer device 110. Computer device 110 can acquire medical question text, perform medical entity recognition on the medical question text using a pre-trained language model, extract medical entities and their type labels, and calculate causal dependency scores between medical entities. Based on the causal dependency scores, a directed acyclic causal graph is constructed. Computer device 110 can retrieve candidate documents corresponding to the medical question text from an external medical knowledge base using a dual encoder, and reorder the candidate documents to obtain knowledge-enhanced documents. Computer device 110 can perform value intervention based on key nodes in the directed acyclic causal graph to generate counterfactual questions, and use the teacher model combined with the knowledge-enhanced documents to generate counterfactual reasoning chains and counterfactual answers corresponding to the counterfactual questions. Based on the original samples and counterfactual samples, a joint distillation loss is calculated, and the parameters of the student model are updated to obtain a student model with causal reasoning capabilities. The model is generated by a computer device 110. Based on a directed acyclic causal graph, the computer device 110 can estimate the causal effect of treatment plans through backdoor adjustments, obtaining the average intervention effect and conditional average intervention effect of the treatment plans. The computer device 110 can perform causal consistency verification on the generated inference chain. If the verification fails, it feeds back an inconsistency signal to the link generating the inference chain, regenerating or adjusting the inference chain until the causal consistency verification passes. Afterward, it extracts the causal relationships in the verified inference chain to obtain a causal mechanism description and a causal strength index. The computer device 110 can prioritize each candidate treatment plan based on the average intervention effect and conditional average intervention effect, generating a final answer and treatment recommendations. It then integrates the causal consistency-verified inference chain, causal mechanism description, and causal strength index to generate a causal inference report. The computer device 110 can be, but is not limited to, various personal computers, laptops, smartphones, robots, drones, tablets, etc.
[0067] In one embodiment, a Causal Reasoning Distillation (CRD) method based on causal graphs and counterfactual reasoning distillation is provided, enabling small-scale language models to acquire causal reasoning capabilities based on knowledge enhancement. Building upon the Knowledge-Enhanced Reasoning Distillation (KARD) framework, CRD systematically injects causal reasoning capabilities into the distillation process, allowing language models with fewer parameters to acquire causal understanding and reasoning capabilities without requiring large-scale online reasoning models. The overall technical solution of CRD consists of three parts: causal graph extraction and knowledge enhancement retrieval, responsible for automatically identifying causal dependencies between entities in medical texts and constructing structured causal graphs, while simultaneously utilizing intensive retrieval and neural reordering to obtain relevant documents supporting causal reasoning from external knowledge bases; counterfactual generation and causal intervention reasoning, responsible for constructing hypothetical scenarios to test and strengthen the model's understanding of causal mechanisms and predicting the intervention effects of specific treatment regimens on disease progression; and causal consistency verification and mechanism extraction, responsible for ensuring the causal logic self-consistency of the reasoning chain and extracting the biological basis of causal relationships to enhance the interpretability of the reasoning. These three parts work together to form a complete technical chain from causal knowledge acquisition and causal reasoning enhancement to causal consistency assurance.
[0068] In one embodiment, such as Figure 2 As shown, a medical question-answering method based on causal graphs and counterfactual reasoning distillation is provided, including the following steps:
[0069] Step 202: Obtain medical question text, use a pre-trained language model to perform medical entity recognition on the medical question text, extract medical entities and their type labels, calculate the causal dependency score between medical entities, and construct a directed acyclic causal graph based on the causal dependency score.
[0070] Computer devices can receive unstructured medical text as input and output a structured directed acyclic graph (DAG), where nodes represent medical entities (symptoms, diseases, treatments, examination indicators, etc.) and directed edges represent causal dependencies between entities. The computer device can first use a pre-trained language model to perform entity recognition on the input text, extracting medical-related entities and their type labels; then, it identifies the direction of causal relationships between entities through a combination of causal pattern matching and semantic reasoning, distinguishing between causal associations and simple correlational associations.
[0071] In one embodiment, a medical question-answering method based on causal graphs and counterfactual reasoning distillation may further include a causal graph extraction process, specifically including: acquiring medical question text; performing word segmentation and standardization on the medical question text; mapping the processed text to standardized medical terms and determining the question type to generate a structured text representation; encoding the structured text representation using a pre-trained language model to obtain a contextual semantic representation; inputting the contextual semantic representation into a conditional random field sequence labeling classifier to identify medical entities in the text; assigning a type label to each medical entity; and for each medical entity, calculating the relationship between the first entity and the second entity through a causal dependency scoring network. The causal dependency score of each medical entity is used to characterize the probability that one medical entity has a causal influence on another medical entity. The positive causal dependency score of the first entity on the second entity and the negative causal dependency score of the second entity on the first entity are calculated to distinguish the direction of causal association. All medical entities are treated as nodes, and directed edges are established between entity pairs with causal dependency scores greater than a preset threshold to construct an adjacency matrix, which is then subject to an acyclic constraint. During training, the acyclic constraint is transformed into a penalty term using the augmented Lagrange method and added to the loss function. The penalty term is constructed based on the square of the difference between the matrix exponent trace of the adjacency matrix and the number of entities. Finally, a directed acyclic causal graph is output.
[0072] Computer equipment can perform word segmentation and text cleaning on the input medical natural language text, mapping colloquial and synonymous expressions into standardized medical terminology. Simultaneously, it parses the input content to determine the question type, such as diagnostic queries, treatment plan consultations, or symptom mechanism analysis, generating a structured text representation suitable for subsequent model input. The medical question text originates from unstructured medical text such as case descriptions input by doctors, examination and test results, and user health consultations.
[0073] Next, the computer device can input the obtained structured text representation into a pre-trained language model. Through multi-layer encoding of the model, the contextual semantic vector corresponding to each character and word is obtained, i.e., the contextual semantic representation. This contextual semantic representation is then input into a Conditional Random Field (CRF) sequence labeling classifier to perform a medical entity recognition task. The CRF sequence labeling classifier outputs sequence labeling results, identifying all medical entities contained in the text and assigning a corresponding type label to each identified medical entity. The type labels for medical entities include, but are not limited to, symptoms, diseases, treatment methods, and examination indicators.
[0074] To distinguish the direction of causal relationships, the computer device can calculate the positive causal dependency score of the first entity acting on the second entity, and the negative causal dependency score of the second entity acting on the first entity. By comparing the two sets of causal dependency scores, the actual direction of the causal relationship between entities can be distinguished, avoiding misjudging undirected statistical correlations as unidirectional causal effects. Next, the computer device can treat all identified medical entities as nodes in a graph structure. For each pair of entities, when the causal dependency score between the entity pair is greater than a preset threshold, a directed edge with the corresponding direction is established between the two entity nodes. The direction of the edge is determined by the positive causal dependency score, thereby constructing the adjacency matrix corresponding to the causal graph. To ensure that the output is a valid directed acyclic graph, an acyclic constraint needs to be applied to the adjacency matrix.
[0075] During model training, the computer can transform the acyclic constraint into a penalty term using the augmented Lagrangian method, and incorporate this penalty term into the overall loss function for iterative model training. The penalty term is constructed based on the squared difference between the matrix trace of the adjacency matrix and the number of entities. This penalty term constraint suppresses causal loops in the graph structure. After multiple rounds of iterative optimization, directed cycles in the graph are eliminated, ultimately outputting a directed acyclic causal graph that satisfies the constraints. In the output directed acyclic causal graph, nodes represent medical entities, and directed edges represent causal dependencies between entities.
[0076] Specifically, for the entity set in the input medical text The goal of causal graph extraction is to learn an adjacency matrix. ,in This indicates the existence of entities To the entity The causal relationship. For each pair of entities This module calculates the causal dependency score: ;in, and Representing entities respectively and The context semantic representation vector, The weight matrix is a learnable matrix. For bias terms, It is the Sigmoid activation function. This represents element-wise multiplication. This represents a vector concatenation operation; the formula for calculating the causal dependency score predicts the probability of causal dependency by comprehensively considering the semantic representations, interaction features, and difference features of the two entities.
[0077] After the adjacency matrix is determined, the computer device may need to ensure the acyclicity constraint of the causal graph. Specifically, a cycle detection algorithm based on topological sorting can be used to check the adjacency matrix. Perform constraint optimization. The acyclicity constraint of the cause-effect graph can be formalized as: ;in, Represents the matrix trace operation. It is the identity matrix. The number of entities is denoted by ; this constraint ensures that the learned causal graph is a directed acyclic graph, avoiding the occurrence of causal loops; during training, this constraint is transformed into a penalty term and added to the loss function through the augmented Lagrangian method.
[0078] Step 204: Retrieve candidate documents corresponding to the medical question text from an external medical knowledge base using a dual encoder, and reorder the candidate documents to obtain knowledge-enhanced documents.
[0079] Computer devices can retrieve documents related to the causal relationship of the current problem from external medical knowledge bases (such as PubMed literature databases and clinical guideline databases), providing external knowledge support for subsequent causal reasoning. Computer devices can employ a dual-encoder intensive retrieval architecture, combined with neural reordering mechanisms, to ensure that the retrieved documents are not only relevant to the problem topic but also contain structured knowledge to support causal reasoning.
[0080] In one embodiment, a medical question-answering method based on causal graphs and counterfactual reasoning distillation may further include a knowledge enhancement and reordering process. The specific process includes: encoding the medical question text using a query encoder in a dual encoder, extracting semantic features and performing pooling to obtain a query vector; encoding candidate documents in an external medical knowledge base using a context encoder in the dual encoder, extracting semantic features and performing pooling to obtain a document vector; calculating the retrieval relevance score between the query vector and the document vector using the inner product, and selecting a set of candidate documents from the external medical knowledge base based on the retrieval relevance score; using a cross-attention reorderer to calculate the interaction representation between the medical question text and each candidate document through a multi-head cross-attention function, capturing the semantic association between each word in the query and each word in the document, and then transforming the cross-attention output nonlinearly through a feedforward network, followed by linear projection and activation function to obtain a reordering score; sorting the candidate document set according to the reordering score, and selecting knowledge-enhanced documents based on the sorted candidate document set.
[0081] The computer device can employ a dual-encoder architecture for document retrieval, comprising a query encoder and a context encoder. The device can call the query encoder to encode medical question text, extract semantic features, and perform pooling on the encoded output features to aggregate a fixed-dimensional query vector. Simultaneously, the device can use the context encoder to encode documents within an external medical knowledge base, extracting semantic features and similarly pooling them to obtain document vectors for each document. This external medical knowledge base can be a PubMed database, clinical guideline database, or other medical professional knowledge bases. Document vectors from documents in this knowledge base can be pre-encoded offline and stored to build a vector index library. During the online inference phase, it is unnecessary to repeatedly encode all documents, thus improving retrieval efficiency.
[0082] Next, the computer device can calculate the inner product of the query vector and each document vector in the vector index, and use the result of the inner product as the retrieval relevance score. The retrieval relevance score represents the degree of semantic matching between the medical question text and the knowledge base documents. Then, the knowledge base documents are sorted in descending order of retrieval relevance score, and several documents with the highest scores are selected to form a candidate document set.
[0083] The computer device can input the obtained candidate document set into a cross-attention re-ranking unit. The re-ranking unit uses a multi-head cross-attention function to calculate the interaction representation between the medical question text and each candidate document, capturing the fine-grained semantic associations between each word in the query and each word in the candidate documents, thus obtaining deep query-document interaction features. The computer device can then feed the output of the multi-head cross-attention function into a feedforward network for nonlinear transformation, followed by linear projection and activation function processing, outputting a re-ranking score for each candidate document. The candidate document set is then sorted in descending order based on the re-ranking scores, and the top-ranked documents are selected as knowledge-enhancing documents.
[0084] Specifically, regarding the input problem The dense retrieval system first uses a query encoder. The problem is encoded into a dense vector representation, and then passed through a context encoder. The documents in the knowledge base are encoded into vectors, and the retrieval relevance score is calculated using the inner product: ;in, This represents the vector dot product operation. The search engine returns the most similar documents from the knowledge base. The document was selected as a candidate set.
[0085] After retrieval, the neural reordering engine performs fine-grained ranking of candidate documents; the reordering engine employs a cross-attention mechanism to model the deep semantic interaction between the query and each candidate document. For the query vector... and candidate document embedding set The reordering score is calculated as follows: ;in, For multi-head cross-attention function, For the projection matrix, For learnable rating vectors, These are bias terms; after reordering, the one with the highest score is selected. document As input for knowledge enhancement, the retrieved documents will be compared with the structured causal graph output by the causal graph extraction module. Figure 1 It is then fed into subsequent counterfactual generation and causal intervention reasoning.
[0086] Step 206: Value intervention is performed on key nodes in the directed acyclic causal graph to generate counterfactual questions. The teacher model is then used in conjunction with knowledge-enhanced documents to generate the counterfactual reasoning chain and counterfactual answer corresponding to the counterfactual questions. The joint distillation loss is calculated based on the original samples and counterfactual samples, and the parameters of the student model are updated to obtain a student model with causal reasoning ability.
[0087] Computer devices can automatically generate counterfactual hypothetical scenarios based on a pre-constructed causal graph by performing value intervention on key nodes (such as treatment methods or disease states) in the causal graph.
[0088] In one embodiment, a medical question-answering method based on causal graphs and counterfactual reasoning distillation may further include a counterfactual generation and joint distillation training process. The specific process includes: selecting a causal path corresponding to the medical question text from a directed acyclic causal graph; performing value intervention operations on key nodes in the causal path to generate a counterfactual question; inputting the counterfactual question and knowledge-enhanced document into a teacher model; generating a counterfactual reasoning chain and counterfactual answer corresponding to the counterfactual question through the teacher model combined with the knowledge-enhanced document; generating an original reasoning chain and original answer for the original question through the teacher model; using the counterfactual reasoning chain and counterfactual answer, and the original reasoning chain and original answer together as distillation supervision signals; calculating the original reasoning chain loss, original answer loss, counterfactual reasoning chain loss, and counterfactual answer loss based on the original samples and counterfactual samples to obtain the joint distillation loss; calculating the gradient signal of the joint distillation loss; calculating the gradient of each parameter of the student model through backpropagation; and updating the parameters of the student model using a gradient descent algorithm to obtain a student model with causal reasoning capabilities.
[0089] Computer devices can select causal paths corresponding to the current medical problem text from a directed acyclic causal graph. Each causal path consists of multiple medical entities related to the medical problem and causal directed edges between these entities. Nodes in the path include medical entities such as symptoms, diseases, treatments, and examination indicators. The computer device can select the starting or intermediate nodes on the causal path as key nodes, prioritizing entity nodes such as treatments and disease states that can influence disease outcomes, and performing value intervention operations on these key nodes. The value intervention operation is implemented using the causal inference do operator, which forcibly replaces the original observed values of the key nodes with hypothetical values, cuts off the original causal arrows pointing to the key node in the causal graph, calculates the distribution of the target variable after intervention according to the truncated factorization formula, and automatically constructs a counterfactual problem based on the changed causal scenario after intervention.
[0090] Subsequently, the computer device can input the generated counterfactual question and the aforementioned output knowledge-enhancing document into the teacher model. The teacher model, combining the external medical literature and clinical guidelines provided by the knowledge-enhancing document, generates the counterfactual reasoning chain and counterfactual answer corresponding to the counterfactual question. At the same time, the teacher model receives the original medical question and generates the corresponding original reasoning chain and original answer; wherein, the original sample consists of the original question, the original reasoning chain, and the original answer, and the counterfactual sample consists of the counterfactual question, the counterfactual reasoning chain, and the counterfactual answer.
[0091] The computer device can use the counterfactual inference chain and counterfactual answer, as well as the original inference chain and original answer, as supervisory signals for distillation training. Specifically, the computer device can calculate four losses: original inference chain loss, original answer loss, counterfactual inference chain loss, and counterfactual answer loss. Each loss adopts the negative log-likelihood loss of the sequence generation task, and then the corresponding weight hyperparameters are configured for weighted summation to obtain the joint distillation loss. The joint distillation loss simultaneously constrains the student model's generation performance on both original and counterfactual samples, forcing the student model to learn to distinguish between spurious statistical correlations and genuine causal relationships.
[0092] The computer equipment can calculate the gradient signal corresponding to the joint distillation loss and solve for the gradients of each parameter of the student model network through the backpropagation algorithm. The gradient descent algorithm is then used to iteratively update the network parameters of the student model based on the gradients. After multiple rounds of iterative training, the distillation process is completed, resulting in a student model with causal reasoning capabilities. This trained student model is a small-scale language model that, in practical reasoning applications, can independently receive medical question inputs and complete causal question-and-answer reasoning without the need for a large online teacher model.
[0093] Specifically, regarding the causal paths involved in the original problem... Computer devices can replace the values of intermediate or starting nodes in a path, generating counterfactual problems.
[0094] The formal definition of counterfactual intervention is: Let the variables in the original causal graph be... The observed value is Intervention operations variables The value is set to Then, under intervention conditions, the target variable The distribution is as follows: ;in, Representing variables The set of parent nodes in a causal graph The value of the parent node; this formula follows the truncated factorization formula in causal inference, by cutting off the direction pointing to the variable being intervened. The causal arrows are used to calculate the distribution of the target variable after intervention.
[0095] After generating counterfactual samples, the teacher model (large language model) generates an inference chain for each counterfactual question. Let the question in the original sample be... The reasoning chain is The answer is The problem with counterfactual samples is The reasoning chain is The answer is Then the overall loss function for distillation training is: ;in, , , , These are the loss weights for the original reasoning chain, the original answer, the counterfactual reasoning chain, and the counterfactual answer, respectively. Let be the probability distribution of the student model. The length of the generated sequence is denoted as . By simultaneously optimizing the generation probabilities of the original samples and counterfactual samples, the student model is forced to learn to distinguish between causal associations and spurious associations, thereby gaining more robust causal reasoning capabilities.
[0096] Step 208: Based on the directed acyclic causal graph, the causal effect of the treatment plan is estimated by adjusting the backdoor to obtain the average intervention effect and conditional average intervention effect of the treatment plan.
[0097] Computer devices can calculate the average treatment effect (ATE) and the conditional average treatment effect (CATE) based on the intervention path in the causal diagram.
[0098] In one embodiment, a medical question-answering method based on causal graphs and counterfactual reasoning distillation may further include a process of causal intervention reasoning and effect estimation. The specific process includes: based on a directed acyclic causal graph, identifying intervention variables that simultaneously point to treatment plan nodes and outcome variables that point to disease progression nodes as confounding variables, forming a candidate confounding variable set; based on the directed acyclic causal graph, identifying all backdoor paths between treatment plans and disease progression, and selecting a backdoor adjustment set from the candidate confounding variable set according to the backdoor criterion; for each value of the confounding variables in the backdoor adjustment set, calculating the conditional probabilities of the intervention variables and outcome variables, and weighting and summing the conditional probabilities of each layer according to the marginal distribution of the confounding variables to obtain the distribution of disease progression after intervention; based on the distribution of disease progression after intervention, calculating the difference between the expected value of disease progression when treatment is used and the expected value of disease progression when no treatment is used, as the average intervention effect; for a patient subgroup with target patient feature vectors, calculating the difference between the expected value of disease progression when treatment is used and the expected value of disease progression when no treatment is used, as the conditional average intervention effect.
[0099] Computer equipment can use a pre-constructed directed acyclic causal graph, treating treatment plan nodes as intervention variables T and disease progression nodes as outcome variables Y. It can then traverse all causal edges in the graph, identifying variables that simultaneously point to both intervention variable T and outcome variable Y, and collecting these variables to form a candidate confounding variable set. Confounding variables can simultaneously influence both the choice of treatment plan and the disease progression outcome. Without correction, the causal effect estimation will be subject to statistical confounding bias, failing to obtain the true causal effect of the treatment plan.
[0100] The computer equipment can continue to rely on the directed acyclic causal graph to identify all backdoor paths between the intervention variable (treatment plan) and the outcome variable (disease progression); and then screen the set of candidate confounding variables according to the backdoor criterion. Specifically, the computer equipment can screen out a subset of variables that can block all backdoor paths and do not contain intermediate nodes in the causal pathway from the intervention variable to the outcome variable, as the backdoor adjustment set. If a new backdoor path is identified, the screening process is repeated to update the backdoor adjustment set, ensuring the effectiveness of subsequent causal effect estimation. After determining the backdoor adjustment set, the computer equipment can iterate through every possible value of the confounding variable in the backdoor adjustment set; and calculate the conditional probabilities of the intervention variable and the outcome variable under the conditions of the confounding variable value, for the two scenarios of implementing treatment intervention and not implementing treatment intervention. Then, according to the marginal distribution of the confounding variable itself, the conditional probabilities obtained by stratification are weighted and summed to eliminate the selection bias caused by the confounding variable, and the corresponding disease progression distribution is obtained.
[0101] Computer devices can calculate the expected disease progression under two intervention scenarios based on the disease progression distribution obtained after intervention: the expected disease progression with treatment and the expected disease progression without treatment. The difference between these two values is the average intervention effect (ATE) corresponding to the treatment plan. The ATE characterizes the overall causal treatment effect of the treatment plan at the level of the entire patient population. Further, for patient subgroups carrying target patient feature vectors, the computer device can calculate the expected disease progression with and without treatment, respectively, under the condition of limiting the patient feature vectors. The difference between these two values yields the conditional average intervention effect (CATE), which characterizes the personalized expected treatment benefit of the treatment plan for the individual target patient.
[0102] Next, the computer equipment can output the calculated average intervention effect and conditional average intervention effect, which can be used to prioritize candidate treatment options and provide quantitative evidence at the causal level for clinical personalized treatment recommendations.
[0103] In this embodiment, for the binary treatment plan ;in, This indicates that treatment has been adopted. Indicates that it will not be used; target disease progression indicators and patient characteristics The average intervention effect is defined as: This indicator measures the overall causal effect of the treatment regimen on disease progression. For individualized treatment recommendation scenarios, this application further calculates the conditional average intervention effect: ;in, For the feature vector of the target patient; CATE allows for personalized treatment effect predictions based on different patient characteristics.
[0104] At the model implementation level, the causal intervention inference submodule estimates causal effects using a backdoor adjustment method. When the treatment plan... and disease progression There are confusing variables Time (i.e., there exists from) Simultaneously pointing to and (Cause-and-effect arrow), the backdoor adjustment formula is: ;in, The set of confounding variables required to satisfy the backdoor criterion is automatically identified by the causal graph extraction module. Through backdoor adjustment, confounding biases can be eliminated, accurately estimating the true causal effects of treatment options. During the inference phase, the student model provides a basis for prioritizing treatment options based on the estimated causal effects.
[0105] Step 210: Perform causal consistency verification on the generated inference chain. If the verification fails, feed back an inconsistency signal to the link that generated the inference chain, regenerate or adjust the inference chain until the causal consistency verification passes. Then, extract the causal relationship in the verified inference chain to obtain the causal mechanism description and causal strength index.
[0106] In one embodiment, a medical question-answering method based on causal graphs and counterfactual reasoning distillation may further include a process of causal consistency verification and mechanism extraction. The specific process includes: performing structured analysis on the reasoning chain, dividing the reasoning chain into various reasoning steps, identifying causal triples in each reasoning step, and summarizing them to obtain a set of causal triples; performing transitive consistency, directional consistency, and evidential consistency checks on the reasoning chain respectively; if all three checks pass, the causal consistency verification is deemed successful; otherwise, the verification is deemed unsuccessful, and an inconsistency signal is generated; the inconsistency signal is used as an additional constraint condition and appended to the input of the student model, which regenerates the reasoning chain and re-performs the causal consistency verification, forming an iterative correction loop until the causal consistency verification is successful; extracting the causal mechanism from the reasoning chain that has passed the causal consistency verification, extracting the described causal action path, and summarizing and integrating the causal action path to generate a structured causal mechanism description; and calculating the causal strength index based on the causal association description of each reasoning step in the reasoning chain, combined with the average intervention effect and the conditional average intervention effect.
[0107] Computer equipment can perform structured parsing and decomposition of the complete inference chain generated by the model. Specifically, the computer equipment can perform structured analysis on the continuous inference chain text, dividing the overall inference chain into multiple independent inference steps according to logical semantic boundaries. For each decomposed inference step, the causal entity relationships contained within the step are accurately identified, and the corresponding causal triples are extracted. After the causal triples of all inference steps are summarized and integrated, a complete set of causal triples covering the entire inference logic is formed, realizing the transformation of unstructured inference chains into structured causal logic units, and providing standardized verification objects for subsequent multi-dimensional consistency verification.
[0108] Next, the computer equipment can perform multi-dimensional joint verification of causal consistency on the reasoning chain based on the causal triple set, specifically including transitive consistency checks, directional consistency checks, and evidential consistency checks. Transitive consistency verifies the logical transitivity of multi-level causal deductions in the reasoning chain, ensuring that the causal relationships between preceding and subsequent reasoning steps are compatible and logically consistent. Directional consistency verifies that the direction of action of each causal association in the reasoning chain is consistent with the causal orientation marked on the aforementioned directed acyclic causal diagram, preventing logical errors such as causal reversal and reverse reasoning. Evidence consistency, combined with the previously acquired knowledge-enhanced document set, verifies whether the reasoning logic corresponding to each causal triple is supported by external medical literature and clinical knowledge. The causal consistency verification of the reasoning chain is considered successful only when all three checks—transitive consistency, directional consistency, and evidential consistency—are passed simultaneously. If any check is not met, there is a causal logical conflict, or evidence is missing, the causal consistency verification is deemed unsuccessful, and a corresponding inconsistency signal is automatically generated.
[0109] When an inconsistency signal is detected, the computer can incorporate it as a specific constraint into the student model's input information. This constraint forces the student model to regenerate or adaptively adjust its inference chain based on the inconsistency feedback. After regenerating the inference chain, the student model performs structured decomposition, causal triple identification, and three-dimensional causal consistency verification on the new chain. This forms an iterative correction loop of verification-feedback-regeneration-re-verification, continuously optimizing the inference logic until the inference chain passes all causal consistency verifications.
[0110] After the causal consistency verification of the inference chain is passed, the computer equipment can perform a refined causal mechanism extraction operation on the compliant inference chain. Specifically, the computer equipment can traverse all causal triples and corresponding causal reasoning steps in the verified inference chain, extracting the causal action path, triggering conditions, action logic, and pathological correlation between each medical entity; then, it can summarize, sort out, and integrate multiple fragmented causal action paths, eliminate redundant and repetitive information, sort out hierarchical logical relationships, and finally generate a clear, logically complete, and highly interpretable structured causal mechanism description.
[0111] Computer devices can quantify the causal strength index corresponding to each causal reasoning step based on the causal relationship logic and entity interaction relationship corresponding to each reasoning step in the reasoning chain, combined with the average intervention effect and conditional average intervention effect quantification results obtained from the aforementioned causal effect estimation stage, and comprehensively consider the causal dependence probability between entities, the strength of causal intervention effect and individualized patient fit differences.
[0112] In this embodiment, transitive consistency checks ensure that causal transitivity holds between adjacent steps in the inference chain. For triples in the inference chain... The transitive consistency constraint is defined as: ;in, These are elements in the adjacency matrix of the cause-effect graph. Indicates from arrive Does a reachable path exist (calculated using matrix exponentiation)? For indicator functions. This constraint ensures that: if in the inference chain... lead to , lead to Then, from the cause-and-effect diagram... arrive A transmission path must exist.
[0113] The directional consistency check ensures that the causal direction in the reasoning chain is consistent with the causal direction in the causal graph. For causal relationships in the reasoning chain... The directional consistency constraint is: That is, the positive causal score must be higher than the negative causal score to ensure that the causal arrows in the reasoning chain are in the correct direction.
[0114] Evidence consistency checks ensure that each causal step in the reasoning chain is supported by documents from an external knowledge base. This check is verified using the document set returned by the knowledge-enhanced retrieval module. The comprehensive consistency loss function unifies the above three constraints into a differentiable training signal: ;in, Let be the set of all causal triples in the reasoning chain. , , These are the weight hyperparameters for transitivity consistency, directional consistency, and evidentiary consistency, respectively. The evidence consistency score is determined by the degree of matching between the retrieved documents and the reasoning steps.
[0115] Specifically, to provide an interpretable biological basis for each causal relationship in the reasoning chain, computer science can transform abstract causal relationships into traceable mechanism descriptions, mainly extracting mechanisms from two levels: qualitative mechanism description and quantitative mechanism strength assessment.
[0116] Qualitative mechanism description involves retrieving relevant literature passages to extract text fragments describing the mechanisms of causal action. For edges in the causal graph... The extraction of the mechanism description can be formalized as a retrieval problem. Let causal pairs... The query vector is: ;in, A dedicated multilayer perceptron is used for mechanism extraction. and These are the semantic representations of the entities. This query vector is used to retrieve descriptions from the knowledge base. How did it lead to The mechanism text.
[0117] Quantitative mechanism strength assessment measures the reliability of causal relationships using causal strength indices. For causal pairs... The strength of causality is defined as: ;in, The normalized causal strength is such that the value is closer to... express right The stronger the causal promoting effect, the closer it is to This indicates a weak causal relationship, close to... This indicates a causal inhibition relationship. This indicator, combined with the mechanistic description text, provides quantitative and qualitative interpretability support for the inference results.
[0118] Step 212: Prioritize each candidate treatment plan according to the average intervention effect and the conditional average intervention effect, generate the final answer and treatment recommendations, and integrate the reasoning chain, causal mechanism description and causal strength index verified by causal consistency to generate a causal reasoning report.
[0119] In one embodiment, a medical question-answering method based on causal graphs and counterfactual reasoning distillation may further include a process of prioritizing treatment options and generating a final answer. The specific process includes: extracting all candidate treatment option nodes related to the current disease from a directed acyclic causal graph; traversing treatment option nodes pointing to disease progression nodes in the directed acyclic causal graph; supplementing the directed acyclic causal graph with treatment option nodes from knowledge-enhanced documents to form a candidate treatment option list; ranking the candidate treatment options in the candidate treatment option list based on the average intervention effect; performing personalized ranking based on the conditional average intervention effect for patient subgroups with target feature vectors; generating a multi-objective ranking based on the results of the overall ranking and personalized ranking; selecting the candidate treatment option ranked first in the multi-objective ranking as the recommended treatment option; and generating the final answer and treatment suggestions by combining the reasoning chain verified by causal consistency.
[0120] Computer devices can extract all treatment plan nodes associated with the disease entity corresponding to the current medical problem from a constructed directed acyclic causal graph. By traversing all treatment plan nodes in the directed acyclic causal graph with causal edges pointing to disease progression nodes, all potential treatment methods that can intervene in the current disease progression are selected, completing the initial screening of treatment plan nodes and ensuring that all candidate plans have a real causal relationship with the current case. The computer device can then supplement and improve the candidate treatment plans by incorporating external knowledge, constructing a complete list of candidate treatment plans. Specifically, the selected treatment plan nodes in the causal graph can be combined with external medical knowledge such as clinical treatment methods, standardized treatment protocols, and guideline-recommended therapies recorded in knowledge enhancement documents to supplement and expand any missing or incomplete treatment plans in the directed acyclic causal graph, thus perfecting all feasible intervention methods corresponding to the current disease and forming a comprehensive and clinically compliant list of candidate treatment plans.
[0121] Subsequently, the computer equipment can employ a two-tiered ranking mechanism combining overall group ranking with patient-specific ranking to achieve precise selection of treatment plans. Specifically, the computer equipment can rank the list of candidate treatment plans based on the average intervention effect corresponding to each candidate treatment plan. The average intervention effect characterizes the overall causal treatment benefit of each treatment plan at the general patient population level, achieving a universal ranking of treatment effects. Simultaneously, the computer equipment can perform personalized ranking for target patients with target feature vectors and corresponding patient subgroups based on the conditional average intervention effect corresponding to each treatment plan, fully adapting to the differences in treatment effects caused by individual patient signs and disease characteristics, achieving individualized and precise ranking.
[0122] Next, the computer equipment can further integrate the overall ranking results with the personalized ranking results to generate a multi-objective comprehensive ranking result that takes into account both the universality of the group and the specificity of the individual. Then, based on the multi-objective ranking results, the candidate treatment plan with the highest comprehensive ranking is selected as the optimal recommended treatment plan. At the same time, combined with a reasoning chain that has undergone complete causal consistency verification, is logically consistent, and is supported by literature evidence, the system integrates the pathogenesis of the disease, the reasoning logic of the condition, and the causal mechanism of treatment intervention to generate a standardized final answer to the current medical problem and a structured, implementable personalized treatment suggestion, thus achieving an organic combination of medical question-and-answer reasoning and clinical treatment recommendation.
[0123] In one embodiment, a medical question-answering method based on causal graphs and counterfactual reasoning distillation may further include a process of generating a causal reasoning report. The specific process includes: constructing a causal reasoning report template, filling the knowledge-enhanced document, directed acyclic causal graph, average intervention effect and conditional average intervention effect, causal mechanism description and causal strength index, final answer and treatment suggestions into the structured fields corresponding to the causal reasoning report template, and generating a causal reasoning report; and outputting the causal reasoning report in a structured document format.
[0124] The computer device can store pre-built causal reasoning report templates adapted to medical causal question-and-answer scenarios. These templates have multiple standardized structured fields to carry different dimensions of reasoning information and experimental evidence, enabling a structured, standardized, and traceable presentation of the output results. The computer device can fill each structured field of the causal reasoning report template with retrieved knowledge-enhanced documents, the constructed directed acyclic causal graph structure, the quantitative data of the average and conditional average intervention effects for each candidate treatment plan, the extracted structured causal mechanism description, the quantified causal strength indicators, the complete reasoning chain verified by causal consistency, and the final generated answer and personalized treatment suggestions. Through multi-dimensional information fusion, the report simultaneously includes the structural causal model basis, external medical knowledge evidence, causal quantitative effects, explainable mechanism principles, reasoning logic chains, and final treatment recommendations, achieving full coverage of the reasoning results from conclusions, processes, mechanisms to quantitative indicators.
[0125] After all field information is filled in, the computer device can integrate all structured field content to generate a complete and standardized causal reasoning report, which is then output in a structured document format. This causal reasoning report fully preserves the causal logic of the model's reasoning, supporting evidence from literature, the strength of causal effects, and the quantitative results of individualized treatment outcomes. This ensures that the output of medical question-and-answer systems is no longer a single conclusion, but rather an intelligent, assisted diagnostic reasoning result that is interpretable, traceable, and quantifiable, effectively improving the reliability and clinical applicability of the medical question-and-answer system.
[0126] It should be understood that although the steps in the flowchart above are shown sequentially as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowchart above may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the sub-steps or stages of other steps.
[0127] In one embodiment, such as Figure 3 As shown, a medical question-answering system based on causal graphs and counterfactual reasoning distillation is provided, including: a causal graph construction module 310, a knowledge enhancement module 320, a counterfactual generation module 330, a causal intervention reasoning module 340, a causal consistency verification and mechanism extraction module 350, and a report output module 360, wherein:
[0128] The causal graph construction module 310 is used to acquire medical question text, use a pre-trained language model to perform medical entity recognition on the medical question text, extract medical entities and their type labels, calculate the causal dependency score between medical entities, and construct a directed acyclic causal graph based on the causal dependency score.
[0129] The knowledge enhancement module 320 is used to retrieve candidate documents corresponding to the medical question text from an external medical knowledge base through dual encoders, and to reorder the candidate documents to obtain knowledge-enhanced documents;
[0130] The counterfact generation module 330 is used to intervene in the key nodes of the directed acyclic causal graph, generate counterfactual questions, and use the teacher model combined with knowledge-enhanced documents to generate the counterfactual reasoning chain and counterfactual answer corresponding to the counterfactual questions; calculate the joint distillation loss based on the original samples and counterfactual samples, update the parameters of the student model, and obtain a student model with causal reasoning ability.
[0131] The causal intervention reasoning module 340 is used to estimate the causal effect of the treatment plan based on the directed acyclic causal graph and through backdoor adjustment, so as to obtain the average intervention effect and conditional average intervention effect of the treatment plan.
[0132] The causal consistency verification and mechanism extraction module 350 is used to verify the causal consistency of the generated inference chain. If the verification fails, an inconsistency signal is fed back to the link that generates the inference chain, and the inference chain is regenerated or adjusted until the causal consistency verification passes. Then, the mechanism is extracted from the causal relationship in the verified inference chain to obtain the causal mechanism description and causal strength index.
[0133] The report output module 360 is used to prioritize each candidate treatment plan based on the average intervention effect and the conditional average intervention effect, generate the final answer and treatment recommendations, and integrate the reasoning chain, causal mechanism description and causal strength index verified by causal consistency to generate a causal reasoning report.
[0134] In one embodiment, the causal graph construction module 310 is further configured to acquire medical question text, perform word segmentation and standardization on the medical question text, map the processed text to standardized medical terms, determine the question type, and generate a structured text representation; encode the structured text representation using a pre-trained language model to obtain a contextual semantic representation, and input the contextual semantic representation into a conditional random field sequence labeling classifier to identify medical entities in the text, assigning a type label to each medical entity; for each medical entity, calculate the causal dependency score from the first entity to the second entity through a causal dependency scoring network, and use the causal dependency score for... The algorithm represents the probability that one medical entity has a causal influence on another medical entity; it calculates the positive causal dependency score of the first entity on the second entity and the negative causal dependency score of the second entity on the first entity to distinguish the direction of causal association; it treats all medical entities as nodes, establishes directed edges between entity pairs with causal dependency scores greater than a preset threshold, constructs an adjacency matrix, and applies an acyclic constraint to the adjacency matrix; during training, the acyclic constraint is transformed into a penalty term and added to the loss function using the augmented Lagrangian method, and the penalty term is constructed based on the square of the difference between the matrix exponent trace of the adjacency matrix and the number of entities; finally, it outputs a directed acyclic causal graph.
[0135] In one embodiment, the knowledge enhancement module 320 is further configured to encode the medical question text using the query encoder in the dual encoder, extract semantic features, and perform pooling to obtain a query vector; encode candidate documents in the external medical knowledge base using the context encoder in the dual encoder, extract semantic features, and perform pooling to obtain a document vector; calculate the retrieval relevance score between the query vector and the document vector using the inner product, and select a set of candidate documents from the external medical knowledge base based on the retrieval relevance score; use a cross-attention reorderer to calculate the interaction representation between the medical question text and each candidate document through a multi-head cross-attention function, capture the semantic association between each word in the query and each word in the document, and after the cross-attention output is nonlinearly transformed by a feedforward network, obtain a reordering score through linear projection and activation function; sort the candidate document set according to the reordering score, and select knowledge-enhanced documents based on the sorted candidate document set.
[0136] In one embodiment, the counterfactual generation module 330 is further configured to select a causal path corresponding to the medical question text from a directed acyclic causal graph, perform value intervention operations on key nodes in the causal path, and generate a counterfactual question; input the counterfactual question and knowledge-enhancing document into the teacher model, generate a counterfactual inference chain and counterfactual answer corresponding to the counterfactual question through the teacher model combined with the knowledge-enhancing document, and generate an original inference chain and original answer for the original question through the teacher model; use the counterfactual inference chain and counterfactual answer, and the original inference chain and original answer together as distillation supervision signals, and calculate the original inference chain loss, original answer loss, counterfactual inference chain loss, and counterfactual answer loss according to the original sample and counterfactual sample, respectively, to obtain the joint distillation loss; calculate the gradient signal of the joint distillation loss, calculate the gradient of each parameter of the student model through backpropagation, and update the parameters of the student model using the gradient descent algorithm to obtain a student model with causal inference ability.
[0137] In one embodiment, the causal intervention inference module 340 is further configured to: identify intervention variables that simultaneously point to treatment plan nodes and outcome variables that point to disease progression nodes as confounding variables based on a directed acyclic causal graph, forming a candidate confounding variable set; identify all backdoor paths between treatment plans and disease progression based on the directed acyclic causal graph, and select a backdoor adjustment set from the candidate confounding variable set according to the backdoor criterion; for each value of the confounding variables in the backdoor adjustment set, calculate the conditional probability of the intervention variable and the outcome variable, and perform a weighted summation of the conditional probabilities of each layer according to the marginal distribution of the confounding variables to obtain the distribution of disease progression after intervention; calculate the difference between the expected value of disease progression when treatment is used and the expected value of disease progression when no treatment is used, based on the distribution of disease progression after intervention, as the average intervention effect; and calculate the difference between the expected value of disease progression when treatment is used and the expected value of disease progression when no treatment is used for a patient subgroup with target patient feature vectors, as the conditional average intervention effect.
[0138] In one embodiment, the causal consistency verification and mechanism extraction module 350 is further used to perform structured analysis on the inference chain, divide the inference chain into various inference steps, identify the causal triples in each inference step, and summarize them to obtain a set of causal triples; perform transitivity consistency, directional consistency, and evidential consistency checks on the inference chain respectively; if all three checks pass, the causal consistency verification is deemed successful; otherwise, the verification is deemed unsuccessful, and an inconsistency signal is generated; the inconsistency signal is used as an additional constraint condition and appended to the input of the student model, the student model regenerates the inference chain, and performs causal consistency verification again, forming an iterative correction loop until the causal consistency verification is successful; the causal mechanism is extracted from the inference chain that has passed the causal consistency verification, the described causal action path is extracted, and the causal action path is summarized and integrated to generate a structured causal mechanism description; based on the causal association description of each inference step in the inference chain, combined with the average intervention effect and the conditional average intervention effect, the causal strength index is calculated.
[0139] In one embodiment, the report output module 360 is further configured to extract all candidate treatment plan nodes related to the current disease from the directed acyclic causal graph, traverse the treatment plan nodes pointing to the disease progression nodes in the directed acyclic causal graph; supplement the directed acyclic causal graph by combining the treatment plan nodes with the treatment plans in the knowledge-enhanced document to form a candidate treatment plan list; rank the candidate treatment plans in the candidate treatment plan list according to the average intervention effect; perform personalized ranking for patient subgroups with target feature vectors according to the conditional average intervention effect; generate a multi-objective ranking based on the results of the overall ranking and personalized ranking, select the candidate treatment plan ranked first in the multi-objective ranking as the recommended treatment plan; and generate the final answer and treatment suggestions by combining the inference chain verified by causal consistency.
[0140] In one embodiment, the report output module 360 is also used to construct a causal reasoning report template, and fill the knowledge-enhanced document, directed acyclic causal graph, average intervention effect and conditional average intervention effect, causal mechanism description and causal strength index, final answer and treatment suggestion into the structured fields corresponding to the causal reasoning report template to generate a causal reasoning report; and output the causal reasoning report in a structured document format.
[0141] In one embodiment, a medical question-answering system based on causal graphs and counterfactual reasoning distillation may further include a causal graph extraction module, a counterfactual generation module, a causal intervention reasoning module, a mechanism extraction module, and a graph reasoning module. The causal graph extraction module identifies causal dependencies between entities in medical text and constructs a structured causal graph. The counterfactual generation module constructs hypothetical scenarios to test the model's understanding of causal mechanisms. The causal intervention reasoning module predicts the intervention effect of treatment plans on disease progression. The mechanism extraction module explains the biological basis of causal relationships. The causal consistency verification module ensures the logical self-consistency of the reasoning chain. The graph reasoning module performs multi-step reasoning along the causal chain and generates treatment suggestions. The system in this embodiment enables small models to acquire causal reasoning capabilities without requiring large models for online reasoning, reducing deployment computational overhead and improving generalization robustness for novel cases and the interpretability of reasoning conclusions. It can be applied to fields such as intelligent medical auxiliary diagnosis, personalized treatment plan recommendation, and online health consultation. While maintaining the advantages of the KARD retrieval-enhanced distillation framework, it systematically injects causal reasoning capabilities into the distillation process, enabling small models to handle medical problems requiring causal understanding, improving generalization ability for novel cases and the interpretability of reasoning conclusions.
[0142] In one embodiment, a medical question-answering system based on causal graphs and counterfactual reasoning distillation may further include a causal graph extraction and knowledge-enhanced retrieval module, a counterfactual generation and causal intervention reasoning module, and a causal consistency verification and mechanism extraction module. In the knowledge-enhanced retrieval module, when a pre-trained dense encoder is lacking or computational resources are limited, a sparse retrieval scheme based on the BM25 algorithm can be used instead of a dense retrieval scheme. BM25 calculates the relevance score between the query and the document using a variant of term frequency-inverse document frequency (TF-IDF), without requiring the training of additional encoder parameters. In this alternative, the causal graph extraction module remains unchanged, and the re-ranking model can be replaced with a learning-to-rank model to reduce computational overhead; this is suitable for deployment scenarios with a small knowledge base or high requirements for retrieval latency.
[0143] In the counterfact generation and distillation module, when the teacher model does not support high-quality chain-like reasoning generation or the quality of the reasoning chain is unstable, a self-consistency sampling strategy can be used instead of the standard single generation. The self-consistency method generates multiple reasoning chains for the same question, extracts the intermediate conclusions and final answers of each chain, and selects the most consistent reasoning chain as the distillation supervision signal through a majority voting mechanism. In this alternative, the counterfactual intervention operation remains unchanged, but the reasoning chains of both the original samples and counterfactual samples in the distillation loss function are derived from the majority voting results, thereby improving the reliability of the supervision signal; this approach is suitable for scenarios where the teacher model has weak reasoning ability but high sampling efficiency.
[0144] In the causal consistency verification and mechanism extraction module, when the causal graph is large and the causal path is long, a graph neural network (GNN) can be used to replace the matrix operation-based transitive consistency check. Specifically, a graph attention network (GAT) is used to perform message passing on the causal graph, learn the causal perception representation of the nodes, and then make consistency judgments based on the learned representations. This is suitable for large-scale medical knowledge graph scenarios with more than hundreds of causal graph nodes, and can capture long-distance causal dependencies more efficiently.
[0145] In the causal intervention reasoning module, when intervention planning is required for complex multi-step treatment combinations, intervention reasoning can be modeled as a Markov decision process (MDP), and reinforcement learning methods (such as proximal policy optimization, PPO) can be used to learn the optimal treatment strategy. In this approach, the state space represents the patient's current condition characteristics, the action space represents the set of available treatment options, and the reward function is provided by the causal intervention effect estimation module; it is suitable for chronic disease management scenarios that require continuous decision-making and long-term intervention effect evaluation.
[0146] In one embodiment, the overall architecture and core data flow of a medical question-answering method and system based on causal graphs and counterfactual reasoning distillation are as follows: Figure 4As shown, the system's input terminal receives users' medical questions (such as symptom descriptions, diagnostic consultations, treatment plan comparisons, etc.) in the form of natural language text sequences. The causal graph extraction and knowledge enhancement retrieval module first uses a pre-trained language model to perform medical entity recognition on the input text, extracting entities such as symptoms, diseases, treatment methods, and examination indicators, along with their type labels. Subsequently, it calculates causal dependency scores between entities through causal pattern matching and semantic reasoning, constructing a structured directed acyclic causal graph (DAG), where the elements of the adjacency matrix represent the existence and direction of causal relationships between entities. Simultaneously, this module retrieves documents causally related to the current question from an external medical knowledge base using a dual-encoder dense retrieval architecture, and performs fine-grained ranking of candidate documents using a cross-attention neural reordering device, returning a set of knowledge documents highly relevant to causal reasoning. The counterfact generation and causal intervention reasoning module receives a structured causal graph and a collection of retrieved documents from the causal graph extraction and knowledge enhancement retrieval module. Based on key nodes in the causal graph, it performs value intervention operations to automatically generate counterfactual hypothetical scenarios and uses a teacher model (large language model) to generate reasoning chains for counterfactual questions. Simultaneously, it eliminates confounding bias using a backdoor adjustment method, calculates the average intervention effect (ATE) and conditional average intervention effect (CATE), and predicts the causal effect of a specific treatment regimen on disease progression. The causal consistency verification and mechanism extraction module checks the logical consistency of the reasoning chain from three dimensions: transitive consistency, directional consistency, and evidentiary consistency. It also extracts biological mechanism descriptions and quantitative strength indicators of causal relationships using a multilayer perceptron. When consistency verification fails, the causal consistency verification and mechanism extraction module sends an inconsistency signal to the counterfact generation and causal intervention reasoning module, triggering the counterfactual reasoning module to regenerate or adjust the reasoning chain, forming a closed-loop feedback loop. The module integrates the consistent-verified reasoning chains and generates the final answer, outputting a complete causal reasoning report containing the reasoning chain, causal mechanism description, and strength indicators.
[0147] In one embodiment, the internal processing flow and interaction relationships between key components of a counterfactual generation and causal intervention reasoning module are provided as follows: Figure 5As shown, the system receives a structured causal graph input from the causal graph extraction module, containing an entity set and an adjacency matrix. The causal path selector selects the most relevant causal path from the causal graph based on the type of causal query involved in the current medical problem. The path selection strategy comprehensively considers path length, causal strength score, and semantic relevance between the path and the problem, prioritizing causal paths containing treatment plan nodes and disease progression nodes. The counterfactual intervention generator performs value intervention operations on key nodes in the selected path, replacing the original observations with hypothetical values, calculating the distribution of the target variable after intervention based on the truncated factorization formula, and automatically generating counterfactual hypothesis questions. For example, when the original causal path is "infection → inflammation → fever," value intervention is performed on the "infection" node (e.g., replacing it with "no infection"), generating the counterfactual question "If the patient is not infected, will they still experience fever symptoms?" Then, the counterfactual question is input into the teacher model (large language model) to generate the corresponding counterfactual reasoning chain and answer, providing high-quality supervision signals for distillation training. The joint distillation loss calculation unit comprehensively calculates the original sample inference chain loss, original answer loss, counterfactual inference chain loss, and counterfactual answer loss. These four losses are weighted and summed using weighting coefficients to ensure the student model simultaneously learns causal inference patterns and counterfactual inference capabilities. The student model parameter update unit updates the student model's parameters based on the gradient signal of the joint distillation loss, enabling the small-scale language model to gradually acquire causal inference capabilities. The causal effect estimator estimates the causal effect between treatment options and disease progression in the causal graph based on the backdoor adjustment formula. It automatically identifies the set of confounding variables that satisfy the backdoor criterion, eliminates confounding bias to obtain the true causal effect of the treatment options, and calculates the average intervention effect (ATE) and conditional average intervention effect (CATE). Based on the causal effect estimation results, candidate treatment options are prioritized, providing causal-level recommendations for clinical decision-making. The causal effect estimator includes a self-feedback mechanism for confounding variable identification; when a new confounding path is detected, the set of confounding variables is automatically updated and the causal effect is re-estimated, ensuring the accuracy of the effect estimation.
[0148] In one embodiment, the complete interaction sequence of a medical question-answering method based on causal graphs and counterfactual reasoning distillation during the training and inference phases is as follows: Figure 6As shown, the message passing order and collaboration mechanism between the modules are presented. A user (U) submits a medical question to the CRD system (S). The system first forwards the question text to the causal graph extraction module (CE). The causal graph extraction module performs two self-processing steps: First, it performs entity recognition using a pre-trained language model, extracts relevant entities in the medical field, and calculates the causal dependency score between each pair of entities. This score predicts the causal dependency probability by comprehensively considering the semantic representation, interaction features, and difference features of the two entities. Second, it constructs an adjacency matrix based on the causal dependency score and verifies the acyclicity constraint of the causal graph using a topological sorting-based cycle detection algorithm, ensuring that the causal graph is a valid directed acyclic graph. Subsequently, the causal graph extraction module passes the structured causal graph and question vector to the knowledge-enhanced retrieval module (KR). This module obtains candidate documents related to the question from an external medical knowledge base using a dual-encoder dense retrieval architecture, then refines the candidate documents using a cross-attention re-ranking device, and returns the re-ranked knowledge documents to the causal graph extraction module. The causal graph extraction module returns the integrated causal graph and retrieved documents to the CRD system. The system passes the causal graph and documents to the counterfactual generation module (CF). This module first performs a self-processing step—selecting causal paths based on the causal graph and performing value intervention operations on key nodes, automatically generating counterfactual hypothesis questions. It then calls the teacher model (large language model) to generate a counterfactual inference chain, returning counterfactual samples and the inference chain. Simultaneously, the system passes the causal graph and intervention paths to the causal intervention inference module (IR). This module performs confounding variable identification and backdoor adjustment, calculating the mean intervention effect (ATE) and conditional mean intervention effect (CATE) of the treatment plan by eliminating confounding bias, and returning the causal effect estimation results. The system passes the inference chain and causal graph to the consistency verification module (CV). This module sequentially performs transitivity consistency checks (verifying the causal transitivity of triples in the inference chain), directional consistency checks (ensuring the correct direction of the causal arrows), and evidence consistency checks (verifying that each causal step is supported by literature), returning the consistency verification results. The system performs backpropagation based on the combined distillation loss, driving the student model (SM) to update parameters and learn causal inference capabilities. Finally, the student model returns the generated inference chain and answer, and the system outputs a complete causal inference report to the user, including the inference chain, a description of the causal mechanism, and strength indicators. The entire interaction process forms a complete closed loop from causal knowledge acquisition and causal inference enhancement to causal consistency assurance, ensuring that the small model acquires reliable causal inference capabilities during the distillation process.
[0149] In one embodiment, combining medical question answering and causal intervention reasoning scenarios, the implementation effects of various methods in the prior art and the CRD method in this application are verified, and the comparison of the causal question answering effects of each method on the MedQA-USMLE dataset is shown in Table 1:
[0150] Table 1 Comparison of causal question answering performance on the MedQA-USMLE dataset.
[0151]
[0152] Table 1 shows that the method in this application improves the accuracy of causal inference, overall accuracy, and consistency of inference chains without increasing the size of the student model parameters.
[0153] Table 2 shows a comparison of the effects of various existing methods and the CRD method in this application on causal intervention reasoning tasks:
[0154] Table 2 Comparison of the effects of causal intervention reasoning tasks
[0155]
[0156] Table 2 shows that the method in this application achieves the best results in terms of intervention effect prediction, counterfactual reasoning, and mechanism explanation coverage, indicating that it is suitable for medical auxiliary decision-making scenarios that emphasize causal logic.
[0157] In this application, the specific data on the experimental environment and model hyperparameter configuration are shown in Table 3:
[0158] Table 3 Experimental Environment and Model Hyperparameter Configuration
[0159]
[0160] Table 3 shows the core implementation configuration of this embodiment, which can be used to build a causal reasoning distillation system for medical question answering.
[0161] In this embodiment, as shown in Table 1, the causal inference accuracy of the method in this application reaches 52.4% on MedQA-USMLE, which is 5.6 percentage points higher than that of KARD. As shown in Table 1, the inference chain consistency of the method in this application reaches 0.83, which is significantly better than the comparative implementation methods, indicating that it can generate a more coherent causal explanation path. As shown in Table 2, the method in this application achieves 48.9% and 51.3% in intervention effect prediction and counterfactual inference, respectively, which is suitable for implementation scenarios that require analysis of the impact of changes in treatment plans. As shown in Table 2, the mechanism explanation coverage of the method in this application reaches 47.8%, indicating that it is more conducive to outputting traceable medical reasoning evidence. As shown in Table 3, this application is still implemented with a student model with 250M parameters, which is convenient for deploying a medical auxiliary question answering system under limited computing power conditions.
[0162] In one embodiment, a medical question-answering method and system based on causal graphs and counterfactual reasoning distillation is provided for deployment in causal reasoning distillation for intelligent auxiliary diagnosis in tertiary hospitals. In the clinical auxiliary diagnosis scenario of tertiary hospitals, doctors face a large number of complex cases and need to quickly obtain diagnostic suggestions based on causal reasoning. This scenario is characterized by: high case complexity, often involving multi-system complications, requiring the model to understand the causal chain between symptoms, diseases, and treatments rather than simple correlation matching; the deployment environment is the hospital's intranet, with strict data privacy requirements, prohibiting the sending of patient information to external large model APIs for reasoning; and the reasoning conclusions must be interpretable, requiring doctors to trace the causal basis for the model's diagnostic judgment. This embodiment deploys the CRD method on a local hospital server, using a 250M parameter student model to replace the 175B parameter teacher model for online reasoning, providing causal-enhanced auxiliary diagnostic suggestions to clinicians while ensuring data remains within the hospital premises; the specific process is as follows... Figure 7 As shown:
[0163] M1: Medical problem input and preprocessing. Doctors input patient symptom descriptions and examination results (such as "patient has fever for a preset number of days, accompanied by cough, lung infiltrates, and elevated WBC") through the clinical workstation. The system performs word segmentation and standardization on the input text to generate a structured medical problem representation, which serves as the input for subsequent causal graph extraction.
[0164] M2: Causal graph extraction and entity relationship modeling. The causal graph extraction module performs medical entity recognition on the input text, extracting entities such as symptoms and examination indicators such as "fever," "cough," "pulmonary infiltrates," and "elevated WBC." It then calculates the causal relationship direction between entities using causal dependency scores, constructing a directed acyclic causal graph with "pulmonary infection" as the central node. Based on pre-set data, the causal inference accuracy of CRD reaches the target performance and is significantly higher than the target performance of KARD, verifying the effect of causal graph extraction on improving inference quality.
[0165] M3: Knowledge-enhanced retrieval and reordering. The dense retrieval module encodes the current question into a query vector and retrieves literature documents related to the causal relationship of lung infection diagnosis from the locally deployed PubMed abstract database and clinical guideline database. The neural reorderer performs fine sorting of the preset numerical candidate documents through a cross-attention mechanism and selects the preset numerical document with the highest causal relevance as the knowledge enhancement input.
[0166] M4: Counterfactual generation and inference chain distillation. The counterfactual generation module performs value intervention operations on key nodes in the causal graph, automatically generating counterfactual hypothetical scenarios (e.g., "If a patient has no pulmonary infiltrates but has elevated WBC counts, should it still be diagnosed as a pulmonary infection?"). The teacher model (GPT-preset values-turbo) generates inference chains for counterfactual questions offline, while the student model learns the inference patterns of both original and counterfactual samples simultaneously through joint distillation loss. The counterfactual generation module contributes a significant gain to the overall accuracy improvement.
[0167] M5: Causal Intervention Inference and Treatment Option Effect Prediction. The causal intervention inference module eliminates confounding bias using a backdoor adjustment method. It calculates the conditionally averaged intervention effect (CATE) for each candidate treatment option (such as antibiotic therapy, antiviral therapy, and symptomatic supportive therapy) and predicts the causal effect of each option on the patient's disease progression. Based on pre-set data, the CRD intervention effect prediction accuracy reaches the target performance, significantly improving the target performance by several percentage points compared to KARD.
[0168] M6: Causal consistency verification and logical self-consistency check. The consistency verification module checks the generated inference chain in three dimensions: transitive consistency, directional consistency, and evidentiary consistency, ensuring that the causal chain such as "lung infection → inflammatory response → fever" is logically consistent and directionally correct during the inference process. Based on preset data, CRD's inference chain consistency score reaches an extremely high level, improving the target performance compared to KARD's preset value.
[0169] M7: Causal mechanism extraction and interpretable report generation. The mechanism extraction module provides biological mechanism descriptions and quantitative causal strength indicators for each step of the causal relationship in the reasoning chain, generating a causal reasoning report that includes the tracing of the reasoning basis. Based on preset data, CRD's mechanism explanation coverage reaches the target performance, significantly improving the target performance by several percentage points compared to KARD.
[0170] M8: Inference results output and clinical feedback. Causal inference reports are output to the clinical workstation, displaying diagnostic suggestions (e.g., "Most probable diagnosis: community-acquired pneumonia"), the inference chain, causal strength indicators for each step, and supporting literature sources. Physicians can make clinical decisions based on the causal evidence in the report, forming a closed loop of "system inference → physician review → feedback calibration". The complete CRD solution achieves the overall accuracy of the target performance on a 250M parameter model, achieving a balance between lightweight deployment and inference quality.
[0171] In the tertiary hospital assisted diagnosis scenario of this embodiment, this solution, while ensuring the final judgment and inference effect, can significantly control the average communication overhead and inference load per page or per round, and can maintain stable link updates in dynamic collaborative scenarios with heterogeneity or lack of modality, making it very suitable for promotion and deployment in real-world scenarios. For new access terminals, this application can achieve rapid adaptation under cold start conditions, balancing personalized performance gains with the maintenance of generalization capabilities.
[0172] In one embodiment, a medical question-answering method and system based on causal graphs and counterfactual reasoning distillation is provided for edge-end causal reasoning question-answering services in primary healthcare institutions. In remote consultation scenarios at primary healthcare institutions (such as community health service centers and township hospitals), primary care physicians often lack sufficient specialist knowledge to support complex medical questions and need to obtain causal-enhanced diagnostic suggestions through intelligent question-answering systems. The core challenges of this scenario include: limited and unstable network bandwidth, making it impossible to rely on large cloud models for real-time inference; lack of high-performance computing equipment in primary healthcare institutions, requiring model deployment on lightweight edge terminals; and diverse and widely distributed case types, necessitating the model's ability to generalize causally to novel cases outside the training set. This embodiment deploys a 250M-parameter student model after CRD distillation on an edge medical terminal, combining it with a local compressed knowledge base to achieve offline causal reasoning question-answering services, focusing on verifying the improvement effect of causal reasoning distillation on out-of-distribution generalization; the specific process is as follows... Figure 8 As shown:
[0173] N1: Primary healthcare problem collection and standardization. Primary care physicians input patient complaints and basic examination information (such as "elderly patient, recurrent dizziness, large fluctuations in blood pressure, still unstable after taking medication") through portable medical terminals. The terminal performs medical entity standardization and word segmentation on the input to generate a standardized problem representation that is adapted to the cause-effect graph extraction module.
[0174] N2: Causal graph extraction and causal link identification. The causal graph extraction module extracts entities such as "dizziness," "blood pressure fluctuation," "medication," and "instability" from the standardized problem, calculates causal dependency scores, constructs a causal graph, and identifies causal links such as "blood pressure fluctuation → insufficient blood supply to the brain → dizziness." This step is completed locally on the edge terminal without a network connection.
[0175] N3: Local knowledge base retrieval and document matching. The intensive retrieval module utilizes a pre-installed compressed medical knowledge base on the edge terminal (containing causal knowledge summaries of common diseases and primary care guidelines) to perform vector retrieval and reordering on the current question, returning knowledge documents related to causal reasoning. The knowledge base size is approximately the target performance of a standard knowledge base, but it covers causal knowledge of common diseases at the primary care level.
[0176] N4: Counterfactual generation and distillation reasoning. The counterfactual generation module was completed during the offline distillation training phase, and the edge terminal directly used the distilled student model for reasoning. Based on its learned counterfactual reasoning ability, the model performs causal reasoning on the current case, such as "whether blood pressure control will improve if the medication regimen is adjusted." According to the pre-set StrategyQA generalization data, CRD achieved the target performance on causal questions, significantly improving the target performance of KARD by several percentage points, verifying the enhancing effect of causal distillation on out-of-distribution generalization.
[0177] N5: Causal Intervention Inference and Drug Regimen Evaluation. The causal intervention inference module performs CATE estimation on candidate drug adjustment regimens (such as increasing antihypertensive drug dosage, changing drug class, and combination therapy) based on the local causal graph, predicting the causal effect of each regimen on patient blood pressure stability. Based on pre-set data, CRD achieves the target performance in counterfactual inference accuracy, significantly improving the target performance of KARD by several percentage points.
[0178] N6: Causal consistency verification and reasoning self-consistency assurance. The consistency verification module performs a three-dimensional consistency check on the reasoning chain at the edge terminal to ensure the logical self-consistency of the causal reasoning link such as "medication adjustment → blood pressure change → symptom relief". When the consistency check fails, the system marks the credibility level of the reasoning conclusion as lower and prompts primary care physicians to refer to it with caution.
[0179] N7: Causal mechanism extraction and primary care-friendly explanation output. The mechanism extraction module generates simplified causal mechanism descriptions, explaining the causal basis for "why this medication adjustment plan is recommended" in language understandable to primary care physicians. It also includes causal strength indicators for physicians to assess the reliability of the recommendation. Based on pre-set data, the CRD's mechanism explanation coverage reaches the target performance, providing primary care physicians with rich interpretable information.
[0180] N8: The system outputs diagnostic suggestions and collaborates with remote experts. Causal inference results are output to the terminal interface in the form of structured question-and-answer cards, including diagnostic suggestions, causal inference chains, mechanism explanations, and credibility levels. For complex cases with low credibility, the system automatically generates referral suggestions and sends anonymized causal inference summaries to the higher-level hospital's remote consultation center via an encrypted channel, forming a closed-loop service link of "grassroots inference → remote collaboration → knowledge feedback." The complete CRD solution significantly improves upon the baseline version using only causal graphs by several percentage points, with significant synergistic gains across modules.
[0181] In the grassroots medical edge deployment scenario of this embodiment, this solution, while ensuring the final judgment and inference effect, can significantly control the average communication overhead and inference load per page or per round, and can maintain stable link updates in dynamic collaborative scenarios with heterogeneity or lack of modality, making it very suitable for promotion and deployment in real-world scenarios. For new access terminals, this application can achieve rapid adaptation under cold start conditions, balancing personalized performance gains with the maintenance of generalization capabilities.
[0182] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 9 As shown, the computer device includes a processor, memory, network interface, display screen, and input devices connected via a system bus. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The network interface is used to communicate with external terminals via a network connection. When executed by the processor, the computer program implements a medical question-and-answer method based on causal graphs and counterfactual reasoning. The display screen can be an LCD screen or an e-ink screen. The input devices can be a touch layer covering the display screen, buttons, a trackball, or a touchpad mounted on the computer device casing, or an external keyboard, touchpad, or mouse.
[0183] Those skilled in the art will understand that Figure 9 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0184] In one embodiment, a computer device is provided, including a memory and a processor, the memory storing a computer program, the processor executing the computer program to implement the steps of a medical question-answering method based on causal graphs and counterfactual reasoning distillation.
[0185] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon, which, when executed by a processor, implements the steps of a medical question-answering method based on causal graphs and counterfactual reasoning distillation.
[0186] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0187] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0188] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of the invention. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A medical question-answering method based on causal graphs and counterfactual reasoning distillation, characterized in that, The method includes: Obtain medical question text, use a pre-trained language model to perform medical entity recognition on the medical question text, extract medical entities and their type labels, calculate the causal dependency score between the medical entities, and construct a directed acyclic causal graph based on the causal dependency score. The candidate documents corresponding to the medical question text are retrieved from an external medical knowledge base using a dual encoder, and the candidate documents are reordered to obtain knowledge-enhanced documents. Value intervention is performed on key nodes in the directed acyclic causal graph to generate counterfactual questions. The teacher model is then used in conjunction with the knowledge-enhanced document to generate the counterfactual reasoning chain and counterfactual answer corresponding to the counterfactual questions. The joint distillation loss is calculated based on the original samples and counterfactual samples to update the parameters of the student model, resulting in a student model with causal reasoning ability. Based on the directed acyclic causal graph, the causal effect of the treatment plan is estimated by backdoor adjustment to obtain the average intervention effect and conditional average intervention effect of the treatment plan. The generated inference chain is subjected to causal consistency verification. If the verification fails, an inconsistency signal is fed back to the link that generated the inference chain, and the inference chain is regenerated or adjusted until the causal consistency verification is passed. Then, the causal relationship in the verified inference chain is extracted to obtain the causal mechanism description and causal strength index. Based on the average intervention effect and the conditional average intervention effect, the candidate treatment options are prioritized to generate a final answer and treatment recommendations. The reasoning chain verified by causal consistency, the description of the causal mechanism, and the causal strength index are integrated to generate a causal reasoning report.
2. The medical question-answering method based on causal graphs and counterfactual reasoning distillation according to claim 1, characterized in that, The process involves acquiring medical question text, performing medical entity recognition on the text using a pre-trained language model, extracting medical entities and their type labels, calculating causal dependency scores between the medical entities, and constructing a directed acyclic causal graph based on the causal dependency scores. The process involves acquiring medical question text, performing word segmentation and standardization on the medical question text, mapping the processed text to standardized medical terms, determining the question type, and generating a structured text representation. The structured text representation is encoded using a pre-trained language model to obtain a contextual semantic representation, which is then input into a conditional random field sequence labeling classifier to identify medical entities in the text and assign type labels to each medical entity. For each medical entity, a causal dependency score from the first entity to the second entity is calculated using a causal dependency score network. The causal dependency score is used to characterize the probability that one medical entity has a causal influence on another medical entity. The positive causal dependency score of the first entity to the second entity and the negative causal dependency score of the second entity to the first entity are calculated respectively to distinguish the direction of causal association. All medical entities are treated as nodes. Directed edges are established between entity pairs whose causal dependency scores are greater than a preset threshold to construct an adjacency matrix, and an acyclic constraint is imposed on the adjacency matrix. During training, the acyclic constraint is transformed into a penalty term and added to the loss function using the augmented Lagrange method. The penalty term is constructed based on the square of the difference between the matrix exponent trace of the adjacency matrix and the number of entities. Finally, a directed acyclic causal graph is output.
3. The medical question-answering method based on causal graphs and counterfactual reasoning distillation according to claim 1, characterized in that, Candidate documents corresponding to the medical question text are retrieved from an external medical knowledge base using a dual encoder, and these candidate documents are then reordered to obtain knowledge-enhanced documents, including: The query encoder in the dual encoder is used to encode the medical question text, extract semantic features, and perform pooling to obtain a query vector; the context encoder in the dual encoder is used to encode candidate documents in an external medical knowledge base, extract semantic features, and perform pooling to obtain a document vector. The inner product is used to calculate the retrieval relevance score between the query vector and the document vector, and a set of candidate documents is selected from the external medical knowledge base based on the retrieval relevance score. A cross-attention reorderer is used to calculate the interaction representation between the medical question text and each candidate document through a multi-head cross-attention function, capturing the semantic association between each word in the query and each word in the document. The cross-attention output is then transformed nonlinearly by a feedforward network and the reordering score is obtained through linear projection and activation function. The candidate document set is sorted according to the re-sorting score, and knowledge-enhanced documents are selected based on the sorted candidate document set.
4. The medical question-answering method based on causal graphs and counterfactual reasoning distillation according to claim 1, characterized in that, Value intervention is performed on key nodes in the directed acyclic causal graph to generate counterfactual questions, and counterfactual reasoning chains and counterfactual answers are generated by combining the teacher model with the knowledge-enhanced document. The joint distillation loss is calculated based on the original sample and the counterfactual sample. The parameters of the student model are then updated to obtain a student model with causal reasoning capabilities, including: Select the causal path corresponding to the medical question text from the directed acyclic causal graph, perform value intervention operations on the key nodes in the causal path, and generate a counterfactual question; The counterfactual question and the knowledge-enhanced document are input into the teacher model. The teacher model, in combination with the knowledge-enhanced document, generates the counterfactual reasoning chain and counterfactual answer corresponding to the counterfactual question. The teacher model also generates the original reasoning chain and original answer for the original question. The counterfactual reasoning chain and the counterfactual answer, along with the original reasoning chain and the original answer, are used together as distillation supervision signals. Based on the original samples and counterfactual samples, the original reasoning chain loss, the original answer loss, the counterfactual reasoning chain loss, and the counterfactual answer loss are calculated respectively to obtain the joint distillation loss. The gradient signal of the combined distillation loss is calculated, the gradient of each parameter of the student model is calculated through backpropagation, and the parameters of the student model are updated using the gradient descent algorithm to obtain a student model with causal reasoning ability.
5. The medical question-answering method based on causal graphs and counterfactual reasoning distillation according to claim 1, characterized in that, Based on the directed acyclic causal graph, causal effect estimation of the treatment plan is performed through backdoor adjustment to obtain the average intervention effect and conditional average intervention effect of the treatment plan, including: Based on the directed acyclic causal graph, intervention variables that simultaneously point to treatment plan nodes and outcome variables that point to disease progression nodes are identified as confounding variables, forming a candidate confounding variable set; Based on the directed acyclic causal graph, all backdoor paths between treatment plans and disease progression are identified, and a backdoor adjustment set is obtained from the candidate confounding variable set according to the backdoor criterion. For each value of the confounding variable in the backdoor adjustment set, the conditional probability of the intervention variable and the outcome variable is calculated. The conditional probabilities of each layer are weighted and summed according to the marginal distribution of the confounding variable to obtain the distribution of disease progression after intervention. Based on the distribution of disease progression after the intervention, the difference between the expected value of disease progression with treatment and the expected value of disease progression without treatment is calculated as the average intervention effect; for patient subgroups with target patient feature vectors, the difference between the expected value of disease progression with treatment and the expected value of disease progression without treatment is calculated as the conditional average intervention effect.
6. The medical question-answering method based on causal graphs and counterfactual reasoning distillation according to claim 1, characterized in that, The generated inference chain is subjected to causal consistency verification. If the verification fails, an inconsistency signal is fed back to the link that generated the inference chain, and the inference chain is regenerated or adjusted until the causal consistency verification passes. After that, the causal relationships in the verified inference chain are extracted to obtain a causal mechanism description and a causal strength index, including: The reasoning chain is structured and analyzed, and the reasoning chain is divided into various reasoning steps. The causal triples in each reasoning step are identified and then summarized to obtain a set of causal triples. The inference chain is subjected to transit consistency, directional consistency, and evidentiary consistency checks respectively. If all three checks pass, the causal consistency verification is deemed successful; otherwise, the verification is deemed unsuccessful, and an inconsistency signal is generated. The inconsistency signal is added as an additional constraint to the input of the student model. The student model regenerates the inference chain and performs causal consistency verification again, forming an iterative correction loop until the causal consistency verification is passed. The causal mechanism is extracted from the inference chain that has passed the causal consistency verification, the described causal action path is extracted, and the causal action path is summarized and integrated to generate a structured causal mechanism description. Based on the causal relationship description of each reasoning step in the reasoning chain, and combining the average intervention effect and the conditional average intervention effect, a causal strength index is calculated.
7. The medical question-answering method based on causal graphs and counterfactual reasoning distillation according to claim 1, characterized in that, Based on the average intervention effect and the conditional average intervention effect, the candidate treatment options are prioritized, and a final answer and treatment recommendations are generated, including: Extract all candidate treatment plan nodes related to the current disease from the directed acyclic causal graph, and traverse the treatment plan nodes pointing to the disease progression nodes in the directed acyclic causal graph. The treatment plan nodes are combined with the treatment plans in the knowledge-enhanced document to supplement the directed acyclic causal graph, forming a candidate treatment plan list; The candidate treatment options in the candidate treatment option list are ranked as a whole based on the average intervention effect; for patient subgroups with target feature vectors, the ranking is personalized based on the conditional average intervention effect. A multi-objective ranking is generated based on the results of the overall ranking and the personalized ranking. The candidate treatment plan ranked first in the multi-objective ranking is selected as the recommended treatment plan. Combined with the reasoning chain that has been verified by causal consistency, the final answer and treatment suggestions are generated.
8. The medical question-answering method based on causal graphs and counterfactual reasoning distillation according to claim 7, characterized in that, The inference chain verified for causal consistency, the description of the causal mechanism, and the causal strength index are integrated to generate a causal inference report, including: Construct a causal reasoning report template, and fill the knowledge enhancement document, directed acyclic causal graph, average intervention effect and conditional average intervention effect, causal mechanism description and causal strength index, final answer and treatment suggestions into the structured fields corresponding to the causal reasoning report template to generate a causal reasoning report; The causal reasoning report will be output in a structured document format.
9. A medical question-answering system based on causal graphs and counterfactual reasoning distillation, characterized in that, The system includes: The causal graph construction module is used to acquire medical question text, perform medical entity recognition on the medical question text using a pre-trained language model, extract medical entities and their type labels, calculate the causal dependency score between the medical entities, and construct a directed acyclic causal graph based on the causal dependency score. The knowledge enhancement module is used to retrieve candidate documents corresponding to the medical question text from an external medical knowledge base through dual encoders, and to reorder the candidate documents to obtain knowledge-enhanced documents; The counterfact generation module is used to intervene in the key nodes of the directed acyclic causal graph, generate counterfactual questions, and use the teacher model in combination with the knowledge-enhanced document to generate the counterfactual reasoning chain and counterfactual answer corresponding to the counterfactual questions; calculate the joint distillation loss based on the original sample and the counterfactual sample, update the parameters of the student model, and obtain a student model with causal reasoning ability. The causal intervention reasoning module is used to estimate the causal effect of the treatment plan based on the directed acyclic causal graph and through backdoor adjustment, so as to obtain the average intervention effect and conditional average intervention effect of the treatment plan. The causal consistency verification and mechanism extraction module is used to verify the causal consistency of the generated inference chain. If the verification fails, an inconsistency signal is fed back to the link that generated the inference chain, and the inference chain is regenerated or adjusted until the causal consistency verification passes. Then, the mechanism is extracted from the causal relationship in the verified inference chain to obtain the causal mechanism description and causal strength index. The report output module is used to prioritize each candidate treatment plan based on the average intervention effect and the conditional average intervention effect, generate a final answer and treatment recommendations, and integrate the reasoning chain verified by causal consistency, the description of the causal mechanism, and the causal strength index to generate a causal reasoning report.
