Model training method, apparatus, storage medium and electronic device
The model training method improves chatbot responses by segmenting and adversarially training a generative network to fuse sentences, ensuring natural and coherent interactions.
Patent Information
- Application Number
- JP2023580518
- Authority / Receiving Office
- JP · JP
- Patent Type
- Patents
- Current Assignee / Owner
- Priority Date
- 2023-08-11
- Filing Date
- 2023-09-13
- Publication Date
- 2026-02-16
- Estimated Expiration
- 2043-09-13
AI Technical Summary
Existing chatbots generate rigid and unnatural responses by simply splicing replies and new topics, affecting user experience.
A model training method involving segmentation of source sentences, adversarial training of a generative adversarial network with a generator and classifiers to fuse independent sentences, ensuring natural word order and semantic coherence.
Generates fluent and coherent responses by fusing sentences with correct word order and semantic matching, enhancing user experience.
Smart Images

Figure 0007814423000014 
Figure 0007814423000015 
Figure 0007814423000016
Abstract
Description
[Technical Field]
[0001] The present invention claims priority to Chinese Patent Application No. 202311010097.X, filed on August 11, 2023, which is incorporated herein by reference in its entirety. The present invention relates to the field of artificial intelligence, and in particular to a model training method, apparatus, storage medium, and electronic device. [Background technology]
[0002] With the development of artificial intelligence, intelligent robots have been applied in various fields, such as chatbots. To provide users with a good chat experience, chatbots can introduce new topics while answering user questions. Because the reply and the new topic may contain the same personal pronouns or related content, simply splicing the reply and the new topic together can result in a rigid chat experience. For example, if the user asks, "What patent does Zhang San hold?", the chatbot can reply, "Zhang San holds a patent for..." To introduce a new topic, the chatbot can also add a response such as, "Zhang San has participated in a long-distance running event." Obviously, the chatbot's response to the user, i.e., "Zhang San holds a patent for.... Zhang San has participated in a long-distance running event," is very rigid and affects the user's chat experience. Summary of the Invention
[0003] The present invention provides a model training method, apparatus, storage medium and electronic device for solving the above problems of the prior art.
[0004] The present invention provides a method for training a model, the method comprising: Segmenting the source sentence into a plurality of independent sentences and adding the plurality of independent sentences to a training dataset; inputting each independent sentence to a generator of a model, fusing the independent sentences by the generator to obtain a fused sentence, and adding the fused sentence to the training data set; inputting a sentence to be identified from the training dataset into a source classifier of the model, and obtaining a classification result output by the source classifier as to whether the sentence to be identified is an original sentence; determining a source identification loss of the source discriminator based on the identification result of the source discriminator and a source label of the sentence to be identified, and determining a source generation loss of the generator based on the identification result of the source discriminator, the source label of the sentence to be identified, and an original sentence corresponding to the sentence to be identified; and performing adversarial training on the model based on the source generation loss and the source identification loss, wherein a generator of the model is used to fuse multiple independent sentences to respond to a user.
[0005] Optionally, the step of determining a source generation loss of the generator based on the identification result of the source identifier, a source label of the sentence to be identified, and an original sentence corresponding to the sentence to be identified comprises: determining a difference in word order between the sentence to be identified and an original sentence corresponding to the sentence to be identified when the identification result of the source identifier does not match the source label of the sentence to be identified; and determining a source generation loss of the generator based on the word order difference.
[0006] Optionally, the model training method further comprises: a step of inputting the sentence to be identified and an independent expression sentence corresponding to the sentence to be identified into a semantic classifier of the model, and obtaining a classification result indicating whether the meaning of the sentence to be identified output by the semantic classifier matches the meaning of the independent expression sentence corresponding to the sentence to be identified; and performing adversarial training on the model based on the classification results output by the semantic classifier.
[0007] Optionally, the step of performing adversarial training on the model based on the classification result output by the semantic classifier includes: determining a semantic identification loss of the semantic classifier based on the identification result output by the semantic classifier and the semantic label of the sentence to be identified, and determining a semantic generation loss of the generator based on the identification result of the semantic classifier, the semantic label of the sentence to be identified, and an independent expression sentence corresponding to the sentence to be identified; and performing adversarial training on the model based on the semantic generative loss and the semantic discriminative loss.
[0008] Optionally, the step of determining a semantic generation loss of the generator based on the identification result of the semantic classifier, the semantic label of the sentence to be identified, and an independent expression sentence corresponding to the sentence to be identified includes: determining a difference in meaning between the sentence to be identified and an independent expression sentence corresponding to the sentence to be identified when the identification result of the semantic identifier does not match the semantic label of the sentence to be identified; and determining a semantic generation loss of the generator based on the semantic difference.
[0009] Optionally, the model training method further comprises: The method includes inputting a plurality of independent expression sentences to be replied to the user to the generator of the model, obtaining a fused sentence output by the generator, and presenting the fused sentence.
[0010] Optionally, the generator comprises a bidirectional autoregressive transformer and the source discriminator comprises a BERT model and a linear classifier.
[0011] The present invention provides a model training apparatus, the apparatus comprising: an independent sentence acquisition module for dividing the source text into a plurality of independent sentences and adding the plurality of independent sentences to a training dataset; a fused sentence acquisition module for inputting each independent sentence to a generator of a model, fusing the independent sentences by the generator to obtain a fused sentence, and adding the fused sentence to the training dataset; a word order identification result module for inputting a sentence to be identified from the training dataset into a source classifier of the model and obtaining an identification result indicating whether the sentence to be identified output by the source classifier is an original sentence; a loss determination module for determining a source identification loss of the source identifier based on the identification result of the source identifier and a source label of the sentence to be identified, and for determining a source generation loss of the generator based on the identification result of the source identifier, the source label of the sentence to be identified, and an original sentence corresponding to the sentence to be identified; and a model training module for performing adversarial training on the model based on the source generation loss and the source identification loss, wherein the model generator is used to fuse multiple independent sentences to respond to a user.
[0012] Optionally, the loss determination module specifically: If the identification result of the source identifier does not match the source label of the sentence to be identified, determining a difference in word order between the sentence to be identified and an original sentence corresponding to the sentence to be identified; Based on the word order differences, a source generation loss of the generator is determined.
[0013] Optionally, the model training device further comprises: inputting the sentence to be identified and an independent expression sentence corresponding to the sentence to be identified into a semantic classifier of the model, and obtaining a classification result indicating whether the meaning of the sentence to be identified output by the semantic classifier matches the meaning of the independent expression sentence corresponding to the sentence to be identified; The semantic training module is configured to perform adversarial training on the model based on the classification result output by the semantic classifier.
[0014] Optionally, the semantic identification module specifically: determining a semantic identification loss of the semantic classifier based on the identification result output by the semantic classifier and the semantic label of the sentence to be identified; and determining a semantic generation loss of the generator based on the identification result of the semantic classifier, the semantic label of the sentence to be identified, and an independent expression sentence corresponding to the sentence to be identified; Based on the semantic generative loss and the semantic discriminative loss, it is used to perform adversarial training on the model.
[0015] Optionally, the semantic identifier module specifically: If the classification result of the semantic classifier does not match the semantic label of the sentence to be classified, determining the semantic difference between the sentence to be classified and an independent expression sentence corresponding to the sentence to be classified; Based on the semantic difference, a semantic generation loss of the generator is determined.
[0016] Optionally, the model training device further comprises: The model further includes an application module for inputting a plurality of independent expression sentences for replying to a user to the generator of the model, obtaining a fusion sentence output by the generator, and presenting the fusion sentence.
[0017] Optionally, the generator comprises a bidirectional autoregressive transformer and the source discriminator comprises a BERT model and a linear classifier.
[0018] The present invention provides a computer-readable storage medium, which stores a computer program, which, when executed by a processor, performs the above model training method.
[0019] The present invention provides an electronic device, the electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, the electronic device performing the model training method when the processor executes the computer program.
[0020] At least one of the above technical solutions used in the present invention can achieve the following beneficial effects:
[0021] As can be seen from the model training method provided in the present invention, this method performs adversarial training on the generator and source classifier in the model, allowing the generator to generate fused sentences that are close to the original sentences, with normal word order and natural, non-rigid content connections, and allowing the source classifier to more accurately determine whether the input sentence is the original sentence. [Brief explanation of the drawings]
[0022] The accompanying drawings described herein are used to further the understanding of the present invention and constitute a part of the present invention, and the exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an undue limitation of the present invention.
[0023] [Figure 1] FIG. 1 is a schematic diagram illustrating the flow of a model training method provided in an embodiment of the present invention. [Figure 2] FIG. 1 is a schematic diagram showing the internal structure of a generative adversarial network provided in an embodiment of the present invention. [Figure 3] 1 is a schematic diagram showing the internal structure of a generator provided in an embodiment of the present invention. [Figure 4] FIG. 2 is a schematic diagram illustrating the internal structure of a source identifier provided in an embodiment of the present invention. [Figure 5] FIG. 10 is a schematic diagram illustrating the internal structure of a generative adversarial network provided in another embodiment of the present invention. [Figure 6] 1 is a schematic diagram illustrating the internal structure of a semantic classifier provided in an embodiment of the present invention; [Figure 7] FIG. 1 is a schematic diagram illustrating a model training apparatus provided in an embodiment of the present invention. [Figure 8] 2 is a schematic diagram showing the structure of an electronic device corresponding to FIG. 1 provided in an embodiment of the present invention; DETAILED DESCRIPTION OF THE INVENTION
[0024] In order to make the objectives, technical solutions and advantages of the present invention clearer, the following clearly and completely describes the technical solutions of the present invention in conjunction with specific embodiments of the present invention and the corresponding accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, but not all of them. All other embodiments that can be obtained by those skilled in the art based on the embodiments of the present invention without requiring creative efforts fall within the protection scope of the present invention.
[0025] Below, the technical solutions provided in each embodiment of the present invention will be described in detail in conjunction with the accompanying drawings.
[0026] 1 is a schematic diagram showing the flow of a model training method provided in an embodiment of the present invention. The model training method includes the following steps S100 to S110.
[0027] In S100, the source sentence is divided into a plurality of independent sentences, and the independent sentences are added to a training data set.
[0028] Typically, when a chatbot answers a user's questions and introduces a new topic to the user, it simply stitches together multiple related pieces of content, resulting in a rigid content displayed to the user. For example, a chatbot might reply to a user, "Zhang San is 188 cm tall. Zhang San likes basketball." Therefore, the present invention provides a model training method. The chatbot can use the model to fuse multiple pieces of content and related sentences, and the resulting content is fluent and smooth. The execution entity of the present invention may be a server for training the model, or a chatbot or other electronic device for responding to the user. For ease of explanation, the following description will focus solely on the server as the execution entity, describing the model training method provided by the present invention.
[0029] The present invention trains a generative adversarial network model to obtain content to reply to a user by a generator in the generative adversarial network.
[0030] FIG. 2 is a schematic diagram showing the internal structure of a generative adversarial network provided in an embodiment of the present invention.
[0031] To train a generator in the generative adversarial network model, it is first necessary to obtain training samples for training the generator. The training samples include independent sentences. When obtaining the independent sentences, the server may divide the source text into multiple independent sentences. That is, the independent sentences can be obtained from the source text by replacing pronouns and abbreviations in the source text with the names of the entities to which the pronouns refer and by replacing conjunctions in the source text that connect sentences with periods.
[0032] For example, the original sentence is "Madonna said, 'Give me high heels, and I can conquer the world...' Men might not care, but I believe in her." By replacing "I" in "Give me high heels, and I can conquer the world..." and "she" in "I believe in her" with "Madonna," we obtain the independent expression sentence "Madonna said, 'Give me high heels, and Madonna can conquer the world...' Men might not care, but I believe in Madonna." The original sentence includes any sentence in the reference resolution dataset. Note that the original sentence may be multiple sentences or a single sentence; the present invention is not limited to this. Here, the reference resolution task is the process of dividing different demonstratives that represent the same entity into an equivalent set, and any sentence in the reference resolution dataset may be a reference resolution task to be solved. In other words, the original sentence may include the name, pronoun, and abbreviation of the entity, and the name, pronoun, and abbreviation of the entity are demonstratives. Following the example above, Madonna Cikoni is both an entity and the name of the entity Madonna Cikoni. "Madonna" is an abbreviation of the entity Madonna Cikoni. The "I" in "Give me high heels and I can conquer the world..." is a pronoun for the entity Madonna Cikoni.
[0033] To facilitate subsequent training of the classifier of the generative adversarial network model and determine labels for multiple independent sentences, the server may add source sentences to the training dataset.
[0034] In S102, each independent sentence is input to a generator of a model, and the generator fuses the independent sentences to obtain a fused sentence, and the fused sentence is added to the training data set.
[0035] In one or more embodiments of the present invention, the generative adversarial network model further includes a source discriminator. The server may input each independent sentence to a generator of the model, fuse the independent sentences by the generator to obtain a fused sentence, and add the fused sentence to the training dataset, so as to determine a source identification loss for the source discriminator to improve the accuracy of the identification result of the source discriminator using the source identification loss, and determine a source generation loss for a generator to improve the content fluency of the fused sentence generated by the generator using the source generation loss.
[0036] Specifically, FIG. 3 is a schematic diagram showing the internal structure of a generator provided in an embodiment of the present invention.
[0037] The generator includes a Bidirectional Auto-Regressive Transformer (BART), and the server inputs each independent sentence into the generator's encoder and obtains a fused sentence based on the generator's decoder. When inputting each independent sentence into the generator, it splits the independent sentence with a period, question mark, or exclamation mark, starts with a [CLS] symbol, joins the split independent sentences in order, separates them with a [SEP] symbol, and finally joins them with a [SEP] symbol. Following the example above, "Madonna said, 'If you put high heels on Madonna, she could conquer the world...' Men might not care, but I believe in Madonna." The input format to the generator is "[CLS] Madonna said, 'If you put high heels on Madonna, she could conquer the world...' [SEP] Men might not care, but I believe in her. [SEP]." The server may determine the format for inputting each independent expression sentence to the generator depending on the type of the generator, and the present invention is not limited thereto.
[0038] In S104, the sentence to be identified in the training data set is input to a source classifier of the model, and a classification result is obtained as to whether the sentence to be identified output by the source classifier is an original sentence or not.
[0039] In order to determine the source identification loss of a source discriminator and train the source discriminator based on the source identification loss, the server first needs to input the sentence to be identified in the training dataset to the source discriminator of the model, obtain a discrimination result indicating whether the sentence to be identified output by the source discriminator is the original sentence, and determine the source identification loss based on the discrimination result.
[0040] Specifically, FIG. 4 is a schematic diagram showing the internal structure of a source identifier provided in an embodiment of the present invention.
[0041] The source discriminator includes a bidirectional encoder representation from a transformer, i.e., a Bidirectional Encoder Representation from Transformers (BERT) model, and a linear classifier. When the server inputs the sentence to be identified to the source discriminator, the sentence to be identified is first processed by the BERT model, then passed to the linear classifier, and finally the discrimination result of the source discriminator is output. Here, the input format of the sentence to be identified to the source discriminator may be the same as the input format of the sentence to be identified to the generator in step S102, and this is not repeated in the present invention. In addition, the output of the source discriminator is a binary classification result, and the meaning corresponding to the discrimination result output by the source discriminator may be set as needed, but the present invention is not limited thereto. For example, a discrimination result of 1 output by the source discriminator indicates that the sentence to be identified is the original sentence, and a discrimination result of 0 output by the source discriminator indicates that the sentence to be identified is not the original sentence. Furthermore, the source identifier may be configured so that when the identification result output by the source identifier is 0, it indicates that the sentence to be identified is the original sentence, and when the identification result output by the source identifier is 1, it indicates that the sentence to be identified is not the original sentence.
[0042] In S106, a source identification loss of the source identifier is determined based on the identification result of the source identifier and the source label of the sentence to be identified.
[0043] In one or more embodiments of the present invention, the source label of the sentence to be identified refers to the type of the sentence to be identified. For example, if the sentence to be identified is an original sentence, the source label of the sentence to be identified is 1, and if the sentence to be identified is a fused sentence, the source label of the sentence to be identified is 0. The source label may be set as needed, but must match the meaning represented by the identification result of the source identifier. For example, if the source label of the sentence to be identified is 1 when the sentence to be identified is an original sentence, the identification result output by the source identifier when the sentence to be identified is identified as an original sentence is also 1. If 0 is output, the source identifier has not performed an accurate identification. If the identification result of the source identifier matches the source label of the sentence to be identified, the source identifier has performed an accurate identification. If the identification result of the source identifier does not match the source label of the sentence to be identified, the source identification loss may be determined using the following equation:
number
number
[0044] In S108, a source generation loss of the generator is determined based on the identification result of the source identifier, the source label of the sentence to be identified, and the original sentence corresponding to the sentence to be identified.
[0045] Specifically, if the classification result of the source classifier does not match the source label of the sentence to be classified, the difference in word order between the sentence to be classified and the source sentence corresponding to the sentence to be classified is determined, and the source generation loss of the generator is determined based on the difference in word order. Of course, the source generation loss of the generator may also be determined based on other differences between the sentence to be classified and the source sentence corresponding to the sentence to be classified, and the present invention is not limited thereto.
[0046] At S110, the model is subjected to adversarial training based on the source generation loss and the source identification loss, and the generator of the model is used to fuse multiple independent sentences to respond to a user.
[0047] Specifically, the source discriminator is trained with the training goal of reducing the source discrimination loss, and the generator is trained with the training goal of reducing the source generation loss. The trained source discriminator can not only enable the generator to generate natural fused sentences, but also be used to classify input sentences.
[0048] Here, the server may alternately train the generator and the source discriminator, i.e., perform one training for the source discriminator based on the source identification loss, determine the source generation loss for the generator after the source discriminator completes one training, and perform one training for the generator based on the source generation loss. After the generator completes one training, the server completes one iteration.
[0049] Based on the model training method shown in Figure 1, this method performs adversarial training on the generator and source classifier in the model, allowing the generator to generate fused sentences that are close to the original sentences, with normal word order and natural, non-rigid content connections, allowing the source classifier to more accurately determine whether the input sentence is the original sentence.
[0050] Before performing step S102, the server may train the generator using maximum likelihood estimation or other methods to make the adversarial training more stable. When training the generator using maximum likelihood estimation, the loss of the generator is expressed as follows:
number
number
number
[0051] Of course, the generator does not have to be trained before performing step S102, and the present invention is not limited thereto.
[0052] When performing step S102, because the model typically does not support direct character recognition, when each independent sentence is input to the generator, it is first converted into an integer index or other recognizable format that can be recognized by the generator.
[0053] Similarly, when a sentence to be classified is input to the source classifier, a similar process must be performed, which is not repeated in the present invention. Furthermore, the source classifier may not be able to output a classification result because it cannot differentiate when recognizing a list of integer indexes. Therefore, the Gumbel-softmax trick may be used to solve the problem of not being able to differentiate.
[0054] Specifically, the generation process of the generator is expressed by the following equation:
number
number
number
number
number
number
[0055] FIG. 5 is a schematic diagram showing the internal structure of a generative adversarial network provided in another embodiment of the present invention.
[0056] After training the model in the above manner, the generator of the model can generate fused sentences with correct word order. The content of the fused sentences may differ in wording or order, but the meaning of the fused sentence may differ from the meaning of the corresponding independent sentences. This includes missing the meaning of one independent sentence, altering the meaning of another independent sentence, or adding information not expressed in all the independent sentences. Therefore, the model may include a semantic classifier.
[0057] FIG. 6 is a schematic diagram showing the internal structure of a semantic classifier provided in an embodiment of the present invention.
[0058] In one or more embodiments of the present invention, the semantic classifier includes a Span BERT model and a linear classifier. To obtain a fused sentence having the same meaning as an independent expression sentence, the server inputs the sentence to be identified and the corresponding independent expression sentence to the semantic classifier of the model, obtains a classification result output by the semantic classifier indicating whether the meaning of the sentence to be identified matches the meaning of the corresponding independent expression sentence, and performs adversarial training on the model based on the classification result output by the semantic classifier.
[0059] Specifically, the server determines the semantic identification loss of the semantic classifier based on the identification result output by the semantic classifier and the semantic label of the sentence to be identified. The format of input to the semantic classifier may be the same as the format of input to the generator, such as "[CLS] source sentence [SEP] independent expression sentence," "[CLS] merged sentence [SEP] independent expression sentence," or "[CLS] interference sentence [SEP] independent expression sentence." The semantic label of the sentence to be identified indicates whether the meaning of the sentence to be identified matches the meaning of the corresponding independent expression sentence. If the meaning of the sentence to be identified matches the meaning of the corresponding independent expression sentence, the semantic label is 1. If the meaning of the sentence to be identified does not match the meaning of the corresponding independent expression sentence, the semantic label is 0. The semantic label may be set as needed.
[0060] The server may determine the semantic identification loss as follows:
number
[0061] The output of the semantic classifier is a binary classification result, and the meaning corresponding to the classification result output by the semantic classifier may be set as needed, and the present invention is not limited thereto. The training dataset may also include interference sentences, which are sentences obtained by replacing a pronoun in the original sentence with a word other than the word referred to by the pronoun. For example, the training dataset may be obtained by replacing "I" in the sentence "Madonna said, 'Give me some high heels and I can conquer the world...'" with "Zhang San," "Li Si," etc.
[0062] The server may determine the semantic identification loss and also determine the semantic generation loss of the generator based on the identification result of the semantic classifier, the semantic label of the sentence to be identified, and the independent expression sentence corresponding to the sentence to be identified. That is, if the identification result of the semantic classifier does not match the semantic label of the sentence to be identified, the server determines the semantic difference between the sentence to be identified and the independent expression sentence corresponding to the sentence to be identified, and determines the semantic generation loss of the generator based on the semantic difference. Finally, the server performs adversarial training on the generative adversarial network model based on the semantic generation loss and the semantic identification loss. Here, the loss of the generative adversarial network model is expressed as follows:
number
[0063] In addition, the server may simultaneously train the generator, source classifier, and semantic classifier of the adversarial network model, or may train the generator and source classifier first and then train the semantic classifier, but the present invention is not limited thereto.
[0064] If the server trains the generator and source classifier before training the semantic classifier, it must determine that the source classifier has been trained before training the semantic classifier.
[0065] After the training of the generative adversarial network model is completed, the server may input multiple independent sentences to the generator of the model to reply to the user, obtain a fused sentence output by the generator, and present the fused sentence. The fused sentence not only has a consistent and natural content, but also has a semantic match with the independent sentences. In addition, a source classifier may be used to detect whether a sentence is fluent, and a semantic classifier may be used to determine whether the meanings of two sentences are similar.
[0066] The above is the method provided in one or more embodiments of the present disclosure, and based on the same idea, the present disclosure further provides a corresponding model training apparatus, as shown in FIG.
[0067] FIG. 7 is a schematic diagram illustrating a model training device provided in an embodiment of the present invention, which includes: an independent sentence acquisition module 700 for dividing the source text into a plurality of independent sentences and adding the plurality of independent sentences to a training dataset; a fused sentence acquisition module 702 for inputting each independent sentence to a generator of a model, fusing the independent sentences by the generator to obtain a fused sentence, and adding the fused sentence to the training dataset; a word order identification result module 704 for inputting a sentence to be identified from the training dataset into a source classifier of the model and obtaining a classification result of whether the sentence to be identified output by the source classifier is an original sentence; a loss determination module 706 for determining a source identification loss of the source identifier based on the identification result of the source identifier and a source label of the sentence to be identified, and for determining a source generation loss of the generator based on the identification result of the source identifier, the source label of the sentence to be identified, and an original sentence corresponding to the sentence to be identified; and a model training module 708 for performing adversarial training on the model based on the source generation loss and the source identification loss, wherein the model generator is used to fuse multiple independent sentences to respond to a user.
[0068] Optionally, the loss determination module 706 specifically: If the identification result of the source identifier does not match the source label of the sentence to be identified, determining a difference in word order between the sentence to be identified and an original sentence corresponding to the sentence to be identified; Based on the word order differences, a source generation loss of the generator is determined.
[0069] Optionally, the model training device further comprises: inputting the sentence to be identified and an independent expression sentence corresponding to the sentence to be identified into a semantic classifier of the model, and obtaining a classification result indicating whether the meaning of the sentence to be identified output by the semantic classifier matches the meaning of the independent expression sentence corresponding to the sentence to be identified; The semantic training module 710 is included for performing adversarial training on the model based on the classification result output by the semantic classifier.
[0070] Optionally, the semantic identification module 710 specifically: determining a semantic identification loss of the semantic classifier based on the identification result output by the semantic classifier and the semantic label of the sentence to be identified; and determining a semantic generation loss of the generator based on the identification result of the semantic classifier, the semantic label of the sentence to be identified, and an independent expression sentence corresponding to the sentence to be identified; Based on the semantic generative loss and the semantic discriminative loss, it is used to perform adversarial training on the model.
[0071] Optionally, the semantic identifier module 710 specifically: If the classification result of the semantic classifier does not match the semantic label of the sentence to be classified, determining the semantic difference between the sentence to be classified and an independent expression sentence corresponding to the sentence to be classified; Based on the semantic difference, a semantic generation loss of the generator is determined.
[0072] Optionally, the model training device further comprises: The system includes an application module 712 for inputting a plurality of independent expression sentences for replying to a user to the generator of the model, obtaining a fusion sentence output by the generator, and presenting the fusion sentence.
[0073] Optionally, the generator comprises a bidirectional autoregressive transformer and the source discriminator comprises a BERT model and a linear classifier.
[0074] The present invention further provides a computer-readable storage medium, which stores a computer program, and the computer program is used to perform the model training method provided in FIG. 1 above.
[0075] The present invention further provides an electronic device. Figure 8 is a schematic diagram showing the structure of the electronic device corresponding to Figure 1. As shown in Figure 8, at the hardware level, the electronic device includes a processor, an internal bus, a network interface, an internal memory, and a non-volatile memory, and may also include other hardware required for operation. The processor loads the corresponding computer program from the non-volatile memory into the internal memory and executes it to implement the model training method described above in Figure 1.
[0076] Of course, in addition to realization by software, the present invention does not exclude other realization methods, such as logical devices or a combination of hardware and software. In other words, the entity that executes the following processing process is not limited to each logical unit, but may also be hardware or a logical device.
[0077] In the 1990s, technological improvements could be clearly divided into hardware improvements (such as improvements to circuit structures like diodes, transistors, and switches) and software improvements (such as improvements to methodology). However, with technological advances, many current methodology improvements can be considered direct improvements to hardware circuit structures. Designers often obtain the corresponding hardware circuit structure by programming the improved methodology into the hardware circuit. Therefore, it is not necessarily true that methodology improvements cannot be realized using physical hardware modules. For example, programmable logic devices (PLDs) (e.g., field programmable gate arrays, or FPGAs) are such integrated circuits, whose logical functions are determined by user programming of the device. Instead of chip manufacturers designing and manufacturing dedicated integrated circuit chips, designers program and "integrate" digital systems onto a single PLD.Nowadays, instead of handcrafting integrated circuit chips, this programming is often achieved using software called a "logic compiler," which is similar to a software compiler used to write a program. To compile the original code, it must be written in a specific programming language called a Hardware Description Language (HDL). There is not just one HDL; there are many, including ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, and RHDL (Ruby Hardware Description Language). The most commonly used HDLs are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. It should be clear to those skilled in the art that a hardware circuit embodying a logical method flow can be easily obtained by simply logically programming the method flow in one of the above hardware description languages and programming it into an integrated circuit.
[0078] The controller may be implemented in any suitable manner. For example, the controller may take the form of a microprocessor or processor, a computer-readable storage medium storing computer-readable program code (e.g., software or firmware) executable by the (micro)processor, logic gates, switches, application-specific integrated circuits (ASICs), programmable logic controllers, and embedded microcontrollers. Examples of controllers include, but are not limited to, microcontrollers such as the ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. A memory controller may also be implemented as part of the control logic of the memory. It will be apparent to those skilled in the art that, in addition to implementing the controller purely with computer-readable program code, it is entirely possible to logically program method steps to cause the controller to perform the same functions in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, embedded microcontrollers, and the like. Therefore, such a controller may be considered a hardware component, and the devices included therein for implementing various functions may also be considered structures within the hardware component. Alternatively, the apparatus for realizing various functions may be considered to be software modules for realizing methods or structures within hardware components.
[0079] The systems, devices, modules, or units described in the above embodiments may be specifically realized by computer chips, entities, or products having certain functions. A typical realizing device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a mobile phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet, a wearable device, or any combination of these devices.
[0080] For the sake of convenience, the above-described device will be described by dividing it into various units according to their functions. Of course, when implementing the present invention, the functions of each unit can be realized by the same or multiple pieces of software and / or hardware.
[0081] As will be appreciated by those skilled in the art, embodiments of the present invention may be provided as a method, a system, or a computer program product. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product embodied in one or more computer-usable storage media (including, but not limited to, magnetic disk memory, CD-ROM, optical memory, etc.) containing computer-usable program code.
[0082] The present invention will be described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and combinations of flows and / or blocks in the flowcharts and / or block diagrams, may be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, whereby the instructions, executed by the processor of the computer or other programmable data processing device, generate an apparatus for implementing the functions specified in one or more flows in the flowcharts and / or one or more blocks in the block diagrams.
[0083] These computer program instructions may be stored in a computer-readable memory that can direct a computer or other programmable data processing device to operate in a particular manner, such that the instructions stored in the computer-readable memory result in an article of manufacture that includes an instruction apparatus that implements the functions specified in one or more flows of the flowcharts and / or one or more blocks of the block diagrams.
[0084] These computer program instructions may be loaded into a computer or other programmable data processing device, whereby a series of operational steps are executed on the computer or other programmable device to generate a computer-implemented process, whereby the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more flows of the flowcharts and / or one or more blocks of the block diagrams.
[0085] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0086] The memory may include volatile memory, random access memory (RAM), and / or non-volatile memory, such as read-only memory (ROM) or flash memory (flash RAM), among other computer-readable storage media. The memory is one example of a computer-readable storage medium.
[0087] Computer-readable storage media include nonvolatile and volatile media, removable and non-removable media, and may implement any method or technology for information storage. Information may be computer-readable instructions, data structures, program modules, or other data. Computer storage media include, but are not limited to, Phase Change Memory (PRAM), Static Random-Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read-Only Memory (ROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), flash memory or other memory technology, Compact Disc Read-Only Memory (CD-ROM), Digital Versatile Disc (DVD) or other optical storage, magnetic cassette tape, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information accessible by a computing device. As defined herein, computer readable storage media does not include transitory computer readable storage media, such as modulated data signals and carriers.
[0088] Additionally, the terms "comprise," "contain," or any other variation thereof, are intended to include a non-exclusive inclusion, whereby a process, method, article, or device that includes a set of elements not only includes those elements, but also includes other elements not expressly listed, or includes the inherent elements of such process, method, article, or device. Absent more limitations, elements qualified by the phrase "comprise..." do not exclude the presence of further identical elements in a process, method, article, or device that includes said elements.
[0089] As will be appreciated by those skilled in the art, embodiments of the present invention may be provided as a method, a system, or a computer program product. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product embodied in one or more computer-usable storage media (including, but not limited to, magnetic disk memory, CD-ROM, optical memory, etc.) containing computer-usable program code.
[0090] The invention may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The invention may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media, including memory storage devices.
[0091] Each embodiment of the present invention will be described in a stepwise manner, and the same or similar parts between each embodiment may be referred to, and the description of each embodiment will focus on the differences from other embodiments. In particular, the system embodiment will be briefly described, since it is basically similar to the method embodiment, and the relevant parts may be referred to the description of part of the method embodiment.
[0092] The above is merely an embodiment of the present invention and is not intended to limit the present invention. Those skilled in the art will appreciate that the present invention may have various modifications and variations. Any modifications, equivalent replacements, improvements, etc. made without departing from the spirit and principles of the present invention should be included in the scope of the claims of the present invention.
Claims
1. Segmenting the source sentence into a plurality of independent sentences and adding the plurality of independent sentences to a training dataset; inputting each independent sentence to a generator of a model, fusing the independent sentences by the generator to obtain a fused sentence, and adding the fused sentence to the training data set; inputting a sentence to be identified from the training dataset into a source classifier of the model, and obtaining a classification result output by the source classifier as to whether the sentence to be identified is an original sentence; determining a source identification loss of the source discriminator based on the identification result of the source discriminator and a source label of the sentence to be identified, and determining a source generation loss of the generator based on the identification result of the source discriminator, the source label of the sentence to be identified, and an original sentence corresponding to the sentence to be identified; and performing adversarial training on the model based on the source generation loss and the source identification loss, wherein a generator of the model is used to fuse multiple independent sentences to reply to a user.
1. A method for training a model performed by an electronic device, comprising:
2. The step of determining a source generation loss of the generator based on the identification result of the source identifier, the source label of the sentence to be identified, and an original sentence corresponding to the sentence to be identified, includes: determining a difference in word order between the sentence to be identified and an original sentence corresponding to the sentence to be identified when the identification result of the source identifier does not match the source label of the sentence to be identified; and determining a source generation loss of the generator based on the word order difference.
2. The method of claim 1, wherein the training step is performed based on the training data.
3. The model training method further comprises: a step of inputting the sentence to be identified and an independent expression sentence corresponding to the sentence to be identified into a semantic classifier of the model, and obtaining a classification result indicating whether the meaning of the sentence to be identified output by the semantic classifier matches the meaning of the independent expression sentence corresponding to the sentence to be identified; and performing adversarial training on the model based on the classification results output by the semantic classifier.
2. The method of claim 1, wherein the training step is performed based on the training data.
4. The step of performing adversarial training on the model based on the classification result output by the semantic classifier includes: determining a semantic identification loss of the semantic classifier based on the identification result output by the semantic classifier and the semantic label of the sentence to be identified, and determining a semantic generation loss of the generator based on the identification result of the semantic classifier, the semantic label of the sentence to be identified, and an independent expression sentence corresponding to the sentence to be identified; and performing adversarial training on the model based on the semantic generation loss and the semantic discrimination loss.
4. The method of claim 3, wherein the training step is performed on a plurality of nodes.
5. The step of determining a semantic generation loss of the generator based on the classification result of the semantic classifier, the semantic label of the sentence to be classified, and an independent expression sentence corresponding to the sentence to be classified includes: determining a difference in meaning between the sentence to be identified and an independent expression sentence corresponding to the sentence to be identified when the identification result of the semantic identifier does not match the semantic label of the sentence to be identified; and determining a semantic generation loss of the generator based on the semantic difference.
5. The method of claim 4, wherein the training step is performed on a plurality of nodes.
6. The model training method further comprises: inputting a plurality of independent expression sentences to be replied to the user into the generator of the model, obtaining a fused sentence output by the generator, and presenting the fused sentence; 2. The method of claim 1, wherein the training step is performed based on the training data.
7. the generator includes a bidirectional autoregressive transformer, and the source discriminator includes a BERT model and a linear classifier; 2. The method of claim 1, wherein the training step is performed based on the training data.
8. an independent sentence acquisition module for dividing the source text into a plurality of independent sentences and adding the plurality of independent sentences to a training dataset; a fused sentence acquisition module for inputting each independent sentence to a generator of a model, fusing the independent sentences by the generator to obtain a fused sentence, and adding the fused sentence to the training dataset; a word order identification result module for inputting a sentence to be identified from the training dataset into a source classifier of the model and obtaining an identification result indicating whether the sentence to be identified output by the source classifier is an original sentence; a loss determination module for determining a source identification loss of the source identifier based on the identification result of the source identifier and a source label of the sentence to be identified, and for determining a source generation loss of the generator based on the identification result of the source identifier, the source label of the sentence to be identified, and an original sentence corresponding to the sentence to be identified; a model training module for performing adversarial training on the model based on the source generation loss and the source identification loss, wherein the model generator is used to fuse multiple independent sentences to respond to a user; A model training device characterized by:
9. A computer-readable storage medium storing a computer program, the computer program being executed by a processor to implement the model training method according to any one of claims 1 to 7. A computer-readable storage medium comprising:
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program executing the model training method according to any one of claims 1 to 7. An electronic device characterized by:
Citation Information
Patent Citations
A writing aiding method based on neural network
CN109522411A
Question and answer information processing method and device, and computer equipment
CN111382232A
Question and answer information processing method and device and computer equipment
CN111401922A