Text generation method and device, equipment and medium
By injecting task adaptation parameters into the text generation model and adjusting model parameters according to the target task identification, the problem of insufficient generalization capabilities of existing models in different text generation tasks is solved, and the development difficulty and deployment cost are achieved.
Patent Information
- Application Number
- CN202411629460.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-14
- Publication Date
- 2025-03-11
AI Technical Summary
The existing comment generation model performs well in the comment generation field, but in other text generation tasks such as news title generation, the model generalization capability is insufficient, resulting in the need to develop multiple independent models, increasing the development difficulty and deployment complexity.
By obtaining the target task identification of the pending task, a matching task is found among the multiple text generation tasks associated with the first text generation model, corresponding task adaptation parameters are injected, and model parameters are adjusted to generate text for a specific task.
It realizes the reduction of model development difficulty and deployment cost under multi-text generation tasks, reduces model maintenance difficulty, and improves deployment flexibility and reliability.
Smart Images

Figure CN119598186A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a text generation method, device, equipment and medium. Background Art
[0002] Currently, text generation tasks can be performed using large language models (LLMs). For example, in a comment generation task, a comment generation model trained by a large language model can be used to generate various comment texts for a specified article.
[0003] However, the inventors found in practice that since the comment generation model is essentially a task-oriented model framework, when the comment generation model is applied in the comment generation field, it only has the ability to generate comment text. For other text generation tasks, such as news headline generation tasks, the model generalization ability is insufficient, and it is necessary to develop a corresponding news headline generation model separately. Therefore, when there are many text generation tasks, it is necessary to develop multiple independent models for different text generation tasks, which will not only increase the difficulty of model development to a certain extent, but also increase the complexity of model deployment and maintenance. Summary of the invention
[0004] The embodiments of the present application provide a text generation method, apparatus, device and medium, which can reduce the difficulty of model development and the cost of model deployment in multi-text generation tasks.
[0005] On the one hand, an embodiment of the present application provides a text generation method, the method comprising:
[0006] Obtaining a target task identifier of a task to be processed; the task to be processed refers to a task of generating a task output text corresponding to a task input text through a first text generation model; the first text generation model is a text generation model that can inject multiple task adaptation parameters corresponding to multiple text generation tasks; one text generation task corresponds to one task adaptation parameter;
[0007] Searching for a text generation task that matches the target task identifier among a plurality of text generation tasks associated with the first text generation model, determining the found text generation task as the target text generation task, and using the task adaptation parameter corresponding to the target text generation task as the first task adaptation parameter to be activated;
[0008] When injecting the first task adaptation parameter into the first text generation model, activating the first task adaptation parameter, and obtaining a second text generation model after adjusting the parameters of the first text generation model;
[0009] When a prompt template text matching the target text generation task is obtained, the second text generation model is guided according to the prompt template text to generate a task output text corresponding to the task input text.
[0010] On the one hand, an embodiment of the present application provides a text generation device, the device comprising:
[0011] A parameter acquisition module is used to obtain a target task identifier of a task to be processed; the task to be processed refers to a task of generating a task output text corresponding to a task input text through a first text generation model; the first text generation model is a text generation model that can inject multiple task adaptation parameters corresponding to multiple text generation tasks; one text generation task corresponds to one task adaptation parameter;
[0012] The parameter acquisition module is further used to search for a text generation task that matches the target task identifier among multiple text generation tasks associated with the first text generation model, determine the found text generation task as the target text generation task, and use the task adaptation parameter corresponding to the target text generation task as the first task adaptation parameter to be activated;
[0013] A parameter injection module, used to activate the first task adaptation parameter when injecting the first task adaptation parameter into the first text generation model, and obtain a second text generation model after adjusting the parameters of the first text generation model;
[0014] The text generation module is used to guide the second text generation model according to the prompt template text to generate a task output text corresponding to the task input text when a prompt template text matching the target text generation task is obtained.
[0015] On one hand, an embodiment of the present application provides a computer device, including a memory and a processor, wherein the memory is connected to the processor, the memory is used to store a computer program, and the processor is used to call the computer program so that the computer device executes the method provided in any one of the above aspects of the embodiment of the present application.
[0016] On one hand, an embodiment of the present application provides a computer-readable storage medium, in which a computer program is stored. The computer program is suitable for being loaded and executed by a processor, so that a computer device with a processor executes the method provided in any of the above aspects of the embodiments of the present application.
[0017] According to one aspect of the present application, a computer program product is provided. The computer program product includes a computer program. When the computer program is executed by a processor, the method provided in any one of the above aspects of the embodiments of the present application is implemented.
[0018] In an embodiment of the present application, when the target task identifier of the task to be processed is obtained, a text generation task that matches the target task identifier can be searched among multiple text generation tasks associated with the first text generation model, and the task adaptation parameters corresponding to the found text generation task (target text generation task) are used as the first task adaptation parameters to be activated, so as to be injected into the first text generation model, thereby obtaining a second text generation model for the task to be processed, wherein the second text generation model is a text generation model that can implement the task to be processed after the parameters of the first text generation model are adjusted; at this time, when the prompt template text matching the target text generation task is obtained, the prompt model text is used to guide the second text generation model to generate a task output text corresponding to the task input text. In this way, the model input form for different text generation tasks can be unified through the prompt template text, and the task adaptation parameters trained for each text generation task can be injected into the unified text generation model to obtain a text generation model for each text generation task to achieve the corresponding text generation task. In this way, whenever a new text generation task is added, it is only necessary to train the corresponding task adaptation parameters for injecting into the first text generation model, which realizes the plug-and-play of the task adaptation parameters. Compared with the workload brought by deploying text generation models for multiple text generation tasks, this can reduce the difficulty of model development and model deployment costs under multiple text generation tasks, as well as reduce the difficulty of template maintenance, while improving deployment flexibility and reliability. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0020] Figure 1 A schematic diagram of a network architecture provided for an embodiment of the present application;
[0021] Figure 2 This is a schematic diagram of a text generation process provided by an embodiment of the present application;
[0022] Figure 3 A flowchart of a text generation method provided in an embodiment of the present application;
[0023] Figure 4 A schematic diagram of a parameter injection scenario provided in an embodiment of the present application;
[0024] Figure 5 A schematic diagram of a task prompt text provided in an embodiment of the present application;
[0025] Figure 6 A schematic diagram of generating a task output text provided in an embodiment of the present application;
[0026] Figure 7 A flowchart of another text generation method provided in an embodiment of the present application;
[0027] Figure 8 A schematic diagram of another parameter injection scenario provided in an embodiment of the present application;
[0028] Fig. 9 A schematic diagram of a scenario of a training architecture provided in an embodiment of the present application;
[0029] Fig.10 A schematic diagram of another scenario of a training architecture provided in an embodiment of the present application;
[0030] Fig.11 A schematic diagram of a scenario of a model application provided in an embodiment of the present application;
[0031] Fig.12 A schematic diagram of the structure of a text generation device provided in an embodiment of the present application;
[0032] Fig.13 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0033] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0034] See also Figure 1 , Figure 1 Schematic diagram of a network architecture provided by an embodiment of the present application. Figure 1 As shown, the system architecture may include a service server 100 and a service terminal cluster, wherein the service terminal cluster may include one or more service terminals (such as user terminals), and the number of service terminals in the service terminal cluster is not limited. Figure 1As shown, the multiple service terminals in the service terminal cluster may specifically include: service terminal 200a, service terminal 200b, ..., service terminal 200n, wherein there may be a communication connection between the service terminal clusters, for example, there is a communication connection between service terminal 200a and service terminal 200b, and there is a communication connection between service terminal 200a and service terminal 200n. At the same time, any service terminal in the service terminal cluster may have a communication connection with the service server 100, so that each service terminal in the service terminal cluster may exchange data with the service server 100 through the communication connection, for example, there is a communication connection between service terminal 200a and service server 100. The above-mentioned communication connection does not limit the connection mode, and may be directly or indirectly connected through a wired communication mode, or directly or indirectly connected through a wireless communication mode, or through other modes, which are not limited in this application.
[0035] Among them, Figure 1 Each service terminal in the service terminal cluster shown in FIG. 1 may be installed with an application client for text generation. When the application client runs in each service terminal, it may be respectively connected to the above-mentioned Figure 1 Data is exchanged between the business servers 100 shown. The application client may be any type of client, such as a social client, an image processing client, an instant messaging client (e.g., a conference client), an entertainment client (e.g., a game client, a live broadcast client), a multimedia client (e.g., a video client), an information client (e.g., a news client), a shopping client, a car client, a multimedia client, an application download client (a client for providing users with various downloadable application resources), and other clients having the function of displaying data information such as text, images, audio, and video. The specific type of the application client is not limited here.
[0036] For example, an application client refers to a client that can instantly send and receive Internet messages and has information search functions, etc. The application client on the business terminal 200a of the business object X can generate a text generation request based on the task input text and the target task identifier of the specified task to be processed. When the business server 100 obtains the target task identifier and the task input text from the text generation request, it can find the task adaptation parameter corresponding to the text generation task that matches the target task identifier, inject it into the first text generation model to obtain the second text generation model, and can generate the task output text corresponding to the task input text through the second text generation model.
[0037] The computer device involved in the embodiment of the present application may be a server (for example, Figure 1 The service server 100 shown in FIG. 1 may also be a terminal (for example, Figure 1 Any business terminal in the business terminal cluster shown). Among them, the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The terminal can be a smart phone, tablet computer, laptop computer, desktop computer, smart speaker, smart TV, smart watch, vehicle-mounted terminal, aircraft, etc., but is not limited to this. The embodiments of the present application can be applied to various scenarios, including but not limited to cloud technology, artificial intelligence, smart transportation, assisted driving, etc.
[0038] in, Figure 1 It is only an example to characterize the possible network architecture of the technical solution of the present application, and does not limit the specific architecture of the technical solution of the present application, that is, the technical solution of the present application can also provide other forms of network architecture.
[0039] Among them, see Figure 2 , Figure 2 1 is a schematic diagram of a text generation process provided by an embodiment of the present application, wherein a plurality of text generation tasks associated with the first text generation model respectively correspond to task adaptation parameters, and one text generation task corresponds to one task adaptation parameter.
[0040] For example, the text generation tasks include task a21, task a22, ..., task a2n. Task a21 corresponds to task adaptation parameter b21, task a22 corresponds to task adaptation parameter b22, ..., task a2n corresponds to task adaptation parameter b2n.
[0041] When obtaining the target task identifier 20a of the task to be processed, a text generation task matching the target task identifier may be searched from multiple text generation tasks (matching is performed from task identifiers of multiple text generation tasks based on the target task identifier).
[0042] The text generation task found at this time is determined as the target text generation task (such as task a21), and the task adaptation parameter corresponding to the target text generation task is used as the first task adaptation parameter to be activated (ie, task adaptation parameter b21).
[0043] Among them, the task adaptation parameter b21 can be injected into the first text generation model 21a, and when the task adaptation parameter b21 is activated in the first text generation model 21a (that is, the first task adaptation parameter is in a usable state in the second text generation model), a second text generation model 21b is obtained after the parameters of the first text generation model are adjusted.
[0044] At this time, a prompt template text 22a matching the target text generation task can be obtained, and the second text generation model can be guided by the prompt template text to generate a task output text that corresponds to the task input text and meets the target text generation task.
[0045] For example, the task prompt text is obtained from the prompt template text 22a and the task input text 23a, and is input into the second text generation model, and the second text generation model generates the task output text 23b corresponding to the task input text based on the task prompt text.
[0046] The task to be processed refers to a task of generating a task output text corresponding to a task input text by using a first text generation model. Different text generation tasks may indicate generating different task output texts corresponding to different task input texts.
[0047] In this way, for multiple text generation tasks, it is only necessary to train to obtain the corresponding task adaptation parameters, and when injected into the first text generation model, the obtained second text generation model can realize the corresponding text generation task. When the second text generation model completes the text generation task, the injected task adaptation parameters can be removed to restore the original first text generation model. This can reduce the model deployment cost and maintenance cost, and realize the adaptive execution of various text generation tasks through a unified text generation model.
[0048] Optionally, the computer device may execute the text generation method to improve the text generation efficiency according to actual business needs. The text generation task may be a generation task in any scenario. For example, it may be a summary generation task (generating a short summary text based on a long text, the summary text retains key information, and facilitates users to quickly obtain information).
[0049] For example, it may be a search term generation task (generating different types of search terms according to the event content, such as factual, knowledge, and extended, etc., to increase the user's click rate on the search terms and the efficiency of searching for event content).
[0050] For example, it may be a comment generation task (generating various types of comment texts according to the event content, such as comment texts with specific emotions, such as approval, opposition, etc.), etc. The specific type of text generation task is not limited here.
[0051] In the technical solution of the present application, corresponding task adaptation parameters can be trained for any text generation task and injected into the text generation model to realize the generation of different texts. Compared with the text generation models for each text generation task deployed separately, this can be integrated to obtain a text generation model architecture for uniformly executing multiple text generation tasks.
[0052] It should be noted that when the computer device in the embodiment of the present application obtains relevant data, such as the target language text uploaded by the business object (user), a prompt interface or pop-up window can be displayed. The prompt interface or pop-up window can be used to prompt the user that the aforementioned data is currently being obtained. Only after the user issues a confirmation operation on the prompt interface or pop-up window, the relevant steps of data acquisition are started, otherwise it ends.
[0053] It is understandable that in the specific implementation of the present application, user data (for example, relevant task input text, such as uploaded articles, etc.) may be involved. When the above embodiments of the present application are applied to specific products or technologies, the user's permission or consent is required, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of the relevant regions.
[0054] It is understood that the above scenarios are only examples and do not constitute a limitation on the application scenarios of the technical solutions provided in the embodiments of the present application. The technical solutions of the present application can also be applied to other scenarios. For example, it is known to those skilled in the art that with the evolution of the system architecture and the emergence of new business scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0055] For further information, see Figure 3 , Figure 3 is a flowchart of a text generation method provided in an embodiment of the present application, such as Figure 3 As shown, the method can be executed by the computer device mentioned above, for example, Figure 1 For any one of the service terminals or service servers shown in , the method may specifically include the following steps S101 to S104:
[0056] S101, obtaining a target task identifier of a task to be processed.
[0057] The task to be processed refers to a task of generating a task output text corresponding to a task input text through a first text generation model.
[0058] For example, a corresponding text generation request may be generated based on the target task identifier and task input text of the task to be processed, and when obtaining the text generation request associated with the task to be processed, the task input text and the target task identifier of the task to be processed are obtained from the text generation request.
[0059] For example, in a news title generation task (generating a news title corresponding to the news text through a first text generation model), when the news text (task input text) of the news title to be generated (task output text) is obtained, a corresponding text generation request can be generated based on the news text and the task identifier of the news title generation task to indicate the generation of a news title corresponding to the news text.
[0060] For example, in a comment text generation task (generating comments corresponding to an article through a first text generation model), when the article (task input text) for which comments are to be generated (task output text) is obtained, a corresponding text generation request can be generated based on the article and the task identifier of the comment text generation task to indicate the generation of comments corresponding to the article.
[0061] Optionally, the first text generation model is a text generation model that can inject multiple task adaptation parameters corresponding to multiple text generation tasks. One text generation task corresponds to one task adaptation parameter. The text generation task can be a task for generating any type of text (such as news headlines, comment texts, etc.). This is not limited here.
[0062] Among them, the task adaptation parameters of a text generation task are model parameters adapted to the text generation task obtained by training the first text generation model, and the determination method thereof can refer to the relevant description of the following embodiment.
[0063] Among them, the first text generation model can be injected with task adaptation parameters corresponding to any text generation task to obtain a second text generation model for executing the text generation task.
[0064] For example, if the text generation task is a news title generation task, the task adaptation parameters corresponding to the news title generation task can be injected into the first text generation model to obtain a second text generation model for executing the news title generation task. At this time, the text generated by the second text generation model is the news title.
[0065] For example, if the text generation task is a comment text generation task, the task adaptation parameters corresponding to the comment text generation task can be injected into the first text generation model to obtain a second text generation model for executing the comment text generation task. At this time, the text generated by the second text generation model is the comment text.
[0066] Optionally, the first text generation model can be a large language model (such as an open source LLM model), wherein the LLM model is an algorithm based on deep learning, which learns the complex patterns and structures of language by training on massive text data.
[0067] Among them, the LLM model usually adopts the Transformer (a deep learning model) architecture and uses the attention mechanism to capture the long-distance dependencies between words. The training process involves predicting the next word in the text sequence, so that the model can master grammar, semantics and a certain degree of reasoning ability. The LLM model can generate fluent and coherent text and complete various natural language processing tasks, such as text summarization, machine translation and question-answering systems.
[0068] Among them, Transformer is a deep learning model based on the self-attention mechanism, which is widely used in processing sequence data. For example, natural language text. It abandons the traditional recurrent neural network structure and calculates the relationship between all input elements in parallel to improve efficiency. Among them, the core of Transformer is the self-attention layer, which allows the model to focus on different parts of the input sequence and learn the dependencies between them. The self-attention layer in Transformer contains multiple attention heads (multi-head), each of which focuses on different aspects. Among them, the LLM model can include multiple layers of Transformer.
[0069] Optionally, the first text generation model may specifically use a decoder-only LLM model as a base model. In this case, the Transformer in the first text generation model may refer to the decoder part in the Transformer (e.g., it may be called a decoding layer, i.e., the first text generation model includes multiple decoding layers).
[0070] In this way, the text content generated by the first text generation model is no longer limited to the encoder input, but only realizes input and output through the decoder, thereby improving generalization and extensibility, reducing the necessity of constructing training data with generalization and extensibility, and reducing the requirements for training data and the workload of construction while ensuring the training effect.
[0071] S102. Search for a text generation task that matches a target task identifier among multiple text generation tasks associated with a first text generation model, determine the found text generation task as a target text generation task, and use task adaptation parameters corresponding to the target text generation task as first task adaptation parameters to be activated.
[0072] Among them, the task identifier that matches the target task identifier can be checked from the task identifiers of multiple text generation tasks, and the text generation task corresponding to the found task identifier can be used as the text generation task that matches the target task identifier. At this time, the task adaptation parameters corresponding to the target text generation task can be used to execute the task to be processed.
[0073] Optionally, at this time, the parameters other than the first task adaptation parameters in the plurality of task adaptation parameters can be used as the second task adaptation parameters to be shielded, and the second task adaptation parameters are shielded. At this time, the unshielded task adaptation parameters (first task adaptation parameters) are the parameters to be injected into the first text generation model.
[0074] S103 . When injecting the first task adaptation parameter into the first text generation model, activating the first task adaptation parameter, and obtaining a second text generation model after adjusting the parameters of the first text generation model.
[0075] Among them, the unmasked first task adaptation parameters can be injected into the first text generation model, and the first task adaptation parameters can be activated (the first task adaptation parameters are in a usable state). At this time, the second text generation model includes the original parameters (original parameters) of the first text generation model and the injected first task adaptation parameters.
[0076] The output result of the second text generation model is determined by the original parameters in the first text generation model and the first task adaptation parameters.
[0077] For example, the routing mechanism can be used to select the task adaptation parameter of the text generation task corresponding to the target task identifier as the first task adaptation parameter to be activated according to the target task identifier of the task to be processed, inject the first task adaptation parameter into the first text generation model, and activate it. After the task to be processed is completed, the first task adaptation parameter can be removed. That is, the routing mechanism can be used to achieve plug-and-play of task adaptation parameters.
[0078] Among them, if the original parameters are trained to adapt to the target text generation task, it will consume a huge amount of work, so the original parameters can be fine-tuned, but directly optimizing the original parameters will make it impossible to apply to other text generation tasks. Therefore, additional parameters can be optimized on the basis of the original parameters to obtain additional parameters suitable for the target text generation task as the task adaptation parameters corresponding to the target text generation task.
[0079] For example, for important parameters in the original parameters (parameters to be optimized), fine-tuning of the important parameters can be achieved by introducing additional parameters. For example, the original parameters include a weight matrix that is critical in the text generation process. Then, by introducing additional parameters for the weight matrix (instead of the optimization parameters) and optimizing the additional parameters, the task adaptation parameters (adaptation weight matrix) corresponding to the weight matrix are obtained.
[0080] The method for determining the adaptation weight matrix may refer to the relevant description of the following embodiment.
[0081] Optionally, the parameter to be optimized can be configured according to a specific scenario. For example, the first text generation model includes multiple decoding layers, and the parameter to be optimized can be a parameter in some or all of the multiple decoding layers (the first decoding layer). For example, the first decoding layer can be the first decoding layer and the second decoding layer in the multiple decoding layers.
[0082] Among them, since the self-attention mechanism is used in the first decoding layer, the parameters to be optimized can be part or all of the parameters contained in each decoding layer in the first decoding layer (such as a specified weight matrix in the decoding layer, such as called a decoding weight matrix).
[0083] Among them, the first text generation model is used to decode to obtain the task output text, so the decoding weight matrix in the first text generation model can be regarded as being used to perform decoding processing (ie, text generation processing).
[0084] For example, the decoding weight matrix is the attention weight matrix in the first text generation model. For example, in the self-attention mechanism, there is a Key matrix (used to determine the key vector, indicating the source to be matched or compared with the query vector), a Value matrix (used to determine the value vector, indicating the information to be weighted and summed according to the degree of matching between the query vector and the key vector), and a Query matrix (used to determine the query vector, used as a vector of query-related information (indicating the target to be focused on or retrieved)). The decoding weight matrix can be one or more of the attention weight matrices.
[0085] Alternatively, the decoding weight matrix may be other weight matrices in the first decoding layer, such as the attention head in the first decoding layer, etc. This is not limited here.
[0086] At this time, when the adaptation weight matrix is injected into the position of the decoding layer in the first text generation model, the decoding weight matrix and the adaptation weight matrix can be used as a new decoding weight matrix (that is, a combined weight matrix composed of the decoding weight matrix and the adaptation weight matrix). In the first text generation model, the step of decoding processing requiring the decoding weight matrix is changed to the step of decoding processing requiring the new decoding weight matrix in the second text generation model.
[0087] Therefore, in the second text generation model, when it is necessary to decode the decoding features obtained in the decoding process through a new decoding weight matrix, the decoding features are actually decoded through the decoding weight matrix and the adaptation weight matrix respectively.
[0088] For example, the decoding result obtained by the new decoding weight matrix may be the sum of the decoding result obtained by the decoding weight matrix and the decoding result obtained by the adaptation weight matrix.
[0089] For example, when decoding is performed in the second text generation model, a decoding feature that needs to be decoded by a new decoding weight matrix is obtained. At this time, the decoding feature is decoded by the original decoding weight matrix and the adapted weight matrix respectively, and the sum of the decoding result obtained by the original decoding weight matrix and the decoding result obtained by the adapted weight matrix is used as the decoding result obtained by the new decoding weight matrix.
[0090] For example, the decoding weight matrix includes the Value matrix in the first decoding layer, then the task adaptation parameters corresponding to the target text generation task may include the adaptation weight matrix corresponding to the Value matrix, and the combined weight matrix obtained by the original Value matrix in the first decoding layer and the injected adaptation weight matrix is the new Value matrix.
[0091] Among them, in the first text generation model, decoding processing through the Value matrix means determining a certain feature vector (such as feature vector A1) through the Value matrix to obtain a value vector, then corresponding to the second text generation model, decoding processing is performed through a new Value matrix.
[0092] Among them, when determining the value vector of a certain eigenvector (eigenvector A2) through the new Value matrix, specifically, the first transition value vector of eigenvector A2 can be determined through the original Value matrix in the new Value matrix, and the second transition value vector of eigenvector A2 can be determined through the adaptation weight matrix in the new Value matrix. The vector sum between the first transition value vector and the second transition value vector can be used as the value vector determined for eigenvector A2 through the new Value matrix.
[0093] Wherein, when there are multiple first decoding layers, the first task adaptation parameters include adaptation parameters for each first decoding layer, and there may be one or more decoding weight matrices in a first decoding layer. The adaptation parameters for a first decoding layer may include adaptation parameters for each decoding weight matrix in the first decoding layer.
[0094] Among them, the adaptation parameters for each first decoding layer can be injected into the corresponding position of the decoding weight matrix in the corresponding first decoding layer, so as to obtain a second text generation model after adjusting the parameters of the first text generation model.
[0095] The principle of decoding processing in the second text generation model is the same as the principle of decoding processing in the first text generation model.
[0096] For example, Figure 4 As shown, Figure 4A schematic diagram of a parameter injection scenario provided for an embodiment of the present application; wherein the first text generation model 40a may be a model structure including only a decoder.
[0097] For example, the first text generation model may include multiple decoding layers (such as decoding layer 41a, decoding layer 41b, decoding layer 41c).
[0098] The multiple decoding layers of the first text generation model may include the first decoding layer (such as decoding layer 41a, decoding layer 41b, decoding layer 41c) to be parameter adjusted. For ease of description, parameter injection of decoding layer 41a is taken as an example for description.
[0099] The first task adaptation parameters may include adaptation parameters for each first decoding layer, which may be injected into the corresponding first decoding layer respectively.
[0100] Among them, the decoding layer 41a injected with the corresponding adaptation parameters may be the second decoding layer 411a, the decoding layer 41b injected with the corresponding adaptation parameters may be the second decoding layer 411b, and the decoding layer 41c injected with the corresponding adaptation parameters may be the second decoding layer 411c.
[0101] For example, taking the decoding layer 41a as an example, the decoding layer 41a may include a decoding weight matrix 42a for parameter fine-tuning. At this time, the first task adaptation parameter may include an adaptation weight matrix 43a corresponding to the decoding weight matrix obtained by parameter fine-tuning.
[0102] At this time, the first task adaptation parameter can be injected into the corresponding decoding layer of the first text generation model, that is, the adaptation weight matrix is injected into the corresponding first decoding layer, and the weight matrix (composed of the combined weight matrix) containing the decoding weight matrix and the adaptation weight matrix in the first decoding layer is used as the new decoding weight matrix (decoding weight matrix 42b) obtained by adjusting the parameters of the original decoding weight matrix. Among them, the decoding layer 41a containing the decoding weight matrix 42b is the second decoding layer 411a obtained by adjusting the parameters of the decoding layer 41a.
[0103] Therefore, the first text generation model including the second decoding layer 411a, decoding layer 41b, and decoding layer 41c injected with the first task adaptation parameters is the second text generation model 40b obtained by adjusting the parameters of the first text generation model.
[0104] At this time, in the second decoding layer 411a of the second text generation model, when the decoding weight matrix 42b performs decoding processing, specifically, the original decoding weight matrix 42a in the decoding weight matrix 42b performs decoding processing and the adapted weight matrix 43a performs decoding processing, and the result sum between the decoding result obtained by the decoding weight matrix 42a and the decoding result obtained by the adapted weight matrix 43a is used as the decoding result obtained by the decoding weight matrix 42b, and the subsequent second text generation model continues to perform decoding processing based on the decoding result obtained by the new decoding weight matrix in the second decoding layer 411a, thereby generating the task output text.
[0105] S104: When a prompt template text matching the target text generation task is obtained, the second text generation model is guided according to the prompt template text to generate a task output text corresponding to the task input text.
[0106] Among them, different target text generation tasks can have different prompt template texts. The prompt model text is also called a prompt word (prompt) for the second text generation model, which is used to prompt the second text generation model to generate a task output text that meets the task requirements (such as requiring the generation of a news headline) based on the task input text.
[0107] Among them, for the text generation model, generating text for a specific task is to let the text generation model play a role. For example, let the text generation model play the role of a journalist writing a news headline, or let the text generation model play the role of a user viewing an article and writing a comment text, etc.
[0108] Among them, in order to make full use of the understanding and generation capabilities of the large language model, the task input text corresponding to the target text generation task can be processed into natural language, that is, the structured task data (that is, the task input text) can be converted into a natural language description that conforms to the target text generation task through prompt engineering.
[0109] In this way, by converting the task input text of any text generation task into the corresponding natural language description, the input of the text generation model for different text generation tasks can be unified, thereby making the text generation model compatible with various text generation tasks and realizing efficient and flexible text generation for various text generation tasks.
[0110] Among them, prompt word engineering refers to guiding the text generation model to understand the text generation task and generate task output text that meets the expected results by designing specific prompt words (prompt template text). The design of prompt words needs to consider factors such as task type, input data characteristics, and output data.
[0111] The configuration of the prompt template text needs to consider the following aspects: (1) the completeness of the task description, ensuring that the prompt words can fully describe the text generation task; (2) the simplicity and clarity of the language, avoiding the use of complex or ambiguous language; (3) the specific requirements related to the text generation task, adding specific requirements and restrictions according to the task requirements. In this way, through the prompt word engineering, the input data of the specific text generation task can be naturalized, so that the text generation model can better understand and process the text generation task.
[0112] For example, for a text generation model, it is necessary to give the role setting that the text generation model needs to play, the task description (description of what kind of feedback is required), the task content (task input text), and the required details, etc. For example, the text generation model is told that the role setting is a user viewing an article, and it is hoped that the text generation model will input text (such as an article) according to the task and write the corresponding comment text according to the approval emotion. At this time, the business model will write a comment text for the article from the perspective of the user viewing the article and from the perspective of approving the article.
[0113] The information used to input the second text generation model is the model prompt information (task prompt text), that is, the instruction to the second text generation model, which is used to prompt the second text generation model, role settings, and things to do or questions to answer, etc. At this time, the business model can predict the corresponding task output text based on the instructions of the task prompt text.
[0114] For example, the prompt template text may be different based on different text generation tasks. For example, in a news headline generation task, the prompt template text is used to instruct the text generation model to generate a news headline (such as including relevant role settings, task description, required details, etc.), or in a comment generation task, the prompt template text is used to instruct the text generation model to generate a comment text (such as including relevant role settings, task description, required details, etc.).
[0115] At this time, the task input text can be filled into the prompt template text to obtain the task prompt text (such as filling the task input text into the specified position in the prompt template text according to the rules of the prompt template text), and the task prompt text is input into the second text generation model, and the second text generation model generates the task output text based on the task prompt text. That is, the second text generation model decodes the task prompt text to obtain the corresponding task output text.
[0116] The second text generation model can decode from the task prompt text to obtain information such as role settings, task descriptions, required details, and task content (task input text) related to the target text generation task, and then generate task output text that conforms to the role settings, task descriptions, and required details based on the task input text.
[0117] For example, for a text generation task, the prompt template text is: You are XX (indicating role setting, such as [journalist]), please help me complete XX (indicating task description, such as [writing news headlines]) according to the following content I give: [...], requiring XX (indicating required details, such as [no more than 30 words]). At this time, the content text of the news headline to be generated can be filled into the prompt template text to obtain the task prompt text.
[0118] Different text generation tasks may have different prompt template texts, and one text generation task may have multiple prompt template texts. The prompt template text of the target text generation task may be obtained according to the target task identifier through the prompt word project, and the task input text may be filled into the prompt template text.
[0119] For example, when the routing mechanism obtains the target task identifier and obtains the second text generation model, the corresponding task prompt text is obtained through the prompt word project to input into the second text generation model. Alternatively, when the routing mechanism obtains the target task identifier, the corresponding task prompt text can be obtained through the prompt word project, and the first task adaptation parameter can be obtained through the target task identifier to obtain the second text generation model, and then the task prompt text can be input into the second text generation model.
[0120] Optionally, a prompt template text may be randomly selected from a plurality of prompt template texts of the text generation task to fill in the task input text.
[0121] Alternatively, the prompt template text may be specified by the user.
[0122] For example, when a comment text with a specific emotion needs to be generated, a prompt template text for instructing to generate the comment text with the specific emotion is selected.
[0123] Alternatively, the prompt word engineering may intelligently identify a matching prompt template text from a plurality of prompt template texts.
[0124] For example, in the news title generation task, different types of news titles may have different generation requirements. For example, for entertainment news, the news title should not be too long, so you can select a prompt template text that includes the title word count requirement; for current affairs news, the news title needs to emphasize important information such as events, people, and places, so you can select a prompt template text in the task description to indicate the generation of current affairs news titles.
[0125] Among them, the prompt template text can be obtained by business personnel according to the text generation task configuration, or it can be supplemented by a large language model (for example, configure part of the prompt template text, and input it into the large language model, and the large language model supplements the remaining prompt template text), which is not limited here.
[0126] Among them, when the second text generation model generates the task output text based on the task prompt text, the second text generation model decodes the task prompt text through the original parameters in the first text generation model and the input first task adaptation parameters to generate the task output text corresponding to the task input text.
[0127] For example, Figure 5 As shown, Figure 5 A schematic diagram of a task prompt text provided for an embodiment of the present application; wherein, for a text generation task, the task identifier of the text generation task and the task input text input prompt word project can be used to generate a task prompt text corresponding to the task input text based on the prompt template text of the text generation task.
[0128] For example, the text generation task is a news title generation task, and the prompt template text is: You are a [journalist], please help me complete the [writing of news title] based on the following content I give: [...], the requirement is [no more than 30 words].
[0129] At this time, you can fill in the task input text that needs to generate a news title (such as [News ABC...]) into the prompt template text corresponding to the news title generation task, and obtain the task prompt text corresponding to the task input text: You are a [journalist], please help me complete the [writing of news title] based on the following content I give: [News ABC...], the requirement is [no more than 30 words].
[0130] For another example, the text generation task is a comment generation task, and the prompt template text is: You are [the user who views this article]. Please help me complete [posting a comment] based on the following content I give: [...], and the requirement is [the emotional tone of the posted comment is approval].
[0131] At this point, you can input the task text that needs to generate comments (such as [XX event...]) into the prompt template text to get the task prompt text: You are [the user who views this article]. Please help me complete [the publication of comments] based on the following content I give: [XX event...]. The requirement is that [the emotional tone of the published comments should be approval].
[0132] For another example, the text generation task is a translation text generation task (and the translation text generation task is to translate Chinese into English at this time), and the prompt template text is: You are good at translating Chinese into English, please return the content I gave into English: [...].
[0133] At this point, you can input the task input text that needs to generate comments (such as [The weather is really nice today]) into the prompt template text to get the task prompt text: You are good at translating Chinese into English, please return the content I gave into English: [The weather is really nice today].
[0134] For example, Figure 6 As shown, Figure 6 A schematic diagram for generating a task output text is provided for an embodiment of the present application; wherein, a task input text 60a is input into a prompt word project 61a, and a prompt template text 62a in the prompt word project that matches the text generation task to which the task input text belongs is used to obtain a task prompt text 62b of the task output text, and when a second text generation model 63b is obtained by injecting a first task adaptation parameter 64a corresponding to the text generation task to which the task input text belongs into a first text generation model 63a, the task prompt text can be input into the second text generation model, and the second text generation model predicts and outputs the corresponding task output text 60b.
[0135] For a text generation task, the task identifier of the text generation task and the task input text may be input into a prompt word project to generate a task prompt text corresponding to the task input text based on a prompt template text of the text generation task.
[0136] In an embodiment of the present application, when the target task identifier of the task to be processed is obtained, a text generation task that matches the target task identifier can be searched among multiple text generation tasks associated with the first text generation model, and the task adaptation parameters corresponding to the found text generation task (target text generation task) are used as the first task adaptation parameters to be activated, so as to be injected into the first text generation model, thereby obtaining a second text generation model for the task to be processed, wherein the second text generation model is a text generation model that can implement the task to be processed after the parameters of the first text generation model are adjusted; at this time, when the prompt template text matching the target text generation task is obtained, the prompt model text is used to guide the second text generation model to generate a task output text corresponding to the task input text. In this way, the model input form for different text generation tasks can be unified through the prompt template text, and the task adaptation parameters trained for each text generation task can be injected into the unified text generation model to obtain a text generation model for each text generation task to achieve the corresponding text generation task. In this way, whenever a new text generation task is added, it is only necessary to train the corresponding task adaptation parameters for injecting into the first text generation model, which realizes the plug-and-play of the task adaptation parameters. Compared with the workload brought by deploying text generation models for multiple text generation tasks, this can reduce the difficulty of model development and model deployment costs under multiple text generation tasks, as well as reduce the difficulty of template maintenance, while improving deployment flexibility and reliability.
[0137] For further information, see Figure 7 , Figure 7 is a flowchart of a text generation method provided in an embodiment of the present application, such as Figure 7 As shown, the method can be executed by the computer device mentioned above, for example, Figure 1 For any one of the service terminals or service servers shown in , the method may specifically include the following steps S201 to S208:
[0138] S201. Obtain task training parameters corresponding to a sample text generation task among multiple text generation tasks.
[0139] Among them, fine-tuning can be performed on the basis of the first text generation model to obtain task adaptation parameters for any text generation task. Here, any one of the multiple text generation tasks is a sample text generation task when task adaptation parameters need to be trained.
[0140] Among them, the fine-tuning technology can be the LoRA (Low-Rank Adaptation) fine-tuning technology, which is used to efficiently fine-tune large language models. The core idea is to limit the change of model parameters to a low-rank matrix instead of updating all parameters.
[0141] Among them, LoRA means introducing a small amount of replacement training parameters to perform fine-tuning to adapt to specific task requirements without changing the original parameters of the text generation model.
[0142] For example, the parameters in the first text generation model are frozen through the LoRA fine-tuning technology, and the trainable rank decomposition matrix (low-rank matrix, that is, the task training parameters required for the sample text generation task) is injected into the decoding layer of the first text generation model. That is, the principle is to inject low-rank matrices into the weight matrices that originally need to be trained in a specific network layer of the model, and adjust the behavior of the model by training these low-rank matrices.
[0143] Among them, at this time, during the training process, only these rank decomposition matrices can be updated, and the updated rank decomposition matrices can be used as task adaptation parameters for the sample text generation task. Compared with optimizing the parameters in the first text generation model or introducing a parameter matrix with the same matrix dimension as the weight matrix originally required to be trained for optimization, it can greatly reduce the number of parameters that need to be trained, and reduce memory consumption and computational costs.
[0144] According to the above embodiment, the task training parameters can be obtained based on the parameters to be optimized in the first text generation model. For example, the first text generation model includes a first decoding layer to be adjusted; the parameters to be optimized can be the first decoding weight matrix (such as the above Key matrix, which is specifically configured by business personnel) included in the first decoding layer.
[0145] At this time, the parameters to be optimized can be decomposed into the product of two low-rank matrices, and the low-rank matrix obtained by the decomposition can be used as an additional replacement optimization parameter introduced for the parameters to be optimized (ie, the task training parameter for the text generation task).
[0146] Optionally, the parameters to be optimized may include one or more decoding weight matrices from different decoding layers. A decoding weight matrix can be decomposed into two low-rank matrices according to the matrix dimension. The decomposed low-rank matrix is the training weight matrix corresponding to the decoding weight matrix included in the task training parameters (the training weight matrix has been initialized).
[0147] Therefore, the task training parameters corresponding to the sample text generation task can be obtained by decomposing the matrix dimension of the decoding weight matrix to obtain a first decomposition matrix dimension and a second decomposition matrix dimension; using the first transition weight matrix corresponding to the first decomposition matrix dimension and the second transition weight matrix corresponding to the second decomposition matrix dimension as training weight matrices; the sum of the matrix parameter quantities of the first transition weight matrix and the second transition weight matrix is less than the matrix parameter quantity of the decoding weight matrix.
[0148] Among them, the matrix dimension of the decoding weight matrix is decomposed into a decomposition matrix dimension for obtaining a low-rank matrix, one decomposition matrix dimension corresponds to a weight matrix (initialized), and the matrix dimension product between the first decomposition matrix dimension and the second decomposition matrix dimension is the matrix dimension of the corresponding decoding weight matrix, thereby reducing the number of parameters.
[0149] That is, the matrix dimension of the product matrix between the first transition weight matrix and the second transition weight matrix is the same as the matrix dimension of the decoding weight matrix.
[0150] In addition, when decoding is performed through the decoding weight matrix, decoding is also performed through the first transition weight matrix and the second transition weight matrix. At this time, the decoding is performed based on the product matrix between the first transition weight matrix and the second transition weight matrix. The decoding process of the decoding weight matrix is the same as the decoding process of the product matrix.
[0151] Among them, since the parameters of the decomposed first transition weight matrix and the second transition weight matrix are optimized instead of the product matrix with the same matrix dimension as the decoding weight matrix, the number of parameters and the workload required for training can be reduced.
[0152] S202. When injecting the task training parameters into the first text generation model, the task training parameters are activated to obtain a transition text generation model after adjusting the parameters of the first text generation model.
[0153] Therefore, the task training parameters can be injected into the first decoding layer corresponding to the first text generation model. For example, the training weight matrix can be injected into the corresponding first decoding layer and the training weight matrix can be activated. Then, the weight matrix including the first decoding weight matrix and the training weight matrix can be used as the second decoding weight matrix corresponding to the first decoding weight matrix, thereby obtaining the second decoding layer.
[0154] The transition text generation model is obtained through the second decoding layer. The first decoding layer in the first text generation model corresponds to the second decoding layer in the transition text generation model, and the first decoding weight matrix in the first decoding layer corresponds to the second decoding weight matrix in the second decoding layer.
[0155] The decoding process performed by the first decoding layer corresponds to the decoding process performed by the second decoding layer. The decoding process performed by the first decoding weight matrix corresponds to the decoding process performed by the second decoding weight matrix.
[0156] Furthermore, performing decoding processing by using the second decoding weight matrix includes: performing decoding processing by using the first decoding weight matrix and performing decoding processing by using the training weight matrix.
[0157] Furthermore, performing decoding processing through the training weight matrix refers to performing decoding processing through the product matrix between the first transition weight matrix and the second transition weight matrix.
[0158] For example, the second decoding weight matrix W is expressed as:
[0159] W=W0+ΔW=W0+BA
[0160] Wherein, W0 is the first decoding weight matrix, B and A are the first transition weight matrix and the second transition weight matrix obtained by decomposition.
[0161] Among them, the matrix dimensions of the weight matrix are as follows:
[0162] B∈R d×r A∈R r×k W0∈R d×k
[0163] Among them, r is a hyperparameter that can be configured by business personnel, r<<min(d,k), which can greatly reduce the amount of parameters to be trained.
[0164] S203: Generate a sample task output text corresponding to the sample task input text through a transition text generation model.
[0165] The sample task input text may be input into the transition text generation model, and the transition text generation model generates a sample task output text that meets the sample text generation task based on the guidance of the prompt template text in the sample task input text.
[0166] S204: Optimize task training parameters by using the sample task output text and the labeled task output text corresponding to the sample task input text to obtain task adaptation parameters corresponding to the sample text generation task.
[0167] For example, a transition prompt template text matching the sample text generation task for optimizing task training parameters can be obtained, and sample task input text for the sample text generation task and the corresponding annotation task output text can be obtained.
[0168] For example, the sample text generation task is a news title generation task. The sample task input text can be the news content used to generate the news title, the labeling task output text can be the news title label annotated for the news content, and the sample task output text can be the news title predicted by the transition text generation model.
[0169] At this time, the transition text generation model can be guided according to the transition prompt template text to generate a sample task output text corresponding to the sample task input text.
[0170] For example, the sample task input text is filled into the transition prompt template text to obtain the sample task prompt text; the sample task prompt text is input into the transition text generation model, and the transition text generation model generates the sample task output text based on the sample task prompt text.
[0171] Among them, through the prompt word engineering, the text generation model can initially have the ability to generate short texts for specific tasks. In order to further improve the text generation effect, the above-mentioned fine-tuning technology can be combined to adapt to specific tasks.
[0172] Therefore, the task training parameters can be optimized through the sample task output text and the labeled task output text corresponding to the sample task input text until convergence, and the task adaptation parameters corresponding to the sample text generation task can be obtained, that is, the training weight matrix after parameter optimization is the task adaptation parameters corresponding to the sample text generation task.
[0173] Therefore, a sample task input text and a corresponding annotation task output text can be constructed for each text generation task, and when the task training parameters corresponding to each text generation task are obtained, the first text generation model can be injected so that the first text generation model after parameter adjustment can generate a sample task output text corresponding to the sample task input text, and then the task training parameters of the corresponding text generation task can be optimized based on the annotation task output text and the sample task output text to obtain the task adaptation parameters for each text generation task.
[0174] Subsequently, when a certain text generation task needs to be performed, the task adaptation parameters of the text generation task can be injected into the first text generation model to generate a task output text that meets the text generation task based on the obtained second text generation model.
[0175] The first decoding weight matrices corresponding to different text generation tasks may be different, so the task training parameters of different text generation tasks may be different, and the injection positions in the first text generation model may be different.
[0176] S205: Obtain the target task identifier of the task to be processed.
[0177] Among them, a text generation request carrying a target task identifier and a task input text may be generated to execute the task to be processed.
[0178] For example, in a comment generation task, when an article that needs to generate comments is obtained (such as content posted by a user), the article can be used as the task input text, and a text generation request for executing the comment generation task can be generated based on the task identifier of the comment generation task and the task input text.
[0179] For example, on the text configuration page, the user can specify the pending tasks (such as news headline generation tasks) and configure the task input text (such as uploading event content). At this time, a text generation request for executing the news headline generation task can be generated based on the task identifier and task input text of the specified pending task.
[0180] S206, among the multiple text generation tasks associated with the first text generation model, searching for a text generation task that matches the target task identifier, determining the found text generation task as the target text generation task, and using the task adaptation parameter corresponding to the target text generation task as the first task adaptation parameter to be activated. The specific implementation of step S206 can be found in the relevant description of the above embodiment, which will not be described in detail here.
[0181] S207 . When injecting the first task adaptation parameter into the first text generation model, the first task adaptation parameter is activated to obtain a second text generation model after adjusting the parameters of the first text generation model.
[0182] Among them, the first task adaptation parameters that are not masked and waiting to be activated can be injected into the corresponding network layer of the first text generation model to obtain a second text generation model, which includes the original parameters in the first text generation model and the first task adaptation parameters.
[0183] For example, the first text generation model includes a first decoding layer to be parameter adjusted; the first decoding layer includes a first decoding weight matrix; the first task adaptation parameter includes an adaptation weight matrix corresponding to the first decoding weight matrix. That is, the first task adaptation parameter is obtained by optimizing the task training parameters determined by the first decoding weight matrix.
[0184] The first decoding layer may be one or more, and one first decoding layer is taken as an example here. The first decoding weight matrix that has been fine-tuned in the first decoding layer may be one or more, and one first decoding weight matrix is taken as an example here. The adaptation weight matrix corresponding to the first decoding weight matrix is the optimization parameter obtained when the first decoding weight matrix is fine-tuned.
[0185] At this time, injecting the first task adaptation parameters into the first text generation model can be, when the adaptation weight matrix is injected into the first decoding layer and the adaptation weight matrix is activated, using the weight matrix including the first decoding weight matrix and the adaptation weight matrix as the new first decoding weight matrix, that is, the second decoding weight matrix corresponding to the first decoding weight matrix.
[0186] In this way, the first decoding layer including the second decoding weight matrix can be determined as a new first decoding layer, that is, the second decoding layer corresponding to the first decoding layer, and the first text generation model including the second decoding layer can be used as the second text generation model.
[0187] The adaptation weight matrix is used to guide the decoding result of the second decoding weight matrix so that the output result of the second text generation model can meet the target text generation task.
[0188] The principle of generating text in the second text generation model is the same as the principle of generating text in the first text generation model. Only when the text is generated by the second decoding weight matrix, the text is generated by the first decoding weight matrix and by the adaptation weight matrix.
[0189] S208: When a prompt template text matching the target text generation task is obtained, the second text generation model is guided according to the prompt template text to generate a task output text corresponding to the task input text.
[0190] The task prompt text may be constructed by using the prompt template text and the task input text, so that the second text generation model generates the task output text corresponding to the task input text based on the task prompt text.
[0191] Among them, taking the first decoding feature as an example, in the second text generation model, during the decoding process, the decoding feature that needs to be decoded by the second decoding weight matrix is the first decoding feature, and the second decoding weight matrix is used to decode the first decoding feature; the first decoding feature is obtained in the second text generation model based on the prompt template text.
[0192] For example, in the process of the second text generation model decoding the task output text corresponding to the prompt template text to obtain the task output text, decoding processing between multiple decoding layers in the second text generation model is involved, such as the output result of the decoding processing of the previous decoding layer is the input feature used by the next decoding layer for decoding processing.
[0193] Therefore, the first decoding feature can be obtained based on the output result of the previous decoding layer located at the second decoding layer. If the output result of the previous decoding layer is input to the second decoding layer, the intermediate decoding feature when the second decoding layer performs decoding processing will pass through the second decoding weight matrix and be processed by the second decoding weight matrix. At this time, the intermediate decoding feature can be the first decoding feature.
[0194] Therefore, the decoding process in the second text generation model can be: decoding the first decoding feature through the first decoding weight matrix in the second decoding weight matrix to obtain the first transition decoding feature; decoding the first decoding feature through the adaptation weight matrix in the second decoding weight matrix to obtain the second transition decoding feature; determining the sum of the features between the first transition decoding feature and the second transition decoding feature as the second decoding feature; and in the second text generation model, generating the task output text based on the second decoding feature.
[0195] The second decoding feature is an intermediate decoding feature obtained by the second decoding weight matrix, and the second decoding layer continues to decode the intermediate decoding feature to obtain the output result of the second decoding layer. The output result of the second decoding layer can continue to be decoded in the second text generation model (such as input to the next decoding layer).
[0196] Among them, taking the first decoding weight matrix as an example, the adaptation weight matrix corresponding to the first decoding weight matrix may include the first transition weight matrix and the second transition weight matrix obtained by performing parameter optimization in the above manner.
[0197] At this time, the first decoding feature can be decoded by using the product matrix between the first transition weight matrix and the second transition weight matrix (the matrix dimension is the same as the first decoding weight matrix, so the decoding processing principle is the same).
[0198] For example, Figure 8 As shown, Figure 8 A schematic diagram of another parameter injection scenario provided for an embodiment of the present application; wherein, the first text generation model includes a first decoding layer, the first decoding layer includes a first decoding weight matrix (weight matrix c81), and the task adaptation parameters include an adaptation weight matrix corresponding to the first decoding weight matrix (such as the first transition weight matrix (weight matrix c82) and the second transition weight matrix (weight matrix c83) obtained by decomposition).
[0199] Among them, the first transition weight matrix and the second transition weight matrix can be injected into the first decoding layer in the first text generation model to obtain a second decoding layer, which includes a second decoding weight matrix (weight matrix c84), and the second decoding weight matrix includes the first decoding weight matrix, the first transition weight matrix and the second transition weight matrix.
[0200] When the first decoding feature 80a is input into the second decoding weight matrix, the first decoding feature is decoded by the first decoding weight matrix to obtain the first transition decoding feature, and the first transition weight matrix and the second transition weight matrix are used to decode the first decoding feature to obtain the second transition decoding feature.
[0201] The first decoding feature may be decoded by determining a product matrix between the first transition weight matrix and the second transition weight matrix, wherein the matrix dimension of the product matrix is the same as the matrix dimension of the first decoding weight matrix.
[0202] The sum of the first transition decoding feature and the second transition decoding feature is used as the second decoding feature 80b outputted by the second decoding weight matrix.
[0203] Optionally, the training framework for fine-tuning parameters to obtain task adaptation parameters through text generation model can be built based on the open source LLM fine-tuning project (such as LLaMA-Factory project), which can support LoRA fine-tuning on GPU (graphics processing unit) or NPU (Neural Processing Unit). Support the effect detection and evaluation of the model training process.
[0204] For example, Figure 9-10 As shown, Figure 9-10 A scenario diagram of a training architecture provided in an embodiment of the present application; wherein, Fig. 9 In the process, the task-specific data can be naturalized through prompt word engineering, and then the local model parameter tuning for the specific task can be performed.
[0205] For example, multiple sample task input texts may be constructed for a specified text generation task, and the prompt word engineering may construct a sample task prompt text corresponding to each sample task input text according to the matched prompt template text.
[0206] The task training parameters of the text generation task can be injected into the first text generation model. The specific usage description of the task training parameters can be found in Figure 8 A description of the example.
[0207] For example, the first text generation model may include a first decoding layer to be parameter adjusted, and the first decoding layer may include a first decoding weight matrix (weight matrix c91) for matrix decomposition when fine-tuning the parameters. Then the task adaptation parameter may include an adaptation weight matrix corresponding to the first decoding weight matrix (such as the first transition weight matrix c92 (such as Figure 8 The weight matrix c82 shown in the example) and the second transition weight matrix c93 (such as Figure 8 The weight matrix c83 is shown in the example.
[0208] The first transition weight matrix and the second transition weight matrix can be injected into the first decoding layer in the first text generation model to obtain a second decoding layer, which includes a second decoding weight matrix (weight matrix c94, such as Figure 8 The illustrated weight matrix c84), the second decoding weight matrix includes the first decoding weight matrix, the first transition weight matrix and the second transition weight matrix.
[0209] When the first decoding feature 90a that needs to be decoded by the second decoding weight matrix is obtained, the decoding process is performed by the first decoding weight matrix and the adaptation weight matrix respectively. For example, the first decoding feature is decoded by the first decoding weight matrix to obtain the first transition decoding feature, and the first decoding feature is decoded by the first transition weight matrix and the second transition weight matrix to obtain the second transition decoding feature.
[0210] The sum of the first transition decoding feature and the second transition decoding feature is used as the second decoding feature 90b outputted by the second decoding weight matrix.
[0211] Optionally, when the sample task prompt text input is injected into the first text generation model with task training parameters, the segmentation vector of each text segmentation (i.e., token, such as text segmentation w91, text segmentation w92,..., text segmentation w9n) in the sample task prompt text can be obtained first, and then the segmentation vector can be decoded using the decoding layer in the first text generation model to predict the output of the corresponding task output text.
[0212] Among them, the word segmentation vector of a text segmentation may include the embedding vector of the text segmentation (such as the embedding vector e91 corresponding to the text segmentation w91, the embedding vector e92 corresponding to the text segmentation w92,..., the embedding vector e9n corresponding to the text segmentation w9n), the position vector (such as the position vector r91 corresponding to the text segmentation w91, the position vector r92 corresponding to the text segmentation w92,..., the position vector r9n corresponding to the text segmentation w9n), the noise vector (such as the noise vector n91 corresponding to the text segmentation w91, the noise vector n92 corresponding to the text segmentation w92,..., the noise vector n9n corresponding to the text segmentation w9n), and the like.
[0213] Optionally, during the process of optimizing the task training parameters, the parameter optimization can be paused, and the effect of the first text generation model currently injected with the task training parameters can be tested using a test set, so as to determine the task training parameters after parameter optimization based on the test effect.
[0214] For example, after using a certain number of training sets for parameter optimization, the test set is used to view the current text generation effect for the text generation task (i.e., view the output text of the test task, such as the generated news headline). If the text generation effect indicates that the training effect is not satisfactory, then a certain number of training sets are used again for parameter optimization, and the test set is used again to view the current text generation effect for the text generation task until the text generation effect indicates that the training effect is satisfactory. At this time, the task training parameters after the current parameter optimization can be used as the task adaptation parameters.
[0215] exist Fig.10In the prompt word project, prompt template texts of multiple text generation tasks (such as task a101, task a102, ..., task a10n) can be constructed. When sample task input texts for each text generation task are constructed respectively (wherein, one text generation task can have multiple sample task input texts), sample task prompt texts corresponding to each sample task input text of each text generation task can be generated by the prompt template text of the corresponding text generation task in the prompt word project, and the sample task prompt text and the labeled task output text corresponding to the sample task input text are used to optimize the task training parameters of each text generation task in the first text generation model injected with the task training parameters of the corresponding text generation task, so as to obtain the task adaptation parameters of each text generation task.
[0216] Among them, there can be one or more prompt template texts corresponding to a text generation task. You can select any prompt template text from them and generate a sample task prompt text with the sample task input text, or you can generate multiple sample task prompt texts for each prompt template text (in this case, one sample task prompt text can correspond to one annotation task output text, or they can all correspond to the same annotation task output text).
[0217] Among them, for a text generation task (such as task a101), the task training parameters of task a101 are injected into the first text generation model to obtain the sample task output text corresponding to the sample task input text of task a101, and the sample task output text corresponding to the sample task input text of task a101 and the labeled task output text corresponding to the sample task input text of task a101 are used to optimize the task training parameters of task a101 to obtain the task adaptation parameters of task a101.
[0218] Among them, the task adaptation parameters of each text generation task can be injected into the first text generation model or removed from the first text generation model at any time.
[0219] For example, a text generation task can be an event discovery task, such as generating event descriptions or concise event titles, structured information, etc. based on the content of hot events in online graphics, texts, and videos, so that users can quickly understand the content of the event.
[0220] At this time, the task input text of the event discovery task can be the content of hot events in network graphics and videos, and the task output text can be the event description or event title, etc. The prompt template text of the event discovery task can be constructed through the prompt word engineering, and the task adaptation parameters of the event discovery task can be obtained through parameter fine-tuning technology training.
[0221] For example, a text generation task can be a summary generation task, such as compressing a long text into a short summary text that retains key information, which can help users quickly obtain information.
[0222] At this time, the task input text of the summary generation task can be the acquired long text, and the task output text can be the summary text, etc. The prompt template text of the summary generation task can be constructed through the prompt word engineering, and the task adaptation parameters of the summary generation task can be obtained through parameter fine-tuning technology training.
[0223] For example, a text generation task can be a comment generation task, such as generating comment texts with different emotions and positions based on different news content to improve the friendliness and activity of the comment area.
[0224] At this time, the task input text of the comment generation task can be the acquired news content, and the task output text can be the comment text, etc. The prompt template text of the comment generation task can be constructed through the prompt word engineering, and the task adaptation parameters of the comment generation task can be obtained through parameter fine-tuning technology training.
[0225] For example, a text generation task can be a social media copy generation task, such as generating social media copy of different styles according to user needs, such as attractive titles, interesting comments, etc.
[0226] At this time, the task input text of the social media copywriting generation task can be user needs, and the task output text can be social media copywriting, etc. The prompt template text of the social media copywriting generation task can be constructed through prompt word engineering, and the task adaptation parameters of the social media copywriting generation task can be obtained through parameter fine-tuning technology training.
[0227] For example, the text generation task may be an advertising copy generation task, such as generating concise, accurate, and attractive advertising copy based on product features to improve advertising effectiveness.
[0228] At this time, the task input text of the advertising copy generation task can be product features, and the task output text can be advertising copy, etc. The prompt template text of the advertising copy generation task can be constructed through the prompt word engineering, and the task adaptation parameters of the advertising copy generation task can be obtained through parameter fine-tuning technology training.
[0229] For example, a text generation task may be a search term generation task, such as being used to generate accurate search terms based on event content to improve the user's search efficiency for the event content.
[0230] For example, in the search term generation task, a variety of different types of search terms (such as factual, knowledge, and extended, etc.) can be generated based on the text generation model, which can enrich the number and types of search terms that can be distributed in the search scenario.
[0231] For example, in a news search carousel word scenario (such as a carousel search term) or a video stream related search scenario (such as displaying related search terms), the search terms generated by introducing the text generation model architecture proposed in the technical solution of the present application can not only increase the supply quantity by several times, but also significantly improve the business revenue, average search page views, website visits, search term clicks, and search term conversion rate.
[0232] For example, Fig.11 As shown, Fig.11 A schematic diagram of a scenario of a model application provided for an embodiment of the present application; wherein, in order to achieve unified processing of multi-style text generation tasks, a multi-LoRA deployment solution for a large language model can be adopted, that is, task adaptation parameters (LoRA parameters) of multiple text generation tasks (such as task a111, task a112, ..., task a11n) are obtained through LoRA fine-tuning.
[0233] Among them, the routing mechanism can select the task adaptation parameters that match the text generation task (such as task a111) corresponding to the current target task identifier from the LoRA parameters (i.e., task adaptation parameters) of different text generation tasks according to the target task identifier of the task to be processed, inject the large language model (first text generation model), and activate the injected task adaptation parameters to obtain the large language model (second text generation model) for the text generation task corresponding to the target task identifier.
[0234] Subsequently, the second text generation model performs reasoning for text generation for task a111, which can effectively avoid interference between task adaptation parameters of different text generation tasks and improve the reasoning efficiency and generation effect of the text generation model.
[0235] The routing mechanism refers to selecting and activating the task adaptation parameters of the text generation task that matches the target task identifier carried in the text generation request, and shielding the task adaptation parameters of other text generation tasks.
[0236] For example, when a text generation request for task a111 (such as a news headline generation task) is received, the routing mechanism will choose to inject the task adaptation parameters of task a111 and activate it, and shield the task adaptation parameters of other text generation tasks, that is, activate the connection line between the task adaptation parameters of task a111 and the first text generation model (the connection line is a solid line at this time, indicating a change from an unactivated state to an activated state), and then form a second text generation model through the first text generation model and the task adaptation parameters connected to the first text generation model by a solid line to execute task a111.
[0237] At this time, the second text generation model can generate and output the corresponding task output text based on the task input text carried in the text generation request (such as the task input text is the content of the news title to be generated, and the task output text is the predicted output news title).
[0238] Specifically, the routing mechanism inputs the target task identifier and the task input text into the prompt word project, generates the prompt template text that matches the task input text according to the text corresponding to the target task identifier, and obtains the task prompt text corresponding to the task input text, and inputs the task prompt text into the second text generation model.
[0239] At this time, the connection line between other text generation tasks and the first text generation model can indicate that the task adaptation parameters of other text generation tasks are in a shielded state, such as the connection line can be represented by a dotted line.
[0240] Among them, after the execution of task a111 is completed, the task adaptation parameters can be removed from the second text generation model, that is, the connection line between the task adaptation parameters of task a111 and the first text generation model is changed from a solid line to a dotted line. At this time, the connection lines between the task adaptation parameters of all text generation tasks and the first text generation model are all dotted lines, indicating that the task adaptation parameters of all current text generation tasks are in a pending activation state, waiting for the next text generation request.
[0241] Among them, this can realize the plug-and-play of task adaptation parameters. The injection and removal operations of task adaptation parameters can be completed dynamically during the reasoning process, realizing the plug-and-play of task adaptation parameters. This method can effectively reduce the cost of model deployment and improve the reliability of the model.
[0242] Therefore, in the technical solution of the present application, a unified model architecture can be implemented. For example, for the first text generation model, a Decoder-only LLM can be used as the base. This no longer limits the input format of the input text for the text generation task, and can unify all text generation tasks into one text generation model, avoiding the cumbersome process of developing multiple adaptive text generation models for different text generation tasks.
[0243] At the same time, flexible text generation task adaptation can be achieved, such as using prompt word engineering and parameter fine-tuning technology to convert different text generation tasks into a unified text generation task, achieving input unification by designing different prompt template texts, and achieving model unification by deploying a plug-and-play architecture of task adaptation parameters for multiple text generation tasks. In this way, the task prompt text obtained from the prompt template text of the text generation task can be used to guide the text generation model to generate text that meets the needs of specific text generation tasks.
[0244] That is, all text generation tasks are unified into a base model. For the adaptive development of different text generation tasks, only some parameters (task adaptation parameters of text generation tasks) need to be fine-tuned, avoiding the tedious process of developing multiple text generation models for different text generation tasks and reducing development costs.
[0245] In addition, since the original parameters in the text generation model have not changed, but only the task adaptation parameters obtained by fine-tuning training are additionally injected, the text generation model still has strong generalization ability and flexibility, so that the basic capabilities of the text generation model are retained while completing specific text generation tasks.
[0246] Among them, an efficient system architecture can be built through decoder-only, prompt word engineering and parameter fine-tuning technology, that is, a complete model system is built, covering data collection and processing, model training, model deployment and online release, etc., to achieve an efficient model development and deployment process.
[0247] Therefore, the technical solution of the present application can provide an efficient and flexible solution for multi-text generation tasks through a unified model architecture, flexible task adaptation and efficient system architecture.
[0248] In an embodiment of the present application, the first text generation model can be adaptively fine-tuned for the text generation task to obtain task adaptation parameters for different text generation tasks, and when the target task identifier of the task to be processed is obtained, the text generation task (target text generation task) that matches the target task identifier is searched to obtain the first task adaptation parameters to be activated, and then the second text generation model for the task to be processed is obtained, and the second text generation model is a text generation model that can implement the task to be processed; at this time, the prompt model text can be used to guide the second text generation model to generate a task output text corresponding to the task input text. The model input form for different text generation tasks can be unified by prompting template text, and the task adaptation parameters trained for each text generation task can be injected into the unified text generation model to obtain a text generation model for each text generation task to achieve the corresponding text generation task. In this way, whenever a new text generation task is added, it is only necessary to train the corresponding task adaptation parameters for injecting into the first text generation model, which realizes the plug-and-play of the task adaptation parameters. Compared with the workload brought by deploying text generation models for multiple text generation tasks, this can reduce the difficulty of model development and model deployment costs under multiple text generation tasks, as well as reduce the difficulty of template maintenance, while improving deployment flexibility and reliability.
[0249] For further information, see Fig.12 , Fig.12 This is a schematic diagram of the structure of a text generation device provided in an embodiment of the present application. Fig.12 As shown, the text generation device 1 can be applied to a computer device. It should be understood that the text generation device 1 can be a computer program (including program code) running in a computer device, for example, the text generation device 1 can be an application software; it can be understood that the text generation device 1 can be used to execute the corresponding steps of the method provided in the embodiment of the present application. Fig.12 As shown, the text generation device 1 may include: a parameter acquisition module 11, a parameter injection module 12, and a text generation module 13. Among them:
[0250] The parameter acquisition module 11 is used to obtain the target task identifier of the task to be processed; the task to be processed refers to a task of generating a task output text corresponding to a task input text through a first text generation model; the first text generation model is a text generation model that can inject multiple task adaptation parameters corresponding to multiple text generation tasks; one text generation task corresponds to one task adaptation parameter;
[0251] The parameter acquisition module 11 is further used to search for a text generation task that matches the target task identifier among multiple text generation tasks associated with the first text generation model, determine the found text generation task as the target text generation task, and use the task adaptation parameter corresponding to the target text generation task as the first task adaptation parameter to be activated;
[0252] A parameter injection module 12 is used to activate the first task adaptation parameter when injecting the first task adaptation parameter into the first text generation model, so as to obtain a second text generation model after adjusting the parameters of the first text generation model;
[0253] The text generation module 13 is used to guide the second text generation model according to the prompt template text to generate a task output text corresponding to the task input text when a prompt template text matching the target text generation task is obtained.
[0254] The first text generation model includes a first decoding layer to be parameter-adjusted; the first decoding layer includes a first decoding weight matrix; the first task adaptation parameter includes an adaptation weight matrix corresponding to the first decoding weight matrix;
[0255] The parameter injection module 12 includes:
[0256] A parameter injection unit 121 is used to inject the adaptation weight matrix into the first decoding layer and activate the adaptation weight matrix, and use the weight matrix including the first decoding weight matrix and the adaptation weight matrix as the second decoding weight matrix corresponding to the first decoding weight matrix;
[0257] The model acquisition unit 122 is used to determine the first decoding layer including the second decoding weight matrix as the second decoding layer, and to use the first text generation model including the second decoding layer as the second text generation model.
[0258] The second decoding weight matrix is used to decode the first decoding feature; the first decoding feature is obtained based on the prompt template text in the second text generation model;
[0259] The text generation module 13 includes:
[0260] A decoding processing unit 131 is used to decode the first decoding feature through the first decoding weight matrix in the second decoding weight matrix to obtain a first transition decoding feature;
[0261] The decoding processing unit 131 is further configured to perform decoding processing on the first decoding feature through the adaptation weight matrix in the second decoding weight matrix to obtain a second transition decoding feature;
[0262] The text generating unit 132 is used to determine the sum of the first transitional decoding feature and the second transitional decoding feature as the second decoding feature;
[0263] The text generation unit 132 is further configured to generate task output text based on the second decoding feature in the second text generation model.
[0264] Wherein, the text generation module 13 includes:
[0265] The text filling unit 133 is used to fill the task input text into the prompt template text to obtain the task prompt text;
[0266] The text generation unit 132 is further configured to input the task prompt text into the second text generation model, and the second text generation model generates the task output text based on the task prompt text.
[0267] Before injecting the first task adaptation parameter into the first text generation model, the parameter acquisition module 11 further includes:
[0268] A parameter masking unit 111, configured to use parameters other than the first task adaptation parameter among the plurality of task adaptation parameters as second task adaptation parameters to be masked;
[0269] The parameter masking unit 111 is further configured to mask the second task adaptation parameter.
[0270] The parameter acquisition module 11 includes:
[0271] A request acquisition unit 112, used to acquire a text generation request associated with a task to be processed;
[0272] The request acquisition unit 112 is further configured to acquire the task input text and the target task identifier of the task to be processed from the text generation request.
[0273] Wherein, any one of the multiple text generation tasks is a sample text generation task;
[0274] The parameter acquisition module 11 also includes:
[0275] A parameter training unit 113, used for the parameter training unit to obtain task training parameters corresponding to the sample text generation task;
[0276] The parameter training unit 113 is further used to activate the task training parameters when injecting the task training parameters into the first text generation model, so as to obtain a transition text generation model after adjusting the parameters of the first text generation model;
[0277] The parameter training unit 113 is used to guide the transition text generation model according to the transition prompt template text to generate a sample task output text corresponding to the sample task input text when the transition prompt template text matching the sample text generation task is obtained;
[0278] The parameter training unit 113 is used to optimize the task training parameters through the sample task output text and the labeled task output text corresponding to the sample task input text, so as to obtain the task adaptation parameters corresponding to the sample text generation task.
[0279] The first text generation model includes a first decoding layer to be parameter-adjusted; the first decoding layer includes a first decoding weight matrix; the task training parameters include a training weight matrix corresponding to the first decoding weight matrix;
[0280] The parameter training unit 113 is specifically used for:
[0281] Decomposing the matrix dimension of the first decoding weight matrix to obtain a first decomposition matrix dimension and a second decomposition matrix dimension;
[0282] The first transition weight matrix corresponding to the first decomposition matrix dimension and the second transition weight matrix corresponding to the second decomposition matrix dimension are used as training weight matrices; the sum of the matrix parameter quantities of the first transition weight matrix and the second transition weight matrix is less than the matrix parameter quantity of the decoding weight matrix.
[0283] The specific implementation of the parameter acquisition module, parameter injection module, and text generation module can be found in the relevant descriptions in the above embodiments, and will not be described in detail here. It should be understood that the description of the beneficial effects obtained by adopting the same method will not be described in detail either.
[0284] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program with a predetermined function, and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories) or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.
[0285] For further information, see Fig.13 , Fig.13 Schematic diagram of the structure of a computer device provided in an embodiment of the present application. Fig.13As shown, the computer device 1400 can be a business terminal or a server, which will not be limited here. For ease of understanding, this application takes the computer device as a server as an example. The computer device 1400 may include: a processor 1401, a network interface 1404 and a memory 1405. In addition, the computer device 1400 may also include: a user interface 1403, and at least one communication bus 1402. Among them, the communication bus 1402 is used to realize the connection and communication between these components. Among them, the user interface 1403 may also include a standard wired interface and a wireless interface. The network interface 1404 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1405 may be a high-speed RAM memory or a non-volatile memory (non-volatile memory), such as at least one disk storage. The memory 1405 may optionally also be at least one storage device located away from the aforementioned processor 1401. As Fig.13 As shown, the memory 1405 as a computer-readable storage medium may include an operating system, a network communication module, a user interface module, and a device control application.
[0286] The network interface 1404 in the computer device 1400 can also provide a network data interaction function. Fig.13 In the computer device 1400 shown in the figure, the network interface 1404 can provide a network data interaction function; the user interface 1403 is mainly used to provide an input interface for the user; and the processor 1401 can be used to call the device control application stored in the memory 1405 to execute the above Figure 3 , Figure 7 The description of the text generation method in the corresponding embodiment can also be performed as described above. Fig.12 The description of the text generation device 1 in the corresponding embodiment will not be repeated here. In addition, the description of the beneficial effects of adopting the same method will not be repeated here.
[0287] In addition, it should be pointed out here that: the embodiment of the present application also provides a computer-readable storage medium, and the computer-readable storage medium stores a computer program executed by the text generation device 1 mentioned above, and the computer program includes a computer program, when the processor executes the computer program, it can execute the above-mentioned Figure 3 , Figure 7The description of the text generation method in the corresponding embodiment will therefore not be repeated here. In addition, the description of the beneficial effects of the same method will not be repeated. For technical details not disclosed in the computer-readable storage medium embodiment involved in this application, please refer to the description of the method embodiment of this application. As an example, the computer program can be deployed on a computing device for execution, or on multiple computing devices located at one location, or on multiple computing devices distributed at multiple locations and interconnected by a communication network. Multiple computing devices distributed at multiple locations and interconnected by a communication network can constitute a blockchain system.
[0288] In addition, it should be noted that: the embodiment of the present application also provides a computer program product, which includes a computer program, and the computer program can be stored in a computer-readable storage medium. The processor of the computer device reads the computer program from the computer-readable storage medium, and the processor can execute the computer program, so that the computer device executes the above Figure 3 , Figure 7 The description of the text generation method in the corresponding embodiment will not be repeated here. In addition, the description of the beneficial effects of adopting the same method will not be repeated. For technical details not disclosed in the computer program product embodiment involved in this application, please refer to the description of the method embodiment of this application.
[0289] It should be noted that, for the above-mentioned various method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that this application is not limited by the order of the actions described, because according to this application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by this application.
[0290] The steps in the method of the embodiment of the present application can be adjusted in order, combined and deleted according to actual needs.
[0291] The modules in the device of the embodiment of the present application can be merged, divided and deleted according to actual needs.
[0292] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing related hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a magnetic disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0293] The above disclosure is only the preferred embodiment of the present application, which certainly cannot be used to limit the scope of rights of the present application. Therefore, equivalent changes made according to the claims of the present application are still within the scope covered by the present application.
Claims
1. A text generation method, characterized in that: The method comprises: Obtaining a target task identifier of a task to be processed; the task to be processed refers to a task of generating a task output text corresponding to a task input text through a first text generation model; the first text generation model is a text generation model that can inject multiple task adaptation parameters corresponding to multiple text generation tasks; one text generation task corresponds to one task adaptation parameter; Searching for a text generation task that matches the target task identifier among the multiple text generation tasks associated with the first text generation model, determining the found text generation task as a target text generation task, and using the task adaptation parameter corresponding to the target text generation task as a first task adaptation parameter to be activated; When injecting the first task adaptation parameter into the first text generation model, activating the first task adaptation parameter to obtain a second text generation model after adjusting the parameters of the first text generation model; When a prompt template text matching the target text generation task is obtained, the second text generation model is guided according to the prompt template text to generate the task output text corresponding to the task input text.
2. The method according to claim 1, characterized in that The first text generation model includes a first decoding layer to be parameter-adjusted; the first decoding layer includes a first decoding weight matrix; the first task adaptation parameter includes an adaptation weight matrix corresponding to the first decoding weight matrix; When injecting the first task adaptation parameter into the first text generation model, activating the first task adaptation parameter to obtain a second text generation model after adjusting the parameters of the first text generation model, includes: When the adaptation weight matrix is injected into the first decoding layer and the adaptation weight matrix is activated, a weight matrix including the first decoding weight matrix and the adaptation weight matrix is used as a second decoding weight matrix corresponding to the first decoding weight matrix; The first decoding layer including the second decoding weight matrix is determined as the second decoding layer, and the first text generation model including the second decoding layer is determined as the second text generation model.
3. The method according to claim 2, characterized in that The second decoding weight matrix is used to perform decoding processing on the first decoding feature; the first decoding feature is obtained in the second text generation model based on the prompt template text; The step of guiding the second text generation model according to the prompt template text to generate the task output text corresponding to the task input text includes: Decoding the first decoding feature by using the first decoding weight matrix in the second decoding weight matrix to obtain a first transition decoding feature; Decoding the first decoding feature by using the adaptation weight matrix in the second decoding weight matrix to obtain a second transition decoding feature; Determine the sum of the first transition decoding feature and the second transition decoding feature as a second decoding feature; In the second text generation model, the task output text is generated based on the second decoding feature.
4. The method according to claim 1, characterized in that The step of guiding the second text generation model according to the prompt template text to generate the task output text corresponding to the task input text includes: Filling the task input text into the prompt template text to obtain the task prompt text; The task prompt text is input into the second text generation model, and the second text generation model generates the task output text based on the task prompt text.
5. The method according to claim 1, characterized in that: Before injecting the first task adaptation parameter into the first text generation model, the method further includes: using parameters other than the first task adaptation parameter among the plurality of task adaptation parameters as second task adaptation parameters to be shielded; The second task adaptation parameter is masked.
6. The method according to claim 1, characterized in that The step of obtaining the target task identifier of the task to be processed includes: Get the text generation request associated with the task to be processed; The task input text and the target task identifier of the task to be processed are obtained from the text generation request.
7. The method according to claim 1, characterized in that Any one of the multiple text generation tasks is a sample text generation task; The method further comprises: Obtaining task training parameters corresponding to the sample text generation task; When injecting the task training parameters into the first text generation model, activating the task training parameters to obtain a transition text generation model after adjusting the parameters of the first text generation model; When a transition prompt template text matching the sample text generation task is obtained, the transition text generation model is guided according to the transition prompt template text to generate a sample task output text corresponding to the sample task input text; The task training parameters are optimized through the sample task output text and the labeled task output text corresponding to the sample task input text to obtain the task adaptation parameters corresponding to the sample text generation task.
8. The method according to claim 7, characterized in that The first text generation model includes a first decoding layer to be parameter-adjusted; the first decoding layer includes a first decoding weight matrix; the task training parameters include a training weight matrix corresponding to the first decoding weight matrix; The step of obtaining task training parameters corresponding to the sample text generation task includes: Decomposing the matrix dimension of the first decoding weight matrix to obtain a first decomposition matrix dimension and a second decomposition matrix dimension; A first transition weight matrix corresponding to the first decomposition matrix dimension and a second transition weight matrix corresponding to the second decomposition matrix dimension are used as the training weight matrices; the sum of the matrix parameter quantities of the first transition weight matrix and the second transition weight matrix is less than the matrix parameter quantity of the decoding weight matrix.
9. A text generation device, characterized in that: The device comprises: A parameter acquisition module, used to obtain a target task identifier of a task to be processed; the task to be processed refers to a task of generating a task output text corresponding to a task input text through a first text generation model; the first text generation model is a text generation model that can inject multiple task adaptation parameters corresponding to multiple text generation tasks; one text generation task corresponds to one task adaptation parameter; The parameter acquisition module is further used to search for a text generation task that matches the target task identifier among the multiple text generation tasks associated with the first text generation model, determine the found text generation task as the target text generation task, and use the task adaptation parameter corresponding to the target text generation task as the first task adaptation parameter to be activated; A parameter injection module, used for activating the first task adaptation parameter when injecting the first task adaptation parameter into the first text generation model, so as to obtain a second text generation model after adjusting the parameters of the first text generation model; The text generation module is used to guide the second text generation model according to the prompt template text to generate the task output text corresponding to the task input text when the prompt template text matching the target text generation task is obtained.
10. A computer device, characterized in that: including memory and processor; The memory is connected to the processor, the memory is used to store a computer program, and the processor is used to call the computer program so that the computer device executes the method according to any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program is suitable for being loaded and executed by a processor, so that a computer device having the processor executes the method according to any one of claims 1 to 8.
12. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 8 when being executed by a processor.