Extensible and secure role prompting method for role-based conversation and prompting system thereof
By combining role prompts and various optimization methods, the high cost and bias issues of manual construction in role-based dialogues are solved, enabling flexible, diverse and secure generation of role-based dialogues, and improving the role-based capabilities and data quality of LLM.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HARBIN INST OF TECH
- Filing Date
- 2024-05-08
- Publication Date
- 2026-04-28
AI Technical Summary
Existing technologies for constructing role-based dialogues suffer from problems such as high costs of manual construction, data scarcity, and the potential for social bias and stereotypes to be introduced by directly applying simple, automatically generated prompts.
A combined role-based prompting approach is adopted, integrating personality traits, definable groups, and optional components. Combining introspection, expert perspective, and brainstorming optimization methods, role-based dialogue simulation is conducted through two LLM-driven dialogue agents.
It provides flexible, diverse, and secure role prompts, reduces reliance on manually constructed data, lowers the risk of social bias and stereotypes, and improves the quality and security of role-based dialogue.
Smart Images

Figure CN118551771B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of human-like dialogue intelligent agent technology in natural language processing, specifically involving a scalable and secure role prompting method and system for role-based dialogue. Background Technology
[0002] Building human-like conversational agents is one of the long-term goals of artificial intelligence, and role-based dialogue plays an important role in this. Role-based dialogue aims to give conversational agents specific roles, which helps to provide more attractive and human-like responses to human users, and has a wide range of applications (intelligent assistants, game NPCs, audience response simulation, etc.).
[0003] Traditional approaches primarily involve fine-tuning pre-trained models, combined with innovations in model architecture or learning methods. These approaches are limited by manually labeled data or crowdsourced dialogues, resulting in limited scalability and high costs and time commitments for manual model building. However, collecting large-scale data directly from social media, particularly relevant dialogues related to specific roles, offers a more effective solution.
[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 containing a wealth of knowledge and possess strong generalization capabilities. Compared to the pre-training fine-tuning paradigm, recent work has demonstrated that LLMs can adapt to specific tasks with minimal or even zero-shot cues, exhibiting state-of-the-art performance. Therefore, thanks to the exceptional performance of LLMs, LLM-driven dialogue agents can simulate a wide variety of general roles with the help of cues. Given the rich diversity of roles, manually constructing cues is cumbersome and requires certain prior knowledge; therefore, automation is a more readily considered approach. However, directly applying simply automatically generated cues to allow LLMs to simulate roles may perpetuate or even amplify social biases and stereotypes present in the massive dataset, further exacerbating their propagation when applied to downstream tasks. Summary of the Invention
[0005] This invention provides a scalable and secure method for constructing role prompts for role-based dialogues, which addresses the problems of high cost of manually constructing role-based dialogue data, scarcity of role information in automatically collected role-based dialogue data, and the potential for social bias and stereotypes to arise from directly applying simple, automatically generated prompts to LLMs simulating roles.
[0006] This invention provides a scalable and secure role prompting system for role-based dialogue, used to construct scalable and secure role prompts for role-based dialogue.
[0007] The present invention also provides a computer device.
[0008] The present invention also provides a computer-readable storage medium.
[0009] This invention is achieved through the following technical solution:
[0010] A method for building scalable and secure role-based prompts for role-based dialogue, the method comprising the following steps:
[0011] Step 1: Constructing composite character hints;
[0012] Step 2: Optimize security based on the combined role prompts in Step 1;
[0013] Step 3: Based on the role prompts for security optimization in Step 2, conduct role-based dialogue simulation.
[0014] Furthermore, step 1 specifically involves integrating personality traits, definable groups, and optional components to construct an extensible, combinatorial role cue.
[0015] Furthermore, step 2 specifically involves optimizing the initial role prompts through three human behavior simulations: introspection, expert perspective, and brainstorming.
[0016] Furthermore, step 3 specifically involves using generated role prompts to guide two LLM-driven dialogue agents in role-based dialogue.
[0017] Furthermore, the integrated personality traits specifically refer to the use of A to represent personality traits, and the use of common adjectives from the Big Five personality theory used to describe five aspects of human personality as part A.
[0018] The definable group feature specifically refers to using B to represent the group name, and using prompting LLMs to directly generate a specified number of representative group names as part B;
[0019] Specifically, the optional part, represented by C, is explicitly reflected in the response.
[0020] Furthermore, the introspection specifically involves prompting LLMs to introspect, reflect on themselves, determine whether the previously generated descriptions of the character contain biases and stereotypes, and make appropriate corrections.
[0021] The expert perspective specifically refers to providing a task-related identity definition description, allowing LLMs to act as sociology experts and offer valuable insights from the perspective of authoritative experts.
[0022] Specifically, the brainstorming process involves allowing each LLM-driven dialogue agent to express its own insights and opinions, with the initial dialogue agent combining these with the group's opinions to make the final judgment.
[0023] Furthermore, two LLM-driven dialogue agents are used, each corresponding to a role. They are made to simulate their respective roles and chat, generating only one round of utterance at a time, updating the text, and switching back and forth to complete the entire dialogue; each dialogue lasts for N rounds.
[0024] A scalable and secure role prompting system for role-based dialogue is provided, the role prompting system using the method described above for building scalable and secure role prompting for role-based dialogue, the role prompting system comprising,
[0025] Build modules for constructing composite role hints;
[0026] The optimization module is used to improve the security of combined role prompts;
[0027] The simulated dialogue module is used for role-playing dialogue simulation.
[0028] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the method described above.
[0029] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the above-described method.
[0030] The beneficial effects of this invention are:
[0031] This invention provides a wide variety of secure role prompts that can be easily applied to downstream tasks.
[0032] This invention employs three automated methods to optimize the safety of role prompts, mitigating potential biases and stereotypes in their application to downstream tasks.
[0033] This invention can automatically generate role-based dialogue data by combining generated role prompts, reducing the reliance of role-based dialogue on manually constructed data.
[0034] The combined role tags constructed by this invention are highly flexible, reusable, and easy to expand.
[0035] This invention avoids the biases and stereotypes that may result from directly using LLMs to simulate characters for role-playing dialogue.
[0036] The role-based dialogue data automatically generated by the framework of this invention can be used to enhance the role-based dialogue capabilities of other less capable LLMs, reducing the need for manually labeled data. Attached Figure Description
[0037] Figure 1 This is a schematic diagram of the structure of the present invention.
[0038] Figure 2 This is a flowchart of the method of the present invention. Detailed Implementation
[0039] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods are omitted so as not to obscure the description of this application with unnecessary detail.
[0040] It should be understood that, when used in this specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.
[0041] It should also be understood that the terminology used in this application specification is for the purpose of describing particular embodiments only and is 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 the plural forms unless the context clearly indicates otherwise.
[0042] The following is in conjunction with the appendix to this application specification. Figure 1 The technical solutions in the embodiments of this application are clearly and completely described. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0043] Many specific details are set forth in the following description in order to provide a full understanding of this application. However, this application may also be implemented in other ways different from those described herein. Those skilled in the art can make similar extensions without departing from the spirit of this application. Therefore, this application is not limited to the specific embodiments disclosed below.
[0044] Implementation Method 1
[0045] Combination Figure 1This embodiment provides a method for building scalable and secure role prompts for role-based dialogue, the method including the following steps:
[0046] Step 1: Constructing composite character hints;
[0047] Furthermore, step 1 specifically involves integrating personality traits, definable groups, and optional components to construct an extensible, combinatorial role cue.
[0048] Compared to the fixed roles of the past, the method of this invention defines roles as a combination of A+B+C.
[0049] A (Personality traits) + B (Definable groups) + C (Optional, such as hobbies, personal experiences, and other descriptive sentences)
[0050] Part A represents representative personality traits. These personality traits significantly influence human thinking, feeling, and behavioral patterns, and are strongly correlated with language use. This invention uses five common adjectives from the Big Five personality theory to describe five aspects of human personality as Part A.
[0051] Part B consists of definable group names, such as various occupational terms, "teenagers," "science fiction fans," etc. This invention chooses groups rather than specific individuals as the simulation subjects because LLMs require additional personal information to simulate a specific person, and information about most individuals is too sparse for the weighting of LLMs. Secondly, biases and stereotypes based on groups are more relevant and valuable in reality. LLMs themselves contain sufficient knowledge; this invention prompts LLMs to directly generate a specified number of representative group names as Part B.
[0052] Part C is optional and can be customized in unlimited quantities. It uses sampled sentences to describe a character's interests, hobbies, personal experiences, etc. This part can be explicitly reflected in the response.
[0053] By employing this flexible, combinable role cues and invoking relevant knowledge from LLMs to describe multiple roles, it is easy to expand upon diverse roles, which can alleviate the problem of role data imbalance to some extent. Furthermore, this invention uses descriptive sentences in the constructed role cues, making the subsequent generation of role-based dialogues very natural, and the textual information has a high degree of transparency.
[0054] Step 2: Optimize security based on the combined role prompts in Step 1;
[0055] Furthermore, step 2 specifically involves optimizing the initial role prompts to make them safer through three human behavior simulations: introspection, expert perspective, and brainstorming.
[0056] Furthermore, directly applying the constructed initial role cues to downstream tasks inevitably introduces some security issues (primarily concerns social bias and stereotypes). Given the feasibility of LLMs simulating human behavior, this invention proposes three optimization methods inspired by everyday phenomena.
[0057] 1) Introspection. Recent research indicates that LLMs possess some human-like characteristics, such as self-improvement and reasoning abilities. A certain size of LLM population can possess the capacity for moral self-correction. Therefore, the method of this invention prompts LLMs to introspect, reflect on themselves, determine whether previously generated descriptions of their roles contain biases and stereotypes, and make appropriate corrections.
[0058] 2) Expert Perspective. This invention's method allows LLMs to assume the role of outstanding experts, unleashing their potential. Specifically, it designs sociological expert prompts, providing task-related identity definitions and descriptions, allowing LLMs to act as sociological experts and offer valuable insights from an authoritative expert's perspective.
[0059] 3) Brainstorming. The interaction of multiple cognitive processes may outweigh individual contributions. The method of this invention combines the brainstorming of multiple LLMs to refine the initial prompt. Specifically, each LLM-driven dialogue agent expresses its own insights and opinions, and the initial dialogue agent makes the final judgment based on the group's opinions.
[0060] Finally, a selector is built to choose the final optimization suggestion from the three methods.
[0061] Step 3: Based on the security optimization in Step 2, conduct simulated role-playing dialogue.
[0062] Furthermore, step 3 specifically involves using generated role prompts to guide two LLM-driven dialogue agents in role-based dialogue.
[0063] Furthermore, while gradient-free techniques are effective in LLMs, the need for smaller, trainable, or fine-tunable models remains in real-world scenarios due to cost constraints, response time, or security and privacy concerns. To address these issues, the method of this invention utilizes LLMs to simulate roles, thereby generating data for role-based dialogue. This not only overcomes the limitations of traditional methods in terms of scale and complexity but also provides a feasible perspective for studying human communication patterns across different roles.
[0064] This invention employs two LLM-driven dialogue agents, each corresponding to a specific role. These agents simulate their respective roles in a conversation, generating only one round of dialogue at a time, updating the text, and switching back and forth to complete the entire dialogue. Certain dialogue requirements are set, such as requiring them to not only talk about themselves but also ask questions. When simulating a role, they cannot simply use the role's descriptive sentences directly. Each dialogue lasts N rounds.
[0065] In summary, based on the steps described above, the method of this invention can flexibly provide a large number of diverse and secure role prompts, which can be directly applied to downstream tasks. Furthermore, the method of this invention can automatically generate role-based dialogue data, promoting the application of data-driven methods.
[0066] Specifically, (1) Quality analysis of generated role-based dialogue data
[0067] The dataset generated by the method of this invention was compared with manually annotated datasets commonly used in the field of role-based dialogue (with the same number of samples) on different dimensions. As shown in Table 1, the data generated by the method of this invention is superior to or close to the sampled data in both traditional evaluation metrics (role consistency, toxicity, and duplication rate) and GPT-4 simulated evaluation metrics (coherence, consistency, engagement, and security).
[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] This invention uses two popular small-scale pre-trained dialogue models (DialoGPT and BlenderBot) as experimental subjects for security performance evaluation. Security assessment is conducted using SAFETYKIT, an open-source toolkit that integrates many existing security detection tools, evaluating two phenomena: the generation of unsafe content and endorsements that promote unsafe content. The tool reports the percentage of generated responses marked as unsafe. This invention compares the model's performance before and after fine-tuning on the generated data. The evaluation results are shown in Table 2. It can be observed that, compared with the original model, the model fine-tuned on the data generated by the method of this invention shows a significant improvement in security performance. This demonstrates the superiority of the method of this invention in terms of security performance.
[0072] Table 2. Impact of generated dialogue data on the security performance of small-scale models
[0073]
[0074] (3) Evaluation of the role-based performance of the method
[0075] To evaluate the performance of the method of this invention in role-based dialogue tasks, experiments were conducted using open-source LLMs fine-tuned on generated data and LLMs fine-tuned with supervised instructions and role-cues. Specifically, the Llama 2 series (7B and 13B) and the Vicuna (13B) were selected. The results of automatic and human evaluation are shown in Tables 3 and 4, respectively. For the automatic evaluation results, the fine-tuned pre-trained model outperformed the corresponding supervised instruction fine-tuned model in role consistency and overlap with human standard responses, demonstrating the value of the generated data for role-based dialogue and the effectiveness of the method of this invention in role-based dialogue. In human evaluation, the fine-tuned pre-trained model had higher win rates in consistency and coherence. However, the supervised instruction fine-tuned model with role cues outperformed the fine-tuned pre-trained model in attractiveness and overall metrics. This indicates that the role cues generated by the method of this invention are effective for role-based dialogue. In addition to task-specific metrics, the cue-based method is more flexible and generalizable, especially on larger-scale models.
[0076] Table 3 Automatic Evaluation Results
[0077]
[0078] Table 4. Results of manual evaluation
[0079]
[0080] Implementation Method 2
[0081] 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 simulated dialogue module.
[0082] The building module is used for constructing composite role prompts;
[0083] The optimization module is used to perform security optimization on combined role prompts;
[0084] The simulated dialogue module is used to conduct simulated role-playing dialogues.
[0085] Furthermore, the working principle of the building module is to integrate personality traits, definable groups, and optional components to construct scalable, combinatorial role cues.
[0086] Compared to the fixed roles of the past, the method of this invention defines roles as a combination of A+B+C.
[0087] A (Personality traits) + B (Definable groups) + C (Optional, such as hobbies, personal experiences, and other descriptive sentences)
[0088] Part A represents representative personality traits. These personality traits significantly influence human thinking, feeling, and behavioral patterns, and are strongly correlated with language use. This invention uses five common adjectives from the Big Five personality theory to describe five aspects of human personality as Part A.
[0089] Part B consists of definable group names, such as various occupational terms, "teenagers," "science fiction fans," etc. This invention chooses groups rather than specific individuals as the simulation subjects because LLMs require additional personal information to simulate a specific person, and information about most individuals is too sparse for the weighting of LLMs. Secondly, biases and stereotypes based on groups are more relevant and valuable in reality. LLMs themselves contain sufficient knowledge; this invention prompts LLMs to directly generate a specified number of representative group names as Part B.
[0090] Part C is optional and can be customized in unlimited quantities. It uses sampled sentences to describe a character's interests, hobbies, personal experiences, etc. This part can be explicitly reflected in the response.
[0091] By employing this flexible, combinable role cues and invoking relevant knowledge from LLMs to describe multiple roles, it is easy to expand upon diverse roles, which can alleviate the problem of role data imbalance to some extent. Furthermore, this invention uses descriptive sentences in the constructed role cues, making the subsequent generation of role-based dialogues very natural, and the textual information has a high degree of transparency.
[0092] Furthermore, the optimization module works by simulating three human behaviors—introspection, expert perspective, and brainstorming—to optimize the initial role prompts and make them safer.
[0093] Furthermore, directly applying the constructed initial role cues to downstream tasks inevitably introduces some security issues (primarily concerns social bias and stereotypes). Given the feasibility of LLMs simulating human behavior, this invention proposes three optimization methods inspired by everyday phenomena.
[0094] 4) Introspection. Recent research indicates that LLMs possess some human-like characteristics, such as self-improvement and reasoning abilities. A certain number of LLMs can possess the capacity for moral self-correction. Therefore, the method of this invention prompts LLMs to introspect, reflect on themselves, determine whether previously generated descriptions of their roles contain biases and stereotypes, and make appropriate corrections.
[0095] 5) Expert Perspective. This invention's method allows LLMs to assume the role of outstanding experts, unleashing their potential. Specifically, it designs sociological expert prompts, providing task-related identity definitions and descriptions, allowing LLMs to act as sociological experts and offer valuable insights from an authoritative expert's perspective.
[0096] 6) Brainstorming. The interaction of multiple cognitive processes may outweigh individual contributions. The method of this invention combines the brainstorming of multiple LLMs to refine the initial prompt. Specifically, each LLM-driven dialogue agent expresses its own insights and opinions, and the initial dialogue agent makes the final judgment based on the group's opinions.
[0097] Finally, a selector is built to choose the final optimization suggestion from the three methods.
[0098] Furthermore, the simulated dialogue module works by using generated role prompts to guide two LLM-driven dialogue agents in role-based dialogue.
[0099] Furthermore, while gradient-free techniques are effective in LLMs, the need for smaller, trainable, or fine-tunable models remains in real-world scenarios due to cost constraints, response time, or security and privacy concerns. To address these issues, the method of this invention utilizes LLMs to simulate roles, thereby generating data for role-based dialogue. This not only overcomes the limitations of traditional methods in terms of scale and complexity but also provides a feasible perspective for studying human communication patterns across different roles.
[0100] This invention employs two LLM-driven dialogue agents, each corresponding to a specific role. These agents simulate their respective roles in a conversation, generating only one round of dialogue at a time, updating the text, and switching back and forth to complete the entire dialogue. Certain dialogue requirements are set, such as requiring them to not only talk about themselves but also ask questions. When simulating a role, they cannot simply use the role's descriptive sentences directly. Each dialogue lasts N rounds.
[0101] In summary, based on the steps described above, the method of this invention can flexibly provide a large number of diverse and secure role prompts, which can be directly applied to downstream tasks. Furthermore, the method of this invention can automatically generate role-based dialogue data, promoting the application of data-driven methods.
Claims
1. A method for constructing scalable and secure role-based prompts for role-based dialogue, characterized in that, The method includes the following steps: Step 1: Constructing composite character hints; Step 2: Optimize security based on the combined role prompts in Step 1; Step 3: Based on the role prompts for security optimization in Step 2, conduct role-based dialogue simulation; Specifically, step 1 involves integrating personality traits, definable groups, and optional components to construct an extensible, combinatorial role cue. The integrated personality traits are specifically defined as follows: A represents personality traits, and the five common adjectives used in the Big Five personality theory to describe human personality are used as part A. The definable group feature specifically refers to using B to represent the group name, and using prompting LLMs to directly generate a specified number of representative group names as part B; Specifically, the optional part, represented by C, is explicitly reflected in the response; Step 2 specifically involves optimizing the initial role prompts through three human behavior simulations: introspection, expert perspective, and brainstorming. The introspection specifically refers to prompting LLMs to introspect, reflect on themselves, judge whether the previously generated descriptions of the character contain biases and stereotypes, and make appropriate corrections. The expert perspective specifically refers to providing a task-related identity definition description, allowing LLMs to act as sociology experts and offer valuable insights from the perspective of authoritative experts. The brainstorming process specifically involves allowing each LLM-driven dialogue agent to express its own insights and opinions, with the initial dialogue agent combining the group's opinions to make the final judgment. Step 3 specifically involves using generated role prompts to guide two LLM-driven dialogue agents in role-based dialogue.
2. The role prompting method according to claim 1, characterized in that, Two LLM-driven conversational agents are used, each corresponding to a role; they are made to simulate the corresponding role to chat, generating only one round of utterance at a time, updating the text and switching back and forth to complete the entire conversation; each conversation lasts for N rounds.
3. A scalable and secure role-based prompting system for role-based dialogue, characterized in that, The role prompting system uses the scalable and secure role prompting method for constructing role-based dialogue as described in any one of claims 1-2, the role prompting system comprising, Build modules for constructing composite role hints; The optimization module is used to improve the security of combined role prompts; The simulated dialogue module is used for role-playing dialogue simulation.
4. A computer device, characterized in that, It includes 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, it implements the method as described in any one of claims 1-2.
5. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method described in any one of claims 1-2.
Citation Information
Patent Citations
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