Medical question and answer method and system based on knowledge enhancement and reasoning optimization
By introducing knowledge enhancement and reasoning optimization technologies into the medical Q&A system, the problem of insufficient knowledge integration and reasoning capabilities in existing systems when dealing with complex medical problems is solved, and more efficient, more accurate and more reliable medical Q&A capabilities are achieved.
Patent Information
- Application Number
- CN202510153096.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-12
- Publication Date
- 2025-06-06
- Estimated Expiration
- 2045-02-12
AI Technical Summary
When facing complex and diverse medical problems, the existing medical Q&A system lacks effective knowledge integration and in-depth reasoning capabilities, resulting in low efficiency, low accuracy and poor reliability of medical Q&A.
A medical question-and-answer method based on knowledge enhancement and reasoning optimization is proposed. By using the preprocessed medical corpus to build an initial model, and the knowledge embedding vector generated by the knowledge graph is fused with semantic vectors to enhance the understanding and application capabilities of the model. Then, a model with medical Q&A ability is obtained by performing inference optimization through the preferences of supervised fine-tuning and detailed inference processes.
It significantly improves the efficiency and accuracy of medical questions and answers, ensures the reliability of answers, enables the system to effectively answer complex medical questions, and provides strong support for clinical decision-making.
Smart Images

Figure CN120104733A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of artificial intelligence and medical information processing, and in particular to a medical question-answering method and system based on knowledge enhancement and reasoning optimization. Background Art
[0002] With the rapid development of information technology, artificial intelligence technology is being used more and more widely in the medical field, especially in medical question-answering systems. By combining natural language processing technology and deep learning algorithms, the system can understand and answer medical-related questions raised by patients or medical professionals. Therefore, the study of medical question-answering is of great significance to the demand for medical services.
[0003] In the current medical information processing environment, facing the increasingly complex and diverse medical question-and-answer needs, traditional medical knowledge retrieval and question-and-answer systems often face multiple challenges. First, most existing systems rely on manual rules or simple matching algorithms, which are prone to misunderstanding when dealing with highly professional and complex medical problems, and cannot provide accurate and authoritative answers. Secondly, these systems lack effective knowledge integration and reasoning capabilities when facing large-scale medical knowledge bases, resulting in the inability to fully utilize existing medical resources to provide high-quality question-and-answer services. In addition, doctors and patients have gradually increased their demands for accuracy and interpretability of answers, which are difficult to meet with existing systems. With the rapid development of artificial intelligence technology, especially large language models, medical question-and-answer models based on deep learning have shown strong performance in the field of natural language processing, but existing medical question-and-answer models lack effective knowledge integration and deep reasoning capabilities when facing diverse and complex medical problems, resulting in low efficiency, low accuracy and poor reliability of medical question-and-answer. Summary of the invention
[0004] In order to solve the problems of low efficiency, low accuracy and poor reliability of medical question answering in the above-mentioned prior art, the present invention proposes a medical question answering method and system based on knowledge enhancement and reasoning optimization, which can effectively improve the efficiency, accuracy and reliability of medical question answering.
[0005] In order to achieve the above technical effects, the technical solution of the present invention is as follows:
[0006] A medical question answering method based on knowledge enhancement and reasoning optimization comprises the following steps:
[0007] S1. Obtain a medical corpus, and preprocess the medical corpus to obtain a preprocessed medical corpus;
[0008] S2. Using the preprocessed medical corpus to train the preset language model, obtaining an initial medical question-answering model for outputting semantic vectors;
[0009] S3. Generate a knowledge embedding vector using a preset knowledge graph, and fuse the knowledge embedding vector with the semantic vector to obtain a fused vector;
[0010] S4. using the fusion vector as the input of the initial medical question answering model, and fine-tuning the initial medical question answering model to obtain a fine-tuned model;
[0011] S5. Performing inference optimization on the fine-tuning model to obtain a trained medical question answering model;
[0012] S6. Input the medical question to be processed into the medical question-answering model and output the answer prediction result.
[0013] Preferably, the preprocessing of the medical corpus comprises:
[0014] S101. Define the medical corpus as where d i is the i-th document, and N is the total number of documents;
[0015] S102. The medical corpus is Clean and get the cleaned corpus The calculation expression is as follows:
[0016]
[0017] Among them, valid(d) is the data validation function;
[0018] S103. Cleaned corpus Perform word segmentation to generate a set of subword units The calculation expression is as follows:
[0019]
[0020] Among them, BPE(.) is the encoding function;
[0021] S104. Group the subword units The Lth subword unit x in L Split into fixed-length input sequences X i as follows:
[0022] X i =[x 1 ,x 2 ,…,x L ]
[0023] Where L is the sequence length;
[0024] S105. The input sequence X iAs a preprocessed medical corpus.
[0025] Preferably, the language model comprises an input layer, a Transformer encoding layer and an output layer, wherein the input layer is connected to the input end of the Transformer encoding layer, the output end of the Transformer encoding layer is connected to the output layer, and the input layer converts the input sequence X i It is represented as an embedding matrix input to the Transformer encoding layer, and the Transformer encoding layer includes multiple layers of Transformer encoders. Each layer of Transformer encoder uses a multi-head self-attention mechanism and a feedforward neural network to encode the embedding matrix to obtain an encoded output result.
[0026] Preferably, each layer of the Transformer encoder encodes the embedding matrix using a multi-head self-attention mechanism and a feedforward neural network to obtain an encoding output result, including:
[0027] S201. The first layer of Transformer encoder is added to the output of the previous layer of Transformer encoder through the multi-head self-attention mechanism, and then normalized to obtain the initial output result H (l) The calculation expression is as follows:
[0028] H (l) =LayerNorm(H (l-1) +Attention(Q (l) ,K (l) ,V (l) ))
[0029] Among them, H (l-1) is the output of the l-1th layer Transformer encoder, LayerNorm(.) is the layer normalization operation, Attention is the multi-head self-attention mechanism, Q (l) is the query matrix of the l-th layer Transformer encoder, K (l) is the key matrix of the l-th layer Transformer encoder, V (l) is the value matrix of the l-th layer Transformer encoder;
[0030] S202. The initial output result H (l) Input the feedforward neural network in the lth layer Transformer encoder to obtain the output of the current layer feedforward neural network, and compare the output of the current layer feedforward neural network with the initial output result H (l) Add them together and go through layer normalization to get the encoding output H′ of the lth layer Transformer encoder(l) as follows:
[0031] H′ (l) =LayerNorm(H (l) +FFN(H (l) ))
[0032] Among them, FFN(.) is a feedforward neural network, H (l) is the initial output result of the l-th layer Transformer encoder.
[0033] Preferably, the first training total loss function is used The language model is trained, and the calculation expression of the first training total loss function is:
[0034]
[0035] Among them, α is a hyperparameter used to control the weight of the masked language model task, and β is a hyperparameter used to control the weight of the next sentence prediction task; is the loss function for training the masked language model task, The loss function for training the next sentence prediction task.
[0036] Preferably, the knowledge graph is represented as a directed graph in is the node set containing medical entities; ε is the edge set used to describe the relationship between medical entities, and each edge is represented by e = (v i ,v j ,r), where r is the relationship type; the method of using a preset knowledge graph to generate a knowledge embedding vector includes:
[0037] S301. According to the nodes in the knowledge graph, a multi-layer graph neural network is used to calculate the node embedding vector in the knowledge graph as follows:
[0038]
[0039] in, is the node embedding calculated by the l-th layer of the graph neural network, σ is the activation function, is a set of relationship types, For node v i The neighbor set of is the attention parameter, W r is the projection matrix of relation type r, is the node embedding calculated by the l-1th layer of the graph neural network;
[0040] S302. Based on node embedding Calculate the final node embedding vector h i The expression is as follows:
[0041]
[0042] Where L is the total number of layers of the graph neural network;
[0043] S303. Based on the node embedding vector h i , calculate the knowledge embedding vector H G The expression is as follows:
[0044] H G =[h 1 ,h 2 ,…,h n ]
[0045] Where n is the total number of nodes in the knowledge graph.
[0046] Preferably, the knowledge embedding vector is fused with the semantic vector to obtain a fused vector Z fusion The calculation expression is as follows:
[0047] Z fusion =Concat(H L ,H G )W z
[0048] Among them, H L is the knowledge embedding vector, H G is the semantic vector, Concat(·) is the vector concatenation operation, W f is the fusion mapping matrix for the fine-tuning training phase.
[0049] Preferably, the second training total loss function is used The medical question answering initial model is fine-tuned, and the second training total loss function The calculation expression is as follows:
[0050]
[0051] in, The optimization objective loss function generated for the answer, is the semantic loss function;
[0052] The optimization objective loss function The calculation expression is as follows:
[0053]
[0054] Among them, P(.) is the probability distribution function, T is the total number of generated true answer words, is the tth generated true answer word in the ith sample, Generate the sequence for the history in the i-th sample, Q i is the input sequence of the ith medical question, and θ is the model parameter;
[0055] The semantic loss function The calculation expression is as follows:
[0056]
[0057] Among them, Embed(·) is the answer semantic embedding function, N is the total number of samples, A i is the true answer to the question, The answer generated for the fine-tuned model, ||.|| represents the norm of the vector.
[0058] Preferably, the performing reasoning optimization on the fine-tuning model includes:
[0059] S501. Initialize the reasoning path using the fusion vector and medical question after fine-tuning the fine-tuning model;
[0060] S502. Decomposing the medical problem into multiple sub-problems under the reasoning path, and generating an answer corresponding to each sub-problem;
[0061] S503. Calculate the total path loss function of the reasoning path according to the answer corresponding to each sub-question and the weight adjustment item of the reasoning path;
[0062] S504. Perform path optimization on the path loss function to obtain a medical question-answering model that outputs a final answer.
[0063] The present invention also proposes a medical question-answering system based on knowledge enhancement and reasoning optimization, comprising:
[0064] A preprocessing module, used for acquiring a medical corpus, preprocessing the medical corpus, and obtaining a preprocessed medical corpus;
[0065] A model training module is used to train a preset language model using the preprocessed medical corpus to obtain an initial medical question-answering model for outputting a semantic vector;
[0066] A knowledge embedding module, used to generate a knowledge embedding vector using a preset knowledge graph, and fuse the knowledge embedding vector with the semantic vector to obtain a fused vector;
[0067] A fine-tuning module, used to use the fusion vector as the input of the initial medical question answering model, fine-tune the initial medical question answering model, and obtain a fine-tuning model;
[0068] An inference optimization module, used to perform inference optimization on the fine-tuning model to obtain a trained medical question-answering model;
[0069] The prediction module is used to input the medical question to be processed into the medical question-answering model and output the answer prediction result.
[0070] Compared with the prior art, the technical solution of the present invention has the following beneficial effects:
[0071] The present invention proposes a medical question-answering method and system based on knowledge enhancement and reasoning optimization. First, a preprocessed medical corpus is used to construct an initial model of medical question-answering. By integrating the knowledge embedding vector generated by the knowledge graph and the semantic vector output by the initial model of medical question-answering, the ability of the initial model of medical question-answering to understand and apply medical knowledge is enhanced. Then, the initial model of medical question-answering is fine-tuned in a supervised manner, and the preference of the detailed reasoning process is introduced for reasoning optimization, so as to obtain a medical question-answering model with medical question-answering ability. The medical question-answering model is further used to predict answers to medical questions to be processed. The present invention not only improves the efficiency and accuracy of medical question-answering, but also ensures the reliability of the answers, so that it can efficiently answer complex medical problems and provide strong support for clinical decision-making. BRIEF DESCRIPTION OF THE DRAWINGS
[0072] Figure 1 A flowchart showing a medical question answering method based on knowledge enhancement and reasoning optimization proposed in an embodiment of the present invention;
[0073] Figure 2 Another flowchart of a medical question answering method based on knowledge enhancement and reasoning optimization proposed in an embodiment of the present invention is shown;
[0074] Figure 3 A flowchart of the inference optimization process proposed in an embodiment of the present invention is shown;
[0075] Figure 4 A structural block diagram of a medical question answering system based on knowledge enhancement and reasoning optimization proposed in an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0076] The drawings are for illustrative purposes only and should not be construed as limiting the present patent;
[0077] It is understandable to those skilled in the art that some well-known contents may be omitted in the drawings;
[0078] The technical solution of the present invention is further described below in conjunction with the accompanying drawings and embodiments.
[0079] Example 1
[0080] like Figure 1 and Figure 2 As shown, this embodiment proposes a medical question answering method based on knowledge enhancement and reasoning optimization, including the following steps:
[0081] S1. Obtain a medical corpus, and preprocess the medical corpus to obtain a preprocessed medical corpus;
[0082] In S1, the medical corpus includes clinical guidelines, medical literature and case reports, covering language expressions and professional terms in various medical fields. The medical corpus is preprocessed through data cleaning and formatting operations to generate an input format suitable for language model training. The preprocessing of the medical corpus includes:
[0083] S101. Define the medical corpus as where d i is the i-th document, N is the total number of documents, and the contents in the medical corpus are screened based on medical professionalism;
[0084] S102. The medical corpus is Clean and get the cleaned corpus The calculation expression is as follows:
[0085]
[0086] Among them, valid(d) is a data validation function that meets the requirements of format integrity and professionalism;
[0087] During the corpus cleaning process, irrelevant non-medical content, redundant characters, and incomplete documents are removed, and the spelling and format of medical terms are standardized;
[0088] S103. Use Byte Pair Encoding (BPE) algorithm to clean the corpus To perform word segmentation, BPE gradually generates a set of sub-word units by merging high-frequency word pairs Generate a set of subword units The calculation expression is as follows:
[0089]
[0090] Among them, BPE(.) is the encoding function; the subword unit set is generated Used to represent medical-related professional terms and high-frequency words;
[0091] S104. Group the subword units The Lth subword unit x in L Split into fixed-length input sequences Xi as follows:
[0092] X i =[x 1 ,x 2 ,…,x L ]
[0093] Where L is the sequence length;
[0094] S105. The input sequence X i As a preprocessed medical corpus; each document is segmented into a sequence to generate a set of subword sequences, forming a structured data format suitable for the preset language model input.
[0095] S2. Using the preprocessed medical corpus to train the preset language model, obtaining an initial medical question-answering model for outputting semantic vectors;
[0096] S3. Generate a knowledge embedding vector using a preset knowledge graph, and fuse the knowledge embedding vector with the semantic vector to obtain a fused vector;
[0097] S4. using the fusion vector as the input of the initial medical question answering model, and fine-tuning the initial medical question answering model to obtain a fine-tuned model;
[0098] S5. Performing inference optimization on the fine-tuning model to obtain a trained medical question answering model;
[0099] S6. Input the medical question to be processed into the medical question-answering model and output the answer prediction result.
[0100] In this embodiment, the existing medical question-answering system lacks effective knowledge integration and deep reasoning capabilities when facing diverse and complex medical problems, resulting in weak accuracy and interpretability of answers, that is, low efficiency, accuracy and reliability of medical question-answering. This embodiment proposes a medical question-answering method based on knowledge enhancement and reasoning optimization. First, the preprocessed medical corpus is used to construct an initial model of medical question-answering. By integrating the knowledge embedding vector generated by the knowledge graph and the semantic vector output by the initial model of medical question-answering, the initial model of medical question-answering is enhanced to understand and apply medical knowledge. Then, the initial model of medical question-answering is fine-tuned in a supervised manner, and the preference of detailed reasoning process is introduced for reasoning optimization to obtain a medical question-answering model with medical question-answering capabilities. The medical question-answering model is further used to predict answers to medical questions to be processed. The present invention not only improves the efficiency and accuracy of medical question-answering, but also ensures the reliability of answers, so that it can efficiently answer complex medical problems and provide strong support for clinical decision-making. This method constructs a medical question-answering model to solve the problem that the existing medical question-answering system lacks knowledge support and detailed reasoning ability when dealing with complex medical problems, resulting in low efficiency, low accuracy and poor reliability of medical question-answering, thereby improving the accuracy, reasoning depth and application breadth of the medical question-answering model in medical question-answering tasks.
[0101] Example 2
[0102] See also Figure 1 and Figure 2 S2 uses the preprocessed medical corpus to train the preset language model. The input is the medical corpus after cleaning, word segmentation and formatting, represented by {X 1 ,X 2 ,…,X N}, where each input sequence X i =[x 1 ,x 2 ,…,x L ] contains L subword units; the language model is based on the Transformer architecture and encodes the input through a multi-layer attention mechanism; the language model includes an input layer, a Transformer encoding layer and an output layer, the input layer is connected to the input end of the Transformer encoding layer, the output end of the Transformer encoding layer is connected to the output layer, and the input layer converts the input sequence X i It is represented as an embedding matrix input to the Transformer encoding layer, and the Transformer encoding layer includes multiple layers of Transformer encoders. Each layer of Transformer encoder uses a multi-head self-attention mechanism and a feedforward neural network to encode the embedding matrix to obtain an encoded output result.
[0103] Each layer of Transformer encoder encodes the embedding matrix using a multi-head self-attention mechanism and a feedforward neural network, and the input of the language model is represented as an embedding matrix:
[0104] E i =Embed(X i )
[0105] Among them, Embed(·) is the embedding function, which maps the input sequence to the embedding space of fixed dimension to obtain the encoding output result, including:
[0106] S201. The first layer of Transformer encoder is added to the output of the previous layer of Transformer encoder through the multi-head self-attention mechanism, and then normalized to obtain the initial output result H (l) The calculation expression is as follows:
[0107] H (l) =LayerNorm(H (l-1) +Attention(Q (l) ,K (l) ,V (l) ))
[0108] Among them, H (l-1) is the output of the l-1th layer Transformer encoder, LayerNorm(.) is the layer normalization operation, Attention is the multi-head self-attention mechanism, Q (l) is the query matrix of the l-th layer Transformer encoder, K (l) is the key matrix of the l-th layer Transformer encoder, V (l) is the value matrix of the l-th layer Transformer encoder;
[0109] The calculation formula of the multi-head self-attention mechanism Attention is as follows
[0110]
[0111] d k is the dimension of the attention head;
[0112] S202. The initial output result H (l) Input the feedforward neural network in the lth layer Transformer encoder to obtain the output of the current layer feedforward neural network, and compare the output of the current layer feedforward neural network with the initial output result H (l) Add them together and go through layer normalization to get the encoding output H′ of the lth layer Transformer encoder (l) as follows:
[0113] H′ (l) =LayerNorm(H (l) +FFN(H (l) ))
[0114] Among them, FFN(.) is a feedforward neural network, H (l) is the initial output result of the l-th layer Transformer encoder;
[0115] The calculation expression of FFN(.) is as follows:
[0116] FFN(H)=max(0,HW 1 +b 1 )W 2 +b 2
[0117] Among them, W 1 ,W 2 is the weight of the feedforward neural network, b 1 ,b 2 is the bias of the feedforward neural network;
[0118] Using the first training total loss function The language model is trained, and the pre-training tasks include a masked language model (MLM) task and a next sentence prediction (NSP) task; for the MLM task, a portion of the word positions in the input sequence are randomly masked, and the mask set is recorded as M. The loss function of the masked language model task is Defined as:
[0119]
[0120] Among them, X i represents the input sequence after removing the mask position;
[0121] For the NSP task, sentence pairs are randomly generated, and the language model needs to predict whether the two sentences are continuous contexts. The goal is to minimize the loss function of the training next sentence prediction task. The calculation expression is as follows:
[0122]
[0123] Among them, X j is the sentence pair input, y j represents the label, N is the total number of samples, P(y j ∣∣X j ) is a given input Xj , the language model predicts y j The probability distribution function of
[0124] The calculation expression of the first training total loss function is:
[0125]
[0126] Among them, α is a hyperparameter used to control the weight of the masked language model task, and β is a hyperparameter used to control the weight of the next sentence prediction task; is the loss function for training the masked language model task, The loss function for training the next sentence prediction task;
[0127] Finally, we get the initial model for medical question answering that outputs semantic vectors, which outputs the context representation vector of each input sequence, expressed as:
[0128]
[0129] Among them, h i is the context feature vector of the i-th subword in the sequence; is the sequence length;
[0130] Through the above steps, the training of the preset language model is completed to form an initial model for medical question answering.
[0131] Example 3
[0132] The knowledge graph described in S3 is represented as a directed graph in is the node set containing medical entities; ε is the edge set used to describe the relationship between medical entities, and each edge is represented by e = (v i ,v j ,r), where r is the relationship type; the initial representation of the node is generated by the embedding function, defined as:
[0133]
[0134] in, For node v i The initial embedding vector of , Embed(·) is a node embedding function; the knowledge embedding vector is generated by using a preset knowledge graph, and the embedding is updated by a multi-layer graph neural network (GNN), including:
[0135] S301. According to the nodes in the knowledge graph, a multi-layer graph neural network is used to calculate the node embedding vector in the knowledge graph as follows:
[0136]
[0137] in, is the node embedding calculated by the l-th layer of the graph neural network, σ is the activation function, is a set of relationship types, For node v i The neighbor set of is the attention parameter, W r is the projection matrix of relation type r, is the node embedding calculated by the l-1th layer of the graph neural network;
[0138] During the embedding update process, the graph attention mechanism is used to model the relationship between nodes and neighboring nodes, and the edge weight is calculated by the following formula:
[0139]
[0140] Among them, W r is the projection matrix of relation r, a is the attention parameter, ‖ represents the vector concatenation operation; the update formula of node embedding is:
[0141]
[0142] S302. Based on node embedding Calculate the final node embedding vector h i The expression is as follows:
[0143]
[0144] Where L is the total number of layers of the graph neural network;
[0145] S303. Based on the node embedding vector h i , calculate the knowledge embedding vector H G The expression is as follows:
[0146] H G =[h 1 ,h 2 ,…,h n ]
[0147] Where n is the total number of nodes in the knowledge graph.
[0148] In step S3, the fusion of the knowledge embedding vector and the semantic vector is achieved by the following formula:
[0149] H fusion =Concat(H L ,H G )W f
[0150] Among them, H L represents the semantic vector generated by the initial model of medical question answering, Concat(·) represents the vector concatenation operation, and W f is the fusion mapping matrix.
[0151] S4 first uses the annotated medical question answering dataset to fine-tune the initial medical question answering model. The annotated medical question answering dataset is defined as:
[0152]
[0153] Among them, Q i is the input sequence of the ith medical question, A i is the corresponding true answer, N is the total number of samples;
[0154] Then the fine-tuned model input is fused with the semantic representation vector H output by the initial medical question answering model L and the knowledge graph embedding matrix H G , embed the knowledge into vector H L Fusion with the semantic vector H G , get the fusion vector Z fusion The calculation expression is as follows:
[0155] Z fusion =Concat(H L ,H G )W z
[0156] Among them, H L is the knowledge embedding vector, H G is the semantic vector, Concat(·) is the vector concatenation operation, W f is the fusion mapping matrix for the fine-tuning training phase.
[0157] Using the second training total loss function The medical question answering initial model is fine-tuned, and the second training total loss function The calculation expression is as follows:
[0158]
[0159] in, The optimization objective loss function generated for the answer, is the semantic loss function;
[0160] The answer generation process is based on a sequence-to-sequence (Seq2Seq) model, and the generated answer sequence is defined as:
[0161]
[0162] Among them, A=[a 1 ,a 2 ,…,a T ] represents the generated answer, a t For the tth generated word, a <t is the historical generation sequence, θ is the model parameter; the optimization goal of answer generation is achieved by maximizing the log-likelihood, and the optimization goal loss function The calculation expression is as follows:
[0163]
[0164] Among them, P(.) is the probability distribution function, T is the total number of generated true answer words, is the tth generated true answer word in the ith sample, Generate the sequence for the history in the i-th sample, Q i is the input sequence of the ith medical question, and θ is the model parameter;
[0165] To improve the semantic consistency of the answers generated by the model, the semantic loss function Add a semantic matching regularization term based on vector similarity, and the semantic loss function The calculation expression is as follows:
[0166]
[0167] Among them, Embed(·) is the answer semantic embedding function, N is the total number of samples, A i is the true answer to the question, The answer generated for the fine-tuned model, ||.|| represents the norm of the vector.
[0168] The fine-tuned model is optimized for inference, see Figure 3 ,include:
[0169] S501. Initialize the reasoning path using the fusion vector and medical question after fine-tuning the fine-tuning model;
[0170] In S501, the fine-tuning model input is composed of the fine-tuned fusion representation vector Z fusion and the medical question Q, which is used to initialize the reasoning path;
[0171] S502. Decomposing the medical problem into multiple sub-problems under the reasoning path, and generating an answer corresponding to each sub-problem;
[0172] In S502, the reasoning optimization decomposes the complex medical problem into a sequence of multiple sub-problems through a step-by-step reasoning strategy as follows:
[0173] Q = {q 1 ,q 2 ,…,q K}
[0174] Among them, q k is the kth subproblem, K is the subproblem q k The total number of subproblems is controlled by the current problem state and the fusion representation;
[0175] The state transition generated by the subproblem is defined by the following formula:
[0176] s k+1 =RNN(s k ,z k )
[0177] Among them, s k represents the current reasoning state, z k is the current input representation, RNN is a recursive neural network module used to model the sequence relationship of the reasoning path;
[0178] The answer to each sub-question is generated through a Seq2Seq model, defined as:
[0179]
[0180] Among them, a k =[a k,1 ,a k,2 ,…,a k,T ] is the answer sequence of the sub-questions, a k,t is the tth generated word;
[0181] S503. Calculate the total path loss function of the reasoning path according to the answer corresponding to each sub-question and the weight adjustment item of the reasoning path;
[0182] In S503, the total path loss function combines the answers to each sub-question to generate the loss and path weight adjustment term, which is defined as:
[0183]
[0184] in, Generate the loss for the answer to the kth sub-question, μ is the regularization coefficient of the path weight adjustment term;
[0185] S504. Optimizing the path loss function to obtain a medical question-answering model that outputs a final answer;
[0186] In S504, the path optimization of the path loss function is mainly completed by optimizing the path weight parameters, and the optimization of the path weight parameters is completed by the policy gradient algorithm to maximize the cumulative reward of the entire reasoning path:
[0187]
[0188] Among them, R k is the immediate reward at step k, π θ Represents the current reasoning strategy, reward function R k is defined as:
[0189]
[0190] in, is the similarity between the generated answer and the true answer, α is the path smoothing weight;
[0191] The final answer is the combination of the answers to all the sub-questions:
[0192] A final =Combine({a 1 ,a 2 ,…,a K})
[0193] Among them, Combine(·) is the answer integration function, which combines the intermediate reasoning results of each sub-question so that the trained medical question-answering model can generate a complete answer.
[0194] Example 4
[0195] This embodiment proposes a medical question answering system based on knowledge enhancement and reasoning optimization, including:
[0196] A preprocessing module, used for acquiring a medical corpus, preprocessing the medical corpus, and obtaining a preprocessed medical corpus;
[0197] A model training module is used to train a preset language model using the preprocessed medical corpus to obtain an initial medical question-answering model for outputting a semantic vector;
[0198] A knowledge embedding module, used to generate a knowledge embedding vector using a preset knowledge graph, and fuse the knowledge embedding vector with the semantic vector to obtain a fused vector;
[0199] A fine-tuning module, used to use the fusion vector as the input of the initial medical question answering model, fine-tune the initial medical question answering model, and obtain a fine-tuning model;
[0200] An inference optimization module, used to perform inference optimization on the fine-tuning model to obtain a trained medical question-answering model;
[0201] The prediction module is used to input the medical question to be processed into the medical question-answering model and output the answer prediction result.
[0202] In this embodiment, the existing medical question-answering system lacks effective knowledge integration and deep reasoning capabilities when facing diverse and complex medical problems, resulting in weak accuracy and interpretability of answers, that is, low efficiency, accuracy and reliability of medical question-answering. This embodiment proposes a medical question-answering system based on knowledge enhancement and reasoning optimization. First, the preprocessed medical corpus is used to construct a medical question-answering initial model. By integrating the knowledge embedding vector generated by the knowledge graph and the semantic vector output by the medical question-answering initial model, the understanding and application capabilities of the medical question-answering initial model for medical knowledge are enhanced; then, the medical question-answering initial model is fine-tuned in a supervised manner, and the preference of the detailed reasoning process is introduced for reasoning optimization to obtain a medical question-answering model with medical question-answering capabilities; the medical question-answering model is further used to predict the answers to the medical questions to be processed. The present invention not only improves the efficiency and accuracy of medical question-answering, but also ensures the reliability of the answers, so that it can efficiently answer complex medical problems and provide strong support for clinical decision-making. This system enhances the understanding and reasoning capabilities of medical professional problems, significantly improves the accuracy and reliability of answers, and realizes autonomous processing and efficient answers to complex medical problems.
[0203] Obviously, the above embodiments of the present invention are only examples for clearly illustrating the present invention, and are not intended to limit the implementation methods of the present invention. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all implementation methods here. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the claims of the present invention.
Claims
1. A medical question answering method based on knowledge enhancement and reasoning optimization, characterized in that: The following steps are involved: S1. Obtain a medical corpus, and preprocess the medical corpus to obtain a preprocessed medical corpus; S2. Using the preprocessed medical corpus to train the preset language model, obtaining an initial medical question-answering model for outputting semantic vectors; S3. Generate a knowledge embedding vector using a preset knowledge graph, and fuse the knowledge embedding vector with the semantic vector to obtain a fused vector; S4. using the fusion vector as the input of the initial medical question answering model, and fine-tuning the initial medical question answering model to obtain a fine-tuned model; S5. Performing inference optimization on the fine-tuning model to obtain a trained medical question answering model; S6. Input the medical question to be processed into the medical question-answering model and output the answer prediction result.
2. The medical question answering method based on knowledge enhancement and reasoning optimization according to claim 1, characterized in that: The preprocessing of the medical corpus comprises: S101. Define the medical corpus as where d i is the i-th document, and N is the total number of documents; S102. The medical corpus is Clean and get the cleaned corpus The calculation expression is as follows: Among them, valid(d) is the data validation function; S103. Cleaned corpus Perform word segmentation to generate a set of subword units The calculation expression is as follows: Among them, BPE(.) is the encoding function; S104. Group the subword units The Lth subword unit x in L Split into fixed-length input sequences X i as follows: X i =[x1,x2,…,x L ] Where L is the sequence length; S105. The input sequence x i As a preprocessed medical corpus.
3. The medical question answering method based on knowledge enhancement and reasoning optimization according to claim 1, characterized in that: The language model includes an input layer, a Transformer encoding layer and an output layer. The input layer is connected to the input end of the Transformer encoding layer, and the output end of the Transformer encoding layer is connected to the output layer. The input layer converts the input sequence X i It is represented as an embedding matrix input to the Transformer encoding layer, and the Transformer encoding layer includes multiple layers of Transformer encoders. Each layer of Transformer encoder uses a multi-head self-attention mechanism and a feedforward neural network to encode the embedding matrix to obtain an encoded output result.
4. The medical question answering method based on knowledge enhancement and reasoning optimization according to claim 3 is characterized in that: Each layer of the Transformer encoder encodes the embedding matrix using a multi-head self-attention mechanism and a feedforward neural network to obtain an encoding output result, including: S201. The first layer of Transformer encoder is added to the output of the previous layer of Transformer encoder through the multi-head self-attention mechanism, and then normalized to obtain the initial output result H( l ) is calculated as follows: H (l) =LayerNorm(H (l-1) +Attention(Q (l) ,K (l) ,V (l) )) Among them, H (l-1) is the output of the l-1th layer Transformer encoder, LayerNorm(.) is the layer normalization operation, Attention is the multi-head self-attention mechanism, Q (l) is the query matrix of the l-th layer Transformer encoder, K (l) is the key matrix of the l-th layer Transformer encoder, V (l) is the lth layer Transforme r The value matrix of the encoder; S202. The initial output result H (l) Input the feedforward neural network in the lth layer Transformer encoder to obtain the output of the current layer feedforward neural network, and compare the output of the current layer feedforward neural network with the initial output result H (l) Add them together and go through layer normalization to get the lth layer Transforme r The encoding output of the encoder is H′ (l) as follows: H′ (l) =LayerNorm(H (l) +FFN(H (l) )) Among them, FFN(.) is a feedforward neural network, H (l) is the initial output result of the l-th layer Transformer encoder.
5. The medical question answering method based on knowledge enhancement and reasoning optimization according to claim 3 is characterized in that: Using the first training total loss function The language model is trained, and the calculation expression of the first training total loss function is: Among them, α is a hyperparameter used to control the weight of the masked language model task, and β is a hyperparameter used to control the weight of the next sentence prediction task; is the loss function for training the masked language model task, The loss function for training the next sentence prediction task.
6. The medical question answering method based on knowledge enhancement and reasoning optimization according to claim 1, characterized in that: The knowledge graph is represented as a directed graph in is the node set containing medical entities; ε is the edge set used to describe the relationship between medical entities, and each edge is represented by e = (v i , v j , r), where r is the relationship type; The method of generating a knowledge embedding vector by using a preset knowledge graph includes: S301. According to the nodes in the knowledge graph, a multi-layer graph neural network is used to calculate the node embedding vector in the knowledge graph as follows: in, is the node embedding calculated by the ,th layer of graph neural network, σ is the activation function, is a set of relationship types, For node v i The neighbor set of is the attention parameter, W r is the projection matrix of relation type r, is the node embedding calculated by the,-1th layer of graph neural network; S302. Based on node embedding Calculate the final node embedding vector h i The expression is as follows: Where L is the total number of layers of the graph neural network; S303. Based on the node embedding vector h i , calculate the knowledge embedding vector H G The expression is as follows: H G =[h1,h2,…,h n ] Where n is the total number of nodes in the knowledge graph.
7. The medical question answering method based on knowledge enhancement and reasoning optimization according to claim 1, characterized in that: The knowledge embedding vector is fused with the semantic vector to obtain a fusion vector Z fusion The calculation expression is as follows: Z fusion =Concat(H L ,H G )W z Among them, H L is the knowledge embedding vector, H G is the semantic vector, Concat(·) is the vector concatenation operation, W f is the fusion mapping matrix for the fine-tuning training phase.
8. The medical question answering method based on knowledge enhancement and reasoning optimization according to claim 1, characterized in that: Using the second training total loss function The medical question answering initial model is fine-tuned, and the second training total loss function The calculation expression is as follows: in, The optimization objective loss function generated for the answer, is the semantic loss function; The optimization objective loss function The calculation expression is as follows: Among them, P(.) is the probability distribution function, T is the total number of generated true answer words, is the tth generated true answer word in the ith sample, is the historical generation sequence in the i-th sample, Qi is the input sequence of the i-th medical question, and θ is the model parameter; The semantic loss function The calculation expression is as follows: Among them, Embed(·) is the answer semantic embedding function, N is the total number of samples, A i is the true answer to the question, The answer generated for the fine-tuned model, ||.|| represents the norm of the vector.
9. The medical question answering method based on knowledge enhancement and reasoning optimization according to claim 1, characterized in that: The performing reasoning optimization on the fine-tuning model includes: S501. Initialize the reasoning path using the fusion vector and medical question after fine-tuning the fine-tuning model; S502. Decomposing the medical problem into multiple sub-problems under the reasoning path, and generating an answer corresponding to each sub-problem; S503. Calculate the total path loss function of the reasoning path according to the answer corresponding to each sub-question and the weight adjustment item of the reasoning path; S504. Perform path optimization on the path loss function to obtain a medical question-answering model that outputs a final answer.
10. A medical question answering system based on knowledge enhancement and reasoning optimization, characterized in that: include: A preprocessing module, used for acquiring a medical corpus, preprocessing the medical corpus, and obtaining a preprocessed medical corpus; A model training module is used to train a preset language model using the preprocessed medical corpus to obtain an initial medical question-answering model for outputting a semantic vector; A knowledge embedding module, used to generate a knowledge embedding vector using a preset knowledge graph, and fuse the knowledge embedding vector with the semantic vector to obtain a fused vector; A fine-tuning module, used to use the fusion vector as the input of the initial medical question answering model, fine-tune the initial medical question answering model, and obtain a fine-tuning model; An inference optimization module, used to perform inference optimization on the fine-tuning model to obtain a trained medical question-answering model; The prediction module is used to input the medical question to be processed into the medical question-answering model and output the answer prediction result.
Citation Information
Patent Citations
Answer selection method and system based on semantic union
CN113342950A
Multi-hop reasoning question and answer method and system based on food safety cognitive map
CN115964459A
Knowledge graph question and answer method based on knowledge enhancement
CN117407541A
Auxiliary medical management method and system based on natural questions and answers and knowledge graph
CN118568228A
Medical knowledge graph completion method and system based on large language model
CN118863046A
Cited By
Large language model reasoning enhancement method, system, equipment and medium
CN121457647A
Digital human question and answer system
CN121658531A
Method for assisting entry of airfreight cargo manifest advisories
CN122527093A