Method for enhancing humor reply capability of machine high-order cognitive pre-training language model
By constructing a humorous response dataset and designing a multi-task learning framework, the humorous response capability of the pre-trained language model is enhanced, solving the problem of insufficient creativity and logic in the generation of humorous responses and achieving more natural human-computer interaction.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- FUDAN UNIVERSITY
- Filing Date
- 2023-09-17
- Publication Date
- 2026-07-10
AI Technical Summary
Existing pre-trained language models perform poorly in responding to humor, mainly due to limited humor corpora and datasets, a lack of humor knowledge, and the generation of humorous texts that lack creativity or do not meet human evaluation standards.
We construct a Chinese interpretable humor response dataset, including context-humor response pairs, humor chains, and humor mind maps. We design humor sentiment style classification and rewriting tasks, enhance the humor response capabilities of the pre-trained language model through multi-task learning, and evaluate and improve it using an encoder-decoder framework.
It significantly improves the humor response capability of pre-trained language models, making the humorous texts they generate more in line with human evaluation standards and possessing higher creativity and logic.
Smart Images

Figure CN117744626B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of machine higher-order cognition technology, specifically relating to a method for enhancing the humor response ability of a pre-trained language model for machine higher-order cognition. Background Technology
[0002] Humor is an important skill in human interaction. Developing a sense of humor requires a comprehensive and in-depth understanding of external knowledge, including semantics and cultural context. Therefore, for machines, figuring out what is "funny" and imbuing them with a sense of humor is a significant challenge. Enabling machines to possess a sense of humor, to better understand human language, and to engage in human-computer interaction in a more natural and empathetic way, has become an increasingly important research problem in natural language processing, especially in question-answering systems, dialogue systems, and machine translation.
[0003] Existing research on humor in natural language processing primarily focuses on humor recognition and humor rewriting. Humor recognition aims to determine whether a sentence is humorous from a human perspective, while humor rewriting aims to transform ordinary text into humorous text. In contrast, humorous response is a more challenging task, aiming to generate humorous text in response to preceding content in a conversation. Although existing pre-trained language models can achieve superior performance in human-computer dialogue, their ability to generate humorous responses remains poor.
[0004] Humorous responses are a subfield of humor generation, and existing methods mainly include template-based and neural network-based approaches. Template-based methods include lexical substitution, such as using synonyms, homophones, and slang. For example, some studies use ontology for variable selection, while others use n-gram co-occurrence as a quantitative indicator for variable selection. Neural network-based methods use deep models, such as sequence-to-sequence models and pre-trained language models, to generate humorous text.
[0005] However, template-generated humor lacks creativity and contradicts human intuition. While neural network-generated humor can be high-quality and fluent, it may not be considered humorous from a human evaluation perspective. There are two fundamental reasons why neural network models, especially pre-trained language models that excel on other tasks, perform poorly in humorous responses. Firstly, existing humor corpora and datasets are extremely limited and of low quality. Secondly, generating humorous responses is a high-level cognitive process requiring rich knowledge and common sense. However, existing knowledge bases and common sense repositories lack this kind of humorous knowledge. Summary of the Invention
[0006] The purpose of this invention is to provide a method for enhancing the humor response ability of a pre-trained language model for higher-order machine cognition.
[0007] The method for enhancing the humor response ability of a pre-trained language model for higher-order machine cognition provided by this invention comprises the following steps:
[0008] (i) Establishing connections between regular text and humorous text; including constructing an interpretable dataset consisting of context-humorous replies, where each context-humorous reply pair has a humor chain and a humor mind map, demonstrating the knowledge and logical reasoning process required to generate humorous replies;
[0009] (ii) Evaluate and improve the humor response ability of the pre-trained language model; including designing a humor sentiment style classification task and a humor rewriting task, which can assist humor response in a multi-task training manner; in addition, design an encoder-decoder framework to inject humor chains and humor mind maps into the pre-trained language model, and enhance the humor response ability of the pre-trained language model by using two auxiliary tasks based on multi-task learning.
[0010] In this invention, a novel Chinese interpretable humor response dataset is constructed, which can be used to comprehensively evaluate and improve the humor response capabilities of pre-trained language models. Each context-humor response pair includes a corresponding humor chain and a humor mind map. Further humor-related auxiliary tasks are designed, including humor sentiment style classification tasks and humor rewriting tasks, and are supported by corresponding datasets to further enhance the humor response capabilities of pre-trained language models.
[0011] This invention improves the humor response capability of pre-trained language models by including the following four key elements: Figure 1 As shown, it specifically includes:
[0012] (1) The above text - humorous reply
[0013] In step (1), text-response pairs with a length of less than 30 words are crawled from internet platforms and marked as humorous or with the most likes. These platforms include, but are not limited to, Xiaohongshu, Douyin, and Zhihu. After collection, the text-response pairs are further manually evaluated, and controversial text-response pairs are discarded to obtain the final text-humorous response pairs.
[0014] (2) Humor chain
[0015] In step (one), a humor chain is marked for each text-humor response pair based on four steps; a humor chain is a piece of text that explains how a humorous response is generated through underlying thought processes; the four steps are: restating the text, that is, converting an interactive text into a declarative sentence; generating a regular response, that is, manually creating or retrieving a regular response to the text through a search engine; marking humor anchors, that is, finding the turning point between a regular response and a humorous response, such as rhetorical devices, inverted keywords, homophones, contrasts, etc.; generating a humorous response, that is, creating a humorous response based on the turning point;
[0016] To accelerate and standardize the process of marking humor chains, this invention establishes some commonly used paradigms for humor chains, such as the unity of opposites and attribute transformation.
[0017] The unity of opposites paradigm: Assume an event X has a property This attribute can also be interpreted as another general attribute. This can be further interpreted as an unconventional attribute. If event Z has attributes Then, event Z can be inferred from event X; this pattern can also be expressed as: ;
[0018] Attribute transformation paradigm: Suppose an event X has two attributes, namely and In another event Y, the focus of the conversation shifted from... Transferred to This pattern can also be represented as: .
[0019] (3) Humorous Mind Map
[0020] To help the pre-trained language model capture the explicit and implicit semantic knowledge and potential logical framework contained in humorous reasoning, step (I) of this invention constructs a humor mind map based on each humor chain, such as... Figure 2 As shown; firstly, humor-related entities are manually labeled in the humor chain. A humor-related entity is a word or phrase that forms part of the humor response reasoning path. It can be an event, a state, or a description, etc. Then, using predefined relation types, relations are established between each entity pair to form a humor triple. The predefined relationships are divided into general relationships and humor-related relationships. General relationships include cause / effect, definition, manner, inclusion / being included, attribute, etc., while humor-related relationships include metaphor, personification, analogy, homonym, opposition, etc. Finally, the humor triplets are connected to form a humor mind map.
[0021] (4) Humorous auxiliary tasks
[0022] In step (two), the humor-assisted tasks include humor emotional style classification and humor text rewriting;
[0023] The humor sentiment style classification task is designed based on the following assumption: a pre-trained language model can generate more reasonable humorous responses by better understanding the sentiment style of the context-response pair. Therefore, this invention further annotates the sentiment and style of context-humor response pairs in an interpretable humorous response dataset. Sentiments are categorized as positive and negative, and styles include amicable, self-reinforcing, aggressive, and self-defeating. The task is to output the corresponding sentiment and style of a complete sentence formed by connecting context-humor response pairs based on rules and human verification, given the context-humor response pair.
[0024] The humor rewriting task is designed based on the following assumption: pre-trained language models tend to generate conventional responses rather than humorous responses, therefore humor rewriting can control the model to generate conventional responses; thus, this invention constructs conventional-humorous text pairs to help the pre-trained language model learn the potential inconsistencies between conventional and humorous expressions; this invention first inputs the preceding text from an interpretable dataset into a search engine or manually writes a conventional response; next, based on grammatical rules, it constructs conventional text and corresponding humorous text; the task is to generate humorous text given a conventional text.
[0025] Based on the key elements of humorous responses mentioned above, a framework for evaluating and improving the humorous response capabilities of pre-trained language models is as follows: Figure 3 As shown, the specific steps are as follows:
[0026] (1) Evaluate the humor response ability of the pre-trained language model
[0027] First, several representative pre-trained language models, such as T5, BART, and CPT, were selected for evaluation. The input of the models was the context from an interpretable dataset, and the output was a humorous response. The pre-trained language models were fine-tuned using the context-humor response algorithm. The humor response capability of the pre-trained language models was evaluated by comparing the labeled humorous responses in the test set with the humorous responses output by the models.
[0028] (2) Evaluate the humor response ability of the pre-trained language model under annotation enhancement.
[0029] Next, in addition to the above, this invention also incorporates humor chains and humor mind maps as input to the model, outputting humorous responses. The pre-trained language model is fine-tuned using the above-humor response pairs, humor chains, and humor mind maps. The humor response capability of the pre-trained language model under annotation enhancement is evaluated by comparing real humorous responses in the test set with the humorous responses output by the model. Specifically, this invention encodes each type of input separately using the corresponding encoder of the pre-trained language model, and then concatenates their outputs and inputs them into the decoder, as shown in the following formula:
[0030] ,
[0031] Where Q and M represent the preceding text and the humorous mind map, respectively. The annotations represent the humorous responses generated by the model with and without annotations, where Enc and Dec represent the encoder and decoder of the pre-trained language model. The effectiveness of annotations and the ability to generate humorous responses with annotation enhancement are evaluated by comparing the quality of humorous responses generated by the model with and without annotations.
[0032] (3) Evaluate the humor response ability of the pre-trained language model under multi-task enhancement.
[0033] This invention designs two humor-assisted tasks: humor sentiment style classification and humor rewriting, to evaluate the humor response capabilities of a pre-trained language model under multi-task augmentation. The humor sentiment style classification task uses a CPT model as its framework, taking a complete sentence composed of context-humor response pairs as input. After fine-tuning the model, it outputs the corresponding sentiment and style. The humor rewriting task uses a T5 model as its framework, taking regular text as input, and outputting semantically invariant humorous text after fine-tuning. This invention utilizes a multi-task learning approach, leveraging auxiliary tasks to enable the pre-trained language model to learn humor responses, and evaluates the pre-trained language model's humor response capabilities under multi-task augmentation. Specifically, this invention minimizes the weighted sum of the loss functions of multiple tasks, where the weights are hyperparameters adjusted experimentally. By comparing the humor response performance of the pre-trained language model under multi-task augmentation and under annotation augmentation, the effectiveness of the auxiliary tasks can be evaluated.
[0034] The main technical features and advantages of this invention are as follows:
[0035] (1) Construct a large-scale Chinese interpretable humor response dataset, including context-humor response pairs, humor chains, humor mind maps, sentiment styles of context-humor response pairs, and regular text-humor text pairs; among which, humor chains and humor mind maps embody the logical reasoning process from context to humor response; sentiment styles of context-humor response pairs and regular text-humor text pairs serve as supporting datasets for auxiliary tasks, namely humor sentiment style classification tasks and humor rewriting tasks; this invention partially solves the problem of data and knowledge gaps in the field of humor responses;
[0036] (2) Design a three-step evaluation framework for the humor response ability of pre-trained language models, including whether the pre-trained language model can give a humorous response after fine-tuning, whether the labeled knowledge helps to improve the humor response ability of the pre-trained language model, and whether the auxiliary task helps to improve the humor response ability of the pre-trained language model.
[0037] (3) Design a novel encoder-decoder framework, use the corresponding encoder of the pre-trained language model to encode each type of input separately, and then connect their outputs to input into the decoder; and use multi-task learning to effectively give full play to the effect of each input to enhance the humor response capability of the pre-trained language model. Attached Figure Description
[0038] Figure 1 This includes humor chains, humor mind maps, and humor-aiding tasks necessary for humans and pre-trained language models to respond to given context and infer humorous responses.
[0039] Figure 2 The process of constructing a humor mind map based on the humor chain of the above-mentioned humorous reply pairs.
[0040] Figure 3 This is a framework for evaluating the humor response ability of pre-trained language models under multi-task enhancement. Detailed Implementation
[0041] The present invention will be further described below through examples.
[0042] Example setup.
[0043] The experiments were conducted on a machine equipped with a Tesla V100 GPU, using the Python programming language and the PyTorch library. The maximum source text length was set to 512 bytes, and the target text length to 128 bytes. The learning rate was set from 2e-5 to 4e-5 based on the machine's memory, with a batch size of 8 bytes, and an early stopping mechanism was used for a maximum of 50 training epochs.
[0044] Results Analysis: This invention showcases several excellent examples generated by a multi-task-based annotation-enhanced humor response framework. See below:
[0045] Example 1
[0046] Previous article: How to be a female programmer with an artistic flair?
[0047] Standard answer: Wearing a skirt is fine!
[0048] Model generation: Wearing a skirt;
[0049] Example 2
[0050] Previous article: Do a certain country's fighter jets and 800,000-ton catamaran aircraft carrier really exist?
[0051] Standard answer: That aircraft carrier is called [Island Name]
[0052] Model generation: A certain island is equivalent to an unsinkable aircraft carrier;
[0053] Example 3
[0054] Previous article: Which traditional Chinese medicines can prevent damage to the body caused by certain genes?
[0055] Standard answer: Of course, it's Banlangen (Isatis root).
[0056] Model generation: Isatis root can eliminate the potential harm of a certain genetically modified crop.
[0057] The specific analysis is as follows: Example 2 uses metaphorical rhetoric, contrasting "a certain island" with "an unsinkable aircraft carrier" to echo the context of "catamaran aircraft carrier." Additionally, Example 3 restates some information, such as "eliminating potential hazards to certain crops." It's worth noting that some examples scored low in automatic evaluation but performed satisfactorily in human evaluation. For example, the question is "Does anyone use a scary wallpaper on their phone?", the real answer is "your account balance," while the predicted answer is "a wallet without money." Although the predicted answer is not similar to the reference answer, it answers the question and still has a sense of humor.
[0058] The above examples illustrate the effectiveness of this method in generating humorous replies.
Claims
1. A method for enhancing the humor response ability of a pre-trained language model for higher-order machine cognition, characterized in that, The specific steps are as follows: (a) Establishing a connection between conventional and humorous texts; This includes constructing an interpretable dataset consisting of context-humor response pairs, where each context-humor response pair has a humor chain and a humor mind map, demonstrating the knowledge and logical reasoning process required to generate humorous responses; The humor chain is a text explaining how humorous responses are generated through underlying thought processes. For each context-humor response pair, the humor chain is labeled with the following steps: restating the context, i.e., converting an interactive context into a declarative sentence; generating a regular response, i.e., manually creating or retrieving a regular response to the context using a search engine; labeling humor anchors, i.e., identifying the turning point between the regular response and the humorous response; and generating a humorous response, i.e., creating a humorous response based on the turning point. The humor mind map is constructed based on each humor chain and is used to help the pre-trained language model capture the explicit and implicit semantic knowledge and potential logical backbone contained in humorous reasoning. The process of building a humor mind map is as follows: First, manually label humor-related entities in the humor chain. A humor-related entity is a word or phrase that forms part of the humor response reasoning path; it can be an event, a state, or a description. Then, a predefined relation type is used to establish a relationship between each entity pair, forming a humor triple. The predefined relationships are divided into general relationships and humor-related relationships. General relationships include cause / effect, definition, manner, inclusion / being included, and attribute. Humor-related relationships include metaphor, personification, analogy, homonym, and opposition. Finally, the humor triplets are connected to form a humor mind map. (II) Evaluating and improving the humor response capability of the pre-trained language model; including designing a humor sentiment style classification task and a humor rewriting task as auxiliary tasks for humor response through multi-task training; in addition, designing an encoder-decoder framework to inject humor chains and humor mind maps into the pre-trained language model, and using two auxiliary tasks to enhance the humor response capability of the pre-trained language model based on multi-task learning; wherein: The humor sentiment style classification task is designed based on the following assumption: a pre-trained language model can generate more reasonable humorous responses by better understanding the sentiment style of the context-response pair; therefore, the sentiment and style of the context-humor response pairs are further labeled in the interpretable humorous response dataset; sentiment includes two categories: positive and negative, and style includes amicable, self-reinforcing, aggressive, and self-defeating; the task is to output the corresponding sentiment and style of a complete sentence formed by connecting context-humor response pairs based on rules and human verification. The humor rewriting task is designed based on the following assumption: pre-trained language models tend to generate conventional responses rather than humorous ones, and humor rewriting is used to control the model to generate conventional responses. Therefore, conventional-humorous text pairs are constructed to help the pre-trained language model learn the potential inconsistencies between conventional and humorous expressions. First, the preceding text from the interpretable dataset is input into a search engine or manually written to obtain conventional responses. Then, based on grammatical rules, conventional text and corresponding humorous text are constructed. The task is to generate humorous text given a conventional text.
2. The method according to claim 1, characterized in that, In step (one): The aforementioned text-humor reply pairs are obtained by scraping text-humor reply pairs with a length of less than 30 words from internet platforms that are marked as humorous or have the most likes. After collection, the text-humor reply pairs are further manually evaluated, and controversial text-humor reply pairs are discarded to obtain the final text-humor reply pairs.
3. The method according to claim 2, characterized in that, In step (1), in order to accelerate and unify the process of marking humor chains, the following common paradigm for humor chains is established: unity of opposites and attribute transformation; The unity of opposites paradigm: Assume an event X has a property This attribute can also be interpreted as another general attribute. This can be further interpreted as an unconventional attribute. If event Z has attributes Then, event Z can be inferred from event X; this pattern is expressed as: ; Attribute transformation paradigm: Suppose an event X has two attributes, namely and In another event Y, the focus of the conversation shifted from... Transferred to The pattern is represented as follows: .
4. The method according to claim 1, characterized in that, In step (ii), based on the key elements of humorous responses mentioned above, the humorous response capability of the pre-trained language model is evaluated and improved. The specific steps are as follows: (1) Evaluate the humor response ability of the pre-trained language model First, several representative pre-trained language models are selected for evaluation. The input of the model is the context from the interpretable dataset, and the output is a humorous response. The pre-trained language model is fine-tuned using the context-humor response pair. The humor response capability of the pre-trained language model is evaluated by comparing the labeled humorous responses in the test set with the humorous responses output by the model. (2) Evaluate the humor response ability of the pre-trained language model under annotation enhancement. Next, in addition to the above, humor chains and humor mind maps are also used as inputs to the model, and humorous responses are output. The pre-trained language model was fine-tuned using humor response pairs, humor chains, and humor mind maps. The model's humor response capability under annotation enhancement was evaluated by comparing real humor responses from the test set with the model's output humor responses. Specifically, the pre-trained language model's corresponding encoder encoded each type of input separately, and then their outputs were concatenated and input into the decoder, as shown in the following formula: , Where Q and M represent the preceding text and the humorous mind map, respectively. The annotations represent the humorous responses generated by the model with and without annotations, where Enc and Dec represent the encoder and decoder of the pre-trained language model. By comparing the quality of humorous responses generated by the model with and without annotations, the role of annotations and the ability to generate humorous responses with annotation enhancement are evaluated. (3) Evaluate the humor response ability of the pre-trained language model under multi-task enhancement. Two humor-assisted tasks—humor sentiment style classification and humor rewriting—were used to evaluate the humor response capabilities of a pre-trained language model under multi-task augmentation. Specifically, the humor sentiment style classification task used the CPT model as a framework, with the input being a complete sentence formed by connecting the context and the humor response pair. After fine-tuning the model, the output was the corresponding sentiment and style. The humor rewriting task used the T5 model as a framework, with the input being regular text. After fine-tuning the model, the output was the corresponding semantically invariant humorous text. Multi-task learning was employed to allow the pre-trained language model to learn humor responses through auxiliary tasks, and the humor response capabilities of the pre-trained language model under multi-task augmentation were evaluated. The weighted sum of the loss functions of multiple tasks was minimized, with the weights being hyperparameters adjusted experimentally. The effectiveness of the auxiliary tasks was evaluated by comparing the humor response performance of the pre-trained language model under multi-task augmentation and under annotation augmentation.