A humorous text automatic generation method, system, medium, device and terminal
Through the generative adversarial network model AMQ-GAN, combined with dual discriminators and contrastive learning technology, it solves the problem of balancing semantic features and humor features in humor text generation, generates high-quality open humor texts, and overcomes data scarcity and humor characteristics. Insufficient problem.
Patent Information
- Application Number
- CN202210576890.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-25
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2042-05-25
AI Technical Summary
Existing humor text generation methods are difficult to take into account both semantic features and humor features in the text, resulting in the loss of semantic information, duplication, and insufficient humor features of the generated humor text. Moreover, Chinese humor text data sets are scarce, making it difficult to learn potential humor features from small-scale corpora.
AMQ-GAN, a humorous text generation model based on generative adversarial networks, is used to extract semantic features and humorous features through dual discriminators, combined with SimCSE contrastive learning and prompting technology to generate open-ended humorous texts with humorous features and semantic features.
It improves the semantic consistency and humorous characteristics of humorous texts. The generated humorous texts perform better than traditional methods in terms of BLEU index and manual evaluation, achieving the goal of generating high-quality open-ended humorous texts on small-scale data sets.
Smart Images

Figure CN114896985B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of humorous text generation, and in particular relates to a humorous text automatic generation method, system, medium, equipment and terminal. Background Art
[0002] At present, humor is an important part of people's daily communication, adding endless fun to people's lives in traditional sketches, comedies, crosstalk and daily conversations. With the development of artificial intelligence and natural language processing, more and more human-machine intelligent interactive products are moving towards people's daily lives. In recent years, intelligent voice assistants such as "Siri", "Xiao Ai Tongxue" and "Microsoft Xiaobing" have quickly won the favor of users all over the world with their good interactivity and intelligence. At the same time, people are not only satisfied with simple dialogues and exchanges with intelligent voice assistants, but increasingly hope that intelligent voice assistants will be endowed with warmth and emotion in the process of human-machine voice interaction, and closer to the way of dialogue in people's daily life. Humor, as an important way of interpersonal communication, can not only narrow the distance between people, but also play an important role in conflicts and problems. Therefore, making intelligent voice assistants humorous can not only increase the personalization and creativity of machines, but also enhance the user experience in the process of human-computer interaction. Research by Nijholt et al. shows that introducing humorous features in human-computer interaction systems can increase the overall conversation volume by 50%. Therefore, the research on humorous text generation is worthy of attention. At present, the research on humorous text generation is mostly focused on deep learning methods that integrate external knowledge, and has achieved certain results, but it is unable to take into account the requirements of both semantic features and humorous features in the text. The generated humorous texts often have problems such as semantic information loss, repetition, and insufficient humorous characteristics. It is difficult to provide a large number of suitable humorous texts in actual human-computer interaction.
[0003] Humor is specifically divided into referential or conceptual humor and verbal humor. Referential or conceptual humor is mainly expressed in ways other than language, such as describing in specific scenes or events. It is often more logical and has deeper meanings, and requires the listener to have certain knowledge, common sense, education and other backgrounds. Verbal humor, on the other hand, is humor conveyed through language and text, such as generating some humor from semantic features such as puns, homophones, inconsistencies, etc. This type of humor is easy for the listener to understand and is the most common type of humor in daily life. The present invention studies the above two types of humor.
[0004] Earlier humorous text generation tasks mainly focused on generating humor in fixed patterns or specific expressions, such as word replacement, puns and other basic methods. Petrovi'c et al. used unsupervised learning to extract triples of jokes to generate humorous text by setting the template of "I like x like I like y,z". Lessard et al. published a research paper on humor generation based on automatic pun generation, which mainly generates humor by automatically generating pun riddles with simple phonetic ambiguity. Ritchie et al. also generated pun-style humor. In recent years, some researchers have analyzed and predicted puns through the incongruity of humor and found that ambiguous sentences are often more interesting. Based on the above work, Yu et al. applied neural models to pun generation. The model they trained highlighted the different meanings of words in sentences and generated humor through homonymy. The language model designed by He et al. generates puns by increasing the probability of homophones, making sentences interesting. However, the above methods are all based on artificial observation of humor features, and the generated jokes are relatively isolated and not open.
[0005] With the rapid development of deep learning in natural language processing, more and more humorous text generation research has begun to use deep learning methods. Ren et al. generated humorous text by training the network model with a given topic using a neural network method. Some related studies have used WordNet and ConceptNet and other networks to generate new humorous words and texts, but these methods are training fixed topics and words, and in fact still do not generate open humor. Zhang et al. created the first humorous knowledge dataset, which generated a specific type of humor by integrating external background knowledge into the end-to-end training model. Littmad et al. constructed a dataset of real-world context-sarcasm title pairs, and then used the existing summary extraction pre-training model for fine-tuning to generate humorous satirical titles through style transfer. Chakrabarty et al. generated relevant common sense in the ConceptNet pre-trained language type, and then introduced common sense to obtain language inconsistency, thereby generating humor. Although the above methods with the help of external background knowledge and common sense extract more relevant humorous words, it is also easy to ignore the semantic information of the context in the humorous text. Tan Hongye and others introduced joke features into the improved generative adversarial network, which generated open humor to a certain extent. However, since the humor features were extracted after pre-training, the characteristics of large-scale pre-training models were not fully utilized, and the proportion of humorous texts generated was still relatively low. It can be seen that the research on humorous text generation tasks is very challenging.
[0006] The humorous text generation task is a branch of natural language generation and a relatively new research direction of text generation. It should not only have the basic features required by general texts, such as fluency and coherence, but also have humorous features such as irony, pun, and inconsistency that can generate laughs. Therefore, humorous corpus is crucial for analyzing and learning humorous features. However, the existing Chinese humorous text datasets are relatively scarce, and it is difficult to simply use deep learning models to fully learn the potential humorous features from small-scale humorous corpora. Hossain et al. also pointed out that the scarcity of public humorous datasets is one of the important challenges in computational humor research.
[0007] Early template-based research methods all generated text by replacing words. The jokes generated were often isolated, and it was difficult to generate open humorous text. At the same time, template-based filling requires a lot of manual annotation and consumes a lot of manpower. Therefore, template-based humorous text generation has many shortcomings and can no longer meet the current human-computer interaction products' demand for creative humorous language.
[0008] At present, humorous text generation methods based on neural networks learn potential humorous features through large-scale corpus or external knowledge to generate specific humorous texts. Compared with traditional humorous generation methods, they have improved a lot. However, in the process of learning humorous features, they do not give full play to the advantages of pre-trained models. The generated sentences have problems such as semantic information loss, overfitting, and repeated generated text. It is difficult to provide a large number of suitable humorous texts in actual human-computer interaction scenarios. Therefore, it is a relatively difficult problem to generate open humorous texts that meet the coexistence of semantic features and humorous features through small-scale humorous texts.
[0009] Based on the above analysis, to enable computers to generate humorous texts, it is necessary not only to learn and understand the potential humorous features in humorous texts, but also to integrate them into the existing natural language text generation tasks. This is a challenging task. The main problems of humorous text generation tasks are as follows:
[0010] 1) The existing public Chinese humor text standard datasets are scarce, and simply using existing models cannot learn the humorous features that meet the requirements from a small sample size.
[0011] 2) Humor generated in a fixed form lacks innovation and is difficult to adapt to existing AI product application scenarios
[0012] 3) Existing methods cannot comprehensively extract semantic features and humorous features from humorous texts and do not pay attention to the trade-off between the two.
[0013] Through the above analysis, the problems and defects of the prior art are as follows:
[0014] (1) Existing humorous text generation methods are based on manually observing humorous features to generate jokes, which easily ignores semantic features such as consistent topics. As a result, a large number of sentences generated are irrelevant to the previous text in order to adapt to the relevant humorous features. It is difficult to generate a complete and semantically coherent humorous text. In other words, the generated jokes are relatively isolated and not open. In addition, extracting humorous features based on manual methods requires a lot of manual annotation, which consumes a lot of manpower.
[0015] (2) The existing method of using neural network methods to train network models to generate humorous texts is to train fixed topics and words. When faced with text input outside the training set, it is difficult to generate humorous texts that are consistent with daily communication. Therefore, open-ended humor is still not actually generated.
[0016] (3) Existing humorous text generation methods based on neural networks do not fully utilize the advantages of pre-trained models and fail to pay attention to both the semantic features and humorous features of humorous texts. The generated sentences have problems such as semantic information loss, overfitting, repeated generated text, and insufficient humorous features. It is difficult to provide a large amount of suitable humorous texts in actual human-computer interaction scenarios.
[0017] (4) Existing Chinese humorous text datasets are relatively scarce, and it is difficult to simply use deep learning models to fully learn the potential humorous features from a small-scale humorous corpus;
[0018] (5) The humor generated in a fixed form lacks innovation and is difficult to adapt to the application scenarios of existing artificial intelligence products. It is also unable to comprehensively extract the semantic features and humorous features in humorous texts and does not pay attention to the trade-off between the two. Summary of the invention
[0019] In view of the problems existing in the prior art, the present invention provides a method, system, medium, device and terminal for automatically generating humorous text, and more particularly, relates to a method, system, medium, device and terminal for automatically generating humorous short text of the poisonous chicken soup type.
[0020] The present invention is achieved by a method for automatically generating a humorous text, the method comprising:
[0021] According to the acquired new humorous text generation task, the first half of the sentence is input, and the second half of the sentence which is flipped over the first half is automatically generated; a humorous text generation model AMQ-GAN based on generative adversarial network is constructed; a dual discriminator is used to extract semantic features and humorous features respectively, the semantic feature discriminator guides the generation of sentences with semantic coherence and consistent themes, and the humorous feature discriminator guides the generation of sentences with humorous features of inconsistency, ambiguity and puns; data enhancement based on contrastive learning is used and a specific humorous text training template is set in combination with prompt, so that the generated text highlights the humorous features.
[0022] Further, the humorous text automatic generation method comprises the following steps:
[0023] Step 1: Use data enhancement technology based on SimCSE contrastive learning to generate multiple different sentence vectors for the same sentence;
[0024] Step 2: Using prompting technology, add a third sentence to judge the humor effect of the text;
[0025] Step three, in the process of generating confrontation, a semantic feature discriminator and a humor feature discriminator are used to perform semantic discrimination and humor discrimination on the generated sentences respectively.
[0026] Furthermore, the semantic feature discriminator in step 3 is responsible for judging whether the semantics and themes of the preceding and following sentences are consistent and fluent;
[0027] The humor feature discriminator is used to discriminate the humor quality of the text through the humor features of inconsistency, pun and homophony. The output scores of the two discriminators are weighted to jointly guide the generation of the generator text.
[0028] Furthermore, the humorous text automatic generation method also includes:
[0029] Given a first half sentence of length m as input: s = [w1, ..., w i ,…,w m ], and the model automatically generates a second half sentence s′=[w′1,…,w′ j ,…,w′ n ], so that the entire text composed of s and s′ forms a joke that subverts the original cognition and achieves contrast and irony effects; the two sentences before and after constitute a poisonous chicken soup text, and the punchline sentence output by the model produces a humorous effect.
[0030] Furthermore, the AMQ-GAN model consists of three parts: pre-training, adversarial training, and semantic feature and humor feature extraction.
[0031] (1) Pre-training part
[0032] Pre-training includes pre-training of the generator G, semantic feature discriminator, and humor feature discriminator. The generator uses the GPT-2 model and uses 500,000 common dialogue sentences to pre-train the generator, so that the generator can generate smooth and fluent general responses based on the input. The semantic feature discriminator and humor feature discriminator are used, and the text generated by the pre-trained generator is added to the common dialogue and humor text to add labels to construct a data set. The former is constructed as a semantic data set to train the semantic feature discriminator, and the latter is constructed as a humor data set to train the humor feature discriminator.
[0033] (2) Adversarial training part
[0034] The optimization objective function used is shown as follows:
[0035]
[0036] Among them, x represents a real sample that obeys the real data distribution, D(x) represents the probability that the discriminator distinguishes sample x as a real sample, and G(z) is a false sample generated by the generator; the optimization of the generator is to minimize log(1-D(G(z))), so that the samples generated by the generator can deceive the discriminator, and the optimization of the discriminator is to maximize log(D(x))+log(1-D(G(z))), so that the discriminator can effectively distinguish between real samples and false samples. Through the training iterations of the generator and the discriminator, the generator is promoted to generate "real samples" that can deceive the discriminator; the dual discriminator is introduced to distinguish the semantic features and humor features of the text respectively.
[0037] (3) Semantic and humorous feature extraction
[0038] The semantic feature and humor feature extraction modules are introduced to guide the generator to generate text with humorous and semantic features; the generator's sentences are calculated at the word level from the semantic and humorous aspects to obtain the bonus score:
[0039] 1) Semantic feature extraction
[0040] The semantic features of the generated text are mainly determined by topic consistency, semantic coherence and universality.
[0041] ①Topic consistency
[0042] If the sentence vectors of the two sentences are close in meaning, the topics discussed are relatively consistent:
[0043] q1=cos(s,s′).
[0044] ② Semantic fluency
[0045] Semantic coherence is the basic semantic indicator for evaluating text. The semantic coherence of generated humorous text is evaluated by calculating the forward probability of generating a punchline sentence s′ given a main sentence s of the text, and the backward probability of generating a main sentence given a punchline sentence s′:
[0046] q2=logP(s′|s)+logP backward (s|s′);
[0047] ③ Universality
[0048] Using a large-scale corpus dataset of 500,000 words as a common word set, the prevalence of the punchline sentence is calculated by calculating the probability that the words in the punchline sentence appear in the common word set:
[0049] q3=logP(w i ).
[0050] 2) Humor feature extraction
[0051] The humor feature discriminator judges the quality of text humor based on the target humor feature extraction module. The extracted humor features are as follows:
[0052] ①Ambiguity
[0053] Ambiguity is one of the important conditions for generating jokes, so ambiguous features can be used as an important component of jokes. The funniness of the generated text is evaluated by counting the number of ambiguous words in the generated text.
[0054]
[0055] Among them, ambiguities(w i ) represents the number of different meanings of the i-th word in the joke.
[0056] ②Phonetic similarity
[0057] Rhyme is one of the important features of jokes. Rhyme makes two different words have the same tone and final vowel, thus creating a punchline. The phonetic similarity of the generated text is evaluated by counting the number of rhyming words in the main sentence and the punchline sentence.
[0058] Where rhymes(s, s′) represents the number of rhyming words in the main sentence and the punchline sentence, and N represents the total number of words in the main sentence and the punchline sentence in the humorous text.
[0059] ③Inconsistency
[0060] Analyze the word set composed of the first half and the second half of the sentence V s and V s′ , if the similarity between two words is small, the preceding and following sentences are considered to constitute a joke.
[0061] q6=min{cos(V s , V s′ )}.
[0062] Furthermore, the adversarial training part includes:
[0063] 1) Generator training
[0064] The generator uses the pre-trained GPT-2 model, and introduces contrastive learning technology, prompting technology and reinforcement learning methods during the generator training stage.
[0065] ① Data enhancement based on contrastive learning
[0066] SimCSE technology is used to expand the data of humorous text. During the training process, by modifying the model Dropoutmask size, the vector representation of the input text is increased, and different vector representations of the same input text are brought closer to each other, while vector representations of different input texts are alienated from each other, so that the expanded humorous text vectors are closer to each other.
[0067] ②Introducing prompt technology
[0068] During the training in the generator, the prompt template is inserted into the sample so that the model can effectively learn the humorous features in the language model. The prompt template determines the effect of the model and the quality of text generation. Four prompt templates are manually set to obtain the optimal model; different prompts are added at the front, middle, and back of the humorous text. Prefix templates are more effective for the generation of humorous text.
[0069] ③Reinforcement Learning
[0070] The Monte Carlo search method is used to search and supplement the generator's sentences. During the generator training process, each state is completed by the Monte Carlo search method to obtain a complete sentence sequence. The sequence is sent to the semantic discriminator and the humor discriminator to obtain the weighted value of the semantic reward score and the humor reward score in the state. After obtaining the reward scores for all states, the reward is used to update the generator's policy gradient, thereby guiding the generator to generate humorous text that meets the requirements.
[0071] 2) Discriminator training
[0072] Both the semantic discriminator and the humor discriminator use LSTM networks to perform binary classification on the input sentences; the semantic discriminator is used to discriminate the semantic truth or falsity of the sentences generated by the generator, and the humor discriminator is used to discriminate the humor or falsity of the sentences generated by the generator.
[0073] After the generator obtains the complete sentence through the Monte Carlo search method, it combines the given first half of the sentence with the second half of the sentence generated by the generator and the real second half of the sentence in the humorous corpus to form fake humor and real humor, and marks them with corresponding labels. The semantic discriminator and humor discriminator are used to distinguish them respectively. The semantic discriminator obtains the semantic discrimination score S f , the humor discriminator obtains the humor discrimination score H f , the scores of the two parts are divided by the weight parameter w shCombined splicing for SH f , using the obtained SH f Guide the training generator;
[0074] SH f =w sh ·(S f , H f ).
[0075] Another object of the present invention is to provide a humorous text automatic generation system using the humorous text automatic generation method, the humorous text automatic generation system comprising:
[0076] Data processing module, used to build corpus and preprocess data;
[0077] Model training module, used for pre-training, building a humorous text generation model, and generating humorous text;
[0078] Evaluation module, used for automatic rating and manual evaluation respectively.
[0079] Another object of the present invention is to provide a computer device, the computer device comprising a memory and a processor, the memory storing a computer program, and when the computer program is executed by the processor, the processor performs the following steps:
[0080] A new humorous text generation task is proposed. The first half of a sentence is input and the second half is automatically generated, which is the flip of the first half. A humorous text generation model AMQ-GAN based on generative adversarial network is constructed. A dual discriminator is used to extract semantic features and humorous features respectively. The semantic feature discriminator guides the generation of semantically coherent and thematically consistent sentences, while the humorous feature discriminator guides the generation of sentences with inconsistency, ambiguity and puns. A data enhancement technology based on contrastive learning is adopted, and prompt is used to set a specific humorous text training template, so that the generated text can better highlight the humorous features.
[0081] Another object of the present invention is to provide a computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, the processor executes the following steps:
[0082] A new humorous text generation task is proposed. The first half of a sentence is input and the second half is automatically generated, which is the flip of the first half. A humorous text generation model AMQ-GAN based on generative adversarial network is constructed. A dual discriminator is used to extract semantic features and humorous features respectively. The semantic feature discriminator guides the generation of semantically coherent and thematically consistent sentences, while the humorous feature discriminator guides the generation of sentences with inconsistency, ambiguity and puns. A data enhancement technology based on contrastive learning is adopted, and prompt is used to set a specific humorous text training template, so that the generated text can better highlight the humorous features.
[0083] Another object of the present invention is to provide an information data processing terminal, which is used to implement the humorous text automatic generation system.
[0084] In combination with the above technical solutions and the technical problems solved, please analyze the advantages and positive effects of the technical solutions to be protected by the present invention from the following aspects:
[0085] First, in view of the technical problems existing in the above-mentioned prior art and the difficulty of solving the problems, the technical solutions to be protected by the present invention and the results and data during the research and development process are closely combined to analyze in detail and deeply how the technical solutions of the present invention solve the technical problems, and some creative technical effects brought about after solving the problems. The specific description is as follows:
[0086] The present invention proposes a new humorous text generation task: input the first half of a sentence and automatically generate the second half, which is the flip of the first half. This form of two halves has a moderate length, which not only takes into account the connection between the context but also highlights the essence of humor.
[0087] For this task, the present invention proposes a humorous text generation model of poisonous chicken soup based on generative adversarial network (AMQ-GAN, Anti-motivational Quotes), inputs the first half of the text, generates the second half containing humorous features by the generator, and evaluates the semantic consistency and humorous characteristics of the generated text by the discriminator. The model provided by the present invention mainly improves the semantic consistency and humorous characteristics of the generated text by the following methods: 1) In order to solve the problem of the small scale of the existing humorous text corpus, the present invention performs data enhancement based on the simSCE contrast learning method; 2) In order to better meet the logical consistency and humorous characteristics, the present invention adds prompt templates to better learn the humorous characteristics in the pre-training model; 3) In order to take into account the theme constraints, smooth writing and humorous requirements of the text, the present invention first decomposes the text vector generated by the generator, and then judges its semantic features and humorous features respectively, and guides the text generation of the generator after weighting. The experimental results on the artificially collected and constructed data set verify the effectiveness and feasibility of the model of the present invention, and the BLEU index and artificial humor judgment have been greatly improved.
[0088] The model proposed in this paper uses a variety of methods to improve the performance of humorous text openness generation:
[0089] (1) The contrastive learning technology SimCSE was introduced. Through contrastive learning, more sentences with similar semantics were obtained and more similar features in the original text were learned, thereby generating more similar words during text generation. This solved the problem of the scarcity of humorous text datasets to a certain extent, indicating that SimCSE technology played a positive role in the semantic feature learning of the model.
[0090] (2) By introducing the prompting technology, the model can effectively learn the humorous features inherent in the pre-trained language model. Different from the downstream tasks of the previous pre-trained model, the setting of the prompt template makes the humorous text generation task closer to the pre-trained language model. With the help of the prompt template, the humorous features can be effectively learned from the large number of features extracted from the pre-trained model, thereby generating more humor. The introduction of the prompting technology effectively improves the model's ability to learn humorous features.
[0091] (3) Based on the above system, the present invention introduces dual discriminators. The semantic feature discriminator and the humor discriminator play a key guiding role in the generator generating texts with semantic features and humor features. Compared with the single discriminator guidance in the GANs network, the two discriminators proposed in the present invention can better promote the generator to learn the semantic information and humor information in the text, thereby generating more open humor texts that meet the requirements in the model generation.
[0092] Second, considering the technical solution as a whole or from the perspective of the product, the technical effects and advantages of the technical solution to be protected by the present invention are described in detail as follows:
[0093] The present invention proposes a humorous text generation task of poisonous chicken soup, which is more in line with the characteristics of conversations in daily communication life, and therefore can better reflect the essence of the humorous text generation task. The present invention designs an AMQ-GAN model, and through SimCSE technology, prompting technology, semantic feature discrimination and humor feature discriminator, effectively guides the generator to generate open text with semantic features and humor features. Experimental results show that the model proposed by the present invention has achieved the requirements of open humorous text to a certain extent.
[0094] Third, as auxiliary evidence of the inventiveness of the claims of the present invention, it is also reflected in the following important aspects:
[0095] (1) The technical solution of the present invention fills the technical gap in the industry at home and abroad:
[0096] Humorous text generation tasks are an important research topic in the field of text generation. Research on humorous short texts is still in its infancy and is relatively difficult. The reason is that the text length of this task is relatively short. It is difficult for existing methods to directly obtain sufficient contextual information from short texts and extract semantic features and humorous features from them. In order to generate humorous sentences that meet the requirements, it is necessary to rely on rich external knowledge and linguistic foundations. A small number of studies have been conducted on humorous short text tasks. However, the introduction of too much external knowledge can easily lead to too many parameters and increase the difficulty of the model. It is also easy to ignore semantic features such as consistent topics, and the generated sentences often have problems of being irrelevant to the previous text.
[0097] Based on this, the present invention proposes a new humorous text generation task for short texts: the toxic chicken soup humorous text generation task. The type of toxic chicken soup text generated by this task is relatively short, conforms to the form of short conversations in interpersonal communication, has a prominent humorous effect, and meets the characteristics of the humorous short text generation task. A toxic chicken soup humorous text generation model is proposed for this task. The model integrates data augmentation technology and prompting technology, and uses a dual discriminator of semantic feature discriminator and humor feature discriminator to fully learn the semantic information and humorous information in the short text, and verifies the effectiveness of the model in solving the task through experiments. Therefore, the present invention proposes a new humorous short text generation task and provides a corresponding method.
[0098] (2) Whether the technical solution of the present invention solves the technical problems that people have been eager to solve but have not been able to solve successfully:
[0099] Research on humorous text generation tasks has always focused on generating high-quality humorous texts with openness. However, since the process of humorous text generation must not only consider the semantic fluency of the sentence itself but also the relevant humorous characteristics, it is more difficult to generate jokes on open texts outside the training set. At present, most humorous text generation adopts a template-based method, which requires a lot of manual annotation, is time-consuming and labor-intensive, and the generated jokes are derived from specific templates and do not have the characteristics of open humorous text generation. Only a small number of researchers have generated humorous texts with a certain degree of openness, but the proportion of generated humorous texts is low and the quality of humorous texts is not high, that is, there are problems of incoherent sentences or insufficient humorous characteristics.
[0100] In addition to the limitations of the method, there is another important challenge in the field of humorous text generation: the lack of public humorous datasets. As the basis of humorous text generation tasks, humorous datasets are very scarce in the current domestic research status. Therefore, how to conduct humorous text generation task research on small-scale humorous text datasets has become another difficult problem.
[0101] Aiming at the current situation of humorous text generation, the present invention is committed to generating high-quality open humorous texts from a small-scale dataset. In view of the characteristics of this task, a humorous text generation model based on generative adversarial networks (AMQ-GAN, Anti-motivational Quotes) is proposed, and a certain scale of Chinese humorous text corpus is constructed by collecting pre-processed datasets. The AMQ-GAN model trained on this corpus has achieved better results than existing methods, generating high-quality open humorous texts, and realizing the generation of high-quality humorous texts with a certain degree of openness on a small-scale dataset. BRIEF DESCRIPTION OF THE DRAWINGS
[0102] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments of the present invention. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0103] Figure 1 is a flow chart of a method for automatically generating humorous texts provided by an embodiment of the present invention;
[0104] Figure 2 It is a structural block diagram of a humorous text automatic generation system provided by an embodiment of the present invention;
[0105] Figure 3 is a diagram of the automatic humorous text generation system provided by an embodiment of the present invention;
[0106] Figure 4is a schematic diagram of a humorous text generation framework of an AMQ-GAN model provided in an embodiment of the present invention;
[0107] Figure 5 It is a schematic diagram of the reinforcement learning process of the AMQ-GAN model generator provided by an embodiment of the present invention;
[0108] In the figure: 1. Data processing module; 2. Model training module; 3. Evaluation module. DETAILED DESCRIPTION
[0109] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0110] In view of the problems existing in the prior art, the present invention provides a method, system, medium, device and terminal for automatically generating humorous text. The present invention is described in detail below with reference to the accompanying drawings.
[0111] 1. Explanatory Examples In order to enable those skilled in the art to fully understand how to implement the present invention, this section provides an illustrative example that expands and describes the technical solution of the claims.
[0112] like Figure 1 As shown, the humorous text automatic generation method provided by the embodiment of the present invention comprises the following steps:
[0113] S101 uses data enhancement technology based on SimCSE contrastive learning to generate multiple different sentence vectors for the same sentence;
[0114] S102, using prompting technology, adds a third sentence to judge the humorous effect of the text;
[0115] S103, in the process of generating confrontation, a semantic feature discriminator and a humor feature discriminator are used to perform semantic discrimination and humor discrimination on the generated sentences respectively.
[0116] like Figure 2 As shown, the humorous text automatic generation system provided by the embodiment of the present invention includes:
[0117] Data processing module 1, used to construct a corpus and perform data preprocessing;
[0118] Model training module 2, used for pre-training, building a humorous text generation model, and generating humorous text;
[0119] Evaluation module 3 is used for automatic rating and manual evaluation respectively.
[0120] The humor text automatic generation system architecture diagram provided by the embodiment of the present invention is as follows Figure 3 shown.
[0121] The technical solution of the present invention is further described below in conjunction with specific embodiments.
[0122] The present invention focuses on the generation of open-ended humorous short texts, and proposes a new task: an automatic generator of poisonous chicken soup-type aphorisms. The first half of a famous quote is input, and the model automatically generates the second half that subverts or reverses the semantics of the first half, thereby achieving the effect of "reasonable but unexpected". For example, the input is "When God closes a door for you", and the output is "He will also pinch your head". This type of humorous text generation task, because the text is short, conforms to the form of short conversations in interpersonal communication, has a prominent humorous effect, and can better reflect the open humor requirements of the humorous text generation task.
[0123] For this task, the present invention proposes a humorous text generation model for toxic chicken soup based on generative adversarial networks (AMQ-GAN, Anti-motivational Quotes). The first half of the input text is used, and the generator generates the second half with humorous features. The discriminator evaluates the semantic consistency and humorous characteristics of the generated text. The model mainly improves the semantic consistency and humorous characteristics of the generated text through the following methods:
[0124] 1) To solve the problem of the small size of the existing humorous text corpus, data enhancement is performed through the simSCE contrastive learning method; 2) To better meet the logical consistency and humorous characteristics, the prompt template is added to better learn the humorous characteristics in the pre-trained model; 3) To take into account the subject constraints, smoothness and humor requirements of the text, the text vector generated by the generator is first decomposed, and then its semantic features and humorous features are judged separately, and after weighting, they jointly guide the text generation of the generator. The experimental results on the artificially collected and constructed datasets verify the effectiveness and feasibility of the model, and there are significant improvements in the BLEU index and manual humor judgment.
[0125] I. Problem Definition
[0126] In this task, a sentence of length m is given as input: s = [w1, ..., w i ,…,w m ], and the model automatically generates a second half sentence s′=[w′1,…,w′ j ,…,w′ n], so that the entire text composed of s and s′ forms a joke that subverts the original cognition and achieves a contrast and ironic effect. The two sentences before and after constitute a kind of poisonous chicken soup text, and the joke sentence output by the model produces a humorous effect. Some examples of humorous texts are shown in Table 1.
[0127] Table 1 Examples of humorous texts
[0128]
[0129] 2. AMQ-GAN Model
[0130] The present invention adopts a humorous text generation method based on target humorous feature extraction and generative adversarial network. In order to further improve the quality of humorous text generation, the following methods are mainly adopted:
[0131] 1) Since the existing Chinese humor text corpus is relatively small, the present invention adopts the data enhancement technology based on SimCSE contrastive learning to generate multiple different sentence vectors for the same sentence, thereby alleviating the problem of insufficient corpus;
[0132] 2) In order to better adapt to the pre-trained model and enable the model to continuously learn the potential humorous features of the text, the present invention adopts prompting technology and adds a third sentence to judge the humorous effect of the text, thereby improving the model's ability to learn the humorous features of the pre-trained language model;
[0133] 3) In the process of generative adversarial, in order to better guide the generator to generate humorous sentences, semantic feature discriminators and humor feature discriminators are used to perform semantic and humor discrimination on the generated sentences respectively. The semantic feature discriminator is mainly responsible for judging whether the semantics and themes of the previous and next sentences are consistent and smooth, etc., while the humor feature discriminator mainly judges the humorous quality of the text through humorous features such as inconsistency, puns, homophony, etc. The output scores of the two discriminators are weighted to jointly guide the generation of the generator text.
[0134] The AMQ-GAN model mainly consists of three parts: pre-training, adversarial training, and semantic feature and humor feature extraction. The overall architecture is as follows: Figure 4 shown.
[0135] 1. Pre-training part
[0136] Pre-training includes pre-training of the generator G, the semantic feature discriminator and the humor feature discriminator. The reason for pre-training is to give the generator and the discriminator a good starting point in the adversarial generative network and to increase the speed of training; the second is to train a generator with good functions in advance to reduce the adverse effects of too few humor data sets. The generator adopts the GPT-2 model. First, 500,000 common dialogue sentences are used to pre-train the generator so that it can generate smooth and fluent general replies based on the input. The present invention adopts a dual discriminator, namely a semantic feature discriminator and a humor feature discriminator. The text generated by the pre-trained generator is added to the common dialogue and humor text respectively, and the labels are added to construct a data set. The former is constructed as a semantic data set to train the semantic feature discriminator, and the latter is constructed as a humor data set to train the humor feature discriminator.
[0137] 2. Adversarial training part
[0138] Adversarial training draws on the improved model of GAN (Generative adversarial networks) proposed by Goodfellow et al., and the optimization objective function used is shown in formula (1):
[0139]
[0140] Among them, x represents a real sample that obeys the real data distribution, D(x) represents the probability that the discriminator discriminates sample x as a real sample, and G(z) is a false sample generated by the generator. The optimization of the generator is to minimize log(1-D(G(z))), so that the samples generated by the generator can deceive the discriminator. The optimization of the discriminator is to maximize log(D(x))+log(1-D(G(z))), so that the discriminator can effectively distinguish between real samples and false samples. Through the training iterations of the generator and the discriminator, the generator is finally promoted to generate "real samples" that can deceive the discriminator. On this basis, the present invention introduces a dual discriminator to distinguish the semantic features and humorous features of the text respectively, which is more suitable for the humorous text generation task studied by the present invention.
[0141] 2.1 Generator Training
[0142] The generator adopts the pre-trained GPT-2 model. In order to enable the model to fully learn the humorous feature information in a small-scale humorous text dataset, the present invention introduces contrastive learning technology, prompting technology and reinforcement learning method in the generator training stage.
[0143] (1) Data enhancement based on contrastive learning
[0144] In order to solve the problem of difficulty in learning humorous features in small-scale samples, the present invention uses SimCSE technology to perform data expansion on humorous texts. During the training process, by modifying the size of the model Dropoutmask, the vector representation of the input text is increased, and different vector representations of the same input text are brought closer to each other, while vector representations of different input texts are alienated from each other, so that the expanded humorous text vectors are closer to each other. The quality of the sentence vector expanded by SimCSE technology is higher than that of previous work, and the problem of insufficient extraction of humorous features in small-scale samples is solved by data expansion.
[0145] (2) Introducing prompting technology
[0146] Prompt technology has been proven to be more adaptable to pre-trained models in small-scale datasets, and pre-trained models can be kept consistent with downstream tasks without introducing additional parameters. Therefore, in order to better enable downstream tasks to learn the characteristics of humorous texts in pre-trained language models, the present invention inserts prompt templates into samples during training in the generator, so that the model can effectively learn the humorous features in the language model. The prompt template determines the effect of the model and the quality of text generation. The present invention manually sets 4 prompt templates to obtain the optimal model, as shown in Table 2. The present invention adds different prompts at the front, middle, and back positions of the humorous text. Experiments have found that prefix templates are more effective for generating humorous texts.
[0147] Table 2 Template example
[0148]
[0149] (3) Reinforcement Learning
[0150] During the generator training process, the sentence formed by splicing the first half of the given humorous corpus and the second half of the sentence generated by the generator is input into the semantic feature discriminator and the humor feature discriminator to obtain the semantic reward score and the humor reward score, thereby guiding the generation of the generator. However, during the training process, the generator can only output one word at a time, but the discriminator can only discriminate a sentence sequence. Therefore, in order to discriminate the semantic score and humor score of each word, the present invention uses the Monte Carlo search method to search and supplement the generator's sentences, such as Figure 5 shown.
[0151] During the generator training process, each state is completed through the Monte Carlo search method to obtain a complete sentence sequence. The sequence is sent to the semantic discriminator and the humor discriminator respectively to obtain the weighted values of the semantic reward score and the humor reward score in the state. After obtaining the reward scores for all states, the reward is used to perform policy gradient update on the generator, thereby guiding the generator to generate humorous text that meets the requirements.
[0152] 2.2 Discriminator Training
[0153] Both the semantic discriminator and the humor discriminator use LSTM networks to perform binary classification on the input sentences. The semantic discriminator is used to judge the semantic truth of the sentences generated by the generator, and the humor discriminator is used to judge the humor of the sentences generated by the generator.
[0154] After the generator obtains the complete sentence through the Monte Carlo search method, it combines the given first half of the sentence with the second half of the sentence generated by the generator and the real second half of the sentence in the humorous corpus to form fake humor and real humor, and marks them with corresponding labels. The semantic discriminator and humor discriminator are used to distinguish them respectively. The semantic discriminator obtains the semantic discrimination score S f , the humor discriminator obtains the humor discrimination score H f , the scores of the two parts are divided by the weight parameter w sh Combined splicing for SH f , using the obtained SH f to guide the training generator.
[0155] SH f =w sh ·(S f ,H f ) (2)
[0156] 3. Semantic and humor feature extraction
[0157] In order to enhance the model's ability to learn humorous and semantic features, the present invention introduces a semantic and humorous feature extraction module to guide the generator to generate text with humorous and semantic features. The present invention calculates the generator's sentences at the word level from the semantic and humorous aspects to obtain the bonus score:
[0158] (1) Semantic feature extraction
[0159] The semantic features of the generated text are mainly judged by topic consistency, semantic coherence and universality.
[0160] 1) Topic consistency
[0161] The present invention believes that if the semantic distance between the sentence vectors of the two sentences is close, the topics discussed are also relatively consistent:
[0162] q1=cos(s,s′) (3)
[0163] 2) Semantic fluency
[0164] Semantic coherence is a basic semantic indicator for evaluating text. The present invention evaluates the semantic coherence of generated humorous text by calculating the forward probability of generating a punchline sentence s′ given a main sentence s of a humorous text, and the backward probability of generating a main sentence given a punchline sentence s′:
[0165] q2=logP(s′|s)+logP backward (s|s′) (4)
[0166] Among them, P(s′|s) calculates the forward probability of generating humorous text, P backward (s|s′) then calculate the backward probability.
[0167] 3) Universality
[0168] The present invention believes that humorous texts often come from common and general words in daily life. It uses a 500,000 large-scale corpus dataset as a common word set and analyzes whether the punchline sentence is universal by calculating the probability that the words in the punchline sentence appear in the common word set.
[0169] q3=logP(w i ) (5)
[0170] (2) Humor feature extraction
[0171] The humor feature discriminator mainly judges the quality of text humor based on the target humor feature extraction module. The extracted humor features are as follows:
[0172] 1) Ambiguity
[0173] Ambiguity is one of the important conditions for generating jokes, so the ambiguous feature can be used as an important component of jokes. The present invention believes that the more ambiguous words are contained in the generated humorous text, the more interesting and funny the text is.
[0174]
[0175] Among them, ambiguities(w i ) represents the number of different meanings of the i-th word in the joke.
[0176] 2) Phonetic similarity
[0177] Rhyme property is one of the important features of jokes. Rhyme makes two different words have the same tone and final vowel, thus generating a joke. The present invention evaluates the phonetic similarity of the generated text by calculating the number of rhyming words in the main sentence and the punchline sentence of the humorous text.
[0178]
[0179] Where rhymes(s, s′) represents the number of rhyming words in the main sentence and punchline sentence in the humorous text, and N represents the total number of words in the main sentence and punchline sentence in the humorous text.
[0180] 3) Inconsistency
[0181] The inconsistency theory holds that the contradiction and conflict between the main sentence and the punchline of a joke can often make readers laugh. This theory is an important indicator for humor discrimination in humor linguistics and is also a theory generally accepted by humor linguistics. Therefore, considering the word set V composed of the main sentence and the punchline of a humorous text, s and V s ′, if the similarity between two words is smaller, it is considered that the contradiction between the previous and next sentences is greater.
[0182] q6=min{cos(V s , V s′ )} (8)
[0183] 2. Application Examples: In order to prove the creativity and technical value of the technical solution of the present invention, this section provides application examples of the technical solution of the claims on specific products or related technologies.
[0184] The AMQ-GAN model proposed in the present invention not only takes into account the adaptation of the pre-training model, but also comprehensively extracts and learns the semantic features and humor features of the text in adversarial training. The generated humorous text is better than the baseline model in terms of fluency, topic consistency, and humor level. Therefore, the method proposed in the present invention can generate more open humorous text. Typical humorous text examples generated by the model of the present invention are shown in Table 3.
[0185] Table 3. Example of humorous text output
[0186]
[0187] 3. Evidence of the effects of the embodiments. The embodiments of the present invention have achieved some positive effects during the development or use process, and indeed have great advantages over the prior art. The following content is described in conjunction with the data, charts, etc. of the test process.
[0188] The present invention screened 1000 humorous text corpora as test samples, divided the test samples into the first half and the second half, given the first half input, the model generated 1000 humorous texts consisting of the second half and the first half, recorded as automatic evaluation sample t-1000, and used the automatic evaluation BLEU method and the manual evaluation method to test the generated sample t-1000, thereby verifying the effectiveness of the model. Since the cost of manual evaluation is too high, the code of the present invention randomly screened 500 samples at t-1000 as manual evaluation samples, recorded as manual evaluation sample t-500.
[0189] At the same time, in order to verify whether the humorous text generated by the model of the present invention is open, the present invention conducted an openness test on the model. In common Weibo conversations, 100 samples were randomly selected, the first half of the test sample was input into the model, and the model output the second half. The two parts constituted 100 open humorous texts output by the model, recorded as t-100 samples, and the open samples were evaluated by manual evaluation.
[0190] The model comparison method adopts the Chinese humor computational model proposed by Tan Hongye et al. This model is based on a generative adversarial network. Both the generator and the discriminator use a double-layer LSTM. The generator is guided to generate humorous text by directly calculating humorous features such as inconsistency and speech similarity of the generated sentences.
[0191] The evaluation method of the present invention mainly adopts BLEU automatic evaluation and manual evaluation. BLEU is one of the most widely used automatic evaluation indicators in natural language generation tasks such as machine translation. The BLEU indicator uses n-gram to compare the similarity between the first half and the second half of the humorous text. The higher the n-gram value, the higher the similarity of the generated text. The present invention uses BLEU-4 value to automatically evaluate the results of the model.
[0192]
[0193] Where N = 4. n Calculate the most similar candidate sentence for each n-gram, which represents the accuracy of text generation. BP is the length penalty factor, which aims to avoid biasing the evaluation towards sentences that are too short and improve the recall rate of text generation. n Yes P n The weighting is set to 1 / N, that is, 1 / 4.
[0194] For creative humorous text generation, the humorous sentences generated by the model may be significantly different from the humorous words generated by humans, so it is not ideal to use n-gram to automatically evaluate the model. Therefore, the present invention manually evaluates the humorous text generated by each model. The present invention sets three scoring items: 1) the semantic fluency of the text is 1-5 points; 2) the theme consistency of the text is divided into 1-5 points; 3) the degree of humor: 1-5 points. The manual evaluation samples t-500 and t-100 are scored, and each paragraph is scored by 3 people. If the sum of the scores is higher than 9 points and each score is not less than 2 points, the generated sentence is considered to be a humorous text, otherwise it is a non-humorous text. The present invention automatically evaluates different models on the test sample t-1000 with BLEU-4, and manually evaluates the three models on the test sample t-500. At the same time, in order to verify whether the humorous text generated by the model is open, a manual evaluation is performed on the open sample t-100. Among them, Joke represents the proportion of texts that are manually evaluated as humorous in the generated text. The evaluation results are shown in Table 4.
[0195] Table 4 Automatic and manual evaluation results
[0196]
[0197] From the experimental results, it can be seen that the AMQ-GAN model proposed in the present invention outperforms the baseline model in both the BLEU-4 automatic evaluation index and the manual evaluation index. Seq2seq does not introduce additional parameters to learn humor features, so the effect is average. Although the GANs model introduces additional parameters to learn humor features, it does not fully utilize the role of the pre-trained model, and the single discriminator is not targeted enough to extract humor features, so the effect needs to be improved.
[0198] Table 5 Examples of different outputs of the three models
[0199]
[0200] Examples of humorous texts generated by the three models are shown in Table 5. From the given examples, it can be seen that the three models can generate a relatively smooth second half of the sentence that is consistent with the theme of the first half, which is in line with the characteristics of the pre-trained model, that is, the language features are learned through a large-scale data set. However, in terms of humor, the seq2seq model does not pay attention to humorous features, so the generated sentences are almost not humorous. The GANs model uses an adversarial method based on the pre-trained model to guide the generator to generate humorous texts, but due to the lack of comprehensive learning of humorous features, the proportion of humorous texts generated is not high. It can be seen from the open test results that the model proposed by the present invention is in Joke t-100The model proposed in this paper uses a variety of methods to improve the performance of humorous text openness generation:
[0201] (1) The contrastive learning technology SimCSE was introduced. Through contrastive learning, more sentences with similar semantics were obtained and more similar features in the original text were learned, thereby generating more similar words during text generation. This solved the problem of the scarcity of humorous text datasets to a certain extent, indicating that SimCSE technology played a positive role in the semantic feature learning of the model.
[0202] (2) By introducing the prompting technology, the model can effectively learn the humorous features inherent in the pre-trained language model. Different from the downstream tasks of the previous pre-trained model, the setting of the prompt template makes the humorous text generation task closer to the pre-trained language model. With the help of the prompt template, the humorous features can be effectively learned from the large number of features extracted from the pre-trained model, thereby generating more humor. The introduction of the prompting technology effectively improves the model's ability to learn humorous features.
[0203] (3) Based on the above system, the present invention introduces dual discriminators. The semantic feature discriminator and the humor discriminator play a key guiding role in the generator generating texts with semantic features and humor features. Compared with the single discriminator guidance in the GANs network, the two discriminators proposed in the present invention can better promote the generator to learn the semantic information and humor information in the text, thereby generating more open humor texts that meet the requirements in the model generation.
[0204] In summary, the present invention proposes a humorous text generation task of poisonous chicken soup, which is more in line with the characteristics of conversations in daily communication life, and therefore can better reflect the essence of the humorous text generation task. The present invention designs an AMQ-GAN model, and through SimCSE technology, prompting technology, semantic feature discrimination and humor feature discriminator, effectively guides the generator to generate open text with semantic features and humor features. The experimental results show that the model proposed by the present invention has achieved the requirements of open humorous text to a certain extent.
[0205] It should be noted that the embodiments of the present invention can be implemented by hardware, software, or a combination of software and hardware. The hardware part can be implemented using dedicated logic; the software part can be stored in a memory and executed by an appropriate instruction execution system, such as a microprocessor or dedicated design hardware. It can be understood by a person of ordinary skill in the art that the above-mentioned devices and methods can be implemented using computer executable instructions and / or contained in a processor control code, such as a carrier medium such as a disk, CD or DVD-ROM, a programmable memory such as a read-only memory (firmware), or a data carrier such as an optical or electronic signal carrier. Such code is provided on the carrier medium. The device and its modules of the present invention can be implemented by hardware circuits such as very large-scale integrated circuits or gate arrays, semiconductors such as logic chips, transistors, etc., or programmable hardware devices such as field programmable gate arrays, programmable logic devices, etc., can also be implemented by software executed by various types of processors, and can also be implemented by a combination of the above-mentioned hardware circuits and software, such as firmware.
[0206] The above description is only a specific implementation mode of the present invention, but the protection scope of the present invention is not limited thereto. Any modifications, equivalent substitutions and improvements made by any technician familiar with the technical field within the technical scope disclosed by the present invention and within the spirit and principle of the present invention should be covered by the protection scope of the present invention.
Claims
1. A method for automatically generating humorous text, characterized in that: The method for automatically generating humorous texts comprises: according to a newly acquired humorous text generation task, inputting a first half sentence, and automatically generating a second half sentence that is a flip of the first half sentence; constructing a humorous text generation model AMQ-GAN based on a generative adversarial network; using a dual discriminator to extract semantic features and humorous features respectively, wherein the semantic feature discriminator guides the generation of sentences with semantic coherence and consistent themes, and the humorous feature discriminator guides the generation of sentences with humorous features of inconsistency, ambiguity and puns; using data enhancement based on contrastive learning and setting a specific humorous text training template in combination with prompt, so that the generated text highlights the humorous features; The AMQ-GAN model consists of three parts: pre-training, adversarial training, and semantic feature and humor feature extraction; (1) Pre-training part Pre-training includes pre-training of the generator G, semantic feature discriminator, and humor feature discriminator. The generator uses the GPT-2 model and uses 500,000 common dialogue sentences to pre-train the generator, so that the generator can generate smooth and fluent general responses based on the input. The semantic feature discriminator and humor feature discriminator are used to construct data sets by adding labels to the texts generated by the pre-trained generator and common dialogues and humorous texts. The former is constructed as a semantic data set to train the semantic feature discriminator, and the latter is constructed as a humor data set to train the humor feature discriminator. (2) Adversarial training part The optimization objective function used is shown as follows: Where x represents a real sample that follows the real data distribution, D(x) represents the probability that the discriminator identifies sample x as a real sample, and G(z) is a fake sample generated by the generator. The optimization of the generator is to minimize log(1-D(G(z))), so that the samples generated by the generator can deceive the discriminator. The optimization of the discriminator is to maximize log(D(x))+log(1-D(G(z))), so that the discriminator can effectively distinguish between real samples and fake samples. Through the training iterations of the generator and the discriminator, the generator is promoted to generate real samples that can deceive the discriminator. The dual discriminator is introduced to distinguish the semantic features and humor features of the text respectively. (3) Semantic and humorous feature extraction The semantic feature and humor feature extraction modules are introduced to guide the generator to generate text with humorous and semantic features; the generator's sentences are calculated at the word level from the semantic and humorous aspects to obtain the bonus score: 1) Semantic feature extraction The semantic features of the generated text are mainly determined by topic consistency, semantic coherence and universality; ①Topic consistency If the sentence vectors of the two sentences are close in meaning, the topics discussed are relatively consistent: q1=cos(s,s′); ② Semantic fluency Semantic coherence is the basic semantic indicator for evaluating text. It is evaluated by calculating the forward probability of generating a punchline sentence s' given a main sentence s of the text, and the backward probability of generating a main sentence given a punchline sentence s': q2=logP(s'|s)+logP backward (s|s′); ③ Universality Using a large-scale corpus dataset of 500,000 words as a common word set, the prevalence of the punchline sentence is calculated by calculating the probability that the words in the punchline sentence appear in the common word set: q3=logP(in i ); 2) Humor feature extraction The humor feature discriminator judges the quality of text humor based on the target humor feature extraction module. The extracted humor features are as follows: ①Ambiguity Ambiguity is one of the important conditions for generating jokes, so the ambiguous feature can be used as an important component of jokes. The funniness of the text can be evaluated by counting the number of ambiguous words in the generated text. Among them, ambiguities(w i ) represents the number of different meanings of the i-th word in the joke; ②Phonetic similarity Rhyme makes two different words have the same tone and final vowel, which creates a punchline. The phonetic similarity of the generated text is evaluated by counting the number of rhyming words in the main sentence and the punchline sentence. Where rhymes(s,s') represents the number of rhyming words in the main sentence and the punchline sentence, and N represents the total number of words in the main sentence and the punchline sentence in the humorous text; ③Inconsistency Analyze the word set composed of the first half and the second half of the sentence V s and V s' , if the similarity between two words is small, then the preceding and following sentences are considered to constitute a joke; q6=min{cos(V s ,V s' )}。 2. The method for automatically generating humorous text according to claim 1, characterized in that: The humorous text automatic generation method comprises the following steps: Step 1: Use data enhancement technology based on SimCSE contrastive learning to generate multiple different sentence vectors for the same sentence; Step 2: Using prompting technology, add a third sentence to judge the humor effect of the text; Step three, in the process of generating confrontation, a semantic feature discriminator and a humor feature discriminator are used to perform semantic discrimination and humor discrimination on the generated sentences respectively.
3. The method for automatically generating humorous text according to claim 2, characterized in that: The semantic feature discriminator in step 3 is responsible for judging whether the semantics and themes of the preceding and following sentences are consistent and fluent; The humor feature discriminator is used to discriminate the humor quality of the text through the humor features of inconsistency, pun and homophony. The output scores of the two discriminators are weighted to jointly guide the generation of the generator text.
4. The method for automatically generating humorous text according to claim 1, characterized in that: The humorous text automatic generation method also includes: Given a first half sentence of length m as input: s = [w1,…,w i ,…,w m ], the model automatically generates a second half sentence s'=[w'1,…,w j ',…,w' n ], so that the entire text composed of s and s' forms a joke that subverts the original cognition and achieves a contrast and ironic effect; the two sentences before and after constitute a poisonous chicken soup text, and the punchline sentence output by the model produces a humorous effect.
5. The method for automatically generating humorous text according to claim 4, characterized in that: The adversarial training part includes: 1) Generator training The generator uses the pre-trained GPT-2 model, and introduces contrastive learning technology, prompting technology and reinforcement learning methods in the generator training stage; ① Data enhancement based on contrastive learning SimCSE technology is used to expand the data of humorous texts. During the training process, the model Dropoutmask size is modified to increase the vector representation of the input text, and different vector representations of the same input text are brought closer to each other, while vector representations of different input texts are alienated from each other, so that the expanded humorous text vectors are closer to each other. ②Introducing prompt technology During the training of the generator, a prompt template is inserted into the sample so that the model can effectively learn the humorous features in the language model; the prompt template determines the effect of the model and the quality of text generation, and 4 prompt templates are manually set to obtain the optimal model; different prompts are added at the front, middle, and back positions of the humorous text, and the prefix template is more effective for the generation of humorous text; ③Reinforcement Learning The Monte Carlo search method is used to search and supplement the generator's sentences. During the generator training process, each state is completed by the Monte Carlo search method to obtain a complete sentence sequence. The sequence is sent to the semantic discriminator and the humor discriminator to obtain the weighted values of the semantic reward score and the humor reward score in the state. After obtaining the reward scores for all states, the reward is used to update the generator's policy gradient, thereby guiding the generator to generate humorous text that meets the requirements. 2) Discriminator training Both the semantic discriminator and the humor discriminator use LSTM networks to perform binary classification on the input sentences; the semantic discriminator is used to discriminate the semantic truth of the sentences generated by the generator, and the humor discriminator is used to discriminate the humor truth of the sentences generated by the generator; After the generator obtains the complete sentence through the Monte Carlo search method, it combines the given first half of the sentence with the second half of the sentence generated by the generator and the real second half of the sentence in the humorous corpus to form fake humor and real humor, and marks them with corresponding labels. The semantic discriminator and humor discriminator are used to distinguish them respectively. The semantic discriminator obtains the semantic discrimination score S f , the humor discriminator obtains the humor discrimination score H f , the scores of the two parts are divided by the weight parameter w sh Combined splicing for SH f , using the obtained SH f Guide the training generator; SH f =w sh ·(S f ,H f )。 6. A humorous text automatic generation system using the humorous text automatic generation method according to any one of claims 1 to 5, characterized in that: The humorous text automatic generation system comprises: Data processing module, used to build corpus and preprocess data; Model training module, used for pre-training, building a humorous text generation model, and generating humorous text; Evaluation module, used for automatic rating and manual evaluation respectively.
7. A computer device, characterized in that: The computer device includes a memory and a processor, the memory stores a computer program, and when the computer program is executed by the processor, the processor executes the steps according to any one of claims 1 to 5.
8. A computer-readable storage medium storing a computer program, wherein when the computer program is executed by a processor, the processor is caused to perform the steps according to any one of claims 1 to 5.
9. An information data processing terminal, characterized in that: The information data processing terminal is used to implement the humorous text automatic generation system as claimed in claim 6.
