A small sample text multi-label model training method based on dynamic sample weights

By introducing dynamic sample weights and composite sample weight loss functions in text multi-label model training, the problem of insufficient number of labeled samples and imbalance of positive and negative samples in the deep model is solved, and an efficient text multi-label model is trained.

CN118194048BActive Publication Date: 2024-09-10BEIJING EASY CHAT TECH CO LTD
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202410522283.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-28
Publication Date
2024-09-10
Estimated Expiration
2044-04-28

AI Technical Summary

Technical Problem

In the existing technology, deep models used for text classification require a large number of labeled samples in supervised learning, and the balance between positive and negative samples is sensitive. Especially when training multi-label models, due to the large difference in the proportion of positive samples and negative samples, the problem It is difficult to train a practical model.

Method used

A small sample text multi-label model training method based on dynamic sample weights is used to initialize sample weights through the smoothing principle, construct a composite sample weight loss function, and adjust sample weights during the training process until the predetermined convergence conditions are met, and the trained multi-labels are obtained Model.

Benefits of technology

It effectively alleviates the problems of insufficient number of labeled samples and imbalance of positive and negative samples, obtains a practical multi-labeled text model, and improves the training effect of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118194048B
    Figure CN118194048B
Patent Text Reader

Abstract

The present invention discloses a small sample text multi-label model training method based on dynamic sample weights, including S1, initializing the weights of multi-label training samples based on the smoothing principle to obtain the initial weights of the multi-label training samples; S2, training the multi-label model using the multi-label training samples, and constructing a composite sample weight loss function for the multi-label model based on the initial weights; S3, in the multi-label model training process, adjusting the weights of the multi-label training samples according to the labeling prediction results of the multi-label training samples by the multi-label model; S4, using the adjusted weights as the initial weights, iteratively executing steps S2 to S3 until the predetermined convergence conditions are met, and obtaining a trained multi-label model. The advantage is that by introducing sample weight adjustment and corresponding loss functions during the training process, the problems caused by insufficient number of labeled samples and imbalance of positive and negative samples can be greatly alleviated, and a practically usable text multi-label model can be obtained.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer software technology and development, and in particular to a small sample text multi-label model training method based on dynamic sample weights. Background Art

[0002] At present, the deep models used for text classification are essentially probabilistic models that use supervised learning methods. Supervised learning requires a large number of labeled samples, while probabilistic models are sensitive to the balance between positive and negative samples. In actual application scenarios, usually only a small number of labeled samples can be provided, and the ratio between positive and negative samples varies greatly (a small number of positive samples and a relatively large number of negative samples). This situation is particularly prominent when training multi-label (which can be understood as multiple binary classification tasks at the same time) models, and it is difficult to train a practical model. Summary of the invention

[0003] The purpose of the present invention is to provide a small sample text multi-label model training method based on dynamic sample weights, so as to solve the above-mentioned problems existing in the prior art.

[0004] In order to achieve the above object, the technical solution adopted by the present invention is as follows:

[0005] A small sample text multi-label model training method based on dynamic sample weights includes the following steps:

[0006] S1. Initialize the weights of the multi-label training samples based on the smoothing principle to obtain the initial weights of the multi-label training samples;

[0007] S2, training a multi-label model using the multi-label training samples, and constructing a composite sample weight loss function for the multi-label model based on the initial weights;

[0008] S3, during the multi-label model training process, adjusting the weight of the multi-label training sample according to the label prediction result of the multi-label model on the multi-label training sample;

[0009] S4. Use the adjusted weights as initial weights and iteratively execute steps S2 to S3 until a predetermined convergence condition is met to obtain a trained multi-label model.

[0010] Preferably, the multi-label training samples include three sets of vectors, namely, a feature vector set X, a label vector set Y, and a sample weight vector set W, and the cardinality of each set is equal to N;

[0011] The single vector x of the set X represents the text feature vector of a single sentence, and its dimension is the output dimension of the vectorization model;

[0012] The single vector y in the set Y represents the tag vector corresponding to a single sentence, and its dimension is the cardinality of the entire tag set, denoted as M; each component of the vector represents a specific tag, and its value range is 0 or 1. When a single sentence has a specific tag, the component value is 1, otherwise it is 0;

[0013] The single vector w in the set W represents the weight vector corresponding to the tag vector, and its dimension is the same as that of the tag vector. Each component in w corresponds to a tag.

[0014] Preferably, the multi-label task can be split into M binary classification tasks. The training samples with M kinds of labels of size N are used as binary classification samples with a size of N×M; the N feature vectors will be repeated M times, corresponding to N×M label scalars, corresponding to N×M weight scalars, and the weights are regarded as sample weights at this time. The sample size and the number of weights are equal, which is N×M.

[0015] Preferably, the vectorized model is a pre-trained language model using the Embedding and Transformer structures in the deep model.

[0016] Preferably, the multi-label model adopts a structure in which a pre-trained language model is used as a backbone and a linear discriminant model is used as a labeling layer; the pre-trained language model is used to generate a text vector, and the linear discriminant model is used to generate a multi-label confidence vector.

[0017] Preferably, the smoothing principle is to obtain the ability to adjust the sample composition by setting pseudo counts for the estimated value of the number of samples outside the training data.

[0018] Preferably, the initial weights of the multi-label training samples are calculated using the following formula:

[0019]

[0020]

[0021]

[0022] Among them, w i,j,t=0 is the weight corresponding to the jth label of the ith sample at t = 0, that is, the initial weight; pc i,j,t=0 is the pseudo count of positive samples corresponding to the jth label of the i-th sample at t = 0; is the total actual count of negative samples; is the total actual count of positive samples; r i,j,t=0 is the normal term corresponding to the jth label of the ith sample at t = 0; is the total pseudo count at t = 0; is the total actual count at t = 0; y i,j is the expected value of the jth label of the ith sample; c i,j,t=0is the actual count corresponding to the jth label of the ith sample at t = 0, which is defined as 1; t is the number of training rounds of the multi-label model.

[0023] Preferably, the weights of the multi-label training samples are adjusted using the following formula:

[0024]

[0025]

[0026]

[0027]

[0028] Among them, w i,j,t is the weight corresponding to the jth label of the ith example in the tth round of training of the multi-label model; pc i,j,t is the pseudo count corresponding to the jth label of the ith sample in the tth round of training of the multi-label model; c i,j,t is the predicted count corresponding to the jth label of the i-th sample in the t-th round of training of the multi-label model; is the total predicted count of the multi-label model during the tth round of training; r i,j,t is the normal term corresponding to the jth label of the ith example in the tth round of training of the multi-label model; is the total pseudo count of the multi-label model during the tth round of training; c i,j,t-1 is the predicted count corresponding to the jth label of the i-th sample in the t-1th round of training of the multi-label model; |y i,j -y′ i,j,t | is the prediction error in the current round of training, y′ i,j,t is the predicted value of the jth label of the ith example in the tth round of training of the multi-label model.

[0029] Preferably, the composite sample weight loss function is calculated using the following formula:

[0030]

[0031] l i,j,t =-w i,j,t ×(y i,j ×ln y′ i,j,t +(1-y i,j )×ln 1-y′ i,j,t )

[0032]

[0033] Among them, loss t is the composite sample weight loss function during the tth round of training of the multi-label model; l i,j,tis the loss component of the j-th label of the ith example in the t-th round of training of the multi-label model; the underlined term refers to the downward truncation function; ε is a very small positive real number.

[0034] Preferably, the preset convergence condition is minimization of the composite sample weight loss function.

[0035] The beneficial effect of the present invention is that the present invention can greatly alleviate the problems caused by insufficient number of labeled samples and imbalance of positive and negative samples by introducing sample weight adjustment and corresponding loss function in the training process, and obtain a practical and usable text multi-label model. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] Figure 1 4 is a flow chart of a multi-label model training method in an embodiment of the present invention. DETAILED DESCRIPTION

[0037] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings. It should be understood that the specific implementation methods described herein are only used to explain the present invention and are not used to limit the present invention.

[0038] Embodiment 1

[0039] In this embodiment, a small sample text multi-label model training method based on dynamic sample weights is provided, comprising the following steps:

[0040] S1. Initialize the weights of the multi-label training samples based on the smoothing principle to obtain the initial weights of the multi-label training samples;

[0041] S2. Train the multi-label model using the multi-label training samples, and construct a composite sample weight loss function for model training based on the initial weights;

[0042] S3, during the multi-label model training process, adjusting the weight of the multi-label training sample according to the label prediction result of the multi-label model on the multi-label training sample;

[0043] S4. Use the adjusted weights as initial weights and iteratively execute steps S2 to S3 until a predetermined convergence condition is met to obtain a trained multi-label model.

[0044] In this embodiment, the above process mainly includes the following two main contents:

[0045] 1. Sample weight dynamic generation algorithm

[0046] 1.1. Sample data structure and sample weight

[0047] The multi-label training samples include three sets of vectors, namely, feature vector set X, label vector set Y and sample weight vector set W. The cardinality of each set is equal to N. Each set element represents an example in the sample, that is, a single sentence text and its label and weight.

[0048] (1) A single vector x in the set X represents the text feature vector of a single sentence, and its dimension is the output dimension of the vectorization model. Here, the vectorization model uses a pre-trained language model (such as BERT) with an Embedding and Transformer structure in a deep model.

[0049] (2) A single vector y in the set Y represents the tag vector corresponding to a single sentence, and its dimension is the cardinality of the entire tag set, denoted as M. Each component of the vector represents a specific tag, and its value range is 0 or 1. When a single sentence has a specific tag, the component value is 1, otherwise it is 0.

[0050] (3) A single vector w in the set W represents the weight vector corresponding to the tag vector, and its dimension is the same as that of the tag vector. Each component in w corresponds to a tag.

[0051] The multi-label task can be split into M binary classification tasks. The multi-label (M kinds of labels) training samples of size N are now used as binary classification samples with a size of N×M; the N feature vectors will be repeated M times, corresponding to N×M label scalars, corresponding to N×M weight scalars. At this time, the weights are regarded as sample weights, and the sample size and the number of weights are equal, which is N×M.

[0052] 1.2. Sample weight initialization and iterative update

[0053] (1) Setting the initial weight value for the purpose of balancing the samples

[0054] The essence of deep models is statistical models. In statistical models, pseudo-counting can be used to adjust the influence of samples in model training. The features or labels in the samples are decomposed into random variables in statistical models, and statistical models are numerical expressions of the conditional joint distribution of these random variables. "Conditions" refer to the prior components in the model, such as various parameters from outside the data, that is, hyperparameters. For deep neural network models (generally referred to as deep models), hyperparameters include the initial model structure, such as different types of computing layers, activation functions, input and output dimensions of each layer, number of neurons, etc. For more standard statistical models, that is, probability models (such as Bayesian networks, Markov networks, etc.), the typical prior part includes the prior distribution and its parameters, which usually have statistical meanings that can be understood by humans. Taking binary classification as an example, assuming that the sample label (x) obeys the binomial distribution (Binomial), and the binomial distribution also obeys the beta distribution (Beta). The beta distribution is the conjugate prior distribution of the binomial distribution, so the posterior distribution composed of the two is still the beta distribution, expressed as follows:

[0055]

[0056] x|θ~Binomial(x|θ)=C(n,x)θ x (1-θ) n-x

[0057]

[0058] θ|x~Beta(θ|x+α,n-x+β)∝Binomial(x|θ)Beta(θ|α,β)

[0059] The alpha (α) and beta (β) parameters in the prior beta distribution mean the number of samples with binomial values ​​of 1 and 0, that is, the estimated value of the number of samples outside the training data (pseudo-counts of positive and negative samples). By setting pseudo-counts, the ability to adjust the sample composition can be obtained, which is called smoothing, such as Laplace smoothing used to alleviate the problem of missing samples in training data. In the formula, the posterior beta distribution parameters x+α and n-x+β are the number of positive and negative samples after smoothing. The present invention calculates the initial weight of the sample based on the smoothing principle for the training process of the deep model. Smoothing is essentially to adjust the sample composition through pseudo-counts to solve the overfitting problem in model learning. In the absence of labeled positive samples, smoothing can be used to address the serious imbalance of positive and negative samples.

[0060] According to the above principles, the initial sample weight is defined as follows:

[0061]

[0062]

[0063]

[0064] Among them, w i,j,t=0 is the weight corresponding to the jth label of the ith sample at t = 0, that is, the initial weight; pc i,j,t=0 is the pseudo count of positive samples corresponding to the jth label of the i-th sample at t = 0; is the total actual count of negative samples; is the total actual count of positive samples; r i,j,t=0 is the normal term corresponding to the jth label of the ith sample at t = 0; is the total pseudo count at t = 0; is the total actual count at t = 0; y i,j is the expected value of the jth label of the ith sample; c i,j,t=0 is the actual count corresponding to the jth label of the ith sample at t = 0, which is defined as 1; t is the number of training rounds of the multi-label model.

[0065] The pseudo count of positive samples of the jth mark is equal to the ratio of the total actual count of negative samples to the total actual count of positive samples. The normal term of the jth mark is the ratio of the total smoothed count to the total actual count. Therefore, the total weight value of the jth mark is guaranteed to be equal to the total actual count, where the actual count is equal to the weight when it is not smoothed. Therefore, the total weight of the jth marked sample can be kept unchanged after smoothing, so that the influence of samples between different marks on the model can be kept relatively unchanged after smoothing.

[0066] (2) Weight Iteration Update

[0067] The initial value of the weight is based on the consideration of balancing positive and negative samples, adjusting the training data, and pseudo-counting to increase the influence of relatively few positive samples in the model. However, due to the relatively small number of positive samples, the associated information between the features and labels contained in them is also less. The model may also have more bias towards positive samples during the learning process, that is, overfitting, and may underfit negative samples. From the perspective of statistical models, both overfitting and underfitting magnify the deviation between the distribution learned by the model from the training process (the empirical distribution from historical data) and the actual distribution. Therefore, in the iterative learning process of the model, the weight is adjusted according to the model state after each iteration, that is, the prediction result, and the smoothing technology is used to enhance the influence of underfitting samples in the subsequent learning process, thereby accelerating the convergence of training. Therefore, the sample weight at the non-initial time is defined as follows:

[0068]

[0069]

[0070]

[0071]

[0072] Among them, w i,j,t is the weight corresponding to the jth label of the ith example in the tth round of training of the multi-label model; pc i,j,t is the pseudo count corresponding to the jth label of the ith sample in the tth round of training of the multi-label model; c i,j,t is the predicted count corresponding to the jth label of the i-th sample in the t-th round of training of the multi-label model; is the total predicted count of the multi-label model during the tth round of training; r i,j,t is the normal term corresponding to the jth label of the ith example in the tth round of training of the multi-label model; is the total pseudo count of the multi-label model during the tth round of training; c i,j,t-1 is the predicted count corresponding to the jth label of the i-th sample in the t-1th round of training of the multi-label model; |y i,j -y′ i,j,t | is the prediction error in the current round of training, y′ i,j,t is the predicted value of the jth label of the ith example in the tth round of training of the multi-label model.

[0073] 2. Loss function based on sample weight

[0074] The loss function commonly used in multi-label is binary cross-entropy. Based on this, the present invention proposes a loss function combined with composite sample weights. The model training process aims to minimize the loss function. The binary cross-entropy loss function as a baseline is constant during the learning process, while the proposed load sample weight loss function, when the weight is regarded as a function parameter, the function itself changes with the training iteration. At any time, the loss function is defined as follows:

[0075]

[0076] l i,j,t =-w i,j,t ×(y i,j ×ln y′ i ,j,t +(1-y i,j )×ln 1-y′ i,j, t )

[0077]

[0078] Among them, loss t is the composite sample weight loss function during the tth round of training of the multi-label model; l i,j,tis the loss component of the j-th label of the ith example in the t-th round of training of the multi-label model; the underlined term refers to the downward truncation function; ε is a very small positive real number.

[0079] Embodiment 2

[0080] In practical applications, the multi-label model uses a pre-trained language model as the backbone and a linear discriminant model as the labeling layer. The former generates text vectors and the latter generates multi-label confidence vectors. The labeled sample data used includes about 40,000 single-sentence texts and about 10,000 labels. The trained model has an ACC of more than 85% for about 90% of the label types in the prediction test (when the prediction confidence on a certain label is greater than 0.85, the predicted sample is considered to have the label, otherwise it is a negative result). The baseline training method (without considering the sample weight and using the standard binary cross entropy loss function) only has an ACC of 85% for 20% of the label types, and there are a large number of label types that cannot produce prediction results with a positive tendency (here, the positive tendency refers to a confidence on a certain label greater than 0.6. Considering the random perturbation of the classification boundary, the confidence of 0.5 is not used as a positive criterion).

[0081] The training method proposed in the present invention can train an effective multi-label model when there are fewer labeled samples. Here, "fewer" refers to the small absolute number of labeled samples (such as less than 10 samples, and more than 10^5 potential unlabeled samples), and the small number of positive samples (from a binary classification perspective) relative to negative samples (such as a difference of 100 times). Therefore, this method can fill a part of the unlabeled samples into the negative samples (in actual application scenarios, positive samples are usually the focus of labeling), expand the overall training sample scale to a certain extent, and avoid the model from producing an invalid model due to too few training samples. "Invalid" means that the model prediction effect does not meet the actual needs. Because supervised learning models such as deep learning models are essentially statistical models, their output is based on the expected value of the probability (distribution) fitted by the model. The ratio of positive and negative samples as an empirical probability distribution determines the prior probability distribution of the model during prediction (for example, if the ratio of positive and negative samples in binary classification is less than 0.5, the prediction will be biased to discriminate the input as a negative example).

[0082] By adopting the above technical solution disclosed in the present invention, the following beneficial effects are obtained:

[0083] The present invention provides a small sample text multi-label model training method based on dynamic sample weights. By introducing sample weight adjustment and corresponding loss function in the training process, the present invention can greatly alleviate the problems caused by insufficient number of labeled samples and imbalance of positive and negative samples, and obtain a practical and usable text multi-label model.

[0084] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be considered as the scope of protection of the present invention.

Claims

1. A small sample text multi-label model training method based on dynamic sample weights, characterized by: The following steps are included: S1. Initialize the weights of the multi-label training samples based on the smoothing principle to obtain the initial weights of the multi-label training samples; The smoothing principle is to estimate the number of samples outside the training data and obtain the ability to adjust the sample composition by setting pseudo counts; The initial weights of multi-label training samples are calculated using the following formula: Among them, w i,j,t=0 is the weight corresponding to the jth label of the ith sample at t = 0, that is, the initial weight; pc i,j,t=0 is the pseudo count of positive samples corresponding to the jth label of the i-th sample at t = 0; is the total actual count of negative samples; is the total actual count of positive samples; r i,j,t=0 is the normal term corresponding to the jth label of the ith sample at t = 0; is the total pseudo count at t = 0; is the total actual count at t = 0; y i,j is the expected value of the jth label of the ith sample; c i,j,t=0 is the actual count corresponding to the jth label of the ith example at t = 0, which is defined as 1; t is the number of training rounds of the multi-label model; S2, training a multi-label model using the multi-label training samples, and constructing a composite sample weight loss function for the multi-label model based on the initial weights; S3, during the multi-label model training process, adjusting the weight of the multi-label training sample according to the label prediction result of the multi-label model on the multi-label training sample; S4. Use the adjusted weights as initial weights and iteratively execute steps S2 to S3 until a predetermined convergence condition is met to obtain a trained multi-label model.

2. The small sample text multi-label model training method based on dynamic sample weights according to claim 1 is characterized in that: The multi-label training samples include three sets of vectors, namely, feature vector set X, label vector set Y and sample weight vector set W. The cardinality of each set is equal to N. The single vector x of the set X represents the text feature vector of a single sentence, and its dimension is the output dimension of the vectorization model; The single vector y in the set Y represents the tag vector corresponding to a single sentence, and its dimension is the cardinality of the entire tag set, denoted as M; each component of the vector represents a specific tag, and its value range is 0 or 1. When a single sentence has a specific tag, the component value is 1, otherwise it is 0; The single vector w in the set W represents the weight vector corresponding to the tag vector, and its dimension is the same as that of the tag vector. Each component in w corresponds to a tag.

3. The small sample text multi-label model training method based on dynamic sample weights according to claim 2 is characterized in that: The multi-label task can be split into M binary classification tasks. The training samples with M labels of scale N are used as binary classification samples with a scale of N×M. The N feature vectors will be repeated M times, corresponding to N×M label scalars and N×M weight scalars. At this time, the weights are regarded as sample weights, and the sample scale and weight number are equal, which is N×M.

4. The small sample text multi-label model training method based on dynamic sample weights according to claim 2 is characterized in that: The vectorized model is a pre-trained language model using the Embedding and Transformer structures in the deep model.

5. The small sample text multi-label model training method based on dynamic sample weights according to claim 2 is characterized in that: The multi-label model adopts a pre-trained language model as a backbone and a linear discriminant model as a labeling layer; the pre-trained language model is used to generate a text vector, and the linear discriminant model is used to generate a multi-label confidence vector.

6. The small sample text multi-label model training method based on dynamic sample weights according to claim 1 is characterized in that: The weights of multi-label training samples are adjusted using the following formula: Among them, w i,j,t is the weight corresponding to the jth label of the ith example in the tth round of training of the multi-label model; pc i,j,t is the pseudo count corresponding to the jth label of the ith sample in the tth round of training of the multi-label model; c i,j,t is the predicted count corresponding to the jth label of the i-th sample in the t-th round of training of the multi-label model; is the total predicted count of the multi-label model during the tth round of training; r i,j,t is the normal term corresponding to the jth label of the ith example in the tth round of training of the multi-label model; is the total pseudo count of the multi-label model during the tth round of training; c i,j,t-1 is the predicted count corresponding to the jth label of the i-th sample in the t-1th round of training of the multi-label model; |y i,j -y i ′ ,j,t | is the prediction error in the current round of training, y i ′ ,j,t is the predicted value of the jth label of the ith example in the tth round of training of the multi-label model.

7. The small sample text multi-label model training method based on dynamic sample weights according to claim 6 is characterized by: The composite sample weight loss function is calculated using the following formula: Among them, loss t is the composite sample weight loss function during the tth round of training of the multi-label model; l i,j,t is the loss component of the j-th label of the ith example in the t-th round of training of the multi-label model; the underlined term refers to the downward truncation function; ε is a very small positive real number.

8. The small sample text multi-label model training method based on dynamic sample weights according to any one of claims 1 to 7, characterized in that: The preset convergence condition is minimization of the composite sample weight loss function.

Citation Information

Patent Citations

  • A generalized K-means algorithm-based text multi-label learning method

    CN109685103A

  • Partial multi-mark learning method based on complementary mark cooperative training

    CN113379037A

  • Noise data processing method and system based on confidence learning and label smoothing

    CN113515639A

  • Text classification method based on lightweight pre-training language model

    CN114168709A

  • Multi-label classification model construction method, classification method, classification device, electronic equipment and storage medium

    CN116310585A