Role interaction method and device, electronic equipment and storage medium
Through the method based on structured character portraits and character style reply models, the problem of lack of depth and reality in role-playing in the prior art is solved, and a higher quality and immersive user interaction is achieved.
Patent Information
- Application Number
- CN202510057241.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-14
- Publication Date
- 2025-06-06
AI Technical Summary
The existing technology cannot fully demonstrate the complexity and depth of the role in character play, resulting in the role being flat, lacking the richness of details, and having a poor sense of reality.
Reply to user input in the style of the target character by obtaining the current user input and based on the structured character portrait of the target character. Structured character portraits are determined based on introduction information related to the target role, and are combined with the character style reply model and matching information in the hotspot knowledge base.
It realizes the consistency and authenticity of the target roles during the dialogue process, improves the quality of conversations with users and the immersion of users, and provides a more personalized and rich communication experience.
Smart Images

Figure CN120104728A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a role interaction method, device, electronic device and storage medium. Background Art
[0002] With the rapid development of artificial intelligence technology, especially the progress in natural language processing (NLP) and machine learning, the ability of chatbots in simulating human conversations has been significantly improved. They can provide responses based on user input and play a role in various application scenarios, such as customer service support, educational guidance, entertainment interaction, etc.
[0003] In the current technical environment, one of the solutions for character role-playing is to simply embed the character description into the prompt of a large language model as a reply prompt. This solution mainly relies on the large language model's ability to follow the style and prompt information. However, this method has certain limitations because it cannot fully demonstrate the complexity and depth of the character and can only provide some basic character information, resulting in the character appearing flat, lacking in detail and poor in realism. Summary of the invention
[0004] The present invention provides a role interaction method, device, electronic device and storage medium to solve the defects existing in the related art.
[0005] The present invention provides a role interaction method, comprising: Get the current user input; Based on the structured character portrait of the target character, reply to the current user input in the style of the target character; The structured character portrait is determined based on the introduction information related to the target role.
[0006] According to a role interaction method provided by the present invention, the structured character portrait based on the target role and the response to the current user input in the style of the target role include: Based on the structured character portrait, applying a character style response model to respond to the current user input in the style of the target character; The role style response model is trained based on the dialogue data related to the target role, and the dialogue data contains the response style corpus of the target role.
[0007] According to a role interaction method provided by the present invention, based on the structured character portrait, applying a role style reply model to reply to the current user input in the style of the target character includes: Based on the current user input, determining matching information in a hotspot knowledge base; The matching information and the structured character portrait and prompt information are fused, and the fusion result is input into the role style response model to obtain the current response content output by the role style response model.
[0008] According to a role interaction method provided by the present invention, the structured character portrait based on the target role is used to reply to the current user input in the style of the target role, and then includes: At least one of the introduction information, the conversation data, and the hotspot knowledge base is updated in real time.
[0009] According to a role interaction method provided by the present invention, the role style response model is obtained by training a large language model based on the dialogue data using LoRA technology.
[0010] According to a role interaction method provided by the present invention, the introduction information includes at least one of document data, picture data, audio and video data, and graphic and text data.
[0011] The present invention also provides a role interaction device, comprising: The acquisition module is used to obtain the current user input; The reply module is used to reply to the current user input in the style of the target character based on the structured character portrait of the target character; the structured character portrait is determined based on the introduction information related to the target character.
[0012] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, any of the above-mentioned character interaction methods is implemented.
[0013] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the character interaction method described in any one of the above is implemented.
[0014] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the above-mentioned role interaction methods.
[0015] The character interaction method, device, electronic device and storage medium provided by the present invention first obtain the current user input; then based on the structured character portrait of the target character, reply to the current user input in the style of the target character; the structured character portrait is determined based on the introduction information related to the target character. The method introduces the structured character portrait of the target character, which can accurately understand and simulate the details of the character, experience and relationship of the target character, ensure the consistency and authenticity of the target character during the dialogue process, not only improve the dialogue quality with the user, but also enhance the user's immersion and improve the user experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the present invention or related technologies, the drawings required for use in the embodiments or related technical descriptions are briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0017] Figure 1 This is one of the flow charts of the role interaction method provided by the present invention.
[0018] Figure 2 It is a flow chart of the LoRA technology in the role interaction method provided by the present invention.
[0019] Figure 3 This is the second structural diagram of the role interaction method provided by the present invention.
[0020] Figure 4 It is a structural schematic diagram of the role interaction device provided by the present invention.
[0021] Figure 5 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0022] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0023] In the current technical environment, character role-playing schemes are mainly divided into two categories. The first category is to simply embed the character description into the prompt information of the large language model as a reply prompt. This scheme mainly relies on the large language model's ability to follow the style and prompt information. However, the large language model used in this method does not know the detailed information about the character, and cannot fully show the complexity and depth of the character. It can only provide some basic character information, which makes the character appear flat, lacks rich details, and has poor realism.
[0024] The second type of character role-playing scheme is to train a special role-playing model by using corpus related to a specific character, which can generate richer and more realistic character performances based on specific character characteristics and background stories. However, this method has very high requirements on the quality of training data and requires a large amount of high-quality corpus related to specific characters. Even with high-quality training data, the role-playing model may still not accurately grasp the details of the character and cannot fully replicate the uniqueness of the character.
[0025] Based on this, a role interaction method is provided in an embodiment of the present invention.
[0026] Figure 1 FIG. 1 is a flow chart of a role interaction method provided in an embodiment of the present invention, such as Figure 1 As shown, the method includes: S1, get the current user input; S2, based on the structured character portrait of the target character, replying to the current user input in the style of the target character; The structured character portrait is determined based on the introduction information related to the target role.
[0027] Specifically, the role interaction method provided in the embodiment of the present invention is executed by a role interaction device, which can be configured in an electronic device. The electronic device can be a computer or a dialogue robot. The computer can be a local computer or a cloud computer. The local computer can be a computer, a tablet, etc., which is not specifically limited here.
[0028] First, step S1 is executed to obtain the current user input. It is understandable that the user and the execution subject may include one or more rounds of dialogue. When one round of dialogue is included, the current user input may be a question. When multiple rounds of dialogue are included, the current user input may be the input content fed back by the user based on the previous reply content provided by the execution subject to the user in the previous round of dialogue, or may be a new question input by the user, which is not specifically limited here.
[0029] Then, step S2 is performed to use the structured character portrait of the target character to reply to the current user input in the style of the target character. The target character may be a character selected by the user to have a conversation with. The target character may be a historical figure, a film and television character, a fairy tale character, etc., which is not specifically limited here.
[0030] The structured character portrait of the target character can be determined through the introduction information related to the target character. The content of the introduction information related to the target character may include but is not limited to the character's background story, personality traits, appearance description, interests and hobbies, etc., and various attributes of the target character can be described and classified in detail. Through the structured parsing model, the introduction information is structured and parsed to obtain a structured character portrait.
[0031] The format of the introduction information may include at least one of document data, image data, audio and video data, and graphic data. The structured parsing model may first convert the introduction information into an introduction text, and then use natural language processing (NLP) technology, such as named entity recognition (NER), dependency syntax analysis, etc., to extract key information from the introduction text. The key information may include the basic information, personality characteristics, behavioral habits, etc. of the target character. By converting the key information into a structured data format, such as JSON or XML, a structured character portrait of the target character can be obtained. The structured character portrait of the target character can be used as a knowledge base for responding to the current user input.
[0032] The style of the target character can be realized by training a character style response model through the dialogue data related to the target character, and the character style response model can give a response content that conforms to the style of the target character according to the input content. It is understandable that the dialogue data can be obtained by preliminary screening through preset rules and a large language model to ensure that it meets the basic dialogue requirements and standards.
[0033] Furthermore, the structured character portrait and the current user input can be input into the role style response model together, and the role style response model can search for information matching the current user input from the structured character portrait as the current response content.
[0034] The role interaction method provided in the embodiment of the present invention first obtains the current user input; then based on the structured character portrait of the target character, the current user input is replied in the style of the target character; the structured character portrait is determined based on the introduction information related to the target character. The method introduces the structured character portrait of the target character, which can accurately understand and simulate the details of the character, experience, and relationship of the target character, ensure the consistency and authenticity of the target character during the dialogue process, and can not only improve the dialogue quality with the user, but also enhance the user's immersion and improve the user experience.
[0035] On the basis of the above embodiment, the structured character portrait based on the target character, and replying to the current user input in the style of the target character, includes: Based on the structured character portrait, applying a character style response model to respond to the current user input in the style of the target character; The role style response model is trained based on the dialogue data related to the target role, and the dialogue data contains the response style corpus of the target role.
[0036] Specifically, when using the structured character portrait of the target character to reply to the current user input in the style of the target character, the structured character portrait can be first used to apply the character style reply model to reply to the current user input in the style of the target character.
[0037] The character style response model can take a structured character portrait and current user input as input, and output the current response content that matches the style of the target character.
[0038] The role style response model can be trained by dialogue data related to the target role. The role style response model can be obtained by training the initial model with a large language model (LLM) using dialogue data. The dialogue data can include the response style corpus of the target role, that is, the response corpus in the dialogue data is obtained by responding in the style of the target role.
[0039] In the embodiment of the present invention, the role style reply model is applied, so that the current reply content meets the style of the target role and better meets the user's needs. Moreover, by applying the role style reply model, the reply efficiency can be greatly improved.
[0040] Since the existing role-playing model is trained based on historical data, it lacks the ability to discuss real-time hot topics and cannot timely reflect the dynamic changes of real-time hot topics. Based on this, on the basis of the above embodiment, the structured character portrait is used to apply the role style reply model to reply to the current user input in the style of the target character, including: Based on the current user input, determining matching information in a hotspot knowledge base; The matching information and the structured character portrait and prompt information are fused, and the fusion result is input into the role style response model to obtain the current response content output by the role style response model.
[0041] Specifically, when applying the role style reply model, the current user input can also be used to determine the matching information in the hot knowledge base. The hot knowledge base can store hot content within the current preset time period and is maintained manually. Here, the hot content can be a hot topic or a hot event.
[0042] Using the vector mapping model, the current user input and each hot content in the hot knowledge base can be converted into vectors, and the vector similarity is calculated, and the first specified number of hot content with high vector similarity is selected from the hot knowledge base as matching information. The vector mapping model can ensure that the hot content can be matched quickly and accurately through complex algorithms and big data support.
[0043] After that, the matching information and structured character portraits can be integrated with prompt information, which is a pre-set instruction. The introduction of this prompt information can guide users to express their opinions and ideas, making the conversation biased towards popular content or content that users are potentially interested in, thereby promoting the development of the conversation in a deeper and broader direction.
[0044] By fusing the matching information with the structured character portrait and prompt information, a fusion result can be obtained. The fusion result is input into the role-style response model, so that the role-style response model can output the current response content according to the given hot content, thereby guiding users to participate and conduct more in-depth discussions.
[0045] The fusion results used in the embodiments of the present invention not only provide hot content, but also guide users to discuss recent hot content or in-depth topics that may arouse users' interest, thereby promoting the conversation to develop in a more in-depth and broad direction, and generating a high-quality current reply content that has both a unique perspective and rich information. The current reply content not only reflects the current hot content, but also incorporates the user's personal insights, making the interaction process more vivid and valuable, optimizing the user experience and promoting in-depth discussions, improving user participation, and avoiding the monotony and boredom of the interaction process.
[0046] Since the existing role-playing models are usually insufficient to meet the user's demand for highly personalized experience, based on this, on the basis of the above embodiment, the structured character portrait based on the target character responds to the current user input in the style of the target character, and then further includes: At least one of the introduction information, the conversation data, and the hotspot knowledge base is updated in real time.
[0047] Specifically, in the embodiment of the present invention, users or developers can upload new introduction information in real time through an external interface or platform to update the introduction information, and by updating the introduction information, the structured character portrait is updated to enrich the semantic understanding ability of the dialogue model. With the addition of more introduction information, the structured character portrait will become more accurate.
[0048] Users or developers can also upload new conversation data in real time to update the conversation data. By updating the conversation data, the character style response model can be updated to make the response of the character style response model more in line with user expectations.
[0049] In addition, users or developers can also synchronously update the hot knowledge base to reflect the latest social concerns, enhance the naturalness and relevance of interactions, and ensure the timeliness and attractiveness of popular information.
[0050] In the embodiment of the present invention, by updating at least one of the introduction information, the dialogue data, and the hot knowledge base in real time, it is possible to ensure that the introduction information, the dialogue data, and the hot content in the hot knowledge base are closely connected with the personalized needs of the user, and to promote the continuous learning and evolution of the role interaction method. Moreover, it is possible to allow the user to customize the exclusive role-playing experience according to his or her own preferences, and to provide developers with more flexibility and creative space, so as to meet the personalized needs of different users and provide different users with a richer and more flexible dialogue experience.
[0051] Since existing role-playing models can only provide surface-level answers, it is difficult to explore complex or deep topics in depth. To this end, based on the above embodiments, in an embodiment of the present invention, the role-playing response model is based on the dialogue data and uses LoRA technology to train a large language model.
[0052] Specifically, LoRA technology is an efficient and accurate fine-tuning method that can significantly improve the performance and accuracy of large language models.
[0053] like Figure 2 As shown, the length of question x in the dialogue data is d, and the original weight matrix of the large language model is , LoRA technology needs to learn a weight update matrix ΔW=A×B, which aims to update the original weight matrix to minimize the loss function value.
[0054] The weight matrix of the character style response model is the updated weight matrix, which can be expressed as W1, and W1=W+ΔW=W+A*B. Among them, A is a dimension reduction matrix, B is a dimension increase matrix, and the ranks of A and B are both r, which are hyperparameters.
[0055] A is initialized to a normal distribution , B is initialized to 0. Among them, is the standard deviation of the normal distribution.
[0056] Question x is input into a large language model to obtain the first result. Question x is processed by A and B in sequence to obtain the second result. The first result is merged with the second result to obtain the third result h. The loss function is calculated using h and the answer in the dialogue data. The loss function value obtained by calculation is used to determine A and B that satisfy the minimum loss function value, thereby obtaining the character style response model.
[0057] The character style response model includes two branches connected sequentially, one branch includes a large language model, and the other branch includes A and B.
[0058] After fine-tuning the LoRA technology, the character style response model not only retains the basic dialogue response capabilities of the large language model, but can also simulate a style that matches the target character and can play the style of the target character well.
[0059] This simulation capability of the character style response model makes the dialogue more vivid and real, as if it were really spoken by the target character himself. In the embodiment of the present invention, applying LoRA technology to the field of character interaction brings new possibilities, making the dialogue of the virtual target character richer and more diverse, meeting the user's demand for personalized dialogue experience.
[0060] In an embodiment of the present invention, by adopting LoRA technology, the depth and quality of the current reply content generated by the role-style reply model can be improved, thereby providing a richer and deeper conversation experience and avoiding providing superficial reply content to users.
[0061] Based on the above embodiments, Figure 3 FIG. 1 is a complete flow chart of a role interaction method provided in an embodiment of the present invention. Figure 3 As shown, the method includes: First, the developer / user uploads the introduction information related to the customized target role, and then parses the introduction information to obtain a structured character portrait.
[0062] Subsequently, the developer / user uploads the dialogue data related to their customized target character, and through adaptive training of the large language model for the target character, a character style response model with the ability to simulate the style of the customized target character is obtained.
[0063] Next, the developer / user can upload the current user input. The role-style response model will combine the parsed structured character portrait and the matching information retrieved from the hot knowledge base through the current user input, and respond to the current user input in the style of the customized target role to obtain the current response content.
[0064] In summary, existing role-playing technical solutions have certain problems in terms of detail richness, content depth, dialogue guidance capabilities, and degree of personalized customization, which limit the quality and satisfaction of user experience. The role interaction method provided in the embodiment of the present invention automatically extracts structured character portraits from introduction information in various formats, and then combines the structured character portraits to provide highly relevant and in-depth answers to current user inputs, and can actively guide users to discuss recent hot topics or in-depth topics that may arouse user interest during the conversation. Compared with existing role-playing models, the role interaction method provided in the embodiment of the present invention has significant improvements in detail richness, content depth, and dialogue guidance capabilities, providing users with a more personalized and thought-provoking communication experience.
[0065] like Figure 4 As shown, based on the above embodiment, an embodiment of the present invention provides a role interaction device, including: The acquisition module 41 is used to acquire the current user input; The reply module 42 is used to reply to the current user input in the style of the target character based on the structured character portrait of the target character; the structured character portrait is determined based on the introduction information related to the target character.
[0066] On the basis of the above-mentioned embodiment, in the role interaction device provided in the embodiment of the present invention, the reply module is specifically used for: Based on the structured character portrait, applying a character style response model to respond to the current user input in the style of the target character; The role style response model is trained based on the dialogue data related to the target role, and the dialogue data contains the response style corpus of the target role.
[0067] On the basis of the above-mentioned embodiment, in the role interaction device provided in the embodiment of the present invention, the reply module is specifically used for: Based on the current user input, determining matching information in a hotspot knowledge base; The matching information and the structured character portrait and prompt information are fused, and the fusion result is input into the role style response model to obtain the current response content output by the role style response model.
[0068] On the basis of the above embodiment, the character interaction device provided in the embodiment of the present invention further includes an updating module, which is used to: At least one of the introduction information, the conversation data, and the hotspot knowledge base is updated in real time.
[0069] On the basis of the above-mentioned embodiment, in the character interaction device provided in the embodiment of the present invention, the character style response model is obtained by training a large language model based on the dialogue data using LoRA technology.
[0070] On the basis of the above-mentioned embodiment, in the character interaction device provided in the embodiment of the present invention, the introduction information includes at least one of document data, picture data, audio and video data and graphic data.
[0071] Specifically, the functions of each module in the role interaction device provided in the embodiment of the present invention correspond one-to-one to the operation flow of each step in the above method embodiment, and the effects achieved are also consistent. Please refer to the above embodiment for details, which will not be repeated in the embodiment of the present invention.
[0072] Figure 5 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 5 As shown, the electronic device may include: a processor 510, a communication interface 520, a memory 530 and a communication bus 540, wherein the processor 510, the communication interface 520 and the memory 530 communicate with each other through the communication bus 540. The processor 510 may call the logic instructions in the memory 530 to execute the role interaction method provided in the above embodiments.
[0073] In addition, the logic instructions in the above-mentioned memory 530 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, or the part that contributes to the relevant technology or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable 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 method described in each embodiment 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 and other media that can store program codes.
[0074] On the other hand, the present invention also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the role interaction method provided in the above embodiments.
[0075] In yet another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which is implemented when the computer program is executed by a processor to execute the role interaction method provided in the above embodiments.
[0076] 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 displayed as units may or may not be physical units, that is, 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. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0077] 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, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology 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 embodiment.
[0078] 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 role interaction method, characterized in that: include: Get the current user input; Based on the structured character portrait of the target character, reply to the current user input in the style of the target character; The structured character portrait is determined based on the introduction information related to the target role.
2. The role interaction method according to claim 1, characterized in that: The step of responding to the current user input in the style of the target character based on the structured character portrait of the target character includes: Based on the structured character portrait, applying a character style response model to respond to the current user input in the style of the target character; The role style response model is trained based on the dialogue data related to the target role, and the dialogue data contains the response style corpus of the target role.
3. The role interaction method according to claim 2, characterized in that: The step of applying a role style response model based on the structured character portrait to respond to the current user input in the style of the target character includes: Based on the current user input, determining matching information in a hotspot knowledge base; The matching information and the structured character portrait and prompt information are fused, and the fusion result is input into the role style response model to obtain the current response content output by the role style response model.
4. The role interaction method according to claim 3, characterized in that: The structured character portrait based on the target character is used to respond to the current user input in the style of the target character, and then includes: At least one of the introduction information, the conversation data, and the hotspot knowledge base is updated in real time.
5. The role interaction method according to claim 2, characterized in that: The role-style response model is obtained by training a large language model based on the dialogue data using LoRA technology.
6. The role interaction method according to any one of claims 1 to 5, characterized in that: The introduction information includes at least one of document data, picture data, audio and video data, and graphic and text data.
7. A character interaction device, characterized in that: include: The acquisition module is used to obtain the current user input; A reply module, used for replying to the current user input in the style of the target character based on the structured character portrait of the target character; The structured character portrait is determined based on introduction information related to the target role.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the role interaction method according to any one of claims 1 to 6 is implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the character interaction method according to any one of claims 1 to 6 is implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the character interaction method according to any one of claims 1 to 6 is implemented.