BERT model training method and system based on alternating direction method of multipliers

Through the combination of the multiplier alternating direction method and the enhanced Lagrangian algorithm, the problem of gradient disappearance and GPU memory limitation of the BERT model in event extraction is solved, efficient model training and parallel processing are achieved, and the efficiency and efficiency of event extraction are improved. Accuracy.

CN114818725BActive Publication Date: 2024-09-17NAT UNIV OF DEFENSE TECH
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202210368115.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-08
Publication Date
2024-09-17
Estimated Expiration
2042-04-08

AI Technical Summary

Technical Problem

The BERT model has gradient disappearance and explosion problems during the event extraction process, limited GPU memory, and difficulty in parallel training, resulting in low training efficiency and poor performance.

Method used

A training method based on the alternating direction method of multipliers is used to represent the BERT model through the Encoder module of the Transformer model. The enhanced Lagrangian algorithm is used to transform the objective function into an enhanced Lagrangian function, and the order is updated through the backward-forward parameters. Solve and simplify LayerNorm calculations to reduce memory redundancy.

Benefits of technology

It effectively avoids the problems of gradient disappearance and explosion, improves training efficiency and performance, realizes efficient training of the BERT model under large-scale data, and solves the problem of insufficient GPU memory and parallel training.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114818725B
    Figure CN114818725B
Patent Text Reader

Abstract

The present invention discloses a BERT model training method and system based on the multiplier alternating direction method, the method steps include: step S1. taking out the sentence to be trained from the training set and extracting the word vector and inputting it into the BERT model; step S2. when the BERT model trains the input word vector, the target function is solved by the multiplier alternating direction method, wherein the target function is determined, and the input word vector is added with restriction conditions, the determined target function is transformed into an enhanced Lagrangian function, and each variable parameter in the target function and the output result of the BERT model are solved by solving the enhanced Lagrangian function; step S3. updating the variable parameters solved in the target function until the training is completed, and the final BERT model training result output is obtained. The present invention has the advantages of being able to avoid the gradient vanishing and explosion problems in the training process, being easy to implement in parallel, having high training efficiency and good training performance.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of information extraction technology, and in particular to a BERT model training method and system based on the alternating direction multiplier method. Background Art

[0002] With the rapid development of the Internet in recent years, online media generates massive amounts of unstructured information such as news, push notifications, announcements, and notifications every day. In response to this massive amount of information, information extraction technology is to quickly and effectively capture valuable information from this information to help analyze certain specific information and make decisions based on this specific information. Event extraction is a branch of information extraction technology, which mainly extracts the event information that users are most interested in from unstructured natural language text and presents it in a structured form. Event extraction has a wide range of applications in many fields, such as building event knowledge graphs, information retrieval, automatic question answering, and assisting other natural language processing tasks. Event extraction can be divided into sentence level and chapter level from the text granularity. Sentence-level event extraction refers to identifying the content of interest from the sentence. First, deep neural networks such as dynamic multi-pooling convolutional neural networks are used to extract text features, and then event elements and roles are identified. Chapter-level event extraction is to identify events from the entire document and extract corresponding event elements.

[0003] Traditional event extraction algorithms mainly focus on pattern matching or statistical machine learning methods. Pattern matching-based methods can achieve good performance in specific fields, but have poor portability; statistical learning-based methods usually have good portability, but are heavily dependent on labeled data. Until recent years, attempts have been made to use CNN / RNN to extract semantics in event extraction, which can significantly improve the evaluation effect, and using DNN to capture semantics can also obtain word vectors with richer features, so the results of event extraction are no longer largely dependent on manually defined local / global features. The BERT (Bidirectional Encoder Representation from Transformers) model is a NLP (natural language processing) model based on deep learning networks that is widely used in the field of event extraction. Using the feature extraction of the BERT model, event-related elements can be effectively extracted from text and the role of the elements can be judged.

[0004] In the process of information extraction, especially in the event extraction task, the training effect of the BERT model is the key to determining the model's information extraction performance. At present, the training of the BERT model usually adopts the traditional deep learning training method. The main process is divided into two processes: forward calculation and back propagation. The forward calculation is: take N samples (x1, x2, x3, ... xN) from the data set X, and the corresponding data sample labels (y1, y2, y3, ..., yN). The corresponding output under the BERT model is (o1, o2, o3, ..., oN). The corresponding loss function value L of the model calculated under such data; the back propagation process first passes the gradient G of the loss result calculated in the forward direction to the forward layer of the BERT model for intermediate value calculation, and finally updates the parameters of the BERT model according to the gradient value. Repeat the above process until the BERT model converges or the model performance reaches the optimal level.

[0005] However, for the BERT model training in the event extraction process, the above training method will have the following problems:

[0006] 1. Gradient vanishing and gradient exploding: Since the gradient in the back propagation process is highly dependent, if the gradient value is too large or too small, it will affect the parameters of the model training, resulting in a decline in the final model performance, causing gradient vanishing and gradient exploding problems. Especially when applied to application areas such as event extraction (or text classification), since the model needs to be calculated based on the context information of the input sequence, the above problems are prone to occur when calculating the gradient value of the target loss function during the reverse calculation process, which in turn makes the BERT model difficult to train and has poor performance. There is also the problem of being unable to solve the long text encoding problem.

[0007] 2. GPU memory is limited: The number of parameters of the BERT model depends on the scale of matrix multiplication in the model. The number of parameters of the BERT model for event extraction is large and requires a large amount of memory space. When the number of parameters reaches a certain value, the current GPU devices cannot meet the memory requirements for training the BERT model.

[0008] 3. Parallelism is not easy to achieve: In order to solve the problem of insufficient GPU memory space, distributed training needs to be adopted. Distributed training mainly includes two methods: data parallelism and model parallelism. Data parallelism is to divide the training data according to the number of computing nodes in the training system. Each computing node only processes the assigned data. Although this type of method is simple to implement, it requires saving a copy of the completed model on each computing node. The BERT model still requires a lot of memory space when training using this type of parallel method, that is, there is still a problem of unmet memory requirements; model parallelism is to divide the neural network model and assign it to the computing nodes in the training system, but it is difficult for the BERT model to achieve model parallelism. Summary of the invention

[0009] The technical problem to be solved by the present invention is: in response to the technical problems existing in the prior art, the present invention provides a BERT model training method and system based on the alternating direction method of multipliers, which can avoid the gradient vanishing and explosion problems and the GPU memory limitation problem in the training process, and is easy to implement in parallel, has high training efficiency and good training performance.

[0010] In order to solve the above technical problems, the technical solution proposed by the present invention is:

[0011] A BERT model training method based on the multiplier alternating direction method, the steps comprising:

[0012] Step S1. Data input: Take the sentences to be trained from the training set, extract the word vectors, and input them into the BERT model;

[0013] Step S2. Solving by the alternating direction method of multipliers: When the BERT model trains the input word vector, the alternating direction method of multipliers is used to solve the objective function, wherein the objective function is determined by using the representation of the BERT model by the Encoder module in the Transformer model, and restrictions are added to the input word vector. The enhanced Lagrangian algorithm is used to transform the objective function into an enhanced Lagrangian function, and the parameters of each variable in the objective function and the output result of the BERT model are solved by solving the enhanced Lagrangian function;

[0014] Step S3. Parameter update: Update the variable parameters solved in the objective function until the training is completed, and obtain the final BERT model training result output for event extraction.

[0015] Furthermore, in step S2, the step of using the Encoder module in the Transformer model to represent the BERT model includes:

[0016] S201. The BERT model is represented by the Encoder module, and the mathematical expression of the BERT model is obtained as follows:

[0017] m eo =MultiHead(X n-1 , X n-1 , X n-1 )

[0018] l eo =LayerNorm(X n-1 +m eo )

[0019] f eo =FeedForward(leo )

[0020] X n =LayerNorm(l eo +f eo )

[0021] Among them, X n , X n-1 are the calculation output results of the nth and n-1th Encoder modules respectively. MultiHead represents the multi-head mechanism module. LayerNorm represents the regularization calculation module in deep learning. FeedForward represents the linear transformation module. eo 、m eo , l eo They represent the corresponding calculation output results after the FeedForward module, the multi-head mechanism module, and the regularization calculation module respectively;

[0022] S202. Perform ReZero approximation calculation on the operation of the LayerNorm module: simplify the LN layer in the Transformer model, and define a residual parameter α for each LN layer, and obtain the mathematical expression for representing the BERT model using the Encoder module:

[0023] m eo =MultiHead(X n-1 , X n-1 , X n-1 )

[0024] l eo =X n-1 +α n1 m eo

[0025] f eo =FeedForward(l eo )

[0026] X n = l eo +α n2 f eo

[0027] Among them, α n1 , α n2 Respectively represent m eo and f eo The corresponding residual parameter.

[0028] Furthermore, in step S2, the objective function is determined according to the following formula:

[0029]

[0030] Among them, for the convenience of representation, Φ is used to represent the final objective function to be solved, L is the loss function, and Ω is E ,Ω D , are regularization functions for E and D respectively, W Ei , W Di , X i-1 Respectively represent E i , D i The weight and the input data corresponding to the i-1th time, FF represents FeedForward, FF(L eo ) is represented by the input L eo The calculation output of FeedForward, v is represented as a hyperparameter.

[0031] Furthermore, in step S2, the mathematical expression using the Encoder module to represent the BERT model is used to set the restriction condition, namely:

[0032] m eo =Multihead(X n-1 , X n-1 , X n-1 )

[0033] l eo =X n-1 +α n1 m eo

[0034] f eo =FF(L eo )

[0035] X n =L eo +α n2 f eo .

[0036] Furthermore, in step S2, the enhanced Lagrangian function obtained by transformation is specifically:

[0037]

[0038] Among them, λ1, λ2, λ3, λ4 are Lagrangian operators, ρ1, ρ2, ρ3, ρ4 are hyperparameters;

[0039] By solving for the variable m eo , X n-1 , α n1 , l eo , f eo , α n2 , X n , in order to complete the solution of the objective function.

[0040] Furthermore, in step S3, the variable parameters solved in the objective function are updated using a backward-forward parameter update order, that is, the forward process is updated according to the rule of first updating the weights and then updating the biases, and the backward process is updated according to the rule of first updating the biases and then updating the weights.

[0041] Furthermore, for the variable parameters to be solved in the objective function, specifically according to X n →α n2 →f eo → eo →α n1 →m eo →X n-1 →X n-1 →m eo →α n1 → eo →f eo →α n2 →X n Update in the order of n , X n-1 are the calculation output results of the nth and n-1th Encoder modules respectively, eo 、m eo , l eo They represent the corresponding calculation output results after the FeedForward module, the multi-head mechanism module and the regularization calculation module respectively; α n1 , α n2 Respectively represent m eo and f eo The corresponding residual parameter.

[0042] Furthermore, in step S3, after the target parameter is updated, the memory occupied by the updated parameter is immediately released.

[0043] A BERT model training system based on the alternating direction method of multipliers includes a processor and a memory, wherein the memory is used to store a computer program, the processor is used to execute the computer program, and the processor is used to execute the computer program to perform the above method.

[0044] A computer-readable storage medium storing a computer program, wherein the computer program implements the above method when executed.

[0045] Compared with the prior art, the advantages of the present invention are:

[0046] 1. The present invention fully considers the characteristics of event extraction and the method based on the alternating direction of multipliers. In the process of training the BERT model after extracting the word vectors for the sentences to be trained in the training set, the method of alternating direction of multipliers is used to solve the BERT model. On the one hand, it can solve the inevitable gradient vanishing and explosion problems existing in traditional stochastic gradient algorithms, and on the other hand, it can utilize the characteristics of the method of alternating direction of multipliers that are easy to implement in parallel to perform parallel processing on the parameters in the training process, which can solve the problem that the BERT model cannot be trained with a single accelerator card when the number of parameters is too large, greatly improving the training efficiency. In addition, the input data length will not affect the performance of the method of alternating direction of multipliers, so it can also solve the model performance problem of the BERT model under long input text in the event extraction task, thereby effectively improving the efficiency and accuracy of event extraction.

[0047] 2. The present invention represents the BERT model by using the Encoder module in the Transformer model, constructs an objective function based on the obtained mathematical expression, and obtains the mathematical form of the alternating direction multiplier method for solving the Transformer, so that the alternating direction multiplier method can be applied to the training of the BERT model in event extraction, and the BERT model is solved by the alternating direction multiplier method, thereby making full use of the advantages of the alternating direction multiplier method to effectively improve the performance of BERT model training.

[0048] 3. The present invention further simplifies the calculation of LayerNorm by adopting ReZero in the process of model solving, which can greatly reduce the amount of calculation and memory redundancy of calculation.

[0049] 4. The present invention further adopts a backward-forward parameter update sequence to update the variable parameters solved in the objective function, which can not only ensure the performance of the model, but also accelerate the convergence of the model and reduce the model training time.

[0050] 5. The present invention further releases the memory occupied by the no longer needed parameters immediately after the corresponding parameter update is completed, which can effectively save memory and enable reasonable use of the GPU memory, thereby meeting the demand for large-scale model training under limited GPU resources. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] Figure 1 It is a schematic diagram of the implementation flow of the BERT model training method based on the alternating direction method of multipliers in this embodiment.

[0052] Figure 2 Schematic diagram of the structure principle of the Scaled Dot-Product Attention module in the Transformer model used in this embodiment.

[0053] Figure 3 Schematic diagram of the structure principle of the Multi-Head Attention module in the Transformer model used in this embodiment.

[0054] Figure 4 Schematic diagram of the structure principle of the Transformer model used in this embodiment.

[0055] Figure 5 Schematic diagram of the structural principle of the BERT model used in this embodiment.

[0056] Figure 6 It is a schematic diagram of the principle of implementing event extraction in a specific application embodiment of the present invention. DETAILED DESCRIPTION

[0057] The present invention is further described below in conjunction with the accompanying drawings and specific preferred embodiments, but the protection scope of the present invention is not limited thereby.

[0058] like Figure 1 As shown, the steps of the BERT model training method based on the multiplier alternating direction method in this embodiment include:

[0059] Step S1. Data input: Take the sentences to be trained from the training set, extract the word vectors, and input them into the BERT model;

[0060] Step S2. Solving by the alternating direction method of multipliers: When the BERT model trains the input word vector, the alternating direction method of multipliers is used to solve the objective function, wherein the objective function is determined by using the Encoder module in the Transformer model to represent the BERT model, and restrictions are added to the input word vector. The enhanced Lagrangian algorithm is used to transform the objective function into an enhanced Lagrangian function, and the parameters of each variable in the objective function and the output result of the BERT model are solved by solving the enhanced Lagrangian function;

[0061] Step S3. Parameter update: Update the variable parameters solved in the objective function until the training is completed, and obtain the final BERT model training result output for event extraction.

[0062] The alternating direction method of multipliers (ADMM) is a computational framework for solving separable convex optimization problems. It has fast processing speed and good convergence performance. It is very suitable for solving distributed convex optimization problems, especially statistical learning problems. The alternating direction method of multipliers restricts the objective function F(x,y) to Ax+By=C, and uses the enhanced Lagrangian algorithm to transform the original objective function into an enhanced Lagrangian function, so that the original objective function to be solved becomes the solution of the enhanced Lagrangian function. In the solution process, the variables x and y are alternately solved using the existing parameters. Different from the traditional deep learning training method, the gradient of the objective function is not calculated during the entire solution process based on the alternating direction method of multipliers. Instead, the analytical solution of the objective function is directly solved, so the gradient will not be used for back propagation, which can avoid the common gradient vanishing and gradient exploding problems in traditional deep learning. In addition, the alternating direction method of multipliers also takes into account the advantages of training robustness, easy parallel implementation, and fast convergence speed. It is particularly suitable for event extraction tasks involving large amounts of data and large numbers of parameters, and can effectively improve the efficiency and accuracy of event extraction.

[0063] This embodiment fully considers event extraction and the above characteristics based on the alternating direction method of multipliers. In the process of training the BERT model after extracting the word vectors from the sentences to be trained in the training set, the alternating direction method of multipliers is used to solve the BERT model. In the solution process, the structural characteristics of the BERT model are combined, and the Encoder module in the Transformer model is used to represent the BERT model to determine the objective function, and restrictions are added to the input word vectors. The solution of the objective function is converted into the solution of the enhanced Lagrangian function to achieve the training of the BERT model. The alternating direction method of multipliers can solve the inevitable gradient vanishing and explosion problems existing in traditional stochastic gradient algorithms on the one hand, and on the other hand, the characteristics of the alternating direction method of multipliers that are easy to implement in parallel can be used to perform parallel processing on the parameters in the training process, which can solve the problem that the BERT model cannot be trained with a single accelerator card when the number of parameters is too large, and greatly improve the training efficiency. In addition, the input data length will not affect the performance of the alternating direction method of multipliers, so it can also solve the model performance problem of the BERT model under long input text in the event extraction task.

[0064] To apply the alternating direction method of multipliers to BERT model training, it is necessary to first formalize its mathematical expression in the case of input data and corresponding labels (X, Y) according to the model form of the Transformer model, so as to facilitate the subsequent construction of the required objective function. The BERT model generally contains L Transformer model Encoder modules. The Transformer model can be decomposed into three parts: Scaled Dot-Product Attention, Multi-Head Attention in Transformer, and the overall Transformer structure. The formalization process of each part includes:

[0065] (1) For Scaled Dot-Product Attention, Figure 2 As shown, input Q, K, V weight matrices, first Q and K matrices are multiplied and then scaled, the scaling result is input into the softmax (normalized exponential) function, and finally multiplied with matrix V. The mathematical expression can be expressed as:

[0066]

[0067] where d k is the dimension of input K.

[0068] (2) For the Multi-Head Attention mechanism, such as Figure 3 As shown in the figure, the three weight matrices Q, K, and V are linearly transformed, and the results of the linear transformation are input into h Scaled Dot-Product Attentions. Each Scaled Dot-Product Attention can be regarded as a head. The calculation results of all heads are concatenated and linearly transformed, which can be expressed mathematically as follows:

[0069] MultiHead(Q,K,V)=concat(head1,...,head h )W o (2)

[0070] head i =Attention(QW i Q , KW i K , VW i V ) (3)

[0071] Among them, QWi Q , KW i K 、VW i V Respectively represent the product of the three input matrices Q, K, and V and the corresponding weight calculation results, W o Represents the weight under the multi-head attention mechanism, W is the training weight corresponding to the input, and concat represents the cascade operation.

[0072] Based on the above expression, the complete Transformer model can be mathematically formalized. Figure 4 As shown, the Transformer model can be divided into two parts: Encoder module and Decoder module, with N encoders and N decoders respectively. Assuming the input data is X0, in the nth Encoder module, its formula is expressed as:

[0073] m eo =MultiHead(X n-1 , X n-1 , X n-1 )

[0074] l eo =LayerNorm(X n-1 +m eo )

[0075] f eo =FeedForward(l eo )

[0076] X n =LayerNorm(l eo +f eo ) (4)

[0077] Among them, m eo 、f eo , l eo They respectively represent the corresponding calculation output results after the FeedForward module, the multi-head mechanism module and the regularization calculation module.

[0078] In the nth Decoder module, the formula is expressed as:

[0079] m do =MultiHead(Y,Y,Y)

[0080] l do1 =LayerNorm(Y+m do )

[0081] l do2=LayerNorm(l do1 +Multihead(X n , X n , l do1 ))

[0082] l do3 =LayerNorm(l do2 +Multihead(l do2 , l do2 , Y))

[0083] o=LayerNorm(l do3 +FeedForward(l do3 )) (5)

[0084] Among them, X n is the calculation output result of the nth Encoder module, LayerNorm is the regularization processing, and FeedForward represents the linear transformation.

[0085] The BERT model generally contains L Transformer model Encoder modules, such as Figure 5 As shown in the figure, after the output of the last Decoder module, a linear transformation and softmax are performed to obtain the output of the entire Transformer model. Based on the mathematical formula of the above Transformer model, the Encoder module is used to represent the BERT model, and the mathematical formula can be obtained as follows:

[0086] m eo =MultiHead(X n-1 , X n-1 , X n-1 )

[0087] l eo =LayerNorm(X n-1 +m eo )

[0088] f eo =FeedForward(l eo )

[0089] X n =LayerNorm(l eo +f eo ) (6)

[0090] Among them, X nIt is the calculation output result of the nth Encoder module, where n is generally 1, 2, ..., 12, wherein X0 represents the output result after the embedding layer. In this embodiment, the embedding layer is not considered in the mathematical representation of the BERT model.

[0091] After N Encoder modules, the output result is X N The output of the BERT model after a linear classification layer is:

[0092] o=classifier(X n ) (7)

[0093] Among them, classifier represents the linear classification layer, and o represents the output result.

[0094] Since the BERT model needs to use different classification layers for different tasks, in order to simplify the calculation, this embodiment uses the output result X after passing through N Encoder modules N As the target output of the solution, the target solved by the multiplier alternating direction method is X N , which is the final calculation solution goal.

[0095] In the actual calculation process, since the LayerNorm operation is not suitable for intuitive mathematical solutions, this embodiment performs ReZero approximation calculation on the LayerNorm operation to simplify and approximate the complex regularization calculation in a simple form, thereby reducing the amount of calculation and memory redundancy. Specifically, when performing ReZeRO approximation calculation in this embodiment, the LayerNorm layer in the Transformer model is simplified, and a residual parameter α is defined for each LayerNorm layer. The calculation formula of the LayerNorm layer is:

[0096] x i+1 =x i +α i F i (x i ) (8)

[0097] Among them, x i+1 、x i They represent the output of the LayerNorm layer of the i-th layer, α i represents the residual parameter of the i-th LayerNorm layer, F i Represents the calculation function of the i-th layer.

[0098] After the above equivalent transformation, the high computational complexity introduced by the original LayerNorm layer is reduced to the calculation of the residual parameter α. The original computational complexity of this layer is O(n 2 ), after ReZero processing, the computational complexity of this layer can be reduced to O(1). This embodiment simplifies the calculation of LayerNorm by using ReZero, which can greatly reduce the amount of calculation and the memory redundancy of the calculation.

[0099] After ReZeRO processing, the mathematical expression of the BERT model using the Encoder module is finally obtained:

[0100] m eo =MultiHead(X n-1 , X n-1 , X n-1 )

[0101] l eo =X n-1 +α n1 m eo

[0102] f eo =FeedForward(l eo )

[0103] X n = l eo +α n2 f eo (9)

[0104] Among them, α n1 , α n2 Respectively represent m eo and f eo The corresponding residual parameter.

[0105] After the above process, the Encoder module can be used to represent the BERT model, and a mathematical expression representing the BERT model can be obtained, as shown in formula (9), which facilitates the subsequent solution of the BERT model based on the multiplier alternating method.

[0106] In step S2 of this embodiment, the detailed steps of using the Encoder module in the Transformer model to represent the BERT model specifically include:

[0107] S201. The BERT model is represented by the Encoder module to obtain a mathematical expression of the BERT model, as shown in formula (6);

[0108] S202. Perform ReZero approximation calculation on the operation of the LayerNorm module: simplify the LN layer in the Transformer model and define a residual parameter α for each LayerNorm layer to obtain a mathematical expression for representing the BERT model using the Encoder module, as shown in formula (9).

[0109] For the target loss function L, the target loss function L in this embodiment is specifically a cross entropy function, which can be expressed as L(X, Y), where (X, Y) represents the input data and the corresponding data label. In step S2 of this embodiment, the target function is determined specifically according to the following formula:

[0110]

[0111] Among them, for the convenience of representation, Φ is used to represent the final objective function to be solved, L is the loss function, and Ω is E ,Ω D , are regularization functions for E and D, respectively. E and D represent the Encoder and Decoder modules in the Transformer module, respectively. W Ei , W Di , X i-1 Respectively represent E i , D i The weight and the input data corresponding to the i-1th time, FF represents FeedForward, FF(l eo ) is represented as input l eo The calculation output of FeedForward, v is represented as a hyperparameter.

[0112] In this embodiment, the BERT model is represented by the Encoder module in the Transformer model, and an objective function is constructed based on the obtained mathematical expression, that is, the above formula (10) is used as the optimization target, and the mathematical form of the multiplier alternating direction method for solving the Transformer is obtained, so that the multiplier alternating direction method can be applied to the training of the BERT model in event extraction, and the multiplier alternating direction method is used to solve the BERT model, so as to fully utilize the advantages of the multiplier alternating direction method to effectively improve the performance of BERT model training and solve the problems of gradient explosion, memory limitation and performance degradation of long input text.

[0113] In step S2 of this embodiment, the Encoder module is used to set a restriction condition on the mathematical expression representing the BERT model to determine the restriction condition AX+BY=C between the input data (X, Y). The restriction condition is specifically:

[0114] m eo =Multihead(Xn-1 , X n-1 , X n-1 )

[0115] l eo =X n-1 +α n1 m eo

[0116] f eo =FF(l eo )

[0117] X n = l eo +α n2 f eo (11)

[0118] This embodiment constructs the above-mentioned restriction conditions according to the specific calculation form of the BERT model, so that the BERT model can be combined with the alternating direction method of multipliers, so that the alternating direction method of multipliers can be used to solve the BERT model.

[0119] Based on the above formal expression, the alternating direction method of multipliers is applied to the objective function to further form the formalized enhanced Lagrangian function: In step S2 of this embodiment, the enhanced Lagrangian function obtained by formalization and transformation is specifically:

[0120]

[0121] Among them, λ1, λ2, λ3, λ4 are Lagrangian operators, and ρ1, ρ2, ρ3, ρ4 are hyperparameters.

[0122] At this point, the original optimization objective function is transformed into an optimization problem for the transformed enhanced Lagrangian function. Different from the traditional deep learning solution method, the solution of the enhanced Lagrangian function in this embodiment is to solve the variable m in the function. eo , X n-1 , α n1 , l eo , f eo , α n2 , X n The solution of X is then completed to solve the objective function. n The value is input into the classification layer, and the result of the classification layer is compared with the data label Y to obtain the calculated loss result.

[0123] In the multiplier alternating direction method, the order of parameter update is very important. An inappropriate parameter update order may cause the model training to not converge. According to the general principle of the multiplier alternating direction method, the target parameter order for solving the Transformer model is X n-1 →m eo →α n1 → eo →f eo →α n2 →X n , it is also necessary to update the Lagrangian operators λ1, λ2, λ3, and λ4. In order to accelerate the convergence of the model, in step S3 of this embodiment, the variable parameters solved in the objective function are updated in a backward-forward parameter update order, that is, the update order of the backward process is exactly the opposite of the forward process (updating the bias first and then the weight) according to the rule of updating the weight first in the forward process, and the update order of the backward process is exactly the opposite of the forward process (updating the bias first and then the weight). This can not only ensure the performance of the model, but also accelerate the convergence of the model and reduce the model training time.

[0124] In this embodiment, the variable parameters to be solved in the objective function are specifically calculated according to X n →α n2 →f eo → eo →α n1 → m eo →X n-1 →X n-1 →m eo →α n1 → eo →f eo →α n2 →X n Update in the order of n , X n-1 are the calculation output results of the nth and n-1th Encoder modules respectively, eo 、m eo , l eo They represent the corresponding calculation output results after the FeedForward module, the multi-head mechanism module and the regularization calculation module respectively; α n1 , α n2 Respectively represent m eo and f eo The corresponding residual parameter.

[0125] In step S3 of this embodiment, after the target parameter is updated, the memory occupied by the updated parameter is immediately released. Since the alternating direction method of multipliers couples the update of each parameter in each iteration and is independent of the gradient during the parameter update, this embodiment can effectively save memory by releasing the memory occupied by the no longer needed parameters immediately after the corresponding parameter update is completed and clearing the memory in time, thereby enabling reasonable use of the GPU memory and meeting the needs of large-scale model training under limited GPU resources.

[0126] The detailed steps of using the above method to perform BERT training and implement event extraction in a specific application embodiment of the present invention are as follows:

[0127] Step 1: Obtain training set: Use English Wikipedia and BooksCorpus datasets as training sets;

[0128] Step 2: Model training: Get the initial BERT model, input the training set into the initial BERT model, and train the training set using the model training method described above, namely:

[0129] Step 2.1. Data input: Take the sentences to be trained from the training set, extract the word vectors, and input them into the BERT model;

[0130] Step 2.2. Solution using the alternating direction method of multipliers: When the BERT model is training the input word vector, the alternating direction method of multipliers is used to solve the objective function. The objective function is determined by using the Encoder module in the Transformer model to represent the BERT model, and restrictions are added to the input word vector. The enhanced Lagrangian algorithm is used to transform the objective function into an enhanced Lagrangian function. By solving the enhanced Lagrangian function, the parameters of each variable in the objective function and the output result of the BERT model are solved.

[0131] Step 2.3. Parameter update: Update the variable parameters solved in the objective function until the training is completed and the final BERT model training result output is obtained for event extraction.

[0132] The detailed process of each step is as described above.

[0133] Step 3: Model fine-tuning: Get the pre-trained weights of the model trained in step 2, and fine-tune the pre-trained model weights according to the current event extraction task to obtain the final BERT model training results.

[0134] Step 4: Event extraction:

[0135] Step 4.1: Extract the word vectors of the sentence to be extracted and output them to the BERT model to obtain the context information of each word in the sentence, so as to capture the interdependence between the components in the sentence from the perspective of the entire sentence;

[0136] Step 4.2 calculates the correlation between the words in the sentence, thereby obtaining the event trigger words and event elements in each event, as well as the event type and role they represent, to complete event extraction.

[0137] As Figure 6 Take the example shown in the figure for example. There are two events in this example. From the syntactic dependency, according to the noun subject relationship (nsubj), it can be concluded from the event element cameraman and the trigger word died that the role of a Victim in the event Die is cameraman, but there is no direct dependency relationship between cameraman and the trigger word fired of another event. Therefore, it is very difficult to find the event element with the role of Target for the Attack type event in the figure based only on the traditional dependency relationship. To solve this problem, this embodiment uses the sequence-to-sequence structure of the Transformer model to comprehensively utilize the contextual semantics and grammatical information of the entire sentence to capture and determine the potential correlation between trigger words and event elements. At the same time, the BERT model is solved by the alternating direction method of multipliers, which can break through the limitations of the backpropagation algorithm and the stochastic gradient algorithm in the traditional deep learning field, and solve the inherent and unavoidable gradient vanishing and explosion problems in the above algorithms. In addition, since the enhanced Lagrangian function is used to solve the analytical solution of the objective function, the model solving performance is better, the convergence speed is faster, and the solving process is more stable. At the same time, the use of the alternating direction method of multipliers to solve the BERT model is easier to implement in model parallelism, which effectively alleviates the GPU memory redundancy problem in data parallelism caused by too many parameters and the problem that model parallelism is difficult to implement.

[0138] This embodiment also discloses a BERT model training system based on the alternating direction method of multipliers, including a processor and a memory, the memory is used to store a computer program, the processor is used to execute the computer program, and the processor is used to execute the computer program to perform the above method.

[0139] This embodiment also discloses a computer-readable storage medium storing a computer program, and the computer program implements the above method when executed.

[0140] The present invention can be applied to event extraction in multiple fields such as question-answering systems and reading comprehension, text summarization, text classification, etc. It can also be applied to other types of information extraction and even other types of natural language processing.

[0141] The above is only a preferred embodiment of the present invention, and does not limit the present invention in any form. Although the present invention has been disclosed as a preferred embodiment, it is not intended to limit the present invention. Therefore, any simple modification, equivalent change and modification made to the above embodiment according to the technical essence of the present invention without departing from the content of the technical solution of the present invention shall fall within the scope of protection of the technical solution of the present invention.

Claims

1. A BERT model training method based on the alternating direction method of multipliers, characterized in that the steps include: Step S1. Data input: Take the sentences to be trained from the training set, extract the word vectors, and input them into the BERT model; Step S2. Solving by the alternating direction method of multipliers: When the BERT model trains the input word vector, the alternating direction method of multipliers is used to solve the objective function, wherein the objective function is determined by using the representation of the BERT model by the Encoder module in the Transformer model, and restrictions are added to the input word vector. The enhanced Lagrangian algorithm is used to transform the objective function into an enhanced Lagrangian function, and the parameters of each variable in the objective function and the output result of the BERT model are solved by solving the enhanced Lagrangian function; Step S3. Parameter update: Update the variable parameters solved in the objective function until the training is completed, and obtain the final BERT model training result output for event extraction.

2. The BERT model training method based on the alternating direction method of multipliers according to claim 1, characterized in that: The step of using the Encoder module in the Transformer model to represent the BERT model in step S2 includes: S201. The BERT model is represented by the Encoder module, and the mathematical expression of the BERT model is obtained as follows: m eo =MultiHead(X n-1 ,X n-1 ,X n-1 ) l eo =LayerNorm(X n-1 +m eo ) f eo =FeedForward(l eo ) X n =LayerNorm(l eo +f eo ) Among them, X n , X n-1 are the calculation output results of the nth and n-1th Encoder modules respectively. MultiHead represents the multi-head mechanism module. LayerNorm represents the regularization calculation module in deep learning. FeedForward represents the linear transformation module. eo 、m eo , l eo They represent the corresponding calculation output results after the FeedForward module, the multi-head mechanism module, and the regularization calculation module respectively; S202. Perform ReZero approximation calculation on the operation of the LayerNorm module: simplify the LN layer in the Transformer model, and define a residual parameter α for each LN layer, and obtain the mathematical expression for representing the BERT model using the Encoder module: m eo =MultiHead(X n-1 ,X n-1 ,X n-1 ) l eo =X n-1 +a n1 m eo f eo =FeedForward(l eo ) X n =l eo +a n2 f eo Among them, α n1 , α n2 Respectively represent m eo and f eo The corresponding residual parameter.

3. The BERT model training method based on the alternating direction method of multipliers according to claim 2, characterized in that: In step S2, the objective function is determined according to the following formula: Among them, Φ represents the final objective function to be solved, L represents the loss function, and Ω E ,Ω D are the regularization functions for E and D, respectively. E and D represent the Encoder and Decoder modules in the Transformer module, respectively. W Ei , W Di , X i-1 Respectively represent E i , D i The weight and the input data corresponding to the i-1th time, FF represents FeedForward, FF(l eo ) is represented as input l eo The calculation output of FeedForward, ν is represented as a hyperparameter.

4. The BERT model training method based on the alternating direction method of multipliers according to claim 3, characterized in that: In step S2, the mathematical expression representing the BERT model using the Encoder module is used to set the restriction condition, namely: m eo =Multihead(X n-1 ,X n-1 ,X n-1 ) l eo =X n-1 +a n1 m eo f eo =FF(l eo ) X n =l eo +a n2 f eo 。 5. The BERT model training method based on the alternating direction method of multipliers according to claim 2, characterized in that: In step S2, the enhanced Lagrangian function obtained by transformation is specifically: Among them, λ1, λ2, λ3, λ4 are Lagrangian operators, ρ1, ρ2, ρ3, ρ4 are hyperparameters; By solving for the variable m eo , X n-1 , α n1 , l eo , f eo , α n2 , X n , in order to complete the solution of the objective function.

6. The BERT model training method based on the alternating direction method of multipliers according to any one of claims 1 to 5, characterized in that: In step S3, the variable parameters solved in the objective function are updated using a backward-forward parameter update sequence, that is, the forward process is updated according to the rule of first updating the weights and then updating the biases, and the backward process is updated according to the rule of first updating the biases and then updating the weights.

7. The BERT model training method based on the alternating direction method of multipliers according to claim 6, characterized in that: For the variable parameters to be solved in the objective function, specifically according to X n →α n2 →f eo → eo →α n1 →m eo →X n-1 →X n-1 →m eo →α n1 → eo →f eo →α n2 →X n Update in the order of n , X n-1 are the calculation output results of the nth and n-1th Encoder modules respectively, eo 、m eo , l eo They represent the corresponding calculation output results after the FeedForward module, the multi-head mechanism module and the regularization calculation module, respectively. n1 , α n2 Respectively represent m eo and f eo The corresponding residual parameter.

8. The BERT model training method based on the alternating direction method of multipliers according to any one of claims 1 to 5, characterized in that: In step S3, after the target parameter is updated, the memory occupied by the updated parameter is released immediately.

9. A BERT model training system based on the alternating direction method of multipliers, comprising a processor and a memory, wherein the memory is used to store a computer program, and the processor is used to execute the computer program, characterized in that: The processor is configured to execute the computer program to perform the method according to any one of claims 1 to 8.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed, the method according to any one of claims 1 to 8 is implemented.

Citation Information

Patent Citations

  • Deep text matching method and device based on word migration learning

    CN109992648A

  • Simplified width learning system based on L1 and L2 norms

    CN111680846A

  • E-commerce customer service matching method and corresponding device, equipment and medium

    CN113434656A

  • Case judgment prediction method and system based on BERT hidden layer information and medium

    CN114219682A