A dialogue reply method and device, and a language model training method and device
By setting an independent parameter set for each virtual character and concatenating them within a pre-trained language model framework, the problem of inflexible switching of virtual character dialogue response models was solved, and high-quality response information generation was achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- NETEASE (HANGZHOU) NETWORK CO LTD
- Filing Date
- 2022-06-10
- Publication Date
- 2026-05-29
Smart Images

Figure CN115221271B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, specifically to a dialogue response method and apparatus, and a language model training method and apparatus. Background Technology
[0002] In the gaming industry, using open-ended chatbots to interact with players enhances gameplay and player engagement. These chatbots include various virtual characters, allowing players to choose their favorites for conversation. The question of how to ensure that the chatbot's responses align with the personality traits of these virtual characters has garnered significant attention.
[0003] In existing technologies, a separate dialogue response model is typically set up for each virtual character. Specifically, the dialogue response character selected by the player is first obtained, and the dialogue response model corresponding to that character is used as the target response model. When a dialogue request containing dialogue information is received from the player, the dialogue information is input into the target response model. Then, the target response model generates and outputs response information based on the dialogue information.
[0004] To respond to multiple players' dialogue requests for different virtual characters, it is necessary to switch between multiple dialogue response models. However, due to the large size of each dialogue response model and the inflexibility of switching, the generated response information is of poor quality. Summary of the Invention
[0005] This application provides a dialogue response method and apparatus, and a language model training method and apparatus, to improve the effect of generating response information.
[0006] In a first aspect, embodiments of this application provide a dialogue response method, the method comprising:
[0007] Obtain the target character identifier and dialogue information;
[0008] Based on the target role identifier, determine the independent parameter set corresponding to the target role identifier;
[0009] Based on the independent parameter set and the preset parameter set, a target parameter set is determined, wherein the preset parameter set is the initial parameter set of the pre-trained language model;
[0010] The target parameter set is used as the parameters of the pre-trained language model to obtain the target pre-trained language model;
[0011] The dialogue information is input into the target pre-trained language model, and the target pre-trained language model outputs target response information that responds to the dialogue information.
[0012] Optionally, both the independent parameter set and the preset parameter set are matrices;
[0013] The step of determining the target parameter set based on the independent parameter set and the preset parameter set includes:
[0014] The independent parameter set and the preset parameter set are concatenated to obtain the target parameter set.
[0015] Optionally, the step of concatenating the independent parameter set and the preset parameter set to obtain the target parameter set includes:
[0016] Determine the matrix dimension of the preset parameter set;
[0017] Based on the direction of the matrix dimension, the independent parameter set is concatenated with the preset parameter set to obtain the target parameter set.
[0018] Optionally, the step of concatenating the independent parameter set with the preset parameter set according to the direction of the matrix dimension to obtain the target parameter set includes:
[0019] Based on the row direction of the matrix dimension, the independent parameter set and the preset parameter set are concatenated rowwise to obtain the target parameter set; or;
[0020] Obtain the number of rows M of the independent parameter set, where M is a positive integer; replace the last M rows of the preset parameter set with the independent parameter set to obtain the target parameter set.
[0021] Optionally, determining the independent parameter set corresponding to the target role identifier based on the target role identifier includes:
[0022] Based on the target character identifier and the preset correspondence, an independent parameter set corresponding to the target character identifier is determined. The preset correspondence is used to indicate the correspondence between the virtual character, the character identifier, and the independent parameter set. The independent parameter set is a set of parameters that can characterize the language features of the virtual character.
[0023] Optionally, the step of inputting the dialogue information into the target pre-trained language model, and the target pre-trained language model outputting target response information in response to the dialogue information, includes:
[0024] The dialogue information is modified according to the prompt text set to obtain the target dialogue information. The prompt text set is text information that can reflect the language characteristics of the target virtual character.
[0025] The target dialogue information is input into the target pre-trained language model, and the target pre-trained language model outputs target response information that responds to the target dialogue information.
[0026] Secondly, embodiments of this application provide a language model training method, the method comprising:
[0027] Based on N training text sets, determine K first training text sets containing dialogue corpora of the target virtual character. The N training text sets include corpora of dialogues between multiple virtual characters. Wherein, N and K are positive integers, and K is less than or equal to N.
[0028] Based on the K first training text sets and the prompt text set of the target virtual character, K second training text sets are determined, wherein the prompt text set is text information that can reflect the language characteristics of the target virtual character;
[0029] Based on the preset parameter set and initial independent parameter set of the pre-trained language model, the training parameter set corresponding to the target virtual character is obtained. The initial independent parameter set is used as the learning parameter set to characterize the language features of the target virtual character.
[0030] The set of parameters to be trained is used as the parameters of the pre-trained language model to obtain the model to be trained;
[0031] The model to be trained is trained based on the K second training text sets to obtain the language model corresponding to the target virtual character. The parameter set of the language model includes an independent parameter set used to characterize the language features of the target virtual character.
[0032] Optionally, the target virtual character type includes a first type and a second type; the virtual characters corresponding to the first type include virtual characters with a corpus size less than a preset threshold, and the virtual characters corresponding to the second type include virtual characters with a corpus size greater than or equal to the preset threshold.
[0033] The step of determining K first training text sets containing dialogue data of the target virtual character based on N training text sets includes:
[0034] When the type of the target virtual character is the first type, the N training text sets are determined as the K first training text sets corresponding to the target virtual character, where N equals K; or...
[0035] When the type of the target virtual character is the second type, for each of the N training text sets, the first processing is performed: if the training text set includes the dialogue data of the target virtual character, the training text set is determined as a first training text set corresponding to the target virtual character; after performing the first processing on all N training text sets, K first training text sets corresponding to the target virtual character are obtained, where N is less than or equal to K.
[0036] Optionally, determining K second training text sets based on the K first training text sets and the prompt text set of the target virtual character includes:
[0037] Obtain the prompt text set of the target virtual character;
[0038] For each of the K first training text sets, the second processing is performed sequentially:
[0039] When the target virtual character is of the first type, the prompt text set is added before the first training text set to obtain the second training text set; or,
[0040] When the type of the target virtual character is the second type, the prompt text set is added after each target virtual character appearing in the first training text set to obtain the second training text set.
[0041] After performing the second processing on all K first training text sets, K second training text sets corresponding to the target virtual character are obtained.
[0042] Optionally, both the initial independent parameter set and the preset parameter set are matrices.
[0043] Determine the matrix dimension of the preset parameter set;
[0044] Based on the direction of the matrix dimension, the initial independent parameter set is concatenated with the preset parameter set to obtain the parameter set to be trained.
[0045] Optionally, obtaining the training parameter set corresponding to the target virtual character based on the preset parameter set and the initial independent parameter set of the language model to be trained includes:
[0046] Based on the row direction of the matrix dimension, the initial independent parameter set and the preset parameter set are concatenated rowwise to obtain the parameter set to be trained; or;
[0047] Obtain the row number J of the initial independent parameter set, where J is a positive integer; replace the last J rows of the preset parameter set with the initial independent parameter set to obtain the parameter set to be trained.
[0048] Thirdly, embodiments of this application provide a dialogue response device, the device comprising:
[0049] The acquisition module is used to acquire the target role identifier and dialogue information;
[0050] The first determining module is used to determine the independent parameter set corresponding to the target role identifier based on the target role identifier;
[0051] The second determining module is used to determine the target parameter set based on the independent parameter set and the preset parameter set, wherein the preset parameter set is the initial parameter set of the pre-trained language model;
[0052] The first processing module is used to use the target parameter set as parameters of the pre-trained language model to obtain the target pre-trained language model.
[0053] The second processing module is used to input the dialogue information into the target pre-trained language model, and the target pre-trained language model outputs target response information in response to the dialogue information.
[0054] Optionally, both the independent parameter set and the preset parameter set are matrices;
[0055] The second determining module is specifically used for:
[0056] The independent parameter set and the preset parameter set are concatenated to obtain the target parameter set.
[0057] Optionally, the second determining module is specifically used for:
[0058] Determine the matrix dimension of the preset parameter set;
[0059] Based on the direction of the matrix dimension, the independent parameter set is concatenated with the preset parameter set to obtain the target parameter set.
[0060] Optionally, the second determining module is specifically used for:
[0061] Based on the row direction of the matrix dimension, the independent parameter set and the preset parameter set are concatenated rowwise to obtain the target parameter set; or;
[0062] Obtain the number of rows M of the independent parameter set, where M is a positive integer; replace the last M rows of the preset parameter set with the independent parameter set to obtain the target parameter set.
[0063] Optionally, the first determining module is specifically used for:
[0064] Based on the target character identifier and the preset correspondence, an independent parameter set corresponding to the target character identifier is determined. The preset correspondence is used to indicate the correspondence between the virtual character, the character identifier, and the independent parameter set. The independent parameter set is a set of parameters that can characterize the language features of the virtual character.
[0065] Optionally, the second processing module is specifically used for:
[0066] The dialogue information is modified according to the prompt text set to obtain the target dialogue information. The prompt text set is text information that can reflect the language characteristics of the target virtual character.
[0067] The target dialogue information is input into the target pre-trained language model, and the target pre-trained language model outputs target response information that responds to the target dialogue information.
[0068] Fourthly, embodiments of this application provide a language model training apparatus, the apparatus comprising:
[0069] The third determining module is used to determine K first training text sets containing dialogue data of the target virtual character based on N training text sets. The N training text sets include corpora of dialogues between multiple virtual characters. N and K are positive integers, and K is less than or equal to N.
[0070] The fourth determining module is used to determine K second training text sets based on the K first training text sets and the prompt text set of the target virtual character, wherein the prompt text set is text information that can reflect the language characteristics of the target virtual character;
[0071] The third processing module is used to obtain the training parameter set corresponding to the target virtual character based on the preset parameter set and the initial independent parameter set of the pre-trained language model. The initial independent parameter set is used as the learning parameter set to characterize the language features of the target virtual character.
[0072] The fourth processing module is used to use the set of parameters to be trained as parameters of the pre-trained language model to obtain the model to be trained.
[0073] The fifth processing module is used to train the model to be trained based on the K second training text sets to obtain the language model corresponding to the target virtual character. The parameter set of the language model includes an independent parameter set used to characterize the language features of the target virtual character.
[0074] Optionally, the target virtual character type includes a first type and a second type; the virtual characters corresponding to the first type include virtual characters with a corpus size less than a preset threshold, and the virtual characters corresponding to the second type include virtual characters with a corpus size greater than or equal to the preset threshold.
[0075] The third determining module is specifically used for, including:
[0076] When the type of the target virtual character is the first type, the N training text sets are determined as the K first training text sets corresponding to the target virtual character, where N equals K; or...
[0077] When the type of the target virtual character is the second type, for each of the N training text sets, the first processing is performed: if the training text set includes the dialogue data of the target virtual character, the training text set is determined as a first training text set corresponding to the target virtual character; after performing the first processing on all N training text sets, K first training text sets corresponding to the target virtual character are obtained, where N is less than or equal to K.
[0078] Optionally, the fourth determining module is specifically used for:
[0079] Obtain the prompt text set of the target virtual character;
[0080] For each of the K first training text sets, the second processing is performed sequentially:
[0081] When the target virtual character is of the first type, the prompt text set is added before the first training text set to obtain the second training text set; or,
[0082] When the type of the target virtual character is the second type, the prompt text set is added after each target virtual character appearing in the first training text set to obtain the second training text set.
[0083] After performing the second processing on all K first training text sets, K second training text sets corresponding to the target virtual character are obtained.
[0084] Optionally, both the initial independent parameter set and the preset parameter set are matrices.
[0085] Determine the matrix dimension of the preset parameter set;
[0086] Based on the direction of the matrix dimension, the initial independent parameter set is concatenated with the preset parameter set to obtain the parameter set to be trained.
[0087] Optionally, the third processing module is specifically used for:
[0088] Based on the row direction of the matrix dimension, the initial independent parameter set and the preset parameter set are concatenated rowwise to obtain the parameter set to be trained; or;
[0089] Obtain the row number J of the initial independent parameter set, where J is a positive integer; replace the last J rows of the preset parameter set with the initial independent parameter set to obtain the parameter set to be trained.
[0090] Fifthly, embodiments of this application provide a dialogue response device, the dialogue response device comprising:
[0091] The memory and the processor are coupled;
[0092] The memory is used to store one or more computer instructions;
[0093] The processor is used to execute one or more computer instructions to implement the dialogue response method described in any of the first aspects above.
[0094] Sixthly, embodiments of this application provide a language model training device, the device comprising:
[0095] The memory and the processor are coupled;
[0096] The memory is used to store one or more computer instructions;
[0097] The processor is used to execute one or more computer instructions to implement the language model training method described in any of the second aspects above.
[0098] In a seventh aspect, embodiments of this application provide a computer-readable storage medium storing one or more computer instructions, characterized in that the instructions are executed by a processor to implement the dialogue response method described in any of the first aspects above, or to implement the language model training method described in any of the second aspects above.
[0099] Eighthly, embodiments of this application provide a computer program product, including a computer program that, when executed by a processor, implements the dialogue response method described in any of the first aspects above, or implements the language model training method described in any of the second aspects above.
[0100] Compared with the prior art, this application has the following advantages:
[0101] The dialogue response method provided in this application involves the following steps: When a player selects a virtual character for dialogue, the player inputs dialogue information and obtains the target character identifier and dialogue information corresponding to the virtual character. Based on the target character identifier, an independent parameter set corresponding to the target character identifier is determined. Based on the independent parameter set and a preset parameter set, a target parameter set is determined, where the preset parameter set is the initial parameter set of the pre-trained language model. The target parameter set is used as the parameters of the pre-trained language model to obtain the target pre-trained language model. The dialogue information is input into the target pre-trained language model, and the target pre-trained language model outputs target response information in response to the dialogue information. When different players select different virtual characters for dialogue, the independent parameter set, which is concatenated with the preset parameter set corresponding to the pre-trained language model, can be flexibly switched within the same model framework to achieve flexible switching of the language model corresponding to different characters, thereby generating response information corresponding to each character. Attached Figure Description
[0102] Figure 1 One of the flowcharts illustrating the language model training method provided in this application embodiment;
[0103] Figure 2 A second schematic flowchart illustrating the language model training method provided in this application embodiment;
[0104] Figure 3 This is one of the flowcharts illustrating the dialogue response method provided in the embodiments of this application;
[0105] Figure 4 One of the schematic diagrams of a dialogue response process provided in an embodiment of this application;
[0106] Figure 5 A second schematic diagram of the dialogue response process provided in an embodiment of this application;
[0107] Figure 6 This is a second flowchart illustrating the dialogue response method provided in the embodiments of this application;
[0108] Figure 7 This is a schematic diagram of the structure of a dialogue response device provided in an embodiment of this application;
[0109] Figure 8 This is a schematic diagram of the structure of a language model training device provided in an embodiment of this application;
[0110] Figure 9 This is a schematic diagram of the hardware structure of the dialogue response device provided in the embodiments of this application;
[0111] Figure 10 This is a schematic diagram of the hardware structure of the language model training device provided in the embodiments of this application. Detailed Implementation
[0112] To make the objectives, advantages, and features of this application clearer, the following detailed description, in conjunction with the accompanying drawings and specific embodiments, further illustrates this application. In the following description, numerous specific details are set forth to provide a thorough understanding of this application. However, this application can be implemented in many other ways different from those described herein, and those skilled in the art can make similar extensions without departing from the spirit of this application. Therefore, this application is not limited to the specific embodiments disclosed below.
[0113] It should be noted that in the description of this application, the terms "first," "second," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance, or a specific order or sequence. Those skilled in the art can understand the specific meaning of the above terms in this application based on the specific circumstances. Furthermore, in the description of this application, unless otherwise stated, the term "multiple" refers to two or more. The term "and / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. The terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products, or devices.
[0114] To facilitate understanding of the technical solution of this application, the relevant concepts involved in this application will be introduced first:
[0115] Pre-trained language models utilize large amounts of unlabeled text data for pre-training, implicitly learning general grammatical and semantic knowledge. Through fine-tuning, they can achieve various downstream tasks such as text classification, semantic role labeling, and dialogue response generation. Pre-training language models offers the following advantages: 1. Pre-training on large-scale text allows for the learning of rich semantic representations, facilitating knowledge transfer for downstream tasks; 2. Pre-training is a regularization process, effectively suppressing overfitting; 3. Pre-trained models receive better initialization parameters, accelerating convergence in downstream tasks and exhibiting better generalization ability. Commonly used pre-trained language models include Generative Pre-training (GPT), GPT-2, GPT-3, and BERT.
[0116] Transfer learning: Transferring the parameters of a pre-trained language model to a new model to aid in its training. Given that most data or tasks are correlated, transfer learning allows the learned parameters (or knowledge acquired by the model) from the pre-trained language model to be shared with the new model, thereby accelerating and optimizing its learning efficiency. In other words, the new model doesn't need to learn from scratch like most models do.
[0117] In natural language processing, computers excel at recognizing numbers but cannot directly recognize text. Therefore, to enable computers to read information corresponding to text, text must be vectorized. Eembedding represents a word or sentence using low-dimensional vectors. The eembedding layer (also known as the vector mapping layer) transforms the information of the original matrix into a new, lower-dimensional matrix according to a mapping relationship. Essentially, it reduces the dimensionality of the original matrix through matrix multiplication, thereby saving storage space. For example, multiplying a 1000000*100000 matrix by a 100000*20 matrix results in a 1000000*20 matrix. This shows that the data size of the resulting 1000000*20 matrix is only 1 / 5000 of the data size of the original 1000000*100000 matrix.
[0118] The following is a detailed explanation of the prior art and the problems existing in the prior art involved in this application:
[0119] In the gaming industry, setting up open-ended chatbots within games to interact with players increases the game's enjoyment and player satisfaction. These chatbots include a variety of roles, allowing players to choose their favorite virtual characters to converse with.
[0120] To ensure that chatbot responses align with the personality traits of the virtual character, existing technologies typically establish a dialogue response model for each virtual character. Specifically, the virtual character selected by the player is first obtained, and the corresponding dialogue response model is acquired and used as the target response model. Upon receiving a dialogue request containing dialogue information from the player, the dialogue information is input into the target response model. Then, the target response model generates and outputs a response based on the dialogue information.
[0121] To enable the game server to simultaneously handle dialogue requests from multiple players for different virtual characters, multiple dialogue response models need to be switched in turn to become the primary dialogue response model to generate response information based on the players' dialogue content. However, due to the large size of each dialogue response model, flexible switching between models is not possible, ultimately resulting in poor quality of generated response information.
[0122] Based on the aforementioned problems, and considering that each literary work has its own writing style and that most characters in literary works have distinct personality traits, if a game's scenario is based on a literary work, then the game scenario should have a certain style, and most of the virtual characters in the game should also have distinct personality traits. To ensure that the chatbot's dialogue responses match the personality traits of the virtual characters and to avoid the poor quality of generated responses caused by setting separate response models for each virtual character, this application proposes using a pre-trained language model obtained through pre-training on a large amount of unlabeled text data as the base model. The base model is trained using text data corresponding to each virtual character to obtain an independent parameter set for each virtual character; this independent parameter set can represent the language features of the virtual character to a certain extent. Then, a framework is used to pre-load the pre-trained language model and the independent parameter sets of all virtual characters into the framework, and a different identifier ID is set for each virtual character to uniquely represent them. Next, the independent parameter sets corresponding to each virtual character are identified. Specifically, the identifier of the independent parameter set corresponding to a virtual character is set to the same identifier ID as the identifier ID of that virtual character. Therefore, within the same framework, the preset parameter set corresponding to the pre-trained language model is concatenated with the independent parameter set corresponding to role A to obtain the complete parameter set of virtual role A. This complete parameter set is then used as the parameter set of the pre-trained language model, which in turn becomes the language model corresponding to virtual role A. It can be understood that by switching the independent parameter set concatenated with the preset parameter set corresponding to the pre-trained language model, different language models corresponding to different virtual roles can be switched within the same framework to generate response information for each virtual role. It should be emphasized that the size of the independent parameter set corresponding to each virtual role is lightweight compared to the preset parameter set corresponding to the pre-trained language model. For example, the data volume of the independent parameter set corresponding to each virtual role is 0.01% of the data volume of the preset parameter set corresponding to the pre-trained language model. Therefore, this application allows for flexible switching of the language model corresponding to different roles within the same framework, by only switching the independent parameter set concatenated with the preset parameter set corresponding to the pre-trained language model, thereby generating response information for each virtual role.
[0123] This application provides a dialogue response method, a corresponding dialogue response apparatus, a dialogue response device that implements the dialogue response method, and a computer-readable storage medium; and provides a language model training method, a corresponding language model training apparatus, a language model training device that implements the language model training method, and a computer-readable storage medium; the following embodiments provide detailed descriptions of the above-mentioned methods, apparatus, electronic devices, and computer-readable storage media.
[0124] To make the objectives and technical solutions of this application clearer and more intuitive, the methods provided by the embodiments of this application will be described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are merely for explaining this application and are not intended to limit this application. It should be noted that the following embodiments may exist independently or in combination with each other; for the same or similar content, the description will not be repeated in different embodiments.
[0125] This application provides a language model training method, the execution subject of which can be an electronic device, such as a mobile terminal or a server. Mobile terminals include mobile phones, laptops, tablets, desktop computers, etc.; servers include local servers and cloud servers, etc.; there are no limitations on this. It should be noted that in the following description of the technical solution provided in one embodiment of this application, a terminal is used as an example of the execution subject. In other possible implementations, a server can also be used as the execution subject to execute the technical solution provided in one embodiment of this application; this application does not limit the type of execution subject in one embodiment.
[0126] Below, in conjunction with Figure 1 To explain, Figure 1 This is one of the flowcharts illustrating the language model training method provided in the embodiments of this application.
[0127] like Figure 1 As shown, the language model training method includes:
[0128] S101. Based on N training text sets, determine K first training text sets containing dialogue data of the target virtual character.
[0129] Where N and K are positive integers, and K is less than or equal to N.
[0130] In this embodiment, a game is used as an example to illustrate N training text sets and virtual characters.
[0131] Assume the game scene is set up based on a pre-defined script. The pre-defined script can be of various types, such as novels, poems, essays, and miscellaneous writings. The game scene primarily uses novels as the script type. The following example illustrates this using a novel as the pre-defined script type. All the plot points in the pre-defined script include the main storyline, side storylines, and adventure storylines. To facilitate subsequent training of the pre-trained language model using the text content of the pre-defined script, all the scripts constituting the complete plot of the pre-defined script are first merged into a single document. Then, the merged document is uniformly segmented to obtain N training text sets that make up the pre-defined script. These N training text sets consist of corpora of dialogues between multiple virtual characters. The document type can be Word or Notepad, etc., and this embodiment does not impose any limitations on this.
[0132] The following provides an example of possible implementations for segmenting the merged document.
[0133] Optionally, the total number of words in each training text set can be controlled within a preset threshold. Specifically, since the plot in the document is coherent, to ensure the continuity of the plot in each training text set after segmentation, the length of each line is counted sequentially from the beginning of the document. If the total number of words in the current training text set plus the number of words in that line does not exceed the preset threshold, then that line is added to the current training text set; if the total number of words in the current training text set plus the number of words in that line exceeds the preset threshold, then the division of the training text set ends. This process is repeated to divide the content of the next training text set until all the text in the entire document has been divided into training text sets, i.e., the document division ends and N training sample sets are obtained. Each training text set is a training sample.
[0134] Optionally, to distinguish between narration and dialogue content in each training text set, double quotation marks are added to each dialogue content. Therefore, text with double quotation marks represents dialogue content, while other content represents narration.
[0135] Optionally, when there are several options in the training text set, only one option needs to be retained. For example, in the sentence "No one has come to collect it recently, and I've been too busy to leave. Then I'll trouble {{gender: young hero | young lady}}.", the part "{{gender: young hero | young lady}}" contains two options: "young hero" and "young lady". Only one option needs to be retained. For example, if only the latter option is retained, the original sentence can be modified to "No one has come to collect it recently, and I've been too busy to leave. Then I'll trouble the young lady."
[0136] In the N training text sets of the preset script, all virtual characters included in the preset script can be divided into two categories based on the total amount of corpus data for each virtual character: Type 1 and Type 2. The corpus can refer to every sentence spoken by a virtual character or a dialogue between that virtual character and other virtual characters, without any limitation. Type 1 virtual characters include those with corpus data less than a preset threshold, while Type 2 virtual characters include those with corpus data greater than or equal to the preset threshold. It should be noted that because Type 1 virtual characters contain too little corpus data, their linguistic characteristics cannot be accurately determined based solely on the limited corpus data. Conversely, based on the rich corpus data corresponding to Type 2 virtual characters, their linguistic characteristics can be determined.
[0137] Virtual characters in games can be designed based on characters in preset scripts. Taking the game *Justice Online* as an example, let's illustrate the first and second types of virtual characters. First-type virtual characters in *Justice Online* include characters like fishermen, woodcutters, and innkeepers; these characters do not exhibit distinct linguistic characteristics. Second-type virtual characters in *Justice Online* include characters from the Four Great Constables: Wuqing, Tieshou, Lengxue, and Zhuiming. These second-type characters each possess distinct linguistic characteristics (or personality traits). For example, Wuqing is relatively calm and meticulous, Tieshou is steady and resolute, Lengxue is taciturn, and Zhuiming is carefree and unrestrained. It should be emphasized that the entire preset script has certain linguistic characteristics (style). For instance, the linguistic characteristics of the script used in *Justice Online* are more in line with the style of ancient martial arts novels.
[0138] The target virtual character is any one of the multiple virtual characters included in the preset text.
[0139] Below, we will provide illustrative examples of two possible implementation methods for determining the K first training text sets corresponding to the target virtual character.
[0140] Optionally, when the target virtual character is of type 1, the N training text sets are determined as the K first training text sets corresponding to the target virtual character. In this case, the value of K is equal to the value of N.
[0141] Optionally, when the target virtual character is of type two, for each first training text set in the N training text sets, the following processing is performed sequentially: determine whether the training text set contains dialogue data of the target virtual character; if it does, then determine that training text set as a first training text set corresponding to the target virtual character. Therefore, from the N training text sets, K first training text sets corresponding to the target virtual character can be determined. In this case, the value of K is less than or equal to the value of N.
[0142] It is important to emphasize that when the target virtual character is of type 1, all N training text sets (the entire preset text) are used as training samples for that target virtual character. In other words, the linguistic characteristics of the entire preset text are used as the linguistic characteristics of the target virtual character. Essentially, this means ensuring that the linguistic characteristics of the target virtual character conform to the linguistic characteristics of the entire preset text. For example, the linguistic characteristics of the fisherman in the game Justice Online only need to conform to the style of ancient martial arts novels.
[0143] S102. Based on the K first training text sets and the prompt text set of the target virtual character, determine the K second training text sets. The prompt text sets are text information that can reflect the language characteristics of the target virtual character.
[0144] It should be noted that in this embodiment, a pre-trained language model is used as the base model to construct the language model. Specifically, during the fine-tuning phase of the pre-trained language model, the training sample data and model parameters need to be adjusted.
[0145] In natural language processing, prompt-tuning is a common method for fine-tuning training data. In prompt-tuning, different prompts are defined for each task based on its characteristics. A prompt, as the name suggests, is a hint or suggestion. Therefore, defining a separate prompt for each task can be understood as defining corresponding prompt information for each task. The prompts are then appended to the training data (i.e., the training data corresponds to the training text set in any embodiment of this application), thus completing the fine-tuning of the training data. A task can be understood as training a language model corresponding to a virtual character A. Therefore, defining the prompt for a task can be understood as defining the prompt text set corresponding to virtual character A. Here, virtual character A can be any virtual character.
[0146] Optionally, obtain the prompt text set corresponding to the target virtual character; next, for each of the K first training text sets corresponding to the target virtual character, perform the following processing in sequence: concatenate the prompt text set to the first training text set, and determine the first training text set after concatenation as a second training text set corresponding to the target virtual character. After the above processing is completed, obtain the K second training text sets corresponding to the target virtual character.
[0147] The following section further explains how to implement the prompt-tuning method to adjust the training data of the pre-trained language model for different types of virtual characters.
[0148] Optionally, when the target virtual character's type is the first type, the corresponding hint text set is obtained. Specifically, for each of the K first training text sets, the following processing is performed sequentially: a hint text set is added before the first training text set to obtain a second training text set. The hint text set consists of multiple rare characters, which are characters that have never appeared in the training text set of the pre-trained language model. After completing the above processing, i.e., when the target virtual character's type is the second type, the K second training text sets corresponding to the target virtual character are obtained.
[0149] Optionally, when the target virtual character is of type two, for each of the K first training text sets, the following processing is performed sequentially: a hint text set is added between the virtual character and the colon ":" in the first training text set to obtain a second training text set. Similarly, this hint text set consists of multiple rare characters. After the above processing is completed, i.e., when the target virtual character is of type two, the K second training text sets corresponding to the target virtual character are obtained.
[0150] S103. Based on the preset parameter set and initial independent parameter set of the pre-trained language model, obtain the training parameter set corresponding to the target virtual character. The initial independent parameter set is used as the learning parameter set to characterize the language features of the target virtual character.
[0151] Optionally, the pre-trained language model used in this embodiment can be GPT. The basic idea of GPT is as follows: First, a pre-trained language model GPT is obtained by learning on a large-scale unlabeled dataset; then, to perform downstream tasks such as dialogue response generation, it is usually necessary to add a layer to fine-tune the pre-trained language model, enabling it to perform downstream tasks. The parameter set of the trained language model (i.e., the pre-trained language model) is called the preset parameter set.
[0152] In this embodiment, a pre-trained language model is used as the base model. Without altering the original model structure, an initial independent parameter set (i.e., a prompt parameter set) is added to the pre-trained language model. Based on the dimensionality information of the pre-trained language model's preset parameter set and the prompt text set, the initial independent parameter set is determined and added to the embedding layer. Adding an initial independent parameter set to the embedding layer can be understood as adding vector parameters corresponding to some virtual tokens (words) to the existing embedding layer. This achieves the goal of adding a parameter set to the pre-trained language model for learning the language characteristics of the target virtual character while keeping other aspects of the model unchanged. For example, if the vector dimension representing each token in the original embedding layer is 1*D, and the number of tokens in the prompt text set is T, then the initial independent parameter set corresponding to the target virtual character is a T*D matrix.
[0153] Below, we will provide examples of possible implementations for determining the initial independent parameter set of a target virtual character, for different types of virtual characters.
[0154] Optionally, when the target virtual character is of type 1 or type 2, the T*D matrix is initialized using random initialization.
[0155] Optionally, when the target virtual character is of type two, an initial independent parameter set can be determined for the target virtual character based on the corresponding prompt text set. For example, if the prompt text set for the target virtual character is "to express agreement, calmly nod." Specifically, the embedding layer of the pre-trained language model is loaded, and the vector corresponding to each character in "to express agreement, calmly nod" is sequentially extracted from the embedding parameter matrix to form the initial independent parameter set for the target virtual character.
[0156] The following is an example of a possible implementation for determining the initial independent parameter set through the prompt text set of the target virtual character when the target virtual character is of type 2.
[0157] Optionally, to obtain the vector corresponding to each word from the Embedding layer, the row identifier of the word in the Embedding layer can be obtained first, and then the vector of the row where the row identifier is located can be obtained from the Embedding layer according to the row identifier corresponding to the word. For example, in the original Embedding layer, the row identifier (ID) of the word "表" in "表示同意" in the Embedding layer is 5 (that is, the vector in the 5th row of the Embedding layer is the vector corresponding to the word "表"). Then, the vector in the 5th row of the Embedding layer is taken out. And so on, the vectors corresponding to the other three words "示", "同", and "意" are taken out from the Embedding layer. Suppose that the vector dimension of each token in the Embedding layer is 4 and there are P tokens, then the matrix dimension of the Embedding parameter matrix is: P * 4. When the row identifiers of "表", "示", "同", and "意" are 3, 5, 6, and 9 respectively, the vectors in the 3rd row, 5th row, 6th row, and 9th row in the Embedding layer are: [x 31 ,x 32 ,x 33 ,x 34 , [x 51 ,x 52 ,x 53 ,x 54 , [x 61 ,x 62 ,x 63 ,x 64 , [x 91 ,x 92 ,x 93 ,x 94 , then the initial independent parameter set P 目标 of the target virtual character is as shown in Formula 1 below.
[0158]
[0159]
[0160] After the initial independent parameter set of the target virtual character is determined, the initial independent parameter set is concatenated after the preset parameter set of the pre-trained language model, and the concatenated parameter set is called the parameter set G to be trained. Combining the above example, the concatenated parameter set G is as shown in Formula 2.
[0161] It should be noted that each virtual character has its own corresponding parameter set to be trained.
[0162] S104. Use the parameter set to be trained as the parameter of the pre-trained language model to obtain the model to be trained.
[0163] Based on step S103, after determining the set of parameters to be trained corresponding to the target virtual character, the set of parameters to be trained is used as the parameters of the pre-trained language model to obtain the model to be trained corresponding to the target virtual character.
[0164] S105. Train the model to be trained based on K second training text sets to obtain the language model corresponding to the target virtual character. The parameter set of the language model includes an independent parameter set used to characterize the language features of the target virtual character.
[0165] In this embodiment, the training model corresponding to the target virtual character is trained using K second training text sets corresponding to the target virtual character. After training, a language model corresponding to the target virtual character is obtained. The parameter set of the language model includes a preset parameter set and an independent parameter set used to characterize the language features of the target virtual character.
[0166] It should be noted that in this embodiment, during model training, the preset parameter set in the pre-trained language model is not updated; only the initial independent parameter set corresponding to the target virtual character is updated using gradient optimization. The updated initial independent parameter set is then determined as the independent parameter set corresponding to the target virtual character. It can be understood that after the pre-trained language model has fully learned from the K second training text sets corresponding to the target virtual character, it obtains an independent parameter set that reflects the linguistic characteristics of the target virtual character.
[0167] The language model control method provided in this application involves determining K first training text sets containing dialogue corpora of a target virtual character based on N training text sets. The N training text sets include corpora of dialogues between multiple virtual characters. Based on the K first training text sets and a prompt text set for the target virtual character, K second training text sets are determined. The prompt text set consists of text information reflecting the language characteristics of the target virtual character. A parameter set to be trained corresponding to the target virtual character is obtained based on a preset parameter set and an initial independent parameter set of a pre-trained language model. The initial independent parameter set is used as a set of parameters to be learned to characterize the language characteristics of the target virtual character. The parameter set to be trained is used as parameters of the pre-trained language model to obtain the model to be trained. The model to be trained is then trained using the K second training text sets to obtain the language model corresponding to the target virtual character. The parameter set of the language model includes an independent parameter set representing the language characteristics of the target virtual character. Firstly, by using the pre-trained language model as the base model to train the language model corresponding to the target virtual character, the training time for obtaining the language model corresponding to the target virtual character is greatly shortened, effectively improving model training efficiency. Secondly, without altering the original model structure and preset parameter set of the pre-trained language model, an initial independent parameter set is added. This ensures that the other structures of the pre-trained language model remain unchanged while adding an initial independent parameter set for training the target virtual character. Finally, the training data required for language model training consists of an unlabeled text set containing the dialogue corpus of the target virtual character. Learning the language characteristics of the target virtual character based on this unlabeled text set greatly avoids the arduous task of manually labeling the text set, significantly reducing labor costs.
[0168] Optionally, the language model training method provided in this application will be further described below with reference to a specific embodiment. Figure 2 This is the second flowchart illustrating the language model training method provided in this application embodiment.
[0169] like Figure 2 As shown, the language model training method includes:
[0170] S201. Based on N training text sets, determine K first training text sets containing dialogue corpora of the target virtual character. The N training text sets include corpora of dialogues between multiple virtual characters.
[0171] The target virtual characters are categorized into two types: Type 1 and Type 2. Type 1 virtual characters include those with a corpus size less than a preset threshold, while Type 2 virtual characters include those with a corpus size greater than or equal to the preset threshold.
[0172] Optionally, when the target virtual character is of type 1, the N training text sets are determined as the K first training text sets corresponding to the target virtual character, where N equals K. Alternatively,
[0173] Optionally, when the target virtual character is of type two, for each of the N training text sets, a first processing step is performed: if the training text set includes dialogue data of the target virtual character, the training text set is determined as a first training text set corresponding to the target virtual character. After performing the first processing step on all N training text sets, K first training text sets corresponding to the target virtual character are obtained, where N is less than or equal to K.
[0174] S202. Obtain the prompt text set of the target virtual character.
[0175] Optionally, the prompt text set is text that can reflect the language characteristics of the target virtual character.
[0176] For example, when the target virtual character is Wuqing, because Wuqing's personality traits are meticulousness and foresight, Wuqing usually appears calm and attentive. Therefore, when the target virtual character is Wuqing, the prompt text could be "Agree, calmly nod and say".
[0177] S203. For each of the K first training text sets, perform the second processing sequentially to obtain the K second training text sets corresponding to the target virtual character.
[0178] In this embodiment, different second processes are applied according to different types of virtual characters.
[0179] Optionally, when the target virtual character is of the first type, the prompt text set is added before the first training text set to obtain the second training text set.
[0180] Optionally, when the type of the target virtual character is the second type, a second training text set is obtained by adding a cue text set after each target virtual character appearing in the first training text set.
[0181] S204. Based on the preset parameter set and initial independent parameter set of the pre-trained language model, obtain the training parameter set corresponding to the target virtual character.
[0182] In the embodiments of this application, when both the initial independent parameter set and the preset parameter set are matrices.
[0183] Optionally, the vector corresponding to each character in the prompt text set is obtained from the preset parameter set. The multiple vectors are then concatenated from top to bottom according to the order of the characters in the prompt text set to obtain the initial independent parameter set corresponding to the target virtual character.
[0184] Next, a specific example is used to illustrate this optional method.
[0185] Assume that the prompt text set of the target virtual character is: Express agreement. Therefore, from the preset parameter set, the vectors corresponding to "表", "示", "同", and "意" are taken out from the Embedding parameter set respectively. For example, the vectors corresponding to "表", "示", "同", and "意" are: [x 61 , x 62 , x 63 , x 64 , [x 81 , x 82 , x 83 , x 84 , [x 21 , x 22 , x 23 , x 24 , [x 41 , x 42 , x 43 , x 44 . According to the order of "表", "示", "同", and "意" in the prompt text set, the vectors corresponding to "表", "示", "同", and "意" are concatenated from top to bottom to generate a matrix P 目标 , P 目标 as shown in Formula 3. Among them, this matrix P 目标 is the initial independent parameter set corresponding to the target virtual character.
[0186]
[0187] Optionally, according to the direction of the matrix dimension, the initial independent parameter set is concatenated with the preset parameter set to obtain the parameter set to be trained.
[0188] Next, two possible implementation methods for concatenating the initial independent parameter set with the preset parameter set according to the direction of the matrix dimension to obtain the parameter set to be trained are described.
[0189] In one possible implementation method, according to the row dimension direction of the matrix dimension, the initial independent parameter set is concatenated with the preset parameter set by rows to obtain the parameter set to be trained.
[0190] Next, an exemplary illustration of the above possible implementation method is given.
[0191] Assume that the initial independent parameter set P corresponding to the target virtual character 目标 is as shown in Formula 3, and the preset parameter set H of the pre-trained language model is as shown in Formula 4. Then the initial independent parameter set P 目标After being concatenated to the preset parameter set H, the pre-trained parameter set H′ corresponding to the target virtual character is obtained, as shown in Formula 5.
[0192]
[0193]
[0194] In another possible implementation, obtain the number of rows J of the initial independent parameter set, where J is a positive integer. Replace the last J rows of the preset parameter set with the initial independent parameter set to obtain the parameter set to be trained.
[0195] The following provides an exemplary description of this possible implementation.
[0196] Combined with the initial independent parameter set P shown in Formula 3 目标 To illustrate, the initial independent parameter set P... 目标 The number of rows is 4. Therefore, replace the last 4 rows of the preset parameter set with the initial independent parameter set P. 目标 Thus, the set of parameters to be trained, H", is obtained, as shown in Formula 6.
[0197]
[0198] S205. Use the set of parameters to be trained as the parameters of the pre-trained language model to obtain the model to be trained.
[0199] S206. Train the model to be trained based on K second training text sets to obtain the language model corresponding to the target virtual character. The parameter set of the language model includes an independent parameter set used to characterize the language features of the target virtual character.
[0200] Optionally, the explanations and descriptions of steps S205-S206 can refer to the explanations and descriptions of steps S104-S105 above, and the same technical effect can be achieved. To avoid repetition, they will not be repeated here.
[0201] The language model training method provided in this application obtains a set of prompt texts corresponding to a target virtual character and determines an initial independent parameter set for the target virtual character based on the prompt text set and the preset parameter set of the pre-trained language model. Since the prompt text set contains texts that reflect the language characteristics of the target virtual character, it is understood that the initial independent parameter set determined based on the prompt text set can also represent the language characteristics of the target virtual character to a certain extent. Using such initial independent parameters improves model training efficiency. Furthermore, during the language model training process for each virtual character, the preset parameter set in the pre-trained language model is not updated; only the initial independent parameter set is updated using gradient optimization. This avoids changes to the original pre-trained model, thus eliminating the need to repeatedly save many large sets of model parameters.
[0202] Below, in conjunction with Figure 3 The dialogue response method provided in this application is described below. The subject executing the dialogue response method can be an electronic device, such as a mobile terminal or a server. Mobile terminals include mobile phones, laptops, tablets, desktop computers, etc.; servers include local servers and cloud servers, etc., without limitation. Figure 3 This is one of the flowcharts illustrating the dialogue response method provided in the embodiments of this application.
[0203] like Figure 3 As shown, the dialogue response method includes:
[0204] S301. Obtain the target role identifier and dialogue information.
[0205] Optionally, the system can receive dialogue requests from players. These requests include the target dialogue character selected by the player and the dialogue information sent by the player.
[0206] Optionally, based on the character list, the target character identifier corresponding to the target character can be obtained. The character list includes multiple virtual characters and their corresponding identifier IDs.
[0207] S302. Determine the independent parameter set corresponding to the target role identifier based on the target role identifier.
[0208] In this embodiment, the independent parameter sets corresponding to all virtual characters are preloaded into the pre-trained language model, and different identifiers are set for each independent parameter set to uniquely represent the independent parameter sets corresponding to different virtual characters.
[0209] Optionally, based on the preset correspondence and the target role identifier, the independent parameter set corresponding to the target role identifier is first determined. The preset correspondence indicates the correspondence between the virtual role, the role identifier, and the independent parameter set. The preset correspondence can be found in Table 1.
[0210] Table 1
[0211]
[0212]
[0213] As shown in Table 1, Table 1 illustrates the relationship between character IDs, virtual characters, and independent parameter sets. For example, the character ID of virtual character 1 is 1, the independent parameter set of virtual character 1 is independent parameter set 1, and the character ID of independent parameter set 1 is 1. The correspondence between other virtual characters, character IDs, and independent parameter sets can be derived similarly from Table 1. Further details are omitted here.
[0214] S303. Determine the target parameter set based on the independent parameter set and the preset parameter set. The preset parameter set is the initial parameter set of the pre-trained language model.
[0215] Below, we will provide illustrative examples of two possible implementation methods for determining the target parameter set based on an independent parameter set and a preset parameter set.
[0216] In one possible implementation, the matrix dimension of the preset parameter set is determined; based on the row direction of the matrix dimension, the independent parameter set and the preset parameter set are concatenated, and the resulting parameter set is determined as the target parameter set. For example, if the independent parameter set is an M*D matrix and the preset parameter set is an L*D matrix, concatenating the independent parameter set to the preset parameter set results in a (L+M)*D matrix as the target parameter set.
[0217] It should be noted that, assuming the vocabulary used in the pre-trained language model has 13,672 tokens, only 6,000 tokens are commonly used in the model's inference and prediction. The remaining tokens are considered rare characters and will not appear in the dialogue response information generated by the model.
[0218] Therefore, based on the above, a preset threshold needs to be set for the pre-trained language model to ensure that the characters in the dialogue response information generated by the pre-trained language model are tokens within the preset threshold. For example, if the vocabulary used in the pre-trained language model has 10,000 tokens (characters), of which only 6,000 are commonly used and the remaining 4,000 are rare characters, then the preset threshold for the pre-trained language model is set to 6,000. Correspondingly, in the preset parameter set, the first 6,000 row vectors are the vectors corresponding to the 6,000 commonly used tokens, and the remaining 4,000 row vectors are the vectors corresponding to the 4,000 rare character tokens.
[0219] In another possible implementation, obtain the number M rows of the independent parameter set, where M is a positive integer. Replace the last M rows of the preset parameter set with the independent parameter set to obtain the target parameter set.
[0220] Based on the above example, an independent parameter set is used to replace the vectors corresponding to some rare characters in the preset parameter set from back to front. For example, when the preset parameter set is a 10000*10 matrix, the independent parameter set is a 30*10 matrix, and the preset threshold is 6000, the last 30 rows of the vectors in the 10000*10 matrix are replaced with the 30*10 matrix of the independent parameter set, and the resulting 10000*10 matrix is determined as the target parameter set.
[0221] S304. Use the target parameter set as the parameters of the pre-trained language model to obtain the target pre-trained language model.
[0222] S305. Input the dialogue information into the target pre-trained language model, and the target pre-trained language model outputs the target response information in response to the dialogue information.
[0223] Next, the dialogue information is input into the target pre-trained language model, which then outputs the target response information based on the dialogue information.
[0224] In order for the model to identify whether a sentence is dialogue or narration based on dialogue information, the dialogue information needs to be processed.
[0225] Optionally, the dialogue information is modified according to the prompt text set to obtain the target dialogue information, where the prompt text set is text information that can reflect the language characteristics of the target virtual character; the target dialogue information is input into the target pre-trained language model, and the target pre-trained language model outputs the target response information that responds to the target dialogue information.
[0226] The following is an exemplary description of this optional implementation method.
[0227] When the virtual character type is Type II, the mock test information is determined based on the prompt text set, and the dialogue information is modified using a template. For example, the template is the content within square brackets: [Player: "Dialogue Information". Virtual Character Prompt Text Information:]. For instance, if the player selects the ruthless virtual character and says to ruthless, "The weather is so nice today!", then after inputting "The weather is so nice today!" into the model, the model will modify this dialogue content according to the template to: Player: "The weather is so nice today!" Ruthless agrees and calmly nods. It should be noted that "agrees and calmly nods" is used to represent Ruthless's personality traits; it is not the actual dialogue content. When inputting it into the model, each word in "agrees and calmly nods" needs to be replaced with 10 different rare words.
[0228] Optionally, when the virtual character is of type 1, a prompt text set is added before the dialogue information.
[0229] It should be noted that in order for the target pre-trained language model to recognize the content of the dialogue information, the modified dialogue information needs to be further converted into a vector that the target pre-trained language model can recognize.
[0230] Below, in conjunction with Figure 4 , Figure 5 And an example is provided to illustrate the specific implementation of inputting dialogue information into a target pre-trained language model and having the target pre-trained language model output response information. Figure 4 This is one of the schematic diagrams of a dialogue response process provided in an embodiment of this application. Figure 5 This is a second schematic diagram of the dialogue response process provided in an embodiment of this application.
[0231] For example, in a game, when a player selects a virtual character to converse with, and the player inputs: "The weather is so nice today," the target pre-trained language model outputs a response that matches the language characteristics of the player's selected virtual character. Taking the game Justice Online as an example, let's illustrate the output of the target pre-trained language model. In Justice Online, Wuqing and Zhuiming are two virtual characters. When the player selects Wuqing as the target virtual character, as shown... Figure 4 As shown, the ruthless reply is: I feel the same way. Player: Senior brother, will you accompany me for a walk? Ruthless: Sure. Let's go to the market. Wait, something's not right here. Figure 4 Describe it. For example... Figure 4 As shown, the ruthless reply reflects the calm and meticulous language characteristics of the virtual character. When the player selects a cold-blooded virtual character, such as... Figure 5 As shown, Cold-Blooded replied: "Hmm, not bad." Player: "Senior brother, come with me for a walk." Cold-Blooded: "Sure, let's go." Wait, something's not right here. Figure 5 Describe it. For example... Figure 5 As shown, the cold-blooded reply reflects the taciturn nature of the virtual character.
[0232] The dialogue response method provided in this application embodiment obtains a target role identifier and dialogue information; determines an independent parameter set corresponding to the target role identifier based on the target role identifier; determines a target parameter set based on the independent parameter set and a preset parameter set, wherein the preset parameter set is the preset parameter set of a pre-trained language model; uses the target parameter set as parameters of the pre-trained language model to obtain a target pre-trained language model; inputs the dialogue information into the target pre-trained language model, and the target pre-trained language model outputs target response information in response to the dialogue information. When different players select different virtual roles for dialogue, the independent parameter set, which is concatenated with the preset parameter set corresponding to the pre-trained language model, can be flexibly switched within the same model framework to achieve flexible switching of the language model corresponding to different roles, thereby generating response information corresponding to each role.
[0233] Optionally, combined Figure 6 The dialogue response method provided in the embodiments of this application will be further described. Figure 6 This is a second flowchart illustrating the dialogue response method provided in an embodiment of this application.
[0234] like Figure 6 As shown, the dialogue response method includes:
[0235] S601. Obtain the target role identifier and dialogue information.
[0236] S602. Determine the independent parameter set corresponding to the target role identifier based on the target role identifier and the preset correspondence.
[0237] The preset correspondence is used to indicate the correspondence between virtual characters, character identifiers, and independent parameter sets. Independent parameter sets are sets of parameters that can characterize the linguistic features of virtual characters.
[0238] Optionally, the correspondence between role identifiers and independent parameter sets can be obtained from a preset correspondence; based on the correspondence between role identifiers and independent parameter sets, the independent parameter set corresponding to the target role identifier can be obtained.
[0239] The following section explains this optional implementation method.
[0240] Taking Table 1 above as an example, the correspondence between virtual characters and independent parameter sets can be obtained from Table 1 as follows: the independent parameter set corresponding to virtual character 1 is independent parameter set 1; the independent parameter set corresponding to virtual character 2 is independent parameter set 2; ...; the independent parameter set corresponding to virtual character Y is independent parameter set Y. If the target virtual character is virtual character 2, then the independent parameter set corresponding to the target virtual character is independent parameter set 2.
[0241] S603. Determine the independent parameter set corresponding to the target role identifier.
[0242] S604. Perform splicing processing based on the independent parameter set and the preset parameter set to determine the target parameter set.
[0243] Optionally, the matrix dimension of the preset parameter set is determined. Based on the row direction of the matrix dimension, the independent parameter set and the preset parameter set are concatenated row by row to obtain the target parameter set.
[0244] Optionally, determine the matrix dimension of the preset parameter set. Obtain the number of rows M of the independent parameter set, where M is a positive integer. Replace the last M rows of the preset parameter set with the independent parameter set to obtain the target parameter set.
[0245] The following is an exemplary description of this optional implementation method.
[0246] For example, when the preset parameter set is a 10000*20 matrix and the preset threshold is 6000, the preset threshold represents the number of commonly used characters in the pre-trained language model. Typically, the response information output by the language model is a sentence composed of characters selected from the first preset threshold; that is, for the language model, when the preset threshold is 6000, the response information output by the language model is a sentence composed of characters selected from the first 6000. When the independent parameter set is a 100*20 matrix, the last 100 rows of this 10000*20 matrix are replaced with the independent parameter set. The resulting 10000*20 matrix is then used as the target parameter set.
[0247] S605. Use the target parameter set as the parameters of the pre-trained language model to obtain the target pre-trained language model.
[0248] S606. Input the dialogue information into the target pre-trained language model, and the target pre-trained language model outputs the target response information in response to the dialogue information.
[0249] Optionally, the explanation and description of step S606 can refer to the explanation and description of step S305 above, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0250] The dialogue response method provided in this application allows all virtual characters' dialogue response functions to be implemented using the same model framework. That is, by flexibly switching between independent parameter sets concatenated with preset parameter sets within a single model framework, different virtual character response models can be flexibly switched within that framework. Therefore, to implement a dialogue response method for a newly added virtual character within the same model framework, it is only necessary to add an independent parameter set corresponding to that new virtual character to the model framework, avoiding the enormous computational and storage pressure caused by repeatedly loading the preset parameter set corresponding to the pre-trained language model.
[0251] Figure 7 This is a schematic diagram of a dialogue response device provided in an embodiment of this application. Figure 7 As shown, the dialogue response device includes: an acquisition module 701, a first determination module 702, a second determination module 703, a first processing module 704, and a second processing module 705.
[0252] like Figure 7 As shown, it includes:
[0253] Module 701 is used to acquire the target role identifier and dialogue information;
[0254] The first determining module 702 is used to determine the independent parameter set corresponding to the target role identifier based on the target role identifier;
[0255] The second determining module 703 is used to determine the target parameter set based on the independent parameter set and the preset parameter set, wherein the preset parameter set is the initial parameter set of the pre-trained language model;
[0256] The first processing module 704 is used to use the target parameter set as parameters of the pre-trained language model to obtain the target pre-trained language model.
[0257] The second processing module 705 is used to input the dialogue information into the target pre-trained language model, and the target pre-trained language model outputs target response information that responds to the dialogue information.
[0258] Optionally, both the independent parameter set and the preset parameter set are matrices;
[0259] The second determining module 703 is specifically used for:
[0260] The independent parameter set and the preset parameter set are concatenated to obtain the target parameter set.
[0261] Optionally, the second determining module 703 is specifically used for:
[0262] Determine the matrix dimension of the preset parameter set;
[0263] Based on the direction of the matrix dimension, the independent parameter set is concatenated with the preset parameter set to obtain the target parameter set.
[0264] Optionally, the second determining module 703 is specifically used for:
[0265] Based on the row direction of the matrix dimension, the independent parameter set and the preset parameter set are concatenated rowwise to obtain the target parameter set; or;
[0266] Obtain the number of rows M of the independent parameter set, where M is a positive integer; replace the last M rows of the preset parameter set with the independent parameter set to obtain the target parameter set.
[0267] Optionally, the first determining module 702 is specifically used for:
[0268] Based on the target character identifier and the preset correspondence, an independent parameter set corresponding to the target character identifier is determined. The preset correspondence is used to indicate the correspondence between the virtual character, the character identifier, and the independent parameter set. The independent parameter set is a set of parameters that can characterize the language features of the virtual character.
[0269] Optionally, the second processing module 705 is specifically used for:
[0270] The dialogue information is modified according to the prompt text set to obtain the target dialogue information. The prompt text set is text information that can reflect the language characteristics of the target virtual character.
[0271] The target dialogue information is input into the target pre-trained language model, and the target pre-trained language model outputs target response information that responds to the target dialogue information.
[0272] The dialogue response device provided in this embodiment can be used to execute the technical solution of the above-described dialogue response method embodiment. Its implementation principle and technical effect are similar, and will not be described again here.
[0273] Figure 8 This is a schematic diagram of the structure of a language model training device provided in an embodiment of this application. Figure 8 As shown, the language model training device includes: a third determining module 801, a fourth determining module 802, a third processing module 803, a fourth processing module 804, and a fifth processing module 805.
[0274] like Figure 8 As shown, it includes:
[0275] The third determining module 801 is used to determine K first training text sets containing dialogue data of the target virtual character based on N training text sets, wherein the N training text sets include dialogue data of multiple virtual characters interacting with each other; wherein N and K are positive integers, and K is less than or equal to N.
[0276] The fourth determining module 802 is used to determine K second training text sets based on the K first training text sets and the prompt text set of the target virtual character, wherein the prompt text set is text information that can reflect the language characteristics of the target virtual character;
[0277] The third processing module 803 is used to obtain the training parameter set corresponding to the target virtual character based on the preset parameter set and the initial independent parameter set of the pre-trained language model. The initial independent parameter set is used as the learning parameter set to characterize the language features of the target virtual character.
[0278] The fourth processing module 804 is used to use the set of parameters to be trained as parameters of the pre-trained language model to obtain the model to be trained.
[0279] The fifth processing module 805 is used to train the model to be trained based on the K second training text sets to obtain the language model corresponding to the target virtual character. The parameter set of the language model includes an independent parameter set used to characterize the language features of the target virtual character.
[0280] Optionally, the target virtual character type includes a first type and a second type; the virtual characters corresponding to the first type include virtual characters with a corpus size less than a preset threshold, and the virtual characters corresponding to the second type include virtual characters with a corpus size greater than or equal to the preset threshold.
[0281] The third determining module 801 is specifically used for, including:
[0282] When the type of the target virtual character is the first type, the N training text sets are determined as the K first training text sets corresponding to the target virtual character, where N equals K; or...
[0283] When the type of the target virtual character is the second type, for each of the N training text sets, the first processing is performed: if the training text set includes the dialogue data of the target virtual character, the training text set is determined as a first training text set corresponding to the target virtual character; after performing the first processing on all N training text sets, K first training text sets corresponding to the target virtual character are obtained, where N is less than or equal to K.
[0284] Optionally, the fourth determining module 802 is specifically used for:
[0285] Obtain the prompt text set of the target virtual character;
[0286] For each of the K first training text sets, the second processing is performed sequentially:
[0287] When the target virtual character is of the first type, the prompt text set is added before the first training text set to obtain the second training text set; or,
[0288] When the type of the target virtual character is the second type, the prompt text set is added after each target virtual character appearing in the first training text set to obtain the second training text set.
[0289] After performing the second processing on all K first training text sets, K second training text sets corresponding to the target virtual character are obtained.
[0290] Optionally, both the initial independent parameter set and the preset parameter set are matrices.
[0291] Determine the matrix dimension of the preset parameter set;
[0292] Based on the direction of the matrix dimension, the initial independent parameter set is concatenated with the preset parameter set to obtain the parameter set to be trained.
[0293] Optionally, the third processing module 803 is specifically used for:
[0294] Based on the row direction of the matrix dimension, the initial independent parameter set and the preset parameter set are concatenated rowwise to obtain the parameter set to be trained; or;
[0295] Obtain the row number J of the initial independent parameter set, where J is a positive integer; replace the last J rows of the preset parameter set with the initial independent parameter set to obtain the parameter set to be trained.
[0296] The training device provided in this embodiment can be used to execute the technical solution of the above-described language model training method embodiment. Its implementation principle and technical effect are similar, and will not be described again here.
[0297] Figure 9 This is a schematic diagram of the hardware structure of the dialogue response device provided in the embodiments of this application, such as... Figure 9 As shown, the dialogue response device 900 of this application embodiment includes: a processor 901 and a memory 902; wherein the memory 902 is used to store computer execution instructions;
[0298] The processor 901 is used to execute computer execution instructions stored in the memory to implement the various steps performed by the dialogue response method in the above embodiments. For details, please refer to the relevant descriptions in the foregoing method embodiments.
[0299] Optionally, the memory 902 can be either standalone or integrated with the processor 901. When the memory 902 is set up independently, the dialog response device also includes a bus 903 for connecting the memory 902 and the processor 901.
[0300] Figure 10This is a schematic diagram of the hardware structure of the language model training device provided in the embodiments of this application, such as... Figure 10 As shown, the language model training device 1000 of this application embodiment includes: a processor 1001 and a memory 1002; wherein
[0301] Memory 1002 is used to store computer-executed instructions;
[0302] The processor 1001 is used to execute computer execution instructions stored in the memory to implement the various steps of the language model training method in the above embodiments. For details, please refer to the relevant descriptions in the foregoing method embodiments.
[0303] Optionally, the memory 1002 can be either standalone or integrated with the processor 1001. When the memory 1002 is set up independently, the language model training device also includes a bus 1003 for connecting the memory 1002 and the processor 1001.
[0304] This application also provides a computer-readable storage medium storing computer-executable instructions. When a processor executes the computer-executable instructions, it implements the dialogue response method executed by the above-mentioned dialogue response device, or the language model training method executed by the above-mentioned language model training device.
[0305] This application also provides a computer program product, which includes: a computer program stored in a readable storage medium, at least one processor of an electronic device can read the computer program from the readable storage medium, and at least one processor executes the computer program to cause the electronic device to perform the scheme provided in any embodiment of the above-described dialogue response method, or the scheme provided in any embodiment of the above-described language model training method.
[0306] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or modules, and may be electrical, mechanical, or other forms.
[0307] The integrated modules implemented as software functional modules described above can be stored in a computer-readable storage medium. These software functional modules, stored in a storage medium, include several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute some steps of the methods described in the various embodiments of this application.
[0308] It should be understood that the aforementioned processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. A general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly manifested as execution by a hardware processor, or execution by a combination of hardware and software modules within the processor.
[0309] The memory may include high-speed RAM, and may also include non-volatile storage (NVM), such as at least one disk storage device, and may also be a USB flash drive, external hard drive, read-only memory, disk or optical disc, etc.
[0310] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.
[0311] The aforementioned storage medium can be implemented from any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The storage medium can be any available medium accessible to general-purpose or special-purpose computers.
[0312] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.
[0313] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. A dialogue response method, characterized in that, The method includes: Obtain the target character identifier and dialogue information; Based on the target role identifier, determine the independent parameter set corresponding to the target role identifier; Based on the independent parameter set and the preset parameter set, a target parameter set is determined, wherein the preset parameter set is the initial parameter set of the pre-trained language model; The target parameter set is used as the parameters of the pre-trained language model to obtain the target pre-trained language model; The dialogue information is input into the target pre-trained language model, and the target pre-trained language model outputs target response information in response to the dialogue information; The step of determining the independent parameter set corresponding to the target role identifier based on the target role identifier includes: Based on the target character identifier and the preset correspondence, an independent parameter set corresponding to the target character identifier is determined. The preset correspondence is used to indicate the correspondence between the virtual character, the character identifier, and the independent parameter set. The independent parameter set is a set of parameters that can characterize the language features of the virtual character.
2. The dialogue response method according to claim 1, characterized in that, Both the independent parameter set and the preset parameter set are matrices; The step of determining the target parameter set based on the independent parameter set and the preset parameter set includes: The independent parameter set and the preset parameter set are concatenated to obtain the target parameter set.
3. The dialogue response method according to claim 2, characterized in that, The step of concatenating the independent parameter set and the preset parameter set to obtain the target parameter set includes: Determine the matrix dimension of the preset parameter set; Based on the direction of the matrix dimension, the independent parameter set is concatenated with the preset parameter set to obtain the target parameter set.
4. The dialogue response method according to claim 3, characterized in that, The step of concatenating the independent parameter set with the preset parameter set according to the direction of the matrix dimension to obtain the target parameter set includes: Based on the row direction of the matrix dimension, the independent parameter set and the preset parameter set are concatenated rowwise to obtain the target parameter set; or; Obtain the number of rows M of the independent parameter set, where M is a positive integer; replace the last M rows of the preset parameter set with the independent parameter set to obtain the target parameter set.
5. The dialogue response method according to claim 1, characterized in that, The step of inputting the dialogue information into the target pre-trained language model, and the target pre-trained language model outputting target response information in response to the dialogue information, includes: The dialogue information is modified according to the prompt text set to obtain the target dialogue information, where the prompt text set is text information that reflects the language characteristics of the target virtual character; The target dialogue information is input into the target pre-trained language model, and the target pre-trained language model outputs target response information that responds to the target dialogue information.
6. A language model training method, characterized in that, The method includes: Based on N training text sets, determine K first training text sets containing dialogue corpora of the target virtual character. The N training text sets include corpora of dialogues between multiple virtual characters. Wherein, N and K are positive integers, and K is less than or equal to N. Based on the K first training text sets and the prompt text set of the target virtual character, K second training text sets are determined, wherein the prompt text set is text information reflecting the language characteristics of the target virtual character; Based on the preset parameter set and initial independent parameter set of the pre-trained language model, the training parameter set corresponding to the target virtual character is obtained. The initial independent parameter set is used as the learning parameter set to characterize the language features of the target virtual character. The set of parameters to be trained is used as the parameters of the pre-trained language model to obtain the model to be trained; The model to be trained is trained based on the K second training text sets to obtain the language model corresponding to the target virtual character. The parameter set of the language model includes an independent parameter set used to characterize the language features of the target virtual character. Both the initial independent parameter set and the preset parameter set are matrices; The step of obtaining the training parameter set corresponding to the target virtual character based on the preset parameter set and the initial independent parameter set of the pre-trained language model includes: Determine the matrix dimension of the preset parameter set; Based on the direction of the matrix dimension, the initial independent parameter set is concatenated with the preset parameter set to obtain the parameter set to be trained.
7. The language model training method according to claim 6, characterized in that, The target virtual character types include a first type and a second type; the virtual characters corresponding to the first type include virtual characters whose corpus quantity is less than a preset quantity threshold, and the virtual characters corresponding to the second type include virtual characters whose corpus quantity is greater than or equal to the preset quantity threshold. The step of determining K first training text sets containing dialogue data of the target virtual character based on N training text sets includes: When the type of the target virtual character is the first type, the N training text sets are determined as the K first training text sets corresponding to the target virtual character, where N equals K; or, When the type of the target virtual character is the second type, for each of the N training text sets, the first processing is performed: if the training text set includes the dialogue data of the target virtual character, the training text set is determined as a first training text set corresponding to the target virtual character; after performing the first processing on all N training text sets, K first training text sets corresponding to the target virtual character are obtained, where N is less than or equal to K.
8. The language model training method according to claim 7, characterized in that, The step of determining K second training text sets based on the K first training text sets and the prompt text set of the target virtual character includes: Obtain the prompt text set of the target virtual character; For each of the K first training text sets, the second processing is performed sequentially to obtain the K second training text sets corresponding to the target virtual character: The second process consists of the following steps: When the target virtual character is of the first type, the prompt text set is added before the first training text set to obtain the second training text set; or, When the type of the target virtual character is the second type, the prompt text set is added after each target virtual character appearing in the first training text set to obtain the second training text set.
9. The language model training method according to claim 6, characterized in that, The step of obtaining the training parameter set corresponding to the target virtual character based on the preset parameter set and the initial independent parameter set of the language model to be trained includes: Based on the row direction of the matrix dimension, the initial independent parameter set and the preset parameter set are concatenated rowwise to obtain the parameter set to be trained; or; Obtain the row number J of the initial independent parameter set, where J is a positive integer; replace the last J rows of the preset parameter set with the initial independent parameter set to obtain the parameter set to be trained.
10. A dialogue response device, characterized in that, The device includes: The acquisition module is used to acquire the target role identifier and dialogue information; The first determining module is used to determine the independent parameter set corresponding to the target role identifier based on the target role identifier; The second determining module is used to determine the target parameter set based on the independent parameter set and the preset parameter set, wherein the preset parameter set is the initial parameter set of the pre-trained language model; The first processing module is used to use the target parameter set as parameters of the pre-trained language model to obtain the target pre-trained language model. The second processing module is used to input the dialogue information into the target pre-trained language model, and the target pre-trained language model outputs target response information in response to the dialogue information; The step of determining the independent parameter set corresponding to the target role identifier based on the target role identifier includes: Based on the target character identifier and the preset correspondence, an independent parameter set corresponding to the target character identifier is determined. The preset correspondence is used to indicate the correspondence between the virtual character, the character identifier, and the independent parameter set. The independent parameter set is a set of parameters that can characterize the language features of the virtual character.
11. A language model training device, characterized in that, The device includes: The third determining module is used to determine K first training text sets containing dialogue data of the target virtual character based on N training text sets. The N training text sets include corpora of dialogues between multiple virtual characters. N and K are positive integers, and K is less than or equal to N. The fourth determining module is used to determine K second training text sets based on the K first training text sets and the prompt text set of the target virtual character, wherein the prompt text set is text information reflecting the language characteristics of the target virtual character; The third processing module is used to obtain the training parameter set corresponding to the target virtual character based on the preset parameter set and the initial independent parameter set of the pre-trained language model. The initial independent parameter set is used as the learning parameter set to characterize the language features of the target virtual character. The fourth processing module is used to use the set of parameters to be trained as parameters of the pre-trained language model to obtain the model to be trained. The fifth processing module is used to train the model to be trained based on the K second training text sets to obtain the language model corresponding to the target virtual character. The parameter set of the language model includes an independent parameter set for characterizing the language features of the target virtual character. Both the initial independent parameter set and the preset parameter set are matrices; The step of obtaining the training parameter set corresponding to the target virtual character based on the preset parameter set and the initial independent parameter set of the pre-trained language model includes: Determine the matrix dimension of the preset parameter set; Based on the direction of the matrix dimension, the initial independent parameter set is concatenated with the preset parameter set to obtain the parameter set to be trained.
12. A dialogue response device, characterized in that, include: The memory and the processor are coupled; The memory is used to store one or more computer instructions; The processor is used to execute one or more computer instructions to implement the dialogue response method as described in any one of claims 1-5.
13. A language model training device, characterized in that, include: The memory and the processor are coupled; The memory is used to store one or more computer instructions; The processor is used to execute one or more computer instructions to implement the language model training method as described in any one of claims 6-9.
14. A computer-readable storage medium, characterized in that, The system stores a data processing program that is executed by a processor to perform the dialogue response method as described in any one of claims 1-5, or to perform the language model training method as described in any one of claims 6-9.