An intelligent question and answer method for digestive system diseases based on a knowledge graph
By combining encoders and decoders based on the Transformer architecture with knowledge graphs and reinforcement learning, knowledge subgraphs are dynamically constructed, solving the problems of reference resolution and deep reasoning in multi-turn dialogues in existing intelligent question answering systems, and achieving accurate and logically clear question-answering responses in the field of digestive system diseases.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- YANCHENG DAFENG PEOPLES HOSPITAL
- Filing Date
- 2026-03-03
- Publication Date
- 2026-06-05
AI Technical Summary
Existing intelligent question-answering systems lack the ability to resolve referential issues, dynamically shift user intent, and perform deep multi-hop reasoning in multi-turn dialogues. This leads to fragmented dialogue context and disjointed information, affecting user experience and the accuracy of decision support.
Employing an encoder and decoder based on the Transformer architecture, combined with knowledge graphs and reinforcement learning, this approach integrates dialogue-internal self-attention and dialogue-knowledge cross-attention mechanisms to generate knowledge-enhanced dialogue state vectors. It dynamically constructs knowledge subgraphs and explores multi-hop reasoning paths through reinforcement learning agents, ultimately generating logically clear natural language responses.
It achieves accurate responses to complex, multi-turn questions in the field of digestive system diseases, ensuring that the responses are accurate, logically clear, and highly interpretable, thereby improving the overall performance and usability of the system.
Smart Images

Figure CN122152993A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of disease learning and question answering, and more specifically, to an intelligent question answering method for digestive system diseases based on knowledge graphs. Background Technology
[0002] With the deep integration of medical informatics and artificial intelligence technologies, intelligent question-answering systems have demonstrated significant value in scenarios such as assisting in the diagnosis and treatment of digestive system diseases, patient health management, and medical education. In practical applications, user interaction with the system is often not a simple, one-round query, but involves a multi-round, progressive, in-depth consultation process. For example, in clinical decision support scenarios, doctors may first inquire about the potential causes of a specific symptom, and then, based on the list of causes provided by the system, further inquire about the key points of differential diagnosis for a specific cause, recommended treatment plans, or their possible side effects. In patient health consultation scenarios, users may start by describing their symptoms, and then continuously ask a series of related questions about dietary restrictions, precautions for taking medication, and subsequent steps if initial measures are ineffective. The core characteristic of this type of dialogue is that the accurate understanding of subsequent questions heavily relies on capturing and reasoning from the historical context of the preceding dialogue. User intent is often implicit in a coherent semantic flow and requires logical association and multi-step deduction based on domain knowledge to clarify and satisfy. However, the currently widely used question-answering technology frameworks have significant limitations in their service capabilities when faced with such complex and coherent interactive needs.
[0003] In existing technologies, intelligent question-answering systems based on information retrieval mostly rely on keyword matching or shallow semantic similarity calculation, treating each user's question as an independent query and retrieving the most relevant fragments from structured knowledge bases or unstructured documents as responses. Although knowledge graph-based methods improve the accuracy of single-point factual queries to some extent by utilizing their structured semantic networks, their dialogue management mechanisms remain weak. Specifically, existing solutions struggle to effectively address the core challenges in multi-turn dialogues: first, the problem of referential resolution and omission recovery commonly found in dialogue history. For example, when users use pronouns like "it" or "this disease," or directly omit subjects already mentioned in the preceding text, the system cannot accurately link back to previous entities or concepts; second, the problem of dynamic migration and continuity maintenance of user intent, i.e., the system lacks the ability to track continuous... The existing system suffers from several technical bottlenecks. First, it lacks the ability to model the logical progression between questions, failing to understand the domain knowledge connections between "possible causes of stomach pain" and "corresponding dietary advice," leading to a break in the dialogue context. Second, it lacks deep multi-hop reasoning capabilities. When a user's question requires connecting relationships and entities across multiple hops in the knowledge graph to arrive at an answer, such as reasoning from "ineffective after taking a certain drug" to "alternative treatment options to consider or complications to be investigated," the current system's usual shallow retrieval or simple graph traversal methods cannot guarantee the accuracy and completeness of the reasoning path. These technical bottlenecks cause the existing system to easily produce irrelevant, contradictory, or inaccessible responses when faced with coherent medical consultations. This not only seriously affects user experience and trust but may also pose potential risks in decision-making scenarios due to the provision of incoherent and incomplete information. Summary of the Invention
[0004] This invention addresses the technical problems existing in the prior art by providing a knowledge graph-based intelligent question-answering method for digestive system diseases, thereby resolving the issues raised in the background section.
[0005] The technical solution of this invention to solve the above-mentioned technical problems is as follows: specifically, it includes the following steps: Step S1: Receive the current user query and dialogue history sequence, input the current user query and dialogue history sequence into the encoder based on the Transformer architecture respectively to obtain the first dialogue encoding vector and the second dialogue encoding vector, and concatenate the first dialogue encoding vector and the second dialogue encoding vector into a comprehensive dialogue encoding vector; extract the entity vector and relation vector from the pre-constructed digestive system disease knowledge graph, use the comprehensive dialogue encoding vector as the query vector, and use the entity vector and relation vector as the key vector and value vector, and calculate through a dual attention mechanism that integrates dialogue internal self-attention and dialogue-knowledge cross-attention, and output the knowledge-enhanced dialogue state vector; Step S2: Based on the knowledge attention weight distribution row vectors corresponding to each entity in the knowledge-enhanced dialogue state vector, select entities with weights higher than a preset threshold from the digestive system disease knowledge graph to form an initial seed node set; Starting from the initial seed node set, perform an iterative walk based on graph attention network on the digestive system disease knowledge graph. In each iterative walk, calculate the information transmission weight of the neighbor node based on the current node feature vector, its neighbor node feature vectors, and the knowledge-enhanced dialogue state vector. After at least one iteration, output a dynamic knowledge subgraph related to the current dialogue context. Step S3: Construct the dynamic knowledge subgraph into a reinforcement learning environment and initialize a reinforcement learning agent. The state of the reinforcement learning agent is a node in the dynamic knowledge subgraph, and the action is to select a relation edge from the current node to jump. According to its policy network, the reinforcement learning agent explores the dynamic knowledge subgraph starting from the nodes of the initial seed node set and generates a multi-hop inference path from the starting node to the target node. The update of the policy network depends on a reward function that integrates the correlation of single-step actions, the global consistency of the path, and the confidence of the target node. Step S4: Input the knowledge-enhanced dialogue state vector, dynamic knowledge subgraph, and multi-hop inference path into the decoder based on the Transformer architecture; linearize the multi-hop inference path into a path sequence and use it as additional input to the decoder; when generating each word of the natural language response, the decoder simultaneously focuses on the integrated dialogue encoding vector and the path sequence, and the policy network of the reinforcement learning agent and the decoder jointly optimize the parameters, wherein the quality of the response generated by the decoder is fed back as an additional reward signal for optimizing the policy network; In a preferred embodiment, the specific process of concatenating the first dialogue encoding vector and the second dialogue encoding vector into a comprehensive dialogue encoding vector in step S1 is as follows: Receive the current query word vector sequence converted from the current user query, and the historical dialogue word vector sequence converted from the dialogue history sequence; The current query word vector sequence and the historical dialogue word vector sequence are respectively input into the same encoder based on the Transformer architecture. The encoder includes a multi-head self-attention mechanism and a feedforward neural network. The current query word vector sequence is processed and the output context vector representing the semantics of the current query is used as the first dialogue encoding vector. At the same time, the historical dialogue word vector sequence is processed and the output context vector representing the semantics of the historical dialogue is used as the second dialogue encoding vector. The first dialogue encoding vector and the second dialogue encoding vector are concatenated along their feature dimensions to generate a comprehensive dialogue encoding vector that integrates the semantics of the current query and all historical dialogues.
[0006] In a preferred embodiment, the specific process of outputting the knowledge-enhanced dialogue state vector is as follows: A1. Knowledge Embedding Preparation: From the pre-trained embedding representation of the digestive system disease knowledge graph, obtain the entity vectors corresponding to each of the N entities. Form an entity vector matrix with N rows from these N entity vectors. Also, obtain the relation vectors corresponding to each of the M relations. Form a relation vector matrix with M rows from these M relation vectors. The entity vectors and relation vectors have the same feature dimension d. Concatenate the entity vector matrix and relation vector matrix along the row direction to form a knowledge embedding matrix with N+M rows and d columns. A2. Vector Projection Transformation: The integrated dialogue encoding vector is mapped to a query vector by a learnable linear transformation, namely by multiplying it by a first learnable weight matrix used to generate the query vector; the knowledge embedding matrix is mapped to a key vector matrix by multiplying it by a second learnable weight matrix used to generate the key vector; the knowledge embedding matrix is mapped to a value vector matrix by multiplying it by a third learnable weight matrix used to generate the value vector. A3. Gated Attention Weight Calculation: Calculate the product of the query vector and the key vector matrix, and divide the product by a preset scaling factor to obtain the initial attention score matrix; multiply the query vector by a fourth learnable weight matrix used to generate the gating vector and perform a non-linear activation function transformation to generate a gating row vector with the same dimension as the projection dimension of the query vector and the key vector matrix; multiply the initial attention score matrix element-wise with the gating matrix obtained by expanding the gating row vector into matrix form to modulate the initial attention score matrix; apply a normalized exponential function to the last dimension of the modulated matrix to obtain the knowledge attention weight distribution row vector reflecting the relevance of each knowledge element to the current dialogue; A4. State Vector Synthesis: Multiply the row vector of knowledge attention weight distribution with the value vector matrix to obtain a weighted knowledge context vector; add the weighted knowledge context vector to the original, untransformed integrated dialogue encoding vector; perform layer normalization on the addition result to output the knowledge-enhanced dialogue state vector.
[0007] In a preferred embodiment, step S2 involves selecting entities with weights higher than a preset threshold from the digestive system disease knowledge graph based on the knowledge attention weight distribution row vectors corresponding to each entity in the knowledge-enhanced dialogue state vector. This specifically includes: Obtain the knowledge attention weight distribution row vector synchronously obtained during the computation of the knowledge-enhanced dialogue state vector. The knowledge attention weight distribution row vector sequentially contains the relevance weights of all entities and all relations in the digestive system disease knowledge graph to the current dialogue. The first row vector contains consecutive weight values, the same number as the total number of entities in the knowledge graph, corresponding to each entity. Extract these consecutive weight values corresponding to entities to form an entity attention weight vector. Set a filtering threshold. Compare the weight value of each entity in the entity attention weight vector with the filtering threshold, and select entities whose weight values are all greater than the filtering threshold. Gather the identifiers of these selected entities to form an initial seed node set.
[0008] In a preferred embodiment, the specific process of outputting a dynamic knowledge subgraph related to the current dialogue context is as follows: Using the initial seed node set as the activation node set for the zeroth iteration, and pre-setting a maximum iteration walk depth; starting from the zeroth iteration, perform the following steps until the maximum iteration walk depth is reached: For each node in the activation node set corresponding to the current iteration, perform the following operations: First, the entity vector corresponding to the node is obtained from the pre-trained embedding representation of the digestive system disease knowledge graph, serving as its current feature vector. Next, all directly adjacent nodes of the node in the digestive system disease knowledge graph are traversed, and the entity vector corresponding to each adjacent node is obtained from the pre-trained embedding representation of the digestive system disease knowledge graph, serving as its current feature vector. Simultaneously, the relationship type from the current node to each adjacent node is recorded. Then, for each adjacent node, a weight score is calculated. This calculation process involves multiplying the knowledge-enhanced dialogue state vector from step S1 by a first learnable weight matrix to obtain a context query vector; and then multiplying the feature vector of the current node by the feature vector of the adjacent node. The features are concatenated along the feature dimension to form a combined feature vector. A learnable diagonal matrix that uniquely corresponds to the relationship type from the current node to its neighboring node is multiplied by the transpose of the combined feature vector to achieve a relationship-aware transformation of the combined feature vector. The context query vector and the result of the relationship-aware transformation are then subjected to a vector dot product operation, and then processed by a linear rectified activation function with leakage to obtain an initial association score. After calculating the initial association score for each neighboring node of the current node, all initial association scores are input into a normalized exponential function for processing, so that all scores are transformed into a probability distribution. Each value in this probability distribution is the normalized information transmission weight of the corresponding neighboring node relative to the current node. Then, based on the normalized information transmission weights, the feature vectors of each adjacent node are weighted and summed. The result of the weighted sum is processed by an activation function to obtain the updated feature vector of the current node. At the same time, all neighboring node identifiers with normalized weights are collected to form the set of active nodes for the next iteration. Once the iteration process is complete, all the nodes that have been activated in each iteration, along with the connecting edges between these nodes in the knowledge graph, together constitute a dynamic knowledge subgraph.
[0009] In a preferred embodiment, step S3, which involves constructing the dynamic knowledge subgraph into a reinforcement learning environment, specifically involves the following steps: The dynamic knowledge subgraph from step S2 is directly defined as the environment of the Markov decision process; the state space of this environment is the set of all nodes in the dynamic knowledge subgraph; the action space of this environment is: In any given state, that is, when the given state corresponds to the current node, it is the set of all available relation edges starting from the current node; The interaction between the reinforcement learning agent and the environment is manifested as follows: Given the current state, i.e. the current node, the reinforcement learning agent takes an action, i.e., selects a relation edge starting from the current node. The environment then, based on the inherent graph structure of the dynamic knowledge subgraph, deterministically transfers the reinforcement learning agent to the neighbor node directly pointed to by the selected relation edge, and returns an immediate reward to the reinforcement learning agent corresponding to this state transition. The interaction system formed by this is the reinforcement learning environment.
[0010] In a preferred embodiment, the reward function, which integrates the relevance of single-step actions, global path consistency, and target node confidence, is specifically configured as follows: The reward function is a weighted sum of three independent reward components. For a complete exploration that generates a sequence of alternating nodes and edges, the total reward is the weighted sum of the three reward components. The single-step action relevance reward is calculated and accumulated once when the reinforcement learning agent selects an edge. The path global consistency reward is calculated and accumulated once when the reinforcement learning agent reaches a new node, based on the entire partial path up to that node. The target node confidence reward is calculated and accumulated only once when the alternating node and edge sequence terminates, based on the terminating node. The three reward components are weighted by a first weight coefficient, a second weight coefficient, and a third weight coefficient, respectively, and the first weight coefficient, the second weight coefficient, and the third weight coefficient are preset positive scalar values. The first reward component is the single-step action relevance reward. The value of the single-step action relevance reward is directly set as the information transmission weight calculated and normalized for the start node and end node of the selected relationship edge in the corresponding iteration round during the graph attention iterative walk in step S2. The second reward component is the path global consistency reward. The calculation process for the path global consistency reward is as follows: First, the visited node and edge sequence is encoded into a path vector through a sequence encoding structure; then, this path vector is concatenated with the knowledge-enhanced dialogue state vector to form a combined vector; next, the combined vector is input into a multilayer perceptron consisting of a fully connected layer for calculation; finally, the Sigmoid function is applied to the output of the multilayer perceptron to obtain a matching degree score between zero and one, which is the value of the path global consistency reward. The third reward component is the target node confidence reward, which is triggered only when a complete exploration path of the reinforcement learning agent terminates. The value of the target node confidence reward is calculated through a preset confidence function, which takes the identifier of the path endpoint node as input and returns a scalar value representing its credibility as an answer based on the prior meta-information of the entity node in the digestive system disease knowledge graph.
[0011] In a preferred embodiment, the reinforcement learning agent explores and updates its policy network according to its policy network, specifically as follows: The reinforcement learning agent includes a parameterized policy network, which is a learnable function whose input is the current state representation. This current state representation is obtained by concatenating the following two vectors along the feature dimension: the first vector is the updated feature vector corresponding to the current node after the graph attention iterative walk in step S2, and the second vector is the knowledge-enhanced dialogue state vector from step S1. The policy network takes the current state representation as input, performs a series of linear transformations and non-linear activation processes on it, and outputs a real number vector. A normalized exponential function is applied to this real number vector to transform it into a probability distribution, which is defined as the action probability distribution. The reinforcement learning agent selects actions based on the action probability distribution and explores multiple complete trajectories in the reinforcement learning environment. Each trajectory is a sequence of alternating nodes and edges that start from nodes in the initial seed node set and end at the termination node. After collecting all exploration trajectories, the total cumulative reward for each trajectory is calculated according to the reward function. The parameters of the policy network are updated using a proximal policy optimization algorithm. The parameter update steps of the near-end policy optimization algorithm include: H1. Based on the trajectory data collected from the parameters of the old version of the policy network, calculate the importance sampling ratio, which is the ratio of the probability of the new policy network and the old policy network selecting the same action in the same state in the trajectory. H2. Calculate the advantage function estimate of the trajectory based on the total cumulative reward; H3. Perform a pruning operation on the importance sampling ratio, restricting its value to a closed interval centered at 1 with a preset small positive number ε as the interval radius; H4. Calculate the product of the importance sampling ratio and the advantage function estimate before the pruning operation, and also calculate the product of the importance sampling ratio and the advantage function estimate after the pruning operation. H5. Take the smaller of the two products in H4 as the contribution of the current trajectory to the parameter update objective function; H6. By maximizing the expected value of the contributions of all trajectories, an objective function for parameter updates is constructed, and this objective function is optimized using the gradient ascent method, thereby iteratively updating the parameters of the policy network. After multiple rounds of iterative training, the updated policy network guides the reinforcement learning agent to generate a sequence of nodes and edges that yield high total cumulative rewards in the dynamic knowledge subgraph, starting from the initial seed node. This sequence is the multi-hop inference path.
[0012] In a preferred embodiment, step S4, which involves linearizing the multi-hop inference path into a path sequence and then using it as additional input to the decoder, specifically involves: Obtain the multi-hop reasoning path from step S3. This path is a sequence consisting of alternating connections between nodes and relation edges. The specific form of the multi-hop reasoning path is: starting node, followed by the first relation edge connecting the starting node, then the first node reached via the first relation edge, followed by the second relation edge connecting the first node, and so on until the terminating node, forming a chain sequence in which nodes and relation edges appear alternately. The multi-hop inference path is linearized and encoded. The linearization process includes the following steps: First, each node and each relation edge in the multi-hop inference path is assigned a predefined and unique text tag. Then, these text tags are arranged in order of their appearance in the multi-hop inference path to form an initial ordered text sequence. Next, a start text tag is added at the beginning of the initial ordered text sequence and an end text tag is added at the end of the sequence to construct a complete path text sequence. Input this path text sequence into a word embedding layer, and map each text token into a fixed-dimensional real-valued vector, thereby transforming the entire path text sequence into a path vector sequence.
[0013] In a preferred embodiment, when generating each word of a natural language response, the decoder simultaneously focuses on the integrated dialogue encoding vector and path sequence, and the policy network of the reinforcement learning agent and the decoder jointly optimize the parameters. The specific process includes: The decoder, based on the Transformer architecture, takes the synthesized dialogue encoding vector from step S1 as its basic input. An additional path attention sublayer is set in one network layer of the decoder. At each time step of generating a response, the current hidden state of the decoder is used as the query vector for two cross-attention operations: the first cross-attention operation uses the synthesized dialogue encoding vector as the key and value; the second cross-attention operation, namely the path attention sublayer, uses the path vector sequence as the key and value. The computation process of the path attention sublayer is as follows: First, the current hidden state vector of the decoder is concatenated with the knowledge-enhanced dialogue state vector from step S1 along the feature dimension to obtain a concatenated vector. This concatenated vector is then input into a learnable linear transformation layer for processing, and a dynamic gating vector is generated by passing the Sigmoid activation function. Next, the current hidden state vector of the decoder is linearly transformed through a learnable query weight matrix to obtain a query vector. The path vector sequence is linearly transformed through a learnable key weight matrix to obtain a key vector sequence. Then, the dot product between the query vector and the transpose of the key vector sequence is calculated, and the dot product result is divided by a scaling factor determined based on the attention space dimension to obtain the initial attention score matrix. The initial attention score matrix is modulated using the dynamic gating vector. A normalized exponential function is applied to the modulated result to obtain the final path attention weight distribution. Finally, the path vector sequence is linearly transformed through a learnable value weight matrix to obtain a value vector sequence, and the value vector sequence is weighted and summed using the path attention weight distribution to output the path context vector. The decoder is trained using a standard language modeling loss function to optimize its generation capabilities. At the same time, a response quality assessment process is introduced to automatically evaluate the complete natural language response generated by the decoder and obtain a quality score, which is defined as a quality reward. The total reward used to update the policy network parameters of the reinforcement learning agent is specifically calculated as follows: the total cumulative reward calculated in step S3 for generating multi-hop inference paths is weighted and summed with the quality reward. The total reward is used to calculate the policy gradient, thereby updating the parameters of the policy network; The parameter update of the policy network and the parameter training of the decoder together constitute a joint optimization process. In this joint optimization process, the optimization objective of the policy network incorporates the evaluation of the internal quality of the multi-hop inference path and the evaluation of the quality of the final generated response through the total reward. This drives the policy network to learn to generate inference paths that not only obtain high path rewards but also support the decoder to produce high-quality responses.
[0014] The beneficial effects of this invention are as follows: By integrating deep semantic understanding and knowledge graph reasoning, it achieves accurate responses to complex multi-turn question-and-answer problems in the field of digestive system diseases. Firstly, it deeply aligns user dialogue with the medical knowledge graph, dynamically focusing on relevant knowledge subgraphs. Then, through reinforcement learning, it explores logically coherent reasoning paths within these subgraphs, ultimately generating traceable answers based on the paths and dialogue history. This process ensures that the responses are not only accurate and logically clear but also highly interpretable. More importantly, by feeding the quality of the generated answers back to the optimization process of the reasoning path, it achieves end-to-end collaborative optimization from semantic understanding, knowledge retrieval, logical reasoning to language generation, significantly improving the overall performance and practicality of the system. Attached Figure Description
[0015] Figure 1 This is a flowchart of the method of the present invention. Detailed Implementation
[0016] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0017] In the description of this application, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more features. In the description of this application, "multiple" means two or more, unless otherwise explicitly specified.
[0018] In the description of this application, the term "for example" is used to mean "used as an example, illustration, or description." Any embodiment described as "for example" in this application is not necessarily to be construed as being more preferred or advantageous than other embodiments. The following description is provided to enable any person skilled in the art to make and use the invention. Details are set forth in the following description for purposes of explanation. It should be understood that those skilled in the art will recognize that the invention can be made without using these specific details. In other instances, well-known structures and processes will not be described in detail to avoid obscuring the description of the invention with unnecessary detail. Therefore, the invention is not intended to be limited to the embodiments shown, but is consistent with the broadest scope of the principles and features disclosed in this application.
[0019] Example 1 This embodiment provides, for example Figure 1 The method for intelligent question answering of digestive system diseases based on knowledge graphs, as shown, includes the following steps: Step S1: Receive the current user query and dialogue history sequence, input the current user query and dialogue history sequence into the encoder based on the Transformer architecture respectively to obtain the first dialogue encoding vector and the second dialogue encoding vector, and concatenate the first dialogue encoding vector and the second dialogue encoding vector into a comprehensive dialogue encoding vector; extract the entity vector and relation vector from the pre-constructed digestive system disease knowledge graph, use the comprehensive dialogue encoding vector as the query vector, and use the entity vector and relation vector as the key vector and value vector, and calculate through a dual attention mechanism that integrates dialogue internal self-attention and dialogue-knowledge cross-attention, and output the knowledge-enhanced dialogue state vector; Step S2: Based on the knowledge attention weight distribution row vectors corresponding to each entity in the knowledge-enhanced dialogue state vector, select entities with weights higher than a preset threshold from the digestive system disease knowledge graph to form an initial seed node set; Starting from the initial seed node set, perform an iterative walk based on graph attention network on the digestive system disease knowledge graph. In each iterative walk, calculate the information transmission weight of the neighbor node based on the current node feature vector, its neighbor node feature vectors, and the knowledge-enhanced dialogue state vector. After at least one iteration, output a dynamic knowledge subgraph related to the current dialogue context. Step S3: Construct the dynamic knowledge subgraph into a reinforcement learning environment and initialize a reinforcement learning agent. The state of the reinforcement learning agent is a node in the dynamic knowledge subgraph, and the action is to select a relation edge from the current node to jump. According to its policy network, the reinforcement learning agent explores the dynamic knowledge subgraph starting from the nodes of the initial seed node set and generates a multi-hop inference path from the starting node to the target node. The update of the policy network depends on a reward function that integrates the correlation of single-step actions, the global consistency of the path, and the confidence of the target node. Step S4: Input the knowledge-enhanced dialogue state vector, dynamic knowledge subgraph, and multi-hop inference path into the decoder based on the Transformer architecture; linearize the multi-hop inference path into a path sequence and use it as additional input to the decoder; when generating each word of the natural language response, the decoder simultaneously focuses on the integrated dialogue encoding vector and the path sequence, and the policy network of the reinforcement learning agent and the decoder jointly optimize the parameters, wherein the quality of the response generated by the decoder is fed back as an additional reward signal for optimizing the policy network.
[0020] In this embodiment, it is specifically necessary to explain the process of concatenating the first dialogue encoding vector and the second dialogue encoding vector into a comprehensive dialogue encoding vector in step S1 as follows: It receives the current query word vector sequence transformed from the current user query, and the historical dialogue word vector sequence transformed from the dialogue history sequence; the transformation includes word segmentation of the text, removal of stop words, and mapping each word to a fixed-dimensional vector using a pre-trained word embedding model, thereby forming a sequence; The current query word vector sequence and the historical dialogue word vector sequence are respectively input into the same encoder based on the Transformer architecture. This encoder includes a multi-head self-attention mechanism and a feedforward neural network. It processes the current query word vector sequence and outputs a context vector representing the semantics of the current query as the first dialogue encoding vector. At the same time, it processes the historical dialogue word vector sequence and outputs a context vector representing the semantics of the historical dialogue as the second dialogue encoding vector. The encoder is usually composed of multiple identical layers stacked together, such as 6 or 12 layers. Each layer contains a multi-head self-attention sublayer and a feedforward neural network sublayer, accompanied by residual connections and layer normalization operations to deeply capture the semantic dependencies within the sequence. The first dialogue encoding vector and the second dialogue encoding vector are concatenated along their feature dimensions to generate a comprehensive dialogue encoding vector that integrates the semantics of the current query and all historical dialogues. The concatenation operation can be implemented in tensor computation using the torch.cat or tf.concat functions. After ensuring that the feature dimensions of the two vectors are aligned, they are concatenated to form a comprehensive dialogue encoding vector with expanded dimensions. The specific process of outputting the knowledge-enhanced dialogue state vector is as follows: A1. Knowledge Embedding Preparation: From the pre-trained embedding representation of the digestive system disease knowledge graph, obtain the entity vectors corresponding to each of the N entities. These N entity vectors form an entity vector matrix with N rows. Also, obtain the relation vectors corresponding to each of the M relations. These M relation vectors form a relation vector matrix with M rows, where the entity vectors and relation vectors have the same feature dimension d. Concatenate the entity vector matrix and the relation vector matrix along the row direction to form a knowledge embedding matrix with N+M rows and d columns. Entities include, but are not limited to, diseases, symptoms, examinations, and drugs; relations include, but are not limited to, etiology, clinical manifestations, and treatment plans. The feature dimension d typically ranges from 256, 512, or 768. A2. Vector Projection Transformation: The integrated dialogue encoding vector is mapped to a query vector by a learnable linear transformation, namely, by multiplying it by a first learnable weight matrix used to generate the query vector; the knowledge embedding matrix is mapped to a key vector matrix by multiplying it by a second learnable weight matrix used to generate the key vector; the knowledge embedding matrix is mapped to a value vector matrix by multiplying it by a third learnable weight matrix used to generate the value vector; the first, second, and third learnable weight matrices project the feature dimension d of the input vector to a common attention space dimension. ,in Less than or equal to d, typically 64 or 128, to ensure computational efficiency and characterization capability;
[0021] A3. Gated Attention Weight Calculation: Calculate the product of the query vector and the key vector matrix, and divide the product by a preset scaling factor to obtain the initial attention score matrix. The preset scaling factor is the dimension of the attention space. The square root of the matrix is used to stabilize the gradient during training. The query vector is multiplied by a fourth learnable weight matrix used to generate the gate vector and transformed by a nonlinear activation function to generate a gated row vector with the same dimension as the projection dimension of the query vector and key vector matrices. The nonlinear activation function is the Sigmoid function, which constrains the output value to the range of 0 to 1, making each element of the gated row vector an independent modulation gate. The initial attention score matrix is then multiplied element-wise with the gated matrix obtained by expanding the gated row vector into matrix form to modulate the initial attention score matrix. The expansion operation involves multiplying the gated row vector with a... The column vectors with all elements equal to 1 are multiplied by a vector outer product to generate a gating matrix with the same dimensions as the initial attention score matrix. This element-wise multiplication causes each gate value in the gating row vector to modulate the attention intensity of the corresponding column in the initial attention score matrix. A normalized exponential function is applied to the last dimension of the modulated matrix to obtain a knowledge attention weight distribution row vector that reflects the relevance of each knowledge element to the current dialogue. Each weight value in the knowledge attention weight distribution row vector corresponds to the degree of relevance between a row of knowledge vectors (i.e., an entity or relation) in the knowledge embedding matrix and the comprehensive dialogue encoding vector of the current dialogue. The higher the weight value, the stronger the relevance. A4. State Vector Synthesis: Multiply the row vector of the knowledge attention weight distribution with the value vector matrix to obtain a weighted knowledge context vector. Add the weighted knowledge context vector to the original, untransformed integrated dialogue encoding vector. This operation is a residual connection, the purpose of which is to retain the original dialogue semantics while incorporating relevant knowledge information and avoid information loss. Perform layer normalization on the addition result to output a knowledge-enhanced dialogue state vector. The layer normalization process standardizes each feature dimension of the added vector to a mean of 0 and a variance of 1 to stabilize the network training process. The final output knowledge-enhanced dialogue state vector integrates accurate dialogue context and filtered, highly relevant knowledge information.
[0022] In this embodiment, it is specifically necessary to explain step S2, in which entities with weights higher than a preset threshold are selected from the digestive system disease knowledge graph based on the knowledge attention weight distribution row vectors corresponding to each entity in the knowledge-enhanced dialogue state vector to form an initial seed node set. This specifically includes: The knowledge attention weight distribution row vector is obtained synchronously during the computation of the knowledge-enhanced dialogue state vector. This row vector sequentially contains the relevance weights of all entities and relationships in the digestive system disease knowledge graph to the current dialogue. The first row contains consecutive weight values, the same number as the total number of entities in the knowledge graph, corresponding to each entity. This design ensures a clear order of correspondence between entities and weights, facilitating rapid indexing and extraction. These consecutive weight values corresponding to entities are extracted to form an entity attention weight vector. A filtering threshold is set; this threshold is a preset scalar value, such as 0.05, or a quantile value dynamically determined based on the statistical distribution of all weight values in the entity attention weight vector. For example, it might select the top 20% of all weight values after sorting from largest to smallest. The weight value is used to compare the weight value of each entity in the entity attention weight vector with the filtering threshold. Entities with all weight values greater than the filtering threshold are selected. Specifically, the entity attention weight vector is traversed, and each element is compared with the filtering threshold. If the element value is greater than the filtering threshold, the entity identifier corresponding to the index of the element in the vector is recorded in a temporary set. The identifiers of these selected entities are gathered together to form an initial seed node set. Each node in this set represents a core knowledge anchor point that is highly relevant to the current dialogue context. Through this threshold filtering mechanism, the focus can be adaptively placed on the few most relevant entities according to the attention intensity of the current dialogue, avoiding the introduction of too many noisy starting points and laying the foundation for subsequent accurate knowledge exploration. The selected entities constitute the precise launch points for the subsequent graph walk. The specific process of outputting a dynamic knowledge subgraph related to the current dialogue context is as follows: The initial seed node set is used as the activation node set for the zeroth iteration, and a maximum iteration walk depth is preset, for example, depth L=3, to balance the ability to explore multi-hop association knowledge with computational complexity. Starting from the zeroth iteration, the following steps are performed until the maximum iteration walk depth is reached: For each node in the activation node set corresponding to the current iteration, the following operations are performed: First, the entity vector corresponding to the node is obtained from the pre-trained embedding representation of the digestive system disease knowledge graph, serving as its current feature vector. Next, all directly adjacent nodes of the node in the digestive system disease knowledge graph are traversed, and the entity vector corresponding to each adjacent node is obtained from the pre-trained embedding representation of the digestive system disease knowledge graph, serving as its current feature vector. Simultaneously, the relationship type from the current node to each adjacent node is recorded. Then, for each adjacent node, a weight score is calculated. This calculation process involves multiplying the knowledge-enhanced dialogue state vector from step S1 with a first learnable weight matrix to obtain a contextual query vector. This vector encodes the global dialogue semantics into a vector form that can be used for targeted queries on the graph structure. The feature vector of the current node and the feature vector of the adjacent node are concatenated along the feature dimension to form a combined feature vector. Finally, a unique relation type corresponding to the relationship type from the current node to the adjacent node is selected. A learnable diagonal matrix is multiplied by the transpose of the combined feature vector to achieve a relation-aware transformation of the combined feature vector. The learnable diagonal matrix enables the model to distinguish the different importance of different semantic relations (such as "cause", "symptom", "treatment") in information transmission. The context query vector and the result of the relation-aware transformation are then multiplied by a vector dot product and processed by a leaky linear rectified activation function to obtain an initial association score. This association score comprehensively reflects the semantic rationality and importance of connecting to the neighboring node through a specific relation in a specific dialogue context. After calculating the corresponding initial association score for each neighboring node of the current node, all initial association scores are input into a normalized exponential function for processing, so that all scores are transformed into a probability distribution. Each value in this probability distribution is the normalized information transmission weight of the corresponding neighboring node relative to the current node. Normalization ensures the interpretability and stability of the weights when aggregating node information. Subsequently, based on the normalized information transmission weights, the feature vectors of each neighboring node are summed using a weighted summation. Before weighting, the feature vector of each neighboring node is multiplied by the same learnable diagonal matrix corresponding to its relation type to incorporate relational semantics. This ensures that relational semantics are consistently encoded into the transmitted information during the information aggregation stage. The result of the weighted summation is processed through an activation function to obtain the updated feature vector of the current node. This update enables the node's feature representation to not only include its own inherent semantics but also incorporate the information of its most relevant neighbors in the current dialogue context, thus achieving context-aware dynamic updating of node features. At the same time, all neighboring node identifiers with normalized weights are collected to form the set of activated nodes for the next iteration, which realizes the hierarchical and guided expansion of the knowledge subgraph based on the dialogue context. Once the iteration process is complete, all nodes activated in each iteration, along with the connecting edges between these nodes in the knowledge graph, together constitute a dynamic knowledge subgraph. This dynamic knowledge subgraph is not pre-defined statically, but is generated entirely by the semantic content of the current dialogue. It precisely focuses on the local knowledge network related to question answering, discarding a large number of irrelevant structures and nodes in the global graph. This provides a highly relevant, compact, and semantically rich efficient operating environment for subsequent steps (such as reasoning in S3), fundamentally solving the problem of excessively large search space when performing complex reasoning on large-scale knowledge graphs.
[0023] In this embodiment, the specific operation of constructing the dynamic knowledge subgraph into a reinforcement learning environment in step S3 is as follows: The dynamic knowledge subgraph from step S2 is directly defined as the environment of the Markov decision process; the state space of this environment is the set of all nodes in the dynamic knowledge subgraph; the action space of this environment is: In any given state, that is, when the given state corresponds to the current node, it is the set of all available relation edges starting from the current node; The interaction between the reinforcement learning agent and the environment is manifested as follows: Given the current state (i.e., the current node), the reinforcement learning agent takes an action, namely, selecting a relation edge starting from the current node. The environment, based on the inherent graph structure of the dynamic knowledge subgraph, deterministically transfers the reinforcement learning agent to the neighbor node directly pointed to by the selected relation edge and returns an immediate reward to the reinforcement learning agent corresponding to this state transition. The interaction system thus constitutes the reinforcement learning environment. This construction method formalizes the knowledge reasoning problem into a sequential decision problem, where both the state and the action have explicit and computable semantic representations (i.e., nodes and edges). This allows the reinforcement learning agent's exploration process to directly correspond to walking along semantic paths in the dynamic knowledge subgraph, laying the foundation for generating interpretable reasoning paths. The determinism of the environment transition stems from the determinism of the knowledge graph structure, which simplifies the environment model and allows the agent to focus more on learning semantic-based decision-making strategies. The reward function, which integrates the relevance of single-step actions, global consistency of the path, and confidence of the target node, is specifically composed as follows: The reward function is a weighted sum of three independent reward components. For a complete exploration generating a sequence of alternating nodes and edges, the total reward is the weighted sum of the three reward components. The single-step action relevance reward is calculated and accumulated once when the reinforcement learning agent selects an edge. The path global consistency reward is calculated and accumulated once when the reinforcement learning agent reaches a new node, based on the entire partial path up to that node. The target node confidence reward is calculated and accumulated only once when the alternating node and edge sequence terminates, based on the terminating node. The three reward components are weighted by a first weight coefficient, a second weight coefficient, and a third weight coefficient, respectively. The first weight coefficient, the second weight coefficient, and the third weight coefficient are preset positive scalar values, for example, all of which can be set to 1.0, indicating that the three reward components are equally weighted. In practical applications, these values can be adjusted according to the task emphasis. The first reward component is the single-step action relevance reward, which measures the local rationality of the reinforcement learning agent's action of choosing a relation edge to jump in the dialogue context. The value of the single-step action relevance reward is directly set as the information transmission weight calculated and normalized for the start node and end node of the selected relation edge in the corresponding iteration round during the graph attention iterative walk in step S2. That is, the weight value is a value between zero and one, representing the importance of transmitting information from the start node to the end node of the edge in the dialogue context. This design creatively transforms the evaluation result of the graph attention network on "context-related neighbors" (i.e., information transmission weight) in step S2 directly into the immediate reward of reinforcement learning, realizing seamless collaboration between the deep semantic perception network and the decision learning process, ensuring that each local decision of the agent is consistent with the semantic focus of the current dialogue, and avoiding blind exploration. The second reward component is the path global consistency reward, which evaluates the overall matching degree between the entire partial path from the starting node to the current node and the global dialogue semantics represented by the knowledge-enhanced dialogue state vector from step S1. The calculation process of the path global consistency reward is as follows: First, the visited node and edge sequence is encoded into a path vector through a sequence encoding structure; then, this path vector is concatenated with the knowledge-enhanced dialogue state vector to form a combined vector; then, the combined vector is input into a multilayer perceptron consisting of at least one fully connected layer for calculation; finally, SigMn is applied to the output of the multilayer perceptron. The `moid` function yields a matching score between zero and one. This score is the value of the global consistency reward for the path. The sequence encoding structure is a long short-term memory network or a Transformer-based encoder. This reward component guides the path planned by the agent to remain consistent with the original user query intent in the overall semantic evolution direction. For example, in a dialogue about "gastric ulcer treatment," this reward encourages paths leading to treatment-related nodes such as "proton pump inhibitors" and "Helicobacter pylori eradication," while suppressing paths leading to "history of etiological research," which are relevant but not the current focus of the question and answer, thereby ensuring the global relevance and topic focus of the reasoning path. The third reward component is the target node confidence reward, which is triggered only when a complete exploration path of the reinforcement learning agent terminates. It is used to evaluate the credibility of the path's endpoint node as the final answer. The value of the target node confidence reward is calculated through a preset confidence function. This confidence function takes the identifier of the path's endpoint node as input and returns a scalar value representing its credibility as an answer based on the prior meta-information of the entity node in the digestive system disease knowledge graph. The prior meta-information includes the score of the entity cited in authoritative medical knowledge bases or the frequency with which it has been marked as a correct answer in historical question-and-answer records. This reward introduces external prior knowledge (authority, historical correctness) into the path optimization objective, guiding the agent to tend to terminate at high-quality, high-credibility answer nodes. For example, among multiple possible diagnostic entities, it tends to choose the more common or authoritative diagnosis in medical guidelines, thereby improving the reliability and practicality of the final answer. The reinforcement learning agent explores and updates its policy network based on its policy network. The specific process is as follows: The reinforcement learning agent includes a parameterized policy network, which is a learnable function whose input is the current state representation. This current state representation is obtained by concatenating two vectors along the feature dimension: the first vector is the updated feature vector corresponding to the current node after the graph attention iterative walk in step S2, and the second vector is the knowledge-enhanced dialogue state vector from step S1. The policy network takes the current state representation as input, performs a series of linear transformations and non-linear activations on it, and outputs a real vector whose dimension is equal to the number of available outgoing edges of the current node. Each real element in the vector uniquely corresponds to an available outgoing edge, representing the unnormalized score for selecting that outgoing edge as the action. A normalized exponential function is applied to this real vector to transform it into a probability distribution, which is defined as the action probability distribution. The reinforcement learning agent selects actions based on the action probability distribution and explores multiple complete trajectories in the reinforcement learning environment. Each trajectory is a sequence of alternating nodes and edges that start from nodes in the initial seed node set and end at the termination node. After collecting all exploration trajectories, the total cumulative reward for each trajectory is calculated according to the reward function. The parameters of the policy network are updated using a proximal policy optimization algorithm. The parameter update steps of the near-end policy optimization algorithm include: H1. Based on the trajectory data collected from the parameters of the old version of the policy network, calculate the importance sampling ratio. This ratio is the ratio of the probability that the new policy network and the old policy network will choose the same action in the same state in the trajectory. The importance sampling ratio is used to correct the probability distribution when using the data sampled from the old policy to estimate the performance of the new policy. H2. Calculate the advantage function estimate of the trajectory based on the total cumulative reward. The advantage function estimate is used to quantify the additional benefit that can be obtained by taking a specific action in a specific state. Compared with the average benefit in that state, it is calculated based on the total cumulative reward using the generalized advantage estimation algorithm, which guides the policy to be updated in a more advantageous direction. H3. Perform a pruning operation on the importance sampling ratio, restricting its value to a closed interval centered at 1 with a preset small positive number ε as the radius; the preset small positive number ε is usually set to 0.1 or 0.2. This pruning operation is the core mechanism to prevent excessive changes in the strategy during a single update. H4. Calculate the product of the importance sampling ratio and the advantage function estimate before the pruning operation, and also calculate the product of the importance sampling ratio and the advantage function estimate after the pruning operation. H5. Take the smaller value of the two products in H4 as the contribution of the current trajectory to the parameter update objective function. This minimum value operation, together with the pruning operation in step H3, constitutes the pruning objective function of the near-end policy optimization algorithm. Its role is to encourage policy improvement (when the advantage function estimate is positive) while strictly constraining the difference between the new policy and the old policy, thereby ensuring the stability of the training process and avoiding the performance collapse caused by policy mutation in the traditional policy gradient method. H6. By maximizing the expected value of the contributions of all trajectories, a target function for parameter updates is constructed, and this target function is optimized using the gradient ascent method, thereby iteratively updating the parameters of the policy network. This step achieves end-to-end optimization of the policy network, enabling the policy to automatically learn how to combine local semantics (node features), global intent (dialogue state vector), and structured reward signals to plan a high-reward inference path in the dynamic knowledge subgraph. After multiple rounds of iterative training, the updated policy network can guide the reinforcement learning agent to stably generate a sequence of nodes and edges that obtain high total cumulative rewards in a dynamic knowledge subgraph, starting from the initial seed node. This sequence is the multi-hop reasoning path. The final multi-hop reasoning path is a comprehensive product that integrates the semantic understanding of step S1, the context-aware subgraph focusing of step S2, and the reward-driven decision of this step. It is not only the basis for generating the final answer, but also constitutes a traceable and interpretable reasoning chain, which greatly enhances the transparency and credibility of the intelligent question answering system.
[0024] In this embodiment, it is specifically necessary to explain that in step S4, the process of linearizing the multi-hop inference path into a path sequence and then using it as an additional input to the decoder is as follows: Obtain the multi-hop reasoning path from step S3. This path is a sequence consisting of alternating connections between nodes and relation edges. The specific form of the multi-hop reasoning path is: starting node, followed by the first relation edge connecting the starting node, then the first node reached via the first relation edge, followed by the second relation edge connecting the first node, and so on until the terminating node, forming a chain sequence in which nodes and relation edges appear alternately. The multi-hop inference path is linearized and encoded, which includes the following steps: First, each node and each relation edge in the multi-hop inference path is assigned a predefined, unique text tag. For example, the entity node "stomach ulcer" can be mapped to the tag "[ENT stomach ulcer]", and the relation "commonly used treatment drugs" can be mapped to the tag "[REL treatment drugs]". Then, these text tags are arranged sequentially according to the order in which the nodes and relation edges appear in the multi-hop inference path, forming an initial ordered text sequence. Next, a start text tag, such as "[PATH_START]", is added at the beginning of the initial ordered text sequence, and an end text tag, such as "[PATH_END]", is added at the end, thus constructing a complete path text sequence, such as "[PATH_START],[ENT stomach pain],[REL possible causes],[ENT stomach ulcer],[REL common examinations],[ENT gastroscopy],[PATH_END]". Input this path text sequence into a word embedding layer, and map each text token therein to a real-valued vector of a fixed dimension, such as 512 or 768, consistent with the other embedding dimensions of the model, thereby transforming the entire path text sequence into a path vector sequence, which will serve as the structured memory information that the decoder needs to focus on when generating the response. When generating each word in the natural language response, the decoder simultaneously focuses on the integrated dialogue encoding vector and path sequence, and the policy network of the reinforcement learning agent and the decoder jointly optimize the parameters. The specific process includes: The decoder, based on the Transformer architecture, takes the synthesized dialogue encoding vector from step S1 as its basic input. An additional path attention sublayer is set up in at least one network layer of the decoder. At each time step in generating a response, the current hidden state of the decoder is simultaneously used as the query vector for two cross-attention operations: the first cross-attention operation uses the synthesized dialogue encoding vector as the key and value to capture the dialogue history context; the second cross-attention operation, the path attention sublayer, uses the path vector sequence as the key and value to capture the logical chain of multi-hop reasoning. The computation process of the path attention sublayer is as follows: First, the current hidden state vector of the decoder is concatenated with the knowledge-enhanced dialogue state vector from step S1 along the feature dimension to obtain a concatenated vector. This concatenated vector is then input into a learnable linear transformation layer for processing, and then a dynamic gating vector is generated by passing the Sigmoid activation function. Each element of this dynamic gating vector has a value between 0 and 1, which is used to dynamically adjust the attention intensity to information at different positions in the path sequence in subsequent attention calculations. Its dimension matches the number of attention heads or the feature dimension. Next, the current hidden state vector of the decoder is linearly transformed through a learnable query weight matrix to obtain a query vector. The path vector sequence is linearly transformed through a learnable key weight matrix to obtain a key vector sequence. Then, the dot product between the query vector and the transpose of the key vector sequence is calculated, and the dot product result is divided by a factor based on the attention space dimension. A predetermined scaling factor, typically the square root of the attention space dimension, is used to stabilize the gradient during training, yielding the initial attention score matrix. This initial attention score matrix is then modulated using a dynamic gating vector. The modulation method involves expanding the dynamic gating vector into a gating matrix with the same dimension as the initial attention score matrix. This expansion is achieved by performing an outer product of the dynamic gating vector and a vector of all ones. Then, the initial attention score matrix is element-wise multiplied by this gating matrix, allowing for refined enhancement or suppression of attention at different parts of the path based on the current generation state and global dialogue semantics. A normalized exponential function is applied to the modulated result to obtain the final path attention weight distribution. Finally, the path vector sequence is linearly transformed through a learnable value weight matrix to obtain a value vector sequence. This value vector sequence is then weighted and summed using the path attention weight distribution to output the path context vector. The decoder is trained using a standard language modeling loss function to optimize its generation capabilities. This loss function is typically a cross-entropy loss based on vocabulary distribution. The decoder parameters are optimized using the maximum likelihood estimation principle. Simultaneously, a response quality assessment process is introduced to automatically evaluate the complete natural language responses generated by the decoder, resulting in a quality score representing its semantic accuracy, information completeness, or medical expertise. This assessment process can comprehensively calculate the BLEU score of the generated response and the standard answer in terms of n-gram overlap, the ROUGE-L score in terms of the longest common subsequence, and the accuracy, recall, and F1 score for identifying key medical entities. These indicators are linearly weighted or geometrically averaged to obtain the final quality score, which is defined as the quality reward. The total reward used to update the policy network parameters of the reinforcement learning agent is specifically defined as follows: the total cumulative reward calculated in step S3 for the exploration trajectory to generate multi-hop inference paths is weighted and summed with the quality reward; wherein, the quality reward needs to be multiplied by a preset adjustment coefficient greater than zero before the weighted summation. The adjustment coefficient is usually between 0.1 and 1.0, which is used to balance the contribution ratio of the path internal reward and the quality reward of the generated response in the total reward. The total reward is used to calculate the policy gradient, thereby updating the parameters of the policy network. Specifically, the proximal policy optimization algorithm calculates the advantage function estimate based on the total reward and updates the policy network parameters by maximizing the pruned policy objective function. The parameter updates of the policy network and the parameter training of the decoder together constitute a joint optimization process, which is carried out alternately during training: First, the policy network is fixed, multiple inference paths are sampled using the current policy and responses are generated, and path rewards and quality rewards are calculated to update the policy network; then, the policy network is fixed again, and the decoder is updated using the paths it guides and the generated responses through language modeling loss; this process is iterative; in this joint optimization process, the optimization objective of the policy network is to incorporate the evaluation of the internal quality of multi-hop inference paths and the quality of the final generated response through the total reward, thereby driving the policy network to learn to generate inference paths that not only obtain high path rewards, but also support the decoder to produce high-quality responses. This design realizes end-to-end collaborative training from semantic understanding, knowledge reasoning to language generation, so that the final generated response is not only based on a reasonable knowledge path, but also optimized to ensure that a high-quality answer can be derived, which significantly improves the overall performance of the question answering system and the interpretability of the answer.
[0025] It should be noted that the descriptions of each embodiment in the above embodiments have different focuses. For parts that are not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.
[0026] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0027] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded computer, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0028] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0029] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0030] Although preferred embodiments of the invention have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including both the preferred embodiments and all changes and modifications falling within the scope of the invention.
[0031] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends to include these modifications and variations.
Claims
1. A knowledge graph-based intelligent question-answering method for digestive system diseases, characterized in that, Specifically, the steps include the following: Step S1: Receive the current user query and dialogue history sequence, input the current user query and dialogue history sequence into the encoder based on the Transformer architecture respectively to obtain the first dialogue encoding vector and the second dialogue encoding vector, and concatenate the first dialogue encoding vector and the second dialogue encoding vector into a comprehensive dialogue encoding vector; extract the entity vector and relation vector from the pre-constructed digestive system disease knowledge graph, use the comprehensive dialogue encoding vector as the query vector, and use the entity vector and relation vector as the key vector and value vector, and calculate through a dual attention mechanism that integrates dialogue internal self-attention and dialogue-knowledge cross-attention, and output the knowledge-enhanced dialogue state vector; Step S2: Based on the knowledge attention weight distribution row vectors corresponding to each entity in the knowledge-enhanced dialogue state vector, select entities with weights higher than a preset threshold from the digestive system disease knowledge graph to form an initial seed node set. Starting with the initial set of seed nodes, an iterative walk based on graph attention network is performed on the knowledge graph of digestive system diseases. In each iteration, the information transmission weight of the neighbor node is calculated by combining the feature vector of the current node, the feature vector of its neighbor nodes, and the knowledge-enhanced dialogue state vector. After at least one iteration, a dynamic knowledge subgraph related to the current dialogue context is output. Step S3: Construct the dynamic knowledge subgraph into a reinforcement learning environment and initialize a reinforcement learning agent. The state of the reinforcement learning agent is a node in the dynamic knowledge subgraph, and the action is to select a relation edge from the current node to jump. The reinforcement learning agent explores the dynamic knowledge subgraph from the initial set of seed nodes according to its policy network, generating a multi-hop inference path from the starting node to the target node. The update of the policy network depends on a reward function that integrates the relevance of single-step actions, the global consistency of the path, and the confidence of the target node. Step S4: Input the knowledge-enhanced dialogue state vector, dynamic knowledge subgraph, and multi-hop reasoning path into the decoder based on the Transformer architecture. After linearizing the multi-hop inference path into a path sequence, it is used as an additional input to the decoder; When generating each word in a natural language response, the decoder simultaneously focuses on the integrated dialogue encoding vector and path sequence. Furthermore, the policy network of the reinforcement learning agent and the decoder jointly optimize the parameters, with the quality of the decoder's generated response being fed back as an additional reward signal to optimize the policy network.
2. The intelligent question-answering method for digestive system diseases based on knowledge graphs according to claim 1, characterized in that: In step S1, the specific process of concatenating the first dialogue encoding vector and the second dialogue encoding vector into a comprehensive dialogue encoding vector is as follows: Receive the current query word vector sequence converted from the current user query, and the historical dialogue word vector sequence converted from the dialogue history sequence; The current query word vector sequence and the historical dialogue word vector sequence are respectively input into the same encoder based on the Transformer architecture. The encoder includes a multi-head self-attention mechanism and a feedforward neural network. The current query word vector sequence is processed and the output context vector representing the semantics of the current query is used as the first dialogue encoding vector. At the same time, the historical dialogue word vector sequence is processed and the output context vector representing the semantics of the historical dialogue is used as the second dialogue encoding vector. The first dialogue encoding vector and the second dialogue encoding vector are concatenated along their feature dimensions to generate a comprehensive dialogue encoding vector that integrates the semantics of the current query and all historical dialogues.
3. The intelligent question-answering method for digestive system diseases based on knowledge graphs according to claim 2, characterized in that: The specific process of outputting the knowledge-enhanced dialogue state vector is as follows: A1. Knowledge Embedding Preparation: From the pre-trained embedding representation of the digestive system disease knowledge graph, obtain the entity vectors corresponding to each of the N entities contained therein, and form an entity vector matrix with N rows from the N entity vectors. Also, obtain the relation vectors corresponding to each of the M relations contained therein, and form a relation vector matrix with M rows from the M relation vectors. The entity vectors and relation vectors have the same feature dimension d. The entity vector matrix and the relation vector matrix are concatenated along the row direction to form a knowledge embedding matrix with N plus M rows and d columns; A2. Vector Projection Transformation: The integrated dialogue encoding vector is mapped to a query vector by a learnable linear transformation, namely by multiplying it by a first learnable weight matrix used to generate the query vector; the knowledge embedding matrix is mapped to a key vector matrix by multiplying it by a second learnable weight matrix used to generate the key vector. The knowledge embedding matrix is mapped to a value vector matrix by multiplying it by a third learnable weight matrix used to generate the value vectors; A3. Gated attention weight calculation: Calculate the product of the query vector and the key vector matrix, and divide the product result by a preset scaling factor to obtain the initial attention score matrix; The query vector is multiplied by a fourth learnable weight matrix used to generate the gate vector and transformed by a nonlinear activation function to generate a gated row vector with the same dimension as the projection dimension of the query vector and key vector matrices. The initial attention score matrix is then modulated by multiplying it element-wise with the gated matrix obtained by expanding the gated row vector into matrix form. Applying a normalized exponential function to the last dimension of the modulated matrix yields a row vector of knowledge attention weights that reflects the relevance of each knowledge element to the current dialogue. A4. State Vector Synthesis: Multiply the row vector of knowledge attention weight distribution with the value vector matrix to obtain a weighted knowledge context vector; add the weighted knowledge context vector to the original, untransformed integrated dialogue encoding vector; perform layer normalization on the addition result to output the knowledge-enhanced dialogue state vector.
4. The intelligent question-answering method for digestive system diseases based on knowledge graphs according to claim 3, characterized in that: In step S2, based on the knowledge attention weight distribution row vectors corresponding to each entity in the knowledge-enhanced dialogue state vector, entities with weights higher than a preset threshold are selected from the digestive system disease knowledge graph to form an initial seed node set, specifically including: Obtain the knowledge attention weight distribution row vector synchronously obtained during the calculation of the knowledge-enhanced dialogue state vector. The knowledge attention weight distribution row vector sequentially contains the relevance weights of all entities and all relationships in the digestive system disease knowledge graph to the current dialogue. The first row vector contains consecutive weight values, the same number as the total number of entities in the knowledge graph, corresponding to each entity. Extract these consecutive weight values corresponding to entities to form an entity attention weight vector. Set a filtering threshold. Compare the weight value of each entity in the entity attention weight vector with the filtering threshold, and select entities with all weight values greater than the filtering threshold. Gather the identifiers of these selected entities to form the initial seed node set.
5. The intelligent question-answering method for digestive system diseases based on knowledge graphs according to claim 4, characterized in that: The specific process of outputting a dynamic knowledge subgraph related to the current dialogue context is as follows: Using the initial seed node set as the activation node set for the zeroth iteration, and pre-setting a maximum iteration walk depth; starting from the zeroth iteration, perform the following steps until the maximum iteration walk depth is reached: For each node in the activation node set corresponding to the current iteration, perform the following operations: First, the entity vector corresponding to the node is obtained from the pre-trained embedding representation of the digestive system disease knowledge graph, serving as its current feature vector. Next, all directly adjacent nodes of the node in the digestive system disease knowledge graph are traversed, and the entity vector corresponding to each adjacent node is obtained from the pre-trained embedding representation of the digestive system disease knowledge graph, serving as its current feature vector. Simultaneously, the relationship type from the current node to each adjacent node is recorded. Then, for each adjacent node, a weight score is calculated. This calculation process involves multiplying the knowledge-enhanced dialogue state vector from step S1 by a first learnable weight matrix to obtain a context query vector; and then multiplying the feature vector of the current node by the feature vector of the adjacent node. A combined feature vector is formed by concatenating features along the feature dimension. A learnable diagonal matrix that uniquely corresponds to the relationship type from the current node to the adjacent node is multiplied by the transpose of the combined feature vector to achieve a relationship-aware transformation of the combined feature vector. The context query vector and the result of the relationship-aware transformation are then subjected to a vector dot product operation, followed by processing with a linear rectified activation function with leakage to obtain an initial association score. After calculating the initial association score for each adjacent node of the current node, all initial association scores are input into a normalized exponential function for processing, so that all scores are transformed into a probability distribution. Each value in this probability distribution is the normalized information transmission weight of the corresponding adjacent node relative to the current node. Then, based on the normalized information transmission weights, the feature vectors of each adjacent node are summed by weight, and the result of the weighted sum is processed by an activation function to obtain the updated feature vector of the current node. At the same time, all neighboring node identifiers with normalized weights are collected to form the set of active nodes for the next iteration. Once the iteration process is complete, all the nodes that have been activated in each iteration, along with the connecting edges between these nodes in the knowledge graph, together constitute a dynamic knowledge subgraph.
6. The intelligent question-answering method for digestive system diseases based on knowledge graphs according to claim 5, characterized in that: In step S3, the specific operation of constructing the dynamic knowledge subgraph into a reinforcement learning environment is as follows: The dynamic knowledge subgraph from step S2 is directly defined as the environment of the Markov decision process; the state space of this environment is the set of all nodes in the dynamic knowledge subgraph; the action space of this environment is: In any given state, that is, when the given state corresponds to the current node, it is the set of all available relation edges starting from the current node; The interaction between the reinforcement learning agent and the environment is manifested as follows: Given the current state, i.e. the current node, the reinforcement learning agent takes an action, i.e., selects a relation edge starting from the current node. The environment then, based on the inherent graph structure of the dynamic knowledge subgraph, deterministically transfers the reinforcement learning agent to the neighbor node directly pointed to by the selected relation edge, and returns an immediate reward to the reinforcement learning agent corresponding to this state transition. The interaction system formed by this is the reinforcement learning environment.
7. The intelligent question-answering method for digestive system diseases based on knowledge graphs according to claim 6, characterized in that: The reward function, which integrates single-step action relevance, path global consistency, and target node confidence, is specifically composed as follows: The reward function is a weighted sum of three independent reward components. For a complete exploration that generates a sequence of alternating nodes and edges, the total reward is the weighted sum of the three reward components. The single-step action relevance reward is calculated and accumulated once when the reinforcement learning agent selects an edge. The path global consistency reward is calculated and accumulated once when the reinforcement learning agent reaches a new node, based on the entire partial path up to that node. The target node confidence reward is calculated and accumulated only once when the alternating node and edge sequence terminates, based on the terminating node. The three reward components are weighted by a first weight coefficient, a second weight coefficient, and a third weight coefficient, respectively, and the first weight coefficient, the second weight coefficient, and the third weight coefficient are preset positive scalar values; The first reward component is the single-step action relevance reward. The value of the single-step action relevance reward is directly set as the information transmission weight calculated and normalized for the start node and end node of the selected relationship edge in the corresponding iteration round during the graph attention iterative walk in step S2. The second reward component is the path global consistency reward. The calculation process for the path global consistency reward is as follows: First, the visited node and edge sequence is encoded into a path vector through a sequence encoding structure; then, this path vector is concatenated with the knowledge-enhanced dialogue state vector to form a combined vector; next, the combined vector is input into a multilayer perceptron consisting of a fully connected layer for calculation; finally, the Sigmoid function is applied to the output of the multilayer perceptron to obtain a matching degree score between zero and one, which is the value of the path global consistency reward. The third reward component is the target node confidence reward, which is triggered only when a complete exploration path of the reinforcement learning agent terminates. The value of the target node confidence reward is calculated through a preset confidence function, which takes the identifier of the path endpoint node as input and returns a scalar value representing its credibility as an answer based on the prior meta-information of the entity node in the digestive system disease knowledge graph.
8. The intelligent question-answering method for digestive system diseases based on knowledge graphs according to claim 7, characterized in that: The reinforcement learning agent explores and updates its policy network based on its policy network, specifically through the following process: The reinforcement learning agent includes a parameterized policy network, which is a learnable function whose input is the current state representation. This current state representation is obtained by concatenating the following two vectors along the feature dimension: the first vector is the updated feature vector corresponding to the current node after the graph attention iterative walk in step S2, and the second vector is the knowledge-enhanced dialogue state vector from step S1. The policy network takes the current state representation as input, performs a series of linear transformations and non-linear activation processes on it, and outputs a real number vector. A normalized exponential function is applied to this real number vector to transform it into a probability distribution, which is defined as the action probability distribution. The reinforcement learning agent selects actions based on the action probability distribution and explores multiple complete trajectories in the reinforcement learning environment. Each trajectory is a sequence of alternating nodes and edges that starts from the initial seed node set and ends at the terminal node. After collecting all exploration trajectories, the total cumulative reward for each trajectory is calculated according to the reward function. The parameters of the policy network are updated using a near-end policy optimization algorithm; The parameter update steps of the near-end policy optimization algorithm include: H1. Based on the trajectory data collected from the parameters of the old version of the policy network, calculate the importance sampling ratio, which is the ratio of the probability of the new policy network and the old policy network selecting the same action in the same state in the trajectory. H2. Calculate the advantage function estimate of the trajectory based on the total cumulative reward; H3. Perform a pruning operation on the importance sampling ratio, restricting its value to a closed interval centered at 1 with a preset small positive number ε as the interval radius; H4. Calculate the product of the importance sampling ratio and the advantage function estimate before the pruning operation, and also calculate the product of the importance sampling ratio and the advantage function estimate after the pruning operation. H5. Take the smaller of the two products in H4 as the contribution of the current trajectory to the parameter update objective function; H6. By maximizing the expected value of the contributions of all trajectories, an objective function for parameter updates is constructed, and this objective function is optimized using the gradient ascent method, thereby iteratively updating the parameters of the policy network. After multiple rounds of iterative training, the updated policy network guides the reinforcement learning agent to generate a sequence of nodes and edges that yield high total cumulative rewards in the dynamic knowledge subgraph, starting from the initial seed node. This sequence is the multi-hop inference path.
9. The intelligent question-answering method for digestive system diseases based on knowledge graphs according to claim 8, characterized in that: In step S4, the process of linearizing the multi-hop inference path into a path sequence and then using it as additional input to the decoder is as follows: Obtain the multi-hop reasoning path from step S3. This path is a sequence consisting of alternating connections between nodes and relation edges. The specific form of the multi-hop reasoning path is: starting node, followed by the first relation edge connecting the starting node, then the first node reached via the first relation edge, followed by the second relation edge connecting the first node, and so on until the terminating node, forming a chain sequence in which nodes and relation edges appear alternately. The multi-hop inference path is linearized and encoded. The linearization process includes the following steps: First, each node and each relation edge in the multi-hop inference path is assigned a predefined and unique text tag. Then, these text tags are arranged in order of their appearance in the multi-hop inference path to form an initial ordered text sequence. Next, a start text tag is added at the beginning of the initial ordered text sequence and an end text tag is added at the end of the sequence to construct a complete path text sequence. Input this path text sequence into a word embedding layer, and map each text token into a fixed-dimensional real-valued vector, thereby transforming the entire path text sequence into a path vector sequence.
10. The intelligent question-answering method for digestive system diseases based on knowledge graphs according to claim 9, characterized in that: When generating each word in a natural language response, the decoder simultaneously focuses on the integrated dialogue encoding vector and path sequence, and jointly optimizes the parameters of the policy network of the reinforcement learning agent and the decoder. The specific process includes: The decoder, based on the Transformer architecture, takes the synthesized dialogue encoding vector from step S1 as its basic input. An additional path attention sublayer is set in one network layer of the decoder. At each time step of generating a response, the current hidden state of the decoder is used as the query vector for two cross-attention operations: the first cross-attention operation uses the synthesized dialogue encoding vector as the key and value; the second cross-attention operation, namely the path attention sublayer, uses the path vector sequence as the key and value. The computation process of the path attention sublayer is as follows: First, the current hidden state vector of the decoder is concatenated with the knowledge-enhanced dialogue state vector from step S1 along the feature dimension to obtain a concatenated vector. This concatenated vector is then input into a learnable linear transformation layer for processing, and a dynamic gating vector is generated by passing the Sigmoid activation function. Next, the current hidden state vector of the decoder is linearly transformed through a learnable query weight matrix to obtain a query vector. The path vector sequence is linearly transformed through a learnable key weight matrix to obtain a key vector sequence. Then, the dot product between the query vector and the transpose of the key vector sequence is calculated, and the dot product result is divided by a scaling factor determined based on the attention space dimension to obtain the initial attention score matrix. The initial attention score matrix is modulated using the dynamic gating vector. A normalized exponential function is applied to the modulated result to obtain the final path attention weight distribution. Finally, the path vector sequence is linearly transformed through a learnable value weight matrix to obtain a value vector sequence, and the value vector sequence is weighted and summed using the path attention weight distribution to output the path context vector. The decoder is trained using a standard language modeling loss function to optimize its generation capabilities. At the same time, a response quality assessment process is introduced to automatically evaluate the complete natural language response generated by the decoder and obtain a quality score, which is defined as a quality reward. The total reward used to update the policy network parameters of the reinforcement learning agent is specifically calculated as follows: the total cumulative reward calculated in step S3 for generating multi-hop inference paths is weighted and summed with the quality reward. The total reward is used to calculate the policy gradient, thereby updating the parameters of the policy network; The parameter update of the policy network and the parameter training of the decoder together constitute a joint optimization process. In this joint optimization process, the optimization objective of the policy network incorporates the evaluation of the internal quality of the multi-hop inference path and the evaluation of the quality of the final generated response through the total reward. This drives the policy network to learn to generate inference paths that not only obtain high path rewards but also support the decoder to produce high-quality responses.