Training sample processing method and device, equipment, storage medium and program product
By masking the original samples and pre-training language model predictions, enhanced samples are generated for training, which solves the problem of the existing model's insufficient ability to recognize unseen aspect words, and improves the accuracy of aspect word extraction and the prediction of the model. Accuracy.
Patent Information
- Application Number
- CN202310358966.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-28
- Publication Date
- 2024-10-01
AI Technical Summary
Existing aspect word extraction models cannot effectively extract new aspect words that have not appeared in the training set in the text, resulting in low extraction accuracy.
By masking the original samples, the pre-trained language model is used to predict the position of aspect words, and enhanced samples are generated, which are used to train the aspect word extraction model to improve the model's recognition ability of new aspect words.
The aspect word extraction model improves the accuracy of extracting new aspect words, enhances the model's prediction accuracy and sample quality, and solves the problem of the model's insufficient ability to recognize unseen aspect words.
Smart Images

Figure CN118734844A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a training sample processing method, apparatus, computer equipment, storage medium and program product, and also to a language model training method, apparatus, computer equipment, storage medium and program product. Background Art
[0002] With the development of computer technology and artificial intelligence technology, sentiment analysis has become one of the most active research directions in the field of natural language processing, and has been widely studied in information retrieval, data mining, text mining, etc. Aspect term extraction (ATE) is a basic subtask in aspect-level sentiment analysis. Given a text, the aspect term extraction task can extract the aspect terms that express the emotions of the user from the text.
[0003] However, the currently trained aspect word extraction model cannot extract all aspect words contained in the text, especially new aspect words that have not appeared in the training set, resulting in low accuracy of the aspect word extraction model in extracting aspect words from the text. Summary of the invention
[0004] Based on this, it is necessary to provide a training sample processing method, device, equipment, storage medium and program product to address the above-mentioned technical problems, which can generate high-quality enhanced samples. The aspect word extraction model obtained by enhancing the sample training can effectively improve the accuracy of the aspect word extraction model in extracting aspect words.
[0005] In a first aspect, the present application provides a training sample processing method, the method comprising:
[0006] Obtaining original samples, each original sample includes text, aspect words in the text, and position information of the aspect words in the text;
[0007] Masking the aspect words in the text to obtain a masked text;
[0008] By using a pre-trained language model, predicting the aspect word position indicated by the position information according to the masked text and the position information, to obtain a predicted aspect word;
[0009] The aspect words in the text of the original sample are replaced with the predicted aspect words to obtain an enhanced sample; the enhanced sample is used to train an aspect word extraction model.
[0010] In a second aspect, the present application also provides a training sample processing device. The device comprises:
[0011] An original sample acquisition module, used to acquire original samples, each original sample includes a text, an aspect word in the text, and position information of the aspect word in the text;
[0012] An original sample masking module, used for performing masking processing on the aspect words in the text to obtain a masked text;
[0013] An original sample prediction module, used to predict the aspect word position indicated by the position information according to the masked text and the position information through a pre-trained language model to obtain a predicted aspect word;
[0014] The enhanced sample generation module is used to replace the aspect words in the text of the original sample with the predicted aspect words to obtain enhanced samples; the enhanced samples are used to train the aspect word extraction model.
[0015] In one of the embodiments, the position information includes a mark indicating whether each word in the text is an aspect word, and marks corresponding to the starting position and the ending position of the aspect word in the text. The training sample processing device also includes an original sample position marking module, which is used to insert a position tag for locating the aspect word in the masked text to obtain a labeled text; and insert a label tag corresponding to the position tag into the position information to obtain labeled labeled position information.
[0016] The original sample prediction module is also used to: predict the aspect word position indicated by the position information according to the labeled text and the label-tokenized position information through the pre-trained language model to obtain the predicted aspect word.
[0017] In one of the embodiments, the original sample masking module is further used to: obtain a preset masking rate, determine the number of aspect words in the text to be masked based on the total number of aspect words in the text and the preset masking rate; and based on the determined number, randomly sample aspect words from the text and perform masking to obtain the masked text.
[0018] In one of the embodiments, the original sample prediction module is further used to: perform semantic encoding according to the masked text and position information through an encoder of a pre-trained language model to obtain a semantic representation corresponding to the text;
[0019] Through the decoder of the pre-trained language model, semantic decoding is performed according to the context of the indicated aspect word position and the semantic representation corresponding to the text to obtain the predicted aspect word.
[0020] In one of the embodiments, the original sample prediction module is further used to: predict the probability distribution corresponding to each aspect word position indicated by the position information according to the masked text and the position information through a pre-trained language model, wherein the probability distribution represents the probability that each word in the vocabulary is the predicted aspect word of the aspect word position;
[0021] For each aspect word position, k candidate words are selected from the vocabulary according to probability, and a word is randomly sampled from the k candidate words as the predicted aspect word corresponding to the aspect word position;
[0022] Here, k is a natural number greater than 1.
[0023] In one of the embodiments, the training sample processing device further includes a denoising module, the denoising module being used to: extract aspect words from the enhanced sample using a pre-trained aspect word extraction model to obtain aspect word extraction results, and determine position information corresponding to the enhanced sample according to the aspect word extraction results;
[0024] From the enhanced samples, the enhanced samples whose determined position information is consistent with the position information corresponding to the aspect words in the text of the corresponding original samples are screened out, and the aspect word extraction model is trained according to the screened enhanced samples.
[0025] In one of the embodiments, the training sample processing device further includes an aspect word extraction model training module, which is used to perform model training on the aspect word extraction model through enhanced samples and original samples in sequence to obtain a trained aspect word extraction model.
[0026] In one of the embodiments, the training sample processing device further includes a pre-trained language model training module, the pre-trained language model training module is used to: obtain training samples, each training sample includes a text, an aspect word in the text, and position information of the aspect word in the text;
[0027] Mask the aspect words in the text to obtain the masked text;
[0028] By initializing the language model, the aspect word position indicated by the position information is predicted according to the masked text and position information to obtain the predicted aspect word;
[0029] According to the difference between the predicted aspect words and the aspect words in the text, a sample loss is constructed, and the initialized language model is updated according to the sample loss to obtain a pre-trained language model.
[0030] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0031] Obtaining original samples, each original sample includes text, aspect words in the text, and position information of the aspect words in the text;
[0032] Masking the aspect words in the text to obtain a masked text;
[0033] By using a pre-trained language model, predicting the aspect word position indicated by the position information according to the masked text and the position information, to obtain a predicted aspect word;
[0034] The aspect words in the text of the original sample are replaced with the predicted aspect words to obtain an enhanced sample; the enhanced sample is used to train an aspect word extraction model.
[0035] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0036] Obtaining original samples, each original sample includes text, aspect words in the text, and position information of the aspect words in the text;
[0037] Masking the aspect words in the text to obtain a masked text;
[0038] By using a pre-trained language model, predicting the aspect word position indicated by the position information according to the masked text and the position information, to obtain a predicted aspect word;
[0039] The aspect words in the text of the original sample are replaced with the predicted aspect words to obtain an enhanced sample; the enhanced sample is used to train an aspect word extraction model.
[0040] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0041] Obtaining original samples, each original sample includes text, aspect words in the text, and position information of the aspect words in the text;
[0042] Masking the aspect words in the text to obtain a masked text;
[0043] By using a pre-trained language model, predicting the aspect word position indicated by the position information according to the masked text and the position information, to obtain a predicted aspect word;
[0044] The aspect words in the text of the original sample are replaced with the predicted aspect words to obtain an enhanced sample; the enhanced sample is used to train an aspect word extraction model.
[0045] The training sample processing method, apparatus, computer equipment, storage medium and computer program product described above perform masking processing on the aspect words in the text of the original sample for each original sample to obtain the masked text, predict the predicted aspect words corresponding to the masked aspect word positions in the masked text through a pre-trained language model, use the predicted aspect words to replace the aspect words in the text of the original sample, generate an enhanced sample containing new aspect words, use the enhanced samples to train an aspect word extraction model, so that the aspect word extraction model can extract new aspect words; and when the aspect words are masked, the number of masked words is less than the corresponding number of masked words when the context of the aspect words is masked, and the degree of damage to the text is less, thereby improving the prediction accuracy of the pre-trained language model, and improving the quality of the enhanced samples generated by the pre-trained language model, thereby improving the accuracy of the aspect word extraction model in extracting aspect words from the text.
[0046] In a sixth aspect, the present application also provides a method for training a language model, the method comprising:
[0047] Acquire training samples, each training sample comprising a text, an aspect word in the text, and position information of the aspect word in the text;
[0048] Masking the aspect words in the text to obtain a masked text;
[0049] Initializing a language model, performing aspect word prediction on the aspect word position indicated by the position information according to the masked text and the position information, to obtain a predicted aspect word;
[0050] According to the difference between the predicted aspect words and the aspect words in the text of the training sample, a sample loss is constructed, and the initialized language model is updated according to the sample loss to obtain a pre-trained language model; the pre-trained language model is used to predict aspect words for the masked text.
[0051] In a seventh aspect, the present application also provides a language model training device. The device comprises:
[0052] A training sample acquisition module, used to acquire training samples, each training sample includes a text, an aspect word in the text, and position information of the aspect word in the text;
[0053] A training sample masking module is used to perform masking processing on the aspect words in the text to obtain a masked text;
[0054] A training sample prediction module is used to predict the aspect word position indicated by the position information according to the masked text and the position information by initializing the language model to obtain a predicted aspect word;
[0055] The model updating module is used to construct a sample loss according to the difference between the predicted aspect words and the aspect words in the text of the training sample, and to update the initialized language model according to the sample loss to obtain a pre-trained language model; the pre-trained language model is used to predict aspect words for the masked text.
[0056] In one of the embodiments, the position information includes a mark indicating whether each word in the text is an aspect word, and marks corresponding to the starting position and the ending position of the aspect word in the text; the training device also includes: a training sample position marking module, the training sample position marking module is used to insert a position tag for locating the aspect word in the masked text to obtain a labeled text; insert a label tag corresponding to the position tag into the position information to obtain a labeled labeled position information.
[0057] The training sample prediction module is also used to: initialize the language model, perform aspect word prediction on the aspect word position indicated by the position information according to the labeled text and the label tokenized position information, and obtain the predicted aspect word.
[0058] In one of the embodiments, the training sample masking module is further used to: obtain a preset masking rate, determine the number of aspect words in the text to be masked based on the total number of aspect words in the text and the preset masking rate; and based on the determined number, randomly sample aspect words from the text and perform masking to obtain the masked text.
[0059] In one of the embodiments, the training sample prediction module is further used to: perform semantic encoding according to the masked text and position information through an encoder of a pre-trained language model to obtain a semantic representation corresponding to the text;
[0060] Through the decoder of the pre-trained language model, semantic decoding is performed according to the context of the indicated aspect word position and the semantic representation corresponding to the text to obtain the predicted aspect word.
[0061] In one embodiment, the training sample prediction module is further used to: predict the probability distribution corresponding to each aspect word position indicated by the position information according to the masked text and the position information by initializing the language model, wherein the probability distribution represents the probability that each word in the vocabulary is the predicted aspect word of the aspect word position;
[0062] For each aspect word position, the predicted aspect word corresponding to the aspect word position is determined from the vocabulary by probability.
[0063] In an eighth aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0064] Acquire training samples, each training sample comprising a text, an aspect word in the text, and position information of the aspect word in the text;
[0065] Masking the aspect words in the text to obtain a masked text;
[0066] Initializing a language model, performing aspect word prediction on the aspect word position indicated by the position information according to the masked text and the position information, to obtain a predicted aspect word;
[0067] According to the difference between the predicted aspect words and the aspect words in the text of the training sample, a sample loss is constructed, and the initialized language model is updated according to the sample loss to obtain a pre-trained language model; the pre-trained language model is used to predict aspect words for the masked text.
[0068] In a ninth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0069] Acquire training samples, each training sample comprising a text, an aspect word in the text, and position information of the aspect word in the text;
[0070] Masking the aspect words in the text to obtain a masked text;
[0071] Initializing a language model, performing aspect word prediction on the aspect word position indicated by the position information according to the masked text and the position information, to obtain a predicted aspect word;
[0072] According to the difference between the predicted aspect words and the aspect words in the text of the training sample, a sample loss is constructed, and the initialized language model is updated according to the sample loss to obtain a pre-trained language model; the pre-trained language model is used to predict aspect words for the masked text.
[0073] In a tenth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0074] Acquire training samples, each training sample comprising a text, an aspect word in the text, and position information of the aspect word in the text;
[0075] Masking the aspect words in the text to obtain a masked text;
[0076] Initializing a language model, performing aspect word prediction on the aspect word position indicated by the position information according to the masked text and the position information, to obtain a predicted aspect word;
[0077] According to the difference between the predicted aspect words and the aspect words in the text of the training sample, a sample loss is constructed, and the initialized language model is updated according to the sample loss to obtain a pre-trained language model; the pre-trained language model is used to predict aspect words for the masked text.
[0078] The training method, apparatus, computer equipment, storage medium and computer program product of the above-mentioned language model, when masking aspect words, the number of masked words is smaller than the corresponding number of masked words when masking the context of the aspect words, and the degree of damage to the text is smaller, thereby improving the prediction accuracy of the initialized language model; according to the difference between the predicted aspect words and the aspect words in the text of the training sample, a sample loss is constructed, and the initialized language model is updated according to the sample loss to obtain a pre-trained language model, so that the potential of the pre-trained language model can be fully exploited to predict new aspect words, not limited to the aspect words that have appeared in the training sample, and the accuracy of aspect word prediction for the masked text can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0079] Figure 1 is an application environment diagram of a training sample processing method in an embodiment;
[0080] Figure 2 is a flow chart of a training sample processing method in one embodiment;
[0081] Figure 3 A schematic diagram of a framework for obtaining predicted aspect words for a pre-trained language model in related technologies;
[0082] Figure 4 A schematic diagram of a framework for obtaining predicted aspect words from a pre-trained language model in one embodiment;
[0083] Figure 5 A schematic diagram of labeling text of an original sample in one embodiment;
[0084] Figure 6 A flowchart of obtaining the masked text of the original sample in one embodiment;
[0085] Figure 7 A flowchart of obtaining predicted aspect words in an original sample in one embodiment;
[0086] Figure 8A flowchart of obtaining predicted aspect words in an original sample in another embodiment;
[0087] Fig. 9 A flowchart of enhancing sample denoising in one embodiment;
[0088] Fig.10 A training graph of a pre-trained language model in one embodiment;
[0089] Fig.11 is a detailed flowchart of a training sample processing method in an embodiment;
[0090] Fig.12 A flowchart of a method for training a language model in one embodiment;
[0091] Fig.13 A flowchart of obtaining the masked text of a training sample in an embodiment;
[0092] Fig.14 A flowchart of obtaining predicted aspect words in a training sample in one embodiment;
[0093] Fig.15 A flowchart for obtaining predicted aspect words in training samples in another embodiment;
[0094] Fig.16 A detailed flowchart of a method for training a language model in an embodiment;
[0095] Fig.17 is a structural diagram of a training sample processing device in one embodiment;
[0096] Fig.18 is a structural diagram of a training device for a language model in one embodiment;
[0097] Fig.19 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0098] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0099] Artificial Intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science that attempts to understand the essence of intelligence and produce a new intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines so that machines have the functions of perception, reasoning and decision-making.
[0100] Artificial intelligence technology is a comprehensive discipline that covers a wide range of fields, including both hardware-level and software-level technologies. The basic technologies of artificial intelligence generally include sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics and other technologies. Artificial intelligence software technology mainly includes computer vision technology, speech processing technology, natural language processing technology, and machine learning / deep learning.
[0101] Some terms involved in the embodiments of the present application are explained:
[0102] Data augmentation: In the embodiments of the present application, it refers to making slight changes to the original samples to increase the number of training samples, avoid overfitting, improve model robustness, improve model generalization ability, avoid sample imbalance, etc.
[0103] CNNs: Convolutional Neural Networks.
[0104] Aspect words: refers to the object to which the sentiment polarity belongs, i.e. aspect. That is, for aspect words, there can be some sentiment polarity (such as positive, negative or neutral). For example, in the text "This computer is very fast", "speed" is an aspect word, and "very fast" is the sentiment polarity. For example, in the text "The ramen in that restaurant is delicious, and the service attitude is also good", "ramen" and "service attitude" are both aspect words, and "very delicious" and "good" are the sentiment polarities.
[0105] ATE: Aspect Term Extraction, aspect term extraction.
[0106] Aspect word extraction is one of the most important subtasks in aspect-level sentiment analysis, which aims to find opinion targets from comment texts. Obviously, the performance of the aspect word extraction model is closely related to the quality of the training samples. In the related art, in order to generate enhanced samples, the context of the aspect words in the text of the original sample is masked to generate pseudo samples. However, this method cannot fully tap the potential of the language model and cannot identify new aspect words. Moreover, this method always destroys existing sentence components, and the quality of the generated enhanced samples is poor, making it difficult to improve the performance of the aspect word extraction model. The method provided in the embodiment of the present application can generate high-quality enhanced samples without destroying the sentence components, thereby effectively improving the performance of the aspect word extraction model.
[0107] The training sample processing method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other servers. The server 104 receives the training sample processing instruction sent by the terminal 102, and obtains the original sample from the data storage system, wherein the original sample includes text, aspect words in the text, and position information of the aspect words in the text; the server 104 masks the aspect words in the text to obtain the masked text; the server 104 predicts the aspect word position indicated by the position information according to the masked text and position information through the pre-trained language model, and obtains the predicted aspect word; the server 104 replaces the aspect words in the text of the original sample with the predicted aspect word to obtain an enhanced sample; wherein the enhanced sample is used to train the aspect word extraction model.
[0108] The terminal 102 may be, but is not limited to, various desktop computers, laptop computers, smart phones, tablet computers, IoT devices, and portable wearable devices. The IoT devices may be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. The portable wearable devices may be smart watches, smart bracelets, head-mounted devices, etc. The server 104 may be implemented as an independent server or a server cluster consisting of multiple servers.
[0109] In one embodiment, Figure 2 As shown, a training sample processing method is provided, which is applied to Figure 1 Taking the computer device (such as server 104) in the example as an example, the following steps are included:
[0110] Step 202: obtaining original samples, each of which includes text, aspect words in the text, and position information of the aspect words in the text.
[0111] The original sample refers to the training sample in the original sample set. Compared with the enhanced sample, the aspect words in the text of the original sample are the original aspect words, and the aspect words in the text of the enhanced sample are the aspect words that have been replaced and updated. Each original sample includes text, aspect words in the text, and position information of the aspect words in the text. The text in the original sample can be text in various languages, or contain text in various languages. For example, the text can be text information such as sentences and articles containing comment data.
[0112] Aspect refers to the object to which the sentiment polarity belongs, that is, what kind of sentiment polarity (positive, negative or neutral) it has for the aspect. For example, in "This computer is very fast", "speed" is an aspect word, and "very fast" is the sentiment polarity. For example, in "The ramen in that restaurant is delicious and the service attitude is also good", "ramen" and "service attitude" are both aspect words, and "very delicious" and "good" are the sentiment polarities.
[0113] In one embodiment, the position information of aspect words in a text can be determined by the positions of aspect words and non-aspect words in the text. The server can assign different tags to aspect words and non-aspect words, thereby determining the position information of aspect words in the text. For example, for aspect words and non-aspect words, the server can adopt different tag strategies, and use different tags to distinguish the starting position and ending position of aspect words. Specifically, label O is used to represent the position of non-aspect words in the text, label B is used to represent the starting position of aspect words in the text, label E is used to represent the ending position of aspect words in the text, and according to the arrangement order of each word in the text, a corresponding label is assigned to each word to obtain the position information L. For example, for the text "their pad penang is delicious.", the aspect word is "pad penang", and the corresponding position information L is: OBEOOO. For example, for the text "this computer is very fast", the aspect word is "speed", and the corresponding position information L is: OO OO OBEOOO.
[0114] Specifically, the server can obtain the original sample from the database, or from the server providing data services. The server can also obtain the original sample uploaded by the terminal. The server can also obtain the original sample provided by the business party.
[0115] Step 204: mask the aspect words in the text to obtain the masked text.
[0116] The purpose of masking is to mask out the aspect words in the text, so that the pre-trained language model can predict the words at the masked position by combining the context information of the aspect words in the text without the information of the aspect words themselves. The server can replace the aspect words in the text with preset tags to indicate that the aspect words are masked. For example, the server can use [MASK] to mask the aspect words in "their pad penang is delicious.", and the masked text is "their[MASK][MASK]is delicious.". For example, the server can use [MASK] to mask the aspect words in "this computer is very fast", and the masked text is "this computer's [MASK] is very fast".
[0117] Specifically, the server uses [MASK] to mask each word in the aspect words of the text to obtain the masked text.
[0118] Step 206 , using a pre-trained language model, predict the aspect word at the position of the aspect word indicated by the position information according to the masked text and the position information to obtain a predicted aspect word.
[0119] As mentioned above, the masked text can express the context information of aspect words, and the position information of the original sample indicates whether each word in the original sample text belongs to an aspect word, as well as the starting position and ending position of the aspect word in the text. For example, label O is used to represent the position in the text that does not belong to an aspect word; label B and label E are used to represent the starting position and ending position of the aspect word in the text, respectively.
[0120] The server can use a pre-trained language model to predict the predicted aspect words corresponding to the masked aspect word positions according to the masked text and the position information of the original sample, and then use the predicted aspect words to replace the aspect words in the text of the original sample to obtain an enhanced sample. The pre-trained language model can be built based on a convolutional neural network or a Transformer model.
[0121] like Figure 3 , which is a schematic diagram of the framework of the language model predicting aspect words in the related art. Figure 3In the related art, taking the text X in the original sample as "the screen is bright and the mouse is nice." as an example, the specific process of using the language model to generate enhanced samples is as follows: the position information L corresponding to the text X in the original sample is: OBO OO OBOOO, which only indicates the position of the aspect words and non-aspect words in the text, and does not indicate the starting position and ending position of the aspect words. Mask the words in the text X except the aspect words (i.e., replace them with [M]) to obtain the masked text The masked text and aspect word annotation information are input into the encoder of the language model to obtain the semantic expression corresponding to the text; the context "is bright and the mouse" of the indicated non-aspect word position and the semantic expression corresponding to the text are input into the decoder of the language model, and the context of the aspect words is predicted by the language model. The predicted context is "bright and the mouse is", and the predicted context is used to replace the context of the aspect words in the original sample to obtain an enhanced sample.
[0122] In this method, since the aspect words in the original sample are not masked, the aspect words in the text are always fixed for the language model, and no new aspect words are generated. Only the context of the aspect words is newly predicted, so the language model cannot recognize new aspect words, and the more masked words are, the more severely the text is damaged, resulting in lower prediction accuracy of the language model, and worse quality of enhanced samples generated by the language model, which in turn leads to lower accuracy of aspect word extraction by the aspect word extraction model. The embodiment of the present application masks the aspect words in the text to obtain the masked text, predicts the predicted aspect words corresponding to the masked aspect word positions in the masked text through a pre-trained language model, and uses the predicted aspect words to replace the aspect words in the text of the original sample to generate an enhanced sample containing new aspect words. Therefore, the pre-trained language model can recognize new aspect words. In addition, when masking aspect words, the number of masked words is smaller than the corresponding number of masked words when masking the context of the aspect words, which causes less damage to the text, improves the prediction accuracy of the pre-trained language model, and improves the quality of enhanced samples generated by the pre-trained language model, thereby improving the accuracy of the aspect word extraction model in extracting aspect words from the text.
[0123] like Figure 4 FIG. 1 is a schematic diagram of a framework for predicting aspect words through a pre-trained language model in one embodiment. Figure 4, taking the text in the original sample as "their pad penang is delicious." as an example, the position information L corresponding to the original sample is: OBEOOO, and the masked text is "their[MASK][MASK]isdelicious.". The masked text and the corresponding position information are input into the pre-trained language model, and the pre-trained language model outputs the predicted aspect word.
[0124] The indicated aspect word position refers to the position information of the aspect word in the text. It should be noted that: since the aspect word includes at least one character, for example, the aspect word in the text "The flowers in this store are very fresh" is flower, and the aspect word in the text "The ramen in this store is delicious" is ramen. When the aspect word is a character, the indicated aspect word position only refers to the position of the aspect word in the text, and the predicted aspect word predicted by the server through the pre-trained language model is also a word, and there is no order of characters; if the aspect word includes multiple characters, the indicated aspect word position refers to the position information of each character in the aspect word. The server predicts the first character of the aspect word at the indicated aspect word position based on the semantic expression of the context of the aspect word in the text through the pre-trained language model, and the second character of the aspect word at the indicated aspect word position based on the masked text and the semantic expression of the first character, and so on, to obtain the last character of the aspect word at the indicated aspect word position, and sort the predicted single characters according to the prediction order to obtain the predicted aspect word.
[0125] Specifically, the server inputs the masked text and the position information corresponding to the text into the pre-trained language model. The server predicts the first character of the aspect word at the indicated aspect word position based on the semantic expression of the context of the aspect word in the text through the pre-trained language model, and predicts the second character of the aspect word at the indicated aspect word position based on the masked text and the semantic expression of the first character, and so on, to obtain the last character of the aspect word at the indicated aspect word position, and sorts the predicted single characters in the prediction order to obtain the predicted aspect word.
[0126] Step 208: replace the aspect words in the text of the original sample with the predicted aspect words to obtain an enhanced sample; the enhanced sample is used to train the aspect word extraction model.
[0127] Among them, the aspect word extraction model is used to extract aspect words from the text. The aspect word extraction model can be built based on the Transformer model, the BERT model (Bidirectional Encoder Representation from Transformers), the CNN model (convolutional neural model) and the LSTM model (Long Short Term Memory, a neural network with the ability to remember long-term and short-term information).
[0128] Specifically, the server obtains the predicted aspect words output by the pre-trained language model, and replaces the aspect words in the text of the original sample with the predicted aspect words to obtain an enhanced sample.
[0129] In one embodiment, in the dataset Laptop and the dataset Restaurant, aspect word extraction models based on different model frameworks are used to extract aspect words from the original samples and enhanced samples. The accuracy of the aspect word extraction models of different model frameworks is shown in the following table:
[0130]
[0131] Among them, the BiLSTM-CRF model is mainly composed of a bidirectional long short-term memory network (Bi-LSTM) and a conditional random field (CRF); the Seq2Seq4ATE model is a model used when the output length is uncertain; the BERT-FTC model and the BERT-PT model belong to the BERT model; and DE-CNN is a convolutional neural network.
[0132] In the datasets Laptop and Restaurant, different enhancements are used to obtain enhanced samples. For example, the enhanced samples are obtained by replacing the aspect words in the original text with synonyms, and the enhanced samples are recorded as DATA_synonym; the enhanced samples generated by the BERT model are recorded as DATA_BERT; the enhanced samples generated by GPT-2 (pre-trained language model) are recorded as DATA_GPT-2; the enhanced samples are obtained by replacing the aspect word context with masks, and the enhanced samples are recorded as DATA_Context; the enhanced samples are obtained by replacing the aspect words with masks, and the enhanced samples are recorded as DATA_Aspect. Based on F1 (an indicator for measuring model accuracy), BLEU (an indicator for evaluating model translation quality) and fluency, the quality of enhanced samples obtained by different enhancement methods is evaluated as shown in the following table:
[0133] Dataset Laptop Restaurant Source 81.08 / 100.00 / 203 74.75 / 100.00 / 158 DATA_synonym 76.93 / 76.68 / 558 73.74 / 78.22 / 438 DATA_BERT 79.32 / 69.93 / 461 74.30 / 68.57 / 435 DATA_GPT-2 66.09 / 54.86 / 328 63.30 / 58.60 / 314 DATA_Context 80.61 / 69.70 / 242 75.41 / 68.42 / 257 DATA_Aspect 82.69 / 50.33 / 150 77.98 / 50.24 / 160
[0134] Among them, the first value under the dataset Laptop and the dataset Restaurant represents the score of the F1 index; the second value represents the score corresponding to the BLEU index; and the third value represents the score corresponding to the fluency. For example, the F1 index, BLEU index, and fluency corresponding to the DATA_synonym enhanced sample in the dataset Laptop are 76.93, 76.68, and 558, respectively.
[0135] By comparing the above table, it can be seen that: the present application performs masking on the aspect words in the text, predicts the predicted aspect words corresponding to the masked text through a pre-trained language model, and uses the predicted aspect words to replace the original aspect words in the text to obtain enhanced samples, thereby improving the performance of the aspect word extraction model, so that the accuracy of the present application method on multiple general data sets (for example, Laptop, Restaurant) exceeds the best existing aspect word extraction models, such as BERT-PT.
[0136] In the above training sample processing method, the aspect words in the text are masked to obtain the masked text, the predicted aspect words corresponding to the positions of the masked aspect words in the masked text are predicted by a pre-trained language model, the predicted aspect words are used to replace the aspect words in the text of the original sample, and an enhanced sample containing new aspect words is generated, and the aspect word extraction model is trained using the enhanced samples, so that the aspect word extraction model can extract new aspect words; and when the aspect words are masked, the number of masked words is less than the corresponding number of masked words when the context of the aspect words is masked, and the degree of damage to the text is less, thereby improving the prediction accuracy of the pre-trained language model, and improving the quality of the enhanced samples generated by the pre-trained language model, thereby improving the accuracy of the aspect word extraction model in extracting aspect words from the text.
[0137] In some cases, after replacing the original aspect words with the predicted aspect words predicted by the pre-trained language model, the position information of the obtained text is inconsistent with the position information corresponding to the original sample. For example, the text of the original sample is "theirpad penang is delicious.", and the corresponding position information L is: OBEOOO, where "pad penang" is a masked aspect word. When predicted by the pre-trained language model, the predicted aspect word obtained is "new apple", where "apple" is an aspect word, but "new" is not an aspect word, so the label corresponding to "new" is O, which is inconsistent with the label B of "pad". In this way, the position information of the original sample and the enhanced sample is different.
[0138] In order to minimize the generation of words that are incompatible with the position information of the original sample, the matching degree between the enhanced sample and the position information is improved, thereby improving the quality of the enhanced sample. In one embodiment, the position information of the original sample includes a mark of whether each word in the text belongs to an aspect word, and also includes marks corresponding to the starting position and the ending position of the aspect word in the text. The above method also includes: inserting a position tag for locating the aspect word in the masked text to obtain a labeled text; inserting a label tag corresponding to the position tag in the position information to obtain label-tokenized position information.
[0139] In this embodiment, position tags can be inserted before and after the aspect words in the masked text, and the position tags can be regarded as normal context tags to further enhance the position information of the aspect words in the text, so that the pre-trained language model can accurately determine the position of the aspect words in the text based on the inserted position tags when predicting. The position tags can be expressed in the form of tags that are semantically related to the tag name. For example, if the tag name is the aspect word start position and the aspect word end position, the position tags can be<aspect_start> and<aspect_end> , the corresponding labels are A_B and A_E. For example, the masked text "their[MASK][MASK]is delicious." Figure 5 As shown in the figure, position tags are inserted before and after the aspect words, and the resulting labeled text is: "their<aspect_start> [MASK][MASK]<aspect_end> is delicious.", insert the label tag corresponding to the location tag into the location information, and get the label-tokenized location information: O A_B BE A_E OOO.
[0140] Specifically, the server adds position tags for locating aspect words before and after aspect words in the masked text to obtain labeled text; in the position information corresponding to the masked text, the server inserts a label mark corresponding to the position tag at the position corresponding to the position tag to obtain labeled labeled position information.
[0141] In some embodiments, step 206, i.e., predicting the aspect word position indicated by the position information according to the masked text and the position information through the pre-trained language model to obtain the predicted aspect word, includes the following steps:
[0142] Through the pre-trained language model, the aspect word position indicated by the position information is predicted according to the labeled text and the label-tokenized position information to obtain the predicted aspect word.
[0143] Specifically, the server inputs the labeled text and the label tokenized position information into the pre-trained language model. The server predicts the first character of the aspect word at the indicated aspect word position based on the semantic expression of the context of the aspect word in the text through the pre-trained language model, and predicts the second character of the aspect word at the indicated aspect word position based on the labeled text and the semantic expression of the first character, and so on, to obtain the last character of the aspect word at the indicated aspect word position, and sorts the predicted single characters in the prediction order to obtain the predicted aspect word.
[0144] In this embodiment, a labeled text is obtained by inserting a position tag for locating aspect words into the masked text; a label mark corresponding to the position tag is inserted into the position information to obtain label-tagged position information; and an aspect word position indicated by the position information is predicted by a pre-trained language model based on the labeled text and the label-tagged position information to obtain a predicted aspect word. This can improve the recognition efficiency of the pre-trained language model for aspect words in the text, minimize the number of tagged words that are incompatible with the original labels, and avoid the problem that the position information of the predicted aspect words output by the pre-trained language model is inconsistent with the position information of the original sample.
[0145] The text includes n aspect words, where n is a natural number greater than 1. If all aspect words in the text are masked, the text will be greatly damaged, and the prediction accuracy of the pre-trained language model will be reduced, as well as the quality of the enhanced samples generated by the pre-trained language model, thereby reducing the accuracy of the aspect word extraction model in extracting aspect words from the text. Therefore, to solve the above problem, in one embodiment, the aspect words in the text are randomly masked according to a preset masking rate. Specifically, Figure 6 As shown, masking is performed on the aspect words in the text to obtain the masked text, including the following steps:
[0146] Step 602: Obtain a preset masking rate, and determine the number of aspect words in the text to be masked according to the total number of aspect words in the text and the preset masking rate.
[0147] The preset masking rate is the ratio between the number of masked aspect words in the text and the total number of aspect words in the text.
[0148] Specifically, the server may obtain a preset masking rate that is manually set or obtained from a database, and determine the number of aspect words in the text to be masked according to the product of the total number of aspect words in the text and the preset masking rate.
[0149] In some embodiments, the preset mask rate may be a fixed mask rate or a dynamic mask rate. In order to increase the diversity of enhanced samples, in this embodiment, the preset mask rate is a dynamic mask rate, and the dynamic mask rate is obtained by randomly sampling a dynamic mask rate ε from a Gaussian distribution N(μ,σ2), where the Gaussian variance σ2 is set to 1 / n2.
[0150] Step 604: randomly sample aspect words from the text according to the determined quantity and perform masking processing to obtain masked text.
[0151] Specifically, after the server determines the number of masks required for the current text, it randomly samples aspect words that are the same as the determined number from the text and performs masking processing to obtain the masked text.
[0152] In this embodiment, the number of aspect words in the text to be masked is determined based on the total number of aspect words in the text and a preset masking rate, and based on the determined number, aspect words are randomly sampled from the text and masked to obtain the masked text; wherein the preset masking rate may be a dynamic masking rate, and the dynamic masking rate is used to perform masking on the same text multiple times, and after each masking, the pre-trained language model outputs different predicted aspect words, thereby generating more different enhanced samples and improving the diversity of the enhanced samples.
[0153] In one embodiment, Figure 7 As shown, by using a pre-trained language model, aspect word prediction is performed on the aspect word position indicated by the position information according to the masked text and position information to obtain the predicted aspect word, including the following steps:
[0154] Step 702, using the encoder of the pre-trained language model, semantic encoding is performed based on the masked text and position information to obtain a semantic representation corresponding to the text.
[0155] The position information may be position information used to locate the position of each word in the text. The semantic representation corresponding to the text refers to the semantic information corresponding to each word in the text.
[0156] Specifically, the server inputs the masked text and position information into the encoder of the pre-trained language model, and the encoder semantically encodes the masked text to obtain the semantic information corresponding to each word in the text.
[0157] Step 704 , using the decoder of the pre-trained language model, semantic decoding is performed according to the context of the indicated aspect word position and the semantic representation corresponding to the text to obtain a predicted aspect word.
[0158] Among them, the decoder is generated sequence to sequence, that is, according to the previous word, the decoding generates the next word (teacherforcing), so the context of the indicated aspect word position needs to be input into the decoder, and the decoder performs semantic decoding according to the context of the indicated aspect word position and the semantic expression corresponding to the text, outputs the first word in the aspect word, and then performs semantic decoding according to the first word of the aspect word and the semantic expression corresponding to the text, outputs the second word in the aspect word, and according to the same principle, outputs the last word in the aspect word, and sorts the predicted single words according to the prediction order to obtain the predicted aspect word.
[0159] For example, Figure 4 Taking the text "their pad penang is delicious." as an example, the corresponding position information L is: OBEOOO, and the masked text is "their[MASK][MASK]is delicious.". The masked text and the corresponding position information are input into the encoder of the pre-trained language model, and the semantic expression of the encoder output text and the embedded expression corresponding to the above "their pad penang" at the indicated aspect word position are input into the decoder of the pre-trained language model. The decoder outputs a predicted "pad" according to "their" and the semantic expression of the encoder output text. The decoder outputs a predicted "penang" according to the embedded expression of "pad" and the semantic expression of the encoder output text, and the results are sorted in the predicted order to obtain the predicted aspect word "pad penang". Furthermore, the embedded expression corresponding to the context of the indicated aspect word position can also be used to calculate the training loss of the pre-trained language model to reversely update the pre-trained language model parameters. The embedded expression corresponding to the context "their pad penang" of the indicated aspect word position is used for decoding; the "pad penang" input to the encoder is used to calculate the training loss. The specific method is: according to the deviation between the output of the decoder and the input "pad peang", the error value is calculated, and the pre-trained language model parameters are reversely updated according to the error value.
[0160] Specifically, the server inputs the semantic representation corresponding to the text output by the encoder and the context of the aspect word position indicated by the position information of the aspect word in the original text into the decoder. The server performs semantic decoding through the decoder according to the context of the indicated aspect word position and the semantic expression corresponding to the text, obtains the first word of the aspect word at the indicated aspect word position, and then performs semantic decoding according to the first word and the semantic expression corresponding to the masked text, obtains the second word of the aspect word at the indicated aspect word position, and so on, obtains the last word in the predicted aspect word, sorts the predicted single words according to the prediction order, and obtains the predicted aspect word.
[0161] In this embodiment, the semantic representation corresponding to the text is obtained through the encoder, and the decoder performs semantic decoding according to the context of the aspect word position indicated in the position information and the semantic representation corresponding to the text to obtain the first word of the aspect word at the indicated aspect word position, and then performs semantic decoding according to the first word and the semantic expression corresponding to the text to obtain the second word of the aspect word at the indicated aspect word position, and so on to obtain the last word in the predicted aspect word, and sort the predicted single words in the prediction order to obtain the predicted aspect word. The predicted aspect word is obtained by sequence-to-sequence learning, which can improve the prediction accuracy of the pre-trained language model.
[0162] Since there is a situation where the predicted aspect words output by the pre-trained language model are the same as the aspect words in the original sample text, when determining the predicted aspect words, if the most likely predicted aspect words are directly selected to replace the aspect words in the original sample text, it is possible to return to the original sample and fail to generate a new enhanced sample. Therefore, to solve the above problem, in one embodiment, Figure 8 The method of performing aspect word prediction on the aspect word position indicated by the position information according to the masked text and the position information through the pre-trained language model to obtain the predicted aspect word includes the following steps:
[0163] Step 802, predicting the probability distribution corresponding to each aspect word position indicated by the position information based on the masked text and the position information through the pre-trained language model, wherein the probability distribution represents the probability that each word in the vocabulary is the predicted aspect word position.
[0164] The vocabulary table refers to a table containing multiple aspect words classified by categories.
[0165] The pre-trained language model predicts the probability distribution corresponding to each aspect word position indicated by the position information based on the following function:
[0166]
[0167] Among them, X is the text in the original sample; is the masked text; x i represents the i-th aspect word in the vocabulary; θ refers to the model parameter; n refers to the length of the aspect word; Represents the i-th aspect word x in the vocabulary i As masked text The probability of the aspect word; m i Represents the mark bit, represented by 0 or 1, where 0 represents an unmarked word and 1 represents a marked word.
[0168] Specifically, the server predicts the aspect word position indicated by the position information based on the masked text and the position information through the pre-trained language model, and obtains the probability that each word in the vocabulary is the predicted aspect word at the aspect word position.
[0169] Step 804, for each aspect word position, select k candidate words from the vocabulary according to probability, and randomly sample a word from the k candidate words as the predicted aspect word corresponding to the aspect word position; wherein k is a natural number greater than 1.
[0170] Among them, the k candidate words are the first k most likely candidate words in the probability distribution output by the pre-trained language model, that is, when the probabilities are sorted from large to small, the candidate words corresponding to the first k probabilities are selected.
[0171] For example, if the text in the original sample is "their pad penang is delicious.", the pre-trained language model may predict: pad penang: 0.31; Coi sandwich: 0.3; MacBook pro: 0.2; ... For example, the top 3 predicted aspect words with the highest probability are: pad penang, Coi sandwich, MacBook pro. Then, randomly select one of them, such as Coi sandwich, and replace the original sentence to generate the enhanced sample "their coi sandwich is delicious." Use the enhanced samples to train the aspect word extraction model.
[0172] Specifically, the server selects k candidate words from the vocabulary in descending order of probability, and the k candidate words form a candidate set Vik, where V represents the set of all aspect words in the vocabulary. A word is randomly sampled from the candidate set as the predicted aspect word corresponding to the aspect word position. The predicted aspect word is used to replace the aspect word in the text of the original sample to generate a new enhanced sample. For each original sample, the above process of generating enhanced samples is repeated to generate multiple enhanced samples.
[0173] In this embodiment, the probability distribution corresponding to each aspect word position indicated by the position information is predicted through a pre-trained language model, k candidate words are screened from the vocabulary in order of probability from large to small, and a word is randomly sampled from the k candidate words as the predicted aspect word corresponding to the aspect word position. This can reduce the probability that the predicted aspect word is the same as the aspect word in the text in the original sample, and avoid the situation where the predicted aspect word is the same as the aspect word in the text in the original sample, resulting in the generated enhanced sample being the same as the original sample, and failing to generate a new enhanced sample.
[0174] Since the enhanced samples are pseudo samples generated based on the original samples, there are still differences between them and the real samples, so there are noise and samples with less information in the enhanced samples. In order to improve the quality of the enhanced samples, in one embodiment, Fig. 9 As shown, after obtaining the enhanced sample, the following steps are also included:
[0175] Step 902: extract aspect words from the enhanced sample using the pre-trained aspect word extraction model to obtain aspect word extraction results, and determine the position information corresponding to the enhanced sample according to the aspect word extraction results.
[0176] The pre-trained aspect word extraction model is a model trained based on existing real samples. After the server extracts aspect words from the enhanced text through the pre-trained aspect word extraction model, it determines the mark of whether each word in the aspect word extraction result belongs to the aspect word, and the marks corresponding to the starting position and the ending position of the aspect word in the text, and determines the position information corresponding to the enhanced sample according to the marks corresponding to the aspect word extraction result.
[0177] Taking the enhanced text "their pad penang is delicious." as an example, the corresponding location information L is: OB EOOO. The pre-trained aspect word extraction model extracts aspect words for it and obtains the aspect word extraction result "padpenang", so the determined location information is OBEOOO.
[0178] Specifically, the server extracts aspect words from the enhanced sample through a pre-trained aspect word extraction model to obtain aspect word extraction results, assigns aspect word tags to the aspect words in the aspect word extraction results, and assigns non-aspect word tags to the non-aspect words in the aspect word extraction results, thereby obtaining location information of the enhanced sample.
[0179] Step 904 , screen out enhanced samples whose determined position information is consistent with the position information corresponding to the aspect words in the text of the corresponding original sample from the enhanced samples, and perform model training on the aspect word extraction model based on the screened enhanced samples.
[0180] Among them, since the enhanced sample is a pseudo sample generated based on the original sample, there is a situation where the aspect words in the enhanced sample are inconsistent with the aspect words corresponding to the original sample. For example, the text of the original sample is "their pad penangis delicious.", and the corresponding position information L is: OBEOOO, and the enhanced sample generated based on the original sample is "their new apple is delicious.". The enhanced sample is extracted from the aspect word extraction model through the pre-trained aspect word extraction model, and the aspect word extraction result is "new apple". The label corresponding to the aspect word extraction result is OE. The position information corresponding to the enhanced sample determined according to the aspect word extraction result is OOEOOO, which is inconsistent with the position information corresponding to the aspect word in the text of the original sample. Therefore, the enhanced sample "their new apple is delicious." does not meet the requirements and needs to be removed.
[0181] Specifically, the server obtains the position information corresponding to the aspect words in the text of the original sample corresponding to the enhanced sample from the database, and determines whether the position information corresponding to the aspect words in the text of the enhanced sample determined in step 902 is consistent with the position information corresponding to the aspect words in the text of the obtained original sample. If not, the enhanced sample is discarded; if consistent, the enhanced sample is retained, and the retained enhanced sample is used to perform model training on the aspect word extraction model.
[0182] In this embodiment, aspect words are extracted from enhanced samples through a pre-trained aspect word extraction model to obtain aspect word extraction results, and position information corresponding to the enhanced samples is determined based on the aspect word extraction results, and enhanced samples whose position information corresponding to the enhanced samples is consistent with the position information corresponding to the aspect words in the text of the corresponding original samples are screened and retained. The pre-trained aspect word extraction model can be used to remove enhanced samples containing noise and less information, thereby improving the quality of the enhanced samples used to train the aspect word extraction model, thereby improving the recognition accuracy of the aspect word extraction model.
[0183] In some embodiments, since the enhanced samples are pseudo samples generated based on the original samples, there are still differences between them and the real samples. Using the enhanced samples to train the aspect word extraction model causes the aspect word extraction model to overfit. Therefore, in order to effectively combine the enhanced samples, this embodiment trains the aspect word extraction model using the enhanced samples and the original samples in turn to obtain a trained aspect word extraction model.
[0184] Specifically, the server trains the aspect word extraction model based on the enhanced samples, and then trains the aspect word extraction model based on the original samples.
[0185] In this embodiment, the aspect word extraction model is trained by sequentially using enhanced samples and original samples, which can not only utilize the enhanced samples but also eliminate the negative impact of the enhanced samples on the aspect word extraction model.
[0186] In one embodiment, the training steps of the pre-trained language model include:
[0187] Step 1: Obtain training samples, each of which includes a text, an aspect word in the text, and position information of the aspect word in the text.
[0188] The training sample refers to the sample in the training sample set that has been annotated with aspect words in the text. Compared with the enhanced sample, the aspect words in the text of the training sample are the original aspect words, while the aspect words in the text of the enhanced sample are the aspect words that have been replaced and updated. Each training sample includes text, aspect words in the text, and location information of the aspect words in the text. The text in the training sample can be text in various languages, or contain text in various languages. For example, the text can be text information such as sentences and articles containing comment data.
[0189] Aspect refers to the object to which the sentiment polarity belongs, that is, what kind of sentiment polarity (positive, negative or neutral) it has for the aspect. For example, in "This computer is very fast", "speed" is an aspect word, and "very fast" is the sentiment polarity. For example, in "The ramen in that restaurant is delicious and the service attitude is also good", "ramen" and "service attitude" are both aspect words, and "very delicious" and "good" are the sentiment polarities.
[0190] In one embodiment, the position information of aspect words in a text can be determined by the positions of aspect words and non-aspect words in the text. The server can assign different labels to aspect words and non-aspect words, thereby determining the position information of aspect words in the text. For example, for aspect words and non-aspect words, the server can adopt different labeling strategies, and use different labels to distinguish the starting position and ending position of aspect words. Specifically, label O is used to represent the position of non-aspect words in the text, label B is used to represent the starting position of aspect words in the text, and label E is used to represent the ending position of aspect words in the text. According to the arrangement order of each word in the text, a corresponding label is assigned to each word to obtain the position information L. For example, Fig.10 As shown, for the text "their pad penang is delicious.", the aspect word is "pad penang", and the corresponding position information L is: OBEOOO. For example, for the text "this computer is very fast", the aspect word is "speed", and the corresponding position information L is: OOOOOBEOOO.
[0191] Specifically, the server can obtain training samples from a database, or from a server that provides data services. The server can also obtain training samples uploaded by a terminal. The server can also obtain training samples provided by a business party.
[0192] Step 2: Mask the aspect words in the text to obtain the masked text.
[0193] The purpose of masking is to mask out the aspect words in the text, so that the initialized language model can predict the words at the masked position by combining the context information of the aspect words in the text without the information of the aspect words themselves. The server can replace the aspect words in the text with preset tags to indicate that the aspect words are masked. For example, Fig.10 As shown in the figure, the server can use [MASK] to mask the aspect words in "their pad penang is delicious.", and the masked text is "their[MASK][MASK]is delicious.". For example, the server can use [MASK] to mask the aspect words in "this computer is very fast", and the masked text is "this computer's [MASK] is very fast".
[0194] Specifically, the server uses [MASK] to mask each word in the aspect words of the text to obtain the masked text.
[0195] Step 3, by initializing the language model, predicting the aspect word position indicated by the position information according to the masked text and the position information, and obtaining the predicted aspect word.
[0196] As mentioned above, the masked text can express the context information of aspect words, and the position information of the original sample indicates whether each word in the original sample text belongs to an aspect word, as well as the starting position and ending position of the aspect word in the text. For example, label O is used to represent the position in the text that does not belong to an aspect word; label B and label E are used to represent the starting position and ending position of the aspect word in the text, respectively.
[0197] The server can predict the predicted aspect words corresponding to the masked aspect word positions according to the masked text and the position information of the original sample by initializing the language model. The initialization language model can be built based on a convolutional neural network or a Transformer model.
[0198] The indicated aspect word position refers to the position information of the aspect word in the text. It should be noted that: since the aspect word includes at least one character, for example, the aspect word in the text "The flowers in this store are very fresh" is flower, and the aspect word in the text "The ramen in this store is delicious" is ramen. When the aspect word is a character, the indicated aspect word position only refers to the position of the aspect word in the text, and the predicted aspect word predicted by the server through the initialized language model is also a word, and there is no order of characters; if the aspect word includes multiple characters, the indicated aspect word position refers to the position information of each character in the aspect word, and the server predicts the first character of the aspect word at the indicated aspect word position according to the semantic expression of the context of the aspect word in the text through the initialized language model, and the second character of the aspect word at the indicated aspect word position according to the masked text and the semantic expression of the first character, and so on, to obtain the last character of the aspect word at the indicated aspect word position, and sort the predicted single characters according to the predicted order to obtain the predicted aspect word.
[0199] Specifically, the server inputs the masked text and the position information corresponding to the text into the initialized language model. The server predicts the first character of the aspect word at the indicated aspect word position according to the semantic expression of the context of the aspect word in the text through the initialized language model, and predicts the second character of the aspect word at the indicated aspect word position according to the masked text and the semantic expression of the first character. And so on, the server obtains the last character of the aspect word at the indicated aspect word position, and sorts the predicted single characters in the prediction order to obtain the predicted aspect word.
[0200] Step 4: According to the difference between the predicted aspect words and the aspect words in the text, a sample loss is constructed, and the initialized language model is updated according to the sample loss to obtain a pre-trained language model.
[0201] For example, Fig.10 As shown, the server predicts the aspect words at the positions of the aspect words indicated by the labels B and E in “their[MASK][MASK]isdelicious.” through the initialized language model, obtains the predicted aspect words, compares them with the original aspect words Y in the text, determines the difference between the predicted aspect words and the aspect words in the text, constructs the sample loss, updates the initialized language model according to the sample loss, and obtains the pre-trained language model.
[0202] Specifically, the server converts the predicted aspect words and the aspect words in the text into word vectors, constructs a sample loss based on the difference between the word vectors corresponding to the predicted aspect words and the word vectors corresponding to the aspect words in the text, and reversely updates the model parameters of the initialized language model based on the sample loss until the sample loss is less than a preset value, thereby obtaining a pre-trained language model.
[0203] In this embodiment, a sample loss is constructed according to the difference between the predicted aspect words and the aspect words in the text, and the initialized language model is updated according to the sample loss to obtain a pre-trained language model, thereby improving the accuracy of the pre-trained language model.
[0204] In one embodiment, Fig.11 As shown, this embodiment provides specific steps of a training sample processing method, which specifically includes the following steps:
[0205] Step 1: Obtain original samples, each of which includes text, aspect words in the text, and position information of the aspect words in the text.
[0206] Step 2, obtaining a preset masking rate, and determining the number of aspect words in the text to be masked according to the total number of aspect words in the text and the preset masking rate; and randomly sampling aspect words from the text according to the determined number and performing masking to obtain the masked text.
[0207] Step 3: insert a position tag for locating the aspect word into the masked text to obtain labeled text; insert a label tag corresponding to the position tag into the position information to obtain label-tokenized position information.
[0208] Step 4: Use the encoder of the pre-trained language model to perform semantic encoding based on the labeled text and the label tokenized position information to obtain the semantic representation corresponding to the text.
[0209] Step 5, through the decoder of the pre-trained language model, semantic decoding is performed according to the context of the indicated aspect word position and the semantic representation corresponding to the text, and the probability distribution corresponding to each aspect word position indicated by the label tokenized position information is predicted. The probability distribution represents the probability that each word in the vocabulary is the predicted aspect word of the aspect word position.
[0210] Step 6: for each aspect word position, k candidate words are selected from the vocabulary according to probability, and a word is randomly sampled from the k candidate words as the predicted aspect word corresponding to the aspect word position; wherein k is a natural number greater than 1.
[0211] Step 7: Replace the aspect words in the text of the original sample with the predicted aspect words to obtain an enhanced sample; the enhanced sample is used to train the aspect word extraction model.
[0212] Step 8, extract aspect words from the enhanced sample using the pre-trained aspect word extraction model to obtain aspect word extraction results, and determine the position information corresponding to the enhanced sample based on the aspect word extraction results.
[0213] Step 9: Filter out, from the enhanced samples, the enhanced samples whose determined position information is consistent with the position information corresponding to the aspect words in the text of the corresponding original sample.
[0214] Step 10, training the aspect word extraction model by using the screened enhanced samples and the original samples in turn, to obtain a trained aspect word extraction model.
[0215] In this embodiment, masking the aspect words causes less damage to the text than the context masking method, thereby improving the recognition accuracy of the initialization language model; inserting position tags for locating aspect words in the masked text can improve the recognition efficiency of the initialization language model for aspect words in the text, and minimize the number of generated marker words that are incompatible with the original tags;
[0216] Mask the aspect words in the original sample, predict the probability distribution corresponding to the position of the masked aspect words in the masked text through the pre-trained language model, and randomly select a candidate word from the probability distribution as the predicted aspect word. This can reduce the probability that the predicted aspect word is the same as the aspect word in the original sample text, and avoid the situation where the generated enhanced sample is the same as the original sample and cannot generate a new enhanced sample;
[0217] The enhanced samples are denoised using a pre-trained aspect word extraction model to obtain high-quality enhanced samples, and the aspect word extraction model is trained in two stages using the high-quality enhanced samples and the original samples in turn. The obtained aspect word extraction model can recognize new aspect words and improves the recognition accuracy of the aspect word extraction model.
[0218] The language model training method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other servers. The server 104 receives the training sample processing instruction sent by the terminal 102, and obtains the training sample from the data storage system, wherein the training sample includes the text, the aspect words in the text, and the position information of the aspect words in the text; the server 104 performs masking on the aspect words in the text to obtain the masked text; the server 104 uses the pre-trained language model to predict the aspect word position indicated by the position information according to the masked text and the position information, and obtains the predicted aspect word; the server 104 constructs a sample loss based on the difference between the predicted aspect word and the aspect word in the text of the training sample, and updates the initialized language model according to the sample loss to obtain the pre-trained language model; the pre-trained language model is used to predict the aspect words of the masked text.
[0219] The terminal 102 may be, but is not limited to, various desktop computers, laptop computers, smart phones, tablet computers, IoT devices, and portable wearable devices. The IoT devices may be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. The portable wearable devices may be smart watches, smart bracelets, head-mounted devices, etc. The server 104 may be implemented as an independent server or a server cluster consisting of multiple servers.
[0220] In one embodiment, if Fig.12 As shown, this embodiment provides a method for training a language model, and the method is applied to Figure 1 The computer device (such as server 104) in the example is used for explanation, and specifically includes the following steps:
[0221] Step 1202: Obtain training samples, each training sample including a text, an aspect word in the text, and position information of the aspect word in the text.
[0222] The training sample refers to the sample in the training sample set that has been annotated with aspect words in the text. Compared with the enhanced sample, the aspect words in the text of the training sample are the original aspect words, while the aspect words in the text of the enhanced sample are the aspect words that have been replaced and updated. Each training sample includes text, aspect words in the text, and location information of the aspect words in the text. The text in the training sample can be text in various languages, or contain text in various languages. For example, the text can be text information such as sentences and articles containing comment data.
[0223] Aspect refers to the object to which the sentiment polarity belongs, that is, what kind of sentiment polarity (positive, negative or neutral) it has for the aspect. For example, in "This computer is very fast", "speed" is an aspect word, and "very fast" is the sentiment polarity. For example, in "The ramen in that restaurant is delicious and the service attitude is also good", "ramen" and "service attitude" are both aspect words, and "very delicious" and "good" are the sentiment polarities.
[0224] In one embodiment, the position information of aspect words in a text can be determined by the positions of aspect words and non-aspect words in the text. The server can assign different labels to aspect words and non-aspect words, thereby determining the position information of aspect words in the text. For example, for aspect words and non-aspect words, the server can adopt different labeling strategies, and use different labels to distinguish the starting position and ending position of aspect words. Specifically, label O is used to represent the position of non-aspect words in the text, label B is used to represent the starting position of aspect words in the text, and label E is used to represent the ending position of aspect words in the text. According to the arrangement order of each word in the text, a corresponding label is assigned to each word to obtain the position information L. For example, Fig.10As shown, for the text "their pad penang is delicious.", the aspect word is "pad penang", and the corresponding position information L is: OBEOOO. For example, for the text "this computer is very fast", the aspect word is "speed", and the corresponding position information L is: OOOOOBEOOO.
[0225] Specifically, the server can obtain training samples from a database, or from a server that provides data services. The server can also obtain training samples uploaded by a terminal. The server can also obtain training samples provided by a business party.
[0226] Step 1204, masking the aspect words in the text to obtain the masked text.
[0227] The purpose of masking is to mask out the aspect words in the text, so that the initialized language model can predict the words at the masked position by combining the context information of the aspect words in the text without the information of the aspect words themselves. The server can replace the aspect words in the text with preset tags to indicate that the aspect words are masked. For example, Fig.10 As shown in the figure, the server can use [MASK] to mask the aspect words in "their pad penang is delicious.", and the masked text is "their[MASK][MASK]is delicious.". For example, the server can use [MASK] to mask the aspect words in "this computer is very fast", and the masked text is "this computer's [MASK] is very fast".
[0228] Specifically, the server uses [MASK] to mask each word in the aspect words of the text to obtain the masked text.
[0229] Step 1206 , by initializing the language model, predicting the aspect word position indicated by the position information according to the masked text and the position information, to obtain a predicted aspect word.
[0230] As mentioned above, the masked text can express the context information of aspect words, and the position information of the original sample indicates whether each word in the original sample text belongs to an aspect word, as well as the starting position and ending position of the aspect word in the text. For example, label O is used to represent the position in the text that does not belong to an aspect word; label B and label E are used to represent the starting position and ending position of the aspect word in the text, respectively.
[0231] The server can predict the predicted aspect words corresponding to the masked aspect word positions according to the masked text and the position information of the original sample by initializing the language model. The initialization language model can be built based on a convolutional neural network or a Transformer model.
[0232] The indicated aspect word position refers to the position information of the aspect word in the text. It should be noted that: since the aspect word includes at least one character, for example, the aspect word in the text "The flowers in this store are very fresh" is flower, and the aspect word in the text "The ramen in this store is delicious" is ramen. When the aspect word is a character, the indicated aspect word position only refers to the position of the aspect word in the text, and the predicted aspect word predicted by the server through the initialized language model is also a word, and there is no order of characters; if the aspect word includes multiple characters, the indicated aspect word position refers to the position information of each character in the aspect word, and the server predicts the first character of the aspect word at the indicated aspect word position according to the semantic expression of the context of the aspect word in the text through the initialized language model, and the second character of the aspect word at the indicated aspect word position according to the masked text and the semantic expression of the first character, and so on, to obtain the last character of the aspect word at the indicated aspect word position, and sort the predicted single characters according to the predicted order to obtain the predicted aspect word.
[0233] Specifically, the server inputs the masked text and the position information corresponding to the text into the initialized language model. The server predicts the first character of the aspect word at the indicated aspect word position according to the semantic expression of the context of the aspect word in the text through the initialized language model, and predicts the second character of the aspect word at the indicated aspect word position according to the masked text and the semantic expression of the first character. And so on, the server obtains the last character of the aspect word at the indicated aspect word position, and sorts the predicted single characters in the prediction order to obtain the predicted aspect word.
[0234] Step 1208, constructing a sample loss according to the difference between the predicted aspect words and the aspect words in the text of the training sample, updating the initialized language model according to the sample loss, and obtaining a pre-trained language model; the pre-trained language model is used to predict aspect words for the masked text.
[0235] For example, Fig.10 As shown, the server predicts the aspect words at the positions of the aspect words indicated by the labels B and E in “their[MASK][MASK]isdelicious.” through the initialized language model, obtains the predicted aspect words, compares them with the original aspect words Y in the text, determines the difference between the predicted aspect words and the aspect words in the text, constructs the sample loss, updates the initialized language model according to the sample loss, and obtains the pre-trained language model.
[0236] Specifically, the server converts the predicted aspect words and the aspect words in the text of the training sample into word vectors, constructs a sample loss based on the difference between the word vectors corresponding to the predicted aspect words and the word vectors corresponding to the aspect words in the text of the training sample, and reversely updates the model parameters of the initialized language model based on the sample loss until the sample loss is less than a preset value, thereby obtaining a pre-trained language model.
[0237] In this embodiment, when aspect words are masked, the number of masked words is smaller than the corresponding number of masked words when the context of the aspect words is masked, and the degree of damage to the text is smaller, thereby improving the prediction accuracy of the initialized language model; based on the difference between the predicted aspect words and the aspect words in the text of the training sample, a sample loss is constructed, and the initialized language model is updated based on the sample loss to obtain a pre-trained language model, thereby improving the accuracy of the pre-trained language model.
[0238] In some cases, after replacing the original aspect words with the predicted aspect words predicted by the initialized language model, the position information of the obtained text is inconsistent with the position information corresponding to the original sample. For example, the text of the original sample is "theirpad penang is delicious.", and the corresponding position information L is: OBEOOO, where "pad penang" is a masked aspect word. When predicted by the initialized language model, the predicted aspect word obtained is "new apple", where "apple" is an aspect word, but "new" is not an aspect word, so the label corresponding to "new" is O, which is inconsistent with the label B of "pad". In this way, the position information of the original sample and the enhanced sample is different.
[0239] In order to minimize the generation of words that are incompatible with the position information of the original sample, the matching degree between the enhanced sample and the position information is improved, thereby improving the quality of the enhanced sample. In one embodiment, the position information of the original sample includes a mark of whether each word in the text belongs to an aspect word, and also includes marks corresponding to the starting position and the ending position of the aspect word in the text. The above method also includes: inserting a position tag for locating the aspect word in the masked text to obtain a labeled text; inserting a label tag corresponding to the position tag in the position information to obtain label-tokenized position information.
[0240] The position information includes the mark of whether each word in the text is an aspect word, and the marks corresponding to the starting position and the ending position of the aspect word in the text. Although the position information of the aspect words in the text is marked in the original sample, the initialized language model still cannot recognize the position of the aspect words, resulting in the output predicted aspect word position information being inconsistent with the position information of the original sample.
[0241] In this embodiment, position tags can be inserted before and after the aspect words in the masked text, and the position tags can be regarded as normal context tags to further enhance the position information of the aspect words in the text, so that when the initialization language model predicts, it can accurately determine the position of the aspect words in the text based on the inserted position tags. The position tags can be expressed in the form of tags that are semantically related to the tag name. For example, if the tag name is the aspect word start position and the aspect word end position, the position tags can be<aspect_start> and<aspect_end> , the corresponding labels are A_B and A_E. For example, the masked text "their[MASK][MASK]is delicious." Figure 5 As shown in the figure, position tags are inserted before and after the aspect words, and the resulting labeled text is: "their<aspect_start> [MASK][MASK]<aspect_end> is delicious.", insert the label tag corresponding to the location tag into the location information, and get the label-tokenized location information: O A_B BE A_E OOO.
[0242] Specifically, the server adds position tags for locating aspect words before and after aspect words in the masked text to obtain labeled text; in the position information corresponding to the masked text, the server inserts a label mark corresponding to the position tag at the position corresponding to the position tag to obtain labeled labeled position information.
[0243] In some embodiments, step 1206, i.e., initializing the language model and performing aspect word prediction on the aspect word position indicated by the position information according to the masked text and the position information to obtain the predicted aspect word, includes the following steps:
[0244] By initializing the language model, aspect word prediction is performed on the aspect word position indicated by the position information according to the labeled text and the label-tokenized position information to obtain the predicted aspect word.
[0245] Specifically, the server inputs the labeled text and the label tokenized position information into the initialized language model. The server predicts the first character of the aspect word at the indicated aspect word position according to the semantic expression of the context of the aspect word in the text through the initialized language model, and predicts the second character of the aspect word at the indicated aspect word position according to the labeled text and the semantic expression of the first character, and so on, to obtain the last character of the aspect word at the indicated aspect word position, and sorts the predicted single characters in the prediction order to obtain the predicted aspect word.
[0246] In this embodiment, a labeled text is obtained by inserting a position tag for locating aspect words into the masked text; a label mark corresponding to the position tag is inserted into the position information to obtain label-tagged position information; and an aspect word prediction is performed on the aspect word position indicated by the position information according to the labeled text and the label-tagged position information by initializing the language model to obtain the predicted aspect word. This can improve the recognition efficiency of the initialized language model for aspect words in the text, minimize the number of label words that are incompatible with the original label, and avoid the problem that the position information of the predicted aspect words output by the initialized language model is inconsistent with the position information of the original sample.
[0247] The text includes n aspect words, where n is a natural number greater than 1. If all aspect words in the text are masked, the text will be greatly damaged and the prediction accuracy of the initialized language model will also be reduced. Therefore, in order to solve the above problem, in this embodiment, aspect words in the text are randomly masked according to a preset masking rate. Specifically, Fig.13 As shown, masking is performed on the aspect words in the text to obtain the masked text, including the following steps:
[0248] Step 1302: Obtain a preset masking rate, and determine the number of aspect words in the text to be masked according to the total number of aspect words in the text and the preset masking rate.
[0249] The preset masking rate is the ratio between the number of masked aspect words in the text and the total number of aspect words in the text.
[0250] Specifically, the server may obtain a preset masking rate that is manually set or obtained from a database, and determine the number of aspect words in the text to be masked according to the product of the total number of aspect words in the text and the preset masking rate.
[0251] In some embodiments, the preset mask rate may be a fixed mask rate or a dynamic mask rate. In order to increase the diversity of enhanced samples, in this embodiment, the preset mask rate is a dynamic mask rate, and the dynamic mask rate is obtained by randomly sampling a dynamic mask rate ε from a Gaussian distribution N(μ,σ2), where the Gaussian variance σ2 is set to 1 / n2.
[0252] Step 1304: randomly sample aspect words from the text according to the determined quantity and perform masking processing to obtain masked text.
[0253] Specifically, after the server determines the number of masks required for the current text, it randomly samples aspect words that are the same as the determined number from the text and performs masking processing to obtain the masked text.
[0254] In this embodiment, the number of aspect words in the text to be masked is determined based on the total number of aspect words in the text and a preset masking rate, and based on the determined number, aspect words are randomly sampled from the text and then masked. Among them, a dynamic masking rate is used to mask the same text instead of masking all aspect words in the text, which can reduce the degree of damage to the text and improve the prediction accuracy of the initialized language model.
[0255] In one embodiment, Fig.14 As shown, by initializing the language model, predicting the aspect word position indicated by the position information according to the masked text and the position information, and obtaining the predicted aspect word, the following steps are included:
[0256] Step 1402, by initializing the encoder of the language model, semantic encoding is performed according to the masked text and position information to obtain the semantic representation corresponding to the text.
[0257] The position information may be position information used to locate the position of each word in the text. The semantic representation corresponding to the text refers to the semantic information corresponding to each word in the text.
[0258] Specifically, the server inputs the masked text and position information into the encoder of the initialized language model, and the encoder semantically encodes the masked text to obtain the semantic information corresponding to each word in the text.
[0259] Step 1404 , by initializing the decoder of the language model, semantic decoding is performed according to the context of the indicated aspect word position and the semantic representation corresponding to the text to obtain the predicted aspect word.
[0260] Among them, the decoder is generated sequence to sequence, that is, according to the previous word, the decoding generates the next word (teacherforcing), so the context of the indicated aspect word position needs to be input into the decoder, and the decoder performs semantic decoding according to the context of the indicated aspect word position and the semantic expression corresponding to the text, outputs the first word in the aspect word, and then performs semantic decoding according to the first word of the aspect word and the semantic expression corresponding to the text, outputs the second word in the aspect word, and according to the same principle, outputs the last word in the aspect word, and sorts the predicted single words according to the prediction order to obtain the predicted aspect word.
[0261] For example, taking the text “their pad penang is delicious.” as an example, the corresponding position information L is: O BE OOO, and the masked text is “their[MASK][MASK]is delicious.”. The masked text and the corresponding position information are input into the encoder of the initialized language model, and the semantic expression of the encoder output text and the embedded expression corresponding to the above “their pad penang” at the indicated aspect word position are input into the decoder of the initialized language model. The decoder outputs the predicted “pad” based on “their” and the semantic expression of the encoder output text. The decoder outputs the predicted “penang” based on the embedded expression of “pad” and the semantic expression of the encoder output text. The results are sorted in the predicted order to obtain the predicted aspect word “pad penang”. Furthermore, the embedded expression corresponding to the context of the indicated aspect word position can also be used to calculate the training loss of the initialized language model to reversely update the initialized language model parameters. The embedded expression corresponding to the context "their pad penang" of the indicated aspect word position is used for decoding; the "pad penang" input to the encoder is used to calculate the training loss. The specific method is: according to the deviation between the output of the decoder and the input "pad peang", the error value is calculated, and the initialized language model parameters are reversely updated according to the error value.
[0262] Specifically, the server inputs the semantic representation corresponding to the text output by the encoder and the context of the aspect word position indicated by the position information of the aspect word in the original text into the decoder. The server performs semantic decoding through the decoder according to the context of the indicated aspect word position and the semantic expression corresponding to the text, obtains the first word of the aspect word at the indicated aspect word position, and then performs semantic decoding according to the first word and the semantic expression corresponding to the masked text, obtains the second word of the aspect word at the indicated aspect word position, and so on, obtains the last word in the predicted aspect word, sorts the predicted single words according to the prediction order, and obtains the predicted aspect word.
[0263] In this embodiment, the semantic representation corresponding to the text is obtained through the encoder, and the semantic decoding is performed through the decoder according to the context of the aspect word position indicated in the position information and the semantic representation corresponding to the text to obtain the first word of the aspect word at the indicated aspect word position, and then semantic decoding is performed according to the first word and the semantic expression corresponding to the text to obtain the second word of the aspect word at the indicated aspect word position, and so on to obtain the last word in the predicted aspect word, and the predicted single words are sorted according to the prediction order to obtain the predicted aspect word. The predicted aspect word is obtained by sequence-to-sequence learning, which can improve the prediction accuracy of the initialized language model.
[0264] In one embodiment, Fig.15 The method of initializing the language model and predicting the aspect word position indicated by the position information according to the masked text and the position information to obtain the predicted aspect word includes the following steps:
[0265] Step 1502, by initializing the language model, predicting the probability distribution corresponding to each aspect word position indicated by the position information according to the masked text and the position information, the probability distribution represents the probability that each word in the vocabulary is the predicted aspect word of the aspect word position.
[0266] The vocabulary table refers to a table containing multiple aspect words classified by categories.
[0267] The pre-trained language model predicts the probability distribution corresponding to each aspect word position indicated by the position information based on the following function:
[0268]
[0269] Among them, X is the text in the original sample; is the masked text; x i represents the i-th aspect word in the vocabulary; θ refers to the model parameter; n refers to the length of the aspect word; Represents the i-th aspect word x in the vocabulary i As masked text The probability of the aspect word; m i Represents the mark bit, represented by 0 or 1, where 0 represents an unmarked word and 1 represents a marked word.
[0270] Specifically, the server initializes the language model, and performs aspect word prediction on the aspect word position indicated by the position information according to the masked text and the position information, and obtains the probability that each word in the vocabulary is the predicted aspect word at the aspect word position.
[0271] Step 1504: for each aspect word position, determine the predicted aspect word corresponding to the aspect word position from the vocabulary according to probability.
[0272] The initialization language model generates the next word (teacher forcing) by decoding the previous word, that is, the initialization language model predicts the predicted word at the corresponding position according to the corresponding chronological position of each word in the masked aspect words in the training text, and combines the predicted words in the predicted order to obtain the predicted aspect words. In order to evaluate the recognition accuracy of the initialization language model and obtain the optimal initialization language model, in this embodiment, the predicted aspect word is the aspect word with the maximum probability corresponding to the output vocabulary of the initialization language model.
[0273] Specifically, the server initializes the language model and outputs the aspect word with the maximum probability in the output vocabulary corresponding to each aspect word position according to the aspect word position corresponding to each masked aspect word in the training text as the predicted aspect word at the corresponding position.
[0274] In this embodiment, the probability distribution corresponding to each aspect word position indicated by the position information is predicted by initializing the language model, and the aspect word corresponding to the maximum probability is selected from the probability distribution as the predicted aspect word corresponding to the aspect word position. The recognition accuracy of the initialized language model can be accurately obtained to obtain the optimal initialized language model.
[0275] In one embodiment, Fig.16 As shown, this embodiment provides a method for training a language model, which specifically includes the following steps:
[0276] Step 1: Obtain training samples, each of which includes a text, an aspect word in the text, and position information of the aspect word in the text.
[0277] Step 2, obtaining a preset masking rate, and determining the number of aspect words in the text to be masked according to the total number of aspect words in the text and the preset masking rate; and randomly sampling aspect words from the text according to the determined number and performing masking to obtain the masked text.
[0278] Step 3: insert a position tag for locating the aspect word into the masked text to obtain labeled text; insert a label tag corresponding to the position tag into the position information to obtain label-tokenized position information.
[0279] Step 4: Use the encoder of the pre-trained language model to perform semantic encoding based on the labeled text and the label tokenized position information to obtain the semantic representation corresponding to the text.
[0280] Step 5, using the decoder of the pre-trained language model, semantic decoding is performed according to the context of the indicated aspect word position and the semantic representation corresponding to the text, and the probability distribution corresponding to each aspect word position indicated by the label tokenized position information is predicted, and the probability distribution represents the probability that each word in the vocabulary is the predicted aspect word of the aspect word position;
[0281] Step 6: For each aspect word position, determine the predicted aspect word corresponding to the aspect word position from the vocabulary according to probability.
[0282] Step 7: construct a sample loss based on the difference between the predicted aspect words and the aspect words in the text, and update the initialized language model based on the sample loss to obtain a pre-trained language model.
[0283] In this embodiment, the aspect words are masked, which causes less damage to the text than the context masking method, thereby improving the recognition accuracy of the initialization language model; inserting position tags for locating aspect words in the masked text can improve the recognition efficiency of the initialization language model for aspect words in the text, and minimize the number of marker words that are incompatible with the original tags; by predicting the probability distribution corresponding to each aspect word position indicated by the position information through the initialization language model, selecting the aspect word corresponding to the maximum probability from the probability distribution as the predicted aspect word corresponding to the aspect word position, the recognition accuracy of the initialization language model can be accurately obtained to obtain the optimal initialization language model.
[0284] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0285] Based on the same inventive concept, the embodiment of the present application also provides a training sample processing device for implementing the training sample processing method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more training sample processing device embodiments provided below can refer to the limitations of the training sample processing method above, and will not be repeated here.
[0286] In one embodiment, Fig.17 As shown, a training sample processing device is provided, comprising: an original sample acquisition module 100, an original sample mask module 200, an original sample prediction module 300 and an enhanced sample generation module 400, wherein:
[0287] The original sample acquisition module 100 is used to acquire original samples, each of which includes text, aspect words in the text, and position information of the aspect words in the text;
[0288] The original sample masking module 200 is used to perform masking processing on the aspect words in the text to obtain the masked text;
[0289] The original sample prediction module 300 is used to predict the aspect word position indicated by the position information according to the masked text and the position information through the pre-trained language model to obtain the predicted aspect word;
[0290] The enhanced sample generation module 400 is used to replace the aspect words in the text of the original sample with the predicted aspect words to obtain enhanced samples; the enhanced samples are used to train the aspect word extraction model.
[0291] In one embodiment, the position information includes a mark indicating whether each word in the text is an aspect word, and marks corresponding to the starting position and the ending position of the aspect word in the text. The training sample processing device also includes an original sample position marking module 500, which is used to insert a position tag for locating the aspect word in the masked text to obtain a labeled text; and insert a label tag corresponding to the position tag into the position information to obtain labeled labeled position information.
[0292] The original sample prediction module 300 is also used to: predict the aspect word position indicated by the position information according to the labeled text and the label-tokenized position information through the pre-trained language model to obtain the predicted aspect word.
[0293] In one embodiment, the original sample masking module 200 is also used to: obtain a preset masking rate, determine the number of aspect words in the text to be masked based on the total number of aspect words in the text and the preset masking rate; and according to the determined number, randomly sample aspect words from the text and perform masking to obtain the masked text.
[0294] In one embodiment, the original sample prediction module 300 is further used to: perform semantic encoding according to the masked text and position information through an encoder of a pre-trained language model to obtain a semantic representation corresponding to the text;
[0295] Through the decoder of the pre-trained language model, semantic decoding is performed according to the context of the indicated aspect word position and the semantic representation corresponding to the text to obtain the predicted aspect word.
[0296] In one embodiment, the original sample prediction module 300 is further used to: predict the probability distribution corresponding to each aspect word position indicated by the position information according to the masked text and the position information through a pre-trained language model, wherein the probability distribution represents the probability that each word in the vocabulary is the predicted aspect word of the aspect word position;
[0297] For each aspect word position, k candidate words are selected from the vocabulary according to probability, and a word is randomly sampled from the k candidate words as the predicted aspect word corresponding to the aspect word position;
[0298] Here, k is a natural number greater than 1.
[0299] In one embodiment, the training sample processing apparatus further includes a denoising module 600, which is used to: extract aspect words from the enhanced sample using a pre-trained aspect word extraction model to obtain aspect word extraction results, and determine the position information corresponding to the enhanced sample according to the aspect word extraction results;
[0300] From the enhanced samples, the enhanced samples whose determined position information is consistent with the position information corresponding to the aspect words in the text of the corresponding original samples are screened out, and the aspect word extraction model is trained according to the screened enhanced samples.
[0301] In one embodiment, the training sample processing device further includes an aspect word extraction model training module 700, which is used to perform model training on the aspect word extraction model through enhanced samples and original samples in sequence to obtain a trained aspect word extraction model.
[0302] In one embodiment, the training sample processing apparatus further includes a pre-trained language model training module 800, which is used to: obtain training samples, each training sample including a text, an aspect word in the text, and position information of the aspect word in the text;
[0303] Mask the aspect words in the text to obtain the masked text;
[0304] By initializing the language model, the aspect word position indicated by the position information is predicted according to the masked text and position information to obtain the predicted aspect word;
[0305] According to the difference between the predicted aspect words and the aspect words in the text, a sample loss is constructed, and the initialized language model is updated according to the sample loss to obtain a pre-trained language model.
[0306] Each module in the above training sample processing device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0307] In one embodiment, Fig.18 As shown, a language model training device is provided, comprising: a training sample acquisition module 110, a training sample mask module 120, a training sample prediction module 130 and a model update module 140, wherein:
[0308] A training sample acquisition module 110 is used to acquire training samples, each of which includes a text, an aspect word in the text, and position information of the aspect word in the text;
[0309] The training sample masking module 120 is used to perform masking processing on the aspect words in the text to obtain the masked text;
[0310] The training sample prediction module 130 is used to predict the aspect word position indicated by the position information according to the masked text and the position information by initializing the language model to obtain the predicted aspect word;
[0311] The model updating module 140 is used to construct a sample loss according to the difference between the predicted aspect words and the aspect words in the text of the training sample, and to update the initialized language model according to the sample loss to obtain a pre-trained language model; the pre-trained language model is used to predict aspect words for the masked text.
[0312] In one embodiment, the position information includes a mark indicating whether each word in the text is an aspect word, and marks corresponding to the starting position and the ending position of the aspect word in the text; the training device also includes: a training sample position marking module 150, the training sample position marking module 150 is used to insert a position tag for locating the aspect word in the masked text to obtain a labeled text; insert a label tag corresponding to the position tag into the position information to obtain labeled labeled position information.
[0313] The training sample prediction module 130 is further used to: initialize the language model, and perform aspect word prediction on the aspect word position indicated by the position information according to the labeled text and the label-tokenized position information to obtain the predicted aspect word.
[0314] In one embodiment, the training sample masking module 120 is also used to: obtain a preset masking rate, determine the number of aspect words in the text to be masked based on the total number of aspect words in the text and the preset masking rate; and based on the determined number, randomly sample aspect words from the text and perform masking to obtain the masked text.
[0315] In one embodiment, the training sample prediction module 130 is further used to: perform semantic encoding according to the masked text and position information through an encoder of a pre-trained language model to obtain a semantic representation corresponding to the text;
[0316] Through the decoder of the pre-trained language model, semantic decoding is performed according to the context of the indicated aspect word position and the semantic representation corresponding to the text to obtain the predicted aspect word.
[0317] In one embodiment, the training sample prediction module 130 is further used to: predict the probability distribution corresponding to each aspect word position indicated by the position information according to the masked text and the position information by initializing the language model, wherein the probability distribution represents the probability that each word in the vocabulary is the predicted aspect word of the aspect word position;
[0318] For each aspect word position, the predicted aspect word corresponding to the aspect word position is determined from the vocabulary by probability.
[0319] Each module in the training device of the above-mentioned language model can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.
[0320] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Fig.19 As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected via a system bus, and the communication interface, the display unit and the input device are connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a training sample processing method and a language model training method are implemented. The display unit of the computer device is used to form a visually visible image, and can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer covered on the display screen, or a button, trackball or touchpad set on the computer device casing, or an external keyboard, touchpad or mouse, etc.
[0321] Those skilled in the art will understand that Fig.19 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0322] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above-mentioned method embodiments when executing the computer program.
[0323] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0324] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0325] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0326] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0327] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0328] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A training sample processing method, characterized in that: The method comprises: Obtaining original samples, each original sample includes text, aspect words in the text, and position information of the aspect words in the text; Masking the aspect words in the text to obtain a masked text; By using a pre-trained language model, predicting the aspect word position indicated by the position information according to the masked text and the position information, to obtain a predicted aspect word; The aspect words in the text of the original sample are replaced with the predicted aspect words to obtain an enhanced sample; the enhanced sample is used to train an aspect word extraction model.
2. The method according to claim 1, characterized in that The position information includes a mark indicating whether each word in the text belongs to an aspect word, and marks corresponding to the starting position and the ending position of the aspect word in the text respectively; the method further includes: Inserting a position tag for locating the aspect word into the masked text to obtain a labeled text; Inserting a label mark corresponding to the position label into the position information to obtain label-marked position information; The pre-trained language model is used to predict the aspect word position indicated by the position information according to the masked text and the position information to obtain the predicted aspect word, including: By using the pre-trained language model, aspect word prediction is performed on the aspect word position indicated by the position information according to the labeled text and the label-tokenized position information to obtain a predicted aspect word.
3. The method according to claim 1, characterized in that The step of performing masking on the aspect words in the text to obtain the masked text includes: Obtaining a preset masking rate, and determining the number of aspect words in the text to be masked according to the total number of aspect words in the text and the preset masking rate; According to the determined quantity, aspect words are randomly sampled from the text and then masked to obtain masked text.
4. The method according to claim 1, characterized in that: The pre-trained language model is used to predict the aspect word position indicated by the position information according to the masked text and the position information to obtain the predicted aspect word, including: Performing semantic encoding according to the masked text and the position information through an encoder of a pre-trained language model to obtain a semantic representation corresponding to the text; Through the decoder of the pre-trained language model, semantic decoding is performed according to the context of the indicated aspect word position and the semantic representation corresponding to the text to obtain the predicted aspect word.
5. The method according to claim 1, characterized in that The pre-trained language model is used to predict the aspect word position indicated by the position information according to the masked text and the position information to obtain the predicted aspect word, including: Predicting, by a pre-trained language model, a probability distribution corresponding to each aspect word position indicated by the position information according to the masked text and the position information, wherein the probability distribution represents the probability that each word in the vocabulary is a predicted aspect word for the aspect word position; For each aspect word position, k candidate words are selected from the vocabulary according to the probability, and a word is randomly sampled from the k candidate words as a predicted aspect word corresponding to the aspect word position; Here, k is a natural number greater than 1.
6. The method according to claim 1, characterized in that The method further comprises: Extracting aspect words from the enhanced sample using a pre-trained aspect word extraction model to obtain an aspect word extraction result, and determining position information corresponding to the enhanced sample according to the aspect word extraction result; From the enhanced samples, the enhanced samples whose determined position information is consistent with the position information corresponding to the aspect words in the text of the corresponding original sample are screened out, and the aspect word extraction model is trained according to the screened enhanced samples.
7. The method according to claim 1, characterized in that The method further comprises: The aspect word extraction model is trained by using the enhanced samples and the original samples in turn to obtain a trained aspect word extraction model.
8. The method according to any one of claims 1 to 7, characterized in that: The training steps of the pre-trained language model include: Acquire training samples, each training sample comprising a text, an aspect word in the text, and position information of the aspect word in the text; Masking the aspect words in the text to obtain a masked text; By initializing the language model, performing aspect word prediction on the aspect word position indicated by the position information according to the masked text and the position information, to obtain a predicted aspect word; According to the difference between the predicted aspect words and the aspect words in the text, a sample loss is constructed, and the initialized language model is updated according to the sample loss to obtain the pre-trained language model.
9. A method for training a language model, characterized in that: The method comprises: Acquire training samples, each training sample comprising a text, an aspect word in the text, and position information of the aspect word in the text; Masking the aspect words in the text to obtain a masked text; By initializing the language model, performing aspect word prediction on the aspect word position indicated by the position information according to the masked text and the position information, to obtain a predicted aspect word; According to the difference between the predicted aspect words and the aspect words in the text of the training sample, a sample loss is constructed, and the initialized language model is updated according to the sample loss to obtain a pre-trained language model; the pre-trained language model is used to predict aspect words for the masked text.
10. The method according to claim 9, characterized in that The position information includes a mark indicating whether each word in the text belongs to an aspect word, and marks corresponding to the starting position and the ending position of the aspect word in the text respectively; the method further includes: Inserting a position tag for locating the aspect word into the masked text to obtain a labeled text; Inserting a label mark corresponding to the position label into the position information to obtain label-marked position information; The initializing the language model and predicting the aspect word position indicated by the position information according to the masked text and the position information to obtain the predicted aspect word includes: By using the initialized language model, aspect word prediction is performed on the aspect word position indicated by the position information according to the labeled text and the label tokenized position information to obtain a predicted aspect word.
11. The method according to claim 9, characterized in that The step of performing masking on the aspect words in the text to obtain the masked text includes: Obtaining a preset masking rate, and determining the number of aspect words in the text to be masked according to the total number of aspect words in the text and the preset masking rate; According to the determined quantity, aspect words are randomly sampled from the text and then masked to obtain masked text.
12. The method according to claim 9, characterized in that The initializing the language model and predicting the aspect word position indicated by the position information according to the masked text and the position information to obtain the predicted aspect word includes: Performing semantic encoding according to the masked text and the position information through an encoder of a pre-trained language model to obtain a semantic representation corresponding to the text; Through the decoder of the pre-trained language model, semantic decoding is performed according to the context of the indicated aspect word position and the semantic representation corresponding to the text to obtain the predicted aspect word.
13. The method according to claim 9, characterized in that The initializing the language model and predicting the aspect word position indicated by the position information according to the masked text and the position information to obtain the predicted aspect word includes: Initializing a language model, predicting a probability distribution corresponding to each aspect word position indicated by the position information according to the masked text and the position information, wherein the probability distribution represents the probability that each word in the vocabulary is a predicted aspect word at the aspect word position; For each aspect word position, a predicted aspect word corresponding to the aspect word position is determined from the vocabulary according to the probability.
14. A training sample processing device, characterized in that: The device comprises: An original sample acquisition module, used to acquire original samples, each original sample includes a text, an aspect word in the text, and position information of the aspect word in the text; An original sample masking module, used for performing masking processing on the aspect words in the text to obtain a masked text; An original sample prediction module, used to predict the aspect word position indicated by the position information according to the masked text and the position information through a pre-trained language model to obtain a predicted aspect word; The enhanced sample generation module is used to replace the aspect words in the text of the original sample with the predicted aspect words to obtain enhanced samples; the enhanced samples are used to train the aspect word extraction model.
15. A language model training device, characterized in that: The device comprises: A training sample acquisition module, used to acquire training samples, each training sample includes a text, an aspect word in the text, and position information of the aspect word in the text; A training sample masking module is used to perform masking processing on the aspect words in the text to obtain a masked text; A training sample prediction module is used to predict the aspect word position indicated by the position information according to the masked text and the position information by initializing the language model to obtain a predicted aspect word; The model updating module is used to construct a sample loss according to the difference between the predicted aspect words and the aspect words in the text of the training sample, and to update the initialized language model according to the sample loss to obtain a pre-trained language model; the pre-trained language model is used to predict aspect words for the masked text.
16. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 13 are implemented.
17. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 13 are implemented.
18. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 13 are implemented.
