Medical model out-of-distribution data detection method, device and equipment and medium
By using a combination of teacher model and student model in the medical dialogue intention classification model, student models are trained to detect medical out-of-distribution data, solving the problem of reduced accuracy and reliability when processing out-of-distribution data, achieving higher detection accuracy.
Patent Information
- Application Number
- CN202411447203.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-16
- Publication Date
- 2025-03-07
AI Technical Summary
The existing medical dialogue intention classification model reduces accuracy and reliability when processing out-of-distributed data, resulting in medical safety issues.
By training the prediction layer and intermediate layer of the student model with the output probability distribution of the pre-constructed teacher model as the goal, the loss function of the prediction layer and intermediate layer is obtained, and the total loss function is integrated to minimize the total loss function, and the trained student model is obtained. The medical distribution data is then entered into the student model to detect the out-of-distribution data.
Through intermediate layer distillation, the student model can learn more deeply about the representation space of the teacher model, thereby better capturing the manifold structure of medical distributed data, improving the detection ability of out-of-distribution data, and achieving higher accuracy.
Smart Images

Figure CN119577627A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of artificial intelligence technology and medical technology, and in particular to a method, device, equipment and medium for detecting data outside the distribution of a medical model. Background Art
[0002] Medical conversation intent classification models are systems used to identify and classify different intents in medical conversations. These models are usually based on deep learning and natural language processing techniques and are implemented by training a large number of medical-related datasets. The following is a detailed description of medical conversation intent classification models: Medical conversation intent classification models require a large number of well-labeled datasets as a training basis. For example, MedDialog and cMedQA2 are two commonly used public datasets, containing more than 3 million multi-round conversations and 108,000 single-round conversations between doctors and patients, respectively. These datasets cover a wide range of topics from common disease consultations to professional medical advice, providing rich training data for the model. Common model architectures include recurrent neural network (RNN) models based on attention mechanisms, which can capture contextual information in conversations and thus improve the accuracy of intent recognition. In addition, some models are also trained in combination with large language models (such as LLaMA) to enhance language understanding and generation capabilities. Model training usually adopts supervised learning methods and is trained through labeled datasets. For example, the DIET (Dual Intent and Entity Transformer) model is trained in a purely supervised manner without large-scale pre-training, but its performance is better than the fine-tuned Bert model. In addition, some studies have combined prompt learning and generative methods to improve the performance of the model in complex conversations. The evaluation of model performance usually includes indicators such as confusion matrix, precision, and recall. For example, some studies have evaluated the model by recruiting professional physicians with a medical background to ensure its safety and usability in actual medical scenarios. In addition, using powerful judges such as GPT-4 for evaluation is also a common method. The medical conversation intention classification model can be used in a variety of scenarios in practical applications, such as intelligent guidance, personalized medical consultation, and medical record writing. These applications can reduce the burden on doctors and improve the efficiency of healthcare, especially during the pandemic. By combining deep learning, natural language processing technology, and a large number of annotated data sets, the medical conversation intention classification model can effectively identify and classify different intentions in medical conversations, thereby improving the intelligence level and application effect of the medical conversation system.
[0003] Among them, data with the same distribution as the training data of the medical intent classification model is called in-distribution (ID) data, and data with different distribution is called out-of-distribution (OoD) data. The medical intent classification model is widely used in medical conversational robots to identify user intentions. In actual application environments, the medical intent classification model will inevitably receive OoD data, which will reduce the accuracy and reliability of the model and cause medical safety problems. OoD detection can improve the robustness of the model and enhance security.
[0004] There are three main existing methods for OoD detection: 1. Method based on pre-trained language model: input the data to be detected into the pre-trained language model, and calculate whether the data to be detected belongs to ID data or OoD data according to the internal state of the model; 2. For the method based on training the language model from scratch: use the ID data to train the initialized language model, then input the data to be detected into the trained model, and calculate the category of the data through the internal state; 3. Train the classifier: use the labeled ID data and OoD data to train a binary classifier for detection.
[0005] However, for existing methods based on pre-trained language models, since the pre-training corpus usually contains large-scale datasets from multiple sources, it may contain some OoD data, which may result in the perplexity between these "leaked" OoD data being indistinguishable, because the model may have seen similar OoD data during pre-training. Summary of the invention
[0006] In view of the above-mentioned deficiencies in the prior art, the purpose of the present invention is to provide a method, device, equipment and medium for detecting data outside the distribution of a medical model, which can be applied to model training or other related fields, aiming to solve the problem of inaccurate detection of data outside the distribution of existing medical dialogue intentions.
[0007] The technical solution of the present invention is as follows:
[0008] The present invention provides a method for detecting data outside the distribution of a medical model, which comprises:
[0009] Taking the output probability distribution of the pre-built teacher model as the target, the prediction layer of the student model is trained to obtain the prediction layer loss function;
[0010] Obtaining the similarity between the intermediate layer hidden vector of the student model and the hidden vector of the teacher model, and obtaining the intermediate layer loss function according to the similarity;
[0011] Integrate the prediction layer loss function and the intermediate layer loss function to obtain a total loss function;
[0012] Using a back propagation algorithm to minimize the total loss function to obtain a trained student model;
[0013] The medical distribution data is input into the trained student model to obtain the data score outside the medical data distribution, and the corresponding data outside the medical data distribution is determined according to the data score.
[0014] On the other hand, this embodiment also provides a method and device for detecting data outside the medical model distribution, including:
[0015] The prediction layer training module is used to train the prediction layer of the student model with the output probability distribution of the pre-built teacher model as the target to obtain the prediction layer loss function;
[0016] An intermediate layer training module, used to obtain the similarity between the intermediate layer hidden vector of the student model and the hidden vector of the teacher model, and obtain the intermediate layer loss function according to the similarity;
[0017] A loss function integration module, used to integrate the prediction layer loss function and the intermediate layer loss function to obtain a total loss function;
[0018] A student model training module, used to minimize the total loss function using a back propagation algorithm to obtain a trained student model;
[0019] The out-of-distribution data detection module is used to input the medical distribution data into the trained student model, obtain the data score outside the medical data distribution, and determine the corresponding data outside the medical data distribution based on the data score.
[0020] On the other hand, this embodiment further provides a method and device for detecting data out of medical model distribution, the device comprising at least one processor; and
[0021] a memory communicatively connected to the at least one processor; wherein,
[0022] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can perform the above-mentioned medical model out-of-distribution data detection method.
[0023] On the other hand, this embodiment also provides a non-volatile computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are executed by one or more processors, the one or more processors can execute the above-mentioned medical model out-of-distribution data detection method.
[0024] Beneficial effects: The present invention discloses a method, device, equipment and medium for detecting data outside the distribution of a medical model. Compared with the prior art, the present invention uses the output probability distribution of a pre-constructed teacher model as a target to train the prediction layer of a student model to obtain a prediction layer loss function; obtains the similarity between the intermediate layer hidden vector of the student model and the hidden vector of the teacher model, and obtains the intermediate layer loss function based on the similarity; integrates the prediction layer loss function and the intermediate layer loss function to obtain a total loss function; uses a back propagation algorithm to minimize the total loss function to obtain a trained student model; inputs medical distribution data into the trained student model to obtain a data score outside the medical data distribution, and determines the corresponding data outside the medical data distribution based on the data score. Through the intermediate layer distillation method, the student model can learn the representation space of the teacher model more deeply, thereby better capturing the manifold structure of the medical distribution data, and improving the ability to map data outside the medical distribution to outside the medical distribution data manifold, which helps to learn more discriminative features, thereby achieving higher accuracy in the task of detecting data outside the medical distribution. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] The present invention will be further described below with reference to the accompanying drawings and embodiments, in which:
[0026] Figure 1 A flow chart of a method for detecting data outside the medical model distribution provided by an embodiment of the present invention;
[0027] Figure 2 A schematic diagram of the functional modules of the device for automatically generating test data provided by an embodiment of the present invention;
[0028] Figure 3 A schematic diagram of the hardware structure of a device for automatically generating test data provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0029] In order to make the purpose, technical solution and effect of the present invention clearer and more specific, the present invention is further described in detail below. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. The embodiments of the present invention are described below in conjunction with the accompanying drawings.
[0030] The medical dialogue intention classification model mentioned in the present invention is a method for identifying and classifying the user's intention in a medical dialogue using deep learning technology. This model can analyze the user's questions and capture the user's most likely intention, thereby guiding the medical dialogue system to provide more accurate and personalized services. Importance of intention recognition: In the medical dialogue system, intention recognition is one of the core functions, which can help the system understand the user's needs, such as finding a doctor, finding a hospital, finding a department, obtaining medical information, etc. Application of deep learning: Through deep learning technology, especially recurrent neural network (RNN) and attention mechanism, the model can learn the semantic information of the user's question and identify potential intentions. Data preprocessing: Before training the model, the medical dialogue data needs to be preprocessed, including steps such as word segmentation and vectorization, so that the model can better understand and learn. Model training: Use labeled medical dialogue data to train the model, which contains the user's question and the corresponding intention label. Fusion model: In order to improve the accuracy and stability of classification, a fusion strategy of multiple models can be adopted, such as combining the results of character vectorization, pinyin vectorization and part-of-speech-character vectorization. Practical Application: This model can be applied to online medical consultation platforms to help the system understand patients’ problems more accurately and provide corresponding medical services.
[0031] The data outside the distribution of the medical dialogue intention of the present invention is in natural language processing (NLP). "Out-of-distribution" (OOD) data refers to data that has not been seen during the model training process, and these data may come from a distribution different from the training data. In a medical dialogue system, processing OOD data is a challenge because the model needs to be able to accurately understand and respond to a variety of medical queries and situations that have not been seen. The OOD data of the medical dialogue intention may include: New diseases or symptoms: As medical research progresses, new diseases or symptoms may appear, which may not be covered when the model is trained. Non-standard queries: Users may express their questions in unconventional ways, such as using slang, abbreviations, or uncommon terms. Cross-domain issues: The model may be trained to handle specific types of medical queries, but users may ask questions in fields different from the training data. Data drift: Over time, users' behavior and language usage may change, resulting in new data distributions that are different from the data distribution when the model was trained. Incorrect or incomplete input: Users may enter incorrect or incomplete information, which may make it difficult for the model to understand and respond correctly. To improve the robustness of the model to OoD data, the following measures can be taken: Data augmentation: Increase the diversity of data by synthesizing new training samples or transforming existing samples. Transfer learning: Use a model pre-trained on a large-scale dataset and fine-tune it on specific medical conversation data. Multi-task learning: Train the model to perform multiple related tasks simultaneously, which can help the model learn more general features. Meta-learning: Train the model to quickly adapt to new or unseen medical queries. Anomaly detection: Develop mechanisms to identify OoD data and provide appropriate responses or request more information when the model is uncertain.
[0032] The method for detecting data outside the distribution of the medical model of the present invention can be the aforementioned anomaly detection to identify OoD data and provide appropriate responses or request more information when the model is uncertain. In fact, it is because the existing method for detecting data outside the distribution of medical conversation intentions is based on a pre-trained language model: the data to be detected is input into the pre-trained language model, and the internal state of the model is used to calculate whether the data to be detected belongs to ID data or OOD data. For the method based on training a language model from scratch: the initialized language model is trained using ID data, and then the data to be detected is input into the trained model, and the category of the data is calculated through the internal state, and the classifier is trained: the labeled ID data and OoD data are used to train a binary classifier for detection.
[0033] The above processing methods cause data leakage caused by the diversity of pre-trained corpora: For methods based on pre-trained language models, since pre-trained corpora usually contain large-scale datasets from multiple sources, they may contain some OoD data. This may result in the perplexity between these "leaked" OoD data being indistinguishable, because the model may have seen similar OoD data during pre-training. The compactness of the representation space causes data to be difficult to distinguish: For methods based on training language models from scratch, since only ID data is used to minimize the self-supervised language modeling loss without other constraints, the representation space of ID data may not be compact enough. This means that OoD data is more likely to be located within the ID data manifold, resulting in overlap between the perplexity distributions of ID data and OoD data. Insufficient generalization ability: Existing methods may not fully utilize the ability of pre-trained models in capturing semantic relevance, which limits the generalization ability of the model on OoD detection tasks. High reliance on OoD data: Some methods rely on OoD data to train binary or multi-class classifiers, but it is often impractical to collect OoD data because there are various reasons for OoD, such as out-of-domain data, adversarial data, etc. High reliance on ID category labels: Some methods assume that the category labels of ID data are available during model training in multi-class classification scenarios, which limits the application of methods in the absence of category labels.
[0034] In order to solve the above-mentioned problems, the present invention proposes a method for detecting data outside the medical model distribution. Figure 1 , Figure 1 A flowchart of an embodiment of a method for detecting data outside the medical model distribution provided by the present invention.
[0035] The medical model out-of-distribution data detection method provided in this embodiment is applied to mobile devices, fixed terminal devices, etc. based on artificial intelligence, and its terminal operating system may include a handheld device operating system (iPhone operating system, iOS system), Android system or other operating systems, including but not limited to smart phones, tablet computers, portable computers and desktop servers, etc. Figure 1 As shown, the method specifically comprises the following steps:
[0036] S101, taking the output probability distribution of the pre-built teacher model as the target, training the prediction layer of the student model to obtain the prediction layer loss function;
[0037] The steps of training the prediction layer of the student model to obtain the prediction layer loss function by taking the output probability distribution of the pre-built teacher model as the target include:
[0038] Train the prediction layer of the student model using the output probability distribution of the pre-built teacher model as the target;
[0039] The KL divergence between the probability distribution of the student model output and the probability distribution of the teacher model is obtained and used as the prediction layer loss function.
[0040] In one embodiment, specifically, it may be:
[0041] The KL divergence between the probability distribution of the student model output and the probability distribution of the teacher model is calculated and used as the loss function. Given a text sequence The learning loss for prediction layer distillation is defined as the mean of the Kullback-Leibler divergence between all output token probability distributions of the teacher model and the student model.
[0042] The Kullback-Leibler (KL) divergence, also known as relative entropy, is a measure of the difference between two probability distributions P and Q. It is asymmetric, that is, the value of the KL divergence from P to Q is usually different from that from Q to P. The KL divergence is defined as:
[0043] Where: P(x) is the true distribution (or what we think of as the “real” distribution). Q(x) is the model distribution (or the distribution we use to approximate the true distribution). P(x) and Q(x) are the probability density functions of these two distributions, respectively.
[0044] The KL divergence has several important properties: it is always non-negative and is zero if and only if P and Q are exactly the same. It is not a true distance, as it does not satisfy the triangle inequality. Due to the asymmetry, it is more commonly used to measure the "deviation" of one distribution with respect to another. In machine learning and information theory, the KL divergence has a variety of applications, including: Evaluating model performance: In machine learning, the KL divergence can be used to measure the difference between the probability distribution predicted by the model and the true data distribution. Information theory: In information theory, the KL divergence is used to quantify the loss of information when the information of one distribution is represented in terms of another distribution. Variational inference: In statistics, the KL divergence is used in variational inference, by optimizing parameters to minimize the KL divergence between the model distribution and the true distribution. The KL divergence is also very important in generative models in natural language processing, image processing, and other fields. For example, in variational autoencoders (VAEs), the KL divergence is used to regularize the distribution of the encoder output to ensure that it is close to the prior distribution.
[0045] Therefore, in this embodiment, the prediction layer loss function is given a text sequence get:
[0046] in, is the prediction loss under the student model parameters θ stu where N is the total number of elements in the sequence. x i represents the i-th element in the sequence. x<i represents all elements before the i-th element in the sequence. θ tea represents the parameters of the teacher model. θ stu represents the parameters of the student model. KL is the Kullback-Leibler divergence, which is used to measure the difference between two probability distributions.
[0047] In this embodiment, the initialization of the student model: use the initialized language model as the student model, and randomly initialize the parameters of the student model to ensure that it has no knowledge about OoD data at the beginning of training.
[0048] S102. Obtain the similarity between the intermediate layer hidden vector of the student model and the hidden vector of the teacher model, and obtain the intermediate layer loss function according to the similarity;
[0049] Specifically, it includes:
[0050] Match each layer hidden vector of the student model with the hidden vectors of all layers of the teacher model one by one, and obtain at least two similarities between the intermediate layer hidden vector of the student model and the hidden vector of the teacher model;
[0051] Determine the intermediate layer loss function according to the at least two similarities.
[0052] In this embodiment, after using the output probability distribution of the teacher model as the target to train the prediction layer of the student model and obtaining the prediction layer loss function, obtain the similarity between the intermediate layer hidden vector of the student model and the hidden vector of the teacher model, and obtain the intermediate layer loss function.
[0053] It can be understood that for each layer of the student model, its hidden vector is dynamically matched with the hidden vectors of different layers of the teacher model, and the most relevant layer of the teacher model is selected based on similarity. Calculate the similarity between the hidden vector of the student model and multiple hidden vectors of the teacher model, and train the student model through weighted average similarity loss. In this way, the student model learns the information flow and representation ability of the teacher model at different layers. The specific description is as follows:
[0054] Use the Euclidean distance to measure the vector generated by the student model for the i-th token in the l-th layer, that is and the hidden vector generated by the teacher model for the i-th token in the j-th layer (that is ) between the similarities:
[0055] where is the hidden vector produced by the student model relative to the i-th token of layer l, is the hidden vector generated by the teacher model relative to the i-th token of the j-th layer, j∈A, A represents the set of teacher model layer indices, and W j are the learned parameters.
[0056] Therefore, the similarity between the intermediate layer hidden vector of the student model and the hidden vector of the teacher model is obtained, and the teacher model is trained to the student model by maximizing the similarity to obtain the intermediate layer loss function, which can be The above formula is used to calculate the Then, by maximizing the similarity To train the student model. Let β k Indicates that it corresponds to The learning loss function of the lth layer about x can be expressed as:
[0057] in, represents the loss function of the student model of the lth layer in predicting the x direction, θ stu Represents the parameters of the student model. N represents the total number of samples or the length of the sequence. K represents the number of possible categories or the size of the action space. β k Represents the weight associated with the k-th category or action, which may be a learning rate or importance weight. It represents the score or probability of taking the kth action for the ith sample at the lth layer.
[0058] This loss function is minimized to train the model so that it learns how to predict the best action or class based on the input data x. This type of loss function is common in reinforcement learning, where β k represents the weight of the reward, and Represents the score or probability of taking a specific action in a given state.
[0059] It should be noted that step S101 takes the output probability distribution of the pre-built teacher model as the target, trains the prediction layer of the student model to obtain the prediction layer loss function, and also includes:
[0060] Loading a causal language model as the pre-trained teacher model;
[0061] Inputting the acquired medical distribution data into the pre-trained teacher model and obtaining the teacher model loss function;
[0062] The cross entropy loss minimization algorithm is adopted to minimize the teacher model loss function and establish the corresponding trained teacher model.
[0063] The aforementioned step of inputting the acquired medical distribution data into the pre-trained teacher model and obtaining the teacher model loss function includes:
[0064] Acquire medical intent text data, pre-process it through a preset text data word segmenter, and output the encoded data;
[0065] The AdamW optimization algorithm is used to perform optimization training on the encoded data at a preset learning rate to generate an in-distribution data set;
[0066] The in-distribution data set is input into the pre-trained teacher model to obtain a teacher model loss function.
[0067] Furthermore, establishing the teacher model and calculating the teacher model loss function according to the teacher model output probability function can be to obtain medical intent text data, output encoded data corresponding to the medical intent text data through a preset causal language model, establish the teacher model, and calculate the teacher model loss function according to the teacher model output probability function.
[0068] Use a causal language model (CLM), such as GPT-2-small, as the base model. Fine-tune the model on the ID data to generate a teacher model. The goal of the teacher model is to minimize the cross entropy loss to learn the distribution of the ID data. Given a text sequence where x i Represents the i-th token in the text sequence, and N represents the length of the text sequence.
[0069] The probability estimation function of the teacher model can be defined as follows:
[0070] where p(x) represents the joint probability of the entire sequence x. N is the number of elements in the sequence. i Represents the i-th element in the sequence. <i Represents all elements before the i-th element in the sequence. (x i ∣x <i ) is the conditional probability, which represents the probability of the ith element appearing given all the elements before the ith element in the sequence.
[0071] It can be understood that the teacher model is fine-tuned on the ID data as follows:
[0072] Prepare ID dataset D inThe ID dataset is the same as the current medical intent distribution. The data only contains the medical intent text. For example, {x: "How to treat leukemia?"}
[0073] Preprocess the data. Using the GPT2Tokenizer in transformers, feed the data into the GPT2Tokenizer and output the encoded data for subsequent use. GPT2Tokenizer is a tokenizer for processing text data. It is a component in the Hugging Face library that is specifically used for text preprocessing compatible with the GPT-2 model. GPT-2 is a generative pre-trained transformer model developed by OpenAI that performs well on a variety of natural language processing tasks, including text generation, text summarization, question answering, etc. The main functions of GPT2Tokenizer include: Tokenization: Split text strings into smaller units called tokens. For GPT-2, these tokens are usually subwords, which means that a word may be split into multiple parts to fit into the model's vocabulary. Encoding: Convert the tokenized tokens into numerical representations that the model can understand, usually integer indices. These indices correspond to words in the model's vocabulary. Padding: In order to ensure that all sequences in the batch are of the same length, short sequences may be padded. Truncation: If the sequence length exceeds the maximum length allowed by the model, GPT2Tokenizer can truncate the overlong sequence. Add special tokens: The GPT-2 model uses special start and end tokens, such as "<|endoftext|>", which are particularly important when generating text.
[0074] The optimizer uses AdamW, and the learning rate is set to 0.00001. AdamW is a popular optimization algorithm, which is a variant of the Adam optimizer and is specifically used for large model training in deep learning. The main feature of AdamW is that it takes weight decay into account when updating weights, which helps prevent overfitting and generally improves model performance.
[0075] The fine-tuned teacher model loss function is defined as follows: Among them, L x (θ tea ) is the teacher model parameter θ tea The loss function for the ith element under . N is the number of elements in the sequence. x i Represents the i-th element in the sequence. <iRepresents all elements before the i-th element in the sequence. θ tea represents the parameters of the teacher model. p(x i |x <i θ tea ) is the conditional probability of the ith element given the first i-1 elements in the sequence.
[0076] This is a conditional probability negative log-likelihood loss function, which is used to evaluate the performance of the teacher model in sequence generation tasks. This type of loss function is often used to train language models or sequence prediction models, with the goal of minimizing the difference between the model output and the real data. This loss function calculates the uncertainty of the model's prediction for each element, by taking the negative log-likelihood. During training, the model's parameters θ tea The optimization algorithm is adjusted to minimize this loss function, thereby improving the model's prediction accuracy for sequence data. This loss function is particularly suitable for tasks that need to consider the dependencies between sequences, such as text generation and understanding tasks in natural language processing.
[0077] S103, integrating the prediction layer loss function and the intermediate layer loss function to obtain a total loss function;
[0078] Prior to this, the initialized language model needs to be used as the student model, and the parameters of the student model need to be randomly initialized to ensure that it has no knowledge about the OoD data at the beginning of training.
[0079] The loss functions of the prediction layer distillation and the intermediate layer distillation are integrated to form a total loss function. Let T represent the set of student model layer indices. The entire training loss of the student model is relative to the ID dataset D in The sum of the losses of all sentences in :
[0080] Among them, L(θ stu ) is the student model parameter θ stu The total loss function of D in Relative to the ID dataset. λ is a weight parameter used to balance the weights of the two distillation methods. is the aforementioned prediction loss, possibly based on the difference between the output of the student model and the teacher model. is the task-specific loss, where T is the set of tasks, is the loss function for a specific task l. x represents a single data point in the input dataset.
[0081] This embodiment is a comprehensive loss function L(θ stu), used to evaluate and train the student model. This loss function combines two different losses: prediction loss and task-specific losses This combination is often used in knowledge distillation or other model compression techniques, where the student model tries to learn the behavior of the teacher model.
[0082] This loss function calculates the total loss by accumulating the weighted prediction loss and task-specific loss over all input data x. The weight parameter λ allows the balance between prediction loss and other task losses to be adjusted during training. This approach allows the student model to not only mimic the predictions of the teacher model, but also perform well on a specific task.
[0083] In practical applications, this loss function can help the student model optimize for a specific task while maintaining the generalization ability of the teacher model. This is especially useful in multi-task learning or when the architectures of the teacher model and the student model are not exactly the same.
[0084] S104, using a back propagation algorithm to minimize the total loss function to obtain a trained student model.
[0085] Specifically, a back propagation algorithm is used to calculate the gradient of the student model parameters corresponding to the total loss function;
[0086] A preset optimizer is used to update the student model parameters according to the gradient until the total loss function is minimized to obtain the trained student model.
[0087] In one embodiment, a training loop is used to train the model. In each iteration, forward propagation is performed, loss is calculated, backpropagation is performed, and model parameters are updated. Gradients are calculated based on the total loss function, and the weights of the student model are updated. Optionally, gradient clipping is used to prevent gradient explosion. An optimizer (such as Adam, SGD, etc.) is selected to update the parameters of the student model, and the performance of the student model is regularly evaluated on the validation set to ensure that it is learning and not overfitting. Depending on the performance on the validation set, the hyperparameter λλ or other training parameters may need to be adjusted. Early stopping: If the performance on the validation set does not improve within a few consecutive epochs, training can be stopped early to avoid overfitting.
[0088] S105. Input the medical distribution data into the trained student model to obtain the data score outside the medical data distribution, and determine the corresponding data outside the medical data distribution according to the data score.
[0089] In this embodiment, the medical distribution data to be detected may be obtained, and the corresponding medical distribution data sequence may be outputted after encoding and conversion;
[0090] Input the medical distribution data sequence into the trained student model and calculate the perplexity of each character string;
[0091] The data score outside the medical conversation intention distribution is calculated according to the character string perplexity, and the corresponding data outside the medical data distribution is determined according to the data score.
[0092] Use the trained student model to calculate the perplexity of each token in the input sequence. The OoD score of the entire input sequence is obtained by averaging the perplexity of all tokens. Given a text sequence The OoD score is defined as follows:
[0093] Where score(x) is the scoring function of the sequence x. N is the number of elements in the sequence. i Represents the i-th element in the sequence. <i Represents all elements before the i-th element in the sequence. θ stu represents the parameters of the student model. p(x i |x <i θ stu ) is the conditional probability of the i-th element occurring given the first i-1 elements in the sequence.
[0094] Finally, a threshold γ can be defined. If the OoD score of the input sequence is greater than γ, it is judged as an OoD example; otherwise, it is an ID example.
[0095] Scoring function score(x), which is used to evaluate the given model parameter θ stu The probability of the next sequence x. This scoring function is often used in language models or other sequence generation tasks to measure how well the model fits the observed sequence. The scoring function measures the fit of the entire sequence by calculating the negative log-likelihood of the conditional probability of each element in the sequence and averaging them. This score is often used as an optimization target during model training. The model parameters θ stu The model is adjusted by minimizing this scoring function to improve the model's prediction accuracy on the data.
[0096] In natural language processing, this scoring function can help the model learn how to generate the next word based on the previous text, thereby improving the performance of text generation or language models. This scoring function also has similar applications in other sequence generation tasks.
[0097] The above-mentioned trained student model is used to calculate the perplexity of each token in the input sequence. Perplexity is an important indicator for measuring the quality of a language model. It can be used to measure the model's ability to predict real data. The lower the perplexity, the more accurate the model's prediction of the data. In natural language processing, perplexity is often used to evaluate the performance of language models.
[0098] This embodiment trains the prediction layer of the student model with the output probability distribution of the pre-constructed teacher model as the target to obtain the prediction layer loss function; obtains the similarity between the intermediate layer hidden vector of the student model and the hidden vector of the teacher model, and obtains the intermediate layer loss function according to the similarity; integrates the prediction layer loss function and the intermediate layer loss function to obtain the total loss function; uses the back propagation algorithm to minimize the total loss function to obtain the trained student model; inputs the medical distribution data into the trained student model to obtain the data score outside the medical data distribution, and determines the corresponding data outside the medical data distribution according to the data score. Through the intermediate layer distillation method, the student model can learn the representation space of the teacher model more deeply, so as to better capture the manifold structure of the medical distribution data and improve the ability to map the data outside the medical distribution to outside the medical distribution data manifold, which helps to learn more discriminative features, so as to achieve higher accuracy in the data detection task outside the medical distribution.
[0099] By combining the methods of training the model from scratch and fine-tuning the pre-trained model, this scheme is able to integrate the advantages of both methods, thereby improving the performance of the model in OoD detection and avoiding OoD data leakage: the student model is only exposed to in-distribution (ID) data during training, avoiding OoD data that may be exposed during the pre-training stage, which can reduce the perplexity of the model when processing real OoD data. Through the intermediate layer distillation method, the student model can learn the representation space of the teacher model more deeply, thereby better capturing the manifold structure of ID data and improving the ability to map OoD data outside the ID data manifold. The student model only sees ID data during training, which helps to learn more discriminative features, thereby achieving higher accuracy in OoD detection tasks.
[0100] Another embodiment of the present invention provides a method and device for detecting data outside the distribution of a medical model, such as Figure 2 As shown, the device comprises:
[0101] A prediction layer training module 201 is used to train the prediction layer of the student model using the output probability distribution of the pre-built teacher model as a target to obtain a prediction layer loss function;
[0102] The prediction layer training module 201 is specifically used for:
[0103] Train the prediction layer of the student model using the output probability distribution of the pre-built teacher model as the target;
[0104] The KL divergence between the probability distribution of the student model output and the probability distribution of the teacher model is obtained and used as the prediction layer loss function.
[0105] An intermediate layer training module 202 is used to obtain the similarity between the intermediate layer hidden vector of the student model and the hidden vector of the teacher model, and obtain the intermediate layer loss function according to the similarity;
[0106] The middle layer training module 202 is specifically used for:
[0107] Matching the hidden vectors of each layer of the student model with the hidden vectors of all layers of the teacher model one by one, and obtaining at least two similarities between the hidden vectors of the middle layer of the student model and the hidden vectors of the teacher model;
[0108] The intermediate layer loss function is determined according to the at least two similarities.
[0109] A loss function integration module 203, used to integrate the prediction layer loss function and the intermediate layer loss function to obtain a total loss function;
[0110] A student model training module 204 is used to minimize the total loss function using a back propagation algorithm to obtain a trained student model;
[0111] The student model training module 204 is specifically used for:
[0112] Using a back propagation algorithm to calculate the gradient of the student model parameters corresponding to the total loss function;
[0113] A preset optimizer is used to update the student model parameters according to the gradient until the total loss function is minimized to obtain the trained student model.
[0114] The out-of-distribution data detection module 205 is used to input the medical distribution data into the trained student model, obtain the data score of the medical data out-of-distribution, and determine the corresponding data out-of-distribution of the medical data according to the data score.
[0115] The out-of-distribution data detection module 205 is specifically used for:
[0116] Obtain the medical distribution data to be detected, perform encoding conversion and output the corresponding medical distribution data sequence;
[0117] Input the medical distribution data sequence into the trained student model and calculate the perplexity of each character string;
[0118] The data score outside the medical conversation intention distribution is calculated according to the character string perplexity, and the corresponding data outside the medical data distribution is determined according to the data score.
[0119] This embodiment also includes:
[0120] The teacher model module is specifically used for:
[0121] Loading a causal language model as the pre-trained teacher model;
[0122] Inputting the acquired medical distribution data into the pre-trained teacher model and obtaining the teacher model loss function;
[0123] The cross entropy loss minimization algorithm is adopted to minimize the teacher model loss function and establish the corresponding trained teacher model.
[0124] The aforementioned step of inputting the acquired medical distribution data into the pre-trained teacher model and obtaining the teacher model loss function includes:
[0125] Acquire medical intent text data, pre-process it through a preset text data word segmenter, and output the encoded data;
[0126] The AdamW optimization algorithm is used to perform optimization training on the encoded data at a preset learning rate to generate an in-distribution data set;
[0127] The in-distribution data set is input into the pre-trained teacher model to obtain a teacher model loss function.
[0128] This embodiment trains the prediction layer of the student model with the output probability distribution of the pre-constructed teacher model as the target to obtain the prediction layer loss function; obtains the similarity between the intermediate layer hidden vector of the student model and the hidden vector of the teacher model, and obtains the intermediate layer loss function according to the similarity; integrates the prediction layer loss function and the intermediate layer loss function to obtain the total loss function; uses the back propagation algorithm to minimize the total loss function to obtain the trained student model; inputs the medical distribution data into the trained student model to obtain the data score outside the medical data distribution, and determines the corresponding data outside the medical data distribution according to the data score. Through the intermediate layer distillation method, the student model can learn the representation space of the teacher model more deeply, so as to better capture the manifold structure of the medical distribution data and improve the ability to map the data outside the medical distribution to outside the medical distribution data manifold, which helps to learn more discriminative features, so as to achieve higher accuracy in the data detection task outside the medical distribution.
[0129] By combining the methods of training the model from scratch and fine-tuning the pre-trained model, this scheme is able to integrate the advantages of both methods, thereby improving the performance of the model in OoD detection and avoiding OoD data leakage: the student model is only exposed to in-distribution (ID) data during training, avoiding OoD data that may be exposed during the pre-training stage, which can reduce the perplexity of the model when processing real OoD data. Through the intermediate layer distillation method, the student model can learn the representation space of the teacher model more deeply, thereby better capturing the manifold structure of ID data and improving the ability to map OoD data outside the ID data manifold. The student model only sees ID data during training, which helps to learn more discriminative features, thereby achieving higher accuracy in OoD detection tasks.
[0130] Another embodiment of the present invention provides a method and device for detecting data outside the distribution of a medical model, such as Figure 3 As shown, the device 10 includes:
[0131] One or more processors 110 and memory 120, Figure 3 A processor 110 is used as an example for description. The processor 110 and the memory 120 may be connected via a bus or other means. Figure 3 The example of connecting through bus is taken in the following.
[0132] The processor 110 is used to complete various control logics of the device 10, and it can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), a single-chip microcomputer, an ARM (Acorn RISCMachine) or other programmable logic device, a discrete gate or transistor logic, a discrete hardware component, or any combination of these components. In addition, the processor 110 can also be any traditional processor, microprocessor or state machine. The processor 110 can also be implemented as a combination of computing devices, for example, a combination of a DSP and a microprocessor, a plurality of microprocessors, one or more microprocessors combined with a DSP and / or any other such configuration.
[0133] The memory 120, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer executable programs and modules, such as program instructions corresponding to the medical model distribution data detection method in the embodiment of the present invention. The processor 110 executes various functional applications and data processing of the device 10 by running the non-volatile software programs, instructions and units stored in the memory 120, that is, implements the medical model distribution data detection method in the above method embodiment.
[0134] The memory 120 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and applications required for at least one function; the data storage area may store data created according to the use of the device 10, etc. In addition, the memory 120 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 120 may optionally include a memory remotely arranged relative to the processor 110, and these remote memories may be connected to the device 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0135] One or more units are stored in the memory 120, and when executed by one or more processors 110, the following steps are implemented:
[0136] Train the prediction layer and intermediate layer of the student model through the teacher model to obtain the prediction layer loss function and the intermediate layer loss function;
[0137] Integrate the prediction layer loss function and the intermediate layer loss function to determine the corresponding entire training loss function of the student model, so that the student model training is completed;
[0138] Input medical distribution data into the trained student model to calculate the score of data outside the medical conversation intention distribution.
[0139] An embodiment of the present invention provides a non-volatile computer-readable storage medium, which stores computer-executable instructions. When the computer-executable instructions are executed by one or more processors, the above steps S101 to S103 are implemented.
[0140] As an example, non-volatile storage media can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) as external cache memory. By way of illustration and not limitation, RAM can be obtained in many forms such as synchronous RAM (SRAM), dynamic RAM, (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), Synchlink DRAM (SLDRAM), and direct Rambus RAM (DRRAM). The disclosed memory components or memories of the operating environment described herein are intended to include one or more of these and / or any other suitable types of memory.
[0141] Of course, those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing related hardware (such as a processor, a controller, etc.) through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium, and the computer program can include the processes of the above-mentioned method embodiments when executed. The storage medium can be a memory, a disk, a floppy disk, a flash memory, an optical storage device, etc.
[0142] Compared with the prior art, the present invention trains the prediction layer of the student model with the output probability distribution of the pre-constructed teacher model as the target to obtain the prediction layer loss function; obtains the similarity between the intermediate layer hidden vector of the student model and the hidden vector of the teacher model, and obtains the intermediate layer loss function according to the similarity; integrates the prediction layer loss function and the intermediate layer loss function to obtain the total loss function; uses the back propagation algorithm to minimize the total loss function to obtain the trained student model; inputs the medical distribution data into the trained student model to obtain the data score outside the medical data distribution, and determines the corresponding data outside the medical data distribution according to the data score. Through the intermediate layer distillation method, the student model can learn the representation space of the teacher model more deeply, so as to better capture the manifold structure of the medical distribution data, and improve the ability to map the data outside the medical distribution to outside the medical distribution data manifold, which helps to learn more discriminative features, thereby achieving higher accuracy in the data detection task outside the medical distribution.
[0143] By combining the method of training the model from scratch and fine-tuning the pre-trained model, the present invention can integrate the advantages of the two methods, thereby improving the performance of the model in OoD detection and avoiding OoD data leakage: the student model is only exposed to in-distribution (ID) data during training, avoiding OoD data that may be exposed in the pre-training stage, which can reduce the confusion of the model when processing real OoD data. Through the intermediate layer distillation method, the student model can learn the representation space of the teacher model more deeply, thereby better capturing the manifold structure of ID data and improving the ability to map OoD data outside the ID data manifold. The student model only sees ID data during training, which helps to learn more discriminative features, thereby achieving higher accuracy in OoD detection tasks.
[0144] It should be understood that the application of the present invention is not limited to the above examples. For ordinary technicians in this field, improvements or changes can be made based on the above description. All these improvements and changes should fall within the scope of protection of the claims attached to the present invention.
[0145] It should be noted that if software tools or components other than those of our company appear in the embodiments of the present application, they are only used for illustrative purposes and do not represent actual use.
Claims
1. A method for detecting data outside the distribution of a medical model, characterized in that: include: Taking the output probability distribution of the pre-built teacher model as the target, the prediction layer of the student model is trained to obtain the prediction layer loss function; Obtaining the similarity between the intermediate layer hidden vector of the student model and the hidden vector of the teacher model, and obtaining the intermediate layer loss function according to the similarity; Integrate the prediction layer loss function and the intermediate layer loss function to obtain a total loss function; Using a back propagation algorithm to minimize the total loss function to obtain a trained student model; The medical distribution data is input into the trained student model to obtain the data score outside the medical data distribution, and the corresponding data outside the medical data distribution is determined according to the data score.
2. The method for detecting out-of-distribution data of a medical model according to claim 1, characterized in that: The steps of training the prediction layer of the student model to obtain the prediction layer loss function by taking the output probability distribution of the pre-built teacher model as the target include: Train the prediction layer of the student model using the output probability distribution of the pre-built teacher model as the target; The KL divergence between the probability distribution of the student model output and the probability distribution of the teacher model is obtained and used as the prediction layer loss function.
3. The medical model out-of-distribution data detection method according to claim 1, characterized in that: The step of obtaining the similarity between the intermediate layer hidden vector of the student model and the hidden vector of the teacher model, and obtaining the intermediate layer loss function according to the similarity comprises: Matching the hidden vectors of each layer of the student model with the hidden vectors of all layers of the teacher model one by one, and obtaining at least two similarities between the hidden vectors of the middle layer of the student model and the hidden vectors of the teacher model; The intermediate layer loss function is determined according to the at least two similarities.
4. The method for detecting out-of-distribution data of a medical model according to claim 2, characterized in that: The steps of training the prediction layer of the student model to obtain the prediction layer loss function using the output probability distribution of the pre-built teacher model as the target also include: Loading a causal language model as the pre-trained teacher model; Inputting the acquired medical distribution data into the pre-trained teacher model and obtaining the teacher model loss function; The cross entropy loss minimization algorithm is adopted to minimize the teacher model loss function and establish the corresponding trained teacher model.
5. The method for detecting data outside the medical model distribution according to claim 4, characterized in that: The step of inputting the acquired medical distribution data into the pre-trained teacher model and obtaining the teacher model loss function comprises: Acquire medical intent text data, pre-process it through a preset text data word segmenter, and output the encoded data; The AdamW optimization algorithm is used to perform optimization training on the encoded data at a preset learning rate to generate an in-distribution data set; The in-distribution data set is input into the pre-trained teacher model to obtain a teacher model loss function.
6. The method for detecting out-of-distribution data of a medical model according to claim 1, characterized in that: The steps of minimizing the total loss function by using a back propagation algorithm to obtain a trained student model include: Using a back propagation algorithm to calculate the gradient of the student model parameters corresponding to the total loss function; A preset optimizer is used to update the student model parameters according to the gradient until the total loss function is minimized to obtain the trained student model.
7. The medical model out-of-distribution data detection method according to claim 1, characterized in that: The steps of inputting the medical distribution data into the trained student model, obtaining the data score outside the medical data distribution, and determining the corresponding data outside the medical data distribution according to the data score include: Obtain the medical distribution data to be detected, perform encoding conversion and output the corresponding medical distribution data sequence; Input the medical distribution data sequence into the trained student model and calculate the perplexity of each character string; The data score outside the medical conversation intention distribution is calculated according to the character string perplexity, and the corresponding data outside the medical data distribution is determined according to the data score.
8. A method and device for detecting data outside the distribution of a medical model, characterized in that: include: The prediction layer training module is used to train the prediction layer of the student model with the output probability distribution of the pre-built teacher model as the target to obtain the prediction layer loss function; An intermediate layer training module, used to obtain the similarity between the intermediate layer hidden vector of the student model and the hidden vector of the teacher model, and obtain the intermediate layer loss function according to the similarity; A loss function integration module, used to integrate the prediction layer loss function and the intermediate layer loss function to obtain a total loss function; A student model training module, used to minimize the total loss function using a back propagation algorithm to obtain a trained student model; The out-of-distribution data detection module is used to input the medical distribution data into the trained student model, obtain the data score outside the medical data distribution, and determine the corresponding data outside the medical data distribution based on the data score.
9. A method and device for detecting data outside the distribution of a medical model, characterized in that: The device comprises at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the medical model out-of-distribution data detection method as described in any one of claims 1-7.
10. A non-volatile computer-readable storage medium, characterized in that: The non-volatile computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by one or more processors, the one or more processors can execute the medical model out-of-distribution data detection method described in any one of claims 1-7.