Model training method, device, computer equipment and storage medium

By using multiple models to obtain feature data and loss functions in natural language processing, the application problems of deep neural networks on resource-constrained devices and the problem of low student model recognition accuracy are solved, and efficient text recognition effect is achieved.

CN114861671BActive Publication Date: 2024-11-05ZHUYI TECHNOLOGY (GUANGDONG HENGQIN GUANGDONG-MACAO DEEP COOP ZONE) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210375330.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-11
Publication Date
2024-11-05
Estimated Expiration
2042-04-11

AI Technical Summary

Technical Problem

Due to the large amount of parameters, the deep neural network model in existing natural language processing is difficult to directly apply on resource-constrained devices, and the student model obtained through knowledge distillation has a low accuracy in text recognition.

Method used

By obtaining text sample data, input it into multiple models to obtain feature data, calculate the similarity and loss function, and comprehensively determine the loss function to train the student model, improving the convergence speed and recognition accuracy of the model.

Benefits of technology

It realizes efficient student models training on resource-constrained devices, improves the accuracy of text recognition, and saves training time and hardware resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114861671B_ABST
    Figure CN114861671B_ABST
Patent Text Reader

Abstract

The present application relates to a model training method, device, computer equipment, storage medium and computer program product. The method comprises: inputting text sample data into a first model, determining a first loss according to the obtained first sample feature data; inputting text sample data into a second model, determining a second loss according to the obtained second sample feature data and the first sample feature data; inputting text sample data into a third model, obtaining third sample feature data, and determining, based on preset conditions, a third loss obtained by the similarity between the first sample feature data and the third sample feature data, or a third loss obtained by the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data; determining a loss function according to the first loss, the second loss and the third loss, and the loss function is used to train the first model. This solution can make the convergence speed of the first model faster and the accuracy of text recognition higher.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of natural language processing technology, and in particular to a model training method, apparatus, computer equipment, storage medium and computer program product. Background Art

[0002] With the development of deep learning, deep neural networks are increasingly used in natural language processing. In order to improve the performance of the model, most models are relatively complex, with large number of parameters and high memory consumption, making it difficult to directly apply them to devices with limited application resources such as GPUs (graphics processing units) and smartphones.

[0003] Knowledge distillation is a transfer learning method, which is to transfer the performance of one model to another model. For the teacher-student network, the teacher network is often a more complex network with better performance and generalization ability. The teacher network can be used as the objective function to guide the learning of another simpler student network, so that the simpler student model with fewer parameters can also have similar performance to the teacher network. This learning model can transform the network from a large network into a small network and retain performance close to that of the large network; it can also transfer the knowledge learned by multiple networks to one network, so that the performance of a single network is close to the overall results of multiple networks.

[0004] Knowledge distillation technology can be used to compress complex models to meet operational requirements, but the student model obtained through knowledge distillation often has low accuracy in text recognition. Summary of the invention

[0005] Based on this, it is necessary to provide a model training method, device, computer equipment, computer-readable storage medium and computer program product that can improve the recognition accuracy of the student model for text in response to the above-mentioned technical problems.

[0006] In a first aspect, the present application provides a model training method. The method comprises:

[0007] Get text sample data;

[0008] Inputting the text sample data into a first model to obtain first sample feature data, and determining a first loss according to the first sample feature data;

[0009] Inputting the text sample data into a second model to obtain second sample feature data, and determining a second loss according to the first sample feature data and the second sample feature data;

[0010] Input the text sample data into a third model to obtain third sample feature data, and determine, based on a preset condition, whether to obtain a third loss by using the similarity between the first sample feature data and the third sample feature data, or to obtain a third loss by using the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data;

[0011] A loss function is determined according to the first loss, the second loss and the third loss, and the loss function is used to train the first model.

[0012] In one embodiment, the text sample data includes a first sample, a second sample and a third sample, and the second sample is semantically similar to the first sample, and the third sample is semantically opposite to the first sample; the inputting the text sample data into the first model to obtain the first sample feature data includes:

[0013] Inputting the text sample data into the first model, and obtaining first target feature data according to the first sample;

[0014] Obtaining second target feature data according to the second sample;

[0015] Obtaining third target feature data according to the third sample;

[0016] The step of inputting the text sample data into the second model to obtain second sample feature data includes:

[0017] Inputting the text sample data into the second model, and obtaining fourth target feature data according to the first sample;

[0018] Obtaining fifth target characteristic data according to the second sample;

[0019] Obtaining sixth target characteristic data according to the third sample;

[0020] The step of inputting the text sample data into a third model to obtain third sample feature data comprises:

[0021] Inputting the text sample data into the third model, and obtaining seventh target feature data according to the first sample;

[0022] Obtaining eighth target characteristic data according to the second sample;

[0023] According to the third sample, ninth target characteristic data is obtained.

[0024] In one embodiment, determining the first loss according to the first sample characteristic data includes:

[0025] Determining a first similarity according to the first target feature data and the second target feature data;

[0026] Determining a second similarity based on the first target feature data and the third target feature data;

[0027] The first loss is determined according to the first similarity and the second similarity.

[0028] In one embodiment, the method further comprises:

[0029] Determining a first entropy value according to the first similarity and the second similarity;

[0030] Determine a first weight corresponding to the second loss and a second weight corresponding to the third loss according to the first entropy value;

[0031] The determining of a loss function according to the first loss, the second loss and the third loss comprises:

[0032] The loss function is determined according to the first loss, the second loss, the first weight, the third loss and the second weight.

[0033] In one embodiment, the determining, based on a preset condition, to obtain a third loss based on the similarity between the first sample feature data and the third sample feature data, or to obtain a third loss based on the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data, comprises:

[0034] Determine an average entropy value according to the first similarity and the second similarity;

[0035] If the average entropy value is greater than a preset threshold, determining that a third loss is obtained based on the similarity between the first sample feature data and the third sample feature data;

[0036] If the average entropy value is less than or equal to a preset threshold, it is determined that a third loss is obtained by using the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data.

[0037] In one embodiment, determining the second loss according to the first sample feature data and the second sample feature data includes:

[0038] determining a third similarity according to the first target feature data and the fourth target feature data;

[0039] Determining a fourth similarity according to the first target feature data and the fifth target feature data and the sixth target feature data;

[0040] The second loss is determined according to the third similarity and the fourth similarity.

[0041] In one embodiment, obtaining the third loss based on the similarity between the first sample feature data and the third sample feature data includes:

[0042] determining a fifth similarity according to the first target feature data and the seventh target feature data;

[0043] Determining a sixth similarity according to the first target feature data and the eighth target feature data and the ninth target feature data;

[0044] The third loss is determined according to the fifth similarity and the sixth similarity.

[0045] In one embodiment, obtaining the third loss based on the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data includes:

[0046] Determine a seventh similarity based on the third sample feature data obtained in this round and the historical third sample feature data;

[0047] The third loss is determined according to the seventh similarity and the fifth and sixth similarities.

[0048] In a second aspect, the present application also provides a model training device. The device comprises:

[0049] A sample data acquisition module is used to acquire text sample data;

[0050] A first loss determination module, configured to input the text sample data into a first model to obtain first sample feature data, and determine a first loss according to the first sample feature data;

[0051] A second loss determination module, configured to input the text sample data into a second model to obtain second sample feature data, and determine a second loss according to the first sample feature data and the second sample feature data;

[0052] A third loss determination module is used to input the text sample data into a third model to obtain third sample feature data, and based on a preset condition, determine whether to obtain a third loss by the similarity between the first sample feature data and the third sample feature data, or to obtain a third loss by the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data;

[0053] A loss function determination module is used to determine a loss function based on the first loss, the second loss and the third loss, and the loss function is used to train the first model.

[0054] In one embodiment, the text sample data includes a first sample, a second sample and a third sample, and the second sample is semantically similar to the first sample, and the third sample is semantically opposite to the first sample; the first loss determination module is further used to:

[0055] Inputting the text sample data into the first model, and obtaining first target feature data according to the first sample;

[0056] Obtaining second target feature data according to the second sample;

[0057] Obtaining third target feature data according to the third sample;

[0058] The second loss determination module is further used for:

[0059] Inputting the text sample data into the second model, and obtaining fourth target feature data according to the first sample;

[0060] Obtaining fifth target characteristic data according to the second sample;

[0061] Obtaining sixth target characteristic data according to the third sample;

[0062] The third loss determination module is further used for:

[0063] Inputting the text sample data into the third model, and obtaining seventh target feature data according to the first sample;

[0064] Obtaining eighth target characteristic data according to the second sample;

[0065] According to the third sample, ninth target characteristic data is obtained.

[0066] In one embodiment, the first loss determination module is further configured to:

[0067] Determining a first similarity according to the first target feature data and the second target feature data;

[0068] Determining a second similarity based on the first target feature data and the third target feature data;

[0069] The first loss is determined according to the first similarity and the second similarity.

[0070] In one embodiment, the model training device further includes a weight determination module for:

[0071] Determining a first entropy value according to the first similarity and the second similarity;

[0072] Determine a first weight corresponding to the second loss and a second weight corresponding to the third loss according to the first entropy value;

[0073] The loss function determination module is further used for:

[0074] The loss function is determined according to the first loss, the second loss, the first weight, the third loss and the second weight.

[0075] In one embodiment, the third loss determination module is further used to:

[0076] Determine an average entropy value according to the first similarity and the second similarity;

[0077] If the average entropy value is greater than a preset threshold, determining that a third loss is obtained based on the similarity between the first sample feature data and the third sample feature data;

[0078] If the average entropy value is less than or equal to a preset threshold, it is determined that a third loss is obtained by using the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data.

[0079] In one embodiment, the second loss determination module is further configured to:

[0080] determining a third similarity according to the first target feature data and the fourth target feature data;

[0081] Determining a fourth similarity according to the first target feature data and the fifth target feature data and the sixth target feature data;

[0082] The second loss is determined according to the third similarity and the fourth similarity.

[0083] In one embodiment, the third loss determination module is further used to:

[0084] determining a fifth similarity according to the first target feature data and the seventh target feature data;

[0085] Determining a sixth similarity according to the first target feature data and the eighth target feature data and the ninth target feature data;

[0086] The third loss is determined according to the fifth similarity and the sixth similarity.

[0087] In one embodiment, the third loss determination module is further used to:

[0088] Determine a seventh similarity based on the third sample feature data obtained in this round and the historical third sample feature data;

[0089] The third loss is determined according to the seventh similarity and the fifth and sixth similarities.

[0090] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:

[0091] Get text sample data;

[0092] Inputting the text sample data into a first model to obtain first sample feature data, and determining a first loss according to the first sample feature data;

[0093] Inputting the text sample data into a second model to obtain second sample feature data, and determining a second loss according to the first sample feature data and the second sample feature data;

[0094] Input the text sample data into a third model to obtain third sample feature data, and determine, based on a preset condition, whether to obtain a third loss by using the similarity between the first sample feature data and the third sample feature data, or to obtain a third loss by using the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data;

[0095] A loss function is determined according to the first loss, the second loss and the third loss, and the loss function is used to train the first model.

[0096] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:

[0097] Get text sample data;

[0098] Inputting the text sample data into a first model to obtain first sample feature data, and determining a first loss according to the first sample feature data;

[0099] Inputting the text sample data into a second model to obtain second sample feature data, and determining a second loss according to the first sample feature data and the second sample feature data;

[0100] Input the text sample data into a third model to obtain third sample feature data, and determine, based on a preset condition, whether to obtain a third loss by using the similarity between the first sample feature data and the third sample feature data, or to obtain a third loss by using the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data;

[0101] A loss function is determined according to the first loss, the second loss and the third loss, and the loss function is used to train the first model.

[0102] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:

[0103] Get text sample data;

[0104] Inputting the text sample data into a first model to obtain first sample feature data, and determining a first loss according to the first sample feature data;

[0105] Inputting the text sample data into a second model to obtain second sample feature data, and determining a second loss according to the first sample feature data and the second sample feature data;

[0106] Input the text sample data into a third model to obtain third sample feature data, and determine, based on a preset condition, whether to obtain a third loss by using the similarity between the first sample feature data and the third sample feature data, or to obtain a third loss by using the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data;

[0107] A loss function is determined according to the first loss, the second loss and the third loss, and the loss function is used to train the first model.

[0108] The above-mentioned model training method, device, computer equipment, storage medium and computer program product obtain text sample data; input the text sample data into a first model to obtain first sample feature data, and determine a first loss based on the first sample feature data; input the text sample data into a second model to obtain second sample feature data, and determine a second loss based on the first sample feature data and the second sample feature data; input the text sample data into a third model to obtain third sample feature data, and based on preset conditions, determine to obtain a third loss based on the similarity between the first sample feature data and the third sample feature data, or to obtain a third loss based on the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data; determine a loss function based on the first loss, the second loss and the third loss, and the loss function is used to train the first model. The present application determines the loss function by combining the first loss obtained according to the first model, the second loss obtained according to the second model and the third loss obtained according to the third model, and selects different methods for determining the third loss according to preset conditions, and then trains the first model according to the loss function, that is, two models are used to guide and train the first model at the same time, so that the convergence speed of the first model is faster, the training efficiency of the model is improved, the training time is saved, and then the hardware resources are saved, and the accuracy of text recognition is higher. BRIEF DESCRIPTION OF THE DRAWINGS

[0109] Figure 1 An application environment diagram of a model training method in an embodiment;

[0110] Figure 2 A schematic diagram of a flow chart of a model training method in one embodiment;

[0111] Figure 3 is a schematic diagram of the process in step 204 in one embodiment;

[0112] Figure 4 is a schematic diagram of the process in step 208 in one embodiment;

[0113] Figure 5 is a schematic diagram of the process in step 206 in one embodiment;

[0114] Figure 6 is a schematic diagram of the flow chart of step 208 in another embodiment;

[0115] Fig. 7A A schematic diagram of a flow chart of a model training method in another embodiment;

[0116] Figure 7B A schematic diagram of a flow chart of a model training method in another embodiment;

[0117] Figure 8 is a structural block diagram of a model training device in one embodiment;

[0118] Fig. 9 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0119] 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.

[0120] The model training method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. The server 104 obtains the text sample data sent by the terminal 102, inputs the text sample data into the first model, obtains the first sample feature data, and determines the first loss according to the first sample feature data; inputs the text sample data into the second model to obtain the second sample feature data, and determines the second loss according to the first sample feature data and the second sample feature data; inputs the text sample data into the third model to obtain the third sample feature data, and based on the preset conditions, determines that the third loss is obtained by the similarity between the first sample feature data and the third sample feature data, or the third loss is obtained by the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data; determines the loss function according to the first loss, the second loss and the third loss, wherein the loss function is used to train the first model.

[0121] The terminal 102 may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, IoT devices, and portable wearable devices. The IoT devices may be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. The portable wearable devices may be smart watches, smart bracelets, head-mounted devices, etc. The server 104 may be implemented as an independent server or a server cluster consisting of multiple servers.

[0122] It should be noted here that any step in the model training method disclosed in the embodiments of the present application can be implemented by the terminal 102 and the server 104 in an interactive manner, or by the server 104 alone, or by the terminal 102 alone, and there is no limitation here.

[0123] In one embodiment, Figure 2As shown, a model training method is provided, which is applied to Figure 1 The server in the example is used to illustrate the following steps:

[0124] Step 202: Obtain text sample data.

[0125] The server can obtain the text sample data through the terminal, or directly obtain the text sample data. The text sample data can be in the form of any sentence, paragraph or article, and can include multiple types of samples at the same time, for example, at least one sample among sample A, sample B and sample C. Sample A is any sentence, paragraph or article, then sample B is the corresponding sentence, paragraph or article with similar semantics to sample A, and sample C is the corresponding sentence, paragraph or article with opposite semantics to sample A. If the text sample data includes three samples, namely sample A, sample B and sample C, when input into the model for processing, the corresponding model can be input in the form of sentence pairs, for example, sentence 1 in sample A, sentence 2 in sample B with similar semantics to sentence 1, and sentence 3 in sample C with opposite semantics to sentence 1 are input into the model for processing.

[0126] Step 204: input the text sample data into the first model to obtain first sample feature data, and determine the first loss according to the first sample feature data.

[0127] The text sample data is input into the first model for processing to obtain the first sample feature data. If the text sample data includes multiple types of samples, the first sample feature data includes multiple target feature data. Among them, the first model is a model to be trained, for example, it can be a 3-layer, 4-layer or 6-layer BERT (Bidirectional Encoder Representations from Transformers) model, or a biLSTM (Bi-directional Long Short-Term Memory). The first loss is determined according to the first sample feature data. In one possible implementation, the similarity between the first feature data is calculated, and then the first loss is determined according to the similarity between the first feature data, for example, the mean square error (MSE, Mean Squared Error) or cross entropy corresponding to the similarity between the first feature data is used as the first loss. For example, if the cross entropy between distribution p and distribution q is to be calculated, it can be calculated by the following formula (1):

[0128]

[0129] Where n represents the number of samples, x i=1,2,…,n represents the i-th sample.

[0130] The mean square error is calculated as follows:

[0131]

[0132] Among them, m represents the number of samples, y i=1,2,…,m represents the i-th sample, Represents the sample mean.

[0133] Step 206: input the text sample data into the second model to obtain second sample feature data, and determine the second loss according to the first sample feature data and the second sample feature data.

[0134] The text sample feature data is input into the second model for processing to obtain the second sample feature data. If the text sample data includes multiple types of samples, the second sample feature data includes multiple target feature data. The second model is a trained model, but the model parameters will be updated in the subsequent process. The type of the second model can be the same as the first model or different, and it is selected according to the actual situation. The second loss is determined according to the first sample feature data and the second sample feature data. Specifically, the similarity between the first sample feature data and the second sample feature data is calculated first, and the second loss is determined according to the similarity between the first sample feature data and the second sample feature data. For example, the mean square error or cross entropy corresponding to the similarity between the first sample feature data and the second sample feature data can be used as the second loss.

[0135] Step 208, input the text sample data into the third model to obtain third sample feature data, and based on preset conditions, determine whether to obtain a third loss based on the similarity between the first sample feature data and the third sample feature data, or to obtain a third loss based on the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data.

[0136] The text sample data is input into the third model for processing to obtain the third sample feature data. If the text sample data includes multiple types of samples, the third sample feature data includes multiple target feature data. Among them, the third model is a trained model, which is equivalent to the target model of the first model. For example, the third model can specifically be a BERT large model or a BERT base model. In this embodiment, by setting preset conditions, it is determined whether the third loss is obtained by the similarity between the first sample feature data and the third sample feature data, or by the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data.

[0137] In a possible implementation, when the preset condition is met, the third loss is obtained by the similarity between the first sample feature data and the third sample feature data; when the preset condition is not met, the third loss is obtained by the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data. Alternatively, when the preset condition is met, the third loss is obtained by the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data; when the preset condition is not met, the third loss is obtained by the similarity between the first sample feature data and the third sample feature data.

[0138] In another possible implementation, the preset condition is a preset threshold value, and if it is greater than the preset threshold value, the third loss is obtained by the similarity between the first sample feature data and the third sample feature data; if it is less than or equal to the preset threshold value, the third loss is obtained by the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data. Alternatively, if it is greater than the preset threshold value, the third loss is obtained by the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data; if it is less than or equal to the preset threshold value, the third loss is obtained by the similarity between the first sample feature data and the third sample feature data.

[0139] In an optional embodiment, when the third loss is obtained by the similarity between the first sample feature data and the third sample feature data, the mean square error or cross entropy corresponding to the similarity between the first sample feature data and the third sample feature data can be used as the third loss. Similarly, when the third loss is obtained by the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data, the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data can be spliced ​​to obtain the spliced ​​similarity, and the mean square error or cross entropy corresponding to the spliced ​​similarity can be used as the third loss. When the third loss is obtained by the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data, the relative entropy of the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data can be used as the third loss.

[0140] Step 210, determining a loss function according to the first loss, the second loss, and the third loss, wherein the loss function is used to train the first model.

[0141] In this embodiment, the loss function is determined according to the first loss, the second loss and the third loss. The loss function can be obtained by weighted summing the first loss, the second loss and the third loss. The first model is trained by the loss function until the training is terminated after the convergence condition is met.

[0142] In the above-mentioned model training method, by obtaining text sample data; inputting the text sample data into the first model to obtain the first sample feature data, and determining the first loss according to the first sample feature data; inputting the text sample data into the second model to obtain the second sample feature data, and determining the second loss according to the first sample feature data and the second sample feature data; inputting the text sample data into the third model to obtain the third sample feature data, and based on the preset conditions, determining the third loss by the similarity between the first sample feature data and the third sample feature data, or by the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data; determining the loss function according to the first loss, the second loss and the third loss, wherein the loss function is used to train the first model. The embodiment of the present application combines the first loss obtained according to the first model, the second loss obtained by the second model and the third loss obtained by the third model to comprehensively determine the loss function, and at the same time selects different ways of determining the third loss according to the preset conditions, and then trains the first model according to the loss function, that is, using two models to guide and train the first model at the same time, so that the convergence speed of the first model is faster, the training efficiency of the model is improved, the training time is saved, and then the hardware resources are saved, and the accuracy of text recognition is higher.

[0143] In one embodiment, the text sample data includes a first sample, a second sample and a third sample, and the second sample is semantically similar to the first sample, and the third sample is semantically opposite to the first sample; in step 204, the text sample data is input into the first model to obtain first sample feature data, including: inputting the text sample data into the first model, obtaining first target feature data according to the first sample; obtaining second target feature data according to the second sample; obtaining third target feature data according to the third sample;

[0144] In step 206, the text sample data is input into the second model to obtain second sample feature data, including: inputting the text sample data into the second model, obtaining fourth target feature data according to the first sample; obtaining fifth target feature data according to the second sample; obtaining sixth target feature data according to the third sample;

[0145] In step 208, the text sample data is input into the third model to obtain third sample feature data, including: inputting the text sample data into the third model to obtain seventh target feature data according to the first sample; obtaining eighth target feature data according to the second sample; and obtaining ninth target feature data according to the third sample.

[0146] In this embodiment, the text sample data includes a first sample, a second sample and a third sample, and the second sample is semantically similar to the first sample, and the third sample is semantically opposite to the first sample. The text sample data is input into different models to obtain corresponding different target feature data. The text sample data is input into the first model to obtain the first sample feature data, and the first sample feature data includes the first target feature data, the second target feature data and the third target feature data; the text sample data is input into the second model to obtain the second sample feature data, and the second sample feature data includes the fourth target feature data, the fifth target feature data and the sixth target feature data; the text sample data is input into the third model to obtain the third sample feature data, and the third sample feature data includes the seventh target feature data, the eighth target feature data and the ninth target feature data. By using multiple types of text sample data, that is, using rich text sample data to train the first model, the accuracy of the first model in recognizing text can be further improved.

[0147] In one embodiment, Figure 3 As shown, determining the first loss according to the first sample characteristic data in step 204 includes:

[0148] Step 302: Determine a first similarity based on the first target feature data and the second target feature data.

[0149] Similarity, that is, represents the similarity between two things. The more similar the two are, the greater the similarity, and vice versa. Similarity can be characterized by Jaccard similarity coefficient, cosine similarity, distance or Pearson correlation coefficient. Among them, Jaccard similarity coefficient is mainly used to calculate the similarity between samples of symbolic measurement or Boolean measurement; cosine similarity evaluates the similarity between two vectors by calculating the cosine value of the angle between two vectors; similarity is characterized by distance, and the Euclidean distance or Manhattan distance between vectors can be used to characterize its similarity; Pearson correlation coefficient is the closeness of the connection between two fixed-distance variables. The specific similarity characterization method is not limited to this, and is not specifically limited here. The corresponding similarity characterization method is selected according to actual needs. In this embodiment, the cosine similarity between the first target feature data and the second target feature data can be calculated as the first similarity.

[0150] Step 304: Determine a second similarity based on the first target feature data and the third target feature data.

[0151] In this embodiment, the cosine similarity between the first target feature data and the third target feature data is calculated to obtain the second similarity.

[0152] Step 306: Determine a first loss according to the first similarity and the second similarity.

[0153] Determine the first loss based on the first similarity and the second similarity. In one possible implementation, the first similarity and the second similarity may be concatenated to obtain a first concatenated similarity, and the first concatenated similarity may be normalized, that is, processed into a value between 0 and 1. For example, a softmax function may be used to obtain a normalized result corresponding to the first concatenated similarity, and the mean square error or cross entropy of the normalized result may be calculated, and the mean square error or cross entropy of the normalized result may be used as the first loss. The softmax function is shown in the following formula (3):

[0154]

[0155] Among them, P(Z i,j ) represents the result of normalization processing, Z i,j is the similarity between the i-th sample and the j-th sample, and C is the total number of samples.

[0156] In one embodiment, the model training method further includes:

[0157] A first entropy value is determined according to the first similarity and the second similarity.

[0158] In this embodiment, a cross entropy corresponding to the first similarity and the second similarity is obtained according to the first similarity and the second similarity, and the first entropy value is determined according to the maximum value of the cross entropy and the actual entropy value.

[0159] In a possible implementation, as described above, the first similarity and the second similarity are concatenated to obtain a first concatenated result, the first concatenated result is normalized to obtain a normalized result, and the cross entropy S(Z) of the normalized result is calculated. i ), as shown in the following formula (4):

[0160] S(Z i )=-Σ j∈C P(Z i,j )log b P(Z i,j ) (4)

[0161] According to the entropy maximum principle, when When , the maximum value of cross entropy is obtained, that is, the similarity of all samples is the same at this time.

[0162] The ratio of the maximum cross entropy value to the actual entropy value is taken as the first entropy value.

[0163] A first weight corresponding to the second loss and a second weight corresponding to the third loss are determined according to the first entropy value.

[0164] In this embodiment, the first entropy value is used to determine the weights corresponding to the second loss and the third loss. Specifically, the first entropy value can be used as the first weight corresponding to the second loss, and the difference between 1 and the first entropy value can be used as the second weight corresponding to the third loss.

[0165] The step 210 of determining a loss function according to the first loss, the second loss and the third loss comprises:

[0166] A loss function is determined according to the first loss, the second loss, the first weight, the third loss, and the second weight.

[0167] In this embodiment, the loss function can be obtained by weighted summing the first loss, the second loss and the third loss, where the weight of the second loss is the first weight and the weight of the third loss is the second weight. In a possible implementation, the weight of the first loss can be 1, that is, the loss function is the sum of the first loss, the product of the second loss and the first weight, and the product of the third loss and the second weight.

[0168] In one embodiment, Figure 4 As shown, in step 208, based on a preset condition, determining that the third loss is obtained by the similarity between the first sample feature data and the third sample feature data, or the third loss is obtained by the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data includes:

[0169] Step 402: determine an average entropy value according to the first similarity and the second similarity.

[0170] For one round of model training, i.e., one iteration, as in the above-mentioned embodiment, the first similarity and the second similarity can be spliced ​​to obtain a first splicing result, the first splicing result can be normalized to obtain a normalized result, and the cross entropy of the normalized result is calculated as the entropy value of this iteration. According to the number of iterations and the entropy value obtained in each iteration, the average entropy value is determined. The average entropy value can be the arithmetic mean of the entropy values ​​of each iteration of the model training, or it can be the weighted average of the entropy values ​​of each iteration.

[0171] Step 404: If the average entropy value is greater than a preset threshold, determine a third loss obtained by the similarity between the first sample feature data and the third sample feature data.

[0172] Step 406: If the average entropy value is less than or equal to the preset threshold, determine a third loss obtained by the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data.

[0173] In this embodiment, the preset condition is the relationship between the average entropy value and the preset threshold value, that is, if the average entropy value is greater than the preset threshold value, the third loss is determined to be obtained by the similarity between the first sample feature data and the third sample feature data; if the average entropy value is less than or equal to the preset threshold value, the third loss is determined to be obtained by the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data. This embodiment dynamically adjusts and selects the determination method of the third loss through the relationship between the average entropy value and the preset threshold value, thereby obtaining a loss function that is more in line with the actual training process, so that the model training accuracy is further improved.

[0174] In one embodiment, Figure 5 As shown, determining the second loss according to the first sample feature data and the second sample feature data in step 206 includes:

[0175] Step 502: Determine a third similarity based on the first target feature data and the fourth target feature data.

[0176] In this embodiment, the third similarity can be obtained by calculating the similarity between the first target feature data and the fourth target feature data, wherein the first target feature data is obtained by the first model according to the first sample in this round of training, and the fourth target feature data is obtained by the second model according to the first sample in this round of training.

[0177] Step 504: Determine a fourth similarity based on the first target feature data and the fifth target feature data and the sixth target feature data.

[0178] In an optional embodiment, the third similarity can be obtained by calculating the similarity between the first target feature data and the fifth target feature data and the sixth target feature data, that is, calculating the similarity between the first target feature data and the fifth target feature data and the sixth target feature data as a whole. The first target feature data is obtained through the first model and based on the first sample in this round of training, the fifth target feature data is obtained through the second model and based on the second sample in this round of training, and the sixth target feature data is obtained through the second model and based on the third sample in this round of training.

[0179] In another optional embodiment, the fourth similarity is determined based on the first target feature data and the fifth target feature data, the sixth target feature data and the historical second sample feature data. The historical second sample feature data is obtained by the text sample data through the second model in the preset number of previous trainings, including the fourth target feature data, the fifth target feature data and the sixth target feature data obtained in the preset number of previous trainings. The preset number of times can be all the previous training times, or it can be the preset number closest to the current round of training. The historical second sample feature data can be stored in the memory corresponding to the second model in the form of a queue. The similarity between the first target feature data and the fifth target feature data, the sixth target feature data and the historical second sample feature data as a whole is calculated as the fourth similarity.

[0180] Step 506: Determine a second loss according to the third similarity and the fourth similarity.

[0181] In this embodiment, the second loss is determined according to the third similarity and the fourth similarity. The third similarity and the fourth similarity may be concatenated to obtain a second concatenated similarity, the second concatenated similarity may be normalized to obtain a normalized result corresponding to the second concatenated similarity, a mean square error or a cross entropy of the normalized result corresponding to the second concatenated similarity may be calculated, and the mean square error or the cross entropy of the normalized result corresponding to the second concatenated similarity may be used as the second loss.

[0182] In one embodiment, Figure 6 As shown, in step 208, the third loss is obtained based on the similarity between the first sample feature data and the third sample feature data, including:

[0183] Step 602: Determine a fifth similarity based on the first target feature data and the seventh target feature data.

[0184] In this embodiment, the fifth similarity can be obtained by calculating the similarity between the first target feature data and the seventh target feature data, wherein the first target feature data is obtained by the first model according to the first sample in this round of training, and the seventh target feature data is obtained by the third model according to the first sample in this round of training.

[0185] Step 604: Determine a sixth similarity based on the first target feature data and the eighth target feature data and the ninth target feature data.

[0186] In an optional embodiment, the sixth similarity can be obtained by calculating the similarity between the first target feature data and the eighth target feature data and the ninth target feature data, that is, calculating the similarity between the first target feature data and the eighth target feature data and the ninth target feature data as a whole. The first target feature data is obtained through the first model and based on the first sample in this round of training, the eighth target feature data is obtained through the third model and based on the second sample in this round of training, and the ninth target feature data is obtained through the third model and based on the third sample in this round of training.

[0187] In another optional embodiment, the fourth similarity is determined based on the first target feature data and the eighth target feature data, the ninth target feature data and the historical third sample feature data. The historical third sample feature data is obtained by the text sample data through the third model in the preset number of previous trainings, including the seventh target feature data, the eighth target feature data and the ninth target feature data obtained in the preset number of previous trainings. The preset number of times can be all the previous training times, or it can be the preset number closest to the current round of training. The historical third sample feature data can be stored in the memory corresponding to the third model in the form of a queue. The similarity between the first target feature data and the eighth target feature data, the ninth target feature data and the historical third sample feature data as a whole is calculated as the fourth similarity.

[0188] Step 606: Determine a third loss according to the fifth similarity and the sixth similarity.

[0189] In this embodiment, the third loss is determined according to the fifth similarity and the sixth similarity. The fifth similarity and the sixth similarity may be concatenated to obtain a third concatenated similarity, the third concatenated similarity may be normalized to obtain a normalized result corresponding to the third concatenated similarity, a mean square error or a cross entropy of the normalized result corresponding to the third concatenated similarity may be calculated, and the mean square error or the cross entropy of the normalized result corresponding to the third concatenated similarity may be used as the third loss.

[0190] In one embodiment, in step 208, obtaining the third loss based on the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data includes:

[0191] The seventh similarity is determined based on the third sample feature data obtained in this round and the historical third sample feature data.

[0192] According to the description of the aforementioned step 604, the historical third sample feature data is obtained by the text sample data through the third model in the previous training of a preset number of times, and the historical third sample feature data includes the seventh target feature data, the eighth target feature data and the ninth target feature data obtained in the previous training of the preset number of times. The third sample feature data obtained in this round includes the seventh target feature data, the eighth target feature data and the ninth target feature data obtained in this round through the third model. In this embodiment, the similarity between the third sample feature data obtained in this round and the historical third sample feature data can be calculated, that is, the similarity between the seventh target feature data, the eighth target feature data and the ninth target feature data obtained in this round and the seventh target feature data, the eighth target feature data and the ninth target feature data obtained in the previous training of the preset number of times is calculated as the seventh similarity.

[0193] A third loss is determined according to the seventh similarity, the fifth similarity, and the sixth similarity.

[0194] In this embodiment, the fifth similarity and the sixth similarity are concatenated to obtain a fifth concatenated similarity, a relative entropy between the seventh similarity and the fifth concatenated similarity is calculated, and the relative entropy between the seventh similarity and the fifth concatenated similarity is used as the third loss.

[0195] In an optional embodiment, the fifth similarity, the sixth similarity and the seventh similarity may be concatenated to obtain a fourth concatenated similarity, the fourth concatenated similarity may be normalized to obtain a normalized result corresponding to the fourth concatenated similarity, the mean square error or cross entropy of the normalized result corresponding to the fourth concatenated similarity may be calculated, and the mean square error or cross entropy of the normalized result corresponding to the fourth concatenated similarity may be used as the third loss.

[0196] In one embodiment, Fig. 7A As shown, the model training method includes:

[0197] Step 702: Acquire text sample data, wherein the text sample data includes a first sample, a second sample, and a third sample, and the second sample is semantically similar to the first sample, and the third sample is semantically opposite to the first sample.

[0198] In this embodiment, the text sample data can be in the form of any sentence, paragraph or article. The text sample data includes a first sample, a second sample and a third sample. In each training, the first sample, the second sample and the third sample are input into the corresponding model for processing. Figure 7B To explain, the text sample data includes sample x, positive sample x + , negative sample x - , sample x, positive sample x + , negative sample x -are input into the model for processing.

[0199] Step 704, input the text sample data into the first model, and obtain the first target feature data according to the first sample; obtain the second target feature data according to the second sample; obtain the third target feature data according to the third sample; input the text sample data into the second model, and obtain the fourth target feature data according to the first sample; obtain the fifth target feature data according to the second sample; obtain the sixth target feature data according to the third sample; input the text sample data into the third model, and obtain the seventh target feature data according to the first sample; obtain the eighth target feature data according to the second sample; and obtain the ninth target feature data according to the third sample.

[0200] In this embodiment, different text sample data are input into different models to obtain different target feature data. The first model can be the same as or different from the second model. For example, the first model and the second model can be a 3-layer, 4-layer or 6-layer BERT model, or a biLSTM, and the third model can be a BERT large model or a BERT base model. Figure 7B In the example, the first model is the student model, the second model is the Small teacher model, and the third model is the Large teacher model. Sample x is input into the student model to generate feature f, and the positive sample x + Input student model to generate features f+, negative samples x - Input the student model to generate feature f-; similarly, input the text sample data into the Small teacher model and the Large teacher model to generate corresponding feature data. In addition, the data generated by the Small teacher model is stored in the form of a queue in memory bank1, and the data generated by the Large teacher model is stored in the form of a queue in memory bank2. The amount of data stored in memory bank1 and memory bank2 is set according to demand and is not further limited here.

[0201] Step 706, calculate the cosine similarity between the first target feature data and the second target feature data to obtain a first similarity; calculate the cosine similarity between the first target feature data and the third target feature data to obtain a second similarity; concatenate the first similarity and the second similarity to obtain a first concatenated similarity, and use the cross entropy of the first concatenated similarity as a first loss.

[0202] In this embodiment, the cosine similarity between the first target feature data and the second target feature data is calculated to obtain the first similarity; the cosine similarity between the first target feature data and the third target feature data is calculated to obtain the second similarity; the first similarity and the second similarity are spliced ​​to obtain the first spliced ​​similarity, the first spliced ​​similarity is normalized to obtain the normalized result corresponding to the first spliced ​​similarity, the cross entropy of the normalized result corresponding to the first spliced ​​similarity is calculated, and the cross entropy of the normalized result is used as the first loss. In a possible implementation, the similarity between the sample and the positive sample, as well as the similarity between the sample and the negative sample, can be obtained by supervised training, and the similarity between the sample and the positive sample, as well as the similarity between the sample and the negative sample are spliced ​​to obtain the first spliced ​​similarity. According to the first splicing similarity Calculate the supervised loss l s , that is, the first loss is l s .

[0203] Step 708, calculate the cosine similarity between the first target feature data and the fourth target feature data to obtain a third similarity; calculate the cosine similarity between the first target feature data and the fifth target feature data, the sixth target feature data and the historical second feature data to obtain a fourth similarity; concatenate the third similarity and the fourth similarity to obtain a second concatenated similarity, and use the cross entropy of the second concatenated similarity as the second loss.

[0204] In this embodiment, the third similarity is obtained by calculating the cosine similarity between the first target feature data obtained in this round of training and the fourth target feature data obtained in this round of training. The fourth similarity is obtained by calculating the cosine similarity between the first target feature data obtained in this round of training and the fifth target feature data obtained in this round of training, the sixth target feature data obtained in this round of training, and the historical second feature data, wherein the historical second feature data is the fourth target feature data, the fifth target feature data, and the sixth target feature data obtained in the preset number of previous trainings. The preset number of times can be all the previous training times, or it can be the preset number closest to the current round of training, for example, the 10 times closest to the current round of training. The third similarity and the fourth similarity are spliced ​​to obtain a second spliced ​​similarity, the second spliced ​​similarity is normalized to obtain a normalized result corresponding to the second spliced ​​similarity, the cross entropy of the normalized result corresponding to the second spliced ​​similarity is calculated, and the cross entropy of the normalized result is used as the second loss.

[0205] Depend on Figure 7B It can be seen that the similarity is calculated based on the features generated by the student model, the features generated by the small teacher model, and the feature data obtained from previous training stored in memory bank1. Based on similarity Calculate the unsupervised loss l u,s , that is, the second loss is l u,s .

[0206] Step 710, determining an average entropy value according to the first similarity and the second similarity; if the average entropy value is greater than a preset threshold, obtaining a third loss in the manner described in step 712; if the average entropy value is less than or equal to the preset threshold, obtaining a third loss in the manner described in step 714.

[0207] In this embodiment, the average entropy value is determined based on the number of iterations and the entropy value obtained in each iteration. According to the description of step 706, the cross entropy corresponding to each round of training can be obtained, and the average entropy value can be determined based on the number of training rounds and the cross entropy corresponding to each round of training. The average entropy value can be the arithmetic mean of the cross entropy of each iteration of model training, or it can be the weighted average of the cross entropy of each iteration. The preset threshold is set according to demand. If the average entropy value is greater than the preset threshold, the third loss is obtained in the manner described in step 712; if the average entropy value is less than or equal to the preset threshold, the third loss is obtained in the manner described in step 714.

[0208] Step 712, calculate the cosine similarity between the first target feature data and the seventh target feature data to obtain the fifth similarity; calculate the cosine similarity between the first target feature data and the eighth target feature data, the ninth target feature data and the historical third sample feature data to obtain the sixth similarity; splice the fifth similarity and the sixth similarity to obtain the third splicing similarity, and use the cross entropy of the third splicing similarity as the third loss.

[0209] The cosine similarity between the first target feature data obtained in this round of training and the seventh target feature data obtained in this round of training is calculated to obtain the fifth similarity. The cosine similarity between the first target feature data obtained in this round of training and the eighth target feature data obtained in this round of training, the ninth target feature data obtained in this round of training, and the third historical sample feature data is calculated to obtain the sixth similarity, wherein the third historical feature data is the seventh target feature data, the eighth target feature data, and the ninth target feature data obtained in the preset number of previous trainings. That is, the similarity between the first target feature data and the eighth target feature data, the ninth target feature data, and the third historical sample feature data as a whole is calculated as the sixth similarity.

[0210] like Figure 7B As shown, the similarity is calculated based on the feature data generated by the student model, the features generated by the large teacher model, and the feature data obtained from previous training stored in memory bank2. Based on similarity Calculate the unsupervised loss l u,l, that is, the third loss is l u,l .

[0211] Step 714, calculate the cosine similarity between the third sample feature data obtained in this round and the historical third sample feature data as the seventh similarity; splice the fifth similarity, the sixth similarity and the seventh similarity to obtain a fourth splicing similarity, and use the cross entropy of the fourth splicing result as the third loss.

[0212] The third sample feature data obtained in this round includes the seventh target feature data, the eighth target feature data and the ninth target feature data obtained by the third model in this round of training; the historical third sample feature data includes the seventh target feature data, the eighth target feature data and the ninth target feature data obtained in the previous training of the preset number of times. In this embodiment, the seventh similarity is obtained by calculating the similarity between the seventh target feature data, the eighth target feature data and the ninth target feature data obtained in this round and the seventh target feature data, the eighth target feature data and the ninth target feature data obtained in the previous training of the preset number of times. The fifth similarity, the sixth similarity and the seventh similarity are spliced ​​to obtain the fourth splicing similarity, the fourth splicing similarity is normalized to obtain the normalized result corresponding to the fourth splicing similarity, the cross entropy of the normalized result corresponding to the fourth splicing similarity is calculated, and the cross entropy of the normalized result corresponding to the fourth splicing similarity is used as the third loss.

[0213] Alternatively, if Figure 7B In the process, the similarity is calculated based on the features generated by the large teacher model obtained in this round and the feature data obtained from previous training stored in memorybank2. Calculating Similarity and The relative entropy between them is used as the distillation loss l kd , that is, the third loss is the distillation loss l kd .

[0214] Step 716, taking the ratio of the maximum value of the cross entropy of the first splicing similarity to the actual entropy value as the first entropy value, taking the first entropy value as the first weight corresponding to the second loss, and taking the difference between 1 and the first entropy value as the second weight corresponding to the third loss.

[0215] According to step 706, the first splicing similarity is obtained, the ratio of the maximum value of the cross entropy of the first splicing similarity to the actual entropy value is used as the first entropy value, the first entropy value is used as the first weight corresponding to the second loss, and the difference between 1 and the first entropy value is used as the second weight corresponding to the third loss.

[0216] Step 718, taking the sum of the first loss, the product of the second loss and the first weight, and the product of the third loss and the second weight as the loss function, and the loss function is used to train the first model.

[0217] In a specific example, Figure 7B As shown, the loss function, that is, the total loss l, can be obtained by the following formula (5):

[0218] l=l s +α×l u,s +(1-α)×choice(l u,l ,l kd ) (5)

[0219] Among them, l s is the first loss, l u,s is the second loss, α is the first weight, then (1-α) is the second weight, choice(l u,l , l kd ) indicates that the third loss is selected as l according to the relationship between the average entropy value and the preset threshold u,l Or kd , if the average entropy value is greater than the preset threshold, then select l u,l As the third loss; if the average entropy value is less than or equal to the preset threshold, then select l kd As the third loss.

[0220] The model training method in this embodiment uses text sample data including the first sample, the second sample and the third sample as training sample data, and uses the second model and the third model to perform multi-level guidance and training on the first model, so that the convergence speed of the first model is faster and the accuracy of text recognition is higher.

[0221] The model training method involved in the embodiment of the present application mainly guides and trains the first model according to the second model and the third model during the training process, that is, the parameters of the first model will be continuously updated with the gradient during the training process until the convergence condition is met. Optionally, in the process of model training, in order to make the training accuracy of the first model higher, the second model can be momentum updated according to the first model, and the parameters of the third model remain unchanged. In one possible implementation, the parameters of the second model for the next round of training are determined based on the parameters of the first model for this round of training and the parameters of the second model for this round of training. Specifically, the update method of the second model can be shown in the following formula (6):

[0222] T i+1 =KS+(1-K)T i (6)

[0223] Among them, T iRepresents the second model parameter used in this round of training, T i+1 represents the second model parameter in the next round of training, S represents the first model parameter obtained in this round, and K is a constant.

[0224] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0225] Based on the same inventive concept, the embodiment of the present application also provides a model training device for implementing the model training method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more model training device embodiments provided below can refer to the limitations on the model training method above, and will not be repeated here.

[0226] In one embodiment, Figure 8 As shown, a model training device is provided, including: a sample data acquisition module 802, a first loss determination module 804, a second loss determination module 806, a third loss determination module 808 and a loss function determination module 810, wherein:

[0227] The sample data acquisition module 802 is used to acquire text sample data;

[0228] A first loss determination module 804, configured to input the text sample data into a first model to obtain first sample feature data, and determine a first loss according to the first sample feature data;

[0229] A second loss determination module 806, configured to input the text sample data into a second model to obtain second sample feature data, and determine a second loss according to the first sample feature data and the second sample feature data;

[0230] A third loss determination module 808 is used to input the text sample data into a third model to obtain third sample feature data, and determine, based on a preset condition, whether to obtain a third loss by the similarity between the first sample feature data and the third sample feature data, or to obtain a third loss by the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data;

[0231] The loss function determination module 810 is used to determine a loss function according to the first loss, the second loss and the third loss, and the loss function is used to train the first model.

[0232] In one embodiment, the text sample data includes a first sample, a second sample and a third sample, and the second sample is semantically similar to the first sample, and the third sample is semantically opposite to the first sample; the first loss determination module 804 is further used to:

[0233] Inputting the text sample data into the first model, and obtaining first target feature data according to the first sample;

[0234] Obtaining second target feature data according to the second sample;

[0235] Obtaining third target feature data according to the third sample;

[0236] The second loss determination module 806 is further configured to:

[0237] Inputting the text sample data into the second model, and obtaining fourth target feature data according to the first sample;

[0238] Obtaining fifth target characteristic data according to the second sample;

[0239] Obtaining sixth target characteristic data according to the third sample;

[0240] The third loss determination module 808 is further configured to:

[0241] Inputting the text sample data into the third model, and obtaining seventh target feature data according to the first sample;

[0242] Obtaining eighth target characteristic data according to the second sample;

[0243] According to the third sample, ninth target characteristic data is obtained.

[0244] In one embodiment, the first loss determination module 804 is further configured to:

[0245] Determining a first similarity according to the first target feature data and the second target feature data;

[0246] Determining a second similarity based on the first target feature data and the third target feature data;

[0247] The first loss is determined according to the first similarity and the second similarity.

[0248] In one embodiment, the model training device further includes a weight determination module, which is used to:

[0249] Determining a first entropy value according to the first similarity and the second similarity;

[0250] Determine a first weight corresponding to the second loss and a second weight corresponding to the third loss according to the first entropy value;

[0251] The loss function determination module 810 is further used to:

[0252] The loss function is determined according to the first loss, the second loss, the first weight, the third loss and the second weight.

[0253] In one embodiment, the third loss determination module 808 is further configured to:

[0254] Determine an average entropy value according to the first similarity and the second similarity;

[0255] If the average entropy value is greater than a preset threshold, determining that a third loss is obtained based on the similarity between the first sample feature data and the third sample feature data;

[0256] If the average entropy value is less than or equal to a preset threshold, it is determined that a third loss is obtained by using the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data.

[0257] In one embodiment, the second loss determination module 806 is further configured to:

[0258] determining a third similarity according to the first target feature data and the fourth target feature data;

[0259] Determining a fourth similarity according to the first target feature data and the fifth target feature data and the sixth target feature data;

[0260] The second loss is determined according to the third similarity and the fourth similarity.

[0261] In one embodiment, the third loss determination module 808 is further configured to:

[0262] determining a fifth similarity according to the first target feature data and the seventh target feature data;

[0263] Determining a sixth similarity according to the first target feature data and the eighth target feature data and the ninth target feature data;

[0264] The third loss is determined according to the fifth similarity and the sixth similarity.

[0265] In one embodiment, the third loss determination module 808 is further configured to:

[0266] Determine a seventh similarity based on the third sample feature data obtained in this round and the historical third sample feature data;

[0267] The third loss is determined according to the seventh similarity and the fifth and sixth similarities.

[0268] Each module in the above-mentioned model training device can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.

[0269] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig. 9 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store sample feature data. 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 model training method is implemented.

[0270] Those skilled in the art will understand that Fig. 9 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0271] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above-mentioned model training methods when executing the computer program.

[0272] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned model training methods are implemented.

[0273] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above-mentioned model training methods when executed by a processor.

[0274] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.

[0275] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0276] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A model training method, characterized in that: The method comprises: Get text sample data; Inputting the text sample data into a first model to obtain first sample feature data, calculating the similarity between the first sample feature data, and determining a first loss based on the similarity between the first sample feature data; Inputting the text sample data into a second model to obtain second sample feature data, and determining a second loss according to the first sample feature data and the second sample feature data; Input the text sample data into a third model to obtain third sample feature data, and determine, based on a preset condition, whether to obtain a third loss by using the similarity between the first sample feature data and the third sample feature data, or to obtain a third loss by using the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data; A loss function is determined according to the first loss, the second loss and the third loss, and the loss function is used to train the first model.

2. The method according to claim 1, characterized in that The text sample data includes a first sample, a second sample and a third sample, and the second sample is semantically similar to the first sample, and the third sample is semantically opposite to the first sample; the text sample data is input into the first model to obtain the first sample feature data, including: Inputting the text sample data into the first model, and obtaining first target feature data according to the first sample; Obtaining second target feature data according to the second sample; Obtaining third target feature data according to the third sample; The step of inputting the text sample data into the second model to obtain second sample feature data includes: Inputting the text sample data into the second model, and obtaining fourth target feature data according to the first sample; Obtaining fifth target characteristic data according to the second sample; Obtaining sixth target characteristic data according to the third sample; The step of inputting the text sample data into a third model to obtain third sample feature data comprises: Inputting the text sample data into the third model, and obtaining seventh target feature data according to the first sample; Obtaining eighth target characteristic data according to the second sample; According to the third sample, ninth target characteristic data is obtained.

3. The method according to claim 2, characterized in that The calculating the similarity between the first sample feature data and determining the first loss based on the similarity between the first sample feature data includes: Determining a first similarity according to the first target feature data and the second target feature data; Determining a second similarity based on the first target feature data and the third target feature data; The first loss is determined according to the first similarity and the second similarity.

4. The method according to claim 3, characterized in that The method further comprises: Determining a first entropy value according to the first similarity and the second similarity; Determine a first weight corresponding to the second loss and a second weight corresponding to the third loss according to the first entropy value; The determining of a loss function according to the first loss, the second loss and the third loss comprises: The loss function is determined according to the first loss, the second loss, the first weight, the third loss and the second weight.

5. The method according to claim 3, characterized in that: The determining, based on a preset condition, that a third loss is obtained by using a similarity between the first sample feature data and the third sample feature data, or that a third loss is obtained by using a similarity between the third sample feature data and a similarity between the first sample feature data and the third sample feature data, comprises: Determine an average entropy value according to the first similarity and the second similarity; If the average entropy value is greater than a preset threshold, determining that a third loss is obtained based on the similarity between the first sample feature data and the third sample feature data; If the average entropy value is less than or equal to a preset threshold, it is determined that a third loss is obtained by using the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data.

6. The method according to claim 2, characterized in that Determining a second loss according to the first sample feature data and the second sample feature data includes: determining a third similarity according to the first target feature data and the fourth target feature data; Determining a fourth similarity according to the first target feature data and the fifth target feature data and the sixth target feature data; The second loss is determined according to the third similarity and the fourth similarity.

7. The method according to claim 2, characterized in that The obtaining a third loss based on the similarity between the first sample feature data and the third sample feature data includes: determining a fifth similarity according to the first target feature data and the seventh target feature data; Determining a sixth similarity according to the first target feature data and the eighth target feature data and the ninth target feature data; The third loss is determined according to the fifth similarity and the sixth similarity.

8. The method according to claim 7, characterized in that The obtaining of the third loss based on the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data includes: Determine a seventh similarity based on the third sample feature data obtained in this round and the historical third sample feature data; The third loss is determined according to the seventh similarity and the fifth and sixth similarities.

9. A model training device, characterized in that: The device comprises: A sample data acquisition module is used to acquire text sample data; A first loss determination module, configured to input the text sample data into a first model to obtain first sample feature data, calculate the similarity between the first sample feature data, and determine a first loss based on the similarity between the first sample feature data; A second loss determination module, configured to input the text sample data into a second model to obtain second sample feature data, and determine a second loss according to the first sample feature data and the second sample feature data; A third loss determination module is used to input the text sample data into a third model to obtain third sample feature data, and based on a preset condition, determine whether to obtain a third loss by the similarity between the first sample feature data and the third sample feature data, or to obtain a third loss by the similarity between the third sample feature data and the similarity between the first sample feature data and the third sample feature data; A loss function determination module is used to determine a loss function based on the first loss, the second loss and the third loss, and the loss function is used to train the first model.

10. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 8 are implemented.

11. 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 method according to any one of claims 1 to 8 are implemented.

12. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.