Text processing methods and systems based on Transformer networks
By updating the encoded times in the Transformer network and cyclically filling the input text, the problem of low GPU utilization under large amounts of data is solved, achieving high-speed text processing and efficient utilization of GPU resources.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-23
- Publication Date
- 2026-04-03
AI Technical Summary
Existing Transformer models based on early exit mechanisms suffer from low GPU utilization and computational efficiency when the batch size is greater than 1, and exhibit significant bottleneck effects, making them difficult to handle large-scale data processing.
By updating the number of times each input text has been encoded in the Transformer network and determining whether it can exit early or reach the maximum number of computation layers, the encoder with the same parameters is used for cyclic filling and encoding calculation to achieve a dynamic exit process and maintain high GPU utilization.
Without modifying the underlying operators, it effectively supports large-scale data processing, improves the model's text processing speed, avoids the bottleneck effect, and enhances GPU utilization and model processing speed.
Smart Images

Figure CN115455979B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of natural language processing technology, specifically to a text processing method and system based on Transformer networks. Background Technology
[0002] Natural Language Processing (NLP) is a subfield of human language, computer science, and artificial intelligence, aiming to enable machines to understand, analyze, and utilize natural language. Downstream tasks include sentiment analysis and text classification. With the rapid development of deep neural networks, especially the emergence of numerous pre-trained NLP models based on the Transformer architecture, the accuracy of various natural language understanding tasks has been significantly improved. However, due to the enormous computational cost of pre-trained models, high latency has become a major challenge.
[0003] like Figure 1 As shown, in case 1 (data batch size 1) and case 3 (data batch size N), large pre-trained models such as BERT first convert the input text into tensors through a word embedding layer. Then, multiple encoders (encoder 0 to encoder d-1) encode the tensors to extract high-dimensional features. Finally, a classification layer converts the tensors into classification results. In this process, due to the large computational cost of the encoders, the latency from text input to output is high.
[0004] To address the issue of high latency, existing technologies offer a solution based on an early exit mechanism. Specifically, in case 2 where the data batch size is 1, an exit layer is added after each encoder to determine whether the current input can exit early at this layer. If the exit layer determines that the current layer can exit early, it directly outputs the classification result at this layer, completing the calculation process for this text, without needing to send it to the next encoder for calculation. If the exit layer determines that the current layer cannot exit early, it continues to send it to the next encoder for calculation, until the exit layer determines that it can exit or all encoder calculations are completed. By introducing an early exit mechanism, a dynamic exit process can be effectively implemented for different input texts, effectively reducing the number of encoder calculations and also effectively reducing model latency.
[0005] However, while the aforementioned solution based on early exit mechanisms offers significant speedup on the Trasnformer architecture, it is difficult to apply on GPUs when the batch size is greater than 1. For example... Figure 3As shown, in case 4 where the data batch size is N, for multiple texts within a batch, the exit positions differ, and the overall latency of the model depends on the last text to exit in that batch, causing the so-called "bottleneck effect." In this case, GPU utilization gradually decreases within a batch. Compared to case 3, which does not use the early exit method, GPU utilization is low, and the acceleration effect is not significant. The early exit mechanism has poor compatibility with GPUs handling data batch sizes greater than 1, resulting in low computational efficiency. Summary of the Invention
[0006] This application provides a text processing method and system based on Transformer networks to solve the problem that existing solutions based on early exit mechanisms are limited to cases where the data batch size is 1.
[0007] The first aspect of this application provides a text processing method based on a Transformer network, comprising:
[0008] After the current encoding calculation, update the number of times each input text in a data batch has been encoded;
[0009] Determine whether each input text can be exited early, and determine whether the number of times each input text has been encoded has reached the preset maximum number of computation layers;
[0010] If there is input text that can be exited early or the number of times it has been encoded has reached the preset maximum number of calculation layers, then the corresponding input text is updated with the text to be processed.
[0011] The next encoding calculation is performed on each input text in the data batch, and the encoder with the same parameters is used for each encoding calculation.
[0012] One implementation also includes:
[0013] The process involves repeated encoding calculations, determining whether each input text can be exited early or whether the number of times each input text has been encoded has reached the preset maximum number of calculation layers, and updating the corresponding input text with the text to be processed, until all texts to be processed have been processed.
[0014] In one implementation, before updating the encoded count of each input text within a data batch after the current encoding calculation, the method further includes:
[0015] Obtain a set of texts to be processed, which includes multiple texts to be processed;
[0016] Initialize the input tensor set. The number of positions of the tensors in the input tensor set is equal to the data batch size. The initial values of the tensors are empty.
[0017] Initialize the encoding count set. The number of elements in the encoding count set is the size of the data batch. Each element is used to record the number of times the corresponding input text has been encoded. The initial value of each element is empty.
[0018] Extract the number of missing positions in the input tensor set to obtain at least one piece of input text;
[0019] Add the padding tensor, which is the result of converting the input text, to the empty position in the input tensor set;
[0020] Encode and calculate each tensor in the input tensor set.
[0021] In one implementation, updating the encoded count of each input text within a data batch includes:
[0022] Increment each element in the encoding count set by 1.
[0023] In one implementation, the step of updating the corresponding input text with the text to be processed if there is input text that can be exited early or has reached a preset maximum number of encoding times includes:
[0024] If there is input text that can be exited early or the number of encoding times has reached the preset maximum number of computation layers, then the tensor corresponding to the input tensor set will be set to empty, and the element corresponding to the encoding times set will be set to empty.
[0025] Repeat the process of retrieving the number of empty positions in the input tensor set and adding the resulting filling tensor to the empty positions in the input tensor set.
[0026] In one implementation, the method further includes: if the input text fails to exit early and the number of encoding iterations has not reached the preset maximum number of calculation layers, then proceed directly to the next encoding calculation.
[0027] A second aspect of this application provides a text processing system based on a Transformer network, comprising:
[0028] The update encoding count module is used to update the encoding count of each input text in a data batch after the current encoding calculation.
[0029] The judgment module is used to determine whether each input text can be exited early, and whether the number of times each input text has been encoded has reached the preset maximum number of calculation layers.
[0030] The input text update module is used to update the corresponding input text with the text to be processed if there is input text that can be exited early or the number of times the encoding has been reached reaches the preset maximum number of calculation layers.
[0031] The next encoding calculation module is used to perform the next encoding calculation on each input text in the data batch. The encoder with the same parameters is used for each encoding calculation.
[0032] In one implementation, a repetitive encoding module is also included. The repetitive encoding module is used for repetitive encoding calculation, determining whether each input text can be exited early or whether the number of times each input text has been encoded has reached the preset maximum number of calculation layers, and updating the corresponding input text with the text to be processed, until all texts to be processed have been processed.
[0033] One implementation also includes:
[0034] The acquisition module is used to acquire a set of texts to be processed, which includes multiple texts to be processed.
[0035] The Tensor Initialization module is used to initialize the input tensor set. The number of positions of the tensors in the input tensor set is equal to the data batch size, and the initial value of the tensors is empty.
[0036] The initialization encoding count module is used to initialize the encoding count set. The number of elements in the encoding count set is the data batch size. Each element is used to record the number of times the corresponding input text has been encoded. The initial value of each element is empty.
[0037] The text input module is used to extract the number of missing positions in the input tensor set of the text to be processed, so as to obtain at least one input text.
[0038] The text filling module is used to add the filled tensor, which is converted from the input text, to the empty positions in the input tensor set;
[0039] The current encoding calculation module is used to perform encoding calculations on each tensor in the input tensor set.
[0040] In one implementation, the update input text module is further configured as follows:
[0041] If there is input text that can be exited early or the number of encoding times has reached the preset maximum number of computation layers, then the tensor corresponding to the input tensor set will be set to empty, and the element corresponding to the encoding times set will be set to empty.
[0042] Repeat the process of retrieving the number of empty positions in the input tensor set and adding the resulting filling tensor to the empty positions in the input tensor set.
[0043] As can be seen from the above technical solution, after the current encoding calculation, this application updates the number of times each input text in a data batch has been encoded, and determines whether each input text can exit early, and whether the number of times each input text has been encoded has reached the preset maximum number of computation layers. If there is an input text that can exit early or the number of times it has been encoded has reached the preset maximum number of computation layers, then the corresponding input text is updated with the text to be processed, and the next encoding calculation is performed on each input text in the data batch. Each encoding calculation uses an encoder with the same parameters. Based on the reuse of encoder parameters and the cyclic filling of input text, the number of texts processed simultaneously by the model on the GPU remains constant at the data batch size. Without modifying the underlying operators, it effectively accommodates the early exit mechanism and data batch sizes greater than 1. By introducing an early exit mechanism, without changing the original model structure, the model adds an exit layer after each network layer to determine whether the calculation can end early. When early exit is possible, new input text is filled in, realizing a dynamic exit process for different inputs. This keeps the GPU in a high utilization state, effectively avoiding the bottleneck effect and improving the model's text processing speed. Attached Figure Description
[0044] Figure 1 A flowchart illustrating a text processing method provided by existing technology;
[0045] Figure 2 This is a schematic diagram of the encoder-decoder structure of the Transformer provided in the embodiments of this application;
[0046] Figure 3 A schematic diagram of an encoder structure provided in an embodiment of this application;
[0047] Figure 4 A flowchart illustrating a text processing method provided in an embodiment of this application;
[0048] Figure 5 This is a flowchart illustrating another text processing method provided in an embodiment of this application. Detailed Implementation
[0049] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.
[0050] The terminology used in the following embodiments is for the purpose of describing particular embodiments only and is not intended to be limiting of this application. As used in the specification and appended claims of this application, the singular expressions “a,” “an,” “the,” “the,” “the,” and “this” are intended to also include expressions such as “one or more,” unless the context clearly indicates otherwise. It should also be understood that in the following embodiments of this application, “at least one,” “one or more” refers to one, two, or more than two, and “multiple” refers to two or more. The term “and / or” is used to describe the relationship between related objects, indicating that three relationships can exist; for example, A and / or B can indicate: A alone, A and B simultaneously, or B alone, where A and B can be singular or plural. The character “ / ” generally indicates that the preceding and following related objects are in an “or” relationship.
[0051] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0052] The Transformer architecture, first proposed in 2017, abandons traditional Convolutional Neural Networks (CNNs) and Recurrent Neural Networks (RNNs), consisting entirely of attention layers and feedforward neural networks. For example... Figure 2 As shown, the Transformer architecture is essentially an encoder-decoder structure, which achieves the encoding and decoding of high-dimensional features by stacking encoders and decoders. Based on the Transformer architecture, a large number of NLP pre-trained models have emerged.
[0053] Taking the BERT model as an example, BERT (Bidirectional Encoder Representations from Transformers) is a bidirectional encoder for Transformers. It aims to pre-train deep bidirectional representations from unlabeled text by computing conditions common to both left and right contexts. Unlike previous models that could only learn semantics in one direction, the BERT model learns semantics bidirectionally by randomly masking part of the input and then having the model predict the masked part, which greatly enhances the model's learning ability.
[0054] In simple terms, BERT can be viewed as a combination of stacked encoder layers from the Transformer and word embedding layers. The word embedding layers primarily perform the text-to-tensor transformation, converting natural language into a representation that computers can process. For example... Figure 3 As shown, the encoder mainly consists of a multi-head attention layer (MHA) and a forward propagation layer (FFN). For an input sequence of arbitrary length, the MHA transforms the input sequence into three matrices, Q, K, and V, through three linear mapping functions. The Q matrix is used for matching each row in K, K is used for querying the Q matrix, and V is used to store information. Then, the correlation between every two elements of the input sequence is calculated using the attention formula, as follows:
[0055]
[0056] Where d represents the scaling factor, and the softmax formula is used to normalize the matrix result, calculated as follows:
[0057]
[0058] The output of a multi-head attention layer is the concatenation of the results of multiple attention formulas. The forward propagation layer is a combination of ReLU and a linear layer, calculated as follows:
[0059] FFN(x0 = Linear(Relu(x));
[0060] The ReLU calculation formula is as follows:
[0061] Relu(x)=max(0,Linear(x00;
[0062] The formula for calculating Linear is as follows:
[0063] Linear(x) = Wx + b;
[0064] Where W and b are the parameters of the linear layer.
[0065] However, due to the massive computational demands of pre-trained models, high latency becomes a significant challenge. Early exit, a method offered by existing technologies to accelerate model computation, shows significant speedup on the Trasnformer architecture, but its application on GPUs is difficult when the batch size is greater than 1. GPUs, due to their parallel computing capabilities, are the most common acceleration hardware for natural language processing, and the compatibility of acceleration methods with large batch sizes is extremely important in applications, which is a major challenge for early exit methods.
[0066] This application provides a text processing method based on Transformer networks. When the batch size is greater than 1, it does not require modification of the underlying operators, effectively compatibility with early exit mechanisms and batch sizes greater than 1, ensuring high GPU utilization throughout the text processing process and effectively improving the average speed of the model in processing text. The following detailed explanation uses the BERT model as an example. It is understood that the text processing method provided in this application can also be applied to other NLP pre-trained models. The text processing method based on Transformer networks provided in this application includes steps S1 to S4.
[0067] S1. After the current encoding calculation, update the number of times each input text in a data batch has been encoded.
[0068] S2. Determine whether each input text can be exited early, and determine whether the number of times each input text has been encoded has reached the preset maximum number of calculation layers.
[0069] S3. If there is input text that can be exited early or the number of times it has been encoded has reached the preset maximum number of calculation layers, then update the corresponding input text with the text to be processed.
[0070] S4. Perform the next encoding calculation on each input text in the data batch, where the encoder with the same parameters is used for each encoding calculation.
[0071] See Figure 4 This application embodiment achieves identical encoder calculation processes for each iteration by reusing encoder parameters. It is understood that the model can be configured with only one encoder, or the parameters of each encoder in the model can be identical. Based on parameter reuse, the sequential calculation process of multiple encoders is viewed as a cyclic calculation of a single encoder. Figure 4 Taking case 5 as an example, when the data batch size is equal to 1, since only one encoder parameter needs to be loaded, the GPU usage rate of loading model parameters is effectively reduced.
[0072] For cases where the data batch size is greater than 1, see [link / reference]. Figure 4 In Case 6, taking the BERT model as an example, this embodiment first converts the text into a tensor through word embedding layer calculation, which serves as the input to the subsequent encoder, avoiding any impact on the overall temporal sequence. Based on parameter reuse, this embodiment ensures that the encoder always processes text of the same batch size simultaneously by cyclically filling the encoder input. For the input text within the current batch, after the encoder completes the current encoding calculation, it updates the number of times each input text within the batch has been encoded, and records the encoder layer number corresponding to the input text using the number of encoded texts.
[0073] Each time the encoder completes a calculation, it determines whether each input text in the data batch can exit early, and whether the number of times each input text has been encoded has reached the preset maximum calculation layer. If an input text can exit or has reached the preset maximum calculation layer, a new input text (the text to be processed) is added at the exit position of that input text. The updated input text in the data batch is then used for the next encoding calculation, ensuring that the number of input texts in the encoder remains within the data batch size. If none of the input texts in the data batch can exit and the number of times they have been encoded has not reached the preset maximum calculation layer, the text is fed into the encoder for the next calculation until an exit is possible or the number of times they have been encoded has not reached the preset maximum calculation layer. This process of encoding calculation, determining whether each input text can exit early, and checking whether the number of times each input text has been encoded has reached the preset maximum calculation layer, and updating the corresponding input text with the text to be processed if an input text can exit early or has reached the preset maximum calculation layer, continues until all texts to be processed have been processed, and the calculation process ends.
[0074] For example, the data batch size is equal to 4. The first batch of input text (i.e., 4 texts to be processed are converted into tensors through word embedding layer) includes the first text, the second text, the third text, and the fourth text. The first batch of input text is input into encoder 0. After encoder 0 encodes and calculates the first batch of input text, it updates the number of times each text in the first batch of input text has been encoded to 1, and determines whether each input text can be exited early and whether the number of times each text has been encoded has reached the preset maximum number of calculation layers d. If the results of the judgment are that the third and fourth texts can exit early, then the results of the third and fourth texts are output, and the positions of the third and fourth texts in the data batch are replaced with new input texts (the fifth and sixth texts). The first, second, fifth, and sixth texts are used as the second batch of inputs and input into encoder 0. After encoder 0 encodes and calculates the second batch of input texts, it updates the encoded count of the first text to 2, the encoded count of the second text to 2, the encoded count of the fifth text to 1, and the encoded count of the sixth text to 1. It then determines whether the first, second, fifth, and sixth texts can exit early and whether the encoded count has reached the preset maximum calculation layer d.
[0075] This application embodiment reuses encoder parameters and cyclically fills the input text, so that the number of texts processed by the model on the GPU at the same time is constant at the data batch size, so that the GPU is always in a high utilization state, effectively avoiding the bottleneck effect and improving the speed of model processing text.
[0076] See Figure 5This application also provides an algorithm flow for a text processing method based on Transformer networks in practical applications.
[0077] S101. Obtain the text set to be processed, which includes multiple texts to be processed, for example, T1, T2, T3, ..., T... n .
[0078] S102. Initialize the input tensor set S. The number of positions of the tensors in the input tensor set is equal to the data batch size. The initial value of the tensors is empty. For example, when the data batch size is 4, the number of positions in S is 4.
[0079] S103. Initialize the encoding count set L. The number of elements in the encoding count set is the data batch size. The elements are used to record the number of times the corresponding input text has been encoded. For example, when the data batch size is 4, L can be a list containing 4 elements that are 0.
[0080] S104. Determine if the input text set is empty. If it is empty, end the current method. If it is not empty, proceed to step S105.
[0081] S105. Extract the text to be processed from the input tensor set S with the number of empty positions, thus obtaining at least one input text. For example, if the number of empty positions in the input tensor set S is t+1, then extract the text to be processed T from the text set S. k T k+1 T k+2 ... T k+t .
[0082] S106. Add the padded tensor, transformed from the text to be processed, to the empty positions in the input tensor set S as input text. For example, use a word embedding layer to convert T... k T k+1 T k+2 ... T k+t Transform into tensor S k S k+1 S k+2 S k+t Add it to the empty position in the input tensor set S.
[0083] S107. Input the input tensor set S into the encoder for encoding calculation.
[0084] S108. After encoding calculation, increment each element in the encoding count set L by 1.
[0085] S109. Determine whether each input text (each tensor in the input tensor set S) can exit early, and determine whether the number of times each input text has been encoded (the encoding count set L represents the number of times the corresponding input text has been encoded) has reached the preset maximum computation level d. If there is an input text that can exit early or the number of times it has been encoded has reached the preset maximum computation level, proceed to step S110; otherwise, jump to S107.
[0086] S110. Set the tensors in the input tensor set S that can exit early or reach the preset maximum computation layer number d to null, and set the element representing the number of times the tensor has been encoded in the corresponding encoding count set L to null. Proceed to step S104.
[0087] The following examples will further illustrate this application.
[0088] The text processing method based on Transformer networks provided in this application is applied to the financial sentiment analysis task using the ELBERT model.
[0089] Financial sentiment analysis, as an important application of Natural Language Processing (NLP) technology, aims to extract sentiment from text. As a tool in financial trading, the speed and accuracy of financial sentiment analysis significantly impact the profitability of trading strategies. While the emergence of pre-trained models has significantly improved the accuracy of financial sentiment analysis, the resulting high latency remains a challenge. The ELBERT model, based on the ALBERT model using an encoder parameter sharing strategy, incorporates an early exit mechanism, effectively achieving speedups of 2 to 10 times on multiple natural language understanding tasks while maintaining almost unchanged accuracy.
[0090] In the financial sentiment analysis and ELBERT implementation, the text to be classified is used as the text set input to the model and fed into an ELBERT-based accelerated algorithm. The text is first converted into tensors through a word embedding layer, which then serve as the input to the encoder. After these tensors are computed by the ELBERT encoder, an early exit check is performed. If early exit is possible, new text is inserted at the exit position and fed into the encoder for the next calculation; otherwise, the encoder continues to the next iteration until all text to be classified has been processed.
[0091] The Transformer-based text processing method provided in this application was applied to two financial sentiment analysis datasets. Experiments demonstrate that the system achieves high classification accuracy and significant speedup, effectively improving GPU utilization and achieving an average text processing speed improvement of up to 12 times.
[0092] A second aspect of this application also provides a text processing system based on a Transformer network, used to execute the text processing method provided in the foregoing embodiments of this application. Detailed information can be found in the foregoing text processing method, which will not be repeated here. The text processing system includes:
[0093] The Update Encoding Count module is used to update the number of times each input text in a data batch has been encoded after the current encoding calculation.
[0094] The judgment module is used to determine whether each input text can be exited early, and whether the number of times each input text has been encoded has reached the preset maximum number of calculation layers.
[0095] The input text update module is used to update the corresponding input text with the text to be processed if there is input text that can be exited early or if the number of encoding attempts has reached the preset maximum number of calculation layers.
[0096] The next encoding calculation module is used to perform the next encoding calculation on each input text in the data batch. The encoder with the same parameters is used for each encoding calculation.
[0097] Furthermore, it also includes a repetitive encoding module, which is used for repetitive encoding calculation, determining whether each input text can be exited early or whether the number of times each input text has been encoded has reached the preset maximum number of calculation layers, and updating the corresponding input text with the text to be processed, until all the text to be processed has been processed.
[0098] Furthermore, it also includes:
[0099] The acquisition module is used to acquire a set of texts to be processed, which includes multiple texts to be processed.
[0100] The Tensor Initialization module is used to initialize the input tensor set. The number of positions of the tensors in the input tensor set is equal to the data batch size, and the initial values of the tensors are empty.
[0101] The Initialize Encoding Counts module is used to initialize the encoding counts set. The number of elements in the encoding counts set is equal to the data batch size. Each element records the number of times the corresponding input text has been encoded. The initial value of each element is empty.
[0102] The text input module is used to extract the number of missing positions in the input tensor set of the text to be processed, so as to obtain at least one input text.
[0103] The Fill Text module is used to add the fill tensor, which is converted from the input text, to the empty positions in the input tensor set.
[0104] The current encoding calculation module is used to perform encoding calculations on each tensor in the input tensor set.
[0105] The updated input text module is further configured to:
[0106] If there is input text that can be exited early or the number of encoding times has reached the preset maximum number of computation layers, then the tensor corresponding to the input tensor set will be set to empty, and the element corresponding to the encoding times set will be set to empty.
[0107] Repeat the process of retrieving the number of empty positions in the input tensor set and adding the resulting filling tensor to the empty positions in the input tensor set.
[0108] In this embodiment, after the current encoding calculation, the number of times each input text in a data batch has been encoded is updated. It then determines whether each input text can exit early and whether the number of times it has been encoded has reached the preset maximum number of computation layers. If an input text can exit early or has reached the preset maximum number of computation layers, the corresponding input text is updated with the text to be processed, and the next encoding calculation is performed on each input text in the data batch. Each encoding calculation uses an encoder with the same parameters. Based on the reuse of encoder parameters and the cyclic filling of input text, the number of texts processed simultaneously on the GPU remains constant within the data batch size. This effectively accommodates the early exit mechanism and data batch sizes greater than 1 without modifying the underlying operators. By introducing an early exit mechanism, without changing the original model structure, an exit layer is added after each network layer to determine whether the calculation can end early. When early exit is possible, new input text is filled in, realizing a dynamic exit process for different inputs. This keeps the GPU in a high utilization state, effectively avoiding the bottleneck effect and improving the model's text processing speed.
[0109] The embodiments described above do not constitute a limitation on the scope of protection of this application.
Claims
1. A text processing method based on Transformer networks, characterized in that, include: After the current encoding calculation, update the number of times each input text in a data batch has been encoded; Determine whether each input text has exited prematurely, and determine whether the number of times each input text has been encoded has reached the preset maximum number of computation layers; If the input text exits prematurely or the number of times it has been encoded reaches the preset maximum number of calculation layers, then the corresponding input text is updated with the text to be processed. Perform the next encoding calculation on each input text in the data batch, where the encoder with the same parameters is used for each encoding calculation; After the current encoding calculation, before updating the encoded count of each input text within a data batch, the method further includes: Obtain a set of texts to be processed, which includes multiple texts to be processed; Initialize the input tensor set. The number of positions of the tensors in the input tensor set is equal to the data batch size. The initial values of the tensors are empty. Initialize the encoding count set. The number of elements in the encoding count set is the size of the data batch. Each element is used to record the number of times the corresponding input text has been encoded. Extract the number of missing positions in the input tensor set to obtain at least one piece of input text. Add the padding tensor, which is the result of converting the input text, to the empty position in the input tensor set; Encode and calculate each tensor in the input tensor set; If an input text exits prematurely or the number of encoded iterations reaches the preset maximum computational layer, the corresponding input text is updated with the text to be processed, including: If the input text exits prematurely or the number of times it has been encoded reaches the preset maximum number of computation layers, then the tensor corresponding to the input tensor set will be set to empty, and the element corresponding to the number of times it has been encoded will be set to empty. Repeat the process of retrieving the number of empty positions in the input tensor set and adding the resulting filling tensor to the empty positions in the input tensor set.
2. The text processing method based on Transformer networks according to claim 1, characterized in that, Also includes: The process involves repeated encoding calculations, determining whether each input text has exited prematurely or whether the number of times each input text has been encoded has reached the preset maximum number of calculation layers, and updating the corresponding input text with the text to be processed, until all texts to be processed have been processed.
3. The text processing method based on Transformer networks according to claim 1, characterized in that, The update of the encoded count of each input text within a data batch includes: Increment each element in the encoding count set by 1.
4. The text processing method based on Transformer networks according to claim 1, characterized in that, Also includes: If the input text fails to exit early and the number of encoding attempts has not reached the preset maximum number of calculation layers, the next encoding calculation will proceed directly.
5. A text processing system based on Transformer networks, characterized in that, include: The update encoding count module is used to update the encoding count of each input text in a data batch after the current encoding calculation. The judgment module is used to determine whether each input text has exited prematurely, and to determine whether the number of times each input text has been encoded has reached the preset maximum number of calculation layers. The input text update module is used to update the corresponding input text with the text to be processed if the input text exits early or the number of times it has been encoded reaches the preset maximum number of calculation layers. The next encoding calculation module is used to perform the next encoding calculation on each input text in the data batch. The encoder with the same parameters is used for each encoding calculation. The system also includes: The acquisition module is used to acquire a set of texts to be processed, which includes multiple texts to be processed. The Tensor Initialization module is used to initialize the input tensor set. The number of positions of the tensors in the input tensor set is equal to the data batch size, and the initial value of the tensors is empty. The initialization encoding count module is used to initialize the encoding count set. The number of elements in the encoding count set is the data batch size. Each element is used to record the number of times the corresponding input text has been encoded. The initial value of each element is empty. The text input module is used to extract the number of missing positions in the input tensor set of the text to be processed, so as to obtain at least one piece of input text. The text filling module is used to add the filled tensor, which is converted from the input text, to the empty positions in the input tensor set; The current encoding calculation module is used to perform encoding calculations on each tensor in the input tensor set; The updated input text module is further configured to: If the input text exits prematurely or the number of times it has been encoded reaches the preset maximum number of computation layers, then the tensor corresponding to the input tensor set will be set to empty, and the element corresponding to the number of times it has been encoded will be set to empty. Repeat the process of retrieving the number of empty positions in the input tensor set and adding the resulting filling tensor to the empty positions in the input tensor set.
6. A text processing system based on a Transformer network according to claim 5, characterized in that, It also includes a repetitive encoding module, which is used for repetitive encoding calculation, determining whether each input text has exited prematurely or whether the number of times each input text has been encoded has reached the preset maximum number of calculation layers, and updating the corresponding input text with the text to be processed, until all the text to be processed has been processed.
Citation Information
Patent Citations
Text processing model operation method and device, electronic equipment and storage medium
CN110909527A
Deep neural network multi-path reasoning acceleration method for edge intelligent application
CN111445026A