Text prediction method, system and electronic device based on adaptive mask strategy
Adjusting the mask ratio of the language model through the adaptive masking strategy solves the problem of low mask efficiency in language prediction model training, improves prediction accuracy and generation quality, and is suitable for a variety of application scenarios.
Patent Information
- Application Number
- CN202310253751.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-16
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2043-03-16
AI Technical Summary
Text masking efficiency in the training tasks of language prediction models in the prior art is low, resulting in low model prediction accuracy. In addition, existing improvement methods require changing decoding strategies or adding training targets, and have limited application scenarios and cannot be generalized to other masks. Code language model.
A text prediction method based on an adaptive masking strategy is adopted. By randomly masking the target sequence, the initial mask proportion of the source sequence is calculated according to the mask proportion, the model is trained, and the mask proportion is adjusted through multiple rounds of iterations to improve the model's performance. Predict performance.
It achieves stable and effective prediction of the model under different mask ratios, improves the performance of iterative non-autoregressive models, is suitable for natural machine translation, summary and code generation tasks, and significantly improves the quality and speed of generation.
Smart Images

Figure CN116451708B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer text prediction, and in particular to a text prediction method, system and electronic equipment based on an adaptive mask strategy. Background Art
[0002] In recent years, with the rapid development of deep learning, models with different neural networks as the main structure have attracted more and more attention. Among them, deep learning models based on "Transformer" have been proven to be effective for various sequence-to-sequence generation tasks, such as machine translation, text summarization, dialogue systems, code generation, etc. Although transformer-based models have good performance, they usually adopt an autoregressive (AR) decoding paradigm, that is, the decoding process of the target sequence is decomposed into multi-step predictions in a left-to-right order, and the next prediction is conditioned on the previously generated part to generate the result word by word. This decoding paradigm makes the cost of inference time increase linearly with the length of the target sequence, which is obviously time-consuming for long sequences. To alleviate this problem, many recent studies have explored non-autoregressive (NAR) methods to predict the target sequence in parallel. This type of method only needs one step to generate the entire sequence during decoding, which can significantly improve the decoding speed. However, under this feature, the next prediction does not have the previously generated part as a condition. The NAR model discards the internal dependency of the target sequence and performs the decoding process entirely based on the source / input sequence. As a result, compared with AR methods of the same scale, although the NAR method has a significant improvement in decoding speed, the lack of internal dependencies of the target sequence leads to lagging generation quality.
[0003] In order to achieve a better trade-off between decoding acceleration and generation quality, the conditional masked language model (CMLM) was proposed and has become one of the most competitive and widely used NAR frameworks. CMLM uses an iterative mask prediction decoding strategy. In the training phase, CMLM uses a masked language model to learn the target. First, the target sequence is divided into a masked part and an unmasked part. According to the source input and the unmasked part in the target sequence, the masked part of the target sequence is generated in parallel. In the inference process, CMLM first generates the entire target sequence in parallel (the first round of iteration), and then repeatedly performs masking operations and predicts low-confidence tokens in subsequent iterations. Based on CMLM, many improvement strategies have also been proposed to improve model performance from different levels, such as improving inference strategies, benefiting from AR models, using better training criteria, introducing self-correction mechanisms, and using pre-training methods.
[0004] Models based on non-autoregressive techniques have attracted increasing attention in recent years due to their high decoding efficiency. First proposed by Gu et al. in 2018, the speed was greatly improved, but the effect was not good. Many improved methods were proposed afterwards. This type of model is also divided into a fully non-autoregressive model and an iterative non-autoregressive model. The former strictly adopts a single decoding in the decoding process, and the model generates the entire target sequence in parallel only once. However, in this case, the improvement in decoding speed comes at the expense of generation quality. Therefore, researchers proposed an iterative non-autoregressive model to achieve a better trade-off between decoding acceleration and generation quality. Li and Zhao et al. first proposed an iterative non-autoregressive model, which aims to use an additional decoder to achieve a refined noisy target sequence. Subsequently, the insertion and deletion operations were also applied to the iterative process by researchers, aiming to insert and delete the generated sequence in each round of iteration to achieve further optimized generation. In addition, many other methods have been proposed to iteratively generate target sequences. Among these iterative non-autoregressive model methods, the conditional masked language model (CMLM) has attracted the interest of many researchers and has been widely used due to its good performance using the mask prediction strategy. Specifically, the goal of the masked language model is to learn the ability to predict the masked part during training. When decoding, the entire masked sequence is started, and prediction and masking are repeated. In each round of iteration, the low-confidence part is first masked and then predicted. The quality of the entire target sequence is repeatedly optimized during the iteration process, and finally a high-quality target sequence is generated. Many recent iterative models have also achieved performance improvements based on CMLM.
[0005] Speaking of masked language models (MLMs), the masked training objective was first introduced by the BERT model and has now become an important part of various pre-training methods. Its standard paradigm is to select a part of the tokens in the target sequence through different masking strategies, replace them with a masked token [mask], and then train the model to predict this part of the tokens. The masking strategy is crucial to these models, so many different masking strategies have been proposed. Since BERT consists of a single transformer encoder and is only applied to monolingual scenarios, it has limitations in various application scenarios, such as machine translation. In order to further expand the application scenarios of masked language models, the conditional masked language model (CMLM) mentioned above is widely used. Non-autoregressive models based on CMLM can also benefit from introducing a unified masking strategy in training and a mask prediction decoding strategy in the inference process. However, only a few improvements on masking strategies have been explored, such as the joint masked language model proposed by Guo et al. and the GLAT model proposed by Qian et al.
[0006] Disadvantages of existing technology:
[0007] In summary, most of the current improvements based on the conditional masked language model (CMLM) require changing the originally proposed decoding strategy or adding additional training objectives. In addition, during the iteration process, the stability of each round of iteration cannot be guaranteed, resulting in invalid decoding time overhead. Therefore, although these methods can improve the performance of the model to a certain extent, they often have operational difficulties and increase decoding overhead. At the same time, such methods have limited application scenarios and can only be applied to the CMLM model and cannot be extended to other masked language models. At the same time, there are few improvement solutions based on mask strategies. Summary of the invention
[0008] To this end, the technical problem to be solved by the present invention is to overcome the problem in the prior art that the text masking efficiency in the language prediction model training task is low, which leads to low model prediction accuracy.
[0009] To solve the above technical problems, the present invention provides a text prediction method based on an adaptive mask strategy, comprising:
[0010] Step S1: randomly masking a target sequence Y in a text pair, calculating an initial mask ratio of a source sequence X in the text pair according to the mask ratio of the target sequence Y, and then performing current training on a model to be trained according to the mask ratio of the target sequence Y and the initial mask ratio of the source sequence X;
[0011] Step S2: The prediction results of the current training of the model to be trained The unmasked part of the target sequence Y is combined to form a new target sequence Y', and the prediction result of the current training of the model to be trained is calculated The accuracy rate β;
[0012] Step S3: masking the new target sequence Y' according to the accuracy β, calculating the re-masking ratio of the source sequence X according to the masking ratio of the new target sequence Y', and then re-training the model to be trained according to the masking ratio of the new target sequence Y' and the re-masking ratio of the source sequence X;
[0013] Step S4: Compare the prediction result of the retraining of the model to be trained with the target sequence Y. If the comparison results are consistent, a trained model is obtained; if the comparison results are inconsistent, return to step S2 until the comparison results are consistent;
[0014] Step S5: Predict the text to be predicted based on the trained model.
[0015] In one embodiment of the present invention, in step S1, the initial mask ratio of the source sequence X in the text pair is calculated according to the mask ratio of the target sequence Y by:
[0016] Divide the target sequence Y into unmasked parts Y obs and the mask part Y mask , and according to the unmasked part Y obs and the mask part Y mask Calculate the mask ratio of the target sequence Y;
[0017] The initial mask ratio of the source sequence X is calculated according to the mask ratio of the target sequence Y.
[0018] In one embodiment of the present invention, the unmasked portion Y obs and the mask part Y mask Calculate the mask ratio of the target sequence Y, the formula is: Among them, α dec represents the mask ratio of the target sequence Y, N obs Represents the unmasked part Y in the target sequence Y obs The number of identifiers, N mask Represents the mask part Y in the target sequence Y mask The number of identifications.
[0019] In one embodiment of the present invention, the initial mask ratio of the source sequence X is calculated according to the mask ratio of the target sequence Y, and the formula is: enc =(b 1 -a 1 )α dec +a 1 , where α enc represents the initial mask ratio of the source sequence X, b 1 represents the first hyperparameter used to control the upper limit of the mask ratio, a 1 represents the first hyperparameter used to control the lower limit of the mask ratio, α dec represents the mask ratio of the target sequence Y.
[0020] In one embodiment of the present invention, the prediction result of the current training of the model to be trained is calculated in step S2. The accuracy rate β is as follows: Among them, Y mask represents the mask part in the target sequence Y, Indicates the prediction result of the current training of the model. Represents Y mask and The number of identical identifiers in mask The masked part Y mask The number of identifications.
[0021] In one embodiment of the present invention, in step S4, the new target sequence Y' is masked according to the accuracy β, and the method is: the prediction result of the current training of the model in the new target sequence Y' is masked according to the accuracy β And the unmasked parts of the target sequence Y are masked respectively.
[0022] In one embodiment of the present invention, the prediction result of the current training of the model in the new target sequence Y' according to the accuracy β And the unmasked parts of the target sequence Y are masked separately, specifically:
[0023] The prediction results of the current model training The masking probability of each identifier in is set to 1-ψ(β), and the unmasked part Y obs The mask probability of each mark in is set to ψ(β), where the formula of ψ(β) is: ψ(β)=(b 2 -a 2 )*β+a 2 , b 2 represents the second hyperparameter used to control the upper limit of the mask ratio, a 2 Represents the second hyperparameter controlling the lower limit of the mask ratio.
[0024] In order to solve the above technical problems, the present invention provides a text prediction system based on an adaptive mask strategy, which is characterized by comprising:
[0025] Current training module: used to randomly mask the target sequence Y in the text pair, calculate the initial mask ratio of the source sequence X in the text pair according to the mask ratio of the target sequence Y, and then perform current training on the model to be trained according to the mask ratio of the target sequence Y and the initial mask ratio of the source sequence X;
[0026] Computation module: used to calculate the prediction results of the current training of the model to be trained The unmasked part of the target sequence Y is combined to form a new target sequence Y', and the prediction result of the current training of the model to be trained is calculated The accuracy rate β;
[0027] A retraining module is used to mask the new target sequence Y' according to the accuracy β, calculate the re-masking ratio of the source sequence X according to the masking ratio of the new target sequence Y', and then re-train the model to be trained according to the masking ratio of the new target sequence Y' and the re-masking ratio of the source sequence X;
[0028] Comparison module: used to compare the prediction results of the retrained model to be trained with the target sequence Y. If the comparison results are consistent, a trained model is obtained; if the comparison results are inconsistent, it returns to the calculation module until the comparison results are consistent;
[0029] Prediction module: used to predict the text to be predicted based on the trained model.
[0030] To solve the above technical problems, the present invention provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the steps of the text prediction method based on the adaptive mask strategy are implemented.
[0031] In order to solve the above technical problem, the present invention provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the text prediction method based on the adaptive mask strategy are implemented.
[0032] The above technical solution of the present invention has the following advantages compared with the prior art:
[0033] The present invention can effectively realize the training of the model through two masking strategies, which are: an adaptive masking strategy based on the source sequence (i.e., determining the source sequence masking ratio according to the target sequence masking ratio) and an adaptive masking strategy based on the target sequence (i.e., determining the masking ratio of the new target sequence according to the prediction result accuracy of the current model training). The two masking strategies can enable the model to have better prediction performance;
[0034] The present invention captures the mask ratio changes under multiple iterations in the reasoning process by training the model at least twice, so that the model can stably and effectively predict the predicted text when facing different mask ratios; the present invention focuses on improving each iteration of the iterative non-autoregressive model, rather than just enhancing the first iteration, so as to achieve the maximum improvement of model performance;
[0035] The present invention is experimented on natural machine translation, summary and code generation tasks, and the experimental results show that the present invention has better performance. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to make the contents of the present invention more clearly understood, the present invention is further described in detail below based on specific embodiments of the present invention in conjunction with the accompanying drawings.
[0037] Figure 1 is a flow chart of the method of the present invention;
[0038] Figure 2is a schematic diagram of a model training structure based on an adaptive mask strategy according to an embodiment of the present invention;
[0039] Figure 3 is a comparison chart of experimental results of machine translation tasks on four WMT datasets in an embodiment of the present invention;
[0040] Figure 4 is a comparison chart of experimental results of machine translation tasks on 8 IWSLT datasets in an embodiment of the present invention;
[0041] Figure 5 is a comparison chart of experimental results on the summary task in an embodiment of the present invention;
[0042] Figure 6 This is a comparison chart of the results of using BLEU and ES indicators to evaluate the code generation task in an embodiment of the present invention;
[0043] Figure 7 is a comparison diagram of the effects of using different categories of mapping functions in the adaptive mask strategy based on the source sequence in an embodiment of the present invention;
[0044] Figure 8 It is a comparison diagram of the effects of using different category mapping functions in the adaptive mask strategy based on the target sequence in the embodiment of the present invention. DETAILED DESCRIPTION
[0045] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it, but the embodiments are not intended to limit the present invention.
[0046] Embodiment 1
[0047] Reference Figure 1 As shown, an embodiment of the present invention provides a text prediction method based on an adaptive mask strategy, comprising:
[0048] Preliminary step: obtaining a data set, wherein the data set includes a large number of text pairs, wherein the text pair includes a source sequence X and a target sequence Y, the source sequence X is the text before prediction (for example, the text before translation), and the target sequence Y is the text after prediction (for example, the text after translation);
[0049] Step S1: randomly masking a target sequence Y in a text pair, calculating an initial mask ratio of a source sequence X in the text pair according to the mask ratio of the target sequence Y, and then performing current training on a model to be trained according to the mask ratio of the target sequence Y and the initial mask ratio of the source sequence X;
[0050] Step S2: The prediction results of the current training of the model to be trained The unmasked part of the target sequence Y is combined to form a new target sequence Y', and the prediction result of the current training of the model to be trained is calculated The accuracy rate β;
[0051] Step S3: masking the new target sequence Y' according to the accuracy β, calculating the re-masking ratio of the source sequence X according to the masking ratio of the new target sequence Y', and then re-training the model to be trained according to the masking ratio of the new target sequence Y' and the re-masking ratio of the source sequence X;
[0052] Step S4: Compare the prediction result of the retraining of the model to be trained with the target sequence Y. If the comparison results are consistent, a trained model is obtained; if the comparison results are inconsistent, return to step S2 until the comparison results are consistent;
[0053] Step S5: Predict the text to be predicted based on the trained model.
[0054] In this embodiment, in step S1, the model to be trained is first trained (adopting an adaptive masking strategy based on the source sequence), and in steps S2 to S3, the model to be trained is retrained (combining the adaptive masking strategy based on the source sequence and the adaptive masking strategy based on the target sequence). By training the model at least twice, the mask ratio changes under multiple iterations in the reasoning process are captured, so that the model can be used to stably and effectively predict the predicted text when facing different mask ratios. This embodiment focuses on the improvement of each iteration of the iterative non-autoregressive model, rather than just enhancing the first iteration, so as to achieve the maximum improvement of model performance.
[0055] It should be noted that in this embodiment, when training the model to be trained, the prediction result accuracy reaches 100% through multiple trainings. However, considering the time overhead and other issues in practice, the total number of model trainings in this embodiment is set to two in practice. This is because there are a large number of text pairs, which can ensure that the trained model has good generalization ability. The following takes two trainings as an example to describe this embodiment in detail:
[0056] (I) Adaptive mask strategy based on source sequence: Given a training pair (X, Y), where X represents the source sequence and Y represents the target sequence, the target sequence Y can be divided into Y obs and Y mask , that is, the unmasked part and the masked part, then the mask ratio α of the target sequence Y dec The calculation formula is as follows:
[0057]
[0058] Among them, N obsand N mask Represents Y obs and Y mask The number of logos in . Get the mask ratio α dec Afterwards, this embodiment proposes a first mapping function To determine the mask ratio of the source sequence X based on the mask ratio of the target sequence Y, if the length of the source sequence X is L X , then this embodiment will randomly select The length is used as the mask part, the first mapping function It can be various. In this embodiment, a linear mapping function is taken as an example, and the formula can be expressed as:
[0059]
[0060] Among them, b 1 and a 1 is a predefined hyperparameter for controlling the first upper limit and the first lower limit of the mask ratio. In practical applications, this embodiment uses b 1 and a 1 Set to 0.3 and 0.1 respectively.
[0061] See also Figure 2 For example, during the training of a machine translation task, the source sequence X is the German Wir das akzeptieren vollkonmen (We totally accept this) and the target sequence Y is the English We totally accept it (We totally accept this). Figure 2 The Uniform Masking part of the left CMLM decoder, that is, Y can be divided into Y obs and Y mask , that is, there is only a single masking operation, and the traditional CMLM directly inputs the source sequence X into the Transformer encoder during training without masking it. In this embodiment, the model chooses to mask the totally and accept in the target sequence We totally accept it, that is, Y mask ={totally,accept},Y obs ={we,it}. The model uses the corresponding loss function L cmlm Train to predict Y mask After applying the adaptive mask strategy based on the source sequence of this embodiment, first calculate Y mask The proportion of the logo in the entire target sequence Y Then use the mapping function Calculate the mask ratio of the source sequence X: Then the identities in the source sequence Wir dasakzeptieren vollkonmen are randomly selected and the result das is masked.
[0062] (II) Adaptive mask strategy based on target sequence: Given a training pair (X, Y), where X represents the source sequence and Y represents the target sequence, the target sequence Y can be divided into Y obs and Y mask , that is, the unmasked part and the masked part, based on the source sequence X and the unmasked part Y obs , the model predicts Y mask For the convenience of distinction, the model prediction results are expressed as The calculation formula for the accuracy rate β of the current prediction result of the model is as follows:
[0063]
[0064] Among them, Y mask represents the mask part in the target sequence Y, Indicates the prediction result of the current training of the model. Represents Y mask and The number of identical identifiers in mask The masked part Y mask The number of identifications.
[0065] Similar to the adaptive mask strategy based on the source sequence, this embodiment proposes a second mapping function ψ(·) to determine the second round of mask training process and Y obs The probability of a symbol being masked, in this embodiment, is given The mask probability of each identity 1-ψ(β), Y obs The masking probability of each identifier ψ(β) in , after the second round of masking, Y is re-divided into Y' mask and Y' obs , the model is then trained to predict Y' mask The mapping function is as follows:
[0066] ψ(β)=(b 2 -a 2 )*β+a 2
[0067] Among them, b 2 and a 2 is a predefined hyperparameter for controlling the second upper limit and the second lower limit of the mask ratio. In practical applications, this embodiment uses b 2 and a 2 Use 0.8 and 0.2 respectively.
[0068] See also Figure 2 , the source sequence X is the German Wir das akzeptieren vollkonmen (We totally accept this), and the target sequence Y is the English We totally accept it (We totally accept this). After applying the adaptive masking strategy based on the target sequence of this embodiment, the model will perform a second masking during training. During the first training, the model masks totally and accept in the target sequence We totally accept it, that is, Y mask ={totally,accept},Y obs ={we,it}. The model uses the corresponding loss function L cmlm Train to predict Y mask The model prediction result in the figure is Compare it with the real identity Y mask ={totally,accept}After comparison, it is found that the accuracy rate of the model's first prediction β is 0.5, that is, the accept prediction is correct, but the totally prediction is wrong. In the second round of training, when the adaptive masking strategy based on the target sequence is applied, ψ(β)=(b 2 -a 2 )*β+a 2 =(0.8-0.2)*0.5+0.2=0.5, Each mark in has a probability of 1-ψ(β)=1-0.5=0.5 to be masked, and Y obs = Each identifier in {we,it} has a probability of ψ(β) = 0.5 to be masked, and the result is as follows Figure 2 As shown, in and Y obs ={we,it}, the labels We and accept are masked, and the model performs a second round of prediction and uses the corresponding loss function L aday Conduct training.
[0069] A trained model can be obtained through the adaptive masking strategy based on the source sequence and the adaptive masking strategy based on the target sequence, and the trained model can be used for various language prediction and reasoning.
[0070] (III) Model training and reasoning: During the model training process, given a training pair (X, Y), firstly, an adaptive masking strategy based on the source sequence is applied to perform the first round of prediction, and then two adaptive masking strategies are applied based on the results of the model prediction to perform the second round of prediction. The model aims to train the identification of the predicted mask part and finally complete the model training. The model reasoning process of this embodiment is consistent with the traditional CMLM method and will not be repeated here.
[0071] The experimental results are analyzed as follows:
[0072] In order to evaluate the adaptive masking strategy (AMOM) of this embodiment, that is, the adaptive masking strategy (AMOM) based on the conditional mask language model (CMLM), and demonstrate its unified role in various sequence generation tasks, this embodiment conducted experiments on natural machine translation, summary and code generation tasks, and verified the effect of AMOM on a total of 15 corresponding data sets. It is worth mentioning that after applying the adaptive masking strategy of this embodiment, compared with the traditional CMLM, the models have consistent improvements, and compared with other improved methods proposed based on CMLM, the AMOM of this embodiment has achieved the best results on 3 data sets, and showed comparable results in other data sets. The following comparison table of the corresponding results is given in this embodiment, see for details. Figure 3 .
[0073] Figure 3 The table in the figure shows the experimental results of machine translation tasks on four WMT datasets, where AMOM is the method of this embodiment. It can be found that AMOM surpasses all baseline methods in the WMT16 EN--RO dataset, including the currently popular fully non-autoregressive model and the improved method based on the CMLM model. It also shows comparable results on the WMT14 EN--DE dataset. At the same time, compared with the traditional autoregressive model "Transformer", it can ensure a 2.3-fold speed increase.
[0074] Figure 4 The experimental results of machine translation tasks on 8 IWSLT data sets are also given, mainly comparing the effects of the traditional autoregressive model "Transformer", the traditional CMLM, and the method of this embodiment (AMOM). It is not difficult to find that the AMOM of this embodiment can surpass the traditional autoregressive model "Transformer" on 5 data sets, and surpass the traditional CMLM, and the average effect performance exceeds the BLEU score of the traditional CMLM model by 0.7. Compared with the traditional autoregressive model "Transformer", there is only a difference of 0.04 BLEU score, and it guarantees a 2.2-fold speed increase.
[0075] This example is also verified on the summary task, see Figure 5 , which is the experimental result of the summary task, comparing the AMOM of this embodiment with the original CMLM and several NAR baseline models. The results show that AMOM outperforms all other NAR models without pre-training. Since pre-training generally can greatly improve this task, the model with pre-training can significantly improve the performance. However, AMOM can also be applied to the pre-training and fine-tuning stages. In the later stage of this embodiment, AMOM will be applied to the pre-trained language model to verify its effect. I believe it can also show good potential.
[0076] Figure 6 This is the result of the code generation task given in this embodiment. Figure 6 Results of the code generation task using BLEU and ES metrics are shown, which measure the character-level edit similarity and n-gram matching accuracy between the target code and the generated code. The results show that the AMOM of this embodiment outperforms the ordinary CMLM in different iterations and obtains better improvements during refinement.
[0077] In addition, this embodiment also conducts many ablation experiments to verify the effects of two important components of the AMOM strategy, the adaptive mask strategy based on the source sequence and the adaptive mask strategy based on the target sequence, as well as the results compared with related work.
[0078] Figure 7 This is a comparison of the effects of different types of mapping functions in the adaptive masking strategy based on source sequence. This embodiment first analyzes the impact of various mapping functions on the adaptive masking strategy based on source sequence. Compared with other mapping functions, the linear mapping function is simple and effective, and the final effect exceeds other mapping functions.
[0079] This embodiment also compares the effects of different category mapping functions in the adaptive mask strategy based on the target sequence. Figure 8 It is not difficult to find that by analyzing the impact of various mapping functions on the adaptive masking strategy based on the target sequence, the linear mapping function is still a simple but effective choice compared with other functions.
[0080] In addition, this embodiment also compares the performance of sequences of different lengths under different numbers of iterations to verify the iteration capability of AMOM compared with CMLM. This embodiment compares the effects of different source sequence lengths and different numbers of decoding iterations on two data sets. This embodiment divides each data set into five parts according to the sentence length, and performs three reasonings according to different steps. The final results show that AMOM shows significant gains compared to traditional CMLM when different decoding iterations increase. Since long sequences require more decoding iterations, this makes the performance of AMOM better.
[0081] Embodiment 2
[0082] This embodiment provides a text prediction system based on an adaptive mask strategy, including:
[0083] Acquisition module: used to acquire a model to be trained and a text pair, wherein the text pair includes a source sequence X and a target sequence Y;
[0084] Current training module: used to randomly mask the target sequence Y, calculate the initial mask ratio of the source sequence X according to the mask ratio of the target sequence Y, and then perform current training on the model according to the mask ratio of the target sequence Y and the initial mask ratio of the source sequence X;
[0085] Computation module: used to calculate the prediction results of the current training of the model The unmasked part of the target sequence Y is combined to form a new target sequence Y', and the prediction result of the current training of the model is calculated The accuracy rate β;
[0086] A retraining module is used to mask the new target sequence Y' according to the accuracy β, calculate the re-masking ratio of the source sequence X according to the masking ratio of the new target sequence Y', and then re-train the model according to the masking ratio of the new target sequence Y' and the re-masking ratio of the source sequence X;
[0087] Comparison module: used to compare the prediction result of the retrained model with the target sequence Y. If the comparison result is consistent, a trained model is obtained; if the comparison result is inconsistent, the process returns to the calculation module and the retraining module;
[0088] Prediction module: used to predict the text to be predicted based on the trained model.
[0089] Embodiment 3
[0090] This embodiment provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the text prediction method based on the adaptive mask strategy described in Embodiment 1 are implemented.
[0091] Embodiment 4
[0092] This embodiment provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the text prediction method based on the adaptive mask strategy described in the first embodiment are implemented.
[0093] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of complete hardware embodiments, complete software embodiments, or embodiments in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code. The scheme in the embodiments of the present application can be implemented in various computer languages, for example, object-oriented programming language Java and literal scripting language JavaScript, etc.
[0094] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0095] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0096] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0097] Although the preferred embodiments of the present application have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications falling within the scope of the present application.
[0098] Obviously, the above embodiments are merely examples for clear explanation and are not intended to limit the implementation methods. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived from these are still within the protection scope of the invention.
Claims
1. A text prediction method based on an adaptive masking strategy, characterized in that: include: Step S1: randomly masking a target sequence Y in a text pair, calculating an initial mask ratio of a source sequence X in the text pair according to the mask ratio of the target sequence Y, and then performing current training on a model to be trained according to the mask ratio of the target sequence Y and the initial mask ratio of the source sequence X; Step S2: The prediction results of the current training of the model to be trained The unmasked part of the target sequence Y is combined to form a new target sequence Y', and the prediction result of the current training of the model to be trained is calculated The accuracy rate β; Step S3: masking the new target sequence Y' according to the accuracy β, calculating the re-masking ratio of the source sequence X according to the masking ratio of the new target sequence Y', and then re-training the model to be trained according to the masking ratio of the new target sequence Y' and the re-masking ratio of the source sequence X; Step S4: Compare the prediction result of the retraining of the model to be trained with the target sequence Y. If the comparison results are consistent, a trained model is obtained; if the comparison results are inconsistent, return to step S2 until the comparison results are consistent; Step S5: predict the text to be predicted according to the trained model; In step S1, the initial mask ratio of the source sequence X in the text pair is calculated according to the mask ratio of the target sequence Y, and the method is: Divide the target sequence Y into unmasked parts Y obs and the mask part Y mask , and according to the unmasked part Y obs and the mask part Y mask Calculate the mask ratio of the target sequence Y; Calculating an initial mask ratio of the source sequence X according to the mask ratio of the target sequence Y; The unmasked portion Y obs and the mask part Y mask Calculate the mask ratio of the target sequence Y, the formula is: Among them, α dec Indicates the mask ratio of the target sequence Y, N obs Represents the unmasked part Y in the target sequence Y obs The number of identifiers, N mask Represents the mask part Y in the target sequence Y mask The number of logos; The initial mask ratio of the source sequence X is calculated according to the mask ratio of the target sequence Y, and the formula is: α enc =(b1-a1)α dec +a1, where α enc represents the initial mask ratio of the source sequence X, b1 represents the first hyperparameter used to control the upper limit of the mask ratio, a1 represents the first hyperparameter used to control the lower limit of the mask ratio, α dec represents the mask ratio of the target sequence Y; In step S2, the prediction result of the current training of the model to be trained is calculated. The accuracy rate β is as follows: Among them, Y mask represents the mask part in the target sequence Y, Indicates the prediction result of the current training of the model. Represents Y mask and The number of identical identifiers in mask The masked part Y mask The number of logos; In step S3, the new target sequence Y' is masked according to the accuracy β, and the method is: the prediction result of the current training of the model in the new target sequence Y' is masked according to the accuracy β and the unmasked parts of the target sequence Y are respectively masked; The prediction result of the current training of the model in the new target sequence Y' according to the accuracy β And the unmasked parts of the target sequence Y are masked separately, specifically: The prediction results of the current model training The masking probability of each identifier in is set to 1-ψ(β), and the unmasked part Y obs The mask probability of each identifier in is set to ψ(β), where the formula of ψ(β) is: ψ(β)=(b2-a2)*β+a2, b2 represents the second hyperparameter for controlling the upper limit of the mask ratio, and a2 represents the second hyperparameter for controlling the lower limit of the mask ratio.
2. A text prediction system based on an adaptive masking strategy, characterized in that: include: Current training module: used to randomly mask the target sequence Y in the text pair, calculate the initial mask ratio of the source sequence X in the text pair according to the mask ratio of the target sequence Y, and then perform current training on the model to be trained according to the mask ratio of the target sequence Y and the initial mask ratio of the source sequence X; Computation module: used to calculate the prediction results of the current training of the model to be trained The unmasked part of the target sequence Y is combined to form a new target sequence Y', and the prediction result of the current training of the model to be trained is calculated The accuracy rate β; A retraining module is used to mask the new target sequence Y' according to the accuracy β, calculate the re-masking ratio of the source sequence X according to the masking ratio of the new target sequence Y', and then re-train the model to be trained according to the masking ratio of the new target sequence Y' and the re-masking ratio of the source sequence X; Comparison module: used to compare the prediction results of the retrained model to be trained with the target sequence Y. If the comparison results are consistent, a trained model is obtained; if the comparison results are inconsistent, it returns to the calculation module until the comparison results are consistent; Prediction module: used to predict the text to be predicted based on the trained model; In the current training module, the initial mask ratio of the source sequence X in the text pair is calculated according to the mask ratio of the target sequence Y, and the method is: Divide the target sequence Y into unmasked parts Y obs and the mask part Y mask , and according to the unmasked part Y obs and the mask part Y mask Calculate the mask ratio of the target sequence Y; Calculating an initial mask ratio of the source sequence X according to the mask ratio of the target sequence Y; The unmasked portion Y obs and the mask part Y mask Calculate the mask ratio of the target sequence Y, the formula is: Among them, α dec Indicates the mask ratio of the target sequence Y, N obs Represents the unmasked part Y in the target sequence Y obs The number of identifiers, N mask Represents the mask part Y in the target sequence Y mask The number of logos; The initial mask ratio of the source sequence X is calculated according to the mask ratio of the target sequence Y, and the formula is: α enc =(b1-a1)α dec +a1, where α enc represents the initial mask ratio of the source sequence X, b1 represents the first hyperparameter used to control the upper limit of the mask ratio, a1 represents the first hyperparameter used to control the lower limit of the mask ratio, α dec represents the mask ratio of the target sequence Y; The calculation module calculates the prediction results of the current training of the model to be trained The accuracy rate β is as follows: Among them, Y mask represents the mask part in the target sequence Y, Indicates the prediction result of the current training of the model. Represents Y mask and The number of identical identifiers in mask The masked part Y mask The number of logos; The retraining module masks the new target sequence Y' according to the accuracy β, and the method is: the prediction result of the current training of the model in the new target sequence Y' is masked according to the accuracy β and the unmasked parts of the target sequence Y are respectively masked; The prediction result of the current training of the model in the new target sequence Y' according to the accuracy β And the unmasked parts of the target sequence Y are masked separately, specifically: The prediction results of the current model training The masking probability of each identifier in is set to 1-ψ(β), and the unmasked part Y obs The mask probability of each identifier in is set to ψ(β), where the formula of ψ(β) is: ψ(β)=(b2-a2)*β+a2, b2 represents the second hyperparameter for controlling the upper limit of the mask ratio, and a2 represents the second hyperparameter for controlling the lower limit of the mask ratio.
3. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the text prediction method based on the adaptive mask strategy as claimed in claim 1 are implemented.
4. 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 text prediction method based on the adaptive mask strategy as claimed in claim 1 are implemented.
Citation Information
Patent Citations
Language model pre-training method and system for table pattern analysis and sequence masks
CN112559556A
Text detection model training method, text detection method, device and equipment
CN113239925A
