Medical dialogue understanding and generation method based on transformer model

By using the Perceiver structure based on the Transformer model and neural frequent differential equations, deep fusion of multi-source heterogeneous data and dynamic semantic trajectory modeling are achieved, which solves the shortcomings of existing medical dialogue generation models in semantic understanding and entity reference consistency, and improves the accuracy and security of dialogue generation.

CN121303334BActive Publication Date: 2026-04-07FUZHOU CHUANGDAHUI INFORMATION TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-09-26
Publication Date
2026-04-07

AI Technical Summary

Technical Problem

Existing medical dialogue generation models have shortcomings in integrating multi-source heterogeneous data, capturing semantic state evolution patterns, and controlling the consistency of generated response content. This results in insufficient understanding of the global context, difficulty in handling semantic changes, and lack of verification of medical entity referential relationships, affecting generation quality and medical safety.

Method used

By employing a Transformer-based approach that combines the Perceiver structure with neural frequent differential equations, we achieve deep fusion of multi-source heterogeneous medical information, dynamic semantic trajectory modeling, and contextual consistency control. Through cross-attention mechanisms and semantic state evolution path functions, we generate dialogues that are semantically accurate, have reasonable responses, and clearly refer to medical entities.

Benefits of technology

It enhances the comprehensive expressive power of dialogue generation, improves the coherence and contextual consistency of response content, strengthens the accuracy and contextual constraints of medical entity reference, ensures the semantic evolution and entity connection consistency of generated text, and improves the accuracy and security of medical dialogue responses.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121303334B_ABST
    Figure CN121303334B_ABST
Patent Text Reader

Abstract

The application discloses a medical dialogue understanding and generation method based on a Transformer model, and comprises the following steps: medical text, structured medical record data and historical dialogue content are extracted, and unified semantic representation is generated through embedding mapping; various embedding representations are input into a Perceiver structure containing a cross-attention mechanism to perform cross-source information fusion, and unified latent semantic vectors are obtained; a semantic state evolution path function is constructed based on a neural ordinary differential equation; a dialogue round is introduced as a time variable to model the dynamic evolution process of the semantic change with the round; a context control semantic vector is constructed in combination with the current semantic state and the historical context, and the natural language generation model is guided to generate initial reply text; and finally, the final medical dialogue response text is output through semantic trajectory consistency and medical entity reference consistency verification. The application has strong context modeling capability.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of artificial intelligence, and in particular to a medical dialogue understanding and generation method based on a Transformer model. BACKGROUND

[0002] With the wide application of artificial intelligence in medical scenarios, medical dialogue systems based on deep learning have gradually become an important part of intelligent medical services. At present, medical dialogue generation usually adopts a language model based on an encoder-decoder structure, combines patient medical record information and historical question and answer content, and realizes automatic inquiry and medical auxiliary decision-making. However, the existing technology still has significant deficiencies in modeling multi-source heterogeneous data, capturing semantic state evolution rules, and controlling the consistency of generated response content.

[0003] On the one hand, mainstream models often rely on simple splicing or attention mechanisms when integrating medical text, structured medical record data and historical dialogue, lack the ability to model a unified semantic space, and are difficult to achieve deep semantic fusion, resulting in insufficient understanding of the global context of the generated results. On the other hand, existing dialogue generation models generally use static semantic representations, which cannot capture the dynamic semantic trajectory of dialogue turns over time, making it difficult to deal with semantic changes and context evolution in complex dialogues. In addition, the lack of checking of the reference relationship of medical entities and the semantic logic of responses often leads to confusion in the content of the replies, inconsistency in the context, and affects the quality of the generation and medical safety.

[0004] Therefore, how to provide a medical dialogue understanding and generation method based on a Transformer model is a problem that those skilled in the art need to solve. SUMMARY

[0005] One object of the present application is to provide a medical dialogue understanding and generation method based on a Transformer model. The present application combines the Perceiver structure containing the cross-attention mechanism and the semantic state evolution modeling mechanism based on neural ordinary differential equations, and describes in detail the whole process of deep fusion of multi-source heterogeneous medical information, dynamic semantic trajectory modeling and context consistency control. The present application has the advantages of accurate semantic understanding, reasonable response generation and clear reference of medical entities.

[0006] The medical dialogue understanding and generation method based on the Transformer model according to the embodiment of the present application comprises the following steps:

[0007] Obtain medical text, structured medical record data and historical dialogue content, and respectively perform embedding mapping to obtain medical text embedding representation, structured medical record embedding representation and historical dialogue embedding representation;

[0008] The medical text embedding representation, the structured medical record embedding representation and the historical dialogue embedding representation are input into a Perceiver structure comprising a cross-attention mechanism, information fusion is performed, and a unified latent semantic vector is generated;

[0009] The unified latent semantic vector is input into a semantic state evolution function constructed based on a neural differential equation as an initial semantic state, and a semantic state evolution path function is generated by taking the current dialogue turn as a time variable;

[0010] Based on the semantic state evolution path function and the current dialogue turn, a state solving operation is performed to obtain a continuous semantic state vector under the current dialogue turn;

[0011] The continuous semantic state vector under the current dialogue turn is fused with the historical dialogue embedding representation to construct a context control semantic vector, and medical entity references are extracted therefrom;

[0012] The context control semantic vector is input into a natural language generation model constructed based on a Transformer decoder to perform response text generation under semantic trajectory guidance, and an initial medical dialogue response text is obtained;

[0013] The initial medical dialogue response text is subjected to semantic state evolution path consistency checking and medical entity reference consistency checking, and response content that does not satisfy the trajectory logic or entity constraints is removed, and a final medical dialogue response text is output.

[0014] Optionally, the obtaining of the medical text embedding representation, the structured medical record embedding representation and the historical dialogue embedding representation comprises:

[0015] The medical text is subjected to word segmentation processing, and the word units are standardized coded based on a medical vocabulary table, the coded medical text is input into a pre-trained Transformer encoder to extract a context semantic vector, and an average pooling operation is applied to generate a medical text embedding representation;

[0016] The numerical fields in the structured medical record data are subjected to normalization processing, and the categorical fields are subjected to one-hot encoding processing, the field vectors are spliced to form a multi-dimensional feature vector, and the multi-dimensional feature vector is input into a feedforward neural network for mapping, and a structured medical record embedding representation is output;

[0017] The historical dialogue content is subjected to turn segmentation, and is arranged in chronological order to form a dialogue sequence, each round of question and answer is subjected to word segmentation and coding, and is input into a Transformer encoder after being attached with role labels and timestamp labels to extract inter-turn semantic dependency relationships, and a historical dialogue embedding representation is generated.

[0018] Optionally, the generation of the unified latent semantic vector comprises:

[0019] The embedding dimension alignment processing is performed on the medical text embedding representation, the structured medical record embedding representation, and the historical dialogue embedding representation respectively, and a data source identification field is added to each type of embedding representation;

[0020] The medical text embedding representation, the structured medical record embedding representation, and the historical dialogue embedding representation with the added data source identification field are organized into a structured input sequence in a set order, and the structured input sequence is packaged into a tensor data structure with channel identification;

[0021] The tensor data structure with channel identification is transmitted to the Perceiver structure containing a cross-attention mechanism through a special input interface, which supports simultaneous reception of structured input sequences and externally set fusion control parameters;

[0022] The set fusion control parameters are called before the structured input sequence is transmitted to the Perceiver structure;

[0023] After receiving the structured input sequence and the fusion control parameters, the Perceiver structure performs semantic alignment and cross-source information fusion operations according to the data source identification field added to the embedding representation and the channel rules set in the fusion control parameters, and outputs a unified latent semantic vector.

[0024] Optionally, the Perceiver structure containing a cross-attention mechanism includes:

[0025] The structured input sequence input to the Perceiver structure is subjected to a semantic path splitting operation, and the structured input sequence is divided into medical entity path representation, medical reasoning path representation, and context background path representation according to semantic categories, respectively forming medical entity path embedding representation, medical reasoning path embedding representation, and context path embedding representation;

[0026] Based on the above three types of path embedding representations, a structured semantic query vector is constructed, the medical entity path embedding representation is taken as the first type of query vector, the medical reasoning path embedding representation is taken as the second type of query vector, and the context path embedding representation is taken as the third type of query vector, and multi-path interactive fusion operations are performed with the embedding representations in the structured input sequence;

[0027] Path-level cross-attention mechanisms are respectively performed, the first type of query vector is cross-attention calculated with the medical entity content of the structured input sequence to generate entity path fusion representation, the second type of query vector is cross-attention calculated with the reasoning content in the structured input sequence to generate reasoning path fusion representation, and the third type of query vector is cross-attention calculated with the context content in the structured input sequence to generate background path fusion representation;

[0028] The entity path fusion representation, inference path fusion representation, and background path fusion representation are fused according to a preset path fusion order and fusion intensity parameters.

[0029] Optionally, the generation of the semantic state evolution path function includes:

[0030] The unified latent semantic vector is used as the initial semantic state vector of the semantic state evolution path function, and the current dialogue turn is mapped to a continuous time variable;

[0031] A semantic state derivative function containing a neural network structure is constructed. The semantic state derivative function receives the semantic state vector and time variable as input and outputs the derivative value of the semantic state at the current time point. The neural network structure constitutes a neural frequent differential modeling unit as part of the semantic state evolution path function.

[0032] Set the time integration interval and computational precision parameters of the semantic state evolution path function, call the built-in ordinary differential equation solver of the neuro-ordinary differential modeling unit, perform numerical integration on the semantic state derivative function, and generate a semantic state evolution trajectory covering the entire dialogue round.

[0033] Record the semantic state vector corresponding to each time point in the semantic state evolution trajectory to form a continuous semantic state vector sequence. The semantic state vector sequence serves as a stage output of the semantic state evolution path function during the generation process.

[0034] The semantic state vector corresponding to the current dialogue turn is extracted and used as the semantic control vector input for the natural language generation module.

[0035] Optionally, obtaining the continuous semantic state vector for the current dialogue turn includes:

[0036] Receive the current dialogue round number and map the corresponding dialogue round number to a continuous time variable, which serves as the target solution time point for the semantic state evolution path function;

[0037] The semantic state evolution path function is invoked, and the unified latent semantic vector is used as the initial semantic state vector of the semantic state evolution path function. The continuous time variable is used as the target time point and input into the semantic state evolution path function.

[0038] Using the built-in ordinary differential equation solver of the divine ordinary differential modeling unit, the initial semantic state vector and the target solution time point are used as boundary conditions to perform a single-point forward integration operation at the time point to generate a continuous semantic state vector under the current dialogue round.

[0039] Optionally, the construction of context-controlled semantic vectors includes:

[0040] Construct the first input path by marking the position of the continuous semantic state vectors under the current dialogue round and writing them into the semantic state path cache to form the first input path;

[0041] Construct a second input path by embedding historical dialogues into a representation that is divided according to round and role information, and injecting time phase encoding in combination with the corresponding time index to form a historical context path;

[0042] Construct a third input path, identify medical entity information involved in historical dialogue embeddings and continuous semantic state vectors, and generate entity alignment paths;

[0043] The first input path, the second input path, and the third input path are input into the path fusion interface, the path identifier is encoded according to the path type, and a path control mapping matrix is ​​constructed.

[0044] The path control mapping matrix is ​​invoked to perform a structural-level weighted combination operation on the three types of input paths, and a path bias term is introduced as a guiding factor to form a fused path representation.

[0045] Extract the fusion result of the current dialogue round node from the fusion path representation and use it as the context control semantic vector.

[0046] Optionally, the generation of the initial medical dialogue response text includes:

[0047] A natural language generation model containing a multi-layer Transformer decoder structure is constructed. The natural language generation model uses context-controlled semantic vectors as mandatory guiding inputs and controls the semantic focus area of ​​each decoding step through a guided attention mechanism.

[0048] The context control semantic vector of the current dialogue turn is copied to each decoding layer of the natural language generation model as a guiding conditional embedding for the decoding attention module. The guiding conditional embedding participates in the multi-head attention mechanism.

[0049] Using the generated historical target word sequence as the target input, and combining the attention output guided by the context-controlled semantic vector, the decoding calculation is recursively performed to generate the candidate word distribution in the dialogue response sequence;

[0050] The semantic state vector corresponding to the current round in the semantic state evolution path function is introduced as the semantic trajectory embedding vector, and semantic consistency calibration is performed with the decoding representation generated at each step to dynamically adjust the ranking weight of the candidate word distribution.

[0051] In the candidate word distribution, based on the probability weights after semantic consistency calibration, a bundle search strategy is used to select the word with the highest probability and gradually generate the initial medical dialogue response text.

[0052] Optionally, the generation of the final medical dialogue response text includes:

[0053] A response consistency verification module is constructed. The response consistency verification module takes the initial medical dialogue response text as input and calls the semantic state vector corresponding to the current dialogue round in the semantic state evolution path function to extract the semantic embedding vector of each sentence in the initial medical dialogue response text and calculate the cosine similarity between it and the semantic state vector.

[0054] A response semantic consistency threshold is set. If the cosine similarity between the semantic embedding vector and the semantic state vector of any statement in the initial medical dialogue response text is lower than the response semantic consistency threshold, then the statement is marked as an inconsistent statement.

[0055] A medical entity reference consistency verification module is constructed to identify all medical entity reference phrases in the initial medical dialogue response text and to perform matching verification by comparing them with the entity reference mapping rules and contextual reference order recorded in the historical dialogue embedding representation;

[0056] Define a set of entity reference consistency rules, including three types of consistency rules: entity type consistency, reference chain integrity, and role context matching. If an entity reference phrase does not meet any of the rules, the entity reference is marked as inconsistent entity reference.

[0057] Summarize all response content marked as inconsistent statements or inconsistent entity references, perform a removal operation, and update the response text;

[0058] Output the initial medical dialogue response text after the removal operation is completed, as the final medical dialogue response text.

[0059] The beneficial effects of this invention are:

[0060] (1) This invention introduces a Perceiver structure with a cross-attention mechanism to connect three heterogeneous semantic paths: medical text, structured medical record data and historical dialogue content, and constructs a unified latent semantic vector. This effectively solves the problems of insufficient information fusion depth and frequent context shifts in existing methods, and improves the comprehensive expression ability of medical semantics.

[0061] (2) This invention uses a semantic state evolution path modeling method based on the neural constant differential equation to dynamically construct the trajectory function of dialogue semantics as the rounds evolve, thereby realizing continuous modeling and predictive control of semantic control vectors. This overcomes the problems of semantic jumps and discontinuities in traditional decoding mechanisms and improves the coherence and contextual consistency of response content.

[0062] (3) This invention uses a multi-path semantic fusion mechanism to construct a context-controlled semantic vector, explicitly introduces semantic state path, historical context path and entity alignment path, realizes context-driven entity constraint modeling and semantic focus control, enhances the accuracy of medical entity reference and context constraint capability, and solves the problems of entity reference confusion and logical inconsistency in existing methods.

[0063] (4) This invention uses semantic state evolution path consistency verification and entity reference consistency verification mechanism to perform semantic trajectory matching and entity logic alignment on the initial response text, eliminate semantic drift or incorrect reference content, and ensure the dual consistency of the generated text in semantic evolution and entity connection, thereby improving the accuracy, security and clinical applicability of medical dialogue response. Attached Figure Description

[0064] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings:

[0065] Figure 1 This is a flowchart of the medical dialogue understanding and generation method based on the Transformer model proposed in this invention;

[0066] Figure 2 A schematic diagram of a Perceiver structure that incorporates a cross-attention mechanism to perform multi-source information fusion and generate a unified latent semantic vector;

[0067] Figure 3 A flowchart for modeling semantic state evolution path functions based on the regular differential equations of God. Detailed Implementation

[0068] The present invention will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, illustrating only the basic structure of the invention, and therefore only show the components relevant to the invention.

[0069] refer to Figures 1-3 A method for medical dialogue understanding and generation based on the Transformer model includes the following steps:

[0070] Medical text, structured medical record data, and historical dialogue content are acquired and embedded and mapped to obtain embedded representations of medical text, structured medical records, and historical dialogues.

[0071] The medical text embedding representation, structured medical record embedding representation, and historical dialogue embedding representation are taken as input and passed to the Perceiver structure containing a cross-attention mechanism to perform information fusion operation and generate a unified latent semantic vector.

[0072] The unified latent semantic vector is used as the initial semantic state and input into the semantic state evolution function constructed based on the divine constant differential equation. The current dialogue round is used as the time variable to generate the semantic state evolution path function.

[0073] Based on the semantic state evolution path function and the current dialogue round, perform state solving operation to obtain the continuous semantic state vector under the current dialogue round;

[0074] The continuous semantic state vector of the current dialogue round is fused with the historical dialogue embedding representation to construct a context control semantic vector, and medical entity references are extracted from it.

[0075] The context control semantic vector is input into a natural language generation model built on a Transformer decoder, and response text generation guided by semantic trajectory is performed to obtain the initial medical dialogue response text.

[0076] Perform semantic state evolution path consistency check and medical entity referencing consistency check on the initial medical dialogue response text, remove response content that does not meet trajectory logic or entity constraints, and output the final medical dialogue response text.

[0077] In this embodiment, obtaining the medical text embedding representation, the structured medical record embedding representation, and the historical dialogue embedding representation includes:

[0078] The medical text is segmented, and the lexical units are standardized and encoded based on the medical vocabulary. The encoded medical text is then input into a pre-trained Transformer encoder to extract the context semantic vector. Average pooling is then applied to generate the embedded representation of the medical text.

[0079] The numerical fields in the structured medical record data are normalized, the categorical fields are one-hot encoded, the field vectors are concatenated to form a multidimensional feature vector, and then input into a feedforward neural network for mapping, outputting a structured medical record embedding representation.

[0080] The historical dialogue content is segmented into rounds and arranged in chronological order to form a dialogue sequence. Each round of questions and answers is segmented and encoded, and then a role tag and a timestamp tag are added before being input into the Transformer encoder to extract the semantic dependencies between rounds and generate a historical dialogue embedding representation.

[0081] In this embodiment, the generation of the unified latent semantic vector includes:

[0082] Embedding dimension alignment is performed on medical text embedding representation, structured medical record embedding representation, and historical dialogue embedding representation respectively to ensure that the three types of embedding representation have a unified semantic space structure, and a data source identifier field is added to each type of embedding representation;

[0083] The medical text embedding representation, structured medical record embedding representation, and historical dialogue embedding representation after the additional data source identifier field are organized into a structured input sequence according to a set order, and the structured input sequence is encapsulated into a tensor data structure with channel identifiers;

[0084] The tensor data structure with channel identifiers is passed to the Perceiver structure containing a cross-attention mechanism through a dedicated input interface, which supports receiving structured input sequences and externally set fusion control parameters simultaneously.

[0085] Before the structured input sequence is passed into the Perceiver structure, the set fusion control parameters are called. The fusion control parameters are used to limit the information fusion method of cross-attention between different data sources, the interaction order between channels, and the fusion intensity ratio.

[0086] After receiving the structured input sequence and fusion control parameters, the Perceiver structure performs semantic alignment and cross-source information fusion operations based on the data source identifier field attached to the embedded representation and the channel rules set in the fusion control parameters, and outputs a unified latent semantic vector.

[0087] The defined channel rules include establishing a channel mapping table in the external fusion control module based on the data source identifier fields carried by the medical text embedding representation, structured medical record embedding representation, and historical dialogue embedding representation, mapping each type of embedding representation to the corresponding channel type, and configuring a channel priority matrix and an allowed interaction relationship matrix in the fusion control parameters to control the information cross-strategy between different channels. When performing information fusion, the Perceiver structure receives the structured input sequence, identifies its channel type based on the data source identifier field attached to each embedding representation, and dynamically adjusts the interaction strength between the query and key-value pairs in the cross-attention mechanism in combination with the channel priority matrix. Semantic alignment is achieved by matching the attention priority of the query channel with the allowed interaction weight of the followed channel. The semantic alignment is achieved by strengthening the attention weighting of the current query channel on related entities, diagnostic terms, or time segments, and finally fusing the aligned attention information in each channel before outputting the latent semantic representation.

[0088] In this embodiment, the Perceiver structure including the cross-attention mechanism includes:

[0089] A semantic path splitting operation is performed on the structured input sequence input to the Perceiver structure. Based on the semantic category, the structured input sequence is divided into medical entity path representation, medical reasoning path representation and contextual path representation, which respectively constitute medical entity path embedding representation, medical reasoning path embedding representation and contextual path embedding representation;

[0090] Based on the above three types of path embedding representations, a structured semantic query vector is constructed. The medical entity path embedding representation is used as the first type of query vector, the medical reasoning path embedding representation is used as the second type of query vector, and the context path embedding representation is used as the third type of query vector. These vectors are then used to perform multi-path interaction and fusion operations with the embedding representations in the structured input sequence.

[0091] The path-level cross-attention mechanism is executed separately. The first type of query vector is cross-attentioned with the medical entity content of the structured input sequence to generate an entity path fusion representation. The second type of query vector is cross-attentioned with the inference content in the structured input sequence to generate an inference path fusion representation. The third type of query vector is cross-attentioned with the context content in the structured input sequence to generate a background path fusion representation.

[0092] The entity path fusion representation, inference path fusion representation, and background path fusion representation are fused according to a preset path fusion order and fusion intensity parameters.

[0093] In this embodiment, the generation of the semantic state evolution path function includes:

[0094] The unified latent semantic vector is used as the initial semantic state vector of the semantic state evolution path function, and the current dialogue turn is mapped to a continuous time variable;

[0095] A semantic state derivative function containing a neural network structure is constructed. The semantic state derivative function receives the semantic state vector and time variable as input and outputs the derivative value of the semantic state at the current time point. The neural network structure constitutes a neural frequent differential modeling unit as part of the semantic state evolution path function.

[0096] Set the time integration interval and computational precision parameters of the semantic state evolution path function, call the built-in ordinary differential equation solver of the neuro-ordinary differential modeling unit, perform numerical integration on the semantic state derivative function, and generate a semantic state evolution trajectory covering the entire dialogue round.

[0097] Record the semantic state vector corresponding to each time point in the semantic state evolution trajectory to form a continuous semantic state vector sequence. The semantic state vector sequence serves as a stage output of the semantic state evolution path function during the generation process.

[0098] The semantic state vector corresponding to the current dialogue turn is extracted and used as the semantic control vector input of the natural language generation module;

[0099] The time integration interval for setting the semantic state evolution path function includes: determining the starting time point of semantic state evolution based on the historical round information of the medical dialogue, mapping the first round of dialogue to the initial time point, and mapping the round number corresponding to the current generated round to the target time point, thus forming the time integration interval; the time variable is mapped from discrete round numbers to a continuous real number interval through linear normalization, for example, mapping the round number range [1, N] to the interval [0.0, 1.0]; the calculation accuracy parameters include the time step and the error tolerance, wherein the time step is determined in reverse based on the predicted length of the target generated response, and a smaller step is used for longer responses, and the error tolerance is set to a fixed value to control the local error limit of the ordinary differential equation solver at each time step; the solver performs numerical integration based on the above time integration interval and accuracy parameters to generate a semantic state vector sequence with stable convergence within the complete time interval.

[0100] In this embodiment, obtaining the continuous semantic state vector under the current dialogue turn includes:

[0101] Receive the current dialogue round number and map the corresponding dialogue round number to a continuous time variable, which serves as the target solution time point for the semantic state evolution path function;

[0102] The semantic state evolution path function is invoked, and the unified latent semantic vector is used as the initial semantic state vector of the semantic state evolution path function. The continuous time variable is used as the target time point and input into the semantic state evolution path function.

[0103] Using the built-in ordinary differential equation solver of the divine ordinary differential modeling unit, with the initial semantic state vector and the target solution time point as boundary conditions, a single-point forward integration operation is performed at the time point to generate a continuous semantic state vector under the current dialogue round.

[0104] The single-point forward integration operation at the execution time point includes: setting an integration start point and an integration end point between the determined initial semantic state vector and the target time point; calling the ordinary differential equation solver in the ordinary differential modeling unit; using the semantic state derivative function as the integrand; and performing forward numerical integration only once along the positive direction of the time axis towards the target time point under a fixed step size, without performing full-range trajectory expansion; during the integration process, the Runge-Kutta method is used to iteratively calculate the derivative value of the current semantic state at the target time point until the error tolerance meets the set conditions, thereby obtaining the single-point continuous semantic state vector corresponding to the current dialogue round.

[0105] In this embodiment, the construction of the context control semantic vector includes:

[0106] Construct the first input path by marking the position of the continuous semantic state vectors under the current dialogue round and writing them into the semantic state path cache to form the first input path;

[0107] Construct a second input path by embedding historical dialogues into a representation that is divided according to round and role information, and injecting time phase encoding in combination with the corresponding time index to form a historical context path;

[0108] Construct a third input path, identify medical entity information involved in historical dialogue embedding representation and continuous semantic state vector, and generate entity alignment path, where each entity node has reference direction and context dependency annotation;

[0109] The first input path, the second input path, and the third input path are input into the path fusion interface, the path identifier is encoded according to the path type, and a path control mapping matrix is ​​constructed.

[0110] The path control mapping matrix is ​​invoked to perform a structural-level weighted combination operation on the three types of input paths, and a path bias term is introduced as a guiding factor to form a fused path representation.

[0111] Extract the fusion result of the current dialogue round node from the fusion path representation and use it as the context control semantic vector;

[0112] The path type refers to the semantic information pathway category set during the construction of context-controlled semantic vectors to achieve structured fusion of information such as semantic state, historical context, and entity constraints. It mainly includes the following three categories: The first type is the semantic state path, used to carry the continuous semantic state vector of the current dialogue turn obtained based on the solution of neural constant differential equations, and includes a dialogue turn identifier and time label; the second type is the historical context path, used to represent the historical dialogue embedding representation organized by turn, role, and time order, and retains the context window structure and time sequence encoding information; the third type is the entity alignment path, used to connect the historical dialogue embedding representation with the medical entities involved in the current semantic state, and introduces entity reference numbers and semantic pointing relationships to indicate the entity source, context position, and semantic dependency method. Each type of path is explicitly distinguished through the path identifier field during the fusion stage, and a differentiated fusion strategy is executed according to the path type in the path fusion interface.

[0113] The inter-path bias term refers to a learnable parameter term set during the construction of context control semantic vectors to achieve differential adjustment and information flow guidance control when fusing different semantic path types. This bias term is dynamically allocated according to the combination of path types and mainly includes three bias modes: time alignment bias between semantic state path and historical context path, used to strengthen semantic continuity between adjacent rounds; entity mapping bias between semantic state path and entity alignment path, used to enhance the current semantic state's ability to focus on key medical entities; and reference transfer bias between historical context path and entity alignment path, used to model the semantic transfer direction and reference strength of entities in the dialogue evolution process. Each pair of path combinations has an independent bias tensor. The bias term participates in the calculation of inter-path fusion weights as an attention score correction term during the fusion stage, thereby guiding the fusion process to follow the semantic evolution logic and entity consistency requirements while maintaining structural distinguishability.

[0114] In this embodiment, the generation of the initial medical dialogue response text includes:

[0115] A natural language generation model containing a multi-layer Transformer decoder structure is constructed. The natural language generation model uses context-controlled semantic vectors as mandatory guiding inputs and controls the semantic focus area of ​​each decoding step through a guided attention mechanism.

[0116] The context control semantic vector of the current dialogue turn is copied to each decoding layer of the natural language generation model as a guiding conditional embedding for the decoding attention module. The guiding conditional embedding participates in the multi-head attention mechanism.

[0117] Using the generated historical target word sequence as the target input, and combining the attention output guided by the context-controlled semantic vector, the decoding calculation is recursively performed to generate the candidate word distribution in the dialogue response sequence;

[0118] The semantic state vector corresponding to the current round in the semantic state evolution path function is introduced as the semantic trajectory embedding vector, and semantic consistency calibration is performed with the decoding representation generated at each step to dynamically adjust the ranking weight of the candidate word distribution.

[0119] In the candidate word distribution, based on the probability weights after semantic consistency calibration, a bundle search strategy is used to select the word with the highest probability and gradually generate the initial medical dialogue response text.

[0120] In this embodiment, the generation of the final medical dialogue response text includes:

[0121] A response consistency verification module is constructed. The response consistency verification module takes the initial medical dialogue response text as input and calls the semantic state vector corresponding to the current dialogue round in the semantic state evolution path function to extract the semantic embedding vector of each sentence in the initial medical dialogue response text and calculate the cosine similarity between it and the semantic state vector.

[0122] A response semantic consistency threshold is set. If the cosine similarity between the semantic embedding vector and the semantic state vector of any statement in the initial medical dialogue response text is lower than the response semantic consistency threshold, then the statement is marked as an inconsistent statement.

[0123] A medical entity reference consistency verification module is constructed to identify all medical entity reference phrases in the initial medical dialogue response text and to perform matching verification by comparing them with the entity reference mapping rules and contextual reference order recorded in the historical dialogue embedding representation;

[0124] Define a set of entity reference consistency rules, including three types of consistency rules: entity type consistency, reference chain integrity, and role context matching. If an entity reference phrase does not meet any of the rules, the entity reference is marked as inconsistent entity reference.

[0125] Summarize all response content marked as inconsistent statements or inconsistent entity references, perform a removal operation, and update the response text;

[0126] Output the initial medical dialogue response text after the removal operation is completed, as the final medical dialogue response text;

[0127] The medical entity referencing mapping rule is based on a triple mapping relationship, including entity text matching mapping, semantic category alignment mapping, and context role association mapping. Entity text matching mapping compares standardized entity names with entity expressions appearing in historical dialogues one by one to identify completely identical or partially overlapping name expressions. Semantic category alignment mapping performs category-level verification based on the semantic tags of the entities to ensure semantic consistency between the referent and the referred to. Context role association mapping uses additional role annotations and time sequence information to determine whether the speaker's identity when the entity first appears is logically consistent with the role when it is cited. Based on the historical dialogue rounds, it establishes a citation order chain between the entity's appearance and citation. If the entity does not appear before the citation or its role is inconsistent before and after, it is determined to be inconsistent with the context citation order.

[0128] Example 1:

[0129] To verify the feasibility of this invention in practice, it was applied to outpatient data from a municipal people's hospital. The medical dialogue understanding and generation method based on the Transformer model proposed in this invention was deployed in the intelligent consultation system to achieve semantic understanding of patient input, medical record association, and automated response generation.

[0130] In this scenario, the patient first inputs their chief complaint via voice, "recent cough and headache." The system converts this input text into structured medical text and embeds it. The system retrieves the patient's electronic structured medical record, including underlying diseases (such as hypertension), allergy history, medication records, etc., and loads the historical dialogue texts from their three previous outpatient visits. All of these are then uniformly input into a Perceiver structure that includes a cross-attention mechanism. The Perceiver structure embeds the three types of input under guided conditions, performing semantic alignment and path-level fusion to obtain a unified latent semantic vector.

[0131] The unified latent semantic vector is used as the initial state input into the constructed semantic state evolution path function based on the neural constant differential equation. The time variable is derived from the current dialogue round (e.g., the 3rd round of consultation corresponds to t=0.4), and the continuous semantic state vector corresponding to the current round is obtained by forward integration through the ODE solver.

[0132] To construct a semantically consistent dialogue control vector, the system extracts the semantic state vector of the current round and constructs three paths (semantic state path, historical context path, and entity alignment path) together with the historical question-and-answer sequence and aligned medical entity information. Guided by the path control mapping matrix and the inter-path bias term, the system integrates the three types of path data to form the current context control semantic vector.

[0133] The natural language generation model employs a six-layer Transformer decoder structure. Context-controlled semantic vectors serve as guiding embedding inputs to each decoding layer. Combined with a semantic trajectory guidance mechanism, word distribution weights are dynamically adjusted. A beam search is used to progressively generate candidate response texts, such as "Have you recently had a fever or been in contact with someone who has a cold?". This response text will then enter the consistency check module.

[0134] The system calculates the cosine similarity between the semantic representation of each sentence in the candidate response and the current semantic state vector. If the similarity of a sentence is lower than the set threshold of 0.72, it is judged as semantically inconsistent and removed. For medical entities such as "headache" and "cough", the system judges whether their reference is accurate based on the entity chain of historical rounds, semantic category labels and role context. If it finds that "he" is incorrectly referred to or the entity is cited without appearing, it will also be marked and removed. Finally, the response text with semantic coherence and consistent entity references is retained.

[0135] This method was deployed in the smart outpatient department of a municipal people's hospital, covering a total of 2,453 patients and generating 11,286 rounds of question-and-answer sessions. The dialogue accuracy and user satisfaction of a traditional template-driven consultation system are compared in the table below:

[0136] Table 1 Comparison of Dialogue Accuracy and Consistency

[0137] Indicator Inventive method Conventional method Average semantic alignment consistency rate 93.6% 81.4% Medical entity reference accuracy 96.1% 84.7% Average response generation time (ms) 812 935 User satisfaction score (out of 10) 9.3 7.8 Inconsistent response rejection rate 6.7% Unable to reject

[0138] Table 2 shows the average time (ms) for each component at different stages.

[0139] Module name Average time consumption Embedding representation generation 132 Perceiver structure fusion processing 147 Neural differential path solving 208 Path fusion to generate context vector 138 Response generation and consistency checking 187

[0140] As can be seen from the comparative data in Tables 1 and 2, the method proposed in this invention significantly outperforms traditional diagnostic systems in several key dimensions, including dialogue understanding accuracy, entity referencing consistency, response generation efficiency, and user experience. Specifically, the average semantic alignment consistency rate reaches 93.6%, which is 12.2 percentage points higher than the traditional method. This indicates that the semantic path splitting and fusion mechanism and semantic state evolution modeling based on the Perceiver structure introduced in this invention can more accurately capture the deep semantic relationships between contexts, thereby generating response content that better matches the dialogue intent. The medical entity referencing accuracy rate is 96.1%, significantly better than the 84.7% of the traditional system, indicating that the entity path annotation and entity referencing consistency verification mechanism introduced in this invention effectively reduces referencing errors and contextual ambiguity.

[0141] In terms of response efficiency, although this invention employs complex mechanisms such as neural frequent differential path modeling, the average response time is controlled at 812ms, which is still about 13.1% faster than traditional methods, indicating that the model structure has good parallelism and real-time performance during the guided generation process. In user satisfaction ratings, the system received a high score of 9.3 out of 10, an improvement of 1.5 points compared to traditional methods. User feedback mainly focused on advantages such as "professional answers, clear logic, and no repetitive jumps."

[0142] Table 2 further analyzes the efficiency contribution of each module in the system: the time for embedding generation and path fusion are 132ms and 138ms respectively, indicating that the model has a fast processing capability in the input representation stage; the average time for the Perceiver structure to perform fusion is 147ms, showing that it is efficient while maintaining deep semantic modeling capabilities; the time for solving the neural constant differential path is 208ms, which is the module with the largest computational cost, but it is still within a reasonable range; the total time for the final response generation and consistency verification stages is 187ms, indicating that the semantic consistency and entity verification mechanisms do not introduce too much delay while ensuring accuracy.

[0143] In summary, the solution of this invention has significant advantages, and the performance of each sub-module is balanced, the link design is reasonable, and it has good engineering adaptability and promotion and application value.

[0144] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.

Claims

1. A method for medical dialogue understanding and generation based on the Transformer model, characterized in that, include: Medical text, structured medical record data, and historical dialogue content are acquired and embedded and mapped to obtain embedded representations of medical text, structured medical records, and historical dialogues. The medical text embedding representation, structured medical record embedding representation, and historical dialogue embedding representation are taken as input and passed to the Perceiver structure containing a cross-attention mechanism to perform information fusion operation and generate a unified latent semantic vector. The unified latent semantic vector is used as the initial semantic state and input into the semantic state evolution function constructed based on the divine constant differential equation. The current dialogue round is used as the time variable to generate the semantic state evolution path function. Based on the semantic state evolution path function and the current dialogue round, perform state solving operation to obtain the continuous semantic state vector under the current dialogue round; The continuous semantic state vector of the current dialogue round is fused with the historical dialogue embedding representation to construct a context control semantic vector, and medical entity references are extracted from it. The context control semantic vector is input into a natural language generation model built on a Transformer decoder, and response text generation guided by semantic trajectory is performed to obtain the initial medical dialogue response text. Perform semantic state evolution path consistency check and medical entity referencing consistency check on the initial medical dialogue response text, remove response content that does not meet trajectory logic or entity constraints, and output the final medical dialogue response text. The generation of unified latent semantic vectors includes: Embedding dimension alignment is performed on medical text embedding representation, structured medical record embedding representation, and historical dialogue embedding representation respectively, and a data source identifier field is added to each type of embedding representation; The medical text embedding representation, structured medical record embedding representation, and historical dialogue embedding representation after the additional data source identifier field are organized into a structured input sequence according to a set order, and the structured input sequence is encapsulated into a tensor data structure with channel identifiers; The tensor data structure with channel identifiers is passed to the Perceiver structure containing a cross-attention mechanism through a dedicated input interface, which supports receiving structured input sequences and externally set fusion control parameters simultaneously. Before the structured input sequence is passed into the Perceiver structure, the set fusion control parameters are called; After receiving the structured input sequence and fusion control parameters, the Perceiver structure performs semantic alignment and cross-source information fusion operations based on the data source identifier field attached to the embedded representation and the channel rules set in the fusion control parameters, and outputs a unified latent semantic vector.

2. The medical dialogue understanding and generation method based on the Transformer model as described in claim 1, characterized in that, The acquisition of medical text embedding representations, structured medical record embedding representations, and historical dialogue embedding representations includes: The medical text is segmented, and the lexical units are standardized and encoded based on the medical vocabulary. The encoded medical text is then input into a pre-trained Transformer encoder to extract the context semantic vector. Average pooling is then applied to generate the embedded representation of the medical text. The numerical fields in the structured medical record data are normalized, the categorical fields are one-hot encoded, the field vectors are concatenated to form a multidimensional feature vector, and then input into a feedforward neural network for mapping, outputting a structured medical record embedding representation. The historical dialogue content is segmented into rounds and arranged in chronological order to form a dialogue sequence. Each round of questions and answers is segmented and encoded, and then a role tag and a timestamp tag are added before being input into the Transformer encoder to extract the semantic dependencies between rounds and generate a historical dialogue embedding representation.

3. The medical dialogue understanding and generation method based on the Transformer model as described in claim 1, characterized in that, Perceiver structures that include cross-attention mechanisms include: A semantic path splitting operation is performed on the structured input sequence input to the Perceiver structure. Based on the semantic category, the structured input sequence is divided into medical entity path representation, medical reasoning path representation and contextual path representation, which respectively constitute medical entity path embedding representation, medical reasoning path embedding representation and contextual path embedding representation; Based on the above three types of path embedding representations, a structured semantic query vector is constructed. The medical entity path embedding representation is used as the first type of query vector, the medical reasoning path embedding representation is used as the second type of query vector, and the context path embedding representation is used as the third type of query vector. These vectors are then used to perform multi-path interaction and fusion operations with the embedding representations in the structured input sequence. The path-level cross-attention mechanism is executed separately. The first type of query vector is cross-attentioned with the medical entity content of the structured input sequence to generate an entity path fusion representation. The second type of query vector is cross-attentioned with the inference content in the structured input sequence to generate an inference path fusion representation. The third type of query vector is cross-attentioned with the context content in the structured input sequence to generate a background path fusion representation. The entity path fusion representation, inference path fusion representation, and background path fusion representation are fused according to a preset path fusion order and fusion intensity parameters.

4. The medical dialogue understanding and generation method based on the Transformer model as described in claim 1, characterized in that, The generation of the semantic state evolution path function includes: The unified latent semantic vector is used as the initial semantic state vector of the semantic state evolution path function, and the current dialogue turn is mapped to a continuous time variable; A semantic state derivative function containing a neural network structure is constructed. The semantic state derivative function receives the semantic state vector and time variable as input and outputs the derivative value of the semantic state at the current time point. The neural network structure constitutes a neural frequent differential modeling unit as part of the semantic state evolution path function. Set the time integration interval and computational precision parameters of the semantic state evolution path function, call the built-in ordinary differential equation solver of the neuro-ordinary differential modeling unit, perform numerical integration on the semantic state derivative function, and generate a semantic state evolution trajectory covering the entire dialogue round. Record the semantic state vector corresponding to each time point in the semantic state evolution trajectory to form a continuous semantic state vector sequence. The semantic state vector sequence serves as a stage output of the semantic state evolution path function during the generation process. The semantic state vector corresponding to the current dialogue turn is extracted and used as the semantic control vector input for the natural language generation module.

5. The medical dialogue understanding and generation method based on the Transformer model as described in claim 1, characterized in that, Obtaining the continuous semantic state vector in the current dialogue round includes: Receive the current dialogue round number and map the corresponding dialogue round number to a continuous time variable, which serves as the target solution time point for the semantic state evolution path function; The semantic state evolution path function is invoked, and the unified latent semantic vector is used as the initial semantic state vector of the semantic state evolution path function. The continuous time variable is used as the target time point and input into the semantic state evolution path function. Using the built-in ordinary differential equation solver of the divine ordinary differential modeling unit, the initial semantic state vector and the target solution time point are used as boundary conditions to perform a single-point forward integration operation at the time point to generate a continuous semantic state vector under the current dialogue round.

6. The medical dialogue understanding and generation method based on the Transformer model as described in claim 1, characterized in that, The construction of context control semantic vectors includes: Construct the first input path by marking the position of the continuous semantic state vectors under the current dialogue round and writing them into the semantic state path cache to form the first input path; Construct a second input path by embedding historical dialogues into a representation that is divided according to round and role information, and injecting time phase encoding in combination with the corresponding time index to form a historical context path; Construct a third input path, identify medical entity information involved in historical dialogue embeddings and continuous semantic state vectors, and generate entity alignment paths; The first input path, the second input path, and the third input path are input into the path fusion interface, the path identifier is encoded according to the path type, and a path control mapping matrix is ​​constructed. The path control mapping matrix is ​​invoked to perform a structural-level weighted combination operation on the three types of input paths, and a path bias term is introduced as a guiding factor to form a fused path representation. Extract the fusion result of the current dialogue round node from the fusion path representation and use it as the context control semantic vector.

7. The medical dialogue understanding and generation method based on the Transformer model as described in claim 1, characterized in that, The generation of the initial medical dialogue response text includes: A natural language generation model containing a multi-layer Transformer decoder structure is constructed. The natural language generation model uses context-controlled semantic vectors as mandatory guiding inputs and controls the semantic focus area of ​​each decoding step through a guided attention mechanism. The context control semantic vector of the current dialogue turn is copied to each decoding layer of the natural language generation model as a guiding conditional embedding for the decoding attention module. The guiding conditional embedding participates in the multi-head attention mechanism. Using the generated historical target word sequence as the target input, and combining the attention output guided by the context-controlled semantic vector, the decoding calculation is recursively performed to generate the candidate word distribution in the dialogue response sequence; The semantic state vector corresponding to the current round in the semantic state evolution path function is introduced as the semantic trajectory embedding vector, and semantic consistency calibration is performed with the decoding representation generated at each step to dynamically adjust the ranking weight of the candidate word distribution. In the candidate word distribution, based on the probability weights after semantic consistency calibration, a bundle search strategy is used to select the word with the highest probability and gradually generate the initial medical dialogue response text.

8. The medical dialogue understanding and generation method based on the Transformer model as described in claim 1, characterized in that, The generation of the final medical dialogue response text includes: A response consistency verification module is constructed. The response consistency verification module takes the initial medical dialogue response text as input and calls the semantic state vector corresponding to the current dialogue round in the semantic state evolution path function to extract the semantic embedding vector of each sentence in the initial medical dialogue response text and calculate the cosine similarity between it and the semantic state vector. A response semantic consistency threshold is set. If the cosine similarity between the semantic embedding vector and the semantic state vector of any statement in the initial medical dialogue response text is lower than the response semantic consistency threshold, then the statement is marked as an inconsistent statement. A medical entity reference consistency verification module is constructed to identify all medical entity reference phrases in the initial medical dialogue response text and to perform matching verification by comparing them with the entity reference mapping rules and contextual reference order recorded in the historical dialogue embedding representation; Define a set of entity reference consistency rules, including three types of consistency rules: entity type consistency, reference chain integrity, and role context matching. If an entity reference phrase does not meet any of the rules, the entity reference is marked as inconsistent entity reference. Summarize all response content marked as inconsistent statements or inconsistent entity references, perform a removal operation, and update the response text; Output the initial medical dialogue response text after the removal operation is completed, as the final medical dialogue response text.

Citation Information

Patent Citations

  • Session content key point extraction method based on reinforcement learning

    CN120353923A

  • Reinforced learning and collaboration system based on Internet hospital medical dialogues and medical records

    CN120544956A