General personalized generation method based on large language model
By introducing learnable personalized representations and style adapters into the large language model, the challenges of large language models in personalized text generation are solved, personalized text generation that matches the user's style is achieved, and the intelligence and personality of the service are improved. degree of ization.
Patent Information
- Application Number
- CN202410722875.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-05
- Publication Date
- 2024-09-27
AI Technical Summary
Existing large language models are difficult to meet the personalized needs of users in terms of personalized text generation. Traditional methods cannot make full use of their advantages and cannot provide text generation that matches the user's personal preferences and style.
A general personalized generation method based on a large language model is designed. Through the cooperation of the learnable personalized representation and the output layer of the large language model, personalized text that is consistent with the training data style is generated. The specific steps include inputting the personalized text data. The embedding layer splices learnable representations to build a personalized generation model, and adjusts the weight of the output layer through the style adapter to achieve personalized text generation.
It realizes the generation of personalized text that is consistent with the user's style, provides more intelligent and personalized services for intelligent assistants, content recommendations and other fields, and improves the effect and degree of personalization of text generation.
Smart Images

Figure CN118708708A
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of natural language processing, and in particular relates to a general personalized generation method based on a large language model. Background Art
[0002] With the continuous advancement of deep learning technology, great progress has been made in the field of natural language processing. Large language models (such as the GPT series) have achieved remarkable performance on various language tasks by pre-training large-scale corpora. Language generation is an important branch of natural language processing, which involves generating new content with grammar and semantics from unstructured data (such as text). The language generation model based on neural networks can generate more fluent and natural text after pre-training on large-scale corpora. With the development of the Internet, personalized services are becoming more and more important. From search engines, social media to recommendation systems, various applications are striving to provide a more personalized user experience. In many application scenarios, text generation models may not meet the personalized needs of users. For example, in the fields of smart assistants, content recommendations, and virtual writing, users often hope that the generated text can match their personal preferences, interests, or styles, so as to provide a more personalized experience.
[0003] Although large language models have powerful language understanding and generation capabilities, how to apply them to the field of personalization remains a challenge. Traditional personalization methods cannot fully utilize the advantages of large language models and meet the needs of personalized generation. Therefore, new methods are needed to achieve universal and personalized text generation to meet the different needs of users and provide more intelligent and personalized services.
[0004] Given the excellent effects and performance of deep pre-training models, we introduce them into personalized generation tasks. In order to better achieve universal and personalized text generation, we need to find a personalized input and output method that fits the characteristics of large language models, and implement a universal personalized generation method that can be used in a variety of application scenarios. Summary of the invention
[0005] In order to solve the problems in the background technology, the present invention provides a general personalized generation method based on a large language model. The purpose of the present invention is to design a style adapter that uses learnable personalized representations to cooperate with the output layer of the original large language model to output personalized text consistent with the style of the training data.
[0006] The technical solution adopted by the present invention is as follows, which specifically comprises the following steps:
[0007] 1. A general personalized generation method based on a large language model, comprising the following steps:
[0008] 1) Input the personalized text data X to be learned into the embedding layer of the large language model to obtain text embedding E;
[0009] 2) Concatenate the text embedding E from step 1) with a set of learnable personalized representations A to obtain a personalized embedding Q;
[0010] 3) Building a personalized generation model structure based on the large language model LLM. The personalized generation model structure includes an LLM layer and an output layer based on a style adapter.
[0011] 4) Training the personalized generation model;
[0012] 5) Input the text T to be processed into the personalized generation model trained in step 4) to continue to generate personalized text Y that is consistent with the style of the training data.
[0013] The step 1) specifically comprises the following steps:
[0014] Each personalized text in the personalized text data to be learned is represented as the following sentence content:
[0015] X={X 1 , X 2 , …, X i}, 1≤i≤Size(X)
[0016] Where X represents the natural language description of the personalized text, X i represents the i-th word;
[0017] The sentence content is input into the Tokenizer of the large language model LLM for word segmentation to obtain Token, and then the Token is input into the embedding layer of the large language model LLM to obtain the following text embedding:
[0018] E={E 1 , E 2 ,…,E i}, 1≤i≤Size(E)
[0019] Among them, E i Represents the text embedding corresponding to the i-th Token after personalized text segmentation.
[0020] The step 2) is specifically as follows:
[0021] Set a fixed-size set of learnable personalized representations A = {A 1 , A 2 , …, A 5}, each vector representation in A has the same dimension size as the embedding element in the text embedding E;
[0022] By connecting the learnable personalized representation A with the text embedding E, we get the personalized embedding Q for training, where Q = {A 1 , A 2 , …, A 5 , E 1 , E 2 , …, E i}, 1≤i≤Size(E).
[0023] The step 3) specifically comprises the following steps:
[0024] 3.1) Input the personalized embedding Q into the LLM layer to obtain the corresponding intermediate representation h = {h 1 ,h 2 ,…,h Size(E)+5};
[0025] In the step 3.1), the LLM layer completes parameter initialization by loading the pre-trained parameters of Llama-2.
[0026] 3.2) Input the output result of the LLM layer into the output layer based on the style adapter to obtain the probability distribution, which specifically includes the following steps:
[0027] 3.2.1) For each decoding step:
[0028] The corresponding style hidden state S is extracted through a simple neural network consisting of two fully connected layers t , the formula is as follows:
[0029] s t =W c (W h h t +b h )+b c
[0030] Among them, s t represents the style hidden state output at step t; W * and b * represents a trainable parameter, * represents any letter; h t represents the intermediate representation of the tth step;
[0031] Among them, each decoding step t will generate a corresponding word
[0032] 3.2.2)Hidden state s of the style t Estimate the style probability distribution P over the entire vocabulary through a feed-forward layer with a Softmax function s (t), the formula is as follows:
[0033] P s (Xt |X <t ; A)=Softmax(W s s t +b s )
[0034] Among them, P s (X t |X <t ; A) represents the style probability distribution output at step t; W s and b s Represents trainable parameters;
[0035] 3.2.3) Set the dynamic gating vector g t Represents the dynamic gating vector of decoding step t, which is set as follows:
[0036] g t =Sigmoid(W r (s′ t +h′ t )+b r )
[0037] Among them, s′ t =Relu(W g P s (X t |X <t ; A)+b g ), h′ t =W k h t +b k ;
[0038] 3.2.4) h passes through the linear layer and Softmax function of LLM to obtain the original probability distribution P based on LLM output o (X t |X <t ; A), through the style probability distribution obtained in step 3.2.2) and the dynamic gating vector in step 3.2.3), the final probability distribution is obtained according to the following formula:
[0039] P(X t |X <t ; A) = g t *P s (X t |X <t ; A)+(1-g t )*P o (X t |X <t ; A).
[0040] The step 4) is specifically as follows:
[0041] According to the operations of step 1) and step 2), the personalized embedding Q is obtained through the input layer of the model, and the personalized generation model constructed in step 3) is trained. Most of the weights of LLM are frozen, and only the output layer of LLM and the style adapter of the learnable personalized representation and personalized generation model are trained; the negative log-likehood function is selected as the final loss function:
[0042]
[0043] Error back propagation is used to adjust the weights and biases of the personalized generation model; the neural network model parameters are selected according to the loss function of the model during training, and a set of parameters corresponding to the minimum loss function is used as the parameters of the unified model.
[0044] The step 5) is specifically as follows:
[0045] Input the input text T into the personalized generative model trained in step 4), obtain the personalized embedding Q according to steps 1) and 2), input the personalized embedding into the personalized generative model, and obtain the probability distribution P(X) of predicting the next word through the LLM layer and the output layer based on the style adapter. t |X <t ; A), take the word with the highest probability of occurrence as the predicted word Y 1 ; Add the predicted word to the end of the input text, return to step 1), and predict the next word based on the new input text loop, and stop when the word with the highest probability of appearing is the preset stop word '', and finally obtain the continued personalized text Y, whose style is consistent with the training data.
[0046] 2. A general personalized generation device based on a large language model, comprising:
[0047] A data processing module, for converting personalized text data into a personalized embedding consisting of a concatenation of a text embedding and a learnable personalized representation;
[0048] Model building module, which builds a personalized generative model structure based on the large language model LLM;
[0049] The personalized text generation module continues the input text according to the trained personalized generation model to generate personalized text consistent with the style of the training data.
[0050] 3. A terminal
[0051] The terminal includes a memory, a processor, and a personalized text generation program stored in the memory and executable on the processor. When the processor executes the personalized text generation program, the general personalized generation method based on the large language model is implemented.
[0052] 4. A computer-readable storage medium
[0053] The computer-readable storage medium stores a personalized text generation program, and when the personalized text generation program is executed by the processor, the above-mentioned general personalized generation method based on the large language model is implemented.
[0054] Beneficial effects of the present invention:
[0055] The present invention provides a general personalized generation method based on a large language model, which helps generate personalized text consistent with style requirements by combining a stylized adapter with the original output layer of the large model, and provides an effective method for the needs of personalized generation in various fields and scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] Figure 1 is a flow chart of the present invention;
[0057] Figure 2 It is a basic structural diagram of the Personalized-generation model of the present invention. DETAILED DESCRIPTION
[0058] The present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.
[0059] like Figure 1 As shown, a general personalized generation method based on a large language model of the present invention comprises the following steps:
[0060] Step 1): Each personalized text of the personalized text data to be learned is represented as a sentence content X = {X 1 , X 2 , …, X i}, 1≤i≤Size(X), input it into the LLM Tokenizer for word segmentation, and input it into the LLM embedding layer to get the text embedding E={E 1 , E 2 , …, E i}, 1≤i≤Size(E).
[0061] The step 2) specifically comprises the following steps:
[0062] Set a fixed-size set of learnable personalized representations A = {A 1 , A 2 , …, A 5}, each vector representation in P has the same dimension size as the embedding element in the text embedding E. We obtain the personalized embedding Q for training by connecting the learnable personalized representation P with the text embedding E, where Q = {A1 , A 2 , …, A 5 , E 1 , E 2 ,…,E i}, 1≤i≤Size(E).
[0063] like Figure 1 "Training" is shown in the figure. The sentence content is: How to manage time effectively? Install a "filter" on time, leaving only important things and letting trivial things slip away like sand. The personalized goal is a metaphorical text answer.
[0064] Step 3): Build Figure 2 The Personalized-generation model described above; constructing a model structure based on a large language model LLM, wherein the Personalized-generation model structure includes an LLM layer and an output layer based on a style adapter;
[0065] 3.1) The LLM layer completes parameter initialization by loading the published Llama-2 pre-training parameters;
[0066] 3.2) The output layer based on the style adapter is as follows Figure 2 As shown, the following steps are included:
[0067] 3.2.1) Input the personalized embedding Q into the decoding layer of LLM to obtain the corresponding intermediate representation = {h 1 ,h 2 ,…,h Size(E)+5}.
[0068] 3.2.2) At each decoding step t, a simple neural network consisting of two fully connected layers is used to extract the corresponding style hidden state S t , the formula is as follows:
[0069] s t =W c (W h h t +b h )+b c , where s t W represents the style hidden state output at step t. * and b * Represents the trainable parameters in .
[0070] 3.2.3) The obtained style hidden state s t The style probability distribution over the entire vocabulary is estimated through a feed-forward layer with a Softmax function, as follows:
[0071] P s(X t |X <t ; A)=Softmax(W s s t +b s ), where P s (x t |x <t ; A) represents the style probability distribution output at step t. W s and b s Represents the trainable parameters in .
[0072] 3.2.4) Set the dynamic gating vector g t Represents the dynamic gating vector of decoding step t, which is set as follows:
[0073] s′ t =Relu(W g P s (X t |X <t ; A)+b g ),
[0074] h′ t =W k h t +b k ,
[0075] g t =Sigmoid(W r (s′ t +h′ t )+b r );
[0076] 3.2.5) Based on the original probability distribution P output by LLM o (x t |x <t ; A), through the style probability distribution obtained in step 3.2.3) and the dynamic gating vector in step 3.2.4), the final probability distribution is obtained according to the following formula:
[0077] P(X t |X <t ; A) = g t *P s (X t |X <t ; A)+(1-g t )*P o (X t |X <t ; A)
[0078] Step 4): Figure 1As shown, according to step 1) and step 2), the personalized embedding Q is obtained through the input layer of the model, and the Personalized-generation model constructed in step 3) is trained. Figure 2 As shown in "Tuned" and "Frozen", most of the weights of LLM are frozen, and only the output layer of LLM and the learnable personalized representation and style adapter of the model are trained. The negative log-likehood function is selected as the final loss function:
[0079]
[0080] Error back propagation is used to adjust the weights and biases of the unified model; the neural network model parameters are selected according to the loss function of the model during training, and a set of parameters corresponding to the minimum loss function is used as the parameters of the unified model.
[0081] Step 5): Figure 1 As shown in the “Inference” of the figure, the Personalized-generation model trained in step 4) is used to obtain the personalized embedding Q based on the input text X according to steps 1) and 2). The personalized embedding is input into the Personalized-generation model, and the probability distribution P(X) of the next word is obtained through the LLM layer and the output layer based on the style adapter. t |X <t ; A), take the word with the highest probability of occurrence as the predicted word Y 1 . Add the predicted word to the end of the input text, and continue to predict the next word with the highest probability of appearing as the preset stop word '', and finally obtain the continued personalized text Y, whose style is consistent with the training data.
[0082] like Figure 1 As shown in the “Inference” in the figure, the input text is: “How to improve team collaboration efficiency?” The model finally outputs a metaphorical personalized text that is consistent with the training style: “Team collaboration is like a puzzle. Find the position of each puzzle piece and work together to create a successful panorama.”
[0083] The effect of this method on the personalized dataset based on the Chinese corpus is as follows:
[0084] Personalized approach BLEU-4 Rouge-1 Rouge-2 DAPT 0.5068 0.2614 0.1398 Prefix-Tuning 0.4389 0.3516 0.2034 Model of the present invention 0.5710 0.4073 0.2851
[0085] Note:
[0086] (1) DAPT and Prefix-Tuning are commonly used personalized algorithm models;
[0087] (2) BLEU-4: BLEU-4∈[0,1], the larger the value, the better the personalization effect;
[0088] (3) Rouge-1: NMI∈[0,1], the larger the value, the better the personalization effect;
[0089] (4) Rouge-2: FMI∈[0,1], the larger the value, the better the personalization effect;
[0090] (5) Compared with DAPT, the BLEU-4, Rouge-1, and Rouge-2 indicators of the present invention on the same dataset are improved by 6.42%, 14.59%, and 14.53%, respectively;
[0091] (6) Compared with Prefix-Tuning, the BLEU-4, Rouge-1, and Rouge-2 indicators of the present invention on the same dataset are improved by 13.21%, 5.57%, and 8.17%, respectively.
Claims
1. A general personalized generation method based on a large language model, characterized in that: The following steps are involved: 1) Input the personalized text data X to be learned into the embedding layer of the large language model to obtain text embedding E; 2) Concatenate the text embedding E from step 1) with a set of learnable personalized representations A to obtain a personalized embedding Q; 3) Building a personalized generative model structure based on the large language model LLM, which includes an LLM layer and an output layer based on a style adapter; 4) Training the personalized generation model; 5) Input the text T to be processed into the personalized generation model trained in step 4) to continue to generate personalized text Y that is consistent with the style of the training data.
2. The general personalized generation method based on a large language model according to claim 1, characterized in that: The step 1) specifically comprises the following steps: Each personalized text in the personalized text data to be learned is represented as the following sentence content: X={X1,X2,...,X i },1≤i≤Size(X) Where X represents the natural language description of the personalized text, X i represents the i-th word; The sentence content is input into the Tokenizer of the large language model LLM for word segmentation to obtain Token, and then the Token is input into the embedding layer of the large language model LLM to obtain the following text embedding: E={E1,E2,...,E i },1≤i≤Subject(E) Among them, E i Represents the text embedding corresponding to the i-th Token after personalized text segmentation.
3. The general personalized generation method based on a large language model according to claim 1, characterized in that: The step 2) is specifically as follows: Set a set of fixed-size learnable personalized representations A = {A1, A2, ..., A5}, where each vector representation in A has the same dimension size as the embedding element in the text embedding E; By connecting the learnable personalized representation A with the text embedding E, we get the personalized embedding Q for training, where Q = {A1, A2, …, A5, E1, E2, …, E i }, 1≤i≤Size(E).
4. The general personalized generation method based on a large language model according to claim 1, characterized in that: The step 3) specifically comprises the following steps: 3.1) Input the personalized embedding Q into the LLM layer to obtain the corresponding intermediate representation h = {h1, h2, ..., h Size(E)+5 }; 3.2) Input the output result of the LLM layer into the output layer based on the style adapter to obtain the probability distribution, which specifically includes the following steps: 3.2.1) For each decoding step: The corresponding style hidden state S is extracted through a simple neural network consisting of two fully connected layers t , the formula is as follows: s t =W c (W h h t +b h )+b c Among them, s t represents the style hidden state output at step t; W * and b * represents a trainable parameter, * represents any letter; h t represents the intermediate representation of the tth step; Among them, each decoding step t will generate a corresponding word 3.2.2)Hidden state s of the style t Estimate the style probability distribution P over the entire vocabulary through a feed-forward layer with a Softmax function s (t), the formula is as follows: P s (X t |X <t ;A)=Softmax(W s s t +b s ) Among them, P s (X t |X <t ; A) represents the style probability distribution output at step t; W s and b s Represents trainable parameters; 3.2.3) Set the dynamic gating vector g t Represents the dynamic gating vector of decoding step t, which is set as follows: g t =Sigmoid(W r (s′ t +h′ t )+b r ) Among them, s′ t =Relu(W g P s (X t |X <t ; A)+b g ), h′ t =W k h t +b k ; 3.2.4) h passes through the linear layer and Softmax function of LLM to obtain the original probability distribution P based on LLM output o (X t |X <t ; A), through the style probability distribution obtained in step 3.2.2) and the dynamic gating vector in step 3.2.3), the final probability distribution is obtained according to the following formula: P(X t |X <t ;A)=g t *P s (X t |X <t ;A)+(1-g t )*P o (X t |X <t ;A)。 5. A general personalized generation method based on a large language model according to claim 4, characterized in that: In the step 3.1): The LLM layer completes parameter initialization by loading the pre-trained parameters of Llama-2.
6. A general personalized generation method based on a large language model according to claim 4, characterized in that: The step 4) is specifically as follows: According to the operations of step 1) and step 2), the personalized embedding Q is obtained through the input layer of the model, and the personalized generation model constructed in step 3) is trained, and most of the weights of the LLM are frozen. Only the output layer of the LLM and the style adapter of the learnable personalized representation and the personalized generation model are trained; Select the negative log-likehood function as the final loss function: Error back propagation is used to adjust the weights and biases of the personalized generation model; the neural network model parameters are selected according to the loss function of the model during training, and a set of parameters corresponding to the minimum loss function is used as the parameters of the unified model.
7. A general personalized generation method based on a large language model according to claim 5, characterized in that: The step 5) is specifically as follows: Input the input text T into the personalized generative model trained in step 4), obtain the personalized embedding Q according to steps 1) and 2), input the personalized embedding into the personalized generative model, and obtain the probability distribution P(X) of predicting the next word through the LLM layer and the output layer based on the style adapter. t |X <t ; A), take the word with the highest probability of occurrence as the predicted word Y1; add the predicted word to the end of the input text, return to step 1), and predict the next word based on the new input text loop, and stop when the word with the highest probability of occurrence is the preset stop word, and finally obtain the continued personalized text Y, whose style is consistent with the training data.
8. A general personalized generation device based on a large language model, characterized in that: include: A data processing module, for converting personalized text data into a personalized embedding consisting of a concatenation of a text embedding and a learnable personalized representation; Model building module, which builds a personalized generative model structure based on the large language model LLM; The personalized text generation module continues the input text according to the trained personalized generation model to generate personalized text consistent with the style of the training data.
9. A terminal, characterized in that: The terminal includes a memory, a processor, and a personalized text generation program stored in the memory and executable on the processor. When the processor executes the personalized text generation program, the general personalized generation method based on a large language model as described in any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a personalized text generation program, and when the personalized text generation program is executed by the processor, the general personalized generation method based on a large language model as described in any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Generation method and device of Chinese universal language, equipment and storage medium
CN116151194A
Personalized news title generation method based on user preference
CN116186420A
Text generation method and device, model training method and device and electronic equipment
CN117540703A
Knowledge graph and personalized learning path construction method and system
CN117952200A
Large language model generation text detection method combining feature engineering and neural network
CN118093800A
