Method and system for constructing extensible and safe role prompt for role-based dialogue
Through combined role prompts and multiple optimization methods, it solves the high cost and bias problems of role-based dialogue construction, provides flexible and safe role prompts, improves the diversity and consistency of dialogue, and reduces manual data dependence.
Patent Information
- Application Number
- CN202410564144.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-08
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2044-05-08
AI Technical Summary
When building role-based dialogues with existing technologies, manual construction costs are high, and automatic collection of role-based dialogue data has problems with social bias and stereotypes.
Adopting a combined character prompting approach to build scalable character prompts by integrating personality traits, definable groups, and optional parts, and safely optimizing through introspection, expert perspectives, and brainstorming methods, leveraging two LLM-driven conversational agents Conduct role-based dialogue simulations.
It provides flexible, diverse and safe role prompts, reduces dependence on manually constructed data, reduces potential biases and stereotypes in downstream tasks, and improves the safety performance and consistency of role-based dialogues.
Smart Images

Figure CN118551771A
Abstract
Description
Technical Field
[0001] The present invention belongs to a technical solution for human-like conversational agents in natural language processing, and specifically relates to a method and a prompt system for constructing a scalable and secure role prompt for role-based conversations. Background Art
[0002] Building human-like conversational agents is one of the long-term goals of achieving artificial intelligence, and role-based conversations play an important role in this process. Role-based conversations aim to give conversational agents specific roles, which helps provide more attractive and human responses to human users, and have a wide range of application scenarios (intelligent assistants, game NPCs, audience response simulation, etc.).
[0003] The standard approach in the past was to fine-tune the pre-trained model, combined with some innovations in model structure or learning methods. These approaches are limited by manually annotated data or crowdsourced conversations, are limited in scale and difficult to expand, and are expensive and time-consuming to manually build. However, if large-scale data is collected directly from social media, the number of conversations related to the role is effective.
[0004] With the emergence of large language models (LLMs) represented by ChatGPT and GPT-4, the performance of many natural language processing tasks has been significantly improved. LLMs are trained on massive corpora, contain a lot of knowledge, and have strong generalization capabilities. Compared with the pre-training fine-tuning paradigm, recent work has shown that LLMs can adapt to specific tasks with a few or zero-shot prompts and show advanced performance. Therefore, with the extraordinary performance of LLMs, LLM-driven conversational agents can simulate a large number of diverse general roles with the help of prompts. Given the richness and diversity of roles, manually constructing prompts is cumbersome and requires certain prior knowledge, so automated methods are more likely to be considered. However, by directly applying simple automatically generated prompts to let LLMs simulate roles, LLMs may perpetuate or even amplify social biases and stereotypes in massive data, and further deepen their propagation when applied to downstream tasks. Summary of the invention
[0005] The present invention provides a scalable and secure method for constructing role prompts for role-based dialogues, which is used to solve the problems of high cost of manually constructing role-based dialogue data, scarcity of role information for automatically collected role-based data, and social bias and stereotypes that may be caused by directly applying simple automatically generated prompts to LLMs to simulate roles.
[0006] The present invention provides a scalable and secure role prompt system for role-based dialogue, which is used to build a scalable and secure role prompt for role-based dialogue.
[0007] The invention also provides a computer device.
[0008] The present invention also provides a computer-readable storage medium.
[0009] The present invention is achieved through the following technical solutions:
[0010] A method for constructing a scalable and secure role prompting method for role-based dialogue, the method comprising the following steps:
[0011] Step 1: Combined role prompt construction;
[0012] Step 2: Perform security optimization based on the combined role prompts in step 1;
[0013] Step 3: Based on the safety optimized role prompts in step 2, perform role-based dialogue simulation.
[0014] Furthermore, the step 1 is specifically to integrate personality traits, definable groups and optional parts to construct an extensible combined role prompt.
[0015] Furthermore, the step 2 is specifically to optimize the initial role prompts through three human behavior simulations: introspection, expert perspective and brainstorming.
[0016] Furthermore, the step 3 specifically includes using the generated role prompts to guide the two LLM-driven dialogue agents to conduct a role-based dialogue.
[0017] Furthermore, the integrated personality characteristics are specifically: A is used to represent personality characteristics, and common adjectives used to describe five aspects of human personality in the Big Five Personality Theory are used as part A;
[0018] The definable group feature is specifically that B is used to represent the group name, and prompt LLMs are used to directly generate a specified number of representative group nouns as part B;
[0019] Specifically, the optional part is represented by C, which is explicitly reflected in the reply.
[0020] Furthermore, the introspection specifically includes self-prompting LLMs to introspect and reflect on themselves, determine whether the previously generated descriptions of the roles are biased and stereotyped, and make appropriate corrections;
[0021] Specifically, the expert perspective is to give a task-related identity definition description, allowing LLMs to play the role of sociology experts and give valuable opinions from an authoritative expert perspective;
[0022] Specifically, the brainstorming is to allow each LLM-driven dialogue agent to express its own insights and opinions, and the initial dialogue agent makes the final judgment based on the group opinions.
[0023] Furthermore, two LLM-driven dialogue agents are used, each corresponding to a role. They are asked to simulate the corresponding role to chat, generate only one round of speech at a time, update the text and switch back and forth to complete the entire conversation; each conversation lasts N rounds.
[0024] A scalable and secure role prompting system for role-based dialogue, the role prompting system uses the above-mentioned scalable and secure role prompting method for role-based dialogue, the role prompting system includes:
[0025] Building blocks for combined character cue construction;
[0026] An optimization module for security optimization of combined role prompts;
[0027] The simulation dialogue module is used to perform role-based dialogue simulation.
[0028] A computer device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the above method is implemented.
[0029] A computer-readable storage medium stores a computer program, and the computer program implements the above method when executed by a processor.
[0030] The beneficial effects of the present invention are:
[0031] The present invention flexibly provides a large number of diverse and safe role cues, which can be directly applied to downstream tasks.
[0032] The present invention adopts three automated methods to safely optimize role prompts and mitigate potential biases and stereotypes in their application in downstream tasks.
[0033] The present invention can combine the generated role prompts to automatically generate role-based dialogue data, reducing the dependence of role-based dialogue on manually constructed data.
[0034] The combined role tag constructed by the present invention is highly flexible, reusable and easy to expand.
[0035] The present invention avoids the bias and stereotype that may be caused by directly using LLMs to simulate roles for role-based dialogue.
[0036] The role-based dialogue data automatically generated by the framework of the present invention can be used to enhance the role-based dialogue capabilities of other LLMs with weaker capabilities, reducing the need for manually annotated data. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 It is a structural schematic diagram of the present invention.
[0038] Figure 2 It is a flow chart of the method of the present invention. DETAILED DESCRIPTION
[0039] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0040] It should be understood that when used in this specification and the appended claims, the term "comprising" indicates the presence of described features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof.
[0041] It should also be understood that the terms used in this application specification are only for the purpose of describing specific embodiments and are not intended to limit the application. As used in this application specification and the appended claims, the singular forms "a", "an" and "the" are intended to include plural forms unless the context clearly indicates otherwise.
[0042] The following is attached to this application specification Figure 1 , the technical solutions in the embodiments of the present application are clearly and completely described. 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 the present application.
[0043] In the following description, many specific details are set forth to facilitate a full understanding of the present application, but the present application may also be implemented in other ways different from those described herein, and those skilled in the art may make similar generalizations without violating the connotation of the present application. Therefore, the present application is not limited to the specific embodiments disclosed below.
[0044] Implementation Method 1
[0045] Combination Figure 1This embodiment provides a scalable and secure role prompting method for role-based dialogue, the method comprising the following steps:
[0046] Step 1: Combined role prompt construction;
[0047] Furthermore, the step 1 is specifically to integrate personality traits, definable groups and optional parts to construct an extensible combined role prompt.
[0048] Compared with the previous fixed roles, the method of the present invention defines the role as a combination of A+B+C.
[0049] A (personality traits) + B (definable group) + C (optional, hobbies, personal experience, and other descriptive sentences)
[0050] Part A is a representative personality trait. Personality traits have an important influence on human thinking, feelings and behavior patterns, and are strongly related to language use. The method of the present invention uses common adjectives used in the Big Five personality theory to describe five aspects of human personality as Part A.
[0051] Part B is a definable group name, such as various occupational nouns, "teenagers", "science fiction fans", etc. The present invention selects a group rather than a specific person as the simulation object. This is because LLMs need additional personal information to simulate a specific person, and the information of most individuals is too sparse for the weight of LLMs. Secondly, the prejudices and stereotypes based on groups are more realistic and valuable. LLMs themselves contain sufficient knowledge. The present invention uses prompts to LLMs to directly generate a specified number of representative group nouns as part B.
[0052] Part C is optional, with unlimited number, and is easy to customize. The sample sentence description can be a description of the character's interests, hobbies, personal experience, etc. This part can be explicitly reflected in the reply.
[0053] By using this flexible combined role prompt and calling the corresponding knowledge in LLMs to describe multiple roles, it is easy to expand the diverse roles, which can alleviate the problem of role data imbalance to a certain extent. In addition, the present invention uses descriptive sentences in the constructed role prompts, which makes the subsequent role-based dialogue generation very natural and the text information has strong transparency.
[0054] Step 2: Perform security optimization based on the combined role prompts in step 1;
[0055] Furthermore, the step 2 is specifically to optimize the initial role prompts to make them safer through three human behavior simulations, namely, introspection, expert perspective and brainstorming.
[0056] Furthermore, directly applying the constructed initial role cues to downstream tasks will inevitably bring some safety issues (mainly focusing on social bias and stereotypes). In view of the feasibility of LLMs in simulating human behavior, this paper proposes three optimization methods inspired by daily life phenomena.
[0057] 1) Introspection. Recent studies have shown that LLMs have some human-like characteristics, such as self-improvement and reasoning ability. LLMs of a certain size can have the ability to self-correct morality. Therefore, the method of the present invention self-prompts LLMs to introspect and reflect on themselves, determine whether the previously generated description of the role is biased and stereotyped, and make appropriate corrections.
[0058] 2) Expert perspective. The method of the present invention allows LLMs to play the role of outstanding experts and stimulate their potential. Specifically, a sociology expert prompt is designed to give a task-related identity definition description, allowing LLMs to play the role of sociology experts and give valuable opinions from the perspective of authoritative experts.
[0059] 3) Brainstorming. The interaction of multiple cognitive processes may be greater than individual contributions. The method of the present invention combines multiple LLMs to brainstorm to modify the initial prompt. Specifically, each LLM-driven dialogue agent is allowed to express its own insights and opinions, and the initial dialogue agent makes the final judgment based on the group's opinions.
[0060] Finally, build a selector to choose the final optimization hint from the three methods.
[0061] Step 3: Based on the security optimization in step 2, conduct a simulated role-based dialogue.
[0062] Furthermore, the step 3 specifically includes using the generated role prompts to guide the two LLM-driven dialogue agents to conduct a role-based dialogue.
[0063] Furthermore, although applying gradient-free techniques in LLMs is effective, the need for smaller trainable or fine-tunable models still exists in real-world scenarios due to cost constraints, response time, or security and privacy issues. To address these issues, the proposed method uses LLMs to simulate roles to generate data for role-based dialogues. It not only solves the limitations of traditional methods in terms of scale and complexity, but also provides a feasible perspective for studying human communication patterns of different roles.
[0064] The method of the present invention uses two LLM-driven conversational agents, each corresponding to a role. They are asked to simulate the corresponding role to chat, generate only one round of speech at a time, update the text and switch back and forth to complete the entire conversation. During the conversation, some conversation requirements will be set. For example, they are required to not only talk about themselves when chatting, but also ask questions. When simulating the role, they cannot simply use the role's descriptive sentences directly. Each conversation lasts N rounds.
[0065] In general, based on the above steps, the method of the present invention can flexibly provide a large number of diverse and safe role prompts, which are convenient for direct application to downstream tasks. In addition, the method of the present invention can automatically generate role-based dialogue data, promoting the application of data-driven methods.
[0066] Specifically, (1) Quality analysis of the generated role-based dialogue data
[0067] The dataset generated by the method of the present invention is compared with the commonly used manually annotated datasets (sampling the same number of samples) in the field of role-based dialogue in different dimensions. As shown in Table 1, the data generated by the method of the present invention is better than or close to the sampled data in terms of traditional evaluation indicators (role consistency, toxicity, and replication rate) and GPT-4 simulation evaluation indicators (coherence, consistency, engagement, and safety).
[0068] Table 1 Evaluation results of automatic evaluation and GPT-4 on role-based dialogue data
[0069]
[0070] (2) Safety performance evaluation of the method
[0071] The present invention uses two popular small-scale pre-trained dialogue models (DialoGPT and BlenderBot) as experimental subjects for safety performance evaluation. The open source toolkit SAFETYKIT that combines many existing security detection tools is used for safety evaluation to evaluate two phenomena: generating unsafe content and endorsing and promoting unsafe content. The tool reports the percentage of generated replies marked as unsafe replies. The present invention compares the performance of the model before and after fine-tuning on the generated data. The evaluation results are shown in Table 2. It can be observed that the safety performance of the model fine-tuned on the data generated by the method of the present invention is significantly improved compared with the original model. The superiority of the method of the present invention in terms of safety performance is demonstrated.
[0072] Table 2 Impact of generated dialogue data on the safety performance of small-scale models
[0073]
[0074] (3) Role-based performance evaluation of methods
[0075] In order to evaluate the performance of the method of the present invention in the role-based dialogue task, open source LLMs fine-tuned on generated data and LLMs fine-tuned with supervised instructions with role prompts were selected for experiments. Specifically, the Llama 2 series of 7B and 13B and Vicuna of 13B. The results of automatic evaluation and manual evaluation are shown in Table 3 and Table 4, respectively. For the results of automatic evaluation, the fine-tuned pre-trained model is superior to the corresponding supervised instruction fine-tuned model in role consistency and overlap with manual standard responses, which proves the value of generated data for role-based dialogue and the effectiveness of the method of the present invention in role-based dialogue. In the manual evaluation, the fine-tuned pre-trained model has a higher win rate in consistency and coherence. However, the supervised instruction fine-tuned model with role prompts is superior to the fine-tuned pre-trained model in terms of attractiveness and overall indicators. This shows that the role prompts generated by the method of the present invention are effective for role-based dialogue. In addition to task-specific indicators, the prompt-based method is more flexible and generalizable, especially on larger models.
[0076] Table 3 Automatic evaluation results
[0077]
[0078] Table 4. Manual evaluation results
[0079]
[0080] (4) Case study of human-computer interactive dialogue
[0081] The present invention explores the interaction between real people and dialogue agents. We find people who meet the requirements of parts A+B and ask them to manually write their own part C. Then, we ask them to have a role-based dialogue with a dialogue agent of a randomly selected role. An example of a dialogue between an LLM based on optimized role prompts and a real human is shown in Table 5. The red ones are dialogue agent utterances involving role information, and the blue ones are real human utterances involving role information.
[0082] Implementation Method 2
[0083] This embodiment provides a scalable and secure role prompting system for role-based dialogue. This embodiment uses the scalable and secure role prompting method for role-based dialogue described in embodiment 1. The role prompting system includes a construction module, an optimization module and a simulation dialogue module.
[0084] The construction module is used for combined role prompt construction;
[0085] The optimization module is used to perform security optimization on the combined role prompt;
[0086] The simulated dialogue module is used to conduct simulated role-based dialogue.
[0087] Furthermore, the working principle of the construction module is specifically to integrate personality traits, definable groups and optional parts to construct an extensible combined role prompt.
[0088] Compared with the previous fixed roles, the method of the present invention defines the role as a combination of A+B+C.
[0089] A (personality traits) + B (definable group) + C (optional, hobbies, personal experience, and other descriptive sentences)
[0090] Part A is a representative personality trait. Personality traits have an important influence on human thinking, feelings and behavior patterns, and are strongly related to language use. The method of the present invention uses common adjectives used in the Big Five personality theory to describe five aspects of human personality as Part A.
[0091] Part B is a definable group name, such as various occupational nouns, "teenagers", "science fiction fans", etc. The present invention selects a group rather than a specific person as the simulation object. This is because LLMs need additional personal information to simulate a specific person, and the information of most individuals is too sparse for the weight of LLMs. Secondly, the prejudices and stereotypes based on groups are more realistic and valuable. LLMs themselves contain sufficient knowledge. The present invention uses prompts to LLMs to directly generate a specified number of representative group nouns as part B.
[0092] Part C is optional, with unlimited number, and is easy to customize. The sample sentence description can be a description of the character's interests, hobbies, personal experience, etc. This part can be explicitly reflected in the reply.
[0093] By using this flexible combined role prompt and calling the corresponding knowledge in LLMs to describe multiple roles, it is easy to expand the diverse roles, which can alleviate the problem of role data imbalance to a certain extent. In addition, the present invention uses descriptive sentences in the constructed role prompts, which makes the subsequent role-based dialogue generation very natural and the text information has strong transparency.
[0094] Furthermore, the working principle of the optimization module is specifically to optimize the initial role prompts to make them safer through three human behavior simulations: introspection, expert perspective and brainstorming.
[0095] Furthermore, directly applying the constructed initial role cues to downstream tasks will inevitably bring some safety issues (mainly focusing on social bias and stereotypes). In view of the feasibility of LLMs in simulating human behavior, this paper proposes three optimization methods inspired by daily life phenomena.
[0096] 4) Introspection. Recent studies have shown that LLMs have some human-like characteristics, such as self-improvement and reasoning ability. LLMs of a certain size can have the ability to self-correct morality. Therefore, the method of the present invention self-prompts LLMs to introspect and reflect on themselves, determine whether the previously generated description of the role is biased and stereotyped, and make appropriate corrections.
[0097] 5) Expert perspective. The method of the present invention allows LLMs to play the role of outstanding experts and stimulate their potential. Specifically, a sociology expert prompt is designed to give a task-related identity definition description, allowing LLMs to play the role of sociology experts and give valuable opinions from the perspective of authoritative experts.
[0098] 6) Brainstorming. The interaction of multiple cognitive processes may be greater than individual contributions. The method of the present invention combines multiple LLMs to brainstorm to modify the initial prompt. Specifically, each LLM-driven dialogue agent is allowed to express its own insights and opinions, and the initial dialogue agent makes the final judgment based on the group's opinions.
[0099] Finally, build a selector to choose the final optimization hint from the three methods.
[0100] Furthermore, the working principle of the simulated dialogue module is specifically to use the generated role prompts to guide two LLM-driven dialogue agents to conduct a role-based dialogue.
[0101] Furthermore, although applying gradient-free techniques in LLMs is effective, the need for smaller trainable or fine-tunable models still exists in real-world scenarios due to cost constraints, response time, or security and privacy issues. To address these issues, the proposed method uses LLMs to simulate roles to generate data for role-based dialogues. It not only solves the limitations of traditional methods in terms of scale and complexity, but also provides a feasible perspective for studying human communication patterns of different roles.
[0102] The method of the present invention uses two LLM-driven conversational agents, each corresponding to a role. They are asked to simulate the corresponding role to chat, generate only one round of speech at a time, update the text and switch back and forth to complete the entire conversation. During the conversation, some conversation requirements will be set. For example, they are required to not only talk about themselves when chatting, but also ask questions. When simulating the role, they cannot simply use the role's descriptive sentences directly. Each conversation lasts N rounds.
[0103] In general, based on the above steps, the method of the present invention can flexibly provide a large number of diverse and safe role prompts, which are convenient for direct application to downstream tasks. In addition, the method of the present invention can automatically generate role-based dialogue data, promoting the application of data-driven methods.
Claims
1. A scalable and secure method for constructing role prompts for role-based dialogues, characterized in that: The method comprises the following steps, Step 1: Combined role prompt construction; Step 2: Perform security optimization based on the combined role prompts in step 1; Step 3: Based on the safety-optimized role prompts from step 2, perform role-based dialogue simulation.
2. The character prompting method according to claim 1, characterized in that: Specifically, step 1 includes integrating personality traits, definable groups, and optional parts to construct an extensible combined role prompt.
3. The character prompting method according to claim 2, characterized in that: Specifically, step 2 is to optimize the initial role prompts through three human behavior simulations: introspection, expert perspective, and brainstorming.
4. The character prompting method according to claim 3, characterized in that: Specifically, step 3 is to use the generated role prompts to guide two LLM-driven dialogue agents to conduct a role-based dialogue.
5. The character prompting method according to claim 2, characterized in that: Specifically, the integrated personality traits are: A represents personality traits, and common adjectives used to describe five aspects of human personality in the Big Five Personality Theory are used as part A; The definable group feature is specifically that B is used to represent the group name, and prompt LLMs are used to directly generate a specified number of representative group nouns as part B; Specifically, the optional part is represented by C, which is explicitly reflected in the reply.
6. The character prompting method according to claim 3, characterized in that: Specifically, the introspection is to self-prompt LLMs to introspect and reflect on themselves, determine whether the previously generated description of the role is biased and stereotyped, and make appropriate corrections; Specifically, the expert perspective is to give a task-related identity definition description, allowing LLMs to play the role of sociology experts and give valuable opinions from an authoritative expert perspective; Specifically, the brainstorming is to allow each LLM-driven dialogue agent to express its own insights and opinions, and the initial dialogue agent makes the final judgment based on the group opinions.
7. The character prompting method according to claim 4, characterized in that: Two LLM-driven conversational agents are used, one for each role. Ask them to simulate the corresponding characters to chat, generate only one round of speech at a time, update the text and switch back and forth to complete the entire conversation; each conversation lasts N rounds.
8. A scalable and secure role prompting system for role-based dialogue, characterized in that: The role prompting system uses a scalable and secure role prompting method for role-based dialogue as described in any one of claims 1-7, and the role prompting system includes: Building blocks for combined character cue construction; An optimization module for security optimization of combined role prompts; The simulation dialogue module is used to perform role-based dialogue simulation.
9. A computer device, characterized in that: The method comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method according to 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 computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Human-machine personalized dialogue method and system based on inference dialogue model
CN113220851A
Personalized role positioning method for group cooperation based on meta-cognition
CN116777402A
Application method of dialogue system based on human big language model in industrial scene
CN117932012A
Interactive recommendation method and interactive recommendation system based on large language model
CN117932142A
Multi-persona social agent
US20220129627A1
Cited By
Data generation method and device, electronic equipment, storage medium and computer program product
CN119358680A
