Medical science popularization question and answer model fine tuning method and device, equipment, medium and product
By cleaning the medical text Q&A dataset and introducing low-rank matrix into the specific matrix of the large language model for fine-tuning, the problems of poor performance and high computational cost of the large language model in medical popularization Q&A tasks are solved, and more efficient and accurate medical Q&A capabilities are achieved.
Patent Information
- Application Number
- CN202411745833.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-03-21
AI Technical Summary
The large language model performs poorly in medical popularization Q&A tasks, has high computing costs, is difficult to deploy in resource-limited environments, and the general model is difficult to meet the needs of specific users.
By cleaning the medical text Q&A dataset, the QKV projection matrix in the multi-head self-attention mechanism and the weight matrix in the feedforward neural network are located, and two low-rank matrices are introduced into these matrices, fine-tuning the pre-trained large language model to generate more accurate and efficient answers.
It significantly improves the performance of large language models on medical popularization Q&A tasks, reduces computing costs, reduces the demand for resources, and makes the model more suitable for the needs of specific fields or complex contexts.
Smart Images

Figure CN119669416A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of large language model fine-tuning, and in particular to a method, device, equipment, medium and product for fine-tuning a medical popular science question-and-answer model. Background Art
[0002] In the medical field, the Medical Knowledge Q&A task aims to provide the public with reliable and easy-to-understand medical information by answering common health questions and medical doubts in the form of questions and answers. It not only focuses on the prevention and treatment of common diseases, but also covers a wide range of topics such as healthy habits in life, first aid knowledge, and mental health. Through this interactive popular science method, the public can obtain information more proactively, thereby improving their health literacy and self-management capabilities. In addition, Medical Knowledge Q&A is also committed to bridging the gap between professional medical knowledge and the general public, so that complex medical concepts can be easily understood and applied by the public, so as to make more scientific and healthy decisions in daily life. Ultimately, the goal of this task is to promote health awareness in the whole society, improve the overall health level, and reduce health problems caused by misunderstandings or lack of information through knowledge popularization and information transparency.
[0003] In recent years, the application of large model technology in medicine has been growing rapidly. However, its application in specific fields such as medical science question answering tasks has the following problems:
[0004] 1. Large models are usually trained on large and diverse datasets, so they are very versatile and can handle a wide range of tasks. However, this versatility often means that the performance on specific tasks is not ideal.
[0005] 2. In the field of popular science question-answering, traditional fine-tuning updates the parameters of all weight matrices of large models. All parameters are optimized in each training. These weight matrices have been learned in the pre-training process, but back-propagation and gradient updates are performed again during fine-tuning. All parameters are involved in the update, which leads to high computational costs, especially in large models with huge parameters. It can be seen that although large models already have powerful language processing capabilities, in specific fields or in certain complex contexts, the model may not be able to accurately understand the user's intentions. This is usually because there is insufficient data in specific fields in the training data or the model has difficulty grasping nuances in some cases.
[0006] 3. Large models are usually large in scale, have high inference and computational costs, and are difficult to deploy in resource-limited environments (such as mobile devices).
[0007] 4. Different scenarios may have different requirements and expectations for models. A general large model is difficult to meet the specific needs of all users. Summary of the invention
[0008] The purpose of this application is to provide a medical science question-and-answer model fine-tuning method, device, equipment, medium and product to solve the above-mentioned problems.
[0009] To achieve the above objectives, this application provides the following solutions:
[0010] In a first aspect, the present application provides a method for fine-tuning a medical science question-answering model, comprising:
[0011] Cleaning the data in the medical text question-answering dataset, determining a cleaned instruction-input-output paradigm dataset, and using the cleaned instruction-input-output paradigm data as a fine-tuning training dataset;
[0012] In the pre-trained large language model, the QKV projection matrix in the multi-head self-attention mechanism and the weight matrix in the feedforward neural network are located; the pre-trained large language model is trained on a large-scale data set and the pre-trained large language model is open source; the QKV projection matrix includes a Q projection matrix, a K projection matrix and a V projection matrix; Q is a query vector, K is a key vector, and V is a value vector;
[0013] Two low-rank matrices are introduced into the QKV projection matrix and the weight matrix respectively, the pre-trained large language model is fine-tuned, and a fine-tuned large language model is determined; the fine-tuned large language model is used to generate answers according to question data in a process of interaction between the user and the fine-tuned large language model; the question data includes text questions.
[0014] In a second aspect, the present application provides a device for fine-tuning a medical science question-and-answer model, comprising:
[0015] A cleaning module, used to clean the data in the medical text question-answering data set, determine a cleaned instruction-input-output paradigm data set, and use the cleaned instruction-input-output paradigm data set as a fine-tuning training data set;
[0016] The matrix positioning module is used to locate the QKV projection matrix in the multi-head self-attention mechanism and the weight matrix in the feedforward neural network in the pre-trained large language model; the pre-trained large language model is trained on a large-scale data set and the pre-trained large language model is open source; the QKV projection matrix includes the Q projection matrix, the K projection matrix and the V projection matrix; Q is the query vector, K is the key vector, and V is the value vector;
[0017] A fine-tuning module is used to introduce two low-rank matrices into the QKV projection matrix and the weight matrix respectively, fine-tune the pre-trained large language model, and determine the fine-tuned large language model; the fine-tuned large language model is used to generate answers according to question data in the process of user interaction with the fine-tuned large language model; the question data includes text questions.
[0018] In a third aspect, the present application provides a computer device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement any of the above-described methods for fine-tuning the medical science question-and-answer model.
[0019] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the above-described methods for fine-tuning the medical science question-and-answer model.
[0020] In a fifth aspect, the present application provides a computer program product, including a computer program, which, when executed by a processor, implements any of the above-mentioned methods for fine-tuning the medical science question-and-answer model.
[0021] According to the specific embodiments provided in this application, this application discloses the following technical effects: (1) This application targets a medical text question-answering dataset in the medical field, and uses a cleaned instruction-input-output paradigm dataset to fine-tune a large language model for a specific task (i.e., medical questions), thereby improving the performance of processing specific tasks.
[0022] (2) Locate the QKV projection matrix in the multi-head self-attention mechanism and the weight matrix in the feedforward neural network, and introduce two low-rank matrices in the QKV projection matrix and the weight matrix respectively, fine-tune the pre-trained large language model, and determine the fine-tuned large language model. This application uses a small-scale high-quality medical text question-answering dataset in a specific field to fine-tune the low-rank matrix part of the large language model, so that the model can better adapt to specific fields or complex context requirements. Since only the low-rank matrix is adjusted, only part of the weight matrix parameters are indirectly updated instead of adjusting all parameters, it can quickly adapt to new fields, and there is no need to train the entire model from scratch, which greatly reduces the computational cost and enhances the model's ability to grasp specific details.
[0023] (3) Since only the low-rank matrix is adjusted to indirectly update some weight matrix parameters instead of adjusting all parameters, the task-specific performance of the model is improved without significantly increasing the computing resource requirements, thereby achieving higher efficiency and better resource utilization in some application scenarios.
[0024] (4) Through fine-tuning of this application on a small-scale high-quality dataset, the model can be customized to meet the needs of specific user groups or application scenarios, such as providing personalized services for specific industries, companies or individuals. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0026] Figure 1 This is a flow chart of a method for fine-tuning a medical science question-and-answer model in one embodiment of the present application. DETAILED DESCRIPTION
[0027] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0028] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below with reference to the accompanying drawings and specific implementation methods.
[0029] The present application embodiment provides a method for fine-tuning a medical science question-and-answer model, which is executed by a computer device, and can be executed by a computer device such as a terminal or a server alone, or by a terminal and a server together. In the present application embodiment, Figure 1 As shown, the method includes the following steps 101-103.
[0030] Step 101: clean the data in the medical text question-answering dataset, determine the cleaned instruction-input-output paradigm dataset, and use the cleaned instruction-input-output paradigm data as a fine-tuning training dataset.
[0031] Step 102: In a pre-trained large language model, locate the QKV projection matrix in the multi-head self-attention mechanism and the weight matrix in the feedforward neural network; the pre-trained large language model is trained on a large-scale data set and the pre-trained large language model is open source; the QKV projection matrix includes a Q projection matrix, a K projection matrix and a V projection matrix; Q is a query vector, K is a key vector, and V is a value vector.
[0032] Step 103: Introduce two low-rank matrices into the QKV projection matrix and the weight matrix respectively, fine-tune the pre-trained large language model, and determine the fine-tuned large language model; the fine-tuned large language model is used to generate answers based on question data during the user's interaction with the fine-tuned large language model; the question data includes text questions.
[0033] In an exemplary embodiment, the large language model is built based on a Transformer model; the Transformer model includes an input layer, an encoding layer and a decoding output layer connected in sequence; wherein the encoding layer includes a multi-head self-attention mechanism, a feedforward neural network, and residual connections and layer normalization connected in sequence; the input layer is used to convert text questions into word units and generate a word unit sequence; the multi-head self-attention mechanism is used to capture the relationship between word units in the word unit sequence and automatically focus on the key elements in the text question; the feedforward neural network is used to perform a nonlinear transformation on the output of the self-attention mechanism to further enhance the model's expressive power and capture of complex features; the residual connection and layer normalization are used to train the query vector, the key vector and the value vector to determine context information; the decoding output layer is used to generate an answer based on the context information and the key elements.
[0034] In an exemplary embodiment, two low-rank matrices are introduced into the QKV projection matrix and the weight matrix respectively, the pre-trained large language model is fine-tuned, and the fine-tuned large language model is determined, which specifically includes: introducing two low-rank matrices into the QKV projection matrix to determine a new QKV projection matrix; according to the new QKV projection matrix, the input embedding vector is converted into a query vector, a key vector and a value vector, and the converted query vector, the converted key vector and the converted value vector are forward propagated and calculated, and the two low-rank matrices are optimized by back propagation; the input embedding vector is a word sequence generated by a text question; two low-rank matrices are introduced into the weight matrices corresponding to the two linear layers in the feedforward neural network respectively to determine a new weight matrix; the pre-trained large language model is fine-tuned according to the new QKV projection matrix and the new weight matrix to determine the fine-tuned large language model.
[0035] The fine-tuning process involves forward propagation and back propagation of the model. During forward propagation, the input data passes through each layer of the model, including the low-rank adaptation layer, to generate the output of the answer content for the question. During the back propagation process, only the parameters in the low-rank adaptation layer (i.e., matrices A and B) are updated, without changing the parameters of the original pre-trained model. Because only a very small number of parameters need to be updated, this method greatly reduces the required computing resources and storage requirements and performs much better than the model before fine-tuning for popular science question-answering tasks.
[0036] In an exemplary embodiment, the new matrix after introducing two low-rank matrices is: W'=W+A×B; wherein W' is a new QKV projection matrix or a new weight matrix; W is the weight corresponding to the QKV projection matrix or the weight matrix; A is the first low-rank matrix; and B is the second low-rank matrix.
[0037] In an exemplary embodiment, the loss function of the fine-tuned large language model is a cross entropy loss function; the cross entropy loss function for: Where T is the length of the word sequence; t is the time step; P(x t |x <t ; θ) is all the output x before the given time step t <t and model parameters θ, the element x at the current time step t t Conditional probability of occurrence; x t is the output element during time step t, such as a word in the sequence; x <t represents the sequence of all output elements before time step t; θ is the parameter set of the model, which includes all weights and biases learned during the training process.
[0038] In an exemplary embodiment, two low-rank matrices are introduced into the QKV projection matrix and the weight matrix respectively, the pre-trained large language model is fine-tuned, and the fine-tuned large language model is determined. The method then includes: configuring a cloud server environment, starting a training script, monitoring the training process of the fine-tuned large language model in real time, determining the changing trend of the loss function, and dynamically adjusting training hyperparameters; the hyperparameters include learning rate, batch size, and optimizer parameters; wherein configuring the cloud server environment includes selecting a GPU instance based on the fine-tuned large language model.
[0039] In another exemplary embodiment, the medical science question-answering model fine-tuning method of the present application includes the following steps:
[0040] 1. Obtain the public medical text question-answering dataset MASHQA, then perform data preprocessing to remove noise data, obtain the processed instruction-input-output paradigm dataset, and split it into training set and test set. Use the structured data as a fine-tuning training dataset and import it into a pre-trained open source large language model, such as the Generative Pre-Trained Transformer (GPT) and the Generalized Linear Model (GLM).
[0041] Taking the Zhipu Qingyan GLM large language model as an example, its architecture is based on the Transformer model, and the specific structure is as follows:
[0042] (1) Input layer.
[0043] 1.1 Vocabulary Mapping (Tokenization).
[0044] The model input is natural language text (such as a sentence or a paragraph). After receiving the input text, the model first goes through vocabulary mapping (Tokenization) to decompose the text into smaller basic units, called tokens. Each token will be mapped to a unique integer ID, indicating its position in the vocabulary.
[0045] 1.2 Embedding Layer
[0046] The input word integer ID enters the embedding layer, and each ID is converted into a fixed-dimensional vector representation, namely the word embedding vector, by looking up the embedding matrix. These vectors capture the semantic information of the input text. In order to enable the model to perceive the position of each word in the sequence, the model adds positional embedding to each word. Positional embedding represents the position of each word in the sequence, which is added to the word embedding to form the final initial input representation.
[0047] (2) Encoding layers (Transformer Encoder Layers).
[0048] 2.1 Multi-Head Self-Attention Mechanism.
[0049] The initial input representation is passed to multiple Transformer encoding layers. Each encoding layer first processes the input through a multi-head self-attention mechanism. The core of this mechanism is to capture the relationship between each word in the input sequence by calculating the similarity between the query, key, and value vectors. Specifically, the model generates query, key, and value vectors for each word, which are obtained from the embedding representation of the word through a linear transformation. The dot product is calculated between the query vector and the key vector of all other words to obtain an attention score, which represents the degree of association between these words. These scores are normalized by the Softmax function to obtain the weight of each word in the weighted sum of the generated value vector. This process is performed in parallel by multiple attention heads, each head focusing on different relationships in the input, and finally the outputs of these attention heads are spliced and integrated into the final attention output through a linear transformation.
[0050] 2.2 Feed-Forward Neural Network (FFN)
[0051] After the multi-head self-attention mechanism, the output passes through a feedforward neural network. This feedforward neural network usually contains two fully connected layers with a nonlinear activation function in the middle, such as GELU. The feedforward neural network further processes the contextual information from the attention mechanism and performs independent nonlinear transformations on the representation of each word. The output size of each feedforward neural network layer is the same as the input to maintain structural consistency.
[0052] 2.3 Residual Connection & Layer Normalization.
[0053] To prevent the gradient vanishing problem, GLM introduces a residual connection in each sublayer, that is, the input of each sublayer is directly added to the output of the sublayer. This can help the model better train deep networks and ensure that information can flow more efficiently in multiple layers. At the same time, the model uses layer normalization, which is used to stabilize the model training process and reduce the problem of gradient explosion or disappearance.
[0054] These Transformer encoding layers are stacked repeatedly multiple times. As the number of layers increases, the model gradually captures deeper semantic relationships in the context. After processing through all the encoding layers, the resulting vector representation contains rich contextual information for each word in the sequence.
[0055] (3) Decoding output layer.
[0056] 3.1 Autoregressive Decoding.
[0057] When performing text generation or prediction tasks, the processed vector representation will enter the decoding layer and the output layer. For generation tasks, GLM uses autoregressive decoding, that is, when generating each word, only the previously generated words are used as context. In this case, GLM predicts the probability distribution of the next word by step-by-step generation. During each generation step, the model calculates the conditional probability distribution of the next word based on the previously generated words and context information.
[0058] 3.2 Output probability distribution and final generation.
[0059] In the decoding layer, the generated result is mapped to the vocabulary space by the processed vector representation. Specifically, the output vector of the decoding layer is linearly transformed and the probability distribution of each word is obtained through the Softmax function. The final result generated by GLM is to select the word with the highest probability as the next word according to these probability distributions, and gradually generate the complete text or answer. This process continues until the end tag (such as the end tag of the sentence) is generated or the preset text length is reached.
[0060] 2. Initialize the large model, select and load the pre-trained large language model (such as Zhipu Qingyan GLM, Tongyi Qianwen QWEN, etc.). Ensure that the model has been trained on a large-scale dataset and has good versatility.
[0061] 3. In the Transformer model part of the pre-trained large language model, locate the QKV projection matrix contained in the multi-head self-attention mechanism and the weight matrix in the feedforward neural network, and introduce low-rank matrices A and B for each matrix. The purpose is to convert the large matrix W (hereinafter referred to as W Q , W K , W V , W1 and W2) is decomposed into the product A×B of two low-rank matrices A and B, which reduces the parameters that need to be updated during training and saves a lot of computing resources and time. At the same time, the weight of the original matrix W remains unchanged, and the newly added A×B is obtained through subsequent fine-tuning training, so that the model can not only maintain the pre-training knowledge but also adapt to the fine-tuned tasks.
[0062] The attention mechanism projection matrix introduces changes in the A and B matrices.
[0063] The three projection matrices W in the model’s multi-head self-attention mechanism Q , W K , W V , which converts the embedding vector X of the input layer into query, key and value vectors: Q = XW Q ,K=XW K ,V=XW V After the low-rank matrix is introduced, the original matrix W becomes W'=W+A×B.
[0064] The input embedding vector X is converted into query, key, and value vectors through the new weight matrix W′ for forward propagation calculation. The loss function is calculated according to the model task, and the parameters of the low-rank matrices A and B are optimized through back-propagation. A and B are low-rank matrices learned through this fine-tuning. The size of A is d×r, and the size of B is r×d. r is the rank of the low-rank matrix, which is much smaller than the rank d of the weight matrix and the projection matrix. After introducing the low-rank matrix, the new representation of the projection matrix is:
[0065] Q=X(WQ +A Q ×B Q ),K=X(W K +A K ×B K ),V=X(W V +A V ×B V ).
[0066] (2) The weight matrix of the feedforward neural network changes when the A and B matrices are introduced.
[0067] The feedforward neural network in the model usually consists of two linear layers, and the corresponding weight matrices are W1 and W2. The new representation after introducing the low-rank matrix is: W1′=W1+A1×B1, W2′=W2+A2×B2.
[0068] 4. Start the actual fine-tuning operation according to the above theoretical method: configure the cloud server environment, and select a GPU instance with sufficient computing power and memory according to the number and complexity of model parameters; then, install the necessary software environment and dependencies on the server, such as CUDA, cuDNN and other toolkits for accelerating deep learning calculations, as well as specific deep learning frameworks (such as TensorFlow, PyTorch, etc.), and ensure that all related library and tool versions are compatible to avoid unforeseen problems during training.
[0069] 5. Prepare data and model. Upload the medical text question answering dataset MASHQA for fine-tuning to the cloud server, or configure the location where the dataset is stored so that it can be easily accessed by the model. Then initialize the parameters. Load the model pre-weights and set the model's hyperparameters (such as learning rate, batch size, optimizer, etc.), using the cross entropy loss function. Measuring the difference between the model's predictions and the true labels to guide the model's optimization process.
[0070] 6. Start the training script, monitor the training process in real time, and check the changing trend of the loss function and the performance on the validation set. According to the intermediate results of the training, dynamically adjust the training hyperparameter settings, such as adjusting the learning rate, changing the optimizer parameters, etc., to ensure that the model can converge to the optimal state. After the training is completed, save the final model weights.
[0071] Compared with traditional fine-tuning methods, this application only adjusts the low-rank matrix to indirectly update the weight matrix parameters, which not only reduces the computational complexity, but also maintains the knowledge already mastered during the model's pre-training, enabling the model to perform better on specific tasks such as medical science question-and-answering, while significantly reducing the parameters and computing resources required for fine-tuning.
[0072] Based on the same inventive concept, the embodiment of the present application also provides a medical science popularization question and answer model fine-tuning device for implementing the medical science popularization question and answer model fine-tuning method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more medical science popularization question and answer model fine-tuning device embodiments provided below can refer to the limitations of the medical science popularization question and answer model fine-tuning method above, and will not be repeated here.
[0073] In an exemplary embodiment, a medical science question-answering model fine-tuning device is provided, comprising:
[0074] The cleaning module is used to clean the data in the medical text question and answer data set, determine the cleaned instruction-input-output paradigm data set, and use the cleaned instruction-input-output paradigm data set as the fine-tuning training data set.
[0075] The matrix positioning is a module, which is used to locate the QKV projection matrix in the multi-head self-attention mechanism and the weight matrix in the feedforward neural network in the pre-trained large language model; the pre-trained large language model is trained on a large-scale data set and the pre-trained large language model is open source; the QKV projection matrix includes the Q projection matrix, the K projection matrix and the V projection matrix; Q is the query vector, K is the key vector, and V is the value vector.
[0076] A fine-tuning module is used to introduce two low-rank matrices into the QKV projection matrix and the weight matrix respectively, fine-tune the pre-trained large language model, and determine the fine-tuned large language model; the fine-tuned large language model is used to generate answers according to question data in the process of user interaction with the fine-tuned large language model; the question data includes text questions.
[0077] In practical applications, the specific process of medical science question answering after low-rank adaptive fine-tuning training is as follows:
[0078] 1. Obtain problem data: Collect questions and clean the data during the user’s interaction with the model to remove noise and information irrelevant to the question.
[0079] 2. Model call: Input the cleaned questions into the fine-tuned large language model to generate answers. The model converts the input questions into vector representations that the model can understand, and then calculates through modules such as attention mechanisms and feedforward neural networks and provides an accurate and understandable answer based on the medical knowledge it has learned and the content in the corpus.
[0080] The specific process of the model calling actual operation is:
[0081] (1) The input text question is converted into a series of tokens. Each token represents a word or symbol in the text: Input_tokens = [token1, token2, ..., token n These words will then be mapped into vector representations through the embedding layer: Input_embeddings = [e1, e2, ..., e n ], where the embedding vector e i is obtained by finding the embedding matrix E: i =E[token i ].
[0082] (2) The embedding vector of the input word unit in the Transformer encoder layer captures the relationship between the word units in the sequence through the multi-head self-attention mechanism, automatically discovers and focuses on the key elements in the problem. After nonlinear transformation through the feedforward neural network, and stable training through residual connection and layer normalization, the final output contains a representation of rich contextual information, and the weight of key features is strengthened layer by layer.
[0083] The model captures the relationship between tokens in the input sequence through a multi-head self-attention mechanism, thereby focusing on the parts related to the key features of the input question. The self-attention mechanism enables the model to refer to the entire sequence when generating the representation of each token, which can automatically capture the key features of the input question and gradually strengthen the weight of these features in the final representation through stacking layers.
[0084] (3) The decoder uses a bidirectional self-attention mechanism to process context and key features and generates an answer through a mask prediction method. During the inference process, the model predicts the next word through the output layer based on the context information and the captured features. At each step, the model predicts the next word based on the current context and the generated text until the complete answer content is output.
[0085] 3. Post-processing of answers: Add a disclaimer to clearly inform users that the answers generated by the system are for reference only and cannot replace the diagnosis and advice of professional doctors.
[0086] 4. User feedback mechanism: After using the model, users can mark the accuracy and satisfaction of the answers, so that the fine-tuning strategy and data set of the model can be adjusted and optimized according to the feedback in subsequent maintenance.
[0087] 5. Information update and model retraining: Knowledge in the medical field is updated rapidly. It is necessary to regularly update the data set and re-fine-tune the model every month to ensure the timeliness and accuracy of the answers.
[0088] The technical solution of this application is described below with practical problems, for example:
[0089] I. Problem: What to do if the airway is blocked by a foreign object?
[0090] II. Process:
[0091] 1. After tokenization, it is decomposed into the following tokens ["by", "foreign object", "block", "住", "airway", "how", "to", "do", "?"] (Note: "住" here might be a character in Chinese that doesn't have a direct English equivalent in this context and is left as is for now).
[0092] These tokens are then mapped to corresponding token IDs, such as [1023, 3451, 562, 634, 1280, 2345, 982, 756, 3842, 1005], which are the unique numbers corresponding to each token.
[0093] 2. Token IDs are converted to Embedding Vectors:
[0094] Each token ID is mapped to a multi - dimensional vector (word embedding), and these vectors contain the semantic information of the tokens.
[0095] For example, the token "foreign object" is mapped to the vector [0.32, 0.45,...], representing its semantic position.
[0096] 3. The multi - dimensional vectors are input into the Transformer layer of the model:
[0097] In the Transformer layer, the vectors of each token are used to calculate the correlation with other tokens through the multi - head self - attention mechanism. This mechanism allows the model to also focus on other words in the sentence when processing a certain word. For example, when processing "blocked", the model will also focus on "foreign object" and "airway" to understand the meaning of the whole sentence.
[0098] 4. Context information fusion: As the tokens pass through multiple Transformer layers, their vector representations are gradually adjusted so that each token vector incorporates the context information of the entire sentence. For example, after processing, the token vector of "blocked" not only represents the literal meaning of this word but also contains its meaning in the context of "airway blocked".
[0099] 5. Generate output: Finally, these processed vectors are input into the output layer to generate different results in specific tasks.
[0100] Classification task: The model output may be the probabilities of classes. For example, the model determines whether a certain sentence is a medical emergency.
[0101] Question - answering task: The model will output an answer. For example, when the question is "What to do if the airway is blocked by a foreign object?", after processing, the model will generate an accurate answer based on the training data, such as "Use the Heimlich maneuver".
[0102] 3. Answer:
[0103] 1. Conscious adults or children:
[0104] Determine if it is completely blocked: If the patient can still cough or make sounds, it may be partially blocked. Encourage them to continue coughing and not pat their back.
[0105] Complete blockage: If the patient cannot breathe or speak and his face turns blue, the following steps should be taken immediately:
[0106] Heimlich maneuver (abdominal thrust):
[0107] Stand behind the patient with your feet shoulder-width apart for a steady stance.
[0108] Wrap your hands around the patient's waist, make a fist with one hand, and place the fist above the navel but not beyond the bottom of the sternum.
[0109] Use your other hand to grab your fist and quickly press inward and upward (similar to a "J" shape).
[0110] Continue impacting several times until the foreign object is expelled.
[0111] 2. Infants (under 1 year old):
[0112] Pat the back method:
[0113] Position the baby face down with the head lower than the body on your forearm, which is supported on your thigh.
[0114] Pat the baby's back gently with the base of your palm 5 times.
[0115] Chest compressions:
[0116] If back pats are ineffective, turn the baby over so that the head is still lower than the body.
[0117] Use two fingers to press under the baby's breastbone 5 times, repeating until the foreign body is expelled or the baby resumes normal breathing.
[0118] 3. When the patient loses consciousness:
[0119] Adult or Child:
[0120] Call emergency services immediately.
[0121] Lay the victim flat on the ground and begin cardiopulmonary resuscitation (CPR): chest compressions (30 times) and rescue breaths (2 times) until emergency personnel arrive or the victim resumes breathing.
[0122] If the foreign body is visible and easy to remove, you can attempt to remove it carefully.
[0123] baby:
[0124] If the baby loses consciousness, call 911 immediately.
[0125] Start CPR: chest compressions (30 times), followed by 2 rescue breaths, repeating this process until the foreign body is dislodged or emergency personnel arrive.
[0126] Note:
[0127] Never blindly use your hands to pick out foreign objects in your throat, as this may push the foreign object deeper.
[0128] If the person resumes breathing, they still need to be sent to the doctor to make sure there are no further complications.
[0129] This application introduces two low-rank matrices A and B so that the change in parameters is expressed as the product of these two matrices. This method only adjusts the low-rank matrices A and B to indirectly update the weight matrix parameters, thereby reducing the number of parameters that need to be adjusted. By introducing low-rank matrices A and B, the original weight matrix can be kept unchanged, and the model can be adjusted only by optimizing a small-scale low-rank matrix, which greatly reduces the number of parameters that need to be updated and the computational complexity. Traditional fine-tuning methods often require direct updates to all parameters of the entire weight matrix. Since the weight matrix of the pre-trained model is usually very large, containing hundreds of millions or even hundreds of billions of parameters, traditional fine-tuning methods not only result in large amounts of computation and high storage requirements, but also require more computing resources and time, and are prone to catastrophic forgetting, that is, the model loses the knowledge learned during pre-training during the fine-tuning process.
[0130] The fine-tuning process involves forward propagation and back propagation of the model. During forward propagation, the input data passes through each layer of the model, including the low-rank adaptation layer, to generate the output. During the back propagation process, only the parameters in the low-rank adaptation layer (i.e., matrices A and B) are updated without changing the parameters of the original pre-trained model. Because only a very small number of parameters need to be updated, this method not only reduces the computational complexity and greatly reduces the required computing resources, but also maintains the knowledge acquired during the pre-training of the model, and makes the model perform better on specific tasks such as medical science question answering.
[0131] In an exemplary embodiment, a computer device is provided, which may be a server or a terminal. The computer device includes a processor, a memory, an input / output interface (I / O for short) and a communication interface. The processor, the memory and the input / output interface are connected via a system bus, and the communication interface is connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store fine-tuning data of a medical science popularization question and answer model. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal via a network connection. When the computer program is executed by the processor, a method for fine-tuning a medical science popularization question and answer model is implemented.
[0132] In an exemplary embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the above method when executing the computer program.
[0133] In an exemplary embodiment, a computer-readable storage medium is provided, storing a computer program, which implements the above method when executed by a processor.
[0134] In an exemplary embodiment, a computer program product is provided, including a computer program, which implements the above method when executed by a processor.
[0135] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM may be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0136] In this application, all actions to obtain signals, information or data are carried out in compliance with the relevant data protection laws and policies of the country where they are located and with the authorization given by the owner of the corresponding device.
[0137] The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. The non-relational database may include a distributed database based on blockchain, etc., but is not limited thereto. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but is not limited thereto.
[0138] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0139] This article uses specific examples to illustrate the principles and implementation methods of this application. The description of the above embodiments is only used to help understand the method and core ideas of this application. At the same time, for those skilled in the art, according to the ideas of this application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting this application.
Claims
1. A method for fine-tuning a medical science question-answering model, characterized in that: The medical science question-answering model fine-tuning method comprises: Cleaning the data in the medical text question-answering dataset, determining a cleaned instruction-input-output paradigm dataset, and using the cleaned instruction-input-output paradigm data as a fine-tuning training dataset; In the pre-trained large language model, the QKV projection matrix in the multi-head self-attention mechanism and the weight matrix in the feedforward neural network are located; the pre-trained large language model is trained on a large-scale data set and the pre-trained large language model is open source; the QKV projection matrix includes a Q projection matrix, a K projection matrix and a V projection matrix; Q is a query vector, K is a key vector, and V is a value vector; Two low-rank matrices are introduced into the QKV projection matrix and the weight matrix respectively, the pre-trained large language model is fine-tuned, and a fine-tuned large language model is determined; the fine-tuned large language model is used to generate answers according to question data in a process of interaction between the user and the fine-tuned large language model; the question data includes text questions.
2. The method for fine-tuning the medical science question-answering model according to claim 1, characterized in that: The large language model is built based on the Transformer model; the Transformer model includes an input layer, an encoding layer and a decoding output layer connected in sequence; wherein the encoding layer includes a multi-head self-attention mechanism, a feedforward neural network, and a residual connection and layer normalization connected in sequence; the input layer is used to convert text questions into word units and generate a word unit sequence; the multi-head self-attention mechanism is used to capture the relationship between word units in the word unit sequence and automatically focus on the key elements in the text question; the feedforward neural network is used to perform a nonlinear transformation on the output of the self-attention mechanism; the residual connection and layer normalization are used to train the query vector, the key vector and the value vector to determine the context information; the decoding output layer is used to generate an answer based on the context information and the key elements.
3. The fine-tuning method of the medical science question-answering model according to claim 1, characterized in that: Introducing two low-rank matrices into the QKV projection matrix and the weight matrix respectively, fine-tuning the pre-trained large language model, and determining the fine-tuned large language model, specifically includes: In the QKV projection matrix, two low-rank matrices are introduced to determine a new QKV projection matrix; According to the new QKV projection matrix, the input embedding vector is converted into a query vector, a key vector and a value vector, and the converted query vector, the converted key vector and the converted value vector are forward propagated and calculated, and two low-rank matrices are optimized by back propagation; the input embedding vector is a word sequence generated by the text question; Into the weight matrices corresponding to the two linear layers in the feedforward neural network, two low-rank matrices are introduced respectively to determine a new weight matrix; The pre-trained large language model is fine-tuned according to the new QKV projection matrix and the new weight matrix to determine a fine-tuned large language model.
4. The fine-tuning method of the medical science question-answering model according to claim 3 is characterized in that: The new matrix after introducing two low-rank matrices is: W'=W+A×B; where W' is the new QKV projection matrix or the new weight matrix; W is the weight corresponding to the QKV projection matrix or the weight matrix; A is the first low-rank matrix; and B is the second low-rank matrix.
5. The method for fine-tuning the medical science question-answering model according to claim 1, characterized in that: The loss function of the fine-tuned large language model is a cross entropy loss function; The cross entropy loss function l(θ) is: Where T is the length of the word sequence; t is the time step; P(x t |x <t ; θ) is all the outputs x before the given time step t <t and model parameters θ, the element x at the current time step t t Conditional probability of occurrence; x t is the output element during time step t; x <t represents the sequence of all output elements before time step t; θ is the parameter set of the model, which includes all weights and biases learned during the training process.
6. The fine-tuning method for the medical popular science question-answering model according to claim 5, characterized in that: Introducing two low-rank matrices into the QKV projection matrix and the weight matrix respectively, fine-tuning the pre-trained large language model, and determining the fine-tuned large language model, and then further comprising: Configure a cloud server environment, start a training script, monitor the training process of the fine-tuned large language model in real time, determine the change trend of the loss function, and dynamically adjust the training hyperparameters; the hyperparameters include learning rate, batch size, and optimizer parameters; wherein configuring the cloud server environment includes selecting a GPU instance based on the fine-tuned large language model.
7. A medical science question-and-answer model fine-tuning device, characterized in that: The medical science question-answering model fine-tuning device comprises: A cleaning module, used to clean the data in the medical text question-answering data set, determine a cleaned instruction-input-output paradigm data set, and use the cleaned instruction-input-output paradigm data set as a fine-tuning training data set; The matrix positioning module is used to locate the QKV projection matrix in the multi-head self-attention mechanism and the weight matrix in the feedforward neural network in the pre-trained large language model; the pre-trained large language model is trained on a large-scale data set and the pre-trained large language model is open source; the QKV projection matrix includes the Q projection matrix, the K projection matrix and the V projection matrix; Q is the query vector, K is the key vector, and V is the value vector; A fine-tuning module is used to introduce two low-rank matrices into the QKV projection matrix and the weight matrix respectively, fine-tune the pre-trained large language model, and determine the fine-tuned large language model; the fine-tuned large language model is used to generate answers according to question data in the process of user interaction with the fine-tuned large language model; the question data includes text questions.
8. A computer device comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the medical science question-and-answer model fine-tuning method described in any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for fine-tuning the medical science question-and-answer model described in any one of claims 1 to 6 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method for fine-tuning the medical science question-and-answer model described in any one of claims 1 to 6 is implemented.
Citation Information
Cited By
Automatic building energy consumption modeling method based on large language model
CN120086954A
Intelligent question and answer large language model construction method for rotating machine fault diagnosis
CN120688626A
Multi-modal large language model fine tuning method, system, equipment and medium
CN121257657A