Model training method, classification method and related equipment

By predicting the probability values ​​and losses of multiple elements during the large model training process, the time-consuming problem of text classification is solved, and efficient single-shot inference and accurate classification results are achieved.

CN120687925APending Publication Date: 2025-09-23MASHANG CONSUMER FINANCE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510377075.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-25
Publication Date
2025-09-23

AI Technical Summary

Technical Problem

Existing technologies take a long time to perform text classification using large models, especially when the output sequence includes multiple elements, requiring multiple inferences and decoding, resulting in low efficiency.

Method used

By predicting the first probability values ​​of multiple first preset elements and determining the loss based on these probability values ​​and the label vectors of the training samples, the model is trained so that the model predicts the probability values ​​of all elements at the first time step and directly calculates the loss without multiple inferences and decoding.

Benefits of technology

It shortens the time consumption of model training and classification process, improves efficiency, avoids the "hallucination" output caused by multiple inferences, and improves the accuracy of classification results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120687925A_ABST
    Figure CN120687925A_ABST
Patent Text Reader

Abstract

The invention discloses a model training method, a classification method and related equipment. The training method comprises: based on features of a training sample, predicting a first probability value corresponding to each first preset element in a plurality of first preset elements, the plurality of first preset elements including elements corresponding to a real classification category of the training sample; determining a first loss based on a first probability value corresponding to each first preset element and a tag vector corresponding to the training sample, the tag vector being used for indicating elements corresponding to the real classification category, and the number of the elements corresponding to the real classification category being greater than 1; and training the model based on the first loss.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and specifically to a model training method, a classification method, and related equipment. Background Art

[0002] In the field of natural language processing, classification is a crucial task, and increasingly, users are leveraging large models to handle it. However, when using large models to classify text, the output is a one-token-by-one-token autoregressive process. This means that each time the model generates a token, it uses the generated token as input to predict the next token, and only after a stopping condition is met and all tokens are output can a complete classification result be obtained. This is very time-consuming.

[0003] Therefore, how to shorten the time spent in classification is an urgent problem to be solved. Summary of the Invention

[0004] This application provides a model training method, a classification method and related equipment, which can shorten the time spent in classification.

[0005] In a first aspect, the present application provides a model training method, the method comprising:

[0006] Predicting a first probability value corresponding to each of a plurality of first preset elements based on the characteristics of the training sample, wherein the plurality of first preset elements include elements corresponding to the true classification category of the training sample;

[0007] Determining a first loss based on a first probability value corresponding to each first preset element and a label vector corresponding to the training sample, wherein the label vector is used to indicate an element corresponding to a true classification category, and the number of elements corresponding to the true classification category is greater than 1;

[0008] The model is trained based on the first loss.

[0009] In a second aspect, the present application provides a classification method, the method comprising:

[0010] Predicting, by means of a model, a second probability value corresponding to each of the plurality of first preset elements based on features of the first text, wherein the model is trained using the model training method of the first aspect;

[0011] Based on the second probability value corresponding to each first preset element, a fourth classification category corresponding to the first text is determined.

[0012] In a third aspect, the present application provides a model training device, the device comprising: a first acquisition unit and a first processing unit;

[0013] A first acquisition unit, configured to acquire a training sample;

[0014] A first processing unit is configured to predict, based on features of a training sample, a first probability value corresponding to each of a plurality of first preset elements, wherein the plurality of first preset elements include elements corresponding to a true classification category of the training sample; determine a first loss based on the first probability value corresponding to each first preset element and a label vector corresponding to the training sample, wherein the label vector is used to indicate an element corresponding to a true classification category, and the number of elements corresponding to the true classification category is greater than 1; and train the model based on the first loss.

[0015] In a fourth aspect, the present application provides a classification device, the device comprising: a second acquisition unit and a second processing unit;

[0016] A second acquiring unit, configured to acquire the first text;

[0017] The second processing unit is used to predict a second probability value corresponding to each of a plurality of first preset elements based on features of the first text through a model, wherein the model is trained using the model training method of the first aspect; and determine a fourth classification category corresponding to the first text based on the second probability value corresponding to each first preset element.

[0018] In a fifth aspect, the present application provides an electronic device comprising: a processor and a memory, the processor being connected to the memory, the memory being used to store computer programs, and the processor being used to execute the computer programs stored in the memory, so that the electronic device performs the method of the first aspect or the second aspect.

[0019] In a sixth aspect, the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the method of the first aspect or the second aspect is performed.

[0020] In a seventh aspect, the present application provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and when the computer program is executed by a processor, performs the method of the first aspect or the second aspect.

[0021] The implementation of this application has the following beneficial effects:

[0022] The present application trains a model, specifically: first, based on the characteristics of the training sample, predict the first probability value corresponding to each first preset element in multiple first preset elements, wherein the multiple first preset elements include elements corresponding to the real classification category to which the training sample belongs; then, based on the first probability value corresponding to each first preset element and the label vector corresponding to the training sample, determine the first loss, wherein the label vector is used to indicate the element corresponding to the real classification category to which the training sample belongs, and the number of elements corresponding to the real classification category is greater than 1. For example, for a single-label classification scenario, that is, the number of real classification categories of the training sample is one at this time, then it is necessary to ensure that the number of elements corresponding to the real classification category is greater than 1, and for a multi-label classification scenario, that is, the number of real classification categories of the training sample is multiple at this time. , then it is necessary to ensure that the total number of elements corresponding to multiple true classification categories is greater than 1, and the number of elements corresponding to each true classification category can be greater than or equal to 1; then based on the first loss, the model is trained, that is, during training, whether it is single-label classification or multi-label classification, or whether the output sequence includes one or more elements, the model only needs to infer once, that is, the model predicts the first probability value corresponding to each first preset element in multiple first preset elements at the first time step, and then directly calculates the first loss based on the first probability value corresponding to each first preset element predicted at the first time step and the label vector of the training sample, without continuing to predict the probability value corresponding to each first preset element at the second, third or even more time steps. In the case where there are multiple elements in the output sequence, according to the traditional method of one token by one token model in the background technology, multiple inferences are required, that is, predictions of multiple time steps are required, and the probability distribution at each time step is output, that is, the probability value corresponding to each first preset element at each time step, and then the loss is calculated based on the probability value corresponding to each first preset element at each time step and the true label corresponding to the output result of each time step. This takes a lot of time. Compared with this, the present application shortens the time and is more efficient, because no matter whether the output sequence consists of one or more elements, the solution of the present application only needs to predict the first probability value corresponding to each first preset element once, and then calculate the loss.

[0023] Furthermore, after the model is trained, the model can be used to predict the second probability value corresponding to each of the multiple first preset elements based on the features of the first text. The second probability value is similar to the first probability value. Then, based on the second probability value corresponding to each first preset element, the fourth classification category corresponding to the first text is determined. That is to say, no matter whether the number of fourth classification categories is one or more, or whether the output sequence corresponding to the first text, that is, the elements in the classification result, is one or more, the model of the present application only needs to be inferred once, that is, the second probability value corresponding to each first preset element is predicted at the first time step, and then the fourth classification category corresponding to the first text can be directly determined based on the second probability value of each first preset element at the first time step, so that the complete output sequence can be obtained, and there is no need to continue to predict the probability value corresponding to each first preset element at the second, third or even more time steps; and similarly, for the case where there are multiple elements in the output sequence, the model one token by one in the background technology The traditional method of tokenization requires multiple inferences, that is, corresponding to multiple time steps, and outputting the probability distribution corresponding to each time step, that is, the probability value corresponding to the first preset element at each time step, and then determining the output of each time step based on the probability distribution corresponding to each time step, until the output of the last time step, to obtain a complete output sequence, which is time-consuming. Compared with this, the present application also shortens the time and is more efficient, because no matter whether the output sequence consists of one or more elements, the solution of the present application only needs to predict the second probability value corresponding to each first preset element once, and can directly obtain the fourth classification category corresponding to the first text. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0025] Figure 1 A schematic diagram of obtaining a complete output sequence based on a first model provided in an embodiment of the present application;

[0026] Figure 2 A flowchart of a model training method provided in an embodiment of the present application;

[0027] Figure 3 A schematic diagram of obtaining a complete output sequence based on a model provided in an embodiment of the present application;

[0028] Figure 4 A flow chart of a classification method provided in an embodiment of the present application;

[0029] Figure 5 A schematic diagram of a classification system provided in an embodiment of the present application;

[0030] Figure 6 A schematic diagram of a model training system provided in an embodiment of the present application;

[0031] Figure 7 A block diagram of the functional units of a model training device provided in an embodiment of the present application;

[0032] Figure 8 A block diagram of the functional units of a classification device provided in an embodiment of the present application;

[0033] Figure 9 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0034] The following will be combined with the accompanying drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0035] The terms "first," "second," "third," and "fourth," etc., in the specification, claims, and drawings of this application are used to distinguish between different objects, not to describe a particular order. In addition, the terms "including," "having," and any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus comprising a series of steps or elements is not limited to the listed steps or elements, but may optionally include steps or elements not listed, or may optionally include other steps or elements inherent to the process, method, product, or apparatus.

[0036] References herein to "embodiments" mean that a particular feature, result, or characteristic described in connection with the embodiments may be included in at least one embodiment of the present application. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor does it constitute an independent or alternative embodiment that is mutually exclusive of other embodiments. It is understood, both explicitly and implicitly, by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0037] First, the relevant terms and related technologies involved in the embodiments of this application are explained:

[0038] Multiple first preset elements: In the embodiments of the present application, it can be understood as including various elements in the preset vocabulary. In the embodiments below, various elements in the vocabulary and multiple first preset elements can refer to the same meaning and do not need to be specially distinguished; and in principle, the multiple first preset elements used in the training phase are the same as the multiple first preset elements used in the model application reasoning phase. It should also be noted that the descriptions of elements, tokens, word units, etc. involved in the embodiments of the present application can be understood as synonyms, used to refer to the same content, and are distinguished by different alignments.

[0039] First, a training method for a first model is introduced. The first model trained by the training method is used to classify text, such as single-label classification (such as binary classification, multi-classification, etc.) and multi-label classification. The first model can be a model based on the Transformer architecture, such as the QWen model (referred to as the Decoder-Only architecture) mainly composed of a decoder, or the Transformer model (referred to as the Encoder-Decoder architecture) mainly composed of an encoder and a decoder. This application does not limit this. The two are similar in training methods, as follows:

[0040] Get the first training sample; then input the first training sample into the first model to obtain the first eigenvector corresponding to each element in the first training sample. At this time, the first eigenvector corresponding to each element contains the context information of the first training sample; then at the first time step, based on the first eigenvector corresponding to each element in the first training sample, determine the probability distribution corresponding to the first time step (that is, the probability corresponding to each element in the vocabulary at the first time step); then based on the probability distribution corresponding to the first time step, decode to obtain the first element of the output sequence. For example, generally speaking, the element with the largest probability among the elements in the vocabulary at the first time step can be taken as the first; then based on the first eigenvector corresponding to each element in the first training sample and the first element of the output sequence, determine the probability distribution corresponding to the second time step (that is, the probability of each element in the vocabulary at the second time step); then based on the probability distribution corresponding to the second time step, decode to obtain the second element of the output sequence. Similarly, gradually decode to obtain other elements of the output sequence until the stopping condition (such as the end mark) is reached. <end>), the complete output sequence is obtained.

[0041] Furthermore, when determining the loss, the cross entropy loss can be calculated by the probability distribution corresponding to each time step to obtain the loss corresponding to the first training sample, as shown in the following formula (1):

[0042]

[0043] Where L1 is the loss corresponding to the first training sample, T is the number of time steps or the length of the output sequence corresponding to the first training sample (i.e., the number of elements in the output sequence), and V is the length of the vocabulary (i.e., the number of elements in the vocabulary). is the true label or true value corresponding to the probability that the kth element in the output sequence belongs to the i-th element in the vocabulary (if the kth element in the output sequence belongs to the i-th element in the vocabulary, it is 1, otherwise it is 0, which means that each element of the output sequence has a corresponding true label. The final evaluation needs to determine whether each token output by the model is accurate, that is, it belongs to a generative model). is the probability that the kth element in the output sequence belongs to the ith element in the vocabulary. After obtaining the loss corresponding to each first training sample, the first model can be iteratively trained based on the loss until the first model converges to obtain a trained first model.

[0044] Furthermore, during the application reasoning stage of the first model, the second text is obtained, and then the second text is input into the trained first model. First, the output of the first time step is obtained by decoding based on the probability distribution corresponding to the first time step (for example, the output with the largest probability is selected as the output of the first time step), and then the output of the first time step is used as the input of the second time step. Then, the output of the second time step is determined based on the probability distribution corresponding to the second time step. The same process is repeated until the stopping condition is reached and the generation is terminated, and a complete output sequence corresponding to the second text is obtained, that is, all classification categories to which the second text belongs.

[0045] For easier understanding, see Figure 1 , Figure 1 This is a schematic diagram of obtaining a complete output sequence based on the first model provided in an embodiment of the present application. Figure 1 As shown, after obtaining the first training sample, that is, Input, the first training sample is vectorized to obtain Embeddings corresponding to the first training sample; then, based on the first model, feature processing is performed on the Embeddings corresponding to the first training sample (mainly including attention processing. When the architecture of the first model is different, there will be other processing before and after the attention processing, such as the normalization layer Norm Layer, the fully connected layer Fully connected layer, etc., specifically refer to the Encoder-Decoder architecture of the Transformer model or the Decoder-Only architecture of the QWen model, which will not be elaborated here), and the feature vector of each element in the first training sample is obtained. At this time, the feature vector of each element in the first training sample contains the context information of the first training sample; then at the t1 time step, the first model is based on the feature vector of each element of the first training sample and the starting flag of the input <start>, and obtain the probability distribution corresponding to the t1th time step, that is, each element in the vocabulary at the t1th time step ( Figure 1 Assume that there are V probabilities, such as P i t1 It represents the probability that the output at the t1th time step belongs to the i-th element in the vocabulary; then the output of the t1th time step is decoded based on the probability distribution corresponding to the t1th time step, that is, "element 1"; then the first model obtains the probability distribution corresponding to the t2th time step based on the feature vector of each element of the first training sample and "element 1", and then the output of the t2th time step, that is, "element 2", is obtained in the same way, and the output of the t3th time step, that is, "element 3", the output of the t4th time step, that is, "element 4", ..., the output of the tnth time step, which is the end mark, is obtained in the same way. <end>, no longer described here one by one, and then the elements in the complete output sequence corresponding to the first training sample include element 1, element 2, element 3 and element 4.

[0046] Furthermore, when calculating the loss, taking the t1th time step as an example, the label vector corresponding to the output of the t1th time step is obtained by one-hot encoding according to the vocabulary dimension, that is, Figure 1 shown (where 1≤i≤V) represents the true label or true value corresponding to the probability that the output of the t1th time step belongs to the i-th element in the vocabulary (if the output of the t1th time step belongs to the i-th element in the vocabulary, it is 1, otherwise it is 0). It can be seen that the 5th element in the V preset elements is encoded as 1, indicating that the true value is 1, and the remaining elements are encoded as 0, indicating that the true value is 0; then, based on the true label or true value corresponding to the probability that the output of the t1th time step belongs to each element in the vocabulary, and the probability that the output of the t1th time step belongs to each element in the vocabulary (V at this time), the loss L(t1) corresponding to the t1th time step can be obtained, that is, in, represents the probability that the output of the t1th time step belongs to the i-th element in the vocabulary, and log() represents the logarithmic function; then, the losses L(t2), ..., L(tn) corresponding to each time step are calculated in the same way, which are not explained one by one here. Then, based on the losses corresponding to n time steps, the loss L1 corresponding to the first training sample is obtained, and at this time L1 = [L(t1) + L(t2) + ... + L(tn)] / n.

[0047] It should be explained that in the above-mentioned training method and application reasoning stage, when it is single-label classification, the output sequence includes only one classification category. When it is multi-label classification, the output sequence includes multiple classification categories. Each classification category consists of one or more elements, so the output sequence includes one or more elements.

[0048] If the output sequence contains only one element, the model only needs to infer, decode, and output once to get the complete output sequence. However, when the output sequence contains multiple elements (whether it is multi-label classification or single-label classification), according to the above Figure 1 Each element in the output sequence obtained by the embodiment is obtained based on the elements that have been generated in the output sequence, that is, the elements in the output sequence are not independent but are related to each other. If the generated elements are incorrect, it will affect the accuracy of the elements in the subsequent output, and the model produces a "hallucination" output, which in turn affects the accuracy of the classification results. Especially for multi-label classification, it can be understood that the elements of each classification category in the output sequence are not independent but are related to each other, that is, if the prediction of the elements in the generated classification category is incorrect, it will affect the accuracy of the elements in the classification category in the subsequent output, and the "hallucination" output reduces the accuracy of the classification.

[0049] In addition, since each element in the output sequence is obtained by autoregressive step-by-step decoding, whether it is single-label classification or multi-label classification, for the case where the output sequence includes multiple elements (such as the classification category of the single-label classification output includes multiple elements, or the elements of multiple classification categories of the multi-label classification output), due to the Figure 1 In this way, the first model generates an element of the output sequence each time it performs inference, decoding, and output. The model needs to perform inference, decoding, and output multiple times to obtain a complete output sequence, that is, all the classification categories to which the training sample belongs. This takes a lot of time and is inefficient.

[0050] Therefore, in the field of classification, whether it is single-label or multi-label classification, for the situation where the output sequence includes multiple elements, that is, the model needs to perform multiple inferences, decoding, and outputs to obtain a complete output sequence, in order to further optimize the problems of "hallucination" and long time consumption, the embodiment of the present application provides a model training method, which is as follows:

[0051] See Figure 2 , Figure 2 A flow chart of a model training method provided in an embodiment of the present application. The method is applied to a model training device, and includes but is not limited to the following steps S201-S203:

[0052] S201: Predict a first probability value corresponding to each first preset element in a plurality of first preset elements based on characteristics of a training sample.

[0053] In an embodiment of the present application, the training sample can be encapsulated in the form of a prompt word Prompt. At this time, the content of Prompt can include not only the training sample (also called data data, which can be understood as text to be classified in the classification field), but also the role definition of the model (such as "You are a classification expert and are good at classifying data data"), task definition (such as "Your task is to learn data data and classify data data"), task requirements (such as "The classification category you obtain by classifying data data must come from the existing classification category in the category library"), etc., to enrich the content of Prompt and improve the capabilities of the model.

[0054] In an optional embodiment, in addition to the data data used for classification, the training sample may also include at least one first classification category corresponding to the training sample (referring to the classification category to be classified, also known as the label set, which at least includes the actual classification category to which the training sample belongs, so as to train the model to predict the classification category to which the training sample belongs from at least one first classification category). Then the task requirement may be "the classification category obtained by classifying the data data must be a classification category from at least one first classification category". In this way, when classifying, the model only needs to judge the classification category to which the training sample belongs from at least one first classification category corresponding to the training sample (data data in this case) in the Prompt. The number of first classification categories is much smaller than the number of classification categories already in the category library, so that the number of training samples required for training is also smaller than that based on the classification categories already in the category library, and the model training is more efficient.

[0055] Of course, optionally, the training sample may not include at least one first classification category. In this case, the model is trained based on the classification categories already in the category library (which also needs to include at least the real classification category to which the training sample belongs). That is, the training model predicts the classification category to which the training sample belongs from the classification categories already in the category library. In this case, since the number of classification categories in the category library is greater than the number of at least one first classification category corresponding to the training sample, the number of training samples required is also greater, and the model training efficiency is slower. This application does not limit these two methods.

[0056] It should also be noted that the examples given in this embodiment are for illustrative purposes only and are not intended to be limiting. To facilitate understanding, the following explanation of the Prompt is provided with reference to specific examples, as follows:

[0057]

[0058] It should be noted that the prompt is only an example and will be adjusted accordingly based on actual needs in specific applications. This application does not limit it.

[0059] In addition, the number of training samples can be multiple, and the embodiment of this application mainly uses one as an example for explanation. Before training, it is necessary to first obtain all classification categories corresponding to the training samples (that is, the classification categories to be classified must at least include the real classification categories to which the training samples belong). For example, it can be the classification categories in the above-mentioned category library, or it can also be at least one first classification category corresponding to the training samples in the above-mentioned Prompt, which is not limited in this application.

[0060] Therefore, taking the example of obtaining all classification categories corresponding to the training sample as at least one first classification category corresponding to the training sample, the element corresponding to each first classification category includes the r-th element of all elements corresponding to each first classification category, and the r-th element corresponding to each first classification category is different. In the case where there are multiple first classification categories, multiple first classification categories can be determined based on the existing multiple second classification categories. Specifically:

[0061] Acquire multiple second classification categories corresponding to the training samples, the multiple second classification categories at least including the true classification category to which the training samples belong; then group the multiple second classification categories based on the rth element of all elements corresponding to each second classification category to obtain a first classification category group, wherein the rth element of all elements corresponding to each classification category in the first classification category group is the same, and the number of first classification category groups can be one or more (this application mainly explains one as an example), for example, when the number of first classification category groups is multiple, the rth elements corresponding to the classification categories in any two first classification category groups are different.

[0062] Then, based on each classification category in the first classification category group, a third classification category is determined from multiple second classification categories, where the third classification category is different from each classification category. That is, the category in the multiple second classification categories that is different from the classification category in the first classification category group is used as the third classification category. In this case, the number of third classification categories can be one or more, and this application mainly uses one as an example for explanation. Then, based on the third classification category and the first classification category group, multiple first classification categories corresponding to the training samples are determined, specifically:

[0063] Semantic information is extracted for each classification category in the first classification category group to obtain semantic information corresponding to each classification category; then, based on the semantic information corresponding to each classification category and the rth element among all elements corresponding to the third classification category, the elements corresponding to the classification categories in the first classification category group are adjusted to obtain a second classification category group, wherein the rth element among all elements corresponding to each classification category in the second classification category group is different and different from the rth element corresponding to the third classification category, and the semantic information of each classification category in the second classification category group does not change before and after the adjustment (for example, the semantic similarity before and after the adjustment is greater than a first threshold, and this application does not limit the value of the first threshold).

[0064] Then, based on the third classification category and the classification categories in the second classification category group, multiple first classification categories corresponding to the training samples are obtained. For example, part or all of the classification categories in the third classification category and the second classification category group are determined as multiple first classification categories corresponding to the training samples. At this time, the rth element corresponding to each first classification category obtained is different.

[0065] It should be noted that in the embodiments of the present application, the rth element among all elements corresponding to the classification category (whether it is the real classification category, the first classification category, the second classification category, the third classification category, etc. in the embodiments of the present application, and other classification categories involved in the embodiments below, which are not listed here one by one) can be the first element, the second element or the third element among all elements corresponding to the classification category, etc. This application does not limit the value of r, and the embodiments of the present application are mainly explained using r=1 as an example.

[0066] Illustratively, when r=1, the elements of the classification categories in the first classification category group can be transposed, replaced with synonyms, deformed, or represented using specific tags, without changing the semantics of the classification categories in the first classification category group and without repeating the first element corresponding to the third classification category. For example, assuming that the classification categories in the first classification category group include "buy toothpaste" and "buy oranges", transposition can be performed to obtain "toothpaste purchase" and "orange purchase"; synonym replacement can also be performed, such as obtaining "purchase toothpaste" and "purchase oranges", or deformation can be performed, such as obtaining "purchase toothpaste" and "purchase oranges", etc. This application is not limited to this. At this time, the first element corresponding to the adjusted classification category is different.

[0067] Similarly, when there are multiple training samples, all second classification categories corresponding to the multiple training samples can be processed simultaneously in the above manner so that the rth elements corresponding to all first classification categories corresponding to the obtained multiple training samples are different. This will not be repeated here. For example, assuming that multiple training samples include [training sample 1, training sample 2, training sample 3], the first classification categories corresponding to training sample 1 include [A1, A2], the first classification categories corresponding to training sample 2 include [B1, B2, B3], and the first classification categories corresponding to training sample 3 include [C1, C2]. Then the first elements of all first classification categories corresponding to the multiple training samples, namely [A1, A2, B1, B2, B3, C1, C2], are classified to obtain a first classification category group. Assume that there are two first classification category groups, [A2, B3] and [A1, C1]. At this time, the rth element corresponding to each classification category in B1, B2 and C2 is different from the rth elements corresponding to other classification categories in all second classification categories corresponding to the multiple training samples, but the rth elements corresponding to A2 and B3 are the same, the rth elements corresponding to A1 and C1 are the same, but the rth elements corresponding to A2 and A1 are different.

[0068] Then, based on the semantic information of each classification category in the first first classification category group [A2, B3] and the second first classification category group [A1, C1], and the rth element corresponding to each classification category in B1, B2, and C2, the elements of each classification category in the first first classification category group [A2, B3] and the second first classification category group [A1, C1] are adjusted respectively. Assume that the corresponding two second classification category groups are [A2', B3']. and [A1', C1'], at this time the semantics of A2' and A2, the semantics of B3' and B3, the semantics of A1' and A1, and the semantics of C1' and C1 have not changed (for example, the semantic similarity is greater than the first threshold), and the r-th element corresponding to each classification category in A2', B3', A1', C1', B1, B2 and C2 is different; then A2', B3', A1', C1', B1, B2 and C2 are taken as all the first classification categories corresponding to multiple training samples.

[0069] It should be noted that, in principle, the vocabulary or multiple first preset elements in the embodiment need to include elements corresponding to each first classification category, such as all elements corresponding to each first classification category. Based on the embodiment of the present application, the vocabulary or multiple first preset elements can also be limited to include at least the rth element of all elements corresponding to each first classification category. However, since there is a situation where the elements of the classification category in the first classification category group corresponding to the training sample are adjusted, if the rth element corresponding to each first classification category obtained after the adjustment does not fall into the vocabulary or multiple first preset elements, the vocabulary or multiple first preset elements can be expanded and updated based on the rth element corresponding to each first classification category after the adjustment to achieve data enhancement.

[0070] Of course, if all the classification categories corresponding to the training samples are obtained as classification categories in the category library, that is, all the classification categories corresponding to all the training samples are classification categories in the category library, then the classification categories in the category library can be directly processed similarly in the same way as the above-mentioned processing method for the second classification category to obtain the processed category library. At this time, the rth element corresponding to each classification category in the processed category library is also different, which will not be repeated here. Then, in subsequent training, each training sample is trained based on the processed category library, so that the model predicts the classification category to which the training sample belongs from the classification category in the processed category library.

[0071] In addition, in an optional embodiment, the index index corresponding to each first preset element in the multiple first preset elements is also predetermined, and the index represents the position of each first preset element in the multiple first preset elements; or the index corresponding to each element in the vocabulary is determined, and the index represents the position of each element in the vocabulary. For example, assuming that the length of the vocabulary is 150,000, the index corresponding to element A is 100444, indicating that the position of element A in the vocabulary is 100444th. Therefore, since the multiple first preset elements or the vocabulary at least include elements corresponding to the first classification category corresponding to the training sample (such as all elements or the rth element corresponding to the first classification category), the index corresponding to the element corresponding to the first classification category can be determined based on the position of the element corresponding to the first classification category in the multiple first preset elements. It should be noted that the following embodiments are mainly described by taking multiple first preset elements as an example.

[0072] Furthermore, since in the above embodiment, after the first classification category finally corresponding to all training samples is determined, the r-th element corresponding to each first classification category is different, it means that the multiple first classification categories corresponding to the training samples can be directly distinguished based on their respective corresponding r-th elements. During subsequent model training, each first classification category can be directly represented based on the r-th element corresponding to each first classification category.

[0073] Therefore, in an embodiment of the present application, a mapping relationship between elements and classification categories can be constructed in advance. For example, element A corresponds to classification category 1, element B corresponds to classification category 2..., and then the classification category corresponding to the element can be determined directly from the mapping relationship based on one element. This is simple and efficient and will not be elaborated in detail here. See below for details.

[0074] Optionally, since the index corresponding to the element corresponding to each first classification category can be determined in the above embodiment, a mapping relationship between the index corresponding to the element and the classification category can also be constructed in advance. For example, (100446, tense) indicates that the classification category is "tense", and the index corresponding to the rth (r=1) element, namely "tight", is 100446. This application does not limit these two methods.

[0075] Furthermore, in an embodiment of the present application, the features of the training sample may include a feature vector corresponding to each element in the training sample, and the feature vector corresponding to each element includes contextual information of the training sample. Thus, based on the feature vector corresponding to each element in the training sample, a first probability value corresponding to each first preset element in a plurality of first preset elements can be predicted. Exemplarily, the training sample is vectorized to obtain a second feature vector corresponding to each element in the training sample; attention processing is then performed on the second feature vector corresponding to each element in the training sample to obtain a feature vector corresponding to each element in the training sample; and prediction is then performed based on the feature vector corresponding to each element in the training sample to obtain a first probability value for each first preset element in a plurality of first preset elements. For example, the feature vector corresponding to each element in the training sample can be directly linearly mapped according to the dimensions of the plurality of first preset elements to obtain the first probability value; or alternatively, after mapping the feature vector corresponding to each element in the training sample according to the dimensions of the plurality of first preset elements to obtain the logical value of each first preset element, the logical value of each first preset element is activated, such as using a sigmoid function, to obtain the first probability value for each first preset element. This application is not limited to these two methods.

[0076] It should be noted that if the structure of the model is different, such as the Encoder-Decoder architecture of the Transformer model and the Decoder-Only architecture of the QWen model, there will be some subtle differences in the way of obtaining the feature vector of each element of the context information of the training sample based on the training sample. This application mainly takes the Decoder-Only architecture of the QWen model as an example to explain step S202, as follows:

[0077] The QWen model mainly includes an embedding layer, a hidden layer, a feature extraction layer, a normalization layer, an output layer, etc., and the number of each layer is not limited. After obtaining the training sample, the training sample can be converted into an index corresponding to a plurality of first preset elements based on the tokenizer to obtain an input sequence corresponding to the training sample; the input sequence is then input into the embedding layer to obtain an embedding vector corresponding to the training sample; the embedding vector is then input into the hidden layer to obtain a hidden state corresponding to the training sample; the hidden state corresponding to the training sample is then input into the feature extraction layer, specifically: after normalization, attention processing is performed, and then residual processing is performed with the input of the feature extraction layer to obtain a feature vector 1 corresponding to each element in the training sample, and then the feature vector 1 is normalized and input into the multilayer perceptron to obtain a feature vector 2 corresponding to each element in the training sample, and then the feature vector 1 corresponding to each element and the feature vector 2 corresponding to each element are subjected to residual processing and input into the normalization layer to obtain a feature vector corresponding to each element in the training sample. At this time, the feature vector corresponding to each element includes the context information of the training sample.

[0078] Furthermore, the feature vector corresponding to each element can be directly mapped to obtain the first probability value corresponding to each first preset element; optionally, the feature vector corresponding to each element can be first mapped to obtain the logical value logit corresponding to each first preset element, and then the logical value logit of each first preset element can be activated, such as using the sig moid function, to obtain the first probability value corresponding to each first preset element. In other words, the first probability value of each first preset element can be the logical value corresponding to each first preset element before activation, or the probability corresponding to each first preset element after activation, which is not limited in this application.

[0079] S202. Determine a first loss based on a first probability value corresponding to each first preset element and a label vector corresponding to the training sample, wherein the label vector is used to indicate an element corresponding to a true classification category, and the number of elements corresponding to the true classification category is greater than 1.

[0080] In an embodiment of the present application, multiple first preset elements include elements corresponding to the real classification categories of the training samples, and the number of elements corresponding to the real classification categories is greater than 1. This is mainly a limitation description for two scenarios. One is that when it is a single-label classification scenario, the number of real classification categories of the training samples is one, then the number of elements corresponding to this real classification category needs to be greater than 1; the other is that when it is a multi-label classification scenario, the number of real classification categories of the training samples is multiple, then the total number of elements corresponding to multiple real classifications needs to be greater than 1, and the number of elements corresponding to each real classification category can be one or more.

[0081] Before training, it is necessary to first determine the label vector corresponding to the training sample. Since the mapping relationship between the elements (or the indexes corresponding to the elements) and the classification categories is pre-established in the above embodiment, and in this application, the elements corresponding to the real classification categories include the rth element of all elements corresponding to the real classification categories, it should be explained that if it is a multi-label classification, then the elements corresponding to each real classification category should include the rth element of all elements corresponding to each real classification category. Therefore, whether it is a single-label classification or a multi-label classification, the label vector can be obtained by encoding the position (i.e., index) of the rth element corresponding to the real classification category to which the training sample belongs in the multiple first preset elements.

[0082] For example, in single-label classification, since only one classification category is output, that is, there is only one true classification category to which the training sample belongs, then during encoding, encoding can be performed based on the position of the rth element corresponding to the true classification category to which the training sample belongs in multiple first preset elements. Assuming that the obtained label vector is [000000010000…000] (its dimension is the length of multiple first preset elements), it means that the rth element corresponding to the true classification category to which the training sample belongs in multiple first preset elements is encoded as "1" (since it is a single-label classification, there is only one element encoded as 1), and the other elements in the multiple first preset elements except the rth element corresponding to the true classification category are encoded as "0".

[0083] Similarly, in multi-label classification, since multiple classification categories are output, that is, there are multiple real classification categories to which the training sample belongs, the encoding is also based on the position of the rth element corresponding to each classification category to which the training sample belongs in the multiple first preset elements. Assume that the obtained label vector is [010000010000…010], which means that the rth element corresponding to each real classification category to which the training sample belongs in the multiple first preset elements is encoded as "1" (for example, the above label vector shows that the encoding as 1 includes 3 elements, and these 3 elements correspond one-to-one to the rth elements corresponding to the 3 real classification categories to which the training sample belongs). The other elements in the multiple first preset elements except the rth element corresponding to the real classification category are encoded as 0.

[0084] Therefore, since the rth element corresponding to the true classification category to which the training sample belongs can be determined through the 0 and 1 in the label vector, and there is a mapping relationship between the element and the classification category, the true classification category to which the training sample belongs can be directly determined through the preset element corresponding to the code 1 in the label vector and the mapping relationship. Therefore, the first probability value corresponding to each first preset element obtained in the above embodiment can be used to predict the classification category to which the training sample belongs. For example, the first probability value of the first preset element represents the confidence that the training sample belongs to the classification category corresponding to this first preset element.

[0085] Furthermore, taking a real classification category as an example, a second preset element corresponding to the rth element corresponding to the real classification category is determined from multiple first preset elements; then a fourth preset element is selected from multiple third preset elements, wherein the multiple third preset elements are elements in the multiple first preset elements and are different from the second preset element. Exemplarily, the multiple third preset elements can be sorted in descending order according to the first probability value corresponding to each third preset element in the multiple third preset elements; then, among the sorted multiple third preset elements, a fourth preset element is selected in descending order according to the first probability value, wherein the number of the fourth preset elements is x times the number of the real classification categories to which the training sample belongs, and the sum of the number of the fourth preset elements and the number of the real classification categories to which the training sample belongs is less than the number of the multiple first preset elements (or the length of the vocabulary), wherein x≥1, and x is a natural number. This application does not specifically limit the value of x.

[0086] It can be seen from the above embodiment that since the first probability value of each first preset element can be the logical value corresponding to each first preset element before activation, it can also be the probability corresponding to each first preset element after activation. Therefore, when selecting the fourth preset element from multiple third preset elements, if the first probability value of each first preset element is the logical value corresponding to each first preset element before activation, it can be understood that the fourth preset element is selected based on the logical value corresponding to each third preset element before activation (the principle is similar and will not be repeated here), and then the logical value corresponding to the fourth preset element is activated to obtain the first probability value corresponding to the fourth preset element; if the first probability value of each first preset element is the probability corresponding to each first preset element after activation, then the selection can be made based on the probability corresponding to each first preset element after activation. The principle is similar and will not be repeated here.

[0087] Then, based on the first probability value corresponding to the rth element corresponding to the true classification category, the first probability value corresponding to the fourth preset element, and the label vector, a first loss is determined. Exemplarily, based on the first probability value corresponding to the fourth preset element, the first probability value corresponding to the rth element corresponding to the true classification category to which the training sample belongs, the encoding value corresponding to the fourth preset element in the label vector, and the encoding value corresponding to the rth element corresponding to the true classification category in the label vector, the first loss is obtained as shown in formula (3):

[0088]

[0089] Wherein, L2 represents the first loss, m represents the number of training samples, z represents the number of true classification categories to which the i-th training sample belongs, (x+1)z represents the sum of the number of the fourth preset elements corresponding to the i-th training sample and the number of true classification categories to which the i-th training sample belongs, represents the first probability value corresponding to the u-th element in the preset elements corresponding to the i-th training sample (the number is (x+1)z, specifically including the fourth preset element and the r-th element corresponding to the true classification category of the i-th training sample), Represents the encoding value (0 or 1) corresponding to the u-th element in the preset elements (the number is (x+1)z, specifically including the fourth preset element and the r-th element corresponding to the true classification category of the i-th training sample) in the label vector.

[0090] S203: Train the model based on the first loss.

[0091] After obtaining the first loss, the model can be subjected to multiple iterative training such as gradient descent based on the first loss, so that the first probability value of the preset element with the corresponding coding value of 1 in the label vector among the above (x+1)z preset elements corresponding to each training sample becomes larger and larger and gradually approaches 1 in subsequent iterative training, that is, gradually approaches the true label. Similarly, the first probability value of the preset element with the corresponding coding value of 0 in the label vector among the above (x+1)z preset elements corresponding to each training sample becomes smaller and smaller and gradually approaches 0 in subsequent iterative training until the model converges and a trained model is obtained.

[0092] Furthermore, if one wants to obtain an output sequence corresponding to the training sample, i.e., a predicted classification category, then the seventh preset element can be directly selected from multiple first preset elements based on the first probability value of each first preset element. For example, a preset number of eighth preset elements are selected from multiple first preset elements in the order of the first probability value corresponding to each first preset element from high to low; then the third position of each eighth preset element in the multiple first preset elements is determined, and the fourth position of the rth element corresponding to each first classification category in the multiple first preset elements is determined; then, based on the third position corresponding to each eighth preset element and the fourth position corresponding to each first classification category, the preset number of eighth preset elements is screened to obtain the seventh preset element, wherein the position of the seventh preset element in the multiple first preset elements is different from the fourth position corresponding to each first classification category. Wherein, if it is a single-label classification, the number of the seventh preset element is 1, and if it is a multi-label classification, the number of the seventh preset element is multiple, i.e., the first preset number (this application does not limit the specific value).

[0093] It should be explained that, especially in multi-label classification, since the preset number of eighth preset elements may include not only some or all of the r-th elements corresponding to each first classification category (or classification category in the category library) corresponding to the training sample, but also some r-th elements corresponding to the first classification category (or classification category in the category library) that do not belong to the training sample, the preset number of eighth preset elements can also be filtered so that the position of the seventh preset element obtained by filtering in the multiple first preset elements is the same as the fourth position corresponding to a first classification category, so as to improve the accuracy of the model in predicting the classification category to which the training sample belongs.

[0094] Then, based on the mapping relationship between elements and classification categories, the classification category corresponding to the seventh preset element is determined; and based on the classification category corresponding to the seventh preset element, the predicted classification category corresponding to the training sample is obtained, that is, the complete output sequence of the training sample.

[0095] Of course, in an optional embodiment, since a corresponding index is established for each first preset element in the embodiment of the present application, as well as a mapping relationship between the index corresponding to the element and the classification category, the seventh preset element determined in the above embodiment can also be understood as determining the index corresponding to the seventh preset element; then, based on the mapping relationship between the index corresponding to the element and the classification category, the classification category corresponding to the index of the seventh preset element can be determined, that is, a complete output sequence of the training sample is obtained. The same is true for other embodiments, which can also be understood as the index corresponding to the element, which will not be elaborated one by one here.

[0096] For ease of understanding, combined Figure 1 and Figure 2 For the relevant description of the embodiment, multi-label classification is used as an example. Figure 3 , Figure 3 This is a schematic diagram of a complete output sequence based on a model provided in an embodiment of the present application. Figure 3 As shown, assuming that the number of training samples is 1, that is, m=1, after obtaining the training sample, that is, Input, the training sample is vectorized to obtain the Embeddings corresponding to the training sample; then, based on the model, the Embeddings corresponding to the training sample are feature processed (mainly including attention processing. When the architecture of the first model is different, there will be other processing before and after the attention processing, such as the normalization layer Norm Layer, the fully connected layer Fully connected layer, etc., specifically refer to the Encoder-Decoder architecture of the Transformer model or the Decoder-Only architecture of the QWen model, which will not be elaborated here), and the feature vector corresponding to each element in the first training sample is obtained. The principle will not be repeated here. At this time, the feature vector corresponding to each element includes the context information of the training sample; then at the first time step, the model is based on the feature vector corresponding to each element and the starting mark of the input <start>Make a prediction and obtain the first probability value corresponding to each first preset element in the plurality of first preset elements (assuming the length is V, i.e. V preset elements) at the first time step, that is, Figure 3 The P shown u (where 1≤u≤V), which will not be repeated here, that is, this application only requires one time step or one inference.

[0097] Furthermore, when calculating the loss, this application only requires one time step or one inference, and the label vector is obtained by multi-hot encoding according to the vocabulary dimension, that is, Figure 3 The y shown u (where 1≤u≤V), it can be seen that the rth element (i.e., the 2nd, 5th, 8th, and Vth elements) corresponding to the true classification category of the training sample in the V preset elements are all encoded as 1, and the remaining preset elements are encoded as 0; then based on the first probability values ​​corresponding to the multiple third preset elements, the fourth preset element (or the index corresponding to the fourth preset element) is selected from the multiple third preset elements. Since the number of true classification categories to which the training sample belongs is 4 at this time (i.e., z=4), the multiple third preset elements are the remaining preset elements (the number is (V-4)) in the V preset elements except the 2nd, 5th, 8th, and Vth elements, and the number of fourth preset elements is x*z; then based on the first probability values ​​corresponding to the x*z fourth preset numbers, the first probability value of the rth element corresponding to the true classification category to which the training sample belongs, the encoding value corresponding to each fourth preset element in the label vector, and the encoding value of the rth element corresponding to the true classification category to which the training sample belongs in the label vector, the first loss L2 corresponding to the training sample can be obtained, as shown in formula (4):

[0098]

[0099] It should be noted that due to Figure 3 The explanation is given with one training sample, ie, m=1, as an example, so it still has the same meaning as the above formula (3), and the explanation of formula (4) will not be repeated here.

[0100] When determining the output sequence corresponding to the training sample, the present application only needs one time step or only needs to infer once, that is, when each first preset element (i.e. Figure 3 After the first probability value corresponding to the V first preset elements is obtained, a preset number of eighth preset elements (or the index of the preset number of eighth preset elements) is directly selected from the V first preset elements; then, according to the rth element corresponding to the true classification category to which the training sample belongs, the preset number of eighth preset elements (or the index of the preset number of eighth preset elements) is filtered to obtain the seventh preset element. The filtering principle is not repeated here. Figure 3 After filtering, four seventh preset elements (or four indices corresponding to the seventh preset elements) are obtained. Then, based on these four seventh preset elements (or the indices corresponding to the four seventh preset elements) and the pre-constructed mapping relationship mentioned in the above embodiment, mapping is performed to obtain category 1, category 2, category 3, and category 4, respectively. That is, the output sequence corresponding to the training sample includes category 1, category 2, category 3, and category 4.

[0101] It can be seen that in the embodiment of the present application, when constructing the label vector corresponding to the training sample, since the present application has pre-established the mapping relationship between the elements and the classification categories, for each training sample, the position of the rth element corresponding to the real classification category of each training sample in multiple first preset elements can be encoded to obtain the corresponding label vector. At this time, the encoding value corresponding to the rth element corresponding to each real classification category in the label vector is 1, and the rest are 0; then when the model is inferring, it only needs to perform one inference based on the feature vector corresponding to each element in the training sample to obtain the first probability value corresponding to each first preset element, which will not be repeated here. At this time, the first probability value corresponding to each first preset element is used to predict the classification category to which the training sample belongs; and then the first loss is calculated based on the above formula (3).

[0102] With the above Figure 1 The difference between the embodiments is that, for the case where the number of elements in the output sequence is multiple, whether it is single-label classification or multi-label classification, the model of the embodiment of the present application does not need one token by one The token-based approach performs multiple inferences (i.e., corresponding to multiple time steps). This means that the generation of the next element in the output sequence does not depend on the elements that have already been generated. Instead, only one inference (i.e., corresponding to the first time step) is required to obtain the complete output sequence. This is because the label vector is encoded according to the position of the rth element corresponding to the true classification category of the training sample among multiple first preset elements, and a mapping relationship between elements and classification categories is pre-established. That is, the corresponding classification category can be determined based on a single element. In this way, when calculating the loss, it can be directly based on the first probability value corresponding to the first preset element and the encoded value or true value (0 or 1) corresponding to the first preset element in the label vector. The goal of training is to make the first probability value corresponding to the first preset element with an encoded value of 1 in the first time step increasingly larger, and the first probability value of the first preset element with an encoded value of 0 increasingly smaller. Then, when determining the output sequence, the seventh preset element determined can represent a classification category. That is, by mapping according to the above mapping relationship, the complete output sequence can be obtained. This not only shortens the time consumption but also avoids the "hallucination" problem caused by the one-token-by-one token approach.

[0103] In addition, during training, since the number of true classification categories to which the training samples belong is generally much smaller than the number of first preset elements or the length of the vocabulary, when calculating the loss, in order to maintain a balance between positive and negative examples during the model learning process, x times the number of labels (i.e., the number of true classification categories to which the training samples belong) can be selected from the preset elements with an encoding value of 0 in the label vector. For example, x can be 2, 3, 4, etc., so that the number of preset elements with an encoding value of 1 and the number of preset elements with an encoding value of 0 in (x+1)*z are relatively balanced, and the number of preset elements with an encoding value of 1 is not too much or too little, thereby reducing the computational burden and improving the accuracy of model learning.

[0104] Furthermore, after obtaining the trained model, you can perform application reasoning based on the trained model. For details, see Figure 4 , Figure 4 This is a flow chart of a classification method provided in an embodiment of the present application. The method is applied to a classification device, and the method includes but is not limited to the following steps S401-S402:

[0105] S401: Predicting a second probability value corresponding to each of a plurality of first preset elements based on features of a first text using a model.

[0106] In the embodiment of the present application, the first text is similar to the training sample in the above embodiment and is encapsulated in the form of prompt. The principle is similar and will not be repeated here.

[0107] The features of the first text include a feature vector corresponding to each element in the first text, and the feature vector corresponding to each element in the first text includes the context information of the first text. Then, based on the feature vector corresponding to each element in the first text, the second probability value corresponding to each first preset element in the plurality of first preset elements can be predicted. The principle is similar to the principle of predicting the first probability value corresponding to each first preset element in the plurality of first preset elements, and will not be repeated here. In addition, the specific training method of the model in step S401 refers to the above Figure 2 The corresponding steps in the embodiment will not be repeated any more.

[0108] S402: Determine a fourth classification category corresponding to the first text based on the second probability value corresponding to each first preset element.

[0109] In an embodiment of the present application, the first text may include at least one fifth classification category (similar to the above-mentioned first classification category, and the relevant content will not be explained here), and the at least one fifth classification category includes at least the fourth classification category corresponding to the first text.

[0110] Therefore, when there are multiple fifth classification categories, like the first classification category, multiple sixth classification categories can be obtained (similar to the second classification category, no further details will be given), wherein the multiple sixth classification categories include at least the fourth classification category corresponding to the first text; then based on the rth element of all elements corresponding to each sixth classification category, the multiple sixth classification categories are grouped to obtain a third classification category group, wherein the rth element corresponding to each classification category in the third classification category group is the same, and the principle is similar to the principle of obtaining the first classification category group mentioned above, and no further details will be given here.

[0111] Then, based on each classification category in the third classification category group, a seventh classification category is determined from multiple sixth classification categories, wherein the seventh classification category is different from each classification category in the third classification category group; then, based on the seventh classification category and the third classification category group, multiple fifth classification categories are determined. Specifically, based on the semantic information corresponding to each classification category in the third classification category group and the rth element corresponding to the seventh classification category, the elements corresponding to the classification categories in the third classification category group are adjusted to obtain a fourth classification category group. The principle is similar to the principle of obtaining the second classification category group mentioned above and will not be repeated here. The rth element corresponding to each classification category in the fourth classification category group is different and different from the rth element corresponding to the seventh classification category; then, based on the seventh classification category and the classification categories in the fourth classification category group, multiple fifth classification categories corresponding to the first text are obtained. For example, the seventh classification category and part or all of the classification categories in the fourth classification category group are determined as multiple fifth classification categories, and finally the rth element in the elements corresponding to each fifth classification category in the multiple fifth classification categories is different.

[0112] Then, further, a fifth preset element can be selected from the plurality of first preset elements based on the second probability value corresponding to each first preset element. The principle is similar to the principle of selecting the seventh preset element described above. Specifically, a preset number of sixth preset elements are selected from the plurality of first preset elements in descending order of the second probability value; then, the first position of each sixth preset element in the plurality of first preset elements is determined; and the second position of the rth element in each fifth classification category is determined in the plurality of first preset elements; then, based on the first position corresponding to each sixth preset element and the second position corresponding to each fifth classification category, the preset number of sixth preset elements are screened to obtain a fifth preset element, wherein the position of the fifth preset element in the plurality of first preset elements is different from the second position corresponding to each fifth classification category. Then, based on the mapping relationship between elements and classification categories, the classification category corresponding to the fifth preset element is determined; and then, based on the classification category corresponding to the fifth preset element, a fourth classification category corresponding to the first text is obtained.

[0113] Finally, it is uniformly stated that in the embodiments of the present application, the rth element in the elements corresponding to the classification category (whether it is the real classification category, the first classification category, the second classification category, the third classification category, the fourth classification category, ..., the tenth classification category, etc. in the embodiments of the present application, all classification categories involved in the full text embodiments are not listed here) can be the first element, the second element or the third element in the elements corresponding to the classification category, etc. This application does not limit the value of r, and the embodiments of the present application are mainly explained using r=1 as an example.

[0114] It should be noted that the classification device performs Figure 4 Each step in the embodiment can also be executed accordingly Figure 2 The corresponding steps in the embodiments have similar principles and can achieve the same technical effects, so they will not be described one by one here.

[0115] It can be seen that when classifying the first text, whether it is single-label classification or multi-label classification, the first text can be encapsulated into a prompt, and then the prompt can also include the fifth classification category corresponding to the first text, and then the prompt is input into the trained model to obtain the output of the first time step, that is, the second probability value of each first preset element in multiple first preset elements, and then the fourth classification category is determined based on the second probability value of each first preset element, that is, the model only needs to output the second probability value corresponding to each first preset element once to obtain a complete output sequence, that is, the probability distribution obtained at this time (that is, the second probability value of each first preset element at the first time step) corresponds to all elements in the output sequence, and there is no need Like the prior art, multiple outputs are performed, which takes a long time, and the probability distribution of each output only corresponds to one element in the output sequence, and the current output needs to depend on the previous output, which is not independent of each other and is prone to "hallucination" problems. Compared with this, the present application not only saves time but also avoids the "hallucination" problem; then, based on the second probability value of each first preset element in descending order, a preset number of sixth preset elements are selected, and the preset number of sixth preset elements are filtered, that is, elements that are different from the rth element corresponding to each fifth classification category are filtered out, and then based on the seventh preset element obtained by filtering, the corresponding fourth classification category is obtained in combination with the mapping relationship, ensuring that the obtained fourth classification category belongs to the fifth classification category, thereby ensuring the accuracy of classification.

[0116] Furthermore, the classification device can be a terminal device, such as a smart phone, tablet computer, laptop computer, desktop computer, smart TV, desktop computer, smart watch, smart car and other smart terminals, which are not limited in this application. The model trained in the above embodiment can be deployed on the terminal device, and then after obtaining the first text, the classification device predicts the second probability value corresponding to each of the multiple first preset elements based on the features of the first text by deploying the locally trained model; then the classification device determines the fourth classification category corresponding to the first text based on the corresponding of each first preset element. The principle will not be repeated here.

[0117] Of course, the above classification device can also be a server, that is, the trained model is deployed on the server, see Figure 5 , Figure 5 A schematic diagram of a classification system provided in an embodiment of the present application.

[0118] Figure 5 The system shown includes a classification device and a client; the classification device can be a server, the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, as well as basic cloud computing services such as big data and artificial intelligence platforms, which are not specifically limited in this application; the client can be a smart phone, tablet computer, laptop computer, desktop computer, smart TV, desktop computer, smart watch, smart car and other smart terminals, but is not limited to this.

[0119] The user can upload the first text through the client, and then the client sends the first text to the classification device. Then the classification device predicts the second probability value corresponding to each of the multiple first preset elements based on the characteristics of the first text through the trained model; then the classification device determines the fourth classification category corresponding to the first text based on the second probability value corresponding to each first preset element. The principle will not be repeated here; further, the classification device sends the fourth classification category corresponding to the first text to the client.

[0120] It should be noted that Figure 5 The principles of the steps performed by the classification device in the embodiment can refer to the corresponding explanations of the above embodiment, which will not be repeated here, and the steps performed by the classification device in the above embodiment can also be performed accordingly, which will not be repeated here.

[0121] Similarly, the model training device in the above embodiment can be a terminal device, such as a smart phone, tablet computer, laptop computer, desktop computer, smart TV, desktop computer, smart watch, smart car and other smart terminals, which are not limited in this application. The model to be trained can be deployed on the terminal device, and then after obtaining the training sample, the model training device determines the first probability value of the training sample falling into each of the multiple first preset elements based on the characteristics of the training sample, and then determines the first loss based on the first probability value of the training sample falling into each of the multiple first preset elements and the label vector corresponding to the training sample, and then trains the model based on the first loss to obtain a trained model. The principle will not be repeated here.

[0122] Of course, the above model training device can also be a server, that is, the model to be trained is deployed on the server, see Figure 6 , Figure 6 A schematic diagram of a model training system provided in an embodiment of the present application.

[0123] Figure 6 The system shown includes a model training device and a client; the model training device can be a server, the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, as well as basic cloud computing services such as big data and artificial intelligence platforms. This application does not make specific limitations; the client can be a smart phone, tablet computer, laptop computer, desktop computer, smart TV, desktop computer, smart watch, smart car and other smart terminals, but is not limited to this.

[0124] The user can upload the training sample through the client, and then the client sends the training sample to the model training device, and then the model training device performs model training based on the training sample, specifically as follows: the model training device predicts the first probability value corresponding to each of the multiple first preset elements based on the characteristics of the training sample, wherein the multiple first preset elements include elements corresponding to the true classification category of the training sample; then the model training device determines the first loss based on the first probability value of each first preset element and the label vector corresponding to the training sample, wherein the label vector is used to indicate the element corresponding to the true classification category, and the number of elements corresponding to the true classification category is greater than 1; then the model training device trains the model based on the first loss to obtain a trained model, and the principle will not be repeated here.

[0125] It should be noted that Figure 6 The principles of the steps executed by the model training device in the embodiment can refer to the corresponding explanations of the above embodiment, which will not be repeated here, and the steps executed by the model training device in the above embodiment can also be executed accordingly, which will not be repeated here.

[0126] It should be noted that the main scenarios applicable to the classification method of the embodiment of the present application may include but are not limited to the following scenarios:

[0127] (1) Sentiment analysis: for example, inputting the input data corresponding to the user (including part or all of the text, video, audio, etc.) into the model in the embodiment of the present application, performing sentiment prediction through the model, and obtaining sentiment information; (2) Intent recognition: for example, inputting the input data corresponding to the user (such as the user's conversation) into the model in the embodiment of the present application, performing intent recognition prediction through the model, and obtaining the user's intention; (3) Speech analysis: for example, performing speech analysis on the user's conversation input into the model in the embodiment of the present application, and outputting the corresponding speech analysis results; (4) Product recommendation: for example, inputting the user's corresponding user portrait data into the model in the embodiment of the present application, performing product recommendation prediction through the model, and outputting products that match the user; and so on. This application does not list them one by one.

[0128] See Figure 7 , Figure 7 This is a block diagram of the functional units of a model training device provided in an embodiment of the present application. The model training device 700 includes: a first acquisition unit 701 and a first processing unit 702;

[0129] A first acquisition unit 701 is used to acquire training samples;

[0130] The first processing unit 702 is used to predict a first probability value corresponding to each first preset element in a plurality of first preset elements based on the characteristics of the training sample, wherein the plurality of first preset elements include elements corresponding to the true classification category of the training sample; determine a first loss based on the first probability value corresponding to each first preset element and a label vector corresponding to the training sample, wherein the label vector is used to indicate the element corresponding to the true classification category, and the number of elements corresponding to the true classification category is greater than 1; and train the model based on the first loss.

[0131] In one embodiment of the present application, the element corresponding to the true classification category includes the rth element among all elements corresponding to the true classification category; in determining the first loss based on the first probability value corresponding to each first preset element and the label vector corresponding to the training sample, the first processing unit 702 is specifically configured to:

[0132] Determining a second preset element corresponding to the rth element from the plurality of first preset elements;

[0133] selecting a fourth preset element from a plurality of third preset elements, wherein the plurality of third preset elements are elements in the plurality of first preset elements and are different from the second preset element;

[0134] The first loss is determined based on the first probability value corresponding to the rth element, the first probability value corresponding to the fourth preset element, and the label vector.

[0135] In one embodiment of the present application, the first processing unit 702 is specifically configured to:

[0136] The label vector is obtained by encoding according to the position of the rth element in the multiple first preset elements.

[0137] In one embodiment of the present application, the number of fourth preset elements is x times the number of real classification categories, and the sum of the number of fourth preset elements and the number of real classification categories is less than the number of multiple first preset elements, where x≥1 and x is a natural number.

[0138] In one embodiment of the present application, the training sample further includes at least one first classification category, wherein the at least one first classification category at least includes the real classification category to which the training sample belongs.

[0139] In one embodiment of the present application, the element corresponding to each first classification category includes the rth element among all elements corresponding to each first classification category, and the rth element corresponding to each first classification category is different.

[0140] In one embodiment of the present application, when there are multiple first classification categories, the first processing unit 702 is specifically configured to:

[0141] Acquire multiple second classification categories corresponding to the training sample, where the multiple second classification categories at least include the real classification category to which the training sample belongs;

[0142] Grouping the plurality of second classification categories based on the rth element in the elements corresponding to each second classification category to obtain a first classification category group, wherein the rth element corresponding to each classification category in the first classification category group is the same;

[0143] determining, based on each classification category, a third classification category from the plurality of second classification categories, wherein the third classification category is different from each classification category;

[0144] Based on the third classification category and the first classification category group, a plurality of first classification categories corresponding to the training samples are determined.

[0145] In one embodiment of the present application, in determining a plurality of first classification categories corresponding to the training sample based on the third classification category and the first classification category group, the first processing unit 702 is specifically configured to:

[0146] Adjusting the elements of the classification categories in the first classification category group based on the semantic information corresponding to each classification category in the first classification category group and the rth element among the elements corresponding to the third classification category to obtain a second classification category group, wherein the rth element corresponding to each classification category in the second classification category group is different and different from the rth element corresponding to the third classification category;

[0147] Based on the third classification category and the classification categories in the second classification category group, a plurality of first classification categories corresponding to the training samples are obtained.

[0148] In one embodiment of the present application, r=1.

[0149] In a specific implementation, the first acquisition unit 701 and the first processing unit 702 described in the embodiment of the present invention can also execute other implementation methods described in the embodiment of the model training method provided by the embodiment of the present invention, which will not be repeated here.

[0150] See Figure 8 , Figure 8 This is a block diagram of the functional units of a classification device provided in an embodiment of the present application. The classification device 800 includes: a second acquisition unit 801 and a second processing unit 802;

[0151] A second acquiring unit 801 is configured to acquire a first text;

[0152] The second processing unit 802 is used to predict the second probability value corresponding to each of the multiple first preset elements based on the characteristics of the first text through a model, wherein the model is trained through an embodiment of the above-mentioned model training method; and determine the fourth classification category corresponding to the first text based on the second probability value corresponding to each first preset element.

[0153] In one embodiment of the present application, in determining the fourth classification category corresponding to the first text based on the second probability value corresponding to each first preset element, the second processing unit 802 is specifically configured to:

[0154] selecting a fifth preset element from the plurality of first preset elements based on the second probability value corresponding to each first preset element;

[0155] Determining a classification category corresponding to a fifth preset element based on a mapping relationship between elements and classification categories;

[0156] Based on the classification category corresponding to the fifth preset element, a fourth classification category is obtained.

[0157] In one embodiment of the present application, the first text further includes at least one fifth classification category, and the at least one fifth classification category includes at least the fourth classification category.

[0158] In one embodiment of the present application, in selecting the fifth preset element from the plurality of first preset elements based on the second probability value corresponding to each first preset element, the second processing unit 802 is specifically configured to:

[0159] selecting a preset number of sixth preset elements from the plurality of first preset elements in descending order of the second probability values;

[0160] Determining a first position of each sixth preset element among the plurality of first preset elements;

[0161] Determining a second position of an r-th element among the elements corresponding to each fifth classification category in the plurality of first preset elements;

[0162] Based on the first position corresponding to each sixth preset element and the second position corresponding to each fifth classification category, a preset number of sixth preset elements are screened to obtain a fifth preset element, wherein the position of the fifth preset element in multiple first preset elements is different from the second position corresponding to each fifth classification category.

[0163] In one embodiment of the present application, the rth element in the elements corresponding to each fifth classification category is different.

[0164] In one embodiment of the present application, r=1.

[0165] In a specific implementation, the second acquisition unit 801 and the second processing unit 802 described in the embodiment of the present invention may also execute other implementation methods described in the embodiment of the classification method provided by the embodiment of the present invention, which will not be repeated here.

[0166] See Figure 9 , Figure 9 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 9 As shown, electronic device 900 includes a transceiver 901, a processor 902, and a memory 903. These are connected via a bus 904. The memory 903 is used to store computer programs and data, and can transmit the data stored in the memory 903 to the processor 902.

[0167] The electronic device 900 may be the model training device 700 or the classification device 800;

[0168] When the electronic device 900 is the model training device 700, the processor 902 is configured to read the computer program in the memory 903 and perform the following operations:

[0169] Control transceiver 901 to obtain training samples;

[0170] Based on the characteristics of the training sample, predict a first probability value corresponding to each first preset element in a plurality of first preset elements, wherein the plurality of first preset elements include elements corresponding to the true classification category of the training sample; determine a first loss based on the first probability value corresponding to each first preset element and a label vector corresponding to the training sample, wherein the label vector is used to indicate the element corresponding to the true classification category, and the number of elements corresponding to the true classification category is greater than 1; and train the model based on the first loss.

[0171] In a specific implementation, the transceiver 901 and processor 902 described in the embodiment of the present invention may also execute other implementation methods described in the embodiment of the model training method provided in the embodiment of the present invention, which will not be repeated here.

[0172] When the electronic device 900 is the classification device 800, the processor 902 is configured to read the computer program in the memory 903 and perform the following operations:

[0173] Controlling the transceiver 901 to obtain a first text;

[0174] Through the trained model, based on the characteristics of the first text, the second probability value corresponding to each first preset element in multiple first preset elements is predicted, wherein the model is trained through an embodiment of the above-mentioned model training method; based on the second probability value corresponding to each first preset element, the fourth classification category corresponding to the first text is determined.

[0175] In a specific implementation, the transceiver 901 and the processor 902 described in the embodiment of the present invention may also execute other implementation methods described in the embodiment of the classification method provided by the embodiment of the present invention, which will not be repeated here.

[0176] Specifically, the transceiver 901 may be Figure 7 The first acquisition unit 701 of the model training device 700 of the embodiment or Figure 8 The second acquisition unit 801 of the classification device 800 of the embodiment, the processor 902 may be Figure 7 The first processing unit 702 of the model training device 700 of the embodiment or Figure 8 The second processing unit 802 of the classification device 800 of the embodiment.

[0177] It should be understood that the electronic device in this application can be a model training device or a classification device, and both the model training device and the classification device can be a terminal device or a server, wherein the terminal device can be a smart phone, tablet computer, laptop computer, desktop computer, smart TV, desktop computer, smart watch, smart car and other smart terminals, but is not limited to this; the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, and basic cloud computing services such as big data and artificial intelligence platforms. This application does not make specific limitations. The above-mentioned electronic devices are only examples, not exhaustive, and include but are not limited to the above-mentioned electronic devices.

[0178] It should be understood that the embodiments of the present application also provide a computer-readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement part or all of the steps of any model training method or classification method recorded in the above method embodiments.

[0179] An embodiment of the present application also provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to enable a computer to execute part or all of the steps of any model training method or classification method described in the above method embodiments.

[0180] It should be noted that for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that this application is not limited by the order of the actions described, because according to this application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in this specification are all optional embodiments, and the actions and modules involved are not necessarily required by this application.

[0181] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0182] In the several embodiments provided in this application, it should be understood that the disclosed devices can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical or other forms.

[0183] Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.

[0184] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or in the form of software program modules.

[0185] If the integrated unit is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a memory and includes a number of instructions for enabling a computer device (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned memory includes various media that can store program codes, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.

[0186] Those skilled in the art will appreciate that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a program. The program can be stored in a computer-readable memory, and the memory can include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0187] The above is a detailed introduction to the embodiments of the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core idea of ​​the present application. At the same time, for those skilled in the art, based on the ideas of the present application, there may be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.< / start> < / end> < / start> < / end>

Claims

1. A model training method, characterized in that: The method comprises: Predicting a first probability value corresponding to each of a plurality of first preset elements based on the characteristics of the training sample, wherein the plurality of first preset elements include elements corresponding to the true classification category of the training sample; Determining a first loss based on a first probability value corresponding to each first preset element and a label vector corresponding to the training sample, wherein the label vector is used to indicate an element corresponding to the true classification category, and the number of elements corresponding to the true classification category is greater than 1; The model is trained based on the first loss.

2. The method according to claim 1, characterized in that The element corresponding to the true classification category includes the rth element among all elements corresponding to the true classification category; The determining of the first loss based on the first probability value corresponding to each first preset element and the label vector corresponding to the training sample includes: Determining a second preset element corresponding to the rth element from the plurality of first preset elements; selecting a fourth preset element from a plurality of third preset elements, wherein the plurality of third preset elements are elements in the plurality of first preset elements and are different from the second preset element; The first loss is determined based on the first probability value corresponding to the rth element, the first probability value corresponding to the fourth preset element, and the label vector.

3. The method according to claim 2, characterized in that The method further comprises: The label vector is obtained by encoding according to the position of the rth element in the multiple first preset elements.

4. The method according to claim 2 or 3, characterized in that The number of the fourth preset elements is x times the number of the real classification categories, and the sum of the number of the fourth preset elements and the number of the real classification categories is less than the number of the multiple first preset elements, where x≥1 and x is a natural number.

5. The method according to any one of claims 2 to 4, characterized in that: The training sample further includes at least one first classification category, wherein the at least one first classification category at least includes the true classification category.

6. The method according to claim 5, characterized in that The elements corresponding to each first classification category include the rth element among all elements corresponding to each first classification category, and the rth elements corresponding to each first classification category are different.

7. The method according to claim 5 or 6, characterized in that In the case where there are multiple first classification categories, the method further includes: Acquire a plurality of second classification categories corresponding to the training samples, wherein the plurality of second classification categories at least include the true classification category; Grouping the plurality of second classification categories based on an r-th element in the elements corresponding to each second classification category to obtain a first classification category group, wherein the r-th element corresponding to each classification category in the first classification category group is the same; determining, based on each classification category, a third classification category from the plurality of second classification categories, wherein the third classification category is different from each classification category; Based on the third classification category and the first classification category group, a plurality of first classification categories corresponding to the training samples are determined.

8. The method according to claim 7, characterized in that The determining, based on the third classification category and the first classification category group, a plurality of first classification categories corresponding to the training samples comprises: Adjusting the elements of the classification categories in the first classification category group based on the semantic information corresponding to each classification category in the first classification category group and the rth element among the elements corresponding to the third classification category to obtain a second classification category group, wherein the rth element corresponding to each classification category in the second classification category group is different and different from the rth element corresponding to the third classification category; Based on the third classification category and the classification categories in the second classification category group, a plurality of first classification categories corresponding to the training samples are obtained.

9. The method according to any one of claims 2 to 8, characterized in that: r=1。 10. A classification method, characterized in that The method comprises: Predicting, by a model, a second probability value corresponding to each of the plurality of first preset elements based on features of the first text, wherein the model is trained using the model training method according to any one of claims 1 to 9; Based on the second probability value corresponding to each first preset element, a fourth classification category corresponding to the first text is determined.

11. The method according to claim 10, characterized in that The determining, based on the second probability value corresponding to each first preset element, a fourth classification category corresponding to the first text includes: selecting a fifth preset element from the plurality of first preset elements based on the second probability value corresponding to each first preset element; Determining the classification category corresponding to the fifth preset element based on a mapping relationship between elements and classification categories; The fourth classification category is obtained based on the classification category corresponding to the fifth preset element.

12. The method according to claim 11, characterized in that The first text further includes at least one fifth classification category, and the at least one fifth classification category includes at least the fourth classification category.

13. The method according to claim 12, characterized in that The selecting a fifth preset element from the plurality of first preset elements based on the second probability value corresponding to each first preset element includes: selecting a preset number of sixth preset elements from the plurality of first preset elements in descending order of the second probability values; determining a first position of each sixth preset element in the plurality of first preset elements; Determine a second position of an r-th element among the elements corresponding to each fifth classification category in the plurality of first preset elements; Based on the first position corresponding to each sixth preset element and the second position corresponding to each fifth classification category, the preset number of sixth preset elements are screened to obtain the fifth preset element, wherein the position of the fifth preset element in the multiple first preset elements is different from the second position corresponding to each fifth classification category.

14. The method according to claim 12 or 13, characterized in that The rth element corresponding to each fifth classification category is different.

15. The method according to claim 13 or 14, characterized in that r=1。 16. A model training device, characterized in that: The model training device includes: a first acquisition unit and a first processing unit; The first acquisition unit is used to acquire training samples; The first processing unit is used to predict a first probability value corresponding to each first preset element in a plurality of first preset elements based on the characteristics of the training sample, wherein the plurality of first preset elements include elements corresponding to the true classification category of the training sample; determine a first loss based on the first probability value corresponding to each first preset element and a label vector corresponding to the training sample, wherein the label vector is used to indicate the element corresponding to the true classification category, and the number of elements corresponding to the true classification category is greater than 1; and train the model based on the first loss.

17. A classification device, characterized in that: The classification device includes: a second acquisition unit and a second processing unit; The second acquiring unit is configured to acquire the first text; The second processing unit is used to predict the second probability value corresponding to each first preset element in multiple first preset elements based on the characteristics of the first text through a model, wherein the model is trained by the model training method described in any one of claims 1-9; based on the second probability value corresponding to each first preset element, determine the fourth classification category corresponding to the first text.

18. An electronic device, characterized in that: include: A processor and a memory, the processor being connected to the memory, the memory being used to store a computer program, and the processor being used to execute the computer program stored in the memory, so that the electronic device performs the method according to any one of claims 1 to 9 or any one of claims 10 to 15.

19. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and the computer program is executed by a processor to implement the method according to any one of claims 1 to 9 or any one of claims 10 to 15.