Classification model training method, device, computer equipment and storage medium
By introducing loss values into the classification model to calculate the text to be trained with different labels, the difference recognition ability of the model is enhanced, which solves the problem of insufficient accuracy in classifying semantically similar texts in the existing technology and achieves higher text classification accuracy.
Patent Information
- Application Number
- CN202111146314.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-28
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2041-09-28
AI Technical Summary
When existing classification models process semantically similar texts, the classification accuracy is insufficient due to the similarity of encoding expressions, and they cannot effectively distinguish subtle gaps, leading to classification errors.
By obtaining the text to be trained in the training set, perform vectorization processing and calculation of prediction results, introduce the text to be trained with different classification labels to calculate the loss value, combine the cross entropy and cosine similarity functions to form the target loss value, and conduct iterative training of the model , enhance the model’s difference identification ability.
It improves the classification model's ability to recognize subtle differences in similar semantic texts, improves the accuracy of text classification, and performs better than the traditional BERT model.
Smart Images

Figure CN113849648B
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of artificial intelligence, and in particular to a classification model training method, apparatus, computer equipment and storage medium. Background Art
[0002] At present, most self-media platforms use the BERT (Bidirectional Encoder Representations from Transformer) classification model to classify texts. However, the semantic similarity of texts and the differences between labels will affect the classification work of the classification model, resulting in reduced performance of the classification model and insufficient classification accuracy. This is because for similar text content, the encoder module encodes similar expressions for this part of the content, and the classification model cannot distinguish these sentences with subtle differences in semantic expressions, resulting in classification errors. Summary of the invention
[0003] The main purpose of this application is to provide a classification model training method, apparatus, computer equipment and storage medium, aiming to solve the technical problem of inaccurate classification of current classification models.
[0004] To achieve the above purpose, the present application provides a classification model training method, comprising the following steps:
[0005] Acquire a first text to be trained in a training set; the first text to be trained has a preset classification label;
[0006] Inputting the first text to be trained into a preset model to be trained to calculate a prediction result of the first text to be trained; wherein the preset model to be trained first performs vectorization processing on the first text to be trained to obtain a corresponding first representation vector, and then calculates the prediction result of the first text to be trained through a preset classification function according to the first representation vector;
[0007] Inputting the prediction result into a preset first loss function to calculate a first loss value;
[0008] Selecting a second text to be trained from the training set; wherein the second text to be trained has a different classification label from the first text to be trained;
[0009] Inputting the first text to be trained and the second text to be trained into a preset second loss function to calculate a second loss value;
[0010] Taking the sum of the first loss value and the second loss value as the target loss value of the model to be trained;
[0011] The model to be trained is iteratively trained according to the target loss value to obtain a trained classification model.
[0012] Furthermore, the step of inputting the prediction result into a preset first loss function to calculate a first loss value includes:
[0013] The prediction result is input into a cross entropy function to calculate the first loss value.
[0014] Furthermore, the step of inputting the first text to be trained and the second text to be trained into a preset second loss function to calculate a second loss value includes:
[0015] Calculating the cosine similarity between the first text to be trained and the second text to be trained;
[0016] The cosine similarity is input into a preset second loss function to calculate the second loss value.
[0017] Further, the step of calculating the second loss value according to the cosine similarity includes:
[0018] According to the formula Calculate the second loss value; wherein the The cosine similarity between the first text to be trained and the second text to be trained is is the first text to be trained, It is the second text to be trained.
[0019] Furthermore, the second text to be trained includes a plurality of texts, and the classification labels of the second texts to be trained are different; the step of inputting the first text to be trained and the second text to be trained into a preset second loss function to calculate the second loss value includes:
[0020] Calculating the cosine similarity between the first text to be trained and each of the second texts to be trained;
[0021] Each cosine similarity is input into a preset second loss function to calculate the second loss value.
[0022] Furthermore, the step of calculating the prediction result of the first text to be trained by a preset classification function includes:
[0023] Detecting whether the model to be trained is for single-label classification or multi-label classification;
[0024] If the model to be trained is used for single-label classification, the prediction result of the first text to be trained is calculated by using the softmax function in the model to be trained;
[0025] If the model to be trained is used for multi-label classification, the prediction result of the first text to be trained is calculated by the sigmoid function in the model to be trained.
[0026] Furthermore, the step of calculating the cosine similarity between the first text to be trained and the second text to be trained includes:
[0027] Inputting the second text to be trained into the model to be trained to obtain a corresponding second representation vector;
[0028] The cosine similarity is calculated according to the first characterization vector and the second characterization vector.
[0029] The present application also provides a classification model training device, comprising:
[0030] An acquisition unit, configured to acquire a first text to be trained in a training set; the first text to be trained has a preset classification label;
[0031] A first calculation unit is used to input the first text to be trained into a preset model to be trained to calculate a prediction result of the first text to be trained; wherein the preset model to be trained first performs vectorization processing on the first text to be trained to obtain a corresponding first representation vector, and then calculates the prediction result of the first text to be trained through a preset classification function according to the first representation vector;
[0032] A second calculation unit, used for inputting the prediction result into a preset first loss function to calculate a first loss value;
[0033] A selection unit, configured to select a second text to be trained from the training set; wherein the second text to be trained has a different classification label from the first text to be trained;
[0034] A third calculation unit, used for inputting the first text to be trained and the second text to be trained into a preset second loss function to calculate a second loss value;
[0035] a target loss value unit, configured to take the sum of the first loss value and the second loss value as the target loss value of the model to be trained;
[0036] The training unit is used to iteratively train the model to be trained according to the target loss value to obtain a trained classification model.
[0037] The present application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the steps of the classification model training method described in any one of the above items are implemented.
[0038] The present application also provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of the classification model training method described in any one of the above items are implemented.
[0039] The classification model training method, apparatus, computer equipment and storage medium provided in the present application calculate a first loss value through the detection result of a first text to be trained, and then select a second text to be trained with a classification label different from that of the first text to be trained, and calculate a second loss value by introducing the second text to be trained, thereby obtaining a target loss value, and the model to be trained is trained through the target loss value to give negative supervision to the model to be trained, and through the difference between the first text to be trained and the second text to be trained, the model to be trained can better distinguish the subtle differences between similar semantics, so that the classification model finally trained can be more accurate. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 This is a schematic diagram of the steps of a classification model training method in one embodiment of the present application;
[0041] Figure 2 This is a structural block diagram of a classification model training device in one embodiment of the present application;
[0042] Figure 3 A schematic block diagram of the structure of a computer device according to an embodiment of the present application.
[0043] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0044] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0045] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Artificial Intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.
[0046] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0047] Reference Figure 1 , an embodiment of the present application provides a classification model training method, comprising the following steps:
[0048] Step S1, obtaining a first text to be trained in a training set; the first text to be trained has a preset classification label;
[0049] Step S2, inputting the first text to be trained into a preset model to be trained to calculate a prediction result of the first text to be trained; wherein the preset model to be trained first performs vectorization processing on the first text to be trained to obtain a corresponding first representation vector, and then calculates the prediction result of the first text to be trained through a preset classification function according to the first representation vector;
[0050] Step S3, inputting the prediction result into a preset first loss function to calculate a first loss value;
[0051] Step S4, selecting a second text to be trained from the training set; wherein the second text to be trained has a different classification label from the first text to be trained;
[0052] Step S5, inputting the first text to be trained and the second text to be trained into a preset second loss function to calculate a second loss value;
[0053] Step S6, taking the sum of the first loss value and the second loss value as the target loss value of the model to be trained;
[0054] Step S7, iteratively training the model to be trained according to the target loss value to obtain a trained classification model.
[0055] In this embodiment, as described in step S1 above, the training set includes multiple texts to be trained, each of which has a preset classification label, and the text to be trained currently input into the training model for training is used as the first text to be trained. In this embodiment, inputting one text to be trained is used as an example for training.
[0056] As described in the above steps S2-S3, the preset model to be trained can be Fasttext, TextCNN, DPCNN, TextRCNN, BERT model, etc. The following takes the BERT model as an example. The BERT model uses the encoder part of the transformer. The difference is that the BERT model adds segment embedding to the input part and the model parameter details are slightly different from the transformer. The first representation vector of the text to be trained is obtained through the encoder of the BERT model. The representation vector is composed of a word vector, a position vector and a segmentation vector.
[0057] The BERT model is pre-set with a classification function to calculate the first representation vector to obtain the prediction result of the first text to be trained. Calculate the first loss value between the prediction result and the pre-set classification label Specifically, the cross entropy loss function can be used to calculate the first loss value .
[0058] As described in step S4 above, the training set includes multiple texts to be trained, and the type of classification label is determined according to the results to be obtained from the training. For example, if you want to determine whether a novel belongs to romance, science fiction, or suspense, the classification labels include romance, science fiction, and suspense. The model to be trained can be a single-label classification or a multi-label classification. Single-label classification is a binary classification, including two classification labels. Multi-label classification indicates that a text to be reviewed can be applied to multiple classification labels. A text to be trained with a different classification label from the first text to be trained is selected from the training set as the second text to be trained. Specifically, the selection can be made by random selection.
[0059] As described in the above steps S5-S7, the second loss value is calculated according to the first text to be trained and the second text to be trained. , the first loss value and the second loss value The added value is used as the target loss value to train the training model, that is, the target loss value After iterative training, the target loss value will gradually decrease. When the target loss value is less than the preset loss threshold, the training can be stopped to obtain a completed text classification model.
[0060] In this embodiment, the second loss value is calculated by introducing the second text to be trained, thereby obtaining the target loss value, and the model to be trained is trained by the target loss value, giving the model to be trained negative supervision, and through the difference between the first text to be trained and the second text to be trained, the model to be trained can better distinguish the subtle differences between similar semantics, so that the text classification model finally trained can be more accurate. In this embodiment, the performance of subtle classification between texts with similar semantics after encoding by the encoder is better, and the accuracy of text classification ability is higher than that of traditional BERT model classification. This is due to the introduction of negative supervision, which allows the model to better distinguish the subtle differences between similar semantics.
[0061] In one embodiment, the step S3 of inputting the prediction result into a preset first loss function to calculate the first loss value includes:
[0062] Step S31, inputting the prediction result into a cross entropy function to calculate the first loss value.
[0063] In this embodiment, the first loss value is calculated using the cross entropy function as the first loss function. The cross entropy can measure the difference between two different probability distributions in the same random variable, which is expressed as the difference between the true probability distribution and the predicted probability distribution in machine learning. The smaller the cross entropy value, the better the model prediction effect.
[0064] In the case of binary classification, there are only two cases where the training model needs to predict the final result. For each category, the probability of our prediction is p and 1-p. At this time, the expression of the cross entropy function is:
[0065]
[0066] in, Represents the classification label of the first training text i, the positive class is 1, the negative class is 0, It indicates the probability that the first training text i is predicted to be a positive class, that is, the prediction result.
[0067] In the case of multi-classification, the expression of the cross entropy function is
[0068]
[0069] Where M is the number of categories, Symbol function (0 or 1), if the true category of the first training text i is equal to c, it takes 1, otherwise it takes 0, It represents the probability that the first training text i is predicted to be category c, that is, the prediction result.
[0070] In this embodiment, the target loss value is combined with the cross entropy as the loss function, so that the learning speed of the model to be trained is faster when the effect is poor, and the learning speed becomes slower when the effect is good.
[0071] In one embodiment, the step S5 of inputting the first to-be-trained text and the second to-be-trained text into a preset second loss function to calculate a second loss value includes:
[0072] Step S51, calculating the cosine similarity between the first text to be trained and the second text to be trained;
[0073] Step S52: input the cosine similarity into a preset second loss function to calculate the second loss value.
[0074] In this embodiment, by calculating the cosine similarity between the first text to be trained and the second text to be trained, the second loss value is calculated to encourage different representations for texts to be trained with different classification labels. The second loss function obtained by the cosine function intuitively encourages the texts to be trained to have a smaller cosine similarity. Through difference learning, the similarity between the second text to be trained and the first text to be trained is made as small as possible.
[0075] In one embodiment, the step S52 of calculating the second loss value according to the cosine similarity includes:
[0076] Step S521, according to the formula Calculate the second loss value; wherein the refers to the cosine similarity between the first text to be trained and the second text to be trained, is the first text to be trained, It is the second text to be trained.
[0077] In this embodiment, in order to encourage these texts to be trained to have different representations, the second loss value is calculated by the above-mentioned second loss function formula, and the sum of the second loss value and the first loss value is used as the target loss value to perform fusion training on the model to be trained, and differentiated learning is introduced to improve the pre-setting rate of the text classification model.
[0078] In one embodiment, the second text to be trained includes a plurality of texts, and the classification labels of the second texts to be trained are different; the step S5 of inputting the first text to be trained and the second text to be trained into a preset second loss function to calculate the second loss value includes:
[0079] Step S5a, calculating the cosine similarity between the first text to be trained and each of the second texts to be trained;
[0080] Step S5b: input each cosine similarity into a preset second loss function to calculate the second loss value.
[0081] In this embodiment, for single-label classification, there are only two categories of classification labels, and there is only one second text to be trained, which is randomly selected from the training set. However, for multi-classification labels, there are multiple classification labels. A text to be trained that has a different classification label from the first text to be trained can be randomly selected as the second text to be trained, that is, the second text to be trained has one, or all texts to be trained that have different classification labels from the first text to be trained can be used as the second text to be trained, that is, the second text to be trained has multiple, that is, N-1, N is the number of classification label types. By calculating the second loss value through multiple second texts to be trained, different classification labels can be better encouraged to have different representations, so that the model to be trained can better distinguish the subtle differences between similar semantics, and the classification results are more accurate.
[0082] Specifically, the cosine similarity between each second training text and the first training text is calculated. i , through the second loss function Calculate the second loss value, where , is the preset weight for each cosine similarity.
[0083] In one embodiment, the step S2 of obtaining the prediction result of the first text to be trained by calculating the preset classification function includes:
[0084] Step S21, detecting whether the model to be trained is for single-label classification or multi-label classification;
[0085] Step S22: if the model to be trained is used for single-label classification, the prediction result of the first text to be trained is calculated by the softmax function in the model to be trained;
[0086] Step S23: If the model to be trained is used for multi-label classification, the prediction result of the first text to be trained is calculated by the sigmoid function in the model to be trained.
[0087] In this embodiment, different functions are used to apply different classification types, and the expression of the softmax function is: where x jis the output value of the jth node, and k is the number of output nodes, that is, the number of categories. The Softmax function can be used to convert the output value of a single-label classification into a probability distribution ranging from 0 to 1. Once the softmax function is applied, we can understand it as a probability. When selecting the output node at the end, we can select the node with the largest probability (that is, the largest corresponding value) as our prediction result. The softmax function first increases the difference between the elements of the input vector (through an exponential function), and then normalizes it into a probability distribution. When applied to classification problems, it makes the probability difference of each category more significant, and the probability of the maximum value is closer to 1, so that the form of the output distribution is closer to the true distribution.
[0088] The expression of the sigmoid function is , where z is a linear combination, and the function of the sigmoid function is equivalent to compressing a real number to between 0 and 1. When z is a very large positive number, s(z) will approach 1, and when z is a very small negative number, s(z) will approach 0.
[0089] In one embodiment, the step S61 of calculating the cosine similarity between the first text to be trained and the second text to be trained includes:
[0090] Step S611, inputting the second text to be trained into the model to be trained to obtain a corresponding second representation vector;
[0091] Step S611: Calculate the cosine similarity according to the first characterization vector and the second characterization vector.
[0092] In this embodiment, when calculating the cosine similarity, the first text to be trained and the second text to be trained use the same editor to obtain corresponding representation vectors, and calculate the cosine similarity, and then train the model to be trained. Due to the introduction of the second text to be trained, the model can better distinguish the subtle differences between similar semantics, and has better performance in subtle classification of texts with similar semantics after encoding by the encoder. Compared with the traditional BERT model classification, the accuracy of text classification ability is higher.
[0093] See also Figure 2 , an embodiment of the present application provides a classification model training device, comprising:
[0094] An acquisition unit 10 is used to acquire a first text to be trained in a training set; the first text to be trained has a preset classification label;
[0095] A first calculation unit 20 is used to input the first text to be trained into a preset model to be trained to calculate a prediction result of the first text to be trained; wherein the preset model to be trained first performs vectorization processing on the first text to be trained to obtain a corresponding first representation vector, and then calculates the prediction result of the first text to be trained through a preset classification function according to the first representation vector;
[0096] A second calculation unit 30, configured to input the prediction result into a preset first loss function to calculate a first loss value;
[0097] A selection unit 40 is used to select a second text to be trained from the training set; wherein the second text to be trained has a different classification label from the first text to be trained;
[0098] A third calculation unit 50, configured to calculate a second loss value according to a preset second loss function inputted according to the first text to be trained and the second text to be trained;
[0099] A target loss value unit 60, configured to use the sum of the first loss value and the second loss value as a target loss value of the model to be trained;
[0100] The training unit 70 is used to iteratively train the model to be trained according to the target loss value to obtain a trained classification model.
[0101] In one embodiment, the second calculation unit 30 includes:
[0102] The first calculation subunit is used to input the prediction result into a cross entropy function to calculate the first loss value.
[0103] In one embodiment, the third calculation unit 50 includes:
[0104] A second calculation subunit, used for calculating the cosine similarity between the first text to be trained and the second text to be trained;
[0105] The third calculation subunit is used to input the cosine similarity into a preset second loss function to calculate the second loss value.
[0106] In one embodiment, the third computing subunit includes:
[0107] The first calculation module is used to calculate the Calculate the second loss value; wherein the Refers to the cosine similarity between the first text to be trained and the second text to be trained.
[0108] In one embodiment, the third calculation subunit 50 includes:
[0109] a fourth calculation subunit, configured to calculate the cosine similarity between the first text to be trained and each of the second texts to be trained;
[0110] The fifth calculation subunit is used to input each cosine similarity into a preset second loss function to calculate the second loss value.
[0111] In one embodiment, the first calculation unit 20 includes:
[0112] A detection subunit, used to detect whether the model to be trained is for single-label classification or multi-label classification;
[0113] a sixth calculation subunit, configured to calculate a prediction result of the first text to be trained by using a softmax function in the model to be trained if the model to be trained is used for single-label classification;
[0114] The seventh calculation subunit is used to calculate the prediction result of the first to-be-trained text by using the sigmoid function in the to-be-trained model if the to-be-trained model is used for multi-label classification.
[0115] In one embodiment, the second computing subunit includes:
[0116] An input module, used for inputting the second text to be trained into the model to be trained to obtain a corresponding second representation vector;
[0117] The second calculation module is used to calculate the cosine similarity according to the first characterization vector and the second characterization vector.
[0118] In this embodiment, the specific implementation of the above-mentioned units, sub-units, and modules please refer to the description in the above-mentioned method embodiment, and will not be repeated here.
[0119] Reference Figure 3 In the embodiment of the present application, a computer device is also provided. The computer device may be a server, and its internal structure may be as follows: Figure 3 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor designed by the computer is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data, etc. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a classification model training method is implemented.
[0120] Those skilled in the art will understand that Figure 3The structure shown in is merely a block diagram of a portion of the structure related to the present application solution and does not constitute a limitation on the computer device to which the present application solution is applied.
[0121] An embodiment of the present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, a classification model training method is implemented.
[0122] In summary, the classification model training method, device, computer equipment and storage medium provided in the embodiments of the present application obtain a first text to be trained in a training set; the first text to be trained has a preset classification label; the first text to be trained is input into the preset model to be trained to calculate the prediction result of the first text to be trained; wherein the preset model to be trained first vectorizes the first text to be trained to obtain the corresponding first representation vector, and then calculates the prediction result of the first text to be trained through a preset classification function according to the first representation vector; the prediction result is input into a preset first loss function to calculate a first loss value; a second text to be trained is selected from the training set; wherein the second text to be trained has a different classification label from the first text to be trained; the first text to be trained and the second text to be trained are input into a preset second loss function to calculate a second loss value; the sum of the first loss value and the second loss value is used as the target loss value of the model to be trained; the model to be trained is iteratively trained according to the target loss value to obtain a trained classification model. The classification model training method, apparatus, computer equipment and storage medium provided in the present application calculate a first loss value through the detection result of a first text to be trained, and then select a second text to be trained that has a different classification label from the first text to be trained, and calculate a second loss value by introducing the second text to be trained to obtain a target loss value. The model to be trained is trained with the target loss value to give negative supervision to the model to be trained. Through the difference between the first text to be trained and the second text to be trained, the model to be trained can better distinguish subtle differences between similar semantics, so that the text classification model finally trained can be more accurate.
[0123] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media provided in this application and used in the embodiments may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0124] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, device, article or method including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, device, article or method. In the absence of further restrictions, an element defined by the sentence "includes a ..." does not exclude the presence of other identical elements in the process, device, article or method including the element.
[0125] The above description is only a preferred embodiment of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly used in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A classification model training method, characterized in that: The following steps are involved: Acquire a first text to be trained in a training set; the first text to be trained has a preset classification label; Inputting the first text to be trained into a preset model to be trained to calculate a prediction result of the first text to be trained; wherein the preset model to be trained first performs vectorization processing on the first text to be trained to obtain a corresponding first representation vector, and then calculates the prediction result of the first text to be trained through a preset classification function according to the first representation vector; Inputting the prediction result into a preset first loss function to calculate a first loss value; Selecting a second text to be trained from the training set; wherein the second text to be trained has a different classification label from the first text to be trained; Inputting the first text to be trained and the second text to be trained into a preset second loss function to calculate a second loss value; Taking the sum of the first loss value and the second loss value as the target loss value of the model to be trained; Iteratively train the model to be trained according to the target loss value to obtain a trained classification model; The step of inputting the prediction result into a preset first loss function to calculate a first loss value comprises: Input the prediction result into a cross entropy function to calculate the first loss value; The step of inputting the first text to be trained and the second text to be trained into a preset second loss function to calculate a second loss value comprises: Calculating the cosine similarity between the first text to be trained and the second text to be trained; Input the cosine similarity into a preset second loss function to calculate the second loss value; The step of calculating the prediction result of the first text to be trained by a preset classification function includes: Detecting whether the model to be trained is for single-label classification or multi-label classification; If the model to be trained is used for single-label classification, the prediction result of the first text to be trained is calculated by using the softmax function in the model to be trained; If the model to be trained is used for multi-label classification, the prediction result of the first text to be trained is calculated by the sigmoid function in the model to be trained.
2. The classification model training method according to claim 1, characterized in that: The step of inputting the cosine similarity into a preset second loss function to calculate the second loss value comprises: According to the formula calculating the second loss value; Among them, the refers to the cosine similarity between the first text to be trained and the second text to be trained, is the first text to be trained, It is the second text to be trained.
3. The classification model training method according to claim 1, characterized in that: The step of calculating the cosine similarity between the first text to be trained and the second text to be trained comprises: Inputting the second text to be trained into the model to be trained to obtain a corresponding second representation vector; The cosine similarity is calculated according to the first characterization vector and the second characterization vector.
4. A classification model training device, used to execute the method according to any one of claims 1 to 3, characterized in that: include: An acquisition unit, used for acquiring the first text to be trained in the training set; The first text to be trained has a preset classification label; A first calculation unit is used to input the first text to be trained into a preset model to be trained to calculate a prediction result of the first text to be trained; wherein the preset model to be trained first performs vectorization processing on the first text to be trained to obtain a corresponding first representation vector, and then calculates the prediction result of the first text to be trained through a preset classification function according to the first representation vector; A second calculation unit, used for inputting the prediction result into a preset first loss function to calculate a first loss value; A selection unit, configured to select a second text to be trained from the training set; wherein the second text to be trained has a different classification label from the first text to be trained; A third calculation unit, used for inputting the first text to be trained and the second text to be trained into a preset second loss function to calculate a second loss value; a target loss value unit, configured to take the sum of the first loss value and the second loss value as the target loss value of the model to be trained; The training unit is used to iteratively train the model to be trained according to the target loss value to obtain a trained classification model.
5. A computer device comprising a memory and a processor, wherein a computer program is stored in the memory, wherein: When the processor executes the computer program, the steps of the classification model training method described in any one of claims 1 to 3 are implemented.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the classification model training method described in any one of claims 1 to 3 are implemented.
