Multi-task processing method and system based on large language model

By constructing a classification and generating module in a large language model, and using the LORA low -ranking method to fine -tune the linear layer, the problem of insufficient generalization capabilities in multi -tasking scenarios and the large memory occupation of memory occupation, and realized the high -efficiency integration in a single model. One task.

CN119356813APending Publication Date: 2025-01-24NARI INFORMATION & COMM TECH +4
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411399969.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-09
Publication Date
2025-01-24

AI Technical Summary

Technical Problem

In multi-task scenarios, the generalization ability of existing large language models is insufficient, resulting in the need to fine-tune the model in specific scenarios, and multiple tasks need to occupy more video memory. How to automatically distinguish the user's problem in the same system The task is a difficult problem.

Method used

A multi-task processing method based on a large language model is adopted. By constructing a large language model including a classification module and a generation module, the LoRA low-rank method is used to fine-tune the linear layer to achieve fine-tuning of the task classification and generation modules, and then in a single model Integrate multiple tasks efficiently.

Benefits of technology

Realize the integration of system integration and reduce memory occupation, and can effectively integrate multiple tasks in the same basic model to save video memory resources and time resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119356813A_ABST
    Figure CN119356813A_ABST
Patent Text Reader

Abstract

The invention discloses a multi-task processing method and system based on a large language model, the large language model is constructed, the large language model comprises a classification module and a generation module, the classification module comprises a classification linear layer ClassifyHead used for task classification and a basic model, the generation module comprises the basic model, and the classification linear layer ClassifyHead is used for task classification. LoRA modules with different weight matrixes are adopted to carry out LoRA low-rank method fine tuning on a linear layer in the basic model; obtaining a plurality of task texts; the task text is converted through a word segmentation device, and an input text of the large language model is obtained; the input text is input into the large language model, the linear layer ClassifyHead of the classification module performs task classification on the input text, and the generation module loads the LoRA module of the corresponding task according to the classification result to process the input text. User question classification and multi-task parallel query are carried out, the same basic model is adopted for fine tuning, different fine-tuned LoRA modules are loaded corresponding to different task types, and a large number of video memory resources and time resources can be saved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to an artificial intelligence large language model, and in particular to a multi-task processing method and system based on the large language model. Background Art

[0002] With the in-depth development and application of artificial intelligence technology, Large Language Model (LLM) has shown great potential in the field of Natural Language Processing (NLP). LLM is a model based on deep learning technology and massive text data, trained by combining unsupervised and supervised data annotation. It can understand and generate natural language and demonstrate excellent capabilities in multiple tasks.

[0003] However, although LLM has achieved remarkable results on a single task, its generalization ability is still insufficient when facing multi-task scenarios, so LLM needs to be fine-tuned when applied to specific scenarios. However, multiple tasks involve multiple models, which require more video memory. How to integrate multiple tasks into the same system and automatically distinguish the tasks to which user questions belong is still a difficult problem. Summary of the invention

[0004] Purpose of the invention: In view of the above shortcomings, the present invention provides a multi-task processing method and system based on a large language model, which improves system integration, reduces video memory occupancy, and realizes effective integration of multiple tasks in a single model.

[0005] Technical solution: To solve the above problems, the present invention adopts a multi-task processing method based on a large language model, comprising the following steps:

[0006] Construct a large language model, the large language model includes a classification module and a generation module, the classification module includes a classification linear layer Classify_Head for task classification, a basic model and a classification LoRA module, the generation module includes a basic model and multiple generation LoRA modules, the weight matrix of each generation LoRA module is different, each generation LoRA module corresponds to a different type of task, the basic models of the classification module and the generation module both include a linear layer, the weight matrix in the classification LoRA module is used to fine-tune the linear layer of the basic model in the classification module using the LoRA low-rank method, and the weight matrix in the generation LoRA module is used to fine-tune the linear layer of the basic model in the generation module using the LoRA low-rank method;

[0007] Obtain several task texts; transform each task text through a word segmenter to obtain the input text of the large language model;

[0008] The input texts of several task texts are input into the large language model, the basic model of the classification module processes all the input texts, the classification linear layer Classify_Head performs task classification according to the processed input texts to obtain the classification results, and the corresponding generation LoRA module in the generation module is loaded according to the classification results to process the input texts.

[0009] Furthermore, the classification linear layer Classify_Head used for task classification is obtained by fine-tuning using the LoRA low-rank method.

[0010] Furthermore, the basic model includes a word embedding layer and a decoder layer.

[0011] Furthermore, the LoRA low-rank method includes: for the weight matrix W0 of each linear layer, initializing a zero matrix B and a random Gaussian distribution matrix A; updating is represented by low-rank decomposition W0+ΔW=W0+BA, and when training the linear layer, only the newly added zero matrix B and random Gaussian distribution matrix A are trained, while the weight matrix W0 of the linear layer remains unchanged, and the cross entropy function is used as the loss function.

[0012] Furthermore, the classification linear layer Classify_Head is an unbiased linear layer, whose input dimension is the latent vector dimension H of the model, and the output dimension is the number of tasks T; the training data of the classification linear layer Classify_Head includes the input text of the task text and the corresponding classification label; the output of the classification linear layer Classify_Head is the probability of the input text corresponding to each category of tasks, and the task category corresponding to the maximum probability is used as the task category of the input text.

[0013] The present invention also adopts a multi-task processing system based on a large language model, comprising:

[0014] A model construction module is used to construct a large language model, which includes a classification module and a generation module. The classification module includes a classification linear layer Classify_Head for task classification, a basic model and a classification LoRA module. The generation module includes a basic model and multiple generation LoRA modules. The weight matrix of each generation LoRA module is different, and each generation LoRA module corresponds to a different type of task. The basic models of the classification module and the generation module both include a linear layer. The weight matrix in the classification LoRA module is used to fine-tune the linear layer of the basic model in the classification module using the LoRA low-rank method, and the weight matrix in the generation LoRA module is used to fine-tune the linear layer of the basic model in the generation module using the LoRA low-rank method.

[0015] The data acquisition module is used to acquire several task texts and transform each task text through a word segmenter to obtain each input text of the large language model;

[0016] The processing module is used to input the input texts of several task texts into the large language model. The basic model of the classification module processes all the input texts. The classification linear layer Classify_Head performs task classification according to the processed input text to obtain the classification result. According to the classification result, the corresponding generation LoRA module in the generation module is loaded to process the input text.

[0017] Furthermore, the classification linear layer Classify_Head used for task classification is obtained by fine-tuning using the LoRA low-rank method.

[0018] Furthermore, the basic model includes a word embedding layer and a decoder layer.

[0019] The present invention also adopts a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.

[0020] The present invention also adopts a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps of the above method are implemented.

[0021] Beneficial effect: Compared with the prior art, the significant advantage of the present invention is that it can perform user question classification and multi-task parallel query, use the same basic model for fine-tuning, and load different fine-tuned LoRA modules corresponding to different task types, which can save a lot of video memory resources and time resources. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Figure 1 This is an application framework diagram of the multi-task processing method based on a large language model in the present invention. DETAILED DESCRIPTION

[0023] Example 1

[0024] like Figure 1 As shown, in this embodiment, a multi-task processing method based on a large language model includes the following steps:

[0025] Step 1: Selection of basic model:

[0026] A large language model for Chat with a decoder-only structure is selected as the basic model. The large language model for Chat has the ability to understand and generate natural language. The structure of the basic model includes a word embedding layer and a decoder layer.

[0027] For example, Chinese-Llama2-13B-Chat is used as the basic model.

[0028] Step 2: Task fine-tuning:

[0029] The weight matrix in the LoRA generation module is used to fine-tune the linear layer of the basic model using the LoRA low-rank method. According to the multiple tasks required by actual needs, the LoRA generation modules with different weight matrices for different tasks are saved separately; the specific steps are as follows:

[0030] Step 2.1: The amount of training data for each task depends on the complexity of the task. Each specific task should be fine-tuned using the business data collected from the original business system. For each task, collect at least 1,000 pieces of training data, including input text and output text. The training data format is as follows: {"instruction":"input text","output":"output text"}.

[0031] Step 2.2: Perform LoRA low-rank conversion on all linear layers (excluding word embedding layers) in the base model. For each linear layer weight matrix W0∈R d×k , initialize a zero matrix B∈R d×r and a random Gaussian distribution matrix A∈R r×k , where r is a low rank, which can generally be 8 or 16. The original linear layer forward process becomes h=W0x+ΔWx=W0x+BAx. The forward process of the linear layer mainly involves obtaining the output through linear transformation of the input data, and its mathematical expression is h=W0x+ΔWx. When training the linear layer, the weight matrix W0 of the linear layer is frozen, and only the zero matrix B and the random Gaussian distribution matrix A are trained. By setting a lower rank r, the amount of training parameters can be greatly reduced. And for specific tasks, the rank r generally only needs to be set to 8 to achieve good results.

[0032] Step 2.3: Use the tokenizer corresponding to the basic model to convert the input text and output text into input_ids and label_ids.

[0033] Step 2.4: Use the cross entropy function as the loss function to fine-tune each task. The loss function during training is the cross entropy function, which measures the correctness of the prediction of the next token (token refers to the smallest unit into which the text is divided). Only the cross entropy of the label_ids part is taken. The loss formula is as follows:

[0034]

[0035] Among them, X represents input_ids, Y represents label_ids, M represents Y, which is the length of label_ids, m represents label_id, V represents the vocabulary size, and y c represents a symbolic function (0 or 1), if the predicted next token is equal to the actual label_id, it takes 1, otherwise it takes 0, p c Indicates the probability value that the next token is c.

[0036] Step 2.4: Save the weight matrix of the generated LoRA module involved in each task.

[0037] Step 3: Construction and training of task classifier:

[0038] Step 3.1: Add an unbiased classification linear layer Classify_Head to the base model for task classification. Gaussian random initializes an unbiased linear layer named Classify_Head, whose input dimension is the latent vector dimension H of the base model and whose output dimension is the number of all tasks T. This linear layer is used to classify each task, and in the forward process of classification reasoning, this linear layer will replace LM_Head used to generate the next token.

[0039] Step 3.2: At the same time, according to the above LoRA low-rank fine-tuning method, generate the zero matrix B and random Gaussian distribution matrix A corresponding to each linear layer (including the linear layer of the basic model and the classification linear layer Classify_Head). The modules that need to update parameters are the classification linear layer Classify_Head and the zero matrix B and random Gaussian distribution matrix A of the classification LoRA module.

[0040] Step 3.3: Use the user's historical question data to train the classification linear layer Classify_Head. The training data includes questions and corresponding classification labels. For example: {"question":"Query today's weather", "label":1}. The amount of training data for each task should be kept as balanced as possible. Each task requires at least 1,000 training data. Similarly, the input text needs to be converted into input_ids by the tokenizer before training.

[0041] Step 3.4: Use the cross entropy function as the loss function to fine-tune the question classification module. The loss formula during training is as follows:

[0042]

[0043] Among them, X represents input_ids; Y represents label classification label; T represents the number of tasks; y c represents a symbolic function (0 or 1), which takes 1 if the predicted task category is equal to the actual label, otherwise it takes 0; p c Represents the probability value of the task.

[0044] Step 3.5: Save the weight matrix of the classification LoRA module and the classification linear layer Classify_Head involved in the classification task.

[0045] Step 4: Reasoning process in the application phase:

[0046] Step 4.1: After the user's question is entered, it is converted into token_ids through the tokenizer.

[0047] Step 4.2: Load the classification LoRA module and the classification linear layer Classify_Head, and form a forward reasoning channel with the Embedding layer and each Decoder module of the basic model. The probability corresponding to each task category is inferred. The task category corresponding to the maximum probability is the task module that the subsequent feedback user should adopt.

[0048] Step 4.3: Load the generated LoRA module of the corresponding task, and form a forward reasoning channel with the Embedding layer, each Decoder module and LM_Head module of the basic model.

[0049] Step 4.4: Combine the prompt words related to the task, concatenate the prompt words with the user input, re-segment the words to obtain new token_ids, and input them into the inference channel for autoregressive generation.

[0050] Step 4.5: Execute the subsequent processing flow for specific tasks.

[0051] Example 2

[0052] In this embodiment, a multi-task processing system based on a large language model includes:

[0053] A model construction module is used to construct a large language model, which includes a classification module and a generation module. The classification module includes a classification linear layer Classify_Head for task classification, a basic model and a classification LoRA module. The generation module includes a basic model and multiple generation LoRA modules. The weight matrix of each generation LoRA module is different, and each generation LoRA module corresponds to a different type of task. The basic models of the classification module and the generation module both include a linear layer. The weight matrix in the classification LoRA module is used to fine-tune the linear layer of the basic model in the classification module using the LoRA low-rank method, and the weight matrix in the generation LoRA module is used to fine-tune the linear layer of the basic model in the generation module using the LoRA low-rank method.

[0054] The data acquisition module is used to acquire several task texts and transform each task text through a word segmenter to obtain each input text of the large language model;

[0055] The processing module is used to input the input texts of several task texts into the large language model. The basic model of the classification module processes all the input texts. The classification linear layer Classify_Head performs task classification according to the processed input text to obtain the classification result. According to the classification result, the corresponding generation LoRA module in the generation module is loaded to process the input text.

[0056] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0057] The present invention is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0058] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0059] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0060] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the enlightenment of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the purpose of the present invention and the claims, which all fall within the protection of the present invention.

Claims

1. A multi-task processing method based on a large language model, characterized in that: The following steps are involved: Construct a large language model, the large language model includes a classification module and a generation module, the classification module includes a classification linear layer Classify_Head for task classification, a basic model and a classification LoRA module, the generation module includes a basic model and multiple generation LoRA modules, the weight matrix of each generation LoRA module is different, each generation LoRA module corresponds to a different type of task, the basic models of the classification module and the generation module both include a linear layer, the weight matrix in the classification LoRA module is used to fine-tune the linear layer of the basic model in the classification module using the LoRA low-rank method, and the weight matrix in the generation LoRA module is used to fine-tune the linear layer of the basic model in the generation module using the LoRA low-rank method; Obtain several task texts; transform each task text through a word segmenter to obtain each input text of the large language model; The input texts of several task texts are input into the large language model, the basic model of the classification module processes all the input texts, the classification linear layer Classify_Head performs task classification according to the processed input texts to obtain the classification results, and the corresponding generation LoRA module in the generation module is loaded according to the classification results to process the input texts.

2. The multi-task processing method based on a large language model according to claim 1, characterized in that: The classification linear layer Classify_Head used for task classification is obtained by fine-tuning using the LoRA low-rank method.

3. The multi-task processing method based on a large language model according to claim 1, characterized in that: The base model includes a word embedding layer and a decoder layer.

4. The multi-task processing method based on a large language model according to claim 2 or 3, characterized in that: The LoRA low-rank method includes: for the weight matrix W0 of each linear layer, initializing a zero matrix B and a random Gaussian distribution matrix A; updating is represented by low-rank decomposition W0+ΔW=W0+BA, and when training the linear layer, only the newly added zero matrix B and random Gaussian distribution matrix A are trained, while the weight matrix W0 of the linear layer remains unchanged, and the cross entropy function is used as the loss function.

5. The multi-task processing method based on a large language model according to claim 1 or 2, characterized in that: The classification linear layer Classify_Head is an unbiased linear layer, whose input dimension is the latent vector dimension H of the model and whose output dimension is the number of tasks T; the training data of the classification linear layer Classify_Head includes the input text of the task text and the corresponding classification label; the output of the classification linear layer Classify_Head is the probability of the input text corresponding to each category of tasks, and the task category corresponding to the maximum probability is used as the task category of the input text.

6. A multi-task processing system based on a large language model, characterized in that: include: A model construction module is used to construct a large language model, which includes a classification module and a generation module. The classification module includes a classification linear layer Classify_Head for task classification, a basic model and a classification LoRA module. The generation module includes a basic model and multiple generation LoRA modules. The weight matrix of each generation LoRA module is different, and each generation LoRA module corresponds to a different type of task. The basic models of the classification module and the generation module both include a linear layer. The weight matrix in the classification LoRA module is used to fine-tune the linear layer of the basic model in the classification module using the LoRA low-rank method, and the weight matrix in the generation LoRA module is used to fine-tune the linear layer of the basic model in the generation module using the LoRA low-rank method. The data acquisition module is used to acquire several task texts and transform each task text through a word segmenter to obtain each input text of the large language model; The processing module is used to input the input texts of several task texts into the large language model. The basic model of the classification module processes all the input texts. The classification linear layer Classify_Head performs task classification according to the processed input text to obtain the classification result. According to the classification result, the corresponding generation LoRA module in the generation module is loaded to process the input text.

7. The multi-task processing system based on a large language model according to claim 6, characterized in that: The classification linear layer Classify_Head used for task classification is obtained by fine-tuning using the LoRA low-rank method.

8. The multi-task processing system based on a large language model according to claim 6, characterized in that: The base model includes a word embedding layer and a decoder layer.

9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 5 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.

Citation Information

Cited By

  • Big model-based official document processing method and device and official document generating and checking all-in-one machine

    CN120873157A

  • Data generation and classification method and large model for data generation and classification

    CN121167362A