A personalized prompt optimization method, device, electronic device and storage medium
Through the MDP model of distributed agents and MARL models under the CTDE paradigm, prompts are dynamically adjusted to solve the problem that prompts in existing recommendation systems cannot capture users' personalized preferences, achieve efficient personalized recommendation effects, and reduce computational costs. Resource and labor costs.
Patent Information
- Application Number
- CN202410780615.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-18
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2044-06-18
AI Technical Summary
In existing recommendation systems, prompts are at the task level and cannot fully capture users' personalized preferences, resulting in poor model recommendation results. Moreover, existing optimization methods rely on manual design or heuristic construction, which consumes a lot of labor and computing resources.
Distributed agents and MARL models are used to construct an MDP model under the CTDE paradigm, and the Actor-Critic algorithm is used to dynamically adjust prompts. Based on user feedback and recommended item update strategies, the quality of prompts and recommendation effects are gradually improved.
It achieves automatic iterative optimization of personalized prompts, improves the recommendation effect of the recommendation system, reduces computing resource consumption and labor input, and is suitable for large-scale user personalized recommendation scenarios.
Smart Images

Figure CN118350378B
Abstract
Description
Technical Field
[0001] The present application relates to the field of recommendation tasks of large language models, and specifically to a personalized prompt optimization method, device, electronic device and storage medium. Background Art
[0002] Recommendation systems can recommend items that are consistent with users' personalized preferences, improve user experience and satisfaction in massive data, and have been widely used in real life. Recently, large language models have demonstrated excellent semantic understanding, intent reasoning, and knowledge utilization capabilities, opening up new dimensions and possibilities for user interest analysis. Therefore, user behavior (clicks, browsing, page dwell time, mouse movement trajectory, etc.) can be modeled as natural language, so that large models can be used to make personalized recommendations for users.
[0003] Since large models are driven by prompts, releasing the model's potential recommendation capabilities requires the model to be able to design or select appropriate prompt text based on user characteristics, historical behavior, preferences, and other information; therefore, although the prompts start with user input or a template pre-set by the model for the user, in advanced personalized recommendation scenarios, the model needs to use user behavior and machine learning algorithms to optimize the prompts to ensure that the model can capture user preferences. In other words, releasing the model's potential recommendation capabilities requires the model to carefully customize the prompts.
[0004] The existing prompts in this field are basically task-level prompts, that is, all users in the same task share the same prompt template.
[0005] Most of these task-level prompts include several components: "role-playing", "history", "step-by-step guidance" and "output restrictions". However, these fixed and identical prompt templates ignore the diversity of users, resulting in the model failing to fully capture the personalized preferences of users. Therefore, it is very important to introduce the concept of instance-level prompts for the recommendation task of large models, that is, to optimize different personalized prompts for each user in the task. Existing prompt optimization methods can be divided into two categories: continuous optimization and discrete optimization. At present, the prompts of mainstream large models are discrete natural languages, so continuous optimization is not feasible. Representative discrete prompt optimization methods include manual design and heuristic construction. However, manual design relies on domain experts or researchers to manually create or adjust prompts based on their understanding of the model, task requirements and in-depth analysis of user characteristics, which requires huge labor; heuristic construction relies on experience and rules to automatically or semi-automatically generate prompts. If it is applied to this task, personalized prompts need to be customized for each user, which consumes expensive computing resources. Therefore, it is necessary to design an automatic iterative prompt optimization method to customize personalized prompts at the instance level. Summary of the invention
[0006] This embodiment provides a personalized prompt optimization method, device, electronic device and storage medium, and explores how to automatically iterate and optimize prompts to customize personalized prompts at the instance level.
[0007] In a first aspect, a personalized prompt optimization method is provided, characterized by comprising:
[0008] Using Distributed Agents , obtain the K components of the large model task-level prompt;
[0009] Constructing an MDP model, the MDP model includes K action spaces corresponding to the K components and a shared global state space; the action of the action space is used to represent the natural language of the prompt of the current iteration, and the state of the state space is used to represent the prompt of the current iteration and the recommended item set output by the large model;
[0010] Get the initial state of the MDP model;
[0011] According to the initial state, use the distributed agent From the action space Select the action at the initial moment, generate the prompt at the current moment from the action at the initial moment; use the prompt at the current moment as input, and output the recommended item set at the current moment;
[0012] Encode the prompt at the current moment and the recommended items selected in the recommended item set at the current moment to obtain the prompt representation and the recommended item representation. According to the prompt representation and the recommended item representation, iterate to obtain the current moment Status ;
[0013] According to the current time Status , using distributed agents From the action space Select Action ; By action Generate the iterated prompt, take the iterated prompt as input, and output the iterated recommended item set; iterate to obtain the state at the next moment according to the iterated prompt and the recommended items selected in the iterated recommended item set;
[0014] According to the state at the next moment, select the action at the next moment, calculate the probability of the action at the next moment, and the value of the state at the next moment;
[0015] Determine the reward based on the selected recommended item ; According to the reward And the value of the state at the next moment, get the cumulative reward ;According to the accumulated rewards , and get the first loss function of the Actor-Critic model and the second loss function ; Using the first loss function Maximize the state value at the next moment, using the second loss function Maximize the probability of the action at the next moment. The two loss functions cooperate with each other to maximize the expected cumulative reward of the Actor-Critic model.
[0016] In some of these embodiments, a distributed agent is used , obtain K components of the large model task-level prompt, including: obtaining task-level prompts with a predefined common format, using distributed agents under the centralized training and decentralized execution paradigm , the task-level prompt is disassembled according to the predefined general format to obtain K components.
[0017] In some of the embodiments, obtaining the initial state of the MDP model includes:
[0018] Get User and items ID information;
[0019] According to user and items ID information, get user embedding and item embedding;
[0020] According to the user embedding and item embedding, the state space of the MDP model is initialized to obtain the initial state.
[0021] In some embodiments, the prompt at the current moment and the recommended item selected in the recommended item set at the current moment are encoded to obtain a prompt expression and a recommended item expression, and the prompt expression and the recommended item expression are iteratively obtained according to the prompt expression and the recommended item expression. Status ,include:
[0022] Use the pre-trained language model BERT and the sequence model GRU to encode the prompt at the current moment respectively and the recommended items set at the current moment , expressed as:
[0023]
[0024]
[0025] in, Represents the first in the output recommendation sequence The embedding of items, and They are the prompts for the current moment. and the recommended items set at the current moment Representation.
[0026] In some embodiments, selecting an action at the next moment according to the state at the next moment, calculating the probability of the action at the next moment, and the value of the state at the next moment, includes:
[0027] Using Distributed Agents The Actor neural network formulates a strategy, which is: according to the state , select an action in the action space , and calculate the action Probability ; Using distributed agents The Critic neural network estimates the value of the state, and the estimated value is: calculating the state Value ; The expression for formulating strategy and estimating value is:
[0028]
[0029] in, is the function representation symbol of the kth Actor, It is the function representation symbol of the k-th Critic.
[0030] In some embodiments, a reward is determined based on the recommended item selected. ,include:
[0031] Using the NDCG evaluation index, the recommended item set of the large model at time t Conduct evaluation, output evaluation results, and use the evaluation results as rewards .
[0032] In some of these embodiments, the cumulative reward , the first loss function and the second loss function The expression is:
[0033] .
[0034] Compared with the prior art, the present invention provides a personalized prompt optimization method, which uses the Actor-Critic algorithm under the CTDE paradigm through the MARL model to construct an MDP model that can dynamically adjust the prompts in each interaction in order to achieve the best recommendation effect. The MDP model will continuously try different prompts and update the strategy based on user feedback and recommended items, thereby gradually improving the quality of the prompts and the recommendation effect.
[0035] In a second aspect, the present invention provides a personalized prompt optimization device, comprising:
[0036] The first acquisition module is used to use the distributed agent , obtain the K components of the large model task-level prompt;
[0037] An MDP model construction module is used to construct an MDP model, wherein the MDP model includes K action spaces corresponding to the K components and a shared global state space; the actions in the action space are used to represent the natural language of the prompt of the current iteration, and the state of the state space is used to represent the prompt of the current iteration and the recommended item set output by the large model;
[0038] The second acquisition module acquires the initial state of the MDP model;
[0039] The output module is used to use the distributed agent according to the initial state From the action space Select the action at the initial moment, generate the prompt at the current moment from the action at the initial moment; use the prompt at the current moment as input, and output the recommended item set at the current moment;
[0040] The first iteration module is used to encode the prompt word at the current moment and the recommended item selected in the recommended item set at the current moment to obtain the prompt word representation and the recommended item representation, and iterate to obtain the current moment according to the prompt word representation and the recommended item representation. Status ;
[0041] The second iteration module is used to Status , using distributed agents From the action space Select Action ; By action Generate the iterated prompt, take the iterated prompt as input, and output the iterated recommended item set; iterate to obtain the state at the next moment according to the iterated prompt and the recommended items selected in the iterated recommended item set;
[0042] A calculation module is used to select an action at the next moment according to the state at the next moment, calculate the probability of the action at the next moment, and the value of the state at the next moment;
[0043] An optimization module that determines rewards based on the selected recommended items ; According to the reward And the value of the state at the next moment, get the cumulative reward ;According to the accumulated rewards , and get the first loss function of the Actor-Critic model and the second loss function ; Using the first loss function Evaluate the state at the next moment and use the second loss function The probability of the next action at the next moment maximizes the expected cumulative reward of the Actor-Critic model.
[0044] In a third aspect, the present invention provides an electronic device, comprising a memory and a processor, wherein the memory stores at least one computer executable instruction, and the processor is configured to run the computer executable instruction, and when the computer executable instruction is executed by the processor, a personalized prompt optimization method described in the first aspect is implemented.
[0045] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the method for optimizing personalized prompts described in the first aspect is implemented.
[0046] Compared with the prior art, the beneficial effects of the personalized prompt optimization device, electronic device and storage medium of the present invention are the same as the beneficial effects of the personalized prompt optimization method described above, so they are not repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Figure 1 A step diagram of a personalized prompt optimization method in an embodiment provided by the present invention;
[0048] Figure 2 A flowchart of a personalized prompt optimization method in an embodiment provided by the present invention;
[0049] Figure 3 A schematic diagram of the MDP model described in the embodiment provided by the present invention;
[0050] Figure 4 A schematic diagram of the action space described in the embodiment provided by the present invention;
[0051] Figure 5A schematic diagram of the historical record subspace described in the embodiment provided by the present invention;
[0052] Figure 6 A schematic diagram of the distribution guidance subspace described in the embodiment provided by the present invention;
[0053] Figure 7 A schematic diagram of the output restriction subspace described in the embodiment provided by the present invention;
[0054] Figure 8 A schematic diagram of the role-playing subspace described in the embodiment provided by the present invention;
[0055] Fig. 9 A schematic diagram of a personalized prompt optimization device in an embodiment of the present invention;
[0056] Fig.10 An electronic device diagram of an embodiment of the present invention; DETAILED DESCRIPTION
[0057] First, the prior art and related concepts involved in the background technology and embodiments of the present invention are described:
[0058] First, the prior art and related concepts involved in the background technology and embodiments of the present invention are described:
[0059] Large model: Large language model for recommendation domain.
[0060] Prompt: In a large model, it is an input text that guides the model to generate a specific type of response or perform a specific task. A prompt might be "List five ways to cook pasta."
[0061] Same prompt template: When using a large model to make recommendations for a large number of users, in order to facilitate and better obtain the answer of the large model, the information of each user is fed into a fixed and unified prompt template; using a pre-designed fixed template, the requirements can be described in batches and a unified output can be obtained, so the format of the task-level prompt is a predefined framework.
[0062] Role Play: Instruct the model to role play (have the model simulate a specific type of expert or style).
[0063] History: Refers to a user's past behavior or preferences.
[0064] Step-by-step instructions: Instruct the model on how to complete a task step by step.
[0065] Output constraints: Set the scope or format of the content generated by the model.
[0066] Restricting the search space: When using reinforcement learning methods to generate personalized prompts, it is necessary to constrain or narrow the set of possible solutions (i.e., the search space). This is because in the process of reinforcement learning, the agent needs to explore a large amount of state space to find the optimal strategy, and an overly large search space will lead to an inefficient learning process and consume a lot of computing resources and time.
[0067] CTDE paradigm: (Centralized Training with Decentralized Execution, CTDE), a training paradigm for multi-agent reinforcement learning. In the execution phase, multiple agents are decentralized and independent, and can only make decisions based on their own local parameters. In the training phase, multiple agents share a central controller to optimize their strategies, and the controller can access the information of all agents. This training paradigm can use global information to guide the learning process during training and improve learning efficiency; it maintains the independence of each distributed agent during execution, which facilitates distributed deployment in applications.
[0068] MARL model: (Multi-Agent Reinforcement Learning, MARL), an algorithm or architecture designed to handle learning problems involving multiple interacting agents in a shared environment. In MARL, the goal of each distributed agent is to learn a policy that defines what actions the agent should take in a given state to maximize some long-term reward or return through interaction with the environment and other agents.
[0069] NDCG indicator: Normalized Discounted Cumulative Gain is an evaluation indicator widely used in information retrieval, recommendation systems and other fields to measure the quality of ranking results.
[0070] Actor-Critic model: a reinforcement learning algorithm that combines the value method and the policy gradient method. The "Actor" in this algorithm is responsible for generating actions based on the current state, that is, the policy function πθ(a|s), which determines what action the agent takes. The "Critic" evaluates the pros and cons of taking an action, that is, the value or advantage of this action, usually represented by a value function Vθ(s) or Qθ(s,a), which is used to guide the Actor to update its strategy. The Actor optimizes its action selection based on the feedback provided by the Critic, while the Critic adjusts its value estimate based on the rewards and actual performance of the environment. This architecture allows the algorithm to simultaneously learn "what to do" (determined by the Actor) and "how well it is done" (evaluated by the Critic), thereby achieving efficient learning.
[0071] In an embodiment of the present invention, a personalized prompt optimization method is provided. The method models the automatic iterative optimization process of instance-level personalized prompts as an MDP model. Under the CTDE paradigm, a MARL model is used to construct a specific Actor-Critic model algorithm, and the algorithm is used to iteratively optimize instance-level prompts. Figures 1 to 10 , Figure 1 It is a flow chart of a personalized prompt optimization method of the present invention, and the process includes:
[0072] Step S1: Using Distributed Agents , obtain K components of the large model task-level prompt; specifically, obtain the task-level prompt with a predefined general format, using a distributed agent under the centralized training and decentralized execution paradigm , the task-level prompt is disassembled according to the predefined general format to obtain K components.
[0073] The task-level prompts come from a large model in the recommended domain, such as the task-level prompts of a large model in the movie recommendation domain. The distributed agent refers to a multi-agent reinforcement learning model executed under the centralized training decentralized execution paradigm (CTDE). The task-level prompts are decomposed into K components by the multi-agent reinforcement learning model executed under the centralized training decentralized execution paradigm (CTDE). Furthermore, Representing the corresponding type of the distributed intelligent agent, the K components refer to a general prompt framework pre-defined according to task-level prompts, such as a role-playing part, a history record part, a distribution guidance part and an output restriction part, which is disassembled into K components.
[0074] Step S2: construct an MDP model, which includes K action spaces corresponding to K components and a shared global state space; the actions in the action space are used to represent the natural language of the prompt of the current iteration, and the state of the state space is used to represent the prompt of the current iteration and the recommended item set output by the large model.
[0075] in, , represents the number of agents, K action spaces, namely: role-playing subspace, historical record subspace, distribution guidance subspace and output restriction subspace.
[0076] refer to Figure 3-8 In this embodiment, the automatic iterative optimization process of instance-level personalized prompts is modeled as a Markov decision process (MDP), i.e., an MDP model. Markov decision process is an important concept in the field of reinforcement learning. It is a mathematical framework used to model problems with sequential decision characteristics, in which an agent outputs actions in a series of states and receives rewards based on these actions. The goal is to find a policy that maximizes the total reward obtained by the agent in the long run. The expression of the MDP model is: .in,
[0077] ①State space (States, S), is the state space, It's the state. ; State space represents the set of possible states in the environment, under which the agent makes decisions; illustratively, in this embodiment, the state Contains information about the current prompt and recommended items.
[0078] ②Action Space (Actions, A) is the action space, It's action. ; The action space represents a set of actions or operations that the agent can take to change the state or affect the reward it receives; illustratively, in this embodiment, the action is the natural language that makes up the prompt (e.g., “Role play” for “You are a movie expert”).
[0079] ③Transition Probabilities (T), is the transition function, and the transition probability describes the probability of transitioning to the next state after a given current state and performing an action; illustratively, in this embodiment, yes Action at all times Lead to state arrive Status of the moment The transition probability.
[0080] ④Rewards (R), is the reward function, which describes the feedback the agent gets immediately after performing an action and evaluates the action For example, in this embodiment, Determines the reward after interacting with the large model In order to combine with the recommendation task, the reward Defined as the evaluation of the items recommended by the large model.
[0081] ⑤Discount factor, Is a discount factor that controls the weight of future rewards and immediate rewards in the feedback; that is, it controls the relative importance of future rewards and immediate rewards. It measures the influence of future rewards on current decisions in a multi-step decision-making process.
[0082] For example, the distributed agent The corresponding action space For the prompt There are several possible expressions for the components. This means that the action space (Roleplay subspace) contains several actions , action space It is a number of actions For example, the role-playing subspace may contain the first action "You are a movie expert", the second action "You are a recommendation expert", etc.
[0083] Step S3: Obtain the initial state of the MDP model; specifically:
[0084] Get User and items ID information;
[0085] According to user and items ID information, get user embedding and item embedding;
[0086] According to the user embedding and item embedding, the state space of the MDP model is initialized to obtain the initial state.
[0087] In this embodiment, the shared global state space provides observation results for independent distributed agents, which include prompts and recommended items in the current environment, and the initial state, i.e., the state at the time Status .
[0088] For example, obtaining user and items ID information, which means collecting basic identification information of users and items, such as the unique number of a user account or the database ID of a movie;
[0089] According to user and items The ID information is used to obtain user embedding and item embedding, which means: the user ID and item ID are converted into continuous vector form through a pre-trained or custom embedding model (such as the LightGCN model). User embedding attempts to capture the user's preference characteristics, while item embedding reflects the content attributes of the item or the user's potential interest in it. Through embedding, the originally abstract ID becomes a vector that can be calculated and compared in multi-dimensional space.
[0090] Specifically, for a given user and items After getting the ID information, you can get their embedding:
[0091]
[0092] Among them, u and i are users and items Representation of; Represents the encoder of a traditional recommender system.
[0093] In this embodiment, "items" refer to a class of items or services that users may be interested in, which can be various things such as movies, music, books, commodities, tourist attractions, etc. In the recommendation system, items are usually recommended objects, that is, the system will recommend suitable items to users based on their historical behaviors and preferences. For example, in a movie recommendation system, "items" refer to movies. The system will collect information such as the user's past viewing history, ratings, comments, and the attributes of the movie itself (such as type, director, actors, etc.), and generate a recommendation list through a certain recommendation algorithm (such as LightGCN) to recommend movies that users may be interested in. Therefore, "items" here is a general term, and the specific meaning depends on the actual application scenario.
[0094] Step S4: Based on the initial state, use the distributed agent From the action space Select the action at the initial moment, generate the prompt at the current moment from the action at the initial moment; use the prompt at the current moment as input, and output the recommended item set at the current moment;
[0095] Step S5: Encode the prompt at the current moment and the recommended item selected in the recommended item set at the current moment to obtain the prompt expression and the recommended item expression. According to the prompt expression and the recommended item expression, iterate to obtain the current moment Status ;
[0096] Exemplarily, this embodiment uses the pre-trained language model BERT and the sequence model GRU to encode the prompt at the current moment respectively and the recommended items set at the current moment , expressed as:
[0097]
[0098] in, Represents the first in the output recommendation sequence The embedding of items, and They are the prompts for the current moment. and the recommended items set at the current moment Representation.
[0099] That is to say, after getting the initial state After that, at the current moment In the current iteration, use the prompt Recommended items for large models To update the current time Status .in, is the first in the output recommendation sequence items, is the number of candidate items.
[0100] Therefore, the current moment in the shared global state space Status , which represents the user at the current moment Recommended Items The selection of recommended items and the current time 's prompt.
[0101] Step S6: According to the current time Status , using distributed agents From the action space Select Action ; By action Generate an iterated prompt, take the iterated prompt as input, and output an iterated recommended item set; iterate to obtain the state at the next moment according to the iterated prompt and the recommended items selected in the iterated recommended item set.
[0102] It can be seen that step S4, step S5, and step S6 are actually an iterative process of state update and action decision. After step S5 updates the state, step S6 makes a decision based on the updated state to obtain a new round of prompts. The MDP model uses the prompts generated in the new round as input and outputs a recommended item set. After the user selects a recommended item in the recommended item set, the next round of state iteration will be generated.
[0103] In order to further explain the above steps, it is necessary to further understand the concept of action space and the actions in action space. It is the action space of the MARL model under the CTDE paradigm; in the coarse-grained understanding, the action space of the MARL model can be divided into Independent distributed agents subspaces, each representing a component of the prompt, including “role-playing”, “history”, “step-by-step guidance”, and “output constraints”. The corresponding action space are several possible expressions of this component in the prompt; that is, at a fine-grained level, the agent The corresponding action space Contains several actions The following is an introduction to the K subspaces corresponding to the K agents;
[0104] 1. The “role-playing action subspace” assigns a specific role to the large model to generate responses consistent with its role characteristics. For example, in the movie recommendation task, The actions may include "You are a movie expert", "You are a recommendation expert" or "You are an interest analysis expert", etc. Therefore, the role-playing subspace contains several role-playing actions, which can capture the specific role of the prompt.
[0105] 2. The "history action subspace" provides the large model with the user's interaction history. Different users' interests may be reflected in recent interactions or in longer interaction histories. The distributed agent personalizes the "history" by selecting different lengths of interaction history for different users. The following are the steps to personalize the "history":
[0106] ① Initialize the interaction history length: First, set an initial interaction history length This is to ensure that, initially, large models have access to at least a certain amount of user interaction data.
[0107] ②In time , providing the large model with The historical information of the interaction record.
[0108] ③ Increase the length of historical records: Each time the time step reaches t+1, the agent will decide whether to increase the length of the historical records. This decision is made by the action taken by the agent at time t If If is greater than zero, the history length increases; otherwise it remains unchanged. The action at the moment determines the number of additional interactions in the "history", that is, the interaction sequence is provided to the large model. Interaction records, .
[0109] ④ Dynamically adjust the length of historical records: Based on the user's interests and behavior patterns, the intelligent body will continuously adjust the length of historical records. The purpose of this is to allow the large model to always receive the most relevant and valuable information to improve its performance and user experience.
[0110] ⑤ Personalized processing: The interests of different users may be reflected in recent interactions or in interaction histories over a longer time span. By providing each user with interaction histories of different lengths, personalized services are achieved, enabling the large model to better understand and meet the needs of different users.
[0111] 3. “Distributed Guidance Action Subspace” is a method for dealing with complex tasks. It simplifies the problem-solving process by breaking down the task into a series of logically connected reasoning steps. This method combines multiple strategies such as “Chain of Thought” (CoT), “reflection” and “optimization” to enhance the efficiency and accuracy of problem solving. For example, in movie recommendations, This can include:
[0112] ①Basic recommendations:
[0113] "Please rank these candidate movies based on my viewing history."
[0114] This step belongs to the basic application, which directly uses the user's past viewing history to rank the candidate movies without further analyzing the details of preferences. It assumes that the viewing history can directly reflect the preference order.
[0115] ② Preference inference:
[0116] “Please infer my movie preferences based on my viewing history and then rank these candidate movies”
[0117] Compared with the first step, the "preference inference" link is added. This means that before sorting, the model will first analyze the user's historical data, try to understand the user's preference patterns (such as favorite genres, directors, actors, etc.), and then sort based on these inferred preferences.
[0118] ③ Sorting recommendation and optimization:
[0119] “Please rank and recommend these candidate movies based on my viewing history, and optimize the ranking results.”
[0120] This step emphasizes the optimization of the ranking results based on the previous two steps. Optimization may involve a variety of strategies, such as adjusting the algorithm weights based on user feedback and introducing more external data (such as popularity and freshness) to improve the accuracy and diversity of recommendations.
[0121] ④Similarity calculation and sorting:
[0122] “Please calculate the similarity between the candidate movies and my movie preferences based on my viewing history, and then rank these candidate movies”
[0123] This step is more quantitative and precise, explicitly requiring the calculation of the similarity score between each candidate movie and the user's preferred features. This may involve techniques such as content filtering (analyzing the match between the movie content and the user's preferences) and collaborative filtering (comparing the user's viewing habits with other similar users). Based on these similarity scores, the system performs a detailed sorting, striving to recommend the movie that best suits the user's taste.
[0124] In the movie recommendation task, "step-by-step guidance" constructs a process of gradually refining recommendations from simple to complex by gradually and deeply analyzing user data, inferring preferences, optimizing recommendation strategies, and finally achieving fine similarity matching, aiming to provide more personalized and accurate services.
[0125] 4. "Output restricted action subspace" is a guiding principle used to standardize the content structure and form of the answers generated by large models, ensuring that the model's responses meet specific requirements or standards for further processing or direct application. This can effectively improve the clarity and utilization of information while reducing unnecessary information redundancy.
[0126] For example, This can include:
[0127] ① "Please only output recommended items with serial numbers, each item occupies one line";
[0128] This instruction requires the model to provide a series of recommendations (such as movies, books, or other items) with each recommendation item preceded by a clear sequence number, and each recommendation should be on a separate line. This organization of the output makes the information clear at a glance, easy to read and subsequent data processing.
[0129] ② “Please only output the recommended items with serial numbers, without explaining the reasons or including any other words”;
[0130] This requirement goes a step further, requiring not only a numbered and separate row format, but also emphasizes that the output should be strictly limited to the recommendation itself, excluding any additional explanations, reasons, or comments. This pure data output format is very suitable for scenarios where only a list of results is needed without accompanying explanations.
[0131] ③ "Your output format should be like this: x.movie title, x is the serial number" and other actions.
[0132] This is a specific output format example that specifies how each recommendation should be presented: starting with a sequence number (x), followed by a period and space, and then the recommended movie title. Such instructions help the model generate output that is formatted uniformly and easy to parse. By setting such "output restrictions", it is possible to guide large models on how to organize their responses so that the output content is concise and structured, making it easy for users to quickly obtain the required information or for automated processing.
[0133] By replacing task-specific or domain-specific terms, this approach can be easily extended to various recommendation tasks (e.g., rating prediction, item ranking) and domains (e.g., games, music). In addition, each component of the prompt can be described in a variety of ways, making the action space That is, the method has good flexibility and scalability.
[0134] Based on the above, this embodiment transforms the process of constructing instance-level personalized prompts into a search strategy , the goal of this strategy is to, in a given state Next, through the intelligent agent From the action space Select Action , and automatically generate the time Tips , .
[0135] in It is a distributed intelligent agent The policy function aims to , decide the next action ; The final optimization objective function of this strategy is:
[0136]
[0137] in, represents the expected cumulative reward for the MARL model; J represents the expectation of the expected reward, γ is the discount factor, which represents the proportion of the reward r at the future time t' in the cumulative reward. The reward r at the future time t' is calculated by the action a_t' and state s_t' at the future time; the expected cumulative reward in this formula Represents the value of the current decision, expected cumulative reward The higher it is, the better the prompt is for the current iteration.
[0138] Step S7: According to the state at the next moment, select the action at the next moment, calculate the probability of the action at the next moment, and the value of the state at the next moment;
[0139] Specifically, using distributed agents The Actor neural network formulates a strategy, which is: according to the state , select an action in the action space , and calculate the action Probability ; Using distributed agents The Critic neural network estimates the value of the state, and the estimated value of the state is: calculate the state Value ; The expression for formulating strategy and estimating value is:
[0140]
[0141] in, is the function representation symbol of the kth Actor, It is the function representation symbol of the k-th Critic.
[0142] Specifically, the function of each Actor neural network According to the status Formulate strategies and select actions in the action space , and calculate the action Probability , and the function of each Critic neural network Calculation status Value .
[0143] Step S8: Determine the reward based on the selected recommended item ; According to the reward And the value of the state at the next moment, get the cumulative reward ;According to the accumulated rewards , and get the first loss function of the Actor-Critic model and the second loss function ; Using the first loss function Evaluate the state at the next moment and use the second loss function The probability of the next action at the next moment maximizes the expected cumulative reward of the Actor-Critic model.
[0144] In this embodiment, the MARL model uses the Actor-Critic algorithm under the CTDE paradigm. This means that all Actor-Critic parameters are trained based on shared feedback signals; actual decisions are made based on independent parameters in independent action spaces.
[0145] For example, the recommended item set after interacting with the large model As a shared reward signal r, it refers to the recommended item set of the large model at time t using the NDCG evaluation indicator Conduct evaluation, output evaluation results, and use the evaluation results as rewards , centralized training updates parameters. During execution, each distributed agent have independent parameters, based on the state in the shared global state space In independent action space Each distributed agent makes decisions. They are composed of Actor and Critic, where Actor and Critic are two-layer fully connected neural networks, respectively and . is the function representation symbol of the kth Actor, It is the function representation symbol of the k-th Critic.
[0146] Since the purpose of this method is to improve the recommendation performance of the large model through personalized instance-level prompts, the NDCG evaluation index is used to evaluate the recommended item set of the large model at time t. Conduct evaluation, output evaluation results, and use the evaluation results as rewards The NDCG evaluation metric takes into account the relevance of recommended items and their positions in the recommendation list and is often used to measure the quality of the recommendation list.
[0147] From the above records, we can see that It represents the expected cumulative reward for the MARL model, which is a general expression of the MARL model. In this embodiment, the Actor-Critic model is the specific structure of the MARL model, so it is necessary to define the iterative optimization target of the Actor-Critic model algorithm; in this embodiment, according to the current and future rewards and the current and future values evaluated by the Critic neural network Calculating the Cumulative Rewards of the Actor-Critic Model Structure , and based on the cumulative rewards Defining optimization goals for actors and critics and , whose expression is:
[0148]
[0149] in It is the loss function of the Critic, and its purpose is to make the value estimated by the Critic close to the actual reward value, so as to learn an accurate value function and evaluate the value of the state; It is the loss function of the Actor, and its purpose is to maximize the expected cumulative reward of the strategy based on the probability of decision-making, so that the Actor can learn an excellent strategy; then the Actor-Critic model continuously optimizes the reward, updates the state, outputs the action, and then iterates the personalized instance-level prompt.
[0150] This embodiment uses the Actor-Critic algorithm under the CTDE paradigm through the MARL model to build an MDP model that can dynamically adjust the prompts in each interaction in order to achieve the best recommendation effect. The MDP model will continuously try different prompts and update the strategy based on user feedback and recommended items, thereby gradually improving the quality of the prompts and the recommendation effect.
[0151] The following is a statistical data of experiments on different data sets in multiple fields to prove a personalized prompt optimization method of this embodiment; in fact, a personalized prompt optimization method is an instance-level prompt personalization method (Reinforced Prompt Personalization, RPP) based on reinforcement learning:
[0152]
[0153] Under the RPP method, ML-1M, Games, and Lastfm datasets from different fields were used for training, and tested on different large language model skeletons (including ChatGPT, LLaMA, and Alpaca). The performance of RPP was compared with the traditional recommendation models Pop, BPRMF, and SASRec, as well as the task-level prompts on the large language model. The experimental results are shown in Table 1. Compared with the task-level prompts, RPP significantly improved the NDCG index of the large language model in ranking recommendations. Compared with the traditional recommendation model, RPP also achieved the best results.
[0154] Table 1: NDCG index of large language model ranking recommendation task under RPP
[0155]
[0156] The embodiment of the present invention further provides a personalized prompt optimization device, which is used to implement the above method embodiment, and will not be repeated hereafter. The terms "module", "unit", "subunit", etc. used below can implement a combination of software and / or hardware of a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware is also possible and conceived.
[0157] like Fig. 9 As shown, Fig. 9 : is a structural block diagram of a personalized prompt optimization device of the present invention, the device comprising:
[0158] The first acquisition module 101 is used to use a distributed agent , obtain the K components of the large model task-level prompt;
[0159] An MDP model construction module 102 is used to construct an MDP model, wherein the MDP model includes K action spaces corresponding to the K components and a shared global state space; the actions in the action space are used to represent the natural language of the prompt of the current iteration, and the state of the state space is used to represent the prompt of the current iteration and the recommended item set output by the large model;
[0160] The second acquisition module 103 acquires the initial state of the MDP model;
[0161] Output module 104, used to use distributed agents according to the initial state From the action space Select the action at the initial moment, generate the prompt at the current moment from the action at the initial moment; use the prompt at the current moment as input, and output the recommended item set at the current moment;
[0162] The first iteration module 105 is used to encode the prompt word at the current moment and the recommended item selected in the recommended item set at the current moment to obtain the prompt word representation and the recommended item representation, and iterate to obtain the current moment according to the prompt word representation and the recommended item representation. Status ;
[0163] The second iteration module 106 is used to Status , using distributed agents From the action space Select Action ; By action Generate the iterated prompt, take the iterated prompt as input, and output the iterated recommended item set; iterate to obtain the state at the next moment according to the iterated prompt and the recommended items selected in the iterated recommended item set;
[0164] A calculation module 107, used to select an action at the next moment according to the state at the next moment, and calculate the probability of the action at the next moment and the value of the state at the next moment;
[0165] The optimization module 108 is used to determine the reward based on the selected recommended items. ; According to the reward And the value of the state at the next moment, get the cumulative reward ;According to the accumulated rewards , and get the first loss function of the Actor-Critic model and the second loss function ; Using the first loss function Evaluate the state at the next moment and use the second loss function The probability of the next action at the next moment maximizes the expected cumulative reward of the Actor-Critic model.
[0166] like Fig.10 As shown, an embodiment of the present invention further provides an electronic device, which includes a memory 230 and a processor 210, wherein the memory 230 stores at least one computer executable instruction, and the processor 210 is configured to run the computer executable instruction, and when the computer executable instruction is run by the processor 210, the above-mentioned personalized prompt optimization method is implemented.
[0167] The electronic device may include a processor 210, a communication interface 220, a memory 230 and a communication bus 240, wherein the processor 210, the communication interface 220 and the memory 230 communicate with each other via the communication bus 240. The processor 210 may call the logic instructions in the memory 230 to execute a personalized prompt optimization method.
[0168] In addition, the logic instructions in the above-mentioned memory 230 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods of various embodiments of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0169] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, i.e., they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Those of ordinary skill in the art may understand and implement it without creative effort.
[0170] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0171] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A personalized prompt optimization method, characterized in that: include: Using Distributed Agents , obtain the K components of the large model task-level prompt; Constructing an MDP model, wherein the MDP model includes K action spaces corresponding to the K components and a shared global state space; The action in the action space is used to represent the natural language of the prompt in the current iteration, and the state in the state space is used to represent the prompt in the current iteration and the recommended item set output by the large model; Get the initial state of the MDP model; According to the initial state, use the distributed agent From the action space Select the action at the initial moment, generate the prompt at the current moment from the action at the initial moment; use the prompt at the current moment as input, and output the recommended item set at the current moment; Encode the prompt at the current moment and the recommended items selected in the recommended item set at the current moment to obtain the prompt representation and the recommended item representation. According to the prompt representation and the recommended item representation, iterate to obtain the current moment Status ; According to the current time Status , using distributed agents From the action space Select Action ; By action Generate the iterated prompt, take the iterated prompt as input, and output the iterated recommended item set; iterate to obtain the state at the next moment according to the iterated prompt and the recommended items selected in the iterated recommended item set; According to the state at the next moment, select the action at the next moment, calculate the probability of the action at the next moment, and the value of the state at the next moment; Determine the reward based on the selected recommended item ; According to the reward And the value of the state at the next moment, get the cumulative reward ;According to the accumulated rewards , and get the first loss function of the Actor-Critic model and the second loss function ; Using the first loss function Evaluate the state at the next moment and use the second loss function The probability of the next action at the next moment maximizes the expected cumulative reward of the Actor-Critic model; Among them, according to current and future rewards and the current and future values evaluated by the Critic neural network Calculating the Cumulative Rewards of the Actor-Critic Model Structure , and based on the cumulative rewards Defining optimization goals for actors and critics and , The cumulative reward , the first loss function and the second loss function The expression is: ; in, It is the loss function of the Critic, and its purpose is to make the value estimated by the Critic close to the actual reward value, so as to learn an accurate value function and evaluate the value of the state; It is the loss function of the Actor, and its purpose is to maximize the expected cumulative reward of the strategy based on the probability of decision-making, so that the Actor can learn an excellent strategy; then the Actor-Critic model continuously optimizes the reward, updates the state, outputs the action, and then iterates the personalized instance-level prompt.
2. A personalized prompt optimization method according to claim 1, characterized in that: Using Distributed Agents , obtain K components of the large model task-level prompt, including: obtaining task-level prompts with a predefined common format, using distributed agents under the centralized training and decentralized execution paradigm , the task-level prompt is disassembled according to the predefined general format to obtain K components.
3. The personalized prompt optimization method according to claim 1, characterized in that: Get the initial state of the MDP model, including: Get User and items ID information; According to user and items ID information, get user embedding and item embedding; According to the user embedding and item embedding, the state space of the MDP model is initialized to obtain the initial state.
4. The personalized prompt optimization method according to claim 1, characterized in that: Encode the prompt at the current moment and the recommended items selected in the recommended item set at the current moment to obtain the prompt representation and the recommended item representation. According to the prompt representation and the recommended item representation, iterate to obtain the current moment Status ,include: Use the pre-trained language model BERT and the sequence model GRU to encode the prompt at the current moment respectively and the recommended items set at the current moment , expressed as: in, Represents the first in the output recommendation sequence The embedding of items, and They are the prompts for the current moment. and the recommended items set at the current moment Representation.
5. The personalized prompt optimization method according to claim 1, characterized in that: According to the state at the next moment, select the action at the next moment, calculate the probability of the action at the next moment, and the value of the state at the next moment, including: Using Distributed Agents The Actor neural network formulates a strategy, which is: according to the state , select an action in the action space , and calculate the action Probability ; Use distributed agents The Critic neural network estimates the value of the state, and the estimated value of the state is: calculate the state Value ; The expression for formulating strategy and estimating value is: in, is the function representation symbol of the kth Actor, It is the function representation symbol of the k-th Critic.
6. A personalized prompt optimization method according to claim 1, characterized in that: Determine the reward based on the selected recommended item ,include: Using the NDCG evaluation index, the recommended item set of the large model at time t Conduct evaluation, output evaluation results, and use the evaluation results as rewards .
7. A personalized prompt optimization device, characterized in that: include: The first acquisition module is used to use the distributed agent , obtain the K components of the large model task-level prompt; An MDP model construction module is used to construct an MDP model, wherein the MDP model includes K action spaces corresponding to the K components and a shared global state space; The action in the action space is used to represent the natural language of the prompt in the current iteration, and the state in the state space is used to represent the prompt in the current iteration and the recommended item set output by the large model; The second acquisition module acquires the initial state of the MDP model; The output module is used to use the distributed agent according to the initial state From the action space Select the action at the initial moment, generate the prompt at the current moment from the action at the initial moment; use the prompt at the current moment as input, and output the recommended item set at the current moment; The first iteration module is used to encode the prompt word at the current moment and the recommended item selected in the recommended item set at the current moment to obtain the prompt word representation and the recommended item representation, and iterate to obtain the current moment according to the prompt word representation and the recommended item representation. Status ; The second iteration module is used to Status , using distributed agents From the action space Select Action ; By action Generate the iterated prompt, take the iterated prompt as input, and output the iterated recommended item set; iterate to obtain the state at the next moment according to the iterated prompt and the recommended items selected in the iterated recommended item set; A calculation module is used to select an action at the next moment according to the state at the next moment, calculate the probability of the action at the next moment, and the value of the state at the next moment; An optimization module that determines rewards based on the selected recommended items ; According to the reward And the value of the state at the next moment, get the cumulative reward ;According to the accumulated rewards , and get the first loss function of the Actor-Critic model and the second loss function ; Using the first loss function Evaluate the state at the next moment and use the second loss function The probability of the next action at the next moment maximizes the expected cumulative reward of the Actor-Critic model; Among them, according to current and future rewards and the current and future values evaluated by the Critic neural network Calculating the Cumulative Rewards of the Actor-Critic Model Structure , and based on the accumulated rewards Defining optimization goals for actors and critics and , The cumulative reward , the first loss function and the second loss function The expression is: ; in, It is the loss function of the Critic, and its purpose is to make the value estimated by the Critic close to the actual reward value, so as to learn an accurate value function and evaluate the value of the state; It is the loss function of the Actor, and its purpose is to maximize the expected cumulative reward of the strategy based on the probability of decision-making, so that the Actor can learn an excellent strategy; then the Actor-Critic model continuously optimizes the reward, updates the state, outputs the action, and then iterates the personalized instance-level prompt.
8. An electronic device, characterized in that: The electronic device includes a memory and a processor, the memory stores at least one computer executable instruction, and the processor is configured to execute the computer executable instruction. When the computer executable instruction is executed by the processor, the personalized prompt optimization method described in any one of claims 1 to 7 is implemented.
9. A computer-readable storage medium, characterized in that: A computer program is stored on a computer-readable storage medium, and when the computer program is executed by a processor, the method for optimizing personalized prompts according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Multi-agent reinforcement learning method based on intelligent planning
CN116841708A
Intelligent learning guiding method based on GPT and multi-agent reinforcement learning
CN117808637A
Cross-behavior information recommendation method based on reinforcement learning
CN118115229A
Text recommendation method and system based on language large model
CN118193683A
Planning for agent control using learned hidden states
US20230073326A1
