Training method and system for enhancing long text processing capability of large language model
By introducing random offsets and scaling coefficients in the continued training of large language models, new position codes are generated, which solves the problem of declining long text processing capabilities in vertical fields and significantly improves the model's long text processing and context expansion capabilities.
Patent Information
- Application Number
- CN202410810068.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-21
- Publication Date
- 2024-09-13
AI Technical Summary
Due to hardware and corpus resource limitations in the continued training of existing large language models in vertical fields, long text processing capabilities and context expansion capabilities are reduced, and long text data cannot be effectively processed.
By introducing randomly generated offsets and scaling coefficients during the continued training process, the original position is calculated, a new position and its encoding are generated, and applied to the input and intermediate states of the model to enhance the model's high position encoding and relative understanding of differences.
The long text processing capabilities and context expansion capabilities of large language models have been significantly improved, enabling them to effectively process long text data, reducing computing resource requirements and improving computing efficiency.
Smart Images

Figure CN118643883A
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of large language model training, and in particular relates to a training method and system for enhancing the long text processing capability of a large language model. Background Art
[0002] In recent years, large language models (LLMs) have made significant progress in the field of natural language processing (NLP). Their powerful generation capabilities and deep understanding of complex contexts make them important tools for natural language processing tasks. These large language models usually use massive long text corpora during the pre-training stage. However, many vertical applications require the pre-trained large language models to be further trained (such as additional pre-training or instruction fine-tuning) to adapt to specific tasks or fields.
[0003] However, in actual operation, due to the limitation of hardware resources and corpus resources, the continued training process often cannot use the same scale of long text corpus as the pre-training stage. The main reason is that the corpus in the vertical field or vertical task may be mainly short texts and short question-answer pairs, lacking long text data. Moreover, since the pre-training stage is usually a computing cluster with more than 1,000 calories, the computing and video memory resources are sufficient, allowing training on long texts, while the continued training work for vertical fields or vertical tasks is usually trained on a single training and pushing machine, which has limited computing and video memory resources and cannot directly support long text training. . Specifically, existing continuous training methods mainly use short text corpora, which can easily lead to the following disadvantages: (1) The ability to process long text positions is reduced: the model may not be able to effectively remember the meaning of high-order position codes at deeper positions beyond the scope of the short text corpus, affecting the generation and comprehension of long texts; (2) The ability to process the relative difference of position codes is reduced: the relative difference of position codes is crucial for sequence processing, and short text training can easily weaken this ability, making it difficult for the model to correctly understand the relative position information in the long text input; (3) It is impossible to expand the context processing capability of the pre-trained model: short text training may cause the model to be unable to handle long-context tasks well, such as long text generation, long text classification, etc.
[0004] In a shorter dataset, the existing continuous training method may lead to a decrease in the model's long-text processing and context expansion capabilities. The main reason is that the core of the large language model, the Transformer architecture, is position-independent. It is necessary to convert the absolute and relative position information into positional encodings and attach them to the model's input and intermediate states (usually in the form of multiplication or addition). The dependencies in the sequence are captured by calculating the correlation between the positions in the input sequence. In the pre-training stage, the model learns how to accurately identify high-position encodings and the gaps between multiple long-distance position encodings by processing a large amount of long-text data. However, in the continuous training stage, due to the limitation of the training set data length, the model cannot access the encodings corresponding to positions higher than the maximum length of the training set data, which leads to the degradation of the model's ability to identify high-position encodings and the gaps between multiple long-distance position encodings. Therefore, when the model that has been continuously trained on short texts processes long texts, its performance may decline.
[0005] In summary, although large language models perform well in natural language processing tasks, in shorter datasets, the existing continued training methods may have problems that lead to a decrease in the model's long-text processing ability and context expansion ability, which still needs to be further studied and resolved. Summary of the invention
[0006] In view of the above, the purpose of the present invention is to provide a training method and system for enhancing the long text processing capability of a large language model. By improving the position encoding technology, the model can avoid losing its understanding of high-order position encoding and relative difference during the continued training of short texts, maintain the model's long text processing capability and context expansion capability, so that it can still effectively process long texts after continued training, and be applied to tasks and fields such as intelligent question answering, summary generation, code generation and long text classification.
[0007] In order to achieve the above-mentioned invention object, the technical solution provided by the present invention is as follows:
[0008] In a first aspect, an embodiment of the present invention provides a training method for enhancing the long text processing capability of a large language model, comprising the following steps:
[0009] Before each training step of continuing to train the pre-trained large language model using the short text, an offset of the original position of the short text input sequence and a scaling factor of the original position are generated;
[0010] In each step of continuous training, the original position is calculated using the offset and scaling factor to obtain the new position and its new position encoding;
[0011] Apply the new positional encoding generated at each step to the input and intermediate states of the pre-trained large language model and complete each step to continue training;
[0012] After iterating each training step and completing the continued training of the pre-trained large language model, a large language model with enhanced long text processing performance is obtained.
[0013] Preferably, the short text input sequence is a token sequence obtained by preprocessing the natural language short text corpus and inputting it into a large language model.
[0014] Preferably, the offset and scaling factor are randomly generated before each training step.
[0015] Preferably, the value range of the offset is an integer greater than or equal to 0.
[0016] Preferably, the scaling factor has a value range greater than or equal to 1.0.
[0017] Preferably, the calculation formula for calculating the new position by using the offset and the scaling factor to calculate the original position is:
[0018]
[0019] Among them, p is the original position, scale is the scaling factor, offset is the offset, p new For the new location, To round down.
[0020] Preferably, the intermediate state is a vector representation corresponding to the input of the large language model at each layer of the model.
[0021] In a second aspect, to achieve the above-mentioned purpose of the invention, an embodiment of the present invention further provides a training system for enhancing the long text processing capability of a large language model, including: an offset and scaling parameter generation module, a new position encoding calculation module, a new position encoding continued training module and a model iterative training enhancement module;
[0022] The offset and scaling parameter generation module is used to generate an offset of the original position of the short text input sequence and a scaling factor of the original position before each training step of continuing to train the pre-trained large language model using the short text;
[0023] The new position code calculation module is used to calculate the original position using the offset and the scaling factor to obtain the new position and its new position code during each step of the training process;
[0024] The new position encoding continued training module is used to apply the new position encoding generated in each step to the input and intermediate state of the pre-trained large language model and complete the continued training in each step;
[0025] The model iterative training enhancement module is used to iterate at each training step and complete the continued training of the pre-trained large language model to obtain a large language model with enhanced long text processing performance.
[0026] In the third aspect, in order to achieve the above-mentioned purpose of the invention, an embodiment of the present invention also provides a training device for enhancing the long text processing capability of a large language model, comprising a memory and one or more processors, wherein the memory is used to store a computer program, and the processor is used to implement the above-mentioned training method for enhancing the long text processing capability of a large language model when executing the computer program.
[0027] In a fourth aspect, in order to achieve the above-mentioned purpose of the invention, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a computer, the above-mentioned training method for enhancing the long text processing capability of a large language model is implemented.
[0028] Compared with the prior art, the present invention has the following beneficial effects:
[0029] The present invention performs continued training on the basis of a pre-trained large language model. By introducing random offsets and scaling factors in the continued training process, the adaptability and robustness of the large language model to high-order position coding and long-distance relative position information can be enhanced, and the problem of forgetting the position coding during the continued training of short texts is avoided. This not only ensures that the continued training using short texts can reduce the demand for computing resources and improve computing efficiency, but also significantly improves the long text processing capability of the large language model, so that it can still effectively process long texts after continued training, and significantly improves the context expansion capability of the large language model, so that it can better handle tasks with longer contexts. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. 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 creative work.
[0031] Figure 1 It is a flowchart of a training method for enhancing the long text processing capability of a large language model provided by an embodiment of the present invention;
[0032] Figure 2 It is a schematic diagram of a framework of a training method for enhancing the long text processing capability of a large language model provided by an embodiment of the present invention;
[0033] Figure 3It is a schematic diagram of the mechanism flow of random parameter generation during the continuous training process provided by an embodiment of the present invention;
[0034] Figure 4 It is a structural diagram of a training system for enhancing the long text processing capability of a large language model provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0035] To make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific implementation methods described herein are only used to explain the present invention and do not limit the scope of protection of the present invention.
[0036] The inventive concept of the present invention is: in view of the problem that the continued training method in the prior art may lead to a decrease in the long-text processing capability and context expansion capability of the model, the embodiment of the present invention provides a training method and system for enhancing the long-text processing capability of a large language model. Based on the pre-trained large language model, continued training for vertical fields or specific tasks is performed. During the continued training process, a position mapping formula is constructed by introducing randomly generated offsets and scaling factors to update the original position, and the encoding corresponding to the new position is applied to the model input and intermediate state, so that the large language model obtained after the continued training can significantly improve the long-text processing capability and context expansion capability.
[0037] Explanation of terms in the embodiments of the present invention:
[0038] (1) Large Language Model (LLM): A large-scale deep learning model that can understand and generate human language;
[0039] (2) Position Encoding: A technique used in the Transformer architecture to represent information about each position in a sequence;
[0040] (3) Offset: A random offset value added during the position encoding process to adjust the overall offset of the absolute position of the input token;
[0041] (4) Scale: A random scale factor applied during the position encoding process to scale the relative position differences between input tokens.
[0042] Figure 1 is a flow chart of a training method for enhancing the long text processing capability of a large language model provided by an embodiment of the present invention, Figure 2 Schematic diagram of the framework of the training method for enhancing the long text processing capability of a large language model provided by an embodiment of the present invention. Figure 1 and Figure 2As shown, the embodiment provides a training method for enhancing the long text processing capability of a large language model, comprising the following steps:
[0043] S1, before each training step of continuing to train the pre-trained large language model using the short text, generate the offset of the original position of the short text input sequence and the scaling factor of the original position.
[0044] Specifically, for pre-trained large language models, for applications in vertical fields or specific tasks, it is necessary to continue training them using natural language short text corpora. First, the token sequence acceptable to the large language model obtained after pre-processing the natural language short text corpus should be used as the short text input sequence. Before each training step, a random offset and scaling factor of the original position of the short text input sequence is generated.
[0045] In the embodiment, the pre-trained large language model uses the Llama3-70B model, and the maximum input length of the pre-training is a long text input sequence of 8192 tokens. The dataset for continued training uses a question-answering corpus with a maximum input length of 2000 tokens as a short text input sequence.
[0046] In the embodiment, the offset and scaling factor are randomly generated before each training step to ensure the adaptability and robustness of the model to the high-order position encoding and the relative distance of the position. Since the range of the short text input sequence to be trained is small, the random generation is to ensure that the encoding corresponding to all positions within the expected range is learned with a relatively fair chance during the training process. The offset value ranges from 0 to 30,000 integers, and the scaling factor ranges from 1.0 to 4.0. At the same time, in the embodiment, the mechanism for generating random parameters is designed to a certain extent, such as Figure 3 As shown in the figure, with a probability of 10% (p), the offset is set to 0 and the scaling factor is set to 1, where the random() function returns a random X, satisfying 0.0≤X<1.0, and the randint(a,b) function returns a random integer N, satisfying a≤N≤b. Since the model is trained using the original position encoding with an offset of 0 and a scaling factor of 1 for inference and application, increasing the proportion of training steps set by this parameter in the random process can effectively ensure stable performance during inference.
[0047] S2, in each step of the training process, the offset and scaling factor are used to calculate the original position to obtain the new position and its new position encoding.
[0048] Specifically, the calculation formula for the new position after calculating and mapping the original position using the offset and the scaling factor is:
[0049]
[0050] Among them, p is the original position, scale is the scaling factor, offset is the offset, p new For the new location, To round down.
[0051] According to the new position p after mapping new Calculate the new position code E new The formula is expressed as:
[0052] E new =PositionEncoding(p new )
[0053] Among them, PositionEncoding(·) is a position encoding algorithm. In the embodiment, the RoPE position encoding algorithm corresponding to the Llama3-70B model is adopted.
[0054] S3, applies the new position encoding generated at each step to the input and intermediate states of the pre-trained large language model and completes each step to continue training.
[0055] Specifically, the generated new position code E new It is applied to the input and intermediate states of the pre-trained large language model to complete the training process of each training step. The intermediate state is the vector representation corresponding to the input token sequence of the large language model at each layer of the model.
[0056] S4, iterates at each training step and completes the continued training of the pre-trained large language model to obtain a large language model with enhanced long text processing performance.
[0057] Specifically, the above steps S1 to S3 are repeated to iteratively train the large language model. The offset and scaling coefficient randomly generated during the training process enable the model to maintain the memory and processing capabilities of the long text position encoding when training short texts, thereby obtaining a large language model with enhanced long text processing performance and performing subsequent model deployment and application.
[0058] In the embodiment, the above steps are used to continue training the Llama3-70B model, and the training data is a question-answer corpus with a length of 2000 tokens. The model obtained after the continued training is tested for its long text processing ability and context expansion ability, and the results show that:
[0059] (1) Long text processing capability: The model can still maintain the processing capability of the pre-trained model when processing text with a length of 8192 tokens (the length range supported by the Llama3-70B pre-trained base model), proving that the model has not lost its understanding of high-order position encoding during short text training;
[0060] (2) Context expansion capability: The model showed a certain understanding ability when processing texts with a length of more than 8192 tokens, indicating that the model’s context processing capability has been expanded through the method of random offset and scaling factor.
[0061] In summary, the embodiment of the present invention provides a training method for enhancing the long text processing capability of a large language model, which uses a random offset (0 to 30,000) and a scaling factor (1.0 to 4.0) to continue training the Llama3-70B model. While maintaining the model's original 8192tokens context processing capability, the model after continued training also obtains a certain ability to understand long texts that exceeds the length range supported by pre-training. This method effectively solves the problem of forgetting position encoding during short text training, and improves the long text processing capability and context expansion capability of the large language model.
[0062] Based on the same inventive concept, Figure 4 As shown, an embodiment of the present invention also provides a training system 400 for enhancing the long text processing capability of a large language model, including: an offset and scaling parameter generation module 410, a new position encoding calculation module 420, a new position encoding continued training module 430 and a model iterative training enhancement module 440.
[0063] The offset and scaling parameter generation module 410 is used to generate the offset of the original position encoding and the scaling coefficient of the original position encoding of the short text input sequence before each training step of continuing to train the pre-trained large language model using the short text.
[0064] The new position code calculation module 420 is used to calculate the original position code using the offset and the scaling factor to obtain the new position code during each step of the training process.
[0065] The new position encoding continued training module 430 is used to replace the original position encoding with the new position encoding generated in each step and apply it to the input and intermediate state of the large language model to complete each step of continued training.
[0066] The model iteration training enhancement module 440 is used to iterate at each training step and complete the continued training of the pre-trained large language model to obtain a large language model with enhanced long text processing performance.
[0067] Based on the same inventive concept, an embodiment of the present invention also provides a training device for enhancing the long text processing capability of a large language model, comprising a memory and one or more processors, the memory being used to store a computer program, and the processor being used to implement the above-mentioned training method for enhancing the long text processing capability of a large language model when executing the computer program.
[0068] Based on the same inventive concept, an embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a computer, the above-mentioned training method for enhancing the long text processing capability of a large language model is implemented.
[0069] It should be noted that the training system for enhancing the long-text processing capability of a large language model, the training device for enhancing the long-text processing capability of a large language model, and the computer-readable storage medium provided in the above-mentioned embodiments all belong to the same inventive concept as the training method for enhancing the long-text processing capability of a large language model. The specific implementation process is detailed in the embodiment of the training method for enhancing the long-text processing capability of a large language model, which will not be repeated here.
[0070] The specific implementation methods described above provide a detailed description of the technical solutions and beneficial effects of the present invention. It should be understood that the above is only the most preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, supplements and equivalent substitutions made within the scope of the principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A training method for enhancing the long text processing capability of a large language model, characterized in that: The following steps are involved: Before each training step of continuing to train the pre-trained large language model using the short text, an offset of the original position of the short text input sequence and a scaling factor of the original position are generated; In each step of continuous training, the original position is calculated using the offset and scaling factor to obtain the new position and its new position encoding; Apply the new positional encoding generated at each step to the input and intermediate states of the pre-trained large language model and complete each step to continue training; After iterating each training step and completing the continued training of the pre-trained large language model, a large language model with enhanced long text processing performance is obtained.
2. The training method for enhancing the long text processing capability of a large language model according to claim 1, characterized in that: The short text input sequence is a token sequence obtained by preprocessing the natural language short text corpus and inputting it into the large language model.
3. The training method for enhancing the long text processing capability of a large language model according to claim 1, characterized in that: The offset and scaling factors are randomly generated before each training step.
4. The training method for enhancing the long text processing capability of a large language model according to claim 1 or 3, characterized in that: The offset value range is an integer greater than or equal to 0.
5. The training method for enhancing the long text processing capability of a large language model according to claim 1 or 3, characterized in that: The scaling factor can be greater than or equal to 1.
0.
6. The training method for enhancing the long text processing capability of a large language model according to claim 1, characterized in that: The calculation formula for calculating the new position by using the offset and scaling factor to calculate the original position is: Among them, p is the original position, scale is the scaling factor, offset is the offset, p new For the new location, To round down.
7. The training method for enhancing the long text processing capability of a large language model according to claim 1, characterized in that: The intermediate state is the vector representation corresponding to the input of the large language model at each layer of the model.
8. A training system for enhancing the long text processing capability of a large language model, characterized in that: include: Offset and scaling parameter generation module, new position encoding calculation module, new position encoding continued training module and model iterative training enhancement module; The offset and scaling parameter generation module is used to generate an offset of the original position of the short text input sequence and a scaling factor of the original position before each training step of continuing to train the pre-trained large language model using the short text; The new position code calculation module is used to calculate the original position using the offset and the scaling factor to obtain the new position and its new position code during each step of the training process; The new position encoding continued training module is used to apply the new position encoding generated in each step to the input and intermediate state of the pre-trained large language model and complete the continued training in each step; The model iterative training enhancement module is used to iterate at each training step and complete the continued training of the pre-trained large language model to obtain a large language model with enhanced long text processing performance.
9. A training device for enhancing the long text processing capability of a large language model, comprising a memory and one or more processors, wherein the memory is used to store a computer program, characterized in that: The processor is used to implement the training method for enhancing the long text processing capability of a large language model as described in any one of claims 1-7 when executing the computer program.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a computer, the training method for enhancing the long text processing capability of a large language model as described in any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Financial large model length extrapolation method for expanding input context length
CN117875434A
Cited By
Data processing method and device, equipment and storage medium
CN120745871A
