Role dialogue model training method, dialogue generation method and device
By structurally adjusting the role dialogue model and training multiple sets of data, the problem of high training cost of role dialogue models in the existing technology is solved, efficient deployment and reasoning on small devices is achieved, and the role consistency and stability of the model are improved. sex.
Patent Information
- Application Number
- CN202410941879.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-15
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-07-15
AI Technical Summary
The training cost of character dialogue models in the existing technology is very high, mainly due to the large number of parameters of large-scale language models, which leads to huge consumption of computing resources and is difficult to deploy and reason on small devices.
By structurally adjusting the character dialogue model to be trained, introducing a character embedding module and a vector conversion module, the target character information is embedded into the learnable parameters of the normalization layer, and multiple sets of character dialogue data are used for training to generate trained characters. Dialog model, remove embedding module and vector transformation module to reduce model size.
It achieves better character dialogue model training effects on traditional small models, greatly reduces training and inference costs, enables the character dialogue model to be deployed on small devices such as mobile phones and microcomputers, and improves the role consistency and stability of the model. sex.
Smart Images

Figure CN118467711B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a method for training a role dialogue model, a method for generating a dialogue, and a device. Background Art
[0002] Role-playing dialogue is an important direction of dialogue tasks and an important application form of current large models. Through role-playing, the model can simulate the language style and behavioral characteristics of a specific role, so as to better interact with users.
[0003] At present, the main method to obtain the role dialogue model is to directly build the corresponding prompt or guide prompt based on the large language model (LLM) such as chatgpt to achieve role playing, or to fine-tune a role dialogue model based on LLM such as llama3-8b. Due to the large number of LLM parameters, the corresponding computing resources consumed during reasoning are huge, resulting in very high training costs. Summary of the invention
[0004] The present invention provides a training method, a dialogue generation method and a device for a role dialogue model, so as to solve the defect that the training cost of the role dialogue model in the prior art is very high. By structurally adjusting the role dialogue model to be trained and training the model to obtain a trained role dialogue model, better training effect can be obtained, and the training reasoning cost is greatly reduced.
[0005] The present invention provides a method for training a role dialogue model, comprising the following steps.
[0006] Acquire a role dialogue model to be trained, wherein a normalization layer of the role dialogue model to be trained includes a target learnable parameter, wherein the target learnable parameter is determined according to an input role embedding vector, wherein the role embedding vector is obtained by embedding target role information, and the target role information is used to characterize characteristics of the target role;
[0007] The role dialogue model to be trained is trained using multiple groups of role dialogue data to obtain a trained role dialogue model.
[0008] According to a method for training a role dialogue model provided by the present invention, the step of obtaining the role dialogue model to be trained comprises:
[0009] Adding a role embedding module to the initial role dialogue model to obtain a modified role dialogue model, wherein the role embedding module is used to convert the received target role information into the role embedding vector, and input the role embedding vector into a normalization layer of the modified role dialogue model;
[0010] A vector conversion module is added to the normalized layer of the modified role dialogue model, and the initial learnable parameters of the normalized layer of the modified role dialogue model are updated to the target learnable parameters to obtain the role dialogue model to be trained. The vector conversion module is used to convert the received role embedding vector into a role adjustment parameter, and the target learnable parameter is determined based on the initial learnable parameter and the role adjustment parameter.
[0011] According to a training method for a role dialogue model provided by the present invention, the target role information includes role feature information and role style information, the role embedding module includes a feature embedding module and a style embedding module, the feature embedding module is used to convert the received role feature information into a feature embedding vector and input it into the normalization layer of the modified role dialogue model, the style embedding module is used to convert the received role style information into a style embedding vector and input it into the normalization layer of the modified role dialogue model, the feature embedding vector and the style embedding vector constitute the role embedding vector.
[0012] According to a training method for a role dialogue model provided by the present invention, the vector conversion module includes a feature conversion module and a style conversion module, the feature conversion module is used to convert the input feature embedding vector into a feature adjustment parameter, the style conversion module is used to convert the style embedding vector into a style adjustment parameter, the feature adjustment parameter and the style adjustment parameter constitute the role adjustment parameter, the initial learnable parameter includes an initial scaling parameter and an initial offset parameter, the target learnable parameter includes a target scaling parameter and a target offset parameter, the target scaling parameter is determined according to the feature adjustment parameter and the initial scaling parameter, and the target offset parameter is determined according to the style adjustment parameter and the initial offset parameter.
[0013] According to a method for training a role dialogue model provided by the present invention, the initial role dialogue model is a pre-trained dialogue model obtained by training using multiple groups of dialogue data samples; after the role dialogue model to be trained is trained using multiple groups of role dialogue data to obtain a trained role dialogue model, the method further includes:
[0014] Delete the role embedding module and the vector conversion module in the trained role dialogue model.
[0015] The present invention provides a dialogue generation method, comprising the following steps.
[0016] Get the question sentence;
[0017] The question statement is input into a trained role dialogue model to obtain a reply statement of the target role corresponding to the question statement, wherein the trained role dialogue model is obtained by training the role dialogue model to be trained using multiple groups of role dialogue data, and the normalization layer of the role dialogue model to be trained includes target learnable parameters, which are determined based on an input role embedding vector, and the role embedding vector is obtained by embedding target role information, and the target role information is used to characterize the characteristics of the target role.
[0018] The present invention also provides a role model training device, comprising the following modules:
[0019] A model acquisition module, used for acquiring a role dialogue model to be trained, wherein the normalization layer of the role dialogue model to be trained includes a target learnable parameter, wherein the target learnable parameter is determined according to an input role embedding vector, wherein the role embedding vector is obtained by embedding target role information, and the target role information is used to characterize the characteristics of the target role;
[0020] The model training module is used to train the role dialogue model to be trained using multiple groups of role dialogue data to obtain a trained role dialogue model.
[0021] The present invention also provides a dialogue generation device, comprising the following modules:
[0022] A sentence acquisition module, used to acquire question sentences;
[0023] A sentence generation module is used to input the question sentence into a trained role dialogue model to obtain a reply sentence of the target role corresponding to the question sentence, wherein the trained role dialogue model is obtained by training the role dialogue model to be trained using multiple groups of role dialogue data, and the normalization layer of the role dialogue model to be trained includes target learnable parameters, which are determined based on an input role embedding vector, and the role embedding vector is obtained by embedding target role information, and the target role information is used to characterize the characteristics of the target role.
[0024] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the processor implements any of the above-described method for training a role dialogue model or the method for generating a dialogue.
[0025] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the above-described method for training a role dialogue model or the above-described method for generating a dialogue.
[0026] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the above-mentioned method for training a role dialogue model or the above-mentioned method for generating a dialogue.
[0027] The character dialogue model training method, dialogue generation method and device provided by the present invention can obtain a trained character dialogue model by structural adjustment and model training of the character dialogue model to be trained, thereby achieving better training results and greatly reducing the training reasoning cost. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0029] Figure 1 This is one of the flow charts of the training method of the role dialogue model provided by the present invention.
[0030] Figure 2 It is a flowchart of the method for obtaining a role dialogue model to be trained provided by the present invention.
[0031] Figure 3 It is a schematic diagram of the structure of the role dialogue model to be trained provided by the present invention.
[0032] Figure 4 This is the second flow chart of the method for training the role dialogue model provided by the present invention.
[0033] Figure 5 It is a flow chart of the dialogue generation method provided by the present invention.
[0034] Figure 6 It is a schematic diagram of the overall flow of the dialogue generation method provided by the present invention.
[0035] Figure 7 A schematic structural diagram of a role model training device provided by the present invention.
[0036] Figure 8 This is a schematic diagram of the structure of the dialogue generation device provided by the present invention.
[0037] Fig. 9 It is a schematic diagram of the physical structure of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0038] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0039] Role-playing dialogue is an important direction of dialogue tasks and an important application form of current large models. Through role-playing, the model can simulate the language style and behavioral characteristics of a specific role, so as to better interact with users. At present, the main approach to obtaining a role dialogue model is to directly build corresponding prompts or guides based on a large language model (LLM) such as chatgpt to achieve role-playing, or to fine-tune a role dialogue model based on LLM such as llama3-8b.
[0040] All feasible solutions in the existing technology are based on LLM. Due to the large number of LLM parameters, the corresponding computing resources consumed during reasoning are huge, resulting in very high training costs.
[0041] In view of this, the present invention provides a training method for a role dialogue model, by obtaining a role dialogue model to be trained, the normalization layer of the role dialogue model to be trained includes target learnable parameters, the target learnable parameters are determined according to an input role embedding vector, the role embedding vector is obtained by embedding target role information, and the target role information is used to characterize the characteristics of the target role; multiple groups of role dialogue data are used to train the role dialogue model to be trained to obtain a trained role dialogue model, which can obtain better training effect and greatly reduce the training reasoning cost.
[0042] The technical solutions in the embodiments of the present invention will be described below in conjunction with the accompanying drawings in the embodiments of the present invention.
[0043] Figure 1 This is one of the flow charts of the role dialogue model training method provided by the present invention. The role dialogue model training method can be applied to electronic devices, which can be various types of devices with information processing capabilities during implementation. For example, the electronic device can include a personal computer, a laptop computer, a PDA or a server, etc.; the electronic device can also be a mobile terminal, for example, the mobile terminal can include a mobile phone, a car computer, a tablet computer or a projector, etc. Figure 1 As shown, the method includes the following:
[0044] Step 101: Obtain a role dialogue model to be trained, wherein a normalization layer of the role dialogue model to be trained includes target learnable parameters, wherein the target learnable parameters are determined based on an input role embedding vector, wherein the role embedding vector is obtained by embedding target role information, and the target role information is used to characterize characteristics of the target role.
[0045] It should be noted that the role dialogue model to be trained includes a normalization layer, and the normalization layer includes learnable parameters. The present invention can input the role embedding vector into the normalization layer of the modified role dialogue model, and the learnable parameters can be adjusted according to the role embedding vector, that is, the role embedding vector is integrated into the learnable parameters, so that the content generated by the model has the characteristics of the target role. The role embedding vector is obtained by embedding the target role information, and the target role information is used to characterize the characteristics of the target role. The target role information is used to characterize the characteristics of the target role.
[0046] The method for obtaining the role dialogue model to be trained may be to adjust the model structure, train the model, etc. The present invention does not limit the method for obtaining the role dialogue model to be trained.
[0047] Step 102: Use multiple groups of role dialogue data to train the role dialogue model to be trained to obtain a trained role dialogue model.
[0048] It should be noted that the method of using multiple sets of role dialogue data to train the role dialogue model to be trained can adopt existing methods, and the present invention does not limit the method of using multiple sets of role dialogue data to train the role dialogue model to be trained.
[0049] Exemplarily, the style of the character dialogue data can be annotated, which can be manual or predicted by an open source model. The granularity of the annotation can be the session level or can be refined to the sentences of the character in each round. The present invention does not limit the types and annotations of multiple groups of character dialogue data. The character dialogue model to be trained can be a sequence-to-sequence seq2seq model, and the character dialogue data can be used to train seq2seq in a normal way.
[0050] It can be understood that the present invention, by introducing the conditional layer normalization technology, embeds the target role information into the embedding process and "integrates" it into the learnable parameters in the normalized layer normalization layer, so that the content style generated by the model is more stable and more consistent with the target role.
[0051] In addition, the solution of the present invention can be applied to traditional small models to achieve better results. For example, the role dialogue model can be trained based on small models such as GPT2 / UniLM / T5. Whether in the training or reasoning stage, the corresponding computing resources are much smaller. Due to its small number of parameters, the training / inference cost is greatly reduced, and it can be deployed on small devices such as mobile phones / microcomputers / tablets.
[0052] In some embodiments, the target character information may be processed by setting an embedding module and then input into the normalization layer.
[0053] Figure 2 FIG. 1 is a flow chart of a method for obtaining a role dialogue model to be trained provided by the present invention. Figure 2 As shown, obtaining the role dialogue model to be trained may include:
[0054] Step 201: Add a role embedding module to the initial role dialogue model to obtain a modified role dialogue model, wherein the role embedding module is used to convert the received target role information into the role embedding vector, and input the role embedding vector into the normalization layer of the modified role dialogue model. The feature embedding vector and the style embedding vector constitute the role embedding vector.
[0055] It should be noted that a role embedding module can be added to the initial role dialogue model to obtain a modified role dialogue model. The role embedding module converts the input target role information into a role embedding vector. The conversion method of the role embedding module can adopt the existing technology, and the present invention does not limit the method in which the role embedding module converts the received target role information into the role embedding vector.
[0056] Step 202: Add a vector conversion module to the normalized layer of the modified role dialogue model, and update the initial learnable parameters of the normalized layer of the modified role dialogue model to the target learnable parameters to obtain the role dialogue model to be trained, wherein the vector conversion module is used to convert the received role embedding vector into a role adjustment parameter, and the target learnable parameter is determined based on the initial learnable parameter and the role adjustment parameter.
[0057] It should be noted that after adding the role embedding module, the normalization layer is added with a vector conversion module, which is used to convert the received role embedding vector into a role adjustment parameter, and according to the role adjustment parameter and the initial learnable parameter, the target learnable parameter can be determined, that is, the target learnable parameter is determined according to the initial learnable parameter and the role adjustment parameter. The vector conversion module can use a fully connected Dense layer when implemented.
[0058] Exemplarily, the target learnable parameter=initial learning parameter+role adjustment parameter, that is, the target learning parameter may be equal to the sum of the initial learning parameter and the role adjustment parameter.
[0059] It can be understood that by modifying the initial role dialogue model, adding a role embedding module, a vector conversion module and a calculation method for updating the learnable parameters, the role dialogue model to be trained can be obtained, which can enable the role dialogue model to be trained to "integrate" the target role information into the learnable parameters in the normalization layer, so that the content style generated by the model is more stable and more consistent with the target role.
[0060] Furthermore, the target character information includes character feature information and character style information, and the character embedding module includes a feature embedding module and a style embedding module. The feature embedding module is used to convert the received character feature information into a feature embedding vector and input it into the normalization layer of the modified character dialogue model. The style embedding module is used to convert the received character style information into a style embedding vector and input it into the normalization layer of the modified character dialogue model. The feature embedding vector and the style embedding vector constitute the character embedding vector.
[0061] It should be noted that by modifying the initial character dialogue model code, two new modules can be added: a style embedding module and a feature embedding module. The feature embedding module can convert the received character feature information into a feature embedding vector and input it into the normalization layer of the modified character dialogue model. The style embedding module is used to convert the received character style information into a style embedding vector and input it into the normalization layer of the modified character dialogue model. The feature embedding vector and the style embedding vector constitute the character embedding vector. By inputting two different types of information into the learnable parameters of the normalization layer, the content style generated by the model can better highlight the characteristics of the target character and be more consistent with the target character.
[0062] Furthermore, the vector conversion module includes a feature conversion module and a style conversion module, the feature conversion module is used to convert the input feature embedding vector into a feature adjustment parameter, the style conversion module is used to convert the style embedding vector into a style adjustment parameter, the feature adjustment parameter and the style adjustment parameter constitute the character adjustment parameter, the initial learnable parameter includes an initial scaling parameter and an initial offset parameter, the target learnable parameter includes a target scaling parameter and a target offset parameter, the target scaling parameter is determined based on the feature adjustment parameter and the initial scaling parameter, and the target offset parameter is determined based on the style adjustment parameter and the initial offset parameter.
[0063] It should be noted that the network structure of the initial character dialogue model can be modified, and the feature conversion module and style conversion module can be added to the normalization layer in the network to adjust the initial scaling parameter α and the initial offset parameter β. The target scaling parameter α′=initial scaling parameter α+feature conversion character-adapter (feature embedding vector character-embedding) / feature adjustment parameter; target offset parameter β′=initial offset parameter β+style conversion style-adapter (style embedding vector style-embedding) / style adjustment parameter.
[0064] It can be understood that by introducing the conditional layer normalization technology, the feature information and style information of the target character are embedded and "integrated" into the two parameters of the scaling parameter and offset parameter in the normalization layer layernormalization, respectively, so that the content style generated by the trained model is more stable and significant, and more consistent with the target character.
[0065] Figure 3 Schematic diagram of the structure of the role dialogue model to be trained provided by the present invention. Figure 3 As shown, the transformer model transformer introduces the conditional layer normalization technology to obtain the modified transformer model transformer, that is, the role dialogue model to be trained. The modified transformer model includes a feature embedding module and a style embedding module. The input end of the feature embedding module is connected to the input feature information, and the output end is connected to the normalization layer. The input end of the style embedding module is connected to the input style information, and the output end is connected to the normalization layer. The normalization layer of the modified transformer model also includes a feature conversion module and a style conversion module. The feature conversion module is used to convert the input feature embedding vector into the feature adjustment parameter, and the style conversion module is used to convert the style embedding vector into the style adjustment parameter. Since the normalization layer is set in multiple components (multi-head attention, forward transmission) of the transformer model, the output end of the feature embedding module will be connected to the feature conversion module of the normalization layer, and the output end of the style embedding module will be connected to the style conversion module of the normalization layer. Then, the initial learnable parameters of the normalization layer in each component are updated to the target learnable parameters, so that the content style generated by the trained model is more stable and significant, and more consistent with the target role.
[0066] In some embodiments, when the amount of character dialogue data is small, we can use a pre-trained dialogue model with dialogue capabilities for training, which can also enable the trained model to acquire character style capabilities.
[0067] In an embodiment of the present invention, the initial role dialogue model may be a pre-trained dialogue model trained using multiple groups of dialogue data samples.
[0068] It should be noted that the dialogue data samples here can be ordinary dialogue data samples, that is, dialogue data without character information. When there is less character dialogue data, the model can be fine-tuned using ordinary dialogue data to make the model have stable dialogue capabilities, and then the character dialogue data can be used to add character information and style information. That is, even with less data resources, a better effect can be obtained, and the requirements for training data are lower.
[0069] It is understandable that for scenarios with less character dialogue data, by introducing pre-dialogue data training, the model first acquires dialogue capabilities, and then uses the character dialogue data to enable the model to acquire character style capabilities. In scenarios with less character dialogue data, good results can be achieved, which improves the convenience of model training.
[0070] Figure 4 FIG. 2 is a flow chart of the training method of the role dialogue model provided by the present invention. Figure 4 As shown, the training method of the role dialogue model may include:
[0071] Step 301: Obtain a role dialogue model to be trained, wherein a normalization layer of the role dialogue model to be trained includes target learnable parameters, wherein the target learnable parameters are determined based on an input role embedding vector, wherein the role embedding vector is obtained by embedding target role information, and the target role information is used to characterize characteristics of the target role.
[0072] It should be noted that the description of step 301 can refer to the description of step 101 in the aforementioned embodiment, which will not be repeated here.
[0073] Step 302: Use multiple groups of role dialogue data to train the role dialogue model to be trained to obtain a trained role dialogue model.
[0074] It should be noted that the description of step 302 can refer to the description of step 102 in the aforementioned embodiment, which will not be repeated here.
[0075] Step 303: Delete the role embedding module and the vector conversion module in the trained role dialogue model.
[0076] It should be noted that after obtaining the trained role dialogue model, the role embedding module and the vector conversion module in the trained role dialogue model may be deleted.
[0077] For example, when training the model, the corresponding feature adjustment parameters character-adapter (character-embedding) / style adjustment parameters style-adapter (style-embedding) have been calculated offline and then added to the normalization layer layer normalization. The network structure of the model can be returned to the unmodified state and deployed online. That is, since the target scaling parameter α′ and the target offset parameter β′ have been trained, the extra modules can be deleted to reduce the space occupied by the model.
[0078] It is understandable that the feature embedding module / style embedding module / feature conversion module / style conversion module are decoupled from the basic model, which is conducive to integrating the newly added modules into the basic model before deployment, so as to return to the basic model structure, which is friendly to deployment. In addition, the feature embedding module and the style embedding module are also decoupled, and can be freely combined in the inference stage, which is also very convenient to use.
[0079] The method for training a role dialogue model provided by the present invention can obtain a better training effect and greatly reduce the training reasoning cost by structurally adjusting the role dialogue model to be trained and training the model to obtain a trained role dialogue model.
[0080] The present invention also provides a method for generating dialogues, which obtains a question sentence; inputs the question sentence into a trained role dialogue model, and obtains a response sentence of a target role corresponding to the question sentence, wherein the trained role dialogue model is obtained by using the training method of the role model. The training model obtained by the model training method can output an accurate response sentence corresponding to the target role.
[0081] Figure 5 Schematic diagram of the flow of the dialogue generation method provided by the present invention. Figure 5 As shown, the dialogue generation method may include:
[0082] Step 401: Obtain a question statement.
[0083] It should be noted that there are many ways to obtain the question sentence, such as through device input, network input, or user input, etc. The present invention does not limit the way to obtain the question sentence.
[0084] Step 402: Input the question statement into a trained role dialogue model to obtain a reply statement of the target role corresponding to the question statement, wherein the trained role dialogue model is obtained by training a role dialogue model to be trained using multiple groups of role dialogue data, wherein the role dialogue model to be trained includes a normalization layer, wherein the normalization layer includes target learnable parameters, wherein the target learnable parameters are determined based on an input role embedding vector, wherein the role embedding vector is obtained by embedding target role information, and the target role information is used to characterize the characteristics of the target role.
[0085] It should be noted that the method of inputting the question statement into the trained role dialogue model can adopt the existing method. The present invention does not limit the method of inputting the question statement into the trained role dialogue model to obtain the response statement of the target character corresponding to the question statement.
[0086] It can be understood that the method for training the role dialogue model to be trained using multiple groups of role dialogue data can be described in the above-mentioned embodiments, which will not be repeated here. The trained role dialogue model obtained by training using the role model training method can achieve better training results, greatly reducing the cost of training reasoning, and using the trained role dialogue model to obtain reply statements can output accurate reply statements corresponding to the target role. Since the above-mentioned model training method and dialogue generation method correspond to a small number of parameters and less computing resources, they can be easily deployed on small devices such as mobile phones / microcomputers / tablets, which is convenient for users to use.
[0087] The following describes an exemplary application of an embodiment of the present invention in a practical application scenario.
[0088] The methods for obtaining character dialogue models in the prior art have the following problems: 1) The effect of directly training based on small models in the prior art is often poor, and its style is difficult to be consistent with the target character, resulting in unusable. 2) The feasible solutions in the prior art are all based on LLM. Due to the large number of LLM parameters, the corresponding computing resources consumed during reasoning are huge, resulting in very high costs. 3) Since the prior art is based on LLM, the graphics memory resources required for fine-tuning are very high, and a single card can no longer meet the requirements. Multiple machines and multiple cards are often required, which increases the difficulty of fine-tuning accordingly. 4) The prior art is based on LLM, and the number of parameters is often large (>1B), which is not friendly to small devices such as mobile phones / microcomputers. It is often impossible to deploy on these devices or the reasoning is very slow.
[0089] Figure 6 FIG. 1 is a schematic diagram of the overall flow of the method for generating a dialogue provided by the present invention. Figure 6 As shown, the method comprises the following steps:
[0090] Step 501: First, the style of the character dialogue data is annotated, which can be done manually or using open source model prediction annotation. The granularity of the annotation can be the session level or refined to the sentence of the character in each round.
[0091] Step 502: Modify the model code and add two modules: style module and character module. The style module includes the style embedding module and the layer normalization style adapter normalization layer style conversion module. The feature module includes the feature embedding module and the layer normalization character adapter normalization layer feature conversion module. Modify the network structure of the model and modify the scaling parameter α and offset parameter β in the normalization layer layer normalization in the network: α′=α+feature conversion character-adapter (feature embedding vector character-embedding); β′=β+style conversion style-adapter (style embedding vector style-embedding). The style conversion module style-adapter / feature conversion module character-adapter can be used in the Dense layer.
[0092] Step 503: Use the character dialogue data to train the model seq2seq normally.
[0093] Step 504: When deploying the model, the corresponding feature adjustment parameters character-adapter (character-embedding) / style adjustment parameters style-adapter (style-embedding) are calculated offline, and then added to the normalization layer layer normalization, and the network structure of the model is returned to the unmodified state, and then deployed online.
[0094] The advantages of the embodiments provided by the present invention include: 1) The conditional layer normalization technology is introduced to explicitly integrate feature information and style information into the model, greatly improving the role consistency of the model. 2) Good results can be obtained on traditional small models, which greatly reduces the training / inference costs and is friendly to devices such as mobile phones and microcomputers. 3) For scenarios with less character dialogue data, by introducing pre-dialogue training, the model first acquires dialogue capabilities, and then uses the character dialogue data to enable the model to acquire character style capabilities. Good results can also be obtained in scenarios with less data. 4) The user feature embedding module / style embedding module / feature conversion module / style conversion module are decoupled from the basic model, which is conducive to integrating the newly added modules into the basic model in advance before deployment, thereby returning to the basic model structure, which is friendly to deployment and online. 5) The feature model and style module are also decoupled, and can be freely combined in the inference stage to facilitate model training.
[0095] The role model training device and the dialogue generation device provided by the present invention are described below. The role model training device described below and the role model training method described above can be referred to in correspondence with each other. The dialogue generation device described below and the dialogue generation method described above can be referred to in correspondence with each other.
[0096] The present invention provides a training device for a role model. The modules included in the device and the units included in the modules can be implemented by a processor; of course, they can also be implemented by a specific logic circuit; during the implementation process, the processor can be a central processing unit (CPU), a microprocessor (MPU), a digital signal processor (DSP) or a field programmable gate array (FPGA), etc.
[0097] Figure 7 The structure diagram of the training device of the role model provided by the present invention is shown in FIG. Figure 7 As shown, the device 600 includes a model acquisition module 601 and a model training module 602, wherein:
[0098] The model acquisition module 601 is used to obtain the role dialogue model to be trained, wherein the role dialogue model to be trained includes a normalization layer, wherein the normalization layer includes target learnable parameters, wherein the target learnable parameters are determined based on an input role embedding vector, wherein the role embedding vector is obtained by embedding target role information, and the target role information is used to characterize the characteristics of the target role.
[0099] The model training module 602 is used to train the role dialogue model to be trained using multiple groups of role dialogue data to obtain a trained role dialogue model.
[0100] Based on the above embodiment, in this embodiment, the model acquisition module 601 includes a role embedding unit and a parameter modification unit, wherein:
[0101] The role embedding unit is used to add a role embedding module to the initial role dialogue model to obtain a modified role dialogue model, and the role embedding module is used to convert the received target role information into the role embedding vector, and input the role embedding vector into the normalization layer of the modified role dialogue model;
[0102] The parameter modification unit is used to add a vector conversion module to the normalized layer of the modified role dialogue model, and to update the initial learnable parameters of the normalized layer of the modified role dialogue model to the target learnable parameters, so as to obtain the role dialogue model to be trained. The vector conversion module is used to convert the received role embedding vector into a role adjustment parameter, and the target learnable parameter is determined based on the initial learnable parameters and the role adjustment parameters.
[0103] Based on the above embodiments, in this embodiment, the character embedding unit is specifically used for: the target character information includes character feature information and character style information, the character embedding module includes a feature embedding module and a style embedding module, the feature embedding module is used to convert the received character feature information into a feature embedding vector and input it into the normalization layer of the modified character dialogue model, the style embedding module is used to convert the received character style information into a style embedding vector and input it into the normalization layer of the modified character dialogue model, the feature embedding vector and the style embedding vector constitute the character embedding vector.
[0104] Based on the above embodiments, in this embodiment, the vector conversion module includes a feature conversion module and a style conversion module, the feature conversion module is used to convert the input feature embedding vector into a feature adjustment parameter, the style conversion module is used to convert the style embedding vector into a style adjustment parameter, the feature adjustment parameter and the style adjustment parameter constitute the character adjustment parameter, the initial learnable parameter includes an initial scaling parameter and an initial offset parameter, the target learnable parameter includes a target scaling parameter and a target offset parameter, the target scaling parameter is determined based on the feature adjustment parameter and the initial scaling parameter, and the target offset parameter is determined based on the style adjustment parameter and the initial offset parameter.
[0105] Based on the above embodiments, in this embodiment, the initial role dialogue model is a pre-trained dialogue model trained using multiple groups of dialogue data samples.
[0106] Based on the above embodiments, in this embodiment, the device further includes a role deletion module, which is used to delete the role embedding module and the vector conversion module in the trained role dialogue model.
[0107] In the embodiment of the present invention, by structurally adjusting the role dialogue model to be trained and training the model to obtain a trained role dialogue model, better training effect can be achieved, and the training reasoning cost is greatly reduced.
[0108] Figure 8 This is a schematic diagram of the structure of the dialogue generation device provided by the present invention. Figure 8 As shown, the device 700 includes a statement acquisition module 701 and a statement generation module 702, wherein:
[0109] The sentence acquisition module 701 is used to acquire the question sentence;
[0110] The sentence generation module 702 is used to input the question sentence into a trained role dialogue model to obtain a response sentence of the target role corresponding to the question sentence. The trained role dialogue model is trained using the above-mentioned role dialogue model training method.
[0111] In an embodiment of the present invention, the training model obtained using the above-mentioned model training method can output accurate reply sentences corresponding to the target role.
[0112] Fig. 9 is a schematic diagram of the physical structure of the electronic device provided by the present invention, such as Fig. 9 As shown, the electronic device may include: a processor 801, a communication interface 802, a memory 803 and a communication bus 804, wherein the processor 801, the communication interface 802 and the memory 803 communicate with each other through the communication bus 804. The processor 801 may call the logic instructions in the memory 803 to execute the training method of the role dialogue model, the method comprising: obtaining the role dialogue model to be trained, the normalization layer of the role dialogue model to be trained includes the target learnable parameter, the target learnable parameter is determined according to the input role embedding vector, the role embedding vector is obtained by embedding the target role information, and the target role information is used to characterize the characteristics of the target role; using multiple groups of role dialogue data to train the role dialogue model to be trained to obtain a trained role dialogue model.
[0113] In addition, the logic instructions in the above-mentioned memory 803 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a disk or an optical disk.
[0114] On the other hand, the present invention also provides a computer program product, which includes a computer program. The computer program can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the training method of the role dialogue model provided by the above methods, the method including: obtaining the role dialogue model to be trained, the normalization layer of the role dialogue model to be trained includes target learnable parameters, the target learnable parameters are determined based on the input role embedding vector, the role embedding vector is obtained by embedding the target role information, and the target role information is used to characterize the characteristics of the target role; using multiple groups of role dialogue data to train the role dialogue model to be trained to obtain a trained role dialogue model.
[0115] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a server or data center that includes one or more available media integrated therein. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive Solid State Disk (SSD)), etc.
[0116] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, it is implemented to execute the training method of the role dialogue model provided by the above-mentioned methods, the method comprising: obtaining the role dialogue model to be trained, the normalization layer of the role dialogue model to be trained including target learnable parameters, the target learnable parameters are determined based on the input role embedding vector, the role embedding vector is obtained by embedding the target role information, and the target role information is used to characterize the characteristics of the target role; using multiple groups of role dialogue data to train the role dialogue model to be trained to obtain a trained role dialogue model.
[0117] The above-mentioned computer-readable storage medium can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, - but not limited to - an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM) or flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.
[0118] Computer-readable signal media may include a data signal propagated in baseband or as part of a carrier wave, which carries a computer-readable program code. Such propagated data signals may take a variety of forms, including, but not limited to, electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0119] The program code embodied on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wire, optical cable, radio frequency (RF), etc., or any suitable combination of the foregoing.
[0120] Computer program code for performing the operations of the present specification may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0121] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0122] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0123] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for training a role dialogue model, characterized in that: include: Acquire a role dialogue model to be trained, wherein a normalization layer of the role dialogue model to be trained includes a target learnable parameter, wherein the target learnable parameter is determined according to an input role embedding vector, wherein the role embedding vector is obtained by embedding target role information, and the target role information is used to characterize characteristics of the target role; Using multiple groups of role dialogue data to train the role dialogue model to be trained to obtain a trained role dialogue model; The step of obtaining the role dialogue model to be trained includes: Adding a role embedding module to the initial role dialogue model to obtain a modified role dialogue model, wherein the role embedding module is used to convert the received target role information into the role embedding vector, and input the role embedding vector into a normalization layer of the modified role dialogue model; A vector conversion module is added to the normalized layer of the modified role dialogue model, and the initial learnable parameters of the normalized layer of the modified role dialogue model are updated to the target learnable parameters to obtain the role dialogue model to be trained. The vector conversion module is used to convert the received role embedding vector into a role adjustment parameter, and the target learnable parameter is determined based on the initial learnable parameter and the role adjustment parameter.
2. The method for training a role dialogue model according to claim 1, characterized in that: The target character information includes character feature information and character style information. The character embedding module includes a feature embedding module and a style embedding module. The feature embedding module is used to convert the received character feature information into a feature embedding vector and input it into the normalization layer of the modified character dialogue model. The style embedding module is used to convert the received character style information into a style embedding vector and input it into the normalization layer of the modified character dialogue model. The feature embedding vector and the style embedding vector constitute the character embedding vector.
3. The method for training a role dialogue model according to claim 2, characterized in that: The vector conversion module includes a feature conversion module and a style conversion module. The feature conversion module is used to convert the input feature embedding vector into a feature adjustment parameter. The style conversion module is used to convert the style embedding vector into a style adjustment parameter. The feature adjustment parameter and the style adjustment parameter constitute the character adjustment parameter. The initial learnable parameter includes an initial scaling parameter and an initial offset parameter. The target learnable parameter includes a target scaling parameter and a target offset parameter. The target scaling parameter is determined based on the feature adjustment parameter and the initial scaling parameter. The target offset parameter is determined based on the style adjustment parameter and the initial offset parameter.
4. The method for training a role dialogue model according to claim 1, characterized in that: The initial role dialogue model is a pre-trained dialogue model obtained by training using multiple groups of dialogue data samples; after the role dialogue model to be trained is trained using multiple groups of role dialogue data to obtain a trained role dialogue model, the method further includes: Delete the role embedding module and the vector conversion module in the trained role dialogue model.
5. A method for generating a dialogue, characterized in that: include: Get the question sentence; The question statement is input into a trained role dialogue model to obtain a response statement of the target role corresponding to the question statement, wherein the trained role dialogue model is obtained by training the role dialogue model to be trained using the role dialogue model training method described in any one of claims 1 to 4.
6. A role model training device, characterized in that: include: A model acquisition module, used for acquiring a role dialogue model to be trained, wherein the normalization layer of the role dialogue model to be trained includes a target learnable parameter, wherein the target learnable parameter is determined according to an input role embedding vector, wherein the role embedding vector is obtained by embedding target role information, and the target role information is used to characterize the characteristics of the target role; A model training module, used to train the role dialogue model to be trained using multiple sets of role dialogue data to obtain a trained role dialogue model; The model acquisition module includes a role embedding unit and a parameter modification unit, wherein: The role embedding unit is used to add a role embedding module to the initial role dialogue model to obtain a modified role dialogue model, and the role embedding module is used to convert the received target role information into the role embedding vector, and input the role embedding vector into the normalization layer of the modified role dialogue model; The parameter modification unit is used to add a vector conversion module to the normalized layer of the modified role dialogue model, and to update the initial learnable parameters of the normalized layer of the modified role dialogue model to the target learnable parameters, so as to obtain the role dialogue model to be trained. The vector conversion module is used to convert the received role embedding vector into a role adjustment parameter, and the target learnable parameter is determined based on the initial learnable parameters and the role adjustment parameters.
7. A dialogue generation device, characterized in that: include: A sentence acquisition module, used to acquire question sentences; A sentence generation module is used to input the question sentence into a trained role dialogue model to obtain a response sentence of the target role corresponding to the question sentence, wherein the trained role dialogue model is obtained by training the role dialogue model to be trained using the role dialogue model training method described in any one of claims 1 to 4.
8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method for training the role dialogue model as described in any one of claims 1 to 4, or the method for generating dialogue as described in claim 5 is implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, it implements the method for training a role dialogue model as described in any one of claims 1 to 4, or the method for generating dialogue as described in claim 5.
Citation Information
Patent Citations
Dialogue model training method, dialogue generation method, device and equipment
CN117273019A
Role dialogue model training method, dialogue generation method, device and equipment
CN117633198A
