Multi-style dialogue model training method, multi-style dialogue method and computer program product
By constructing multi-style question-and-answer sample pairs and multi-turn dialogue data models, and combining them with LoRA technology for fine-tuning, the problem of monotonous language style in cooking-related dialogue models was solved, enabling personalized interaction with diverse styles and improving user experience and contextual understanding.
Patent Information
- Application Number
- CN202511504145.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-21
- Publication Date
- 2026-01-16
AI Technical Summary
Existing cooking-related dialogue models have a monotonous language style, lack emotional expression and personalized features, and are unable to meet users' personalized interaction needs in scenarios such as family life.
By constructing multi-style question-and-answer sample pairs and multi-turn dialogue data models, training multi-style dialogue models, and fine-tuning them using LoRA technology, responses with different language styles such as humor, humanities, and professionalism are generated.
It enables the output of answers in diverse language styles based on user preferences, enhancing the naturalness and friendliness of the user experience, and strengthening contextual understanding and continuous interaction capabilities.
Smart Images

Figure CN121350618A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of large language model technology, and more specifically, to a multi-style dialogue model training method, a multi-style dialogue method, and a computer program product. Background Technology
[0002] With the current trend of intelligent dialogue systems being widely applied in vertical industries, cooking information services are gradually evolving from the traditional static recipe query mode to intelligent, interactive question-and-answer systems. Cooking assistants based on large language models can understand questions posed by users in natural language and generate semantically coherent and content-related answers, significantly improving the convenience of information retrieval and response efficiency.
[0003] However, existing cooking-related dialogue models typically employ standardized, formulaic professional language in their responses. Their style tends to be formal, objective, and function-oriented, such as: "Braised pig ears take 30 to 40 minutes to cook and require the use of spices like star anise and cinnamon." While such responses possess a degree of accuracy and practicality, their mechanical and rigid expression lacks emotional depth and personalization, failing to create a warm and engaging interactive atmosphere. For ordinary family users seeking a relaxed and enjoyable experience, this textbook-style response can easily create a sense of alienation, weakening user engagement and stickiness. Summary of the Invention
[0004] In view of this, the purpose of this invention is to provide a multi-style dialogue model training method, a multi-style dialogue method, and a computer program product to at least partially improve the above-mentioned problems.
[0005] To achieve the above objectives, the technical solutions adopted in the embodiments of the present invention are as follows: In a first aspect, embodiments of the present invention provide a method for training a multi-style dialogue model, including: Obtain a set of user questions and a set of knowledge fragments; wherein, the set of user questions includes multiple user questions, and the set of knowledge fragments includes multiple knowledge fragments; Each of the user questions is input into a general large language model, and after being constrained by multiple style types, multiple question-answer sample pairs with different styles are obtained; Each of the multiple knowledge fragments is input into the general large language model, and the general large language model is used to conduct self-dialogue to generate multi-turn dialogue data samples. The baseline model is trained using question-and-answer sample pairs of different styles and multi-turn dialogue data samples of different styles to obtain a multi-style dialogue model.
[0006] Optionally, the step of inputting each user question into a general large language model, and subjecting it to constraints of multiple style types, yields multiple question-answer sample pairs with different styles, including: For each user question, the user question is input into a general large language model to obtain a detailed answer from the general large language model; The detailed answer is input into a general large language model and subjected to constraints of multiple style types to generate multiple simplified answers in different styles. The user questions and their brief answers are combined to form question-and-answer sample pairs.
[0007] Optionally, the detailed answer is input into a general large language model and subjected to constraints of multiple style types to generate multiple simplified answers in different styles, including: Get multiple preset style types; The style types and detailed answers are combined to form corresponding prompt words; Input each of the aforementioned prompt words into the general large language model to obtain a simplified answer for each of the aforementioned style types.
[0008] Optionally, the step of inputting each of the multiple knowledge fragments into the general large language model, and generating multi-turn dialogue data samples through the general large language model to perform self-dialogue includes: For each knowledge fragment, an empty question-and-answer list is initialized; the question-and-answer list represents a multi-turn dialogue, and the knowledge fragment is the topic of the multi-turn dialogue; The question-and-answer list and the knowledge fragments are assembled with multiple preset style types into multiple prompt words; Each of the aforementioned prompt words is input into the general large language model to conduct self-dialogue, generating multi-turn dialogue data samples.
[0009] Optionally, the step of inputting each of the prompt words into the general large language model to perform self-dialogue and generate multi-turn dialogue data samples includes: Based on the prompt words, a simulated user question is generated using the general large language model; Based on the simulated user question and the prompt words, a simulated question answer is generated using the general large language model; Add the simulated user questions and their answers to the question-and-answer list; Determine whether the number of dialogue rounds in the question-and-answer list has reached a preset threshold; If not, then continue to generate simulated user questions and simulated question answers based on the question and answer list until the number of dialogue rounds in the question and answer list reaches a preset threshold.
[0010] Optionally, the step of training the baseline model using question-answer sample pairs of different styles and multi-turn dialogue data samples to obtain a multi-style dialogue model includes: Based on the question-and-answer sample pairs described above, the baseline model is fine-tuned and trained using LoRA technology to obtain a multi-style dialogue model that includes multiple style adapters. The multi-style dialogue model is fine-tuned and trained again using the multi-turn dialogue data samples to obtain a multi-style dialogue model with improved context understanding capabilities.
[0011] Optionally, the step of fine-tuning the baseline model using LoRA technology based on each of the question-and-answer sample pairs to obtain a multi-style dialogue model including multiple style adapters includes: For any of the question-and-answer sample pairs, the question-and-answer sample pair is input into the baseline model; Based on the style type in the question-and-answer sample pairs, the LoRA controller is used to find the corresponding target style adapter, and the target style adapter is loaded into the baseline model; The baseline model is trained once using the question-and-answer samples. By iterating through each question-and-answer sample pair, the baseline model is trained once using the question-and-answer samples to obtain a multi-style dialogue model that includes multiple style adapters.
[0012] Secondly, embodiments of the present invention provide a multi-style dialogue method, including: Obtain the style type selected by the user and the content of the question entered by the user; The style type and the question content are input into the multi-style dialogue model to obtain the answer corresponding to the style type; the multi-style dialogue model is trained by the multi-style dialogue model training method described in any of the above.
[0013] Thirdly, embodiments of the present invention provide a computer program product, the computer program product including instructions, which, when executed on an electronic device, cause the electronic device to perform the method described in any of the above-mentioned embodiments.
[0014] The present invention provides a multi-style dialogue model training method, a multi-style dialogue method, and a computer program product. By constructing question-answer sample pairs of multiple styles for the same question, the trained model can output answers with different language styles such as humor, humanities, and professionalism according to the user's selection, thus solving the problem that traditional models can only output a single style.
[0015] To make the above-mentioned objectives, features and advantages of this application more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0016] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 A schematic structural block diagram of an electronic device provided in an embodiment of the present invention; Figure 2 This is one of the flowcharts illustrating a multi-style dialogue model training method provided in an embodiment of the present invention; Figure 3 This is a second flowchart illustrating a multi-style dialogue model training method provided in an embodiment of the present invention. Figure 4 The third flowchart illustrates a multi-style dialogue model training method provided in this embodiment of the invention. Figure 5 The fourth flowchart illustrates a multi-style dialogue model training method provided in this embodiment of the invention. Figure 6 The fifth flowchart illustrates a multi-style dialogue model training method provided in this embodiment of the invention. Figure 7 A flowchart illustrating a multi-style dialogue model training method provided in an embodiment of the present invention is shown in Figure 6. Figure 8 The seventh flowchart illustrates a multi-style dialogue model training method provided in this embodiment of the invention. Figure 9 This is a flowchart illustrating a multi-style dialogue method provided in an embodiment of the present invention.
[0018] Icons: 100 - Electronic device; 101 - Memory; 102 - Communication interface; 103 - Processor; 104 - Communication bus. Detailed Implementation
[0019] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0020] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0021] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this invention, terms such as "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0022] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0023] In related technologies, while cooking-related dialogue systems based on large language models can accurately answer user questions, their language style is generally monotonous, lacking emotional expression and personalized features, making it difficult to meet the personalized needs of different users in diverse interaction scenarios. The standardized and formulaic response methods limit the naturalness and friendliness of the user experience, especially in non-professional scenarios such as family life and leisure activities, where users prefer humorous, vivid, or culturally rich responses rather than cold, functional statements.
[0024] Based on the above, embodiments of the present invention provide a multi-style dialogue model training method, a multi-style dialogue method, and a computer program product. By constructing question-and-answer samples covering multiple language styles to train a multi-turn dialogue data model, the trained model can output answers in different language styles according to the user's selection.
[0025] To implement the process steps and functions of the various examples of this invention, please refer to [link / reference]. Figure 1 , Figure 1This is a schematic structural block diagram of an electronic device provided in an embodiment of the present invention. The electronic device 100 includes a memory 101 and a processor 103, which are electrically connected directly or indirectly to each other to achieve data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses 104 or signal lines. The memory 101 can be used to store software programs and modules, and the processor 103 executes the software programs and modules stored in the memory 101, thereby performing various functional applications and data processing.
[0026] Electronic device 100 can be, but is not limited to, a personal computer (PC), a server, a distributed computer, etc. It is understood that electronic device 100 is not limited to a physical server, but can also be a virtual machine on a physical server, a virtual machine built on a cloud platform, or any other computer that can provide the same functionality as the server or virtual machine. The operating system of electronic device 100 can be, but is not limited to, Windows, Linux, etc.
[0027] The memory 101 may be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.
[0028] The communication connection between the electronic device 100 and external devices is achieved through at least one communication interface 102 (which can be wired or wireless).
[0029] Processor 103 may be an integrated circuit chip with signal processing capabilities. In implementation, the steps of this embodiment can be completed by integrated logic circuits in the hardware of processor 103 or by instructions in software form. Processor 103 may be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0030] Understandable. Figure 1 The structure shown is for illustrative purposes only; the electronic device 100 may also include components that are more advanced than those shown. Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown. Figure 1 The components shown can be implemented using hardware, software, or a combination thereof.
[0031] The following is an exemplary description of the multi-style dialogue model training method provided by this invention. See also... Figure 2 The subject executing this method can be one of the above. Figure 1 The electronic device 100 shown, the method includes as follows Figure 2 The following steps are described: S210: Obtain the user question set and the knowledge fragment set. The user question set includes multiple user questions, and the knowledge fragment set includes multiple knowledge fragments.
[0032] S220: Input each user's question into the general large language model, and after constraint processing of multiple style types, obtain multiple question-answer sample pairs with different styles.
[0033] S230: Input multiple knowledge fragments into the general large language model, and use the general large language model to conduct self-dialogue to generate multi-turn dialogue data samples.
[0034] S240: Train the baseline model using question-and-answer sample pairs of different styles and multi-turn dialogue data samples to obtain a multi-style dialogue model.
[0035] First, obtain two basic datasets: a set of user questions and a set of knowledge fragments.
[0036] The user question set includes several common questions from real-world cooking scenarios, such as: "How long should I cook braised pig's ears?", "Can I use olive oil instead of butter?", and "How do I make shredded pork with garlic sauce?". These questions cover a wide range of topics, from ingredient selection and heat control to dish substitutions, ensuring that the generated answers are broadly applicable. These questions were collected through online communities, user surveys, or historical interaction logs, and have been cleaned and deduplicated to form a representative set of input samples.
[0037] The knowledge fragment set contains multiple structured culinary knowledge units, each corresponding to a specific dish recipe, technique description, or ingredient introduction. Examples include "The Standard Recipe for Braised Pork Belly" and "How to Choose Fresh Salmon." Each knowledge fragment is organized in text format and can be sourced from authoritative recipe databases, professional books, or expert writings, ensuring the accuracy and completeness of the information to serve as the basis for generating subsequent answers.
[0038] For each user question in the user question set, a general large language model (such as GPT-4o, Claude 3, or other closed / open source large models with strong generation capabilities) is used for processing.
[0039] Each user's question and style control instructions are input into a general language model, guiding it to generate answers with specific language styles. Style types include, but are not limited to, humor, humanism, and professionalism, aiming to simulate the expressive characteristics of different types of "chef assistants."
[0040] By adjusting the style descriptions and example samples in the prompts, the general-purpose large language model can output diverse and distinctive concise answers. For example, for the same question, "What meat is suitable to eat in winter?", different styles but semantically consistent answers can be generated: Humorous style: "Have some mutton, it warms the body and the heart, more reliable than a boyfriend." Cultural style: "Winter is a time for nourishing the body, and there is a saying that 'eating mutton in winter is better than ginseng'..." Professional style: "It is recommended to choose lamb belly or beef shank, which are rich in myoglobin and saturated fat, which are beneficial for maintaining body temperature."
[0041] Each user question is paired with the answers generated under different styles to form multiple question-answer sample pairs with different styles, which constitute one of the core data supporting multi-style training.
[0042] To enhance the contextual understanding and continuous interaction capabilities of the multi-style dialogue model in practical use, this implementation further constructs multi-turn dialogue data. Each knowledge fragment in the knowledge fragment set is used as a topic, and a self-chat process is executed using a generalized large language model. That is, the model autonomously simulates multi-turn question-and-answer behavior between the user and the system. For example, in a self-chat process: the generalized large language model first generates an initial question based on the current knowledge topic; then it generates a response based on existing dialogue history and knowledge content; next, it raises new follow-up questions based on the previous round's answer, gradually developing a deeper exchange; the entire process continues for several rounds until a preset dialogue depth or topic convergence is reached.
[0043] Each generated multi-turn dialogue revolves around a clear knowledge topic, containing a reasonable logical progression and a natural language expression pattern, which can effectively reflect the thinking path and interaction needs of real users in the cooking process.
[0044] Finally, all generated dialogue sequences are organized into multi-turn dialogue data samples to enhance the model's ability to understand contextual dependencies and complex instructions.
[0045] After constructing the two types of training data mentioned above, the model training phase begins. A pre-trained large language model is selected as the baseline model (e.g., Qwen, Llama series, or other basic models suitable for vertical tasks). The multi-style question-answering sample pairs generated in step S220 and the multi-turn dialogue data samples generated in step S230 are used together as the training dataset to train the baseline model. After sufficient training, the resulting multi-style dialogue model has the ability to output multiple styles of answers based on user preferences or system configuration.
[0046] This method constructs multi-style question-answering sample pairs, enabling the trained model to output diverse language styles. It also uses Self-chat technology to generate multi-turn dialogue data, enhancing the model's contextual understanding and continuous interaction capabilities in real-world scenarios.
[0047] Step S220 generates multiple question-answer sample pairs with different styles by inputting the user's question into a general large language model and applying style constraints. To improve the accuracy and style controllability of the generated answers, in an optional implementation, the generation process can adopt a two-stage separation strategy: first ensuring the completeness and accuracy of the answer content, and then performing stylistic compression and expression conversion. See also Figure 3 Step S220 may include the following steps: S221: For each user question, input the user question into the general large language model to obtain a detailed answer from the general large language model.
[0048] S222: Input the detailed answer into the general large language model and process it through constraints of multiple style types to generate multiple simplified answers of different styles.
[0049] S223: Combine user questions with brief answers to form question-answer sample pairs.
[0050] For each question in the user question set, it is first input into a general large language model and configured with "detailed, accurate, and structured" output requirements to guide the model in generating a comprehensive and logically clear answer. For example, for the question "How long does it take to cook braised pig ears?", the general large language model may generate an answer that includes complete information such as raw material processing, blanching to remove the fishy smell, spice matching, stewing time, and heat control, ensuring that all the technical points required for the question are covered.
[0051] After obtaining detailed answers, a general large language model is used to further reconstruct the style of the language. For the preset multiple language style types (such as "humor", "humanistic", "professional"), corresponding prompts are constructed for each style, which include: style name; style description (such as tone features, word preference).
[0052] Then, the aforementioned prompts and the original detailed answer are input into a general-purpose language model, which is then instructed to restate the answer according to a specified style and output a concise and clear answer with a distinct style. For example, the method of making the same dish might be expressed in a humorous style, in a humanistic style it might be reflected in the use of cultural allusions, and in a professional style it might highlight parameterized guidance (such as temperature, time, and proportions). In this way, the system can generate multiple concise answers with different styles but consistent semantics for the same question, achieving "different answers for the same question, and controllable style".
[0053] Finally, the original user questions are paired with simplified answers for each style to form multiple question-answer pairs. Each pair is labeled with its corresponding style tag, which is used to guide the model in recognizing and learning output patterns of different styles during subsequent supervised training.
[0054] In one alternative implementation, see [link to implementation details]. Figure 4 Step S222 may include the following steps: S2221: Get multiple preset style types.
[0055] S2222: Assemble each style type and detailed answer into corresponding prompt words.
[0056] S2223: Input each prompt word into the general large language model to obtain simplified answers for each style type.
[0057] Several distinct language style types are pre-configured to differentiate different expression modes. These style types include, but are not limited to: Humor: using lighthearted banter, personification, or internet slang to enhance interest; Humanistic: incorporating elements of food culture, regional customs, or emotional resonance to convey warmth and sentiment; Professional: presenting information using standardized terminology, precise parameters, and rigorous logic.
[0058] Each style type is identified by a separate label, which is associated with corresponding descriptive information and a sample library, serving as the basis for the construction of subsequent prompt words.
[0059] For each preset style type, a dedicated Prompt template is built. This template includes the following components: Instruction section: explicitly requires the model to output a concise answer that conforms to a certain style; Style definition section: provides a textual description of the style (e.g., "Please express yourself in a warm and story-like way"); few-shot example section: embeds 1 to 3 labeled stylized statements as reference samples; Input content section: fills in the detailed answer generated in the previous steps.
[0060] For example, when dealing with a "humorous" style, the prompt might look like this: "Please rewrite the following cooking instructions in a humorous style, with a lighthearted and slightly teasing tone, suitable for young people: Style instructions: You can use personification, exaggeration, puns, etc., and appropriately add popular terms such as 'office slave' or 'working class'. Example 1: 'The oil temperature is too high when stir-frying? Be careful, the pan might even smoke and run away!' Example 2: 'Cook noodles for three minutes, the soul depends entirely on that last spoonful of chili oil to seal it.' Content to be converted: [Original detailed answer]."
[0061] Finally, the prompts constructed for each style are sequentially input into the general large language model, and the reasoning generation task is executed to obtain a simplified answer for the corresponding style.
[0062] Since each prompt is independent of the others and is generated based on the same detailed answer, the multiple simplified answers output maintain consistency in core information, differing only in expression, tone, and rhythm, thus meeting the data construction requirement of "synonyms with different expressions and distinct styles".
[0063] Step S230 generates multi-turn dialogue data samples to enhance the model's contextual understanding capabilities by inputting knowledge fragments into a general large language model and performing self-chat. To ensure that the generated data not only reflects real interaction logic but also demonstrates consistent expression of specific language styles, in one optional implementation, the self-dialogue process incorporates a multi-style cue word construction mechanism to support the model's ability to maintain style stability across multiple turns of interaction. See also Figure 5 Step S230 may include the following steps: S231: For each knowledge fragment, initialize an empty question-and-answer list. The question-and-answer list represents a multi-turn dialogue, and the knowledge fragment represents the topic of that dialogue.
[0064] S232: Assemble a list of questions and answers and knowledge fragments with multiple preset style types into multiple prompt words.
[0065] S233: Input each prompt word into the general large language model to conduct self-dialogue and generate multi-turn dialogue data samples.
[0066] For each knowledge fragment in the knowledge fragment set, initiate an independent multi-turn dialogue construction task.
[0067] First, initialize an empty question-and-answer list to record the historical interactions of this conversation. This list is initially empty, representing a completely new conversation; as subsequent steps proceed, it will be gradually populated with simulated user questions and system responses.
[0068] At the same time, the knowledge fragments currently being processed are set as the core topics of this multi-round dialogue to ensure that all generated content revolves around this theme and avoids deviating from the theme or losing focus on information.
[0069] To ensure the generated multi-turn dialogues possess diverse linguistic styles, corresponding prompt word templates are constructed for each preset style type (such as humorous, humanistic, or professional). Each prompt word contains the following key elements: historical dialogue content in the current question-and-answer list (initially empty); the topic of the current dialogue—i.e., a knowledge fragment; clear style identifiers and descriptive information (e.g., "Please answer in a lighthearted and joking tone"); optional few-shot style examples to reinforce style consistency; and control instructions to guide the model to simulate user follow-up questions and generate responses that match the user's role.
[0070] Each of the aforementioned prompt words is input into a general-purpose large language model, triggering a stylized self-dialogue process. In each execution: the model autonomously generates the first round of "user questions" based on the context of the prompt word; then, based on the question and knowledge fragment, it generates the first round of "system answers," which must conform to a specified style; after adding this question-and-answer pair to the question-and-answer list, the model continues to generate the next round of questions and answers based on the updated context; this process repeats until the preset maximum number of dialogue rounds is reached or the topic naturally ends. Ultimately, each prompt word generates a complete multi-turn dialogue sequence.
[0071] To ensure the generated dialogue has reasonable interaction depth and logical coherence, in one optional implementation, the self-dialogue process can employ an iterative closed-loop generation mechanism. This involves repeatedly calling the model to simulate the alternating speech between the user and the system, gradually constructing a complete multi-turn dialogue sequence. See also... Figure 6 Step S233 may include the following steps: S2331: Based on the prompt words, use a general large language model to generate a simulated user question.
[0072] S2332: Based on the simulated user question and the prompt words, use a general large language model to generate a simulated question answer.
[0073] S2333: Add simulated user questions and their answers to the question and answer list.
[0074] S2334: Determine whether the number of dialogue rounds in the question-and-answer list has reached a preset threshold.
[0075] S2335: If not, continue to generate simulated user questions and simulated question answers based on the question and answer list until the number of dialogue rounds in the question and answer list reaches a preset threshold.
[0076] After each self-dialogue task is initiated, the currently constructed prompts (including knowledge fragments, historical question-and-answer lists, style settings, etc.) are input into the general large language model, which is then instructed to act as the "user" and generate a new simulated user question based on the existing context. After obtaining the simulated user question, the general large language model is invoked again, instructing it to act as the "assistant" and, combining the original knowledge fragments, the current dialogue history, and the preset language style, generate a semantically accurate and appropriately expressed simulated question answer. The newly generated question-and-answer pair (i.e., the question from step S2331 and the answer from step S2332) is appended to the current question-and-answer list as the historical context for subsequent dialogues.
[0077] The system continuously monitors the number of dialogue rounds in the question-and-answer list (each round is defined as one question and one answer). Once the latest round of questions and answers is added, it checks if the current total number of rounds has reached a preset maximum threshold (e.g., 5 rounds). If not, it continues generating simulated user questions and answers based on the question-and-answer list until the preset threshold is reached. If so, the generation process ends.
[0078] To further improve the efficiency and modularity of model training, in one optional implementation, the training process can employ a two-stage step-by-step fine-tuning mechanism, and lightweight parameter adjustment can be achieved through LoRA technology. See also Figure 7 Step S240 may include the following steps: S241: Based on each question-answer sample pair, the baseline model is fine-tuned using LoRA technology to obtain a multi-style dialogue model that includes multiple style adapters.
[0079] S242: The multi-style dialogue model is fine-tuned and trained again using multi-turn dialogue data samples to obtain a multi-style dialogue model with improved context understanding.
[0080] First, a pre-trained large language model is selected as the baseline model, its backbone parameters are frozen, and a trainable low-rank matrix module—the LoRA adapter—is introduced only into its attention layer. For each style of question-answer sample pair generated in step S220, the following operations are performed: the sample is input into the baseline model; according to the style type of the sample, the corresponding LoRA adapter is activated; only the low-rank parameters in the LoRA module are updated, completing a local fine-tuning.
[0081] By traversing question-answer sample pairs of all style types, the unique expression patterns of each language style are gradually learned and encoded into independent style adapters (i.e., "style plugins"). This results in an intermediate model containing multiple parallel LoRA modules, capable of dynamically loading the corresponding style adapter based on input instructions, achieving precise style control output.
[0082] After completing the first stage of training, the multi-turn dialogue data samples generated in step S230 are used as the training input for the second stage to fine-tune the intermediate model that already has multi-style capabilities.
[0083] The training objective at this stage is no longer style differentiation, but rather to enhance the model's ability in continuous dialogue: context awareness, historical information memory and reference resolution, and responsiveness to control commands such as "more details" and "simply put it."
[0084] During training, the LoRA architecture remains unchanged, and the parameter-efficient fine-tuning strategy continues, updating only some parameters of the adapter or introducing a small number of additional trainable layers. Since the model already possesses basic style representation capabilities, this round of training primarily optimizes its coherence and stability in real-world interactive scenarios.
[0085] The final output model can not only switch language styles as needed, but also maintain topic consistency and accurately understand user intent in multi-turn dialogues, significantly improving the user experience in practical applications.
[0086] In one alternative implementation, see [link to implementation details]. Figure 8 Step S241 may include the following steps: S2411: For any question-answer sample pair, input the question-answer sample pair into the baseline model.
[0087] S2412: Based on the style type in the question-answer sample pair, use the LoRA controller to find the corresponding target style adapter and load the target style adapter into the baseline model.
[0088] S2413: Use question-answer samples to train the baseline model once.
[0089] S2414: Iterate through each question-and-answer sample pair, use the question-and-answer samples to train the baseline model once, and obtain a multi-style dialogue model including multiple style adapters.
[0090] Select a sample pair from the multi-style question-answering sample set generated in step S220 and input it as the current training instance into the baseline model.
[0091] The system parses the style type (e.g., "humorous") of the question-and-answer sample and performs index matching using the built-in LoRA controller. The LoRA controller maintains a mapping table between style types and LoRA adapters, for example: "humorous" → `lora_adapter_humorous`, "humanistic" → `lora_adapter_humanistic`, "professional" → `lora_adapter_professional`.
[0092] If the target adapter has not been initialized, a new low-rank matrix structure is created; if it already exists, its parameter state is loaded directly.
[0093] Subsequently, the target style adapter is injected into the relevant attention layer of the baseline model, making it the only trainable part in the current forward propagation.
[0094] After the target style adapter is loaded, perform a forward propagation to calculate the loss value (the cross-entropy loss function can be used), and then perform backpropagation to update only the trainable parameters in the LoRA module.
[0095] Since other parameters (including the backbone network and other LoRA modules of different styles) remain frozen, this training only enhances the model's ability to respond to that particular style without affecting other style features already learned.
[0096] Repeat steps S2411 to S2413 to process all question-answer sample pairs annotated with style information in sequence.
[0097] As training progresses, the LoRA adapter parameters for each style branch are gradually improved. Ultimately, adapters for all style types are independently optimized, forming a unified yet modular multi-style dialogue model.
[0098] Furthermore, embodiments of the present invention also provide a multi-style dialogue method, see [link to relevant documentation]. Figure 9 This multi-style dialogue method includes the following steps: S310: Obtain the style type selected by the user and the question content entered by the user.
[0099] S320: Input the style type and question content into the multi-style dialogue model to obtain the answer corresponding to the style type. This multi-style dialogue model is trained using the multi-style dialogue model training method described above.
[0100] Step S320 may include the following steps: The corresponding LoRA style adapter is activated based on the style type; the LoRA style adapter is obtained by fine-tuning the baseline model based on question-answering sample pairs of different styles.
[0101] The activated multi-style dialogue model is used to decode the question content and generate a natural language response with that style.
[0102] First, based on the user's selected target answer style (such as humor, humanism, or professionalism), a matching target adapter is found among several pre-defined LoRA style adapters. Each LoRA style adapter is obtained during the aforementioned training phase by applying low-rank adaptation techniques to a benchmark large language model and fine-tuning it using question-and-answer samples labeled with specific style tags. Each style adapter contains a set of low-rank decomposition matrices used to adjust the weight update direction in the model's attention layer, thereby learning the unique expression patterns of the corresponding language style, such as tone features, vocabulary preferences, and sentence structure.
[0103] Next, the found target LoRA style adapter is loaded into the key network layer of the baseline large language model (preferably the query and value projection layer of the self-attention module) to form a temporary inference model with specific style expression capabilities. During this process, the backbone parameters of the baseline model remain frozen, and variable style control signals are introduced only through the LoRA path, realizing an efficient and lightweight style switching mechanism.
[0104] Subsequently, the user's question is input into the activated multi-style dialogue model, which then performs an autoregressive decoding process to generate natural language responses that conform to the target style characteristics word by word. Since the LoRA adapter has injected style-related bias information into the forward propagation path, the generated answers are not only semantically accurate but also exhibit a clear personalization tendency in language style—for example, using witty expressions and internet slang in the "humorous" mode, incorporating food culture allusions in the "humanistic" mode, and employing terminological and parameterized guidance statements in the "professional" mode.
[0105] Furthermore, embodiments of the present invention also provide a computer program product, the computer program product including instructions configured to, when run on an electronic device 100, cause the electronic device 100 to perform the multi-style dialogue model training method or multi-style dialogue method as described above.
[0106] In summary, the multi-style dialogue model training method, multi-style dialogue method, and computer program product provided by the embodiments of the present invention significantly improve the style expression ability and context understanding level of the large language model in personalized interaction scenarios by constructing dual-path training data of "multi-style question-answer sample pairs" and "stylized multi-turn dialogue data" and combining LoRA low-rank adaptation technology for phased fine-tuning.
[0107] In the embodiments provided by this invention, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative; for example, the flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram and / or flowchart, and combinations of blocks in block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0108] In addition, the functional modules in the various embodiments of the present invention can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0109] If the functionality is implemented as a software module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a computer-readable storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0110] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
[0111] It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the invention can be implemented in other specific forms without departing from its spirit or essential characteristics. Therefore, the embodiments should be considered in all respects as exemplary and non-limiting, and the scope of the invention is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be included within the present invention. No reference numerals in the claims should be construed as limiting the scope of the claims.
Claims
1. A method for training a multi-style dialogue model, the method comprising: The method comprises the following steps: acquiring a user question set and a knowledge fragment set; the user question set comprises multiple user questions, and the knowledge fragment set comprises multiple knowledge fragments; inputting each user question into a general large language model, and obtaining multiple question and answer sample pairs of different styles through constraint processing of multiple style types; inputting each knowledge fragment into the general large language model, and generating multiple round dialogue data samples through self-dialogue of the general large language model; training a benchmark model using each question and answer sample pair of different styles and each multiple round dialogue data sample, and obtaining a multi-style dialogue model.
2. The method of claim 1, wherein, The step of inputting each user question into a general large language model and obtaining multiple question and answer sample pairs of different styles through constraint processing of multiple style types comprises the following steps: for each user question, inputting the user question into a general large language model to obtain a detailed answer replied by the general large language model; inputting the detailed answer into the general large language model to generate multiple brief answers of different styles through constraint processing of multiple style types; combining the user question and each brief answer into a question and answer sample pair.
3. The method of claim 2, wherein, The step of inputting the detailed answer into the general large language model to generate multiple brief answers of different styles through constraint processing of multiple style types comprises the following steps: acquiring multiple preset style types; assembling each style type and the detailed answer into a corresponding prompt word; inputting each prompt word into the general large language model to obtain a brief answer of each style type.
4. The method of claim 1, wherein, The step of inputting each knowledge fragment into the general large language model and generating multiple round dialogue data samples through self-dialogue of the general large language model comprises the following steps: for each knowledge fragment, initializing an empty question and answer list; the question and answer list represents a multiple round dialogue, and the knowledge fragment is a topic of the multiple round dialogue; assembling the question and answer list, the knowledge fragment and multiple preset style types into multiple prompt words; inputting each prompt word into the general large language model for self-dialogue to generate multiple round dialogue data samples.
5. The method of claim 4, wherein, The step of inputting each prompt word into the general large language model for self-dialogue to generate multiple round dialogue data samples comprises the following steps: generating a simulated user question using the general large language model according to the prompt word; generating a simulated question answer using the general large language model according to the simulated user question and the prompt word; adding the simulated user question and the simulated question answer to the question and answer list; judging whether the dialogue round number of the question and answer list reaches a preset threshold; if not, continuously generating a simulated user question and a simulated question answer according to the question and answer list until the dialogue round number of the question and answer list reaches the preset threshold.
6. The method of claim 1, wherein, The step of training a benchmark model using each question and answer sample pair of different styles and each multiple round dialogue data sample to obtain a multi-style dialogue model comprises the following steps: fine-tuning the benchmark model using LoRA technology according to each question and answer sample pair to obtain a multi-style dialogue model comprising multiple style adapters. The multi-style dialogue model is fine-tuned again using each of the multi-round dialogue data samples to obtain a multi-style dialogue model with improved context understanding capability.
7. The method of claim 6, wherein, The multi-style dialogue model is obtained by fine-tuning a baseline model using LoRA technology according to each of the question and answer sample pairs, and includes a plurality of style adapters, including: For any question and answer sample pair, the question and answer sample pair is input into the baseline model; According to the style type in the question and answer sample pair, a corresponding target style adapter is found using a LoRA controller, and the target style adapter is loaded into the baseline model; The baseline model is trained once using the question and answer sample pair; Each of the question and answer sample pairs is traversed, and the baseline model is trained once using the question and answer sample pair to obtain a multi-style dialogue model including a plurality of style adapters.
8. A multi-style dialogue method, characterized by, Including: Obtaining a user-selected style type and user-input question content; The style type and the question content are input into a multi-style dialogue model to obtain an answer corresponding to the style type; The multi-style dialogue model is trained by the multi-style dialogue model training method of any one of claims 1 to 7.
9. The method of claim 8, wherein, The style type and the question content are input into a multi-style dialogue model to obtain an answer corresponding to the style type, including: According to the style type, activate the corresponding LoRA style adapter; wherein the LoRA style adapter is obtained by fine-tuning a baseline model based on different style question and answer sample pairs; Using the activated multi-style dialogue model to decode the question content to generate a natural language response with the style type.
10. A computer program product, characterised in that, The computer program product includes instructions that, when executed on an electronic device, cause the electronic device to implement the method of any one of claims 1 to 9.