Model training method and device

By collecting data sets, extracting language features, performing average pooling and similarity calibration loss calculations in text readability evaluation tasks, and alternately adjusting model parameters and feature embeddings, the problem of single-dimensional feature characterization and insufficient processing of category similarity is solved. , improves the accuracy and generalization of the model.

CN119150023APending Publication Date: 2024-12-17GUOMAI CULTURE MEDIA CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411362643.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-27
Publication Date
2024-12-17

AI Technical Summary

Technical Problem

In the prior art, the single-processing of feature representations and category similarity in text readability assessment tasks, resulting in poor performance of models in tasks with deep understanding of text context and unclear boundaries of category division.

Method used

By collecting data sets of text and its categories, language features are extracted and input embedding sequences are formed, average pooling is performed to obtain language feature category embeddings, similarity calibration losses are calculated, and model parameters and feature embeddings are alternately adjusted during model training. Ensure that classification loss and similarity calibration loss reach the threshold.

Benefits of technology

The accuracy and generalization of the model in the text readability evaluation task is improved, ensuring that the model can more accurately distinguish different categories, and avoiding the problems of single-dimensional feature representation and insufficient processing of category similarity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119150023A_ABST
    Figure CN119150023A_ABST
Patent Text Reader

Abstract

The invention aims to provide a model training method and equipment. The method comprises the following steps: collecting a data set containing a text and a text category thereof; extracting language features from each text, and embedding the extracted language features of all texts into prompt information for model training to form an input embedding sequence; performing average pooling on the language features of all texts to obtain feature embedding of each language feature category; in a model training process, based on feature embedding of all language feature categories, calculating similarity calibration loss between any two language feature categories; and inputting the input embedding sequence into the to-be-trained model, calculating classification loss and similarity calibration loss in the training process of the to-be-trained model, alternately adjusting model parameters and feature embedding of various language feature categories until the classification loss and the similarity calibration loss respectively reach respective corresponding loss thresholds, and generating a target model. And the later PA task processing performance of the model is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of training model technology, and in particular to a model training method and device. Background Art

[0002] During model training, readability assessment (RA) is a task to assess the difficulty of text reading, which is extremely important in the field of natural language processing. Traditional methods rely on manually designed linguistic features, but traditional methods have poor training performance under few-sample training settings. In recent years, with the rise of pretrained language models (PLMs), prompt-based tuning methods have achieved remarkable results in few-sample classification tasks. However, since RA tasks require rich language knowledge, the performance of traditional prompt learning methods in RA still needs to be improved.

[0003] In the prior art, a text classification method based on deep learning is often used, especially the use of a pre-trained model for fine-tuning to solve the RA task. Specifically, the following steps are included: 1. Fine-tuning the pre-trained model: fine-tuning the pre-trained language model on a specific task (RA task), usually by adding additional classification layers (such as fully connected layers) to adapt to the specific classification task; 2. Input format construction: converting the input text sequence into a format accepted by the model; 3. Loss function optimization: optimizing the model by minimizing the cross entropy loss so that the model can predict the correct category label.

[0004] Based on the above method steps, the existing technology has the following shortcomings: 1. Simplified feature representation: Most existing methods rely on the general language representation learned by the pre-trained model itself, and fail to make full use of the domain knowledge or feature engineering of specific tasks, resulting in unsatisfactory performance in tasks that require a deep understanding of the text context; 2. Insufficient processing of similarities between categories: When dealing with the similarities and differences between different categories, existing methods only optimize through classification loss, ignoring the similarities between categories, resulting in poor performance of the model in tasks with unclear category boundaries or complex category structures. Summary of the invention

[0005] One purpose of the present application is to provide a model training method and device, which improves the processing performance of the model to be trained by reasonably constructing an input embedding sequence and alternately adjusting model parameters and feature embedding during the training process, and ensures that the model to be trained can more accurately distinguish different categories during the training process, thereby improving the accuracy and generalization of the model.

[0006] According to one aspect of the present application, a model training method is provided, wherein the method comprises:

[0007] Collecting a data set containing texts and text categories thereof, wherein the data set includes at least one text;

[0008] Extracting language features from each of the texts, and embedding the extracted language features of all the texts into prompt information for model training to form an input embedding sequence;

[0009] Average pooling is performed on the language features of all the texts to obtain feature embeddings for each language feature category;

[0010] During the model training process, based on the feature embeddings of all types of the language feature categories, a similarity calibration loss between any two of the language feature categories is calculated;

[0011] The input embedding sequence is input into the model to be trained, and during the training process of the model to be trained, the classification loss and the similarity calibration loss are calculated respectively, and the model parameters of the model to be trained and the feature embeddings of various language feature categories are alternately adjusted until the classification loss and the similarity calibration loss reach their respective corresponding loss thresholds, thereby generating a target model.

[0012] Furthermore, in the above method, extracting language features from each of the texts, and embedding the extracted language features of all the texts into prompt information for model training to form an input embedding sequence includes:

[0013] Extracting language features from each of the texts, and converting the extracted language features of all the texts in vector form into embedding vectors using a multi-head multilayer perceptron;

[0014] Constructing prompt information including hard prompts, soft prompts and mixed prompts, and converting the prompt information to obtain a prompt input sequence;

[0015] The embedding vector and the prompt input sequence are combined to obtain an input embedding sequence.

[0016] Furthermore, the above model training method also includes:

[0017] Convert all the texts into the input format of the model to be trained;

[0018] Convert the text in the input format by encoding the model to be trained to generate a hidden state vector;

[0019] The hard mark in the hard hint is replaced by the hidden state vector to generate the soft hint.

[0020] Furthermore, in the above method, the linguistic features of all the texts are averagely pooled to obtain feature embedding of each linguistic feature category, including:

[0021] Combining the language features of all the texts into a language feature category set according to language feature categories, wherein each of the language feature categories includes at least one language feature;

[0022] The language feature category set is processed using average pooling to obtain an embedded language feature set, wherein the language feature set includes feature embeddings of each language feature category.

[0023] Furthermore, in the above method, the training process of the model to be trained includes at least one training cycle, wherein the classification loss and the similarity calibration loss are calculated separately, and the model parameters of the model to be trained and the feature embedding of various language feature categories are alternately adjusted, including:

[0024] In the current training cycle, according to the data set, the category probability of each of the texts is predicted by a classifier, and the classification loss of the current training cycle is calculated;

[0025] Calculate the similarity matrix between the various language feature categories based on cosine similarity, and calculate the similarity calibration loss of the current training cycle through a list sorting loss function;

[0026] Update the model parameters of the current training cycle according to the classification loss of the current training cycle;

[0027] According to the similarity calibration loss of the current training cycle, the feature embeddings of the various language feature categories of the current training cycle are adjusted.

[0028] Furthermore, in the above method, the calculation formula of the classification loss is:

[0029]

[0030] Wherein, D represents the data set; x i Indicates the input text; y i Represents text x i Corresponding text category label; P(y i |x i ; M) represents the model to be trained M for the input text x i The predicted category probability distribution, where i represents the i-th text in the dataset D.

[0031] Furthermore, in the above method, the calculation formula of the similarity calibration loss is:

[0032]

[0033] Where k represents the number of samples in a certain language feature category; n represents the total number of language feature categories; i represents the index of a language feature category, and its value ranges from 1 to n, where n is a positive integer greater than or equal to 2; j represents the index of another language feature category, and its value ranges from 1 to n, where n is a positive integer greater than or equal to 2; s′ π(i,i) Represents the elements of the similarity matrix between the various language feature categories before rearrangement; s′ π(i,j) Represents the elements of the similarity matrix between the various language feature categories after rearrangement; exp() represents the exponential function; π(i, i) represents the element in the i-th row and i-th column in the original similarity matrix, which represents the self-similarity of category i, that is, the similarity between category i and itself; π(i, j) represents the element in the i-th row and j-th column in the original similarity matrix M, which represents the similarity between category i and category j.

[0034] According to another aspect of the present application, a non-volatile storage medium is also provided, on which computer-readable instructions are stored. When the computer-readable instructions can be executed by a processor, the processor implements a model training method as described above.

[0035] According to another aspect of the present application, a model training device is also provided, wherein the device comprises:

[0036] one or more processors;

[0037] A computer readable medium for storing one or more computer readable instructions,

[0038] When the one or more computer-readable instructions are executed by the one or more processors, the one or more processors implement a model training method as described above.

[0039] Compared with the prior art, the present application collects a data set containing texts and their text categories, wherein the data set includes at least one text; extracts language features from each of the texts, and embeds the extracted language features of all the texts into prompt information for model training to form an input embedding sequence; average pools the language features of all the texts to obtain feature embeddings for each language feature category; during the model training process, based on the feature embeddings of all types of the language feature categories, calculates the similarity calibration loss between any two of the language feature categories; inputs the input embedding sequence into the model to be trained, and during the training process of the model to be trained, respectively calculates the classification loss and the similarity calibration loss. Similarity calibration loss, alternately adjust the model parameters of the model to be trained and the feature embedding of various language feature categories until the classification loss and the similarity calibration loss reach their respective corresponding loss thresholds, and generate a target model. Not only is the input embedding sequence embedded with language features combined with the calculation of the similarity calibration loss, but also an alternating adjustment mechanism is used to optimize the training process of the model to be trained, so that the model to be trained can better capture the characteristics of the text, and ensure that different language feature categories are accurately distinguished during the training process, thereby improving the accuracy and generalization of the model training process, improving the performance of the model in post-processing PA tasks, and avoiding the problems of single feature representation and insufficient similarity processing between categories in the prior art. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Other features, objects and advantages of the present application will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings:

[0041] Figure 1 A flowchart of a model training method according to one aspect of the present application is shown.

[0042] The same or similar reference numerals in the drawings represent the same or similar components. DETAILED DESCRIPTION

[0043] The present application is described in further detail below in conjunction with the accompanying drawings.

[0044] In a typical configuration of the present application, the terminal, the device of the service network and the trusted party all include one or more processors (CPU), input / output interfaces, network interfaces and memories.

[0045] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0046] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include non-transitory media such as modulated data signals and carrier waves.

[0047] This application makes up for the shortcomings of traditional training methods by introducing language features in the training process. Its core lies in utilizing the representation ability of the model to be trained and related technologies such as feature engineering, by reasonably constructing the input embedding sequence and setting the alternating training mechanism, so that the model to be trained can have better performance in the reading difficulty classification task. Specifically, Figure 1 FIG. 1 is a flow chart of a model training method according to one aspect of the present application, wherein the method comprises step S11, step S12, step S13, step S14 and step S15, specifically comprising the following steps:

[0048] Step S11, collect a data set containing text and its text categories, wherein the data set includes at least one text; it should be noted that the data set also includes a text category label corresponding to each text, and the text category label is used to indicate the reading difficulty or other reading difficulty-related attributes of the text, so as to provide data support for calculating the classification loss in the subsequent training process of the model to be trained.

[0049] After the data set is prepared, step S12 is executed to extract language features from each of the texts, and the extracted language features of all the texts are embedded into the prompt information for model training to form an input embedding sequence; here, the prompt information refers to prompt learning designed according to the actual training task, which is used to provide inspiring information or prompts to help the model to be trained produce expected outputs that better meet the task requirements. By extracting rich language features from the text and embedding them into the prompt information, the model to be trained can better capture the semantic information, structural information and other related text information of the text during the training process, thereby improving the performance of the target model in the reading difficulty classification task; and, according to the text content of different texts, the number of language features that can be extracted from each text is not limited in this application, that is, according to the text content of different texts, one text can extract one language feature, multiple language features, or no language feature. In a preferred embodiment of the present application, the language features extracted from each text are preferably represented by feature vectors.

[0050] Step S13, average pooling is performed on the language features of all the texts to obtain feature embedding for each language feature category; it should be noted that average pooling refers to a process of calculating the average value in a local area. The feature map is divided, and each sub-area calculates the average of all values ​​within it to smooth the feature map, which helps to reduce the overfitting of the model and improve the generalization ability of the model, so as to provide data support for calculating the similarity calibration loss for the subsequent training process of the model to be trained.

[0051] In order to overcome the problem of insufficient similarity processing between categories in the prior art and to make the features between the feature embeddings of each language feature category more prominent, explicit optimization is performed between the language feature categories. At this time, a similarity calibration mechanism is introduced. In step S14, during the model training process, based on the feature embeddings of all types of the language feature categories, the similarity calibration loss between any two of the language feature categories is calculated to ensure that the model can more accurately distinguish different categories during the inference process, especially when the boundaries are blurred or similar categories exist.

[0052] Step S15, inputting the input embedding sequence into the model to be trained, and in the training process of the model to be trained, respectively calculating the classification loss and the similarity calibration loss, alternately adjusting the model parameters of the model to be trained and the feature embeddings of the various language feature categories, until the classification loss and the similarity calibration loss respectively reach their corresponding loss thresholds, and generating a target model; it should be noted that, in the training process of the model to be trained, the classification loss is calculated based on all the texts in the data set and their corresponding text category labels; the target model refers to the model obtained after training with the training model.

[0053] Specifically, the calculation formula of the classification loss is:

[0054]

[0055] Wherein, D represents the data set; xi represents the input text; yi represents the text category label corresponding to the text xi; P(yi|xi; M) represents the category probability distribution predicted by the model to be trained M for the input text xi, where i represents the i-th text in the data set D; It should be noted that the category probability distribution can be calculated with the help of the FC classifier and using the following formula:

[0056] P(y|x)=Softmax(FC(h cls ));

[0057] Among them, x represents any text in the text set in the dataset D; y represents the text category label corresponding to text x; h cls Refers to the starting component in the hidden state vector corresponding to the text x.

[0058] The calculation formula of the similarity calibration loss is:

[0059]

[0060] Where k represents the number of samples in a certain language feature category; n represents the total number of language feature categories; i represents the index of a language feature category, and its value ranges from 1 to n, where n is a positive integer greater than or equal to 2; j represents the index of another language feature category, and its value ranges from 1 to n, where n is a positive integer greater than or equal to 2; s′ π(i,i) Represents the elements of the similarity matrix between the various language feature categories before rearrangement; s′ π(i,j) Represents the elements of the similarity matrix between the various language feature categories after rearrangement; exp() represents the exponential function; π(i, i) represents the element in the i-th row and i-th column in the original similarity matrix, which represents the self-similarity of category i, that is, the similarity between category i and itself; π(i, j) represents the element in the i-th row and j-th column in the original similarity matrix M, which represents the similarity between category i and category j.

[0061] The loss threshold corresponding to the classification loss and the loss threshold corresponding to the similarity calibration loss can both be set according to different actual training tasks, and the loss threshold corresponding to the classification loss and the loss threshold corresponding to the similarity calibration loss can both be a certain loss value or a certain loss range. The specific settings are not limited in this application.

[0062] Through the above steps S11 to S15, rich language features are extracted from the text and embedded into the prompt information, so that the model to be trained can better capture the semantic information and structural information of the text, thereby improving the processing performance of the model on specific tasks; a similarity calibration mechanism is introduced in the training process to ensure that the model can more accurately distinguish different categories during the inference process; an alternating training method is adopted to optimize the classification loss and the similarity calibration loss to ensure that the model can take into account both accuracy and generalization during the learning process, thereby improving the stability and effect in practical applications.

[0063] In a preferred embodiment of the present application, first, a data set D = {X, Y} including text X and corresponding text category label Y is collected, where X represents a text set, which includes text x1, text x2, ..., text x (l-1) and text x l (where x and l are both positive integers greater than 2); Y represents the text category label set corresponding to each text in the X text set, which includes the text category label y1 corresponding to text x1, the text category label y2 corresponding to text x2, ..., the text category label y1 corresponding to text x1, the text category label y2 corresponding to text x2, ..., the text category label y2 corresponding to text x1, the text category label y2 corresponding to text x2, ..., the text category label y1 corresponding to text x1, the text category label y1 corresponding to text x2, ..., the text category label y2 ...1 corresponding to text x1, ..., the text category label y1 corresponding to text x1, ..., the text category label y1 corresponding to text x2, ..., the text category label (l-1) The corresponding text category label y (l-1) and text x l The corresponding text category label y l (where y and l are both positive integers greater than 2); after the data set D is prepared, the model to be trained for the current training task is selected, and the weights and configuration of the model are loaded for subsequent fine-tuning and feature extraction.

[0064] Secondly, from text x1-text x l Extract language features and get the feature vector f corresponding to text x1 x1 , the feature vector f corresponding to the text x2 x2 , ..., text x (l-1) The corresponding eigenvector f x(l-1) and text x l The corresponding eigenvector f xl , respectively, the feature vector f x1 -Eigenvector f xl Embed into the prompt information to obtain the input embedding sequence seq.

[0065] Next, the extracted feature vector f is processed using average pooling x1 -Eigenvector f xl , we get feature embeddings of n language feature categories, which are: feature embedding of language feature category C1, feature embedding of language feature category C2, ..., feature embedding of language feature category C (n-1) Feature embedding and language feature category C nfeature embedding (where n is a positive integer greater than 1) to facilitate the calculation of the similarity calibration loss between any two language feature categories during model training.

[0066] Finally, the input embedding sequence seq is input into the model to be trained and training begins. During the training process of the model to be trained, the classification loss L is calculated based on the text set X and the text category label set Y in the data set D = {X, Y} classification ; Based on the feature embedding of n language feature categories, calculate the similarity calibration loss L between each language feature category calibration ; By the classification loss L classification and similarity calibration loss L calibration The real-time calculation results of the training model are adjusted alternately, and the model parameters of the model to be trained and the feature embedding of n language feature categories are adjusted, and the classification loss L classification Reaching the classification loss L classification The loss threshold and similarity calibration loss L calibration Achieve similarity calibration loss L calibration When the loss threshold is reached, the target model model is generated.

[0067] In order to deeply integrate the language features into the model to be trained, following the above embodiment of the present application, the step S12 extracts the language features from each of the texts, and embeds the extracted language features of all the texts into the prompt information for model training to form an input embedding sequence, including:

[0068] Extract language features from each of the texts, and use a multi-head multilayer perceptron to convert the extracted language features of all the texts in vector form into embedded vectors; here, the language features include but are not limited to syntactic features, lexical features, etc. In a preferred embodiment of the present application, the preferred language features include syntactic features and lexical features; the multi-head multilayer sensor refers to MultiHeadMLP (Multilayer Perceptron), which maps multiple input data sets to a single output data set, that is, the language features extracted in the form of feature vectors can be converted into embedded vectors through MultiHeadMLP, realizing the feature extraction and conversion of language features into embedded vectors. Specifically, the conversion of language features into embedded vectors can be achieved through the following formula:

[0069] MultiHeadMLP(f xi )={v xi1 , v xi2 , ..., v xi(p-1) , v xip};

[0070] Among them, f xiRefers to text x i The corresponding eigenvector; {v xi1 , v xi2 , ..., v xi(p-1) , v xip} refers to f xi The transformed embedding vector consisting of p components; x i Refers to the i-th text in the text set.

[0071] Construct prompt information including hard prompts, soft prompts and mixed prompts, and convert the prompt information to obtain a prompt input sequence; it should be noted that the hard prompt is used to convert the input text x i Transforms the prompt input x to contain at least one [MASK] token prompt , for the model to be trained to fill in the prediction, in actual application scenarios, hard prompts can be obtained through a fixed template T(x i ) is constructed; the soft prompt is optimized through a continuous and learnable prompt sequence so that the model to be trained can be continuously adjusted and improved according to feedback; the mixed prompt refers to the combination of hard prompt and soft prompt.

[0072] The converting of the prompt information to obtain a prompt input sequence refers to converting hard prompts, soft prompts and mixed prompts into embedding vectors respectively through an embedding vector conversion function to obtain embedding vectors corresponding to hard prompts, embedding vectors corresponding to soft prompts and embedding vectors corresponding to mixed prompts, and then combining the embedding vectors corresponding to hard prompts, soft prompts and embedding vectors corresponding to mixed prompts to obtain a prompt input sequence, thereby enhancing the ability of the model to be trained to understand all texts.

[0073] The embedding vector and the prompt input sequence are combined to obtain an input embedding sequence, so as to integrate the embedding vector into the input embedding sequence, deeply train the model to be trained, and enable it to better understand the text content, thereby improving the training effect.

[0074] Following the above embodiment of the present application, another aspect of the present application provides a model training method further comprising:

[0075] All the texts are converted into the input format of the model to be trained; here, in the actual application scenario, the input format is [CLS, SEP] format, where CLS and SEP are special start and end tags.

[0076] The text in the input format is converted by encoding the model to be trained to generate a hidden state vector, wherein the hidden state vector is used to consider the text context in the input data when the model to be trained processes the input data, and provide a trainable soft tag for the construction of subsequent soft prompts.

[0077] The hard mark in the hard prompt is replaced by the hidden state vector to generate the soft prompt, so as to add a trainable soft mark to the soft mark, enhance the prompt effect of the prompt input sequence, and promote the efficient training of the model to be trained in a specific task.

[0078] Following the above embodiment of the present application, in step S15, the language features of all the texts are averagely pooled to obtain feature embedding for each language feature category, including:

[0079] The language features of all the texts are grouped into a language feature category set according to language feature categories, wherein each of the language feature categories includes at least one language feature.

[0080] The language feature category set is processed using average pooling to obtain an embedded language feature set, wherein the language feature set includes feature embeddings of each language feature category, which not only achieves clear classification of all language features, but also improves feature distinction between categories, which is conducive to judging similarities between categories.

[0081] Following the above embodiment of the present application, the training process of the model to be trained includes at least one training cycle, wherein the classification loss and the similarity calibration loss are calculated respectively in step S15, and the model parameters of the model to be trained and the feature embedding of various language feature categories are alternately adjusted, including:

[0082] In the current training cycle, based on the data set, the category probability of each of the texts is predicted by a classifier, and the classification loss of the current training cycle is calculated; it should be noted that the classification loss in the current training cycle is calculated by a classifier based on the text category label corresponding to each text in the data set; the classifier includes but is not limited to the FC classifier.

[0083] The similarity matrix between the various language feature categories is calculated based on cosine similarity, and the similarity calibration loss of the current training cycle is calculated through a list sorting loss function; here, the list sorting loss function includes but is not limited to a ListMLE function, which realizes the maintenance of the similarity structure between categories.

[0084] Update the model parameters of the current training cycle based on the classification loss of the current training cycle.

[0085] According to the similarity calibration loss of the current training cycle, the feature embeddings of the various language feature categories of the current training cycle are adjusted to optimize the classification loss and the similarity calibration loss, while alternately adjusting the model to be trained and the feature embeddings to improve the accuracy and generalization of the model to be trained during the training process.

[0086] For example, in an actual application scenario, the specific steps of this application are as follows: 1. Data preparation: collect a data set D = {X, Y} containing text X and corresponding label Y, where each text is annotated with a text category label, indicating its reading difficulty or other relevant attributes; 2. Determine the model to be trained: select a model to be trained for a suitable task and load the weights and configuration of the model to be trained for subsequent fine-tuning and feature extraction; 3. Hint-based fine-tuning: convert each text x into a format acceptable to the language model to be trained, usually in the format of [CLS, SEP]; the language model to be trained encodes the text in the modified format as an input sequence to generate a hidden state vector h = {h [cls] ,h1,h2,...,h l ,h [sep]}, and use the classifier FC to predict the category probability distribution of the text; 4. Feature prompt fine-tuning: (1) Feature extraction and embedding: Extract language features from the text, such as syntactic features, lexical features, etc. In order to integrate language features into the model, each text language feature is represented as a feature vector, whose dimension depends on the number of features; use multi-head MLP to map the feature vector to a vector space (each space represents a language feature category), and obtain the embedding vector {v xi1 , v xi2 , ..., v xi(p-1) , v xip}; (2) Prompt construction: Design hard prompts, soft prompts, and mixed prompts according to specific tasks, convert hard prompts, soft prompts, and mixed prompts into embedding vectors, and obtain the prompt input sequence {h1, h2, ..., h l , e(T), e([MASK]), e(x)}, where the e() function is the embedding vector conversion function; the embedding vector {v xi1 , v xi2 , ..., v xi(p-1) , v xip} and the prompt input sequence {h1, h2, ..., h l , e(T), e([MASK]), e(x)} are combined to form an input embedding sequence, which is passed to the pre-trained language model model for subsequent calculation of the classification loss L classification; 5. Model training preparation: Based on the language features corresponding to the dataset D and the text, a language feature set F containing n categories is formed according to the language feature categories; 6. Set the formula for calculating the classification loss and determine the loss threshold corresponding to the classification loss; 7. Similarity calibration: Use average pooling to process the language feature set F to obtain the embedded language feature set F'. Calculate the inter-class similarity matrix M based on cosine similarity, and maintain the similarity structure between categories through the list sorting loss function ListMLE. Set the formula for calculating the similarity calibration loss and determine the loss threshold corresponding to the similarity calibration loss; 8. Alternating training process: The training process is divided into two main goals: optimizing the classification loss and the similarity calibration loss to minimize the classification loss and minimize the similarity calibration loss; in order to effectively train these two losses, the model parameters and feature embeddings are updated alternately in each training cycle to ensure that the model to be trained model can accurately classify the data while maintaining the similarity structure in the feature space to obtain the target model model`.

[0087] In practical application scenarios, the present invention mainly extracts linguistic features from text through the lingfeat and zhfeat toolkits, and then uses multi-head MLP to convert these features into embedding vectors so that the model can better understand the contribution and relationship of these features in text classification, and realize feature extraction and embedding; by averaging the extracted linguistic features, the feature embedding of each category is obtained, and then the similarity is used to measure the similarity between different categories. In order to maintain the distribution of extracted features, a list-based ranking loss function (ListMLE) based on cosine similarity is introduced, and the feature embedding is adjusted by minimizing the loss function to ensure that similar categories maintain a close distance in the embedding space, so as to achieve cross-class similarity calibration; in the training process, an alternating training strategy is adopted to alternately optimize the text classification loss and the similarity calibration loss. In each training cycle, the order of the data set is randomly disrupted to avoid the model's dependence on the data order. The model parameters are updated by minimizing the classification loss, and the feature embedding is adjusted by minimizing the similarity calibration loss, so that the model can accurately classify the data while maintaining the similarity structure in the embedding space.

[0088] According to another aspect of the present application, a non-volatile storage medium is also provided, on which computer-readable instructions are stored. When the computer-readable instructions can be executed by a processor, the processor implements a model training method as described above.

[0089] According to another aspect of the present application, a model training device is also provided, wherein the device comprises:

[0090] one or more processors;

[0091] A computer readable medium for storing one or more computer readable instructions,

[0092] When the one or more computer-readable instructions are executed by the one or more processors, the one or more processors implement a model training method as described above.

[0093] Here, the detailed contents of each embodiment of the model training device can be specifically referred to the corresponding part of the embodiment of the above-mentioned model training method, which will not be repeated here.

[0094] In summary, the present application collects a data set containing texts and their text categories, wherein the data set includes at least one text; extracts language features from each of the texts, and embeds the extracted language features of all the texts into prompt information for model training to form an input embedding sequence; average pools the language features of all the texts to obtain feature embeddings for each language feature category; during the model training process, based on the feature embeddings of all types of the language feature categories, calculates the similarity calibration loss between any two of the language feature categories; inputs the input embedding sequence into the model to be trained, and during the training process of the model to be trained, respectively calculates the classification loss and the similarity loss. Calibration loss, alternately adjusting the model parameters of the model to be trained and the feature embeddings of the various language feature categories until the classification loss and the similarity calibration loss reach their respective corresponding loss thresholds, and generating a target model. Not only is the input embedding sequence embedded with language features combined with the calculation of the similarity calibration loss, but also an alternating adjustment mechanism is used to optimize the training process of the model to be trained, so that the model to be trained can better capture the features of the text, and ensure that different language feature categories are accurately distinguished during the training process, thereby improving the accuracy and generalization of the model training process, improving the performance of the model in post-processing PA tasks, and avoiding the problems of single feature representation and insufficient similarity processing between categories in the prior art.

[0095] It should be noted that the present application can be implemented in software and / or a combination of software and hardware, for example, can be implemented using an application specific integrated circuit (ASIC), a general purpose computer or any other similar hardware device. In one embodiment, the software program of the present application can be executed by a processor to implement the steps or functions described above. Similarly, the software program of the present application (including relevant data structures) can be stored in a computer-readable recording medium, for example, a RAM memory, a magnetic or optical drive or a floppy disk and similar devices. In addition, some steps or functions of the present application can be implemented using hardware, for example, as a circuit that cooperates with a processor to perform each step or function.

[0096] In addition, a part of the present application may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present application through the operation of the computer. The program instruction for calling the method of the present application may be stored in a fixed or removable recording medium, and / or transmitted through a data stream in a broadcast or other signal-bearing medium, and / or stored in a working memory of a computer device that runs according to the program instruction. Here, according to an embodiment of the present application, a device is included, the device including a memory for storing computer program instructions and a processor for executing program instructions, wherein, when the computer program instruction is executed by the processor, the device is triggered to run the method and / or technical solution based on the aforementioned multiple embodiments according to the present application.

[0097] It is obvious to those skilled in the art that the present application is not limited to the details of the above exemplary embodiments, and that the present application can be implemented in other specific forms without departing from the spirit or basic features of the present application. Therefore, from any point of view, the embodiments should be regarded as exemplary and non-restrictive, and the scope of the present application is limited by the attached claims rather than the above description, so it is intended to include all changes that fall within the meaning and scope of the equivalent elements of the claims in the present application. Any figure mark in the claims should not be regarded as limiting the claims involved. In addition, it is obvious that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices stated in the device claim can also be implemented by one unit or device through software or hardware. Words such as left and right are used to indicate names, and do not indicate any particular order.

Claims

1. A model training method, wherein: The method comprises: Collecting a data set containing texts and text categories thereof, wherein the data set includes at least one text; Extracting language features from each of the texts, and embedding the extracted language features of all the texts into prompt information for model training to form an input embedding sequence; Average pooling is performed on the language features of all the texts to obtain feature embeddings for each language feature category; During the model training process, based on the feature embeddings of all types of the language feature categories, a similarity calibration loss between any two of the language feature categories is calculated; The input embedding sequence is input into the model to be trained, and during the training process of the model to be trained, the classification loss and the similarity calibration loss are calculated respectively, and the model parameters of the model to be trained and the feature embeddings of various language feature categories are alternately adjusted until the classification loss and the similarity calibration loss reach their respective corresponding loss thresholds, thereby generating a target model.

2. The method according to claim 1, wherein: The extracting language features from each of the texts and embedding the extracted language features of all the texts into prompt information for model training to form an input embedding sequence includes: Extracting language features from each of the texts, and converting the extracted language features of all the texts in vector form into embedding vectors using a multi-head multilayer perceptron; Constructing prompt information including hard prompts, soft prompts and mixed prompts, and converting the prompt information to obtain a prompt input sequence; The embedding vector and the prompt input sequence are combined to obtain an input embedding sequence.

3. The method according to claim 2, wherein: The method further comprises: Convert all the texts into the input format of the model to be trained; Convert the text in the input format by encoding the model to be trained to generate a hidden state vector; The hard mark in the hard hint is replaced by the hidden state vector to generate the soft hint.

4. The method according to claim 1, wherein: The linguistic features of all the texts are averagely pooled to obtain feature embedding for each linguistic feature category, including: Combining the language features of all the texts into a language feature category set according to language feature categories, wherein each of the language feature categories includes at least one language feature; The language feature category set is processed using average pooling to obtain an embedded language feature set, wherein the language feature set includes feature embeddings of each language feature category.

5. The method according to claim 1, wherein the training process of the model to be trained includes at least one training cycle, wherein: The respectively calculating the classification loss and the similarity calibration loss, and alternately adjusting the model parameters of the to-be-trained model and the feature embedding of various language feature categories, include: In the current training cycle, according to the data set, the category probability of each of the texts is predicted by a classifier, and the classification loss of the current training cycle is calculated; Calculate the similarity matrix between the various language feature categories based on cosine similarity, and calculate the similarity calibration loss of the current training cycle through a list sorting loss function; Update the model parameters of the current training cycle according to the classification loss of the current training cycle; According to the similarity calibration loss of the current training cycle, the feature embeddings of the various language feature categories of the current training cycle are adjusted.

6. The method according to any one of claims 1 to 5, wherein: The calculation formula of the classification loss is: Wherein, D represents the data set; xi represents the input text; yi represents the text category label corresponding to the text xi; P(yi|xi; M) represents the category probability distribution predicted by the model to be trained M for the input text xi, where i represents the i-th text in the data set D.

7. The method according to any one of claims 1 to 5, wherein: The calculation formula of the similarity calibration loss is: Where k represents the number of samples in a certain language feature category; n represents the total number of language feature categories; i represents the index of a language feature category, and its value ranges from 1 to n, where n is a positive integer greater than or equal to 2; j represents the index of another language feature category, and its value ranges from 1 to n, where n is a positive integer greater than or equal to 2; s′ π(i,i) Represents the elements of the similarity matrix between the various language feature categories before rearrangement; s′ π(i,j) Represents the elements of the similarity matrix between the various language feature categories after rearrangement; exp() represents the exponential function; π(i, i) represents the element in the i-th row and i-th column in the original similarity matrix, which represents the self-similarity of category i, that is, the similarity between category i and itself; π(i, j) represents the element in the i-th row and j-th column in the original similarity matrix M, which represents the similarity between category i and category j.

8. A non-volatile storage medium having computer-readable instructions stored thereon, wherein when the computer-readable instructions are executable by a processor, the processor is enabled to implement the method according to any one of claims 1 to 7.

9. A model training device, wherein: The equipment includes: one or more processors; A computer readable medium for storing one or more computer readable instructions, When the one or more computer-readable instructions are executed by the one or more processors, the one or more processors implement the method according to claims 1 to 7.

Citation Information

Cited By

  • User privacy protection cross-domain service recommendation method for large language model enhancement

    CN120216760A