Text task processing method and model training method thereof, equipment, medium and product

By performing frequency division and interpolation processing on the position coding information of the language model, and using the window mask method for extrapolation, the problem of low accuracy of large-scale language models in long text data processing is solved, and more efficient long text tasks are achieved. processing power.

CN118586448AActive Publication Date: 2024-09-03LANGCHAO ELECTRONIC INFORMATION IND CO LTD

Patent Information

Application Number
CN202411074251.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-07
Publication Date
2024-09-03
Estimated Expiration
2044-08-07

AI Technical Summary

Technical Problem

When large-scale language models process long text data, due to the limitation of the context window size, they lose the global understanding of the text, resulting in low task execution accuracy.

Method used

By dividing the dimensions of positional encoding information into multiple frequency-based groups, using different interpolation strategies for interpolation processing, and combining the window mask method to extrapolate the initial language model, its reasoning capabilities are extended to handle long text data.

Benefits of technology

It improves the accuracy and efficiency of language models for long text tasks, enables it to better understand and analyze large-scale text data such as long documents and long-term conversation records, and quickly extract key information and insights.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118586448A
    Figure CN118586448A
Patent Text Reader

Abstract

The invention discloses a text task processing method and a model training method, equipment, a medium and a product thereof, which are applied to the technical field of artificial intelligence. The method comprises the following steps: acquiring a fine-tuning text data set and a pre-trained initial language model; dividing the position coding information dimension of each fine-tuning text sample according to a plurality of frequency reference values, and performing interpolation processing on the position coding information of different groups by adopting a matched interpolation method to obtain a transition language model with the processed target length text data. And setting a window mark length parameter value and a maximum allowable distance parameter value based on the target length, setting a target text length parameter value based on the reasoning text length, and performing extrapolation processing on the transition language model by utilizing a window mask method to obtain a text task processing model. According to the method, the problem of performance reduction caused by loss of global understanding capability of the long text in related technologies can be solved, and the execution precision of the long text task can be effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a language model training method for processing text tasks, a text task processing method, an electronic device, a non-volatile storage medium, and a computer program product. Background Art

[0002] NLP (Natural Language Processing) can help computers understand and process human language, enabling computers to read and understand natural language. With the rapid development of artificial intelligence technology, the scale of language models that can handle natural language processing tasks is getting larger and larger, and the accuracy of the output results of large-scale language models performing various natural language processing tasks is also getting higher and higher.

[0003] However, for natural language processing tasks that require reasoning about long text data, such as extracting the summary of a novel or generating a long news report, large-scale language models lose their global understanding of the text due to limitations on the size of the context window, resulting in low accuracy in the final task execution.

[0004] In view of this, improving the execution accuracy of language models for long text tasks is a technical problem that those skilled in the art need to solve. It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of this application, and therefore may include information that does not constitute prior art known to ordinary technicians in the field. Summary of the invention

[0005] The present invention provides a language model training method for processing text tasks and a text task processing method, an electronic device, a non-volatile storage medium, and a computer program product, which effectively improve the execution accuracy of long text tasks.

[0006] In order to solve the above technical problems, the present invention provides the following technical solutions: On the one hand, the present invention provides a language model training method for processing text tasks, comprising: Acquire a fine-tuning text dataset and an initial language model; the initial language model is a language model that has completed a pre-training phase, and the fine-tuning text length of the fine-tuning text samples of the fine-tuning text dataset is greater than the training text length of the training text data of the initial language model; In the process of fine-tuning the initial language model using the fine-tuning text data set, the position coding information dimension of each fine-tuning text sample is divided according to a plurality of frequency reference values, and the position coding information of different groups is interpolated using a matching interpolation method to obtain a transitional language model with a processing target length of text data; the target length is greater than the training text length and less than the fine-tuning text length; Using a window mask method, a window mark length parameter value and a maximum allowed distance parameter value are set based on the target length, and a target text length parameter value is set based on the target inference text length, and the transition language model is extrapolated to obtain a text task processing model having text data for processing the target inference text length; the target inference text length is greater than the fine-tuning text length.

[0007] In a first exemplary implementation, after interpolating different groups of position coding information using matching interpolation methods, the method further includes: Determining a logical value scaling factor according to the fine-tuning text length and the training text length; The self-attention score is calculated according to the logical value scaling factor and the encoding information of each position.

[0008] In a second exemplary implementation, determining a logical value scaling factor according to the fine-tuning text length and the training text length includes: Determine a matching dynamic scaling factor for each position according to each token of the input sequence of the fine-tuning text sample and the length of the training text; The value of the logic value scaling factor is updated in real time according to the value of the dynamic scaling factor at each position.

[0009] In a third exemplary embodiment, determining a matching dynamic scaling factor for each position according to each tag of the input sequence of the fine-tuning text sample and the length of the training text includes: For each marker at each position, the larger value between the position number adjustment value of each marker and the training text length is taken as the training length adjustment value; According to a preset initial adjustment factor, adjusting the logarithmic value of the ratio of the training length adjustment value to the training text length to obtain an initial scaling factor; According to the initial scaling factor and the preset reference value, a dynamic scaling factor matching each position is determined.

[0010] In a fourth exemplary implementation, calculating a self-attention score according to the logical value scaling factor and each position encoding information includes: For each position, determine the original relationship value between the current position mark and the target position mark according to the query matrix value of the current position, the key matrix value of the target position and the word vector dimension corresponding to the fine-tuning text sample; The original relationship value is scaled and adjusted using the logical value scaling factor, and the scaled relationship value is processed using the target activation function to obtain a self-attention score of the current position relative to the target position.

[0011] In a fifth exemplary implementation, dividing the position encoding information dimensions of each fine-tuning text sample according to a plurality of frequency reference values ​​includes: Acquire a first frequency reference value and a second frequency reference value; the first frequency reference value is greater than the second frequency reference value; The position coding information greater than the first frequency reference value is divided into a first position coding group, the position coding information less than the first frequency reference value and greater than the second frequency reference value is divided into a second position coding group, and the position coding information less than the second frequency reference value is divided into a third position coding group.

[0012] In a sixth exemplary implementation, the interpolation processing of different groups of position coding information using matching interpolation methods includes: performing extrapolation processing on each position code value of the first position code group; Using a neural tangent kernel method to process each position code value of the second position code group; Each position code value of the third position code group is processed by linear interpolation.

[0013] In a seventh exemplary implementation, the process of dividing the position coding information dimensions of each fine-tuning text sample according to a plurality of frequency reference values, and performing interpolation processing on the position coding information of different groups using a matching interpolation method includes: If the current position code value is greater than the first frequency reference value, the corresponding ramp function value is the first preset value; If the current position code value is less than the second frequency reference value, the corresponding ramp function value is the second preset value; If the current position code value is greater than or equal to the second frequency reference value and less than or equal to the first frequency reference value, determining a corresponding ramp function value according to the current position code value, the second frequency reference value and the first frequency reference value; The slope function value of each dimension is adjusted using the ratio of the training text length to the fine-tuning text length, and the rotation angle of the corresponding dimension is determined based on the adjusted slope function value, the word vector dimension corresponding to the fine-tuning text sample and the preset rotation base value.

[0014] In an eighth exemplary implementation, using a window mask method, setting a window mark length parameter value and a maximum allowable distance parameter value based on the target length, and setting a target text length parameter value based on the fine-tuning text length, and performing extrapolation processing on the transitional language model, including: Replacing the self-attention function in the transformer network structure of the transition language model with an immediate length generalization method; Determining a maximum allowable distance parameter value based on the target length, and setting different start mark length parameter values ​​and window mark length parameter values ​​to obtain a plurality of length parameter combinations; Based on different length parameter combinations, the replaced transition language model is extrapolated, and the target length parameter combination with the best extrapolation effect is selected; The target start tag length parameter value and the target window tag length parameter value in the target length parameter combination are used as the start tag length parameter value and the window tag length parameter value of the replaced transition language model to obtain a text task processing model.

[0015] In a ninth exemplary implementation, after the self-attention function in the converter network structure of the transitional language model is replaced with the immediate length generalization method, the method further includes: Determine the target converter network structure and the total number of target tags that the transition language model needs to focus on according to the text task; the total number of target tags is greater than the start tag length parameter value; For at least one attention head of each target converter network structure, the same number of tags as the total number of target tags are independently selected, and the current effective distance parameter value is set to half of the target length value ± the adjustment value.

[0016] In a tenth exemplary implementation, performing extrapolation processing on the transitional language model includes: When a memory overflow warning message is detected, the data generated by the forward calculation process of the replaced transition language model is stored in the cache.

[0017] Another aspect of the present invention provides a text task processing method, comprising: Preliminarily using the language model training method for processing text tasks as described in any one of the preceding items, training a text task processing model; Acquire text data to be processed; the maximum text length of the text data to be processed is the same as the target inference text length of the text task processing model; The text data to be processed is input into the text task processing model to obtain a text processing result.

[0018] The present invention also provides an electronic device, comprising a processor, wherein the processor is used to implement the language model training method for processing text tasks as described in any of the preceding items or the steps of the text task processing method as described in the preceding items when executing a computer program stored in a memory.

[0019] Finally, the present invention also provides a non-volatile storage medium, on which a computer program is stored. When the computer program is executed by a processor, the language model training method for processing text tasks as described in any of the preceding items or the steps of the text task processing method as described above are implemented.

[0020] Finally, the present invention also provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the language model training method for processing text tasks as described in any of the preceding items or the steps of the text task processing method as described above.

[0021] The advantage of the technical solution provided by the present invention is that by dividing the dimension of the position encoding information into multiple frequency-based groups, each group adopts a different interpolation strategy, so that the pre-trained initial language model has the reasoning ability to process long texts of the target length, and then uses a window mask to extrapolate the fine-tuned transition language model to the required reasoning text length, thereby obtaining a text task processing model capable of processing long texts. It can better understand and analyze large-scale text data such as long documents and long conversation records, extract key information and insights from massive text data more quickly, and improve the accuracy and efficiency of text task processing.

[0022] In addition, the present invention also provides a corresponding text task processing method, electronic device, non-volatile storage medium, and computer program product for the language model training method for processing text tasks, further making the method more practical, and the text task processing method, electronic device, non-volatile storage medium, and computer program product have corresponding advantages.

[0023] The technical features mentioned above, the technical features to be mentioned below, and the technical features shown separately in the drawings can be arbitrarily combined with each other, as long as the combined technical features are not contradictory. All feasible feature combinations are technical contents clearly recorded in this article. Any of the multiple sub-features contained in the same sentence can be applied independently, and does not have to be applied together with other sub-features. It should be understood that the above general description and the detailed description below are only exemplary and cannot limit the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] In order to more clearly illustrate the technical solutions of the present invention or related technologies, the following briefly introduces the drawings required for use in the embodiments or related technical descriptions. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0025] Figure 1 A flow chart of a language model training method for processing text tasks provided by the present invention; Figure 2 A schematic diagram of a window mask provided by the present invention in an exemplary application scenario; Figure 3 A flowchart of another text task processing method provided by the present invention; Figure 4 A schematic diagram of a framework of the text task processing method provided by the present invention in an exemplary application scenario; Figure 5 A structural framework diagram of an exemplary implementation of a language model training device for processing text tasks provided by the present invention; Figure 6 A structural framework diagram of an exemplary implementation of the text task processing device provided by the present invention; Figure 7 A structural diagram of a specific implementation of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0026] In order to enable those skilled in the art to better understand the technical solution of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. Among them, the terms "first", "second", "third", "fourth", etc. in the specification and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations of the two are intended to cover non-exclusive inclusions. The term "exemplary" means "used as an example, embodiment or illustrative". Any embodiment described here as "exemplary" is not necessarily interpreted as being superior or better than other embodiments.

[0027] Natural language processing is to use computer technology to analyze, understand and process natural language with language as the object, to conduct quantitative research on language information with the support of computers, and to provide language descriptions that can be used by both people and computers. It includes NLU (Natural Language Understanding) and NLG (Natural Language Generation). Language models are widely used to perform natural language processing tasks. With the rapid development of artificial intelligence technology, large-scale language models, such as LLM (large language model), are widely used in various natural language processing tasks due to their more outstanding performance.

[0028] However, although large-scale language models have very good performance, since language models can only consider a limited number of contextual tags when processing text data, once the context window is exceeded, the global understanding of the text will be lost, which will lead to a decline in the performance of the entire language model. In other words, the language model is limited by the size of the context window, which is not conducive to application scenarios that require learning a large number of examples to understand and reason about the context. Generally speaking, a large number of long text data sets can be constructed to adjust the language model to improve its learning ability for long text data, but this method requires a lot of computing resources and time, and compared with short text, long text data is more scarce, and may require more preprocessing and cleaning work, which is costly. In addition, the introduction of new token positions may cause catastrophic numerical problems and affect the stability of the language model.

[0029] In order to improve the reasoning ability of the language model for long text data, the related technology linearly interpolates the position index within the pre-trained length limit, that is, multiplying the position code of the long text data to be predicted by the scaling factor. Although this method of linearly interpolating the rotation angle of RoPE (rotary position embedding) by using position interpolation can avoid crossing the boundary of distant positions, this method also compresses the distance between adjacent tokens, and the local resolution of the model is seriously disturbed. Since the reasoning process of the language model depends on local relationships, this leads to inaccurate prediction results of the language model. In order to alleviate the problem of position congestion under the position interpolation method, the related technology uses NTK (Neural Tangent Kernel) to distribute the interpolation pressure on the entire RoPE dimension, that is, less scaling in low dimensions (that is, high-frequency extrapolation), large scaling in high dimensions (that is, low-frequency interpolation), and dynamically changing the scaling factor to achieve interpolation and extrapolation of unequal RoPE positions. This method can expand the context window without fine-tuning, but the degree of expansion is limited. The maximum expansion ratio that can be achieved is 4, that is, the text inference length is 4 times its training length, which still cannot meet the accuracy requirements of long text tasks.

[0030] In view of this, the present invention divides the dimension of the position encoding information into multiple frequency-based groups, and each group adopts a different interpolation strategy, so that the pre-trained initial language model has the reasoning ability to process long texts of the target length, and then uses a window mask to extrapolate the fine-tuned transition language model to the required reasoning text length, thereby obtaining a text task processing model with the ability to process long texts. After introducing the technical scheme of the present invention, various non-limiting embodiments of the present invention are described in detail below. In order to better illustrate the present invention, numerous specific details are given in the specific embodiments below. Those skilled in the art should understand that the present invention can also be implemented without these specific details. In other examples, methods, means, components and circuits well known to those skilled in the art are not described in detail in order to highlight the subject matter of the present invention.

[0031] First see Figure 1 , Figure 1 A flow chart of a language model training method for processing text tasks provided in this embodiment may include the following contents: S101: Obtain a fine-tuning text dataset and an initial language model.

[0032] In the present invention, the fine-tuning text data set includes a large amount of text sample data, which is used to fine-tune the initial language model so that the fine-tuned initial language model is adapted to the corresponding text task, and the text sample data matches the text task to be performed. For example, if the text task is a text classification task, the text sample data included in the fine-tuning text data set is a text of multiple categories, and each text carries a label of the required category. The initial language model is any language model that completes the pre-training stage, that is, a deep learning network model with text processing capabilities. The text length of the fine-tuning text sample included in the fine-tuning text data set is defined as the fine-tuning text length in this embodiment, and the text length of the training text data for training the initial language model is defined as the training text length. The present invention is for processing long text data, and the fine-tuning text length is greater than the training text length. For example, the training text length is 64k and the fine-tuning text length is 256k. In order to obtain better results, text data slightly longer than the target length can be used for training during fine-tuning, and the target length can be 128k.

[0033] S102: In the process of fine-tuning the initial language model using the fine-tuning text dataset, the position coding information dimension of each fine-tuning text sample is divided according to multiple frequency reference values, and the position coding information of different groups is interpolated using a matching interpolation method to obtain a transitional language model with the ability to process text data of the target length.

[0034] In this embodiment, the position encoding information can be obtained by calculating the query matrix q, the key matrix k, and the value matrix v based on any position encoding method and adding the position information. For example, RoPE (rotary position embedding) can be used to multiply the query matrix q and the key matrix k by a rotation matrix to introduce the position information, that is, the position encoding information is calculated using the following relationship, so that the absolute position information of the token and the relative position information between the tokens can be used to better capture the input order: ; ; ; In the formula, represents the position encoding information corresponding to the d-dimensional embedding word vector xm corresponding to the mth token at the mth token position of the query matrix q, and Wq represents the projection matrix of the query matrix q. represents the position encoding information corresponding to the d-dimensional embedding word vector xn corresponding to the nth token at the key matrix k, Wk represents the projection matrix of the query matrix k, represents the rotation angle, e represents the exponential function, and i represents the imaginary unit express and When the word embedding dimension d is greater than 2, the word embedding vector elements can be divided into groups of two, and the same rotation operation is applied to each group. Correspondingly, the rotation angle calculation formula for each group is: , j represents the dimension of the encoded position information, and the position encoding matrix at position m can be expressed as: ; Taking into account the sparsity of the matrix, the above matrix can be simplified as follows: .

[0035] Among them, the number and value of the frequency reference values ​​can be selected according to the actual situation, but at least 2 different frequency reference values ​​are included, that is, the position coding information dimension is at least divided into three groups, that is, at least a high-frequency group, a low-frequency group and an intermediate group. Different interpolation methods are used for position coding information of different frequencies. Those skilled in the art can flexibly choose according to the actual situation, and the present invention does not impose any restrictions on this. The target length is greater than the training text length and less than the fine-tuning text length. For example, the training text length is 64k, the target length can be 128k, and the fine-tuning text length can be 256k. That is to say, by using this step to fine-tune the initial language model, the initial language model has the ability to process text data longer than the training text length while ensuring the model performance. For the convenience of description, the initial language model with this ability can be defined as a transitional language model.

[0036] Furthermore, in order to improve the performance of the transitional language model, the training parameters can be adjusted during the fine-tuning of the initial language model. For example, when using the AdamW optimization algorithm, 2×10 -5 or 2×10 -6 The learning rate, momentum parameter can be set to 0.9, weight decay parameter can be set to 0.95, the number of fine-tuning steps can be 200 or 400, and the batch size can be set to 64 to find the best fine-tuning strategy.

[0037] S103: Using the window mask method, the window mark length parameter value and the maximum allowed distance parameter value are set based on the target length, and the target text length parameter value is set based on the target inference text length, and the transition language model is extrapolated to obtain a text task processing model with text data that can process the target inference text length.

[0038] Since the position embedding in the transformer architecture of the initial language model presents complex non-uniform information entropy, information loss will still occur after the above S102 step, limiting the length of the context window. In order to further improve the length of the predicted text and support large models for processing novels, long conversations, long news reports, etc., it is necessary to achieve reasoning for at least 1024k contexts. This step can also be further implemented by using LM-infinite (immediate length generalization) based on the initial extrapolation of S102. The model uses a window mask (window mask method) for extrapolation, so that the model pays attention to the neighboring tokens while paying attention to the initial token, and then obtains the information of the entire long text, realizing extrapolation of at least 1024k length. Among them, the target reasoning text length is the text length processing capability that the user wants the text task processing model to have, such as 1024K, 2048K, and the target reasoning text length is greater than the fine-tuning text length. The window tag length parameter value is the length value of the local toke of LM-infinite, the maximum allowed distance parameter value is the distance limitation of LM-infinite, that is, distance limitation, and the target text length parameter value is the target context_length of LM-infinite. LM-infinite includes such as Figure 2The Λ-shaped window mask and a distance limit are shown. The Λ-shaped window mask is also the Λ-shaped attention mask. The window size is the training length during pre-training, that is, the training text length. The Λ-shaped attention mask includes a global branch on the left and a local branch on the right. The global branch allows each token to focus on the initial global (that is, the first few) tokens when it appears before the current token, and the local branch allows each token to focus on the previous token within the local range. Any other tokens outside these two branches are ignored during the attention process. The distance limit needs to limit the effective distance d to within the range of Lpretrain, which only affects the tokens located in the global branch. That is, in relative position encoding, the original form of the attention weight is w(q, k, d), where d is the distance between two tokens. LM-infinite modifies it to w(q, k, min(d, Lpretrain)), ensuring that the large-scale language model will not be exposed to distances that have not been seen during pre-training, avoiding the attention score from tending to unstable values ​​as the length of the inference text increases. For the sake of ease of description, the model that can process text data of the target inference text length is defined as a text task processing model. The text task processing model can be used to process any long text-related text task, including but not limited to text generation tasks, text classification tasks, key information extraction tasks, sentiment analysis tasks, semantic role labeling tasks, named entity recognition tasks, topic detection and tracking tasks, text clustering tasks, and text summarization tasks.

[0039] In the technical solution provided in this embodiment, by dividing the dimension of the position encoding information into multiple frequency-based groups, each group adopts a different interpolation strategy, so that the pre-trained initial language model has the reasoning ability to process long texts of the target length, and then uses a window mask to extrapolate the fine-tuned transition language model to the required reasoning text length, thereby obtaining a text task processing model capable of processing long texts. This can better understand and analyze large-scale text data such as long documents and long conversation records, extract key information and insights from massive text data more quickly, and improve the accuracy and efficiency of text task processing.

[0040] In order to further improve the processing efficiency and processing accuracy of long text tasks, based on the above embodiments, the present invention further improves the model performance by reducing the model perplexity. The present invention may include the following contents: The logical value scaling factor is determined according to the fine-tuning text length and the training text length; the self-attention score is calculated according to the logical value scaling factor and the encoding information of each position.

[0041] The process of the initial language model learning fine-tuning text data is as follows: if the fine-tuning text data of length N in the fine-tuning text dataset is input into the initial language model, the input sequence can be expressed as , is the i-th token in the input sequence; the word embedding vector corresponding to the input sequence is , is the d-dimensional embedding vector corresponding to the i-th token. After the query matrix, key matrix, and value matrix are calculated and the position information is added, the , After that, in order to learn the relationship between tokens, it is necessary to calculate the self-attention score. In order to reduce the model perplexity, this embodiment multiplies the logits (logical value) value of the attention by a scaling factor. The scaling factor is a logical value scaling factor. In this embodiment, the value of the logical value scaling factor can be determined by fine-tuning the text length and the training text length. For example, it can be calculated by calling the relationship 0.1*log( )+1 to calculate the logical value scaling factor. Once the logical value scaling factor is determined, the attention score can be calculated. For example, the relationship can be called , and finally multiply the self-attention score by the corresponding Get the output vector .

[0042] If the initial language model is f(x), x is the input text, since f(x) is in For training in, f(x) is The sample effect within is the best. After the initial extrapolation modification, the transition language model is , when the length of x does not exceed When .when When the length extrapolation can make the longer sample effect better, the original Further, in order to solve this problem and improve the model performance, this embodiment adjusts the fixed logical value scaling factor of the above embodiment to a dynamically updated value. For example, according to each tag of the input sequence of the fine-tuning text sample and the length of the training text, a matching dynamic scaling factor is determined for each position; according to the value of the dynamic scaling factor of each position, the value of the logical value scaling factor is updated in real time, so that the smallest logical value scaling factor with the least theoretical impact on the model effect can be found for each position, further reducing the model perplexity, improving the model performance, and improving the accuracy of text task processing.

[0043] Exemplarily, the present invention also provides a method for calculating the dynamic scaling factor. For the mark at each position, the larger value between the position number adjustment value of each mark and the training text length is taken as the training length adjustment value; according to the preset initial adjustment factor, the logarithmic value of the ratio of the training length adjustment value and the training text length is adjusted to obtain the initial scaling factor; according to the initial scaling factor and the preset reference value, the dynamic scaling factor matching each position is determined. In this embodiment, the position number adjustment value may be, for example, the current position number ± a constant, the preset adjustment factor is a preset constant less than 1, and the preset reference value may be 1. As an efficient method for determining the logical value scaling factor, the position number adjustment value is the current position number + 1, the preset adjustment factor is 0.1, and the preset reference value is 1. The dynamic scaling factor calculation relationship can be stored locally in advance, and the dynamic scaling factor calculation relationship can be directly called to calculate the dynamic scaling factor matching each position; the dynamic scaling factor calculation relationship can be: ; In the formula, is the dynamic scaling factor of the ith position, pos is the position number of the current marker, is the length of the training text.

[0044] Based on the above embodiment, this embodiment also provides a method for calculating a self-attention score. For each position, the original relationship value between the current position mark and the target position mark is determined according to the query matrix value of the current position, the key matrix value of the target position, and the word vector dimension corresponding to the fine-tuning text sample; the original relationship value is scaled and adjusted using a logical value scaling factor, and the scaled relationship value is processed using a target activation function to obtain the self-attention score of the current position relative to the target position. The target activation function can use any activation function, and the present invention does not impose any restrictions on this. For example, a softmax function can be used. As an efficient method for calculating the self-attention score, the self-attention score relationship formula can be stored locally in advance, and the self-attention score relationship formula can be directly called to calculate the self-attention score; the self-attention score relationship formula can be expressed as: ; In the formula, Represents the self-attention scores corresponding to positions m and n, is the query matrix value at position m, is the key matrix value at position n, pos is the position number of the current mark, is the length of the training text, T represents transposition, d is the word vector dimension corresponding to the fine-tuning text sample, Represents the value matrix value at position n.

[0045] In the above embodiment, there is no limitation on how to divide the position coding information dimensions of each fine-tuning text sample according to multiple frequency reference values. Based on the above embodiment, the present invention also provides an exemplary implementation of how to divide the position coding information dimensions, which may include the following contents: Acquire a first frequency reference value and a second frequency reference value; divide the position coding information greater than the first frequency reference value into a first position coding group, and perform extrapolation processing on each position coding value of the first position coding group; divide the position coding information less than the first frequency reference value and greater than the second frequency reference value into a second position coding group, and use a neural tangent kernel method to process each position coding value of the second position coding group; divide the position coding information less than the second frequency reference value into a third position coding group, and use linear interpolation to process each position coding value of the third position coding group.

[0046] Among them, the first frequency reference value is greater than the second frequency reference value. The YaRN (Yet another RoPEextensioN method, a position encoding method for language models) method is used to divide the position encoding information dimension into three frequency-based groups. Each group adopts a different interpolation strategy. The high-frequency dimension is extrapolated and the low-frequency dimension is linearly interpolated. The NTK processing is used in between, which can effectively improve the processing length of the context window.

[0047] Based on the above embodiment, this embodiment also provides an exemplary calculation method for the rotation angle, if the current position encoding value is greater than the first frequency reference value, the corresponding slope function value is the first preset value; if the current position encoding value is less than the second frequency reference value, the corresponding slope function value is the second preset value; if the current position encoding value is greater than or equal to the second frequency reference value and less than or equal to the first frequency reference value, the corresponding slope function value is determined according to the current position encoding value, the second frequency reference value and the second frequency reference value; the slope function value of each dimension is adjusted by using the ratio of the training text length and the fine-tuning text length, and the rotation angle of the corresponding dimension is determined according to the adjusted slope function value, the word vector dimension corresponding to the fine-tuning text sample and the preset rotation base value. Among them, the first preset value, the second preset value, and the preset rotation base value can be flexibly selected according to the actual situation, and the present invention does not impose any limitation on this. In order to further improve the performance of the transition language model, when fine-tuning the initial language model using the YaRN method, the first frequency reference value can be set to 32, the second frequency reference value can be set to 1, and the rotary_base can be set to 10000 to reduce the modification of the original pre-critical dimension and avoid the extrapolation of the value of the post-critical dimension.

[0048] In order to further improve the training efficiency of the transition language model, the position coding processing function relationship can be stored in advance, and the rotation angle of the rotation position coding can be determined by the position coding processing function relationship. The position coding processing function relationship can be expressed as: ; in, ; In the formula, is the rotation angle corresponding to the jth dimension of the position encoding information, is the corresponding ramp function, r j is the position encoding value of the corresponding dimension, d is the word vector dimension corresponding to the fine-tuning text sample, is the length of the training text, To fine tune the text length.

[0049] The above embodiment does not limit how to perform extrapolation processing on the transition language model. Based on the above embodiment, the present invention also provides an exemplary implementation method of performing extrapolation processing on the transition language model using a window mask method, which may include the following contents: The self-attention function in the converter network structure of the transition language model is replaced with an immediate length generalization method; the maximum allowable distance parameter value is determined based on the target length, and different start tag length parameter values ​​and window tag length parameter values ​​are set to obtain multiple length parameter combinations; based on different length parameter combinations, the replaced transition language model is extrapolated, and the target length parameter combination with the best extrapolation effect is selected; the target start tag length parameter value and the target window tag length parameter value in the target length parameter combination are used as the start tag length parameter value and the window tag length parameter value of the replaced transition language model to obtain a text task processing model. In this embodiment, the initial token (start tag length parameter value) or the global token, that is, the first few tokens, the local toke (window tag length parameter value) n, the target context_length, and the distance limitation values ​​can be set first, such as Figure 2 As shown in the figure, the initial token is 2 and the local token is 3. =2, the numbers in the figure represent the distance. For example, the initial token can be set to 100, the local token length can be set to 128k, the target context_length=1024k, and the distance limitation= =128k, thus achieving 1024k context reasoning while ensuring key information. To achieve the best results, you can try to use different initial token and local token lengths to find the best combination. For example, the initial token can be any value in the range of 100-2000, 4k. The local token is determined by the target length, that is, target_context_length. If the target length is 64K, the local token is 64k. If the target length is 128K, the local token is 128k.

[0050] For LM-infinite, the information contained in the initial token is more important than other tokens, so it pays more attention to the initial token and the token in the window, where the initial token (initial token) pays attention to the attention of all forward tokens, and the token in the window (local token) only pays attention to the information of the tokens close to it, which makes the model ignore the information of the intermediate tokens. For text tasks where the intermediate token information is very important, such as PassKey Retrieval (password retrieval task) and Needle Retreival (needle in a haystack task), based on the above embodiment, the task execution accuracy can be improved by paying attention to the top-k tokens in the intermediate tokens. Top-k means the first k tokens to be paid attention to, that is, after replacing the self-attention function in the converter network structure of the transition language model with the immediate length generalization method, it can also include: The target converter network structure and the total number of target tags that the transition language model needs to pay attention to are determined according to the text task; the total number of target tags is greater than the starting tag length parameter value; the same number of tags as the total number of target tags are independently selected for at least one attention head of each target converter network structure, and the current effective distance parameter value is set to half of the target length value ± the adjustment value.

[0051] In this embodiment, the target converter network structure can be, for example, the target converter network structure above the hth layer in the transition language model, the total number of target tags is k, the range of k and h can be given in advance, the transition language model is experimented with a verification data set such as the data set used by PassKey Retrieval, and the optimal k value and h value are selected according to the final experimental results. When the k value and h value are determined, k tokens are independently selected for each attention head above the hth layer. At the same time, the effective distance parameter value needs to be set to half of the target length value ± the adjustment value, and the adjustment value is a small fluctuation value. Of course, it can also be 0, that is, if the target length is 128k, the effective distance parameter value d=1 / 2* =1 / 2*128k=64k.

[0052] From the above, it can be seen that this embodiment can solve the problem that the LM-infinite method forcibly cuts off the attention outside the window and sacrifices long-range dependencies in exchange for the ability to process long texts. If the intermediate token contains important information, it will be ignored, resulting in a decrease in model performance when the inference length becomes longer.

[0053] Furthermore, in order to improve the stability of model training, during the extrapolation process of the transitional language model, when a memory overflow warning message is detected, the data generated by the forward calculation process of the replaced transitional language model is stored in the cache.

[0054] In this embodiment, OOM (Out Of Memory) means that there is unreclaimable memory or too much memory is used in the application system, which eventually makes the memory used for program operation greater than the maximum memory that can be provided. In this embodiment, the intermediate results in the forward calculation process are saved to caches such as memory, hard disk (such as NVMe (Non Volatile Memory Host Controller Interface Specification), and then loaded or recalculated when needed to further reduce the video memory usage. Of course, the ZeRO offload method can also be used to offload the optimizer memory, gradients, and model weights to the CPU or NVMe, thereby freeing up GPU memory and supporting the training of models that exceed the device memory.

[0055] Based on the above embodiment, the present invention also provides a text task processing method, see Figure 3 , which may include the following: S301: Pre-training a text task processing model.

[0056] This step utilizes the steps of the language model training method for processing text tasks recorded in any of the above embodiments to train a text task processing model, and deploys the text task processing model to the hardware end that actually executes the text task.

[0057] S302: Obtain text data to be processed.

[0058] In this step, the text data to be processed is long text data. In order to ensure the execution accuracy of the text task, the maximum text length of the text data to be processed is the same as the target inference text length of the text task processing model, that is, the maximum text length of the text data to be processed is the text length processing capability of the text task processing model. The text data to be processed is the input data of the text task to be executed. If the text task to be executed is a text generation task to generate a coherent Chinese text based on a certain context or prompt, the text data to be processed can be context data or prompt data. If the text task to be executed is a text classification task or an information extraction task, the text data to be processed can be a long text data, such as a news report.

[0059] S303: Input the text data to be processed into the text task processing model to obtain the text processing result.

[0060] The text processing result of this step refers to the predicted answer output by the text task processing model after the text data to be processed is processed. If the text task to be executed is a text generation task, the text processing result is the corresponding generated text content. If the text task to be executed is a text classification task, the text processing result is the category to which the corresponding generated text content belongs. If the text task to be executed is an information extraction task, the text processing result is the key content of the extracted text data to be processed.

[0061] From the above, it can be seen that this embodiment utilizes a text task processing model with the ability to process long texts, which can better understand and analyze large-scale text data such as long documents and long conversation records, extract key information and insights from massive text data more quickly, and improve the accuracy and efficiency of long text related task processing.

[0062] It should be noted that there is no strict order of execution between the steps in the present invention. As long as they comply with the logical order, these steps can be executed simultaneously or in a certain preset order. Figure 1 and Figure 3 This is just a schematic and does not mean that this is the only execution order.

[0063] Finally, based on the technical solution of the present invention, Figure 4 Some possible application scenarios involved in the technical solution of the present invention are introduced by way of examples. Figure 4A schematic diagram of a hardware composition framework applicable to a text task processing method provided by the present invention may include the following contents:

[0064] The hardware composition framework may include a first electronic device 41 and a second electronic device 42, which are connected via a network 43. The first electronic device 41 is configured to execute a processor of the language model training method for processing text tasks described in any of the above embodiments, and the second electronic device 42 is configured to provide a user terminal for a human-computer interaction interface.

[0065] The second electronic device 42 sends the fine-tuned text data set to the first electronic device 41, and the first electronic device 41 completes the training of the text task model through the language model training method steps for processing text tasks recorded in the above embodiment, and stores the trained text task model. When the user needs to perform text task processing, the text data to be processed is sent through the second electronic device 42, and the second electronic device 42 sends the text data to be processed to the first electronic device 41. The first electronic device 41 calls the text task processing model to process the text data to be processed, obtains the text processing result, and sends the text processing result to the second electronic device 42, which can be displayed on the user interface of the second electronic device 42.

[0066] From the above, it can be seen that this embodiment utilizes a text task processing model with the ability to process long texts, which can better understand and analyze large-scale text data such as long documents and long conversation records, extract key information and insights from massive text data more quickly, and improve the accuracy and efficiency of long text related task processing.

[0067] The present invention also provides a corresponding device for a language model training method and a text task processing method for processing text tasks, which further makes the method more practical. Among them, the device can be described from the perspective of functional modules and hardware. The following is an introduction to the language model training device and text task processing device for processing text tasks provided by the present invention. The device is used to implement the language model training method and text task processing method for processing text tasks provided by the present invention. In this embodiment, the language model training device and text task processing device for processing text tasks may include or be divided into one or more program modules, which are stored in a storage medium and executed by one or more processors, and the language model training method and text task processing method for processing text tasks disclosed in the first embodiment have been completed. The program module referred to in this embodiment refers to a series of computer program instruction segments that can complete specific functions, which is more suitable for describing the execution process of the language model training device and text task processing device for processing text tasks in the storage medium than the program itself. The following description will specifically introduce the functions of each program module of this embodiment. The language model training device and text task processing device for processing text tasks described below and the language model training method and text task processing method for processing text tasks described above can be referred to each other.

[0068] From the perspective of functional modules, see Figure 5 , Figure 5 A structural diagram of a language model training device for processing text tasks provided in this embodiment in a specific implementation manner, the device may include:

[0069] The data acquisition module 501 is used to acquire a fine-tuning text dataset and an initial language model; the initial language model is a language model that has completed the pre-training stage, and the fine-tuning text length of the fine-tuning text samples of the fine-tuning text dataset is greater than the training text length of the training text data of the initial language model.

[0070] The initial extrapolation module 502 is used to divide the position coding information dimensions of each fine-tuning text sample according to multiple frequency reference values ​​in the process of fine-tuning the initial language model using the fine-tuning text data set, and interpolate the position coding information of different groups using a matching interpolation method to obtain a transitional language model with a processing target length of text data; the target length is greater than the training text length and less than the fine-tuning text length.

[0071] The secondary extrapolation module 503 is used to use the window mask method to set the window mark length parameter value and the maximum allowable distance parameter value based on the target length, and to set the target text length parameter value based on the fine-tuning text length, to perform extrapolation processing on the transition language model, and obtain a text task processing model with text data that processes the target inference text length; the target inference text length is greater than the fine-tuning text length.

[0072] Exemplarily, in some implementations of this embodiment, the above-mentioned initial extrapolation module 502 can also be used to: determine the logical value scaling factor based on the fine-tuning text length and the training text length; calculate the self-attention score based on the logical value scaling factor and the encoding information of each position.

[0073] As an exemplary implementation of the above embodiment, the above initial extrapolation module 502 can be further used to: determine a matching dynamic scaling factor for each position according to each tag of the input sequence of the fine-tuning text sample and the length of the training text; and update the value of the logical value scaling factor in real time according to the value of the dynamic scaling factor of each position.

[0074] As another exemplary implementation of the above embodiment, the above initial extrapolation module 502 can be further used to: for the mark at each position, take the larger value between the position number adjustment value of each mark and the training text length as the training length adjustment value; according to the preset initial adjustment factor, adjust the logarithmic value of the ratio of the training length adjustment value to the training text length to obtain the initial scaling factor; determine the dynamic scaling factor matching each position according to the initial scaling factor and the preset reference value.

[0075] As another exemplary implementation of the above embodiment, the above initial extrapolation module 502 can be further used to: for each position, determine the original relationship value between the current position mark and the target position mark according to the query matrix value of the current position, the key matrix value of the target position and the word vector dimension corresponding to the fine-tuning text sample; use the logical value scaling factor to scale the original relationship value, and use the target activation function to process the scaled relationship value to obtain the self-attention score of the current position relative to the target position.

[0076] Exemplarily, in some implementations of the present embodiment, the above-mentioned initial extrapolation module 502 can also be used to: obtain a first frequency reference value and a second frequency reference value; the first frequency reference value is greater than the second frequency reference value; the position coding information greater than the first frequency reference value is divided into a first position coding group, the position coding information less than the first frequency reference value and greater than the second frequency reference value is divided into a second position coding group, and the position coding information less than the second frequency reference value is divided into a third position coding group.

[0077] As another exemplary implementation of the above embodiment, the above initial extrapolation module 502 can be further used for: extrapolating each position coding value of the first position coding group; processing each position coding value of the second position coding group using a neural tangent kernel method; and processing each position coding value of the third position coding group using linear interpolation.

[0078] Exemplarily, in some implementations of the present embodiment, the above-mentioned initial extrapolation module 502 can also be used for: if the current position coding value is greater than the first frequency reference value, the corresponding slope function value is the first preset value; if the current position coding value is less than the second frequency reference value, the corresponding slope function value is the second preset value; if the current position coding value is greater than or equal to the second frequency reference value and less than or equal to the first frequency reference value, the corresponding slope function value is determined according to the current position coding value, the second frequency reference value and the second frequency reference value; using the ratio of the training text length and the fine-tuning text length, the slope function value of each dimension is adjusted, and the rotation angle of the corresponding dimension is determined according to the adjusted slope function value, the word vector dimension corresponding to the fine-tuning text sample and the preset rotation base value.

[0079] Exemplarily, in some implementations of the present embodiment, the secondary extrapolation module 503 may also be used to: replace the self-attention function in the converter network structure of the transition language model with an immediate length generalization method; determine the maximum allowable distance parameter value based on the target length, and set different start tag length parameter values ​​and window tag length parameter values ​​to obtain a plurality of length parameter combinations; perform extrapolation processing on the replaced transition language model based on different length parameter combinations, and select the target length parameter combination with the best extrapolation effect; use the target start tag length parameter value and the target window tag length parameter value in the target length parameter combination as the start tag length parameter value and the window tag length parameter value of the replaced transition language model to obtain a text task processing model.

[0080] As an exemplary implementation of the above embodiment, the above-mentioned secondary extrapolation module 503 can be further used to: determine the target converter network structure and the total number of target tags that the transition language model needs to pay attention to according to the text task; the total number of target tags is greater than the start tag length parameter value; independently select the same number of tags as the total number of target tags for at least one attention head of each target converter network structure, and the current effective distance parameter value is set to half of the target length value ± the adjustment value.

[0081] As an exemplary implementation of the above embodiment, the above secondary extrapolation module 503 may be further used for: when a memory overflow warning message is detected, storing the data generated by the forward calculation process of the replaced transition language model into the cache.

[0082] From the perspective of functional modules, see Figure 6 , Figure 6 The structural diagram of the text task processing device provided in this embodiment under a specific implementation mode, the device may include:

[0083] The model training module 601 is used to train a text task processing model in advance using any of the above language model training methods for processing text tasks.

[0084] The task acquisition module 602 is used to acquire text data to be processed; the maximum text length of the text data to be processed is the same as the fine-tuning text length of the text task processing model.

[0085] The task execution module 603 is used to input the text data to be processed into the text task processing model to obtain the text processing result.

[0086] The functions of the various functional modules of the language model training device and the text task processing device for processing text tasks in this embodiment can be specifically implemented according to the method in the above-mentioned method embodiment. The specific implementation process can refer to the relevant description of the above-mentioned method embodiment, which will not be repeated here.

[0087] It can be seen from the above that this embodiment can solve the problem of performance degradation in related technologies due to the loss of the ability to globally understand long texts, and can effectively improve the execution accuracy of long text tasks.

[0088] The language model training device and text task processing device for processing text tasks mentioned above are described from the perspective of functional modules. Furthermore, the present invention also provides an electronic device, which is described from the perspective of hardware. Figure 7 The following is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention in one implementation manner. Figure 7 As shown, the electronic device includes a memory 70 for storing computer programs; a processor 71 for implementing the steps of the language model training method for processing text tasks and the text task processing method mentioned in any of the above embodiments when executing the computer program.

[0089] Among them, the processor 71 may include one or more processing cores, such as a 4-core processor, an 8-core processor, and the processor 71 may also be a controller, a microcontroller, a microprocessor or other data processing chip. The processor 71 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 71 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 71 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 71 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.

[0090] The memory 70 may include one or more computer non-volatile storage media, which may be non-transitory. The memory 70 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices and flash memory storage devices. In some embodiments, the memory 70 may be an internal storage unit of an electronic device, such as a hard disk of a server. In other embodiments, the memory 70 may also be an external storage device of an electronic device, such as a plug-in hard disk equipped on a server, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. Further, the memory 70 may also include both an internal storage unit of an electronic device and an external storage device. The memory 70 can not only be used to store application software and various types of data installed in the electronic device, such as: executing the code of the program in the language model training method and the text task processing method for processing text tasks, but also can be used to temporarily store data that has been output or is to be output. In this embodiment, the memory 70 is at least used to store the following computer program 701, wherein, after the computer program is loaded and executed by the processor 71, it can implement the language model training method for processing text tasks and the relevant steps of the text task processing method disclosed in any of the aforementioned embodiments. In addition, the resources stored in the memory 70 may also include an operating system 702 and data 703, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system 702 may include Windows, Unix, Linux, etc. The data 703 may include but is not limited to the language model training method for processing text tasks and the data corresponding to the text task processing results, etc.

[0091] In some embodiments, the electronic device may further include a display screen 72, an input / output interface 73, a communication interface 74 or a network interface, a power supply 75 and a communication bus 76. Among them, the display screen 72 and the input / output interface 73, such as a keyboard, belong to the user interface, and exemplary user interfaces may also include standard wired interfaces, wireless interfaces, and the like. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, and an OLED (Organic Light-Emitting Diode) touch device, and the like. The display may also be appropriately referred to as a display screen or a display unit, which is used to display information processed in the electronic device and to display a visual user interface. The communication interface 74 may exemplarily include a wired interface and / or a wireless interface, such as a WI-FI interface, a Bluetooth interface, and the like, which are generally used to establish a communication connection between the electronic device and other electronic devices. The communication bus 76 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, and the like. The bus may be divided into an address bus, a data bus, a control bus, and the like. For ease of representation, Figure 7 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0092] Those skilled in the art will understand that Figure 7 The structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure, for example, it may also include a sensor 77 to implement various functions.

[0093] The functions of the functional modules of the electronic device described in this embodiment can be specifically implemented according to the method in the above method embodiment. The specific implementation process can refer to the relevant description of the above method embodiment, which will not be repeated here.

[0094] It is understandable that if the language model training method and text task processing method for processing text tasks in the above embodiment are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile storage medium. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the relevant technology or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium to perform all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes but is not limited to: U disk, mobile hard disk, read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), electrically erasable programmable ROM, register, hard disk, multimedia card, card-type memory (such as SD or DX memory, etc.), magnetic memory, removable disk, CD-ROM, disk or optical disk, etc. Various media that can store program codes. Based on this, the present invention also provides a non-volatile storage medium on which a computer program is stored, and when the computer program is executed by a processor, the language model training method and text task processing method for processing text tasks described in any of the above embodiments are performed.

[0095] It is understandable that if the language model training method and text task processing method for processing text tasks in the above embodiments are implemented in the form of software functional units and sold or used as independent products, the computer software product may not need to be stored in a physical storage medium. For example, it can be directly transmitted to a computer or other device with information processing capabilities through a wired network or a wireless network to perform all or part of the steps of the methods of each embodiment of the present invention. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the relevant technology or all or part of the technical solution can be embodied in the form of a software product. Based on this, the present invention also provides a computer program product storing a computer program. When the computer program is executed by a processor, the steps of the language model training method and text task processing method for processing text tasks recorded in any of the above embodiments are performed.

[0096] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can refer to each other. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention. The above is a detailed introduction to a language model training method for processing text tasks and a text task processing method, an electronic device, a non-volatile storage medium, and a computer program product provided by the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. Without departing from the principle of the present invention, the present invention can also be improved and modified in several ways, and these improvements and modifications also fall within the scope of protection of the present invention.

Claims

1. A language model training method for processing text tasks, characterized in that: include: Get a fine-tuning text dataset and an initial language model; The initial language model is a language model that has completed a pre-training phase, and the fine-tuning text length of the fine-tuning text samples of the fine-tuning text data set is greater than the training text length of the training text data of the initial language model; In the process of fine-tuning the initial language model using the fine-tuning text data set, the position coding information dimension of each fine-tuning text sample is divided according to a plurality of frequency reference values, and the position coding information of different groups is interpolated using a matching interpolation method to obtain a transitional language model with a processing target length of text data; the target length is greater than the training text length and less than the fine-tuning text length; Using a window mask method, a window mark length parameter value and a maximum allowed distance parameter value are set based on the target length, and a target text length parameter value is set based on the target inference text length, and the transition language model is extrapolated to obtain a text task processing model having text data for processing the target inference text length; the target inference text length is greater than the fine-tuning text length.

2. The language model training method for processing text tasks according to claim 1, characterized in that: After interpolation processing is performed on different groups of position coding information using matching interpolation methods, the following is also included: Determining a logical value scaling factor according to the fine-tuning text length and the training text length; The self-attention score is calculated according to the logical value scaling factor and the encoding information of each position.

3. The language model training method for processing text tasks according to claim 2, characterized in that: Determining a logical value scaling factor according to the fine-tuning text length and the training text length includes: Determine a matching dynamic scaling factor for each position according to each token of the input sequence of the fine-tuning text sample and the length of the training text; The value of the logic value scaling factor is updated in real time according to the value of the dynamic scaling factor at each position.

4. The language model training method for processing text tasks according to claim 3, characterized in that: According to each token of the input sequence of the fine-tuning text sample and the length of the training text, a matching dynamic scaling factor is determined for each position, including: For each marker at each position, the larger value between the position number adjustment value of each marker and the training text length is taken as the training length adjustment value; According to a preset initial adjustment factor, adjusting the logarithmic value of the ratio of the training length adjustment value to the training text length to obtain an initial scaling factor; According to the initial scaling factor and the preset reference value, a dynamic scaling factor matching each position is determined.

5. The language model training method for processing text tasks according to claim 2, characterized in that: According to the logical value scaling factor and each position encoding information, the self-attention score is calculated, including: For each position, determine the original relationship value between the current position mark and the target position mark according to the query matrix value of the current position, the key matrix value of the target position and the word vector dimension corresponding to the fine-tuning text sample; The original relationship value is scaled and adjusted using the logical value scaling factor, and the scaled relationship value is processed using the target activation function to obtain a self-attention score of the current position relative to the target position.

6. The language model training method for processing text tasks according to claim 1, characterized in that: The position encoding information dimensions of each fine-tuning text sample are divided according to multiple frequency reference values, including: Acquire a first frequency reference value and a second frequency reference value; the first frequency reference value is greater than the second frequency reference value; The position coding information greater than the first frequency reference value is divided into a first position coding group, the position coding information less than the first frequency reference value and greater than the second frequency reference value is divided into a second position coding group, and the position coding information less than the second frequency reference value is divided into a third position coding group.

7. The language model training method for processing text tasks according to claim 6, characterized in that: The position coding information of different groups is interpolated using matching interpolation methods, including: performing extrapolation processing on each position code value of the first position code group; Using a neural tangent kernel method to process each position code value of the second position code group; Each position code value of the third position code group is processed by linear interpolation.

8. The language model training method for processing text tasks according to claim 1, characterized in that: The process of dividing the position coding information dimensions of each fine-tuning text sample according to multiple frequency reference values, and performing interpolation processing on the position coding information of different groups using matching interpolation methods includes: If the current position code value is greater than the first frequency reference value, the corresponding ramp function value is the first preset value; If the current position code value is less than the second frequency reference value, the corresponding ramp function value is the second preset value; If the current position code value is greater than or equal to the second frequency reference value and less than or equal to the first frequency reference value, determining a corresponding ramp function value according to the current position code value, the second frequency reference value and the first frequency reference value; The slope function value of each dimension is adjusted using the ratio of the training text length to the fine-tuning text length, and the rotation angle of the corresponding dimension is determined based on the adjusted slope function value, the word vector dimension corresponding to the fine-tuning text sample and the preset rotation base value.

9. The language model training method for processing text tasks according to any one of claims 1 to 8, characterized in that: Using a window mask method, setting a window mark length parameter value and a maximum allowable distance parameter value based on the target length, and setting a target text length parameter value based on a target inference text length, and performing extrapolation processing on the transition language model, including: Replacing the self-attention function in the transformer network structure of the transition language model with an immediate length generalization method; Determining a maximum allowable distance parameter value based on the target length, and setting different start mark length parameter values ​​and window mark length parameter values ​​to obtain a plurality of length parameter combinations; Based on different length parameter combinations, the replaced transition language model is extrapolated, and the target length parameter combination with the best extrapolation effect is selected; The target start tag length parameter value and the target window tag length parameter value in the target length parameter combination are used as the start tag length parameter value and the window tag length parameter value of the replaced transition language model to obtain a text task processing model.

10. The language model training method for processing text tasks according to claim 9, characterized in that: After replacing the self-attention function in the transformer network structure of the transition language model with the immediate length generalization method, it also includes: Determine the target converter network structure and the total number of target tags that the transition language model needs to focus on according to the text task; the total number of target tags is greater than the start tag length parameter value; For at least one attention head of each target converter network structure, the same number of tags as the total number of target tags are independently selected, and the current effective distance parameter value is set to half of the target length value ± the adjustment value.

11. The language model training method for processing text tasks according to claim 9, characterized in that: The transition language model is extrapolated, including: When a memory overflow warning message is detected, the data generated by the forward calculation process of the replaced transition language model is stored in the cache.

12. A text task processing method, characterized in that: include: Preliminarily using the language model training method for processing text tasks as described in any one of claims 1 to 11 to train a text task processing model; Acquire text data to be processed; the maximum text length of the text data to be processed is the same as the target inference text length of the text task processing model; The text data to be processed is input into the text task processing model to obtain a text processing result.

13. An electronic device, characterized in that: It comprises a processor and a memory, wherein the processor is used to implement the steps of the language model training method for processing text tasks as described in any one of claims 1 to 11 or the text task processing method as described in claim 12 when executing the computer program stored in the memory.

14. A non-volatile storage medium, characterized in that: The non-volatile storage medium stores a computer program, which, when executed by a processor, implements the steps of the language model training method for processing text tasks as described in any one of claims 1 to 11 or the text task processing method as described in claim 12.

15. A computer program product comprising a computer program / instructions, characterized in that When the computer program / instruction is executed by a processor, the steps of the language model training method for processing text tasks as described in any one of claims 1 to 11 or the text task processing method as described in claim 12 are implemented.

Citation Information

Patent Citations

  • Financial large model length extrapolation method for expanding input context length

    CN117875434A

  • Large language model long text output method and device, equipment and storage medium

    CN117933270A

  • Text processing method, electronic equipment and storage medium

    CN117973319A

  • Text information extraction method based on large language model and efficient parameter fine tuning

    CN118132674A

  • Model context length expansion method and device, equipment, storage medium and product

    CN118153556A

Cited By

  • Text task processing method, system and device, medium and computer program product

    CN119495359A

  • Data processing method and device, equipment and storage medium

    CN120745871A

  • Text data processing method and device, storage medium and electronic equipment

    CN120821828A

  • Text reasoning method, product, equipment and storage medium

    CN120849131A

  • Long text generalization method and device based on Fourier position coding

    CN121212126A