Text irony detection method based on contextual information sufficiency judgment
By evaluating and supplementing context information, the ironic detection performance problem caused by insufficient context information in the prior art is solved, and a more accurate and efficient ironic detection effect is achieved.
Patent Information
- Application Number
- CN202411503651.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-25
- Publication Date
- 2025-02-25
AI Technical Summary
When the prior art performs satirical detection in combination with context information, it is impossible to effectively perceive whether the context information is sufficient, resulting in the performance of satirical detection that needs to be improved.
A text satirical detection method based on the determination of the adequacy of context information is proposed. By obtaining the text to be analyzed and its satirical context information, the adequacy of context information is evaluated, and when insufficient, a preset context information is used to provide supplementary context information using the preset context information retrieval library, and finally determine whether the text to be analyzed has ironic emotions.
This method can effectively determine whether the context information is sufficient, reduce ironic detection errors caused by insufficient context information, and improve the performance and accuracy of ironic detection.
Smart Images

Figure CN119513312A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of natural language processing, in particular to the field of large language models, and more particularly to a text sarcasm detection method based on context information sufficiency determination. Background Art
[0002] Sarcasm is a literary device and a complex form of language expression. People who express opinions usually use sarcasm to express their opinions on a target in a way that hides the opposite meaning of the literal meaning, so as to expose, criticize or ridicule the target. Sarcasm is widely found in literary works, news reports, oral communication and online social media. When people use sarcasm to express their opinions, their true opinions and attitudes are often not limited to the surface meaning of the words, but hidden in the deep semantics of the words.
[0003] Detecting and revealing sarcasm is the key to uncovering users' true emotions, intentions, and positions, and is crucial to research in the fields of sentiment analysis, position analysis, and hate speech identification.
[0004] Sarcasm detection is usually considered a classification problem in the field of natural language processing, that is, using detection methods to judge the data to be analyzed and mark it as "sarcasm" or "non-sarcasm". According to different data modalities (such as text, audio, pictures, videos, etc.) and the combination of different data modalities, sarcasm detection is divided into single-modal sarcasm detection and multi-modal sarcasm detection.
[0005] With the growing demand for sarcastic language detection and technological innovation and progress, the research on sarcasm detection has shifted from traditional rule-based methods and feature-based machine learning methods to deep learning-based methods. Rule-based methods mainly rely on artificially created patterns for analysis, and are limited to fixed patterns to identify and detect sarcasm. In order to improve adaptability in common scenarios, people have proposed feature-based machine learning methods, which convert artificially designed key features into low-dimensional vectors and classify them to assist in the identification and detection of sarcasm. In the era of deep learning, in order to reduce human intervention and strengthen language analysis, people have begun to turn to deep learning methods for sarcasm detection, which mainly include the following categories: (1) using inconsistency to infer sarcasm; (2) using the correlation between emotion and sarcasm to detect sarcasm; (3) using external knowledge or common sense to detect sarcasm. Among them:
[0006] (1) Using inconsistency to identify sarcasm is based on the fact that inconsistency is a typical and common way of expressing sarcasm in social media. In sarcasm detection, "inconsistency" refers to the contradiction or mismatch between the surface meaning and the underlying meaning of a sentence, which is one of the core factors that produce the sarcasm effect. For example, the contradiction between the surface meaning of a sentence and the context or expectation is used to express semantic inconsistency, such as "I'm very sorry, my foot hit your heel" to express the anger / reminder of not receiving a timely apology after being stepped on. Research shows that inconsistency not only exists in the text to be analyzed, but also the inconsistency between the text to be analyzed and its context is also a characteristic of sarcasm. For example, when analyzing social forum data, other comments or description information on the topic of the data to be analyzed is considered; when analyzing social media data, the comment information of the data to be analyzed, as well as the user's historical speech and user information of the publisher are considered. Research shows that sarcasm detection methods that combine contextual information can achieve better results.
[0007] (2) Using the correlation between sentiment and sarcasm to detect sarcasm is to use the sentiment analysis results of given data to help identify the sentiment tendency contained in the sentence, such as positive, negative or neutral. Sarcastic sentences can be identified by capturing the complex relationship between sentiment and sarcasm, such as sarcasm often contains negative sentiment. Similar to the method of using inconsistency to detect sarcasm, some current research methods focus on analyzing the sentiment difference between the text to be analyzed and its context to detect sarcasm.
[0008] (3) Detecting sarcasm with the help of external knowledge or common sense is to detect sarcasm by accessing common sense knowledge related to the data to be analyzed. External knowledge or common sense libraries can provide background knowledge and information related to the text to be analyzed, which can serve as context information of the data to be analyzed to assist in sarcasm detection.
[0009] In general, using deep learning methods for sarcasm detection, whether it is through inconsistency, sentiment analysis, or external knowledge, combined with contextual information for sarcasm detection is the current mainstream and effective method.
[0010] At present, among the deep learning methods for sarcasm detection, the sarcasm detection method using inconsistency and sentiment reasoning can be combined with contextual information for analysis; the external knowledge or common sense detection method can identify external knowledge or common sense as a kind of background knowledge, and the background knowledge can be used as a kind of context. The sarcasm detection method that combines contextual information can achieve better results.
[0011] However, when combining context information, most methods only consider the macroscopic possibility that combining context may improve the effect of sarcasm detection. They simply use context information to complete sarcasm detection and obtain relevant results. The actual performance needs to be further improved.
[0012] It should be noted that this background technology is only used to introduce the relevant information of the present invention to help understand the technical solution of the present invention, but it does not mean that the relevant information is necessarily the prior art. The relevant information is submitted and disclosed together with the present invention solution. If there is no evidence that the relevant information has been disclosed before the application date of the present invention, the relevant information shall not be regarded as the prior art. Summary of the invention
[0013] Therefore, the purpose of the present invention is to overcome the defects of the prior art and provide a method for detecting sarcasm in text.
[0014] The objective of the present invention is achieved through the following technical solutions:
[0015] According to the first aspect of the present invention, a method for detecting sarcasm in text is provided, comprising: obtaining a text to be analyzed and its sarcasm context information, wherein the sarcasm context information refers to context information used to assist in determining whether the text to be analyzed contains sarcasm; evaluating the sufficiency of the sarcasm context information of the text to be analyzed based on the text to be analyzed and its sarcasm context information; in the case where the sarcasm context information of the text to be analyzed is insufficient, providing supplementary context information based on a preset context information retrieval library to obtain updated sarcasm context information; determining whether the text to be analyzed contains sarcasm based on the text to be analyzed and its latest sarcasm context information. The technical solution can at least achieve the following beneficial technical effects: the method makes up for the defect that the existing method cannot perceive whether the context information is sufficient, and proposes a method for effectively determining whether the given context information is sufficient.
[0016] Optionally, the results of evaluating the sufficiency of the sarcastic context information of the text to be analyzed include: sufficient, insufficient and no context required, and the method further includes: when the sarcastic context information of the text to be analyzed is sufficient, determining whether the text to be analyzed has a sarcastic emotion based on the text to be analyzed and its latest sarcastic context information; when no context is required, determining whether the text to be analyzed has a sarcastic emotion based on the text to be analyzed and its latest sarcastic context information, the latest sarcastic context information being a default value.
[0017] Optionally, the process of evaluating whether the ironic context of the text to be analyzed is sufficient includes: determining whether the ironic context of the text to be analyzed is sufficient using a pre-trained first detection model according to the text to be analyzed and its ironic context information. This technical solution can at least achieve the following beneficial technical effects: the pre-trained first detection model can be used to automatically detect whether the ironic context is sufficient, thereby improving detection efficiency.
[0018] Optionally, the pre-trained first detection model is trained in the following manner: obtain a first training set, the training set includes multiple samples and their labels, wherein each sample includes a sample text and its sarcastic context, the label space includes at least 3 categories, namely, categories with sufficient context, insufficient context, and no context required, and the label indicates the category to which the corresponding sample belongs; use the first training set to train the first detection model to identify the corresponding text as belonging to the category with sufficient context, insufficient context, or no context required based on the input sample. This technical solution can at least achieve the following beneficial technical effects: additionally setting the category without context allows the model to effectively judge whether some categories that can be judged as sarcastic based on the text to be analyzed itself are sarcastic, so as to avoid forcibly adding sarcastic context and better ensure the accuracy of sarcastic detection.
[0019] Optionally, the pre-trained first detection model is trained in the following manner: obtain a first detection model, which is obtained by adding an adaptation layer to some layers of a trained large language model; obtain a first training set, which includes multiple samples and their labels, wherein each sample includes a sample text and its sarcastic context, and the label space includes at least 3 categories, namely, categories with sufficient context, insufficient context, and no context required, and the label indicates the category to which the corresponding sample belongs; use the first training set to train the first detection model to identify whether the corresponding text belongs to the category of sufficient context, insufficient context, or no context required based on the input sample, and only update the parameters of the adaptation layer during training. This technical solution can at least achieve the following beneficial technical effects: train the first detection model to identify three categories of text to be analyzed, so as to better provide more accurate information for subsequent sarcastic detection and improve the performance of sarcastic detection.
[0020] Optionally, the process of determining whether the text to be analyzed contains sarcastic emotions includes: optionally, using a second detection model to determine whether the text to be analyzed contains sarcastic emotions, if so, classifying the text to be analyzed as sarcastic, if not, classifying it as non-sarcastic, wherein the second detection model is a large model.
[0021] Optionally, the method includes: obtaining pre-designed interactive instructions to guide the large model to determine whether the text to be analyzed contains sarcastic emotions, wherein the interactive instructions include: guide words, used to provide task descriptions to guide the large model to obtain task requirements; examples, used to provide reference cases to the large model to guide the large model to understand the task requirements; instruction formats, used to provide instruction templates, carrying the text to be analyzed that needs to be input into the large model and its latest sarcastic context information, to determine whether the input text to be analyzed contains sarcastic emotions. This technical solution can at least achieve the following beneficial technical effects: using preset interactive instructions to guide the large model to determine whether the text to be analyzed contains sarcastic emotions, reducing the difficulty of detection, and using the rich knowledge reserves of the large model to improve the accuracy of sarcastic detection.
[0022] Optionally, the method further includes: constructing a context information retrieval library, which includes: a first sub-library and a second sub-library, wherein the first sub-library stores context information in the real context of the text to be analyzed, and the second sub-library stores an external knowledge base based on common sense; according to the context information retrieval library, obtaining supplementary context information from at least one of the first sub-library and the second sub-library. This technical solution can use two sub-libraries to automatically supplement multiple context information according to sufficiency results; combine the context information to perform sarcasm detection on the data to be analyzed, optimize the sarcasm detection process, and improve the accuracy of sarcasm detection.
[0023] According to a second aspect of the present invention, there is provided a computer program product, comprising a computer program / instruction, which implements the steps of the method described in the first aspect when executed by a processor.
[0024] According to a third aspect of the present invention, there is provided an electronic device comprising: one or more processors; and a memory, wherein the memory is used to store executable instructions; the one or more processors are configured to implement the steps of the method described in the first aspect by executing the executable instructions. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] The embodiments of the present invention are further described below with reference to the accompanying drawings, in which:
[0026] Figure 1 A schematic diagram of a process of implementing a context information sufficiency determination model using a fine-tuning model according to an embodiment of the present invention;
[0027] Figure 2 A schematic diagram of a flow chart of a method for sarcasm detection based on a large language model according to an embodiment of the present invention;
[0028] Figure 3 The figure is a flow chart of a method for detecting sarcasm in text according to an embodiment of the present invention. DETAILED DESCRIPTION
[0029] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below through specific embodiments in conjunction with the accompanying drawings. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0030] As mentioned in the background technology section, when conducting sarcasm detection research, the inventors found that most of the sarcasm detection research based on contextual information did not consider whether the contextual information of each text to be analyzed was sufficient. Some FPs (False Positives) were due to insufficient contextual information, and the algorithm could not draw the conclusion of "sarcasm", that is, it did not consider whether the provided contextual information could support the algorithm to draw the conclusion of "sarcasm" or "non-sarcasm".
[0031] Furthermore, in natural language processing, the prediction results of the classification algorithm are compared with the actual results, and are divided into correctly predicted positive samples (True Positive, abbreviated as TP), incorrectly predicted positive samples (False Positive, abbreviated as FP), correctly predicted negative samples (True Negative, abbreviated as TN), and incorrectly predicted negative samples (False Negative, abbreviated as FN). In the sarcasm detection algorithm, there are some FP samples, that is, samples that should be predicted as "sarcasm", but are mistakenly predicted as "non-sarcasm". The reason is that there is not enough effective context provided, which makes the algorithm unable to determine its "sarcasm" and then judges it as "non-sarcasm".
[0032] Since the text data for sarcasm detection comes from various sources, such as article fragments, social forums, social media, etc., the context information involved is also diverse. In the definition of the present invention, the context information for sarcasm detection is considered from a broad perspective. In analyzing article sentences, the context information can be paragraph fragments of the article adjacent to the data to be analyzed; in analyzing social forum data, the context information includes other comments or description information on the topic of the data to be analyzed; in social media, the context information includes comment information on the data to be analyzed; in social media, the context information includes the historical speeches and user information of the user who published the data to be analyzed; and when external knowledge is involved, the context information includes knowledge or common sense information in the field involved in the data to be analyzed.
[0033] The inventor has conducted in-depth research on such situations and proposed that we should first perceive whether the currently provided context information is sufficient, and perform sarcasm detection when the context information is sufficient. When the context information is insufficient, we should try to continue to obtain more complete context information for auxiliary judgment, thereby reducing the situation where sarcasm detection errors are caused by insufficient context information, and improving the performance of sarcasm detection.
[0034] According to an embodiment of the present invention, a method for detecting sarcasm in text is provided, wherein the method comprises using two detection models based on neural networks and a context information retrieval library to complete sarcasm detection. The two detection models and the context information retrieval library are respectively described below.
[0035] (1) First Detection Model
[0036] The first detection model needs to be trained before use. The pre-trained first detection model is used to determine whether the context of the text to be analyzed is sufficient based on the input text to be analyzed and its ironic context information.
[0037] According to one embodiment of the present invention, the pre-trained first detection model is trained in the following manner: obtain a first training set, the training set includes multiple samples and their labels, wherein each sample includes a sample text and its sarcastic context, the label space includes at least 3 categories, namely, categories with sufficient context, insufficient context, and no context required, and the label indicates the category to which the corresponding sample belongs; use the first training set to train the first detection model to identify the corresponding text as belonging to the category with sufficient context, insufficient context, or no context required based on the input sample. The first detection model can be implemented based on the backbone network of an existing neural network model (non-large language model). For example, the first detection model can be implemented based on a BERT model or other Transformer model, first collect some samples and annotate the labels to form a data set, and then extract the first training set from the data set to train the model. In addition, it should be noted that in the present invention, sarcastic context information may be referred to as sarcastic context, context information, context, or context information, etc.
[0038] In order to simplify the difficulty of deploying the first detection model and improve the performance, the large language model can be fine-tuned to achieve this. According to one embodiment of the present invention, the pre-trained first detection model is fine-tuned and trained in the following manner: obtain a first detection model, which is obtained by adding an adaptation layer to some layers of the trained large language model; obtain a first training set, which includes multiple samples and their labels, wherein each sample includes a sample text and its ironic context, and the label space includes at least 3 categories, namely, categories with sufficient context, insufficient context, and no context required, and the label indicates the category to which the corresponding sample belongs; use the first training set to train the first detection model to identify that the corresponding text belongs to the category of sufficient context, insufficient context, or no context required according to the input sample, and only update the parameters of the adaptation layer during training.
[0039] According to an example of the present invention, this example uses instruction fine-tuning to fine-tune the large language model to obtain a judgment model that obtains sufficient context information in the field of sarcasm detection. The steps of fine-tuning the model are as follows: Figure 1 The fine-tuning model flow chart includes steps S11-S14:
[0040] S11: Select the original large language model, such as Llama 2-7B (alpaca model, with 7 billion parameters), Llama3.1-8B model, Llama3.1-70B model, Atom-7B model, etc.;
[0041] S12: Construct a data set, wherein the data set includes at least three categories of data, namely, samples with "sufficient context", samples with "insufficient context", and samples with "no context required"; wherein, the context of the sample with "sufficient context" is sufficient to support the determination of the text to be analyzed as "sarcasm", and the context-based fragment in the sample is marked, and the result label of the sample is "sufficient context". The sample with "insufficient context" can be obtained by deleting the context-based fragment of the sample with "sufficient context", so that its context is insufficient to support the determination of the data to be analyzed as "sarcasm", and the result label of the sample is "insufficient context". The sample with "no context required" can perform sarcasm detection from the data to be analyzed without other context, and the result label of the sample is "no context required".
[0042] S13: Design instructions. According to the tasks of this model, design interactive instructions with the big model. For "sufficient context" samples, the instructions should include the text to be analyzed, the sarcastic context, the basis for judging it as sarcastic, and the label result of "sufficient context"; for "insufficient context" samples, the instructions should include the text to be analyzed, the sarcastic context, and the label result of "insufficient context"; for "no context required", the instructions should include the text to be analyzed, the sarcastic context (optional, i.e. set as default), and the label result of "no context required".
[0043] It should be understood that the first detection model may also be configured to only determine whether the context is sufficient or insufficient to obtain other implementations.
[0044] The following is an example of interactive instructions for the context information sufficiency determination model in the field of sarcasm detection. The instruction format of this task should include the instruction interaction format and a few sample examples. The instruction interaction format can constrain the answer format when the large model performs the task, and a small number of sample examples can guide the model to understand the structure and requirements of a specific task.
[0045] Task Description:
[0046] Determine whether the given sarcastic context is sufficient to support the sarcasm in the text being analyzed. For each example, follow these steps:
[0047] 1. Read the text to be analyzed and the ironic context.
[0048] 2. If the ironic context is sufficient to support the irony in the text to be analyzed, please mark the key sentences in the ironic context with square brackets and answer "sufficient".
[0049] 3. If the ironic context is not sufficient to support the irony in the text being analyzed, please answer “Insufficient” or “No context required”.
[0050] 4. In each answer, provide specific basis for your decision.
[0051] "Enough context" sample example:
[0052] -Text to be analyzed: "Today's weather is really nice, suitable for outdoor activities."
[0053] - Sarcasm context: It rained heavily yesterday and it finally cleared up today, but the level 7 gale can blow people away.
[0054] Sample "Not Enough Context" example:
[0055] -Text to be analyzed: "Today's weather is good, suitable for outdoor activities."
[0056] - Sarcasm Context: It rained heavily yesterday.
[0057] "No context needed" example:
[0058] -Text to be analyzed: "On this long trip, I drove for 7 hours and he slept for 7 hours. We both made great efforts."
[0059] -Sarcasm Context: None.
[0060] Interactive commands:
[0061] -Please do the following:
[0062] -Mark key sentences in sarcastic context.
[0063] -Answer "sufficient", "insufficient", "no context required".
[0064] - Provide the basis for judgment.
[0065] Example model response:
[0066] Sample "Enough Context" example response:
[0067] - Sarcasm context sentence fragment marker: [But a force 7 gale can blow people away]
[0068] -Judgment result: Sufficient
[0069] - Judgment basis: The weather in the text to be analyzed is usually used to describe sunny weather suitable for outdoor activities. However, the ironic context points out that although the weather has turned sunny, the existence of a force 7 gale makes outdoor activities dangerous, which is in sharp contrast to "good". Therefore, the "good" in the text is actually a satire that today's weather is not suitable for outdoor activities, and the ironic context is sufficient to support the irony in the text.
[0070] "Insufficient context" response:
[0071] - Sarcasm Context Sentence Snippet Tags: [None]
[0072] -Judgment result: Insufficient
[0073] - Judgment basis: The word "good weather" in the text is used to describe the weather and expresses a positive emotion. Although the context mentions that it rained yesterday, it does not mention today's weather conditions, but this is not enough to constitute a satire of "good weather". The text content does not reflect the opposite of the literal meaning of irony.
[0074] "No context needed" response:
[0075] - Sarcasm Context Sentence Snippet Tags: [None]
[0076] -Judgment result: No context required
[0077] Judgment basis: In this example, the irony is very obvious. Through contrast and exaggeration, it satirizes the inequality between the other party's ease (sleeping) during a long journey and one's own hard work (driving), while also expressing dissatisfaction with this unfair phenomenon.
[0078] S14: Train the model and fine-tune the model using a preset fine-tuning method. For example, fine-tune using LoRA (Low-Rank Adaptation), Prefix Tuning or Prompt Tuning. Preferably, LoRA is used, which simplifies the adaptation process of the pre-trained model by introducing a low-rank matrix. This method achieves adaptation for a specific task by adding additional trainable parameters without changing the parameters of the pre-trained model. LoRA is particularly suitable for fine-tuning under limited resources because it requires less computing resources. Introduce LoRA adaptation layers in the base model. These layers are usually added to the attention mechanism of the model so that only these additional parameters are trained during the fine-tuning process, while the parameters of the pre-trained model remain unchanged. Train the adaptation layer using the prepared data set. Since only the adaptation layer parameters are updated, the training process is usually faster and requires less computing resources. Evaluate the performance of the model on the validation set and adjust the model as needed. Since LoRA takes up less resources, is efficient, and does not change the original model, but only trains a newly added additional parameter, it is preferred to use the LoRA method to fine-tune the model. When LoRA performs model inference, it adds the low-rank matrix and the original attention layer weights to form the LoRA layer (i.e. the adaptation layer mentioned above), and replaces the original attention layer to perform reasoning on specific tasks.
[0079] (2) Second Detection Model
[0080] The second detection model needs to be trained before use, and then the pre-trained second detection model is used to determine whether the context of the text to be analyzed contains sarcastic emotions based on the input text to be analyzed and its sarcastic context information.
[0081] According to an embodiment of the present invention, the second detection model also uses a large model. The large model is still a certain large language model, which is simply abbreviated as a large model only to distinguish it from the aforementioned large language model in terms of literal meaning.
[0082] According to one embodiment of the present invention, a pre-designed interactive instruction is obtained to guide the large model to determine whether the text to be analyzed contains sarcastic emotions, wherein the interactive instruction includes: a guide word, which is used to provide a task description to guide the large model to obtain the task requirements; an example, which is used to provide a reference case to the large model to guide the large model to understand the task requirements; an instruction format, which is used to provide an instruction template, carrying the text to be analyzed and its latest sarcastic context information that needs to be input into the large model, to determine whether the input text to be analyzed contains sarcastic emotions. The embodiment of the present invention also uses the instruction fine-tuning method to fine-tune the large language model to obtain a model for sarcasm detection based on context information. The main process of its fine-tuning is similar to the fine-tuning process of the context information sufficiency judgment model, only when constructing the data set and designing the instructions, different designs are performed according to different tasks. Schematically speaking, it includes:
[0083] Dataset construction: This task is to fine-tune the large model to adapt it to the task of determining whether sarcasm is involved based on the text and context to be analyzed. When constructing the dataset, public datasets or web crawlers and manual annotations are used to obtain sarcastic sentences and their contexts. Positive samples are sentences involving sarcasm and their contexts, and are labeled as "sarcasm"; negative samples are sentences that do not involve sarcasm and their contexts, and are labeled as "non-sarcasm".
[0084] Design instructions. According to the task of this model, design interactive instructions with the big model. For positive samples, the instructions should include the text to be analyzed, the sarcastic context, and the mark judged as sarcastic; for negative samples, the instructions should include the text to be analyzed, the sarcastic context, and the mark judged as non-sarcastic.
[0085] According to an example of the present invention, the present invention also provides an example of interactive instructions for a sarcasm detection model combined with context information. The instruction format of this task should include an instruction interaction format and a few sample examples. The instruction interaction format can constrain the answer format when the large model performs the task, and the few sample examples can guide the model to understand the structure and requirements of a specific task.
[0086] Task Description:
[0087] This task requires the large model to determine whether the text is sarcastic based on the given text to be analyzed and the sarcastic context. Please follow the steps below:
[0088] 1. Carefully read the text to be analyzed and the satirical context.
[0089] 2. Based on the text content and contextual information, determine whether the text contains sarcastic elements.
[0090] 3. Based on the judgment results, give "sarcasm" or "non-sarcasm".
[0091] Instruction format:
[0092] -Text to be analyzed: [Specific text content]
[0093] - Sarcasm context: [describe the satirical background or situation in detail]
[0094] - Determination requirements:
[0095] - If the text is sarcastic, answer "sarcastic".
[0096] - If the text is not sarcastic, answer "Not sarcastic".
[0097] - If you cannot determine, please answer "Cannot determine"
[0098] Example:
[0099] -Text to be analyzed: "Today's weather is really nice, suitable for outdoor activities."
[0100] - Sarcasm context: It rained heavily yesterday and it finally cleared up today, but the level 7 gale can blow people away.
[0101] [Model response]
[0102] - Verdict: Sarcasm
[0103] (3) Contextual Information Retrieval Library
[0104] The context information retrieval library is used to provide supplementary context information for the text to be analyzed.
[0105] According to one embodiment of the present invention, a context information retrieval library includes: a first sub-library and a second sub-library, wherein the first sub-library stores context information in the real context of the text to be analyzed, and the second sub-library stores an external knowledge base based on common sense; according to the context information retrieval library, supplementary context information is obtained from at least one of the first sub-library and the second sub-library. The context information retrieval library can be constructed based on existing data; wherein the context information is divided into two types, the context information in the real context of the text to be analyzed, which is stored in the first sub-library, and the external knowledge based on common sense, which is stored in the second sub-library (also called the external knowledge base based on common sense). For the first sub-library, before use, based on the context information in the real context of the text to be analyzed, the text to be analyzed and its context information are segmented and stored in the first sub-library of the retrieval system, and meta-information attributes that can locate the text to be analyzed are stored, such as its posting time, author, publishing platform and other attribute information. The purpose of storing these meta-information attributes is to filter the context information of the text to be analyzed. Since the context information of multiple texts to be analyzed is stored in the context retrieval information library, the context information of the text to be analyzed can be located through the meta-information attributes. Therefore, these meta-information attributes are determined based on data samples, as long as the context information corresponding to the text to be analyzed can be determined through the meta-information attributes. The system can obtain its context information by querying the text to be analyzed. For the second sub-library, the present invention will cut the text data of the external knowledge base, convert it into a vector, and store it in the vector retrieval library. The system can input the text to be analyzed to obtain semantically similar external knowledge information. For example: the text to be analyzed is calculated for similarity with each external knowledge text pre-stored in the second sub-library, and the external knowledge text is selected as supplementary satirical context information based on the similarity. Among them, it can be selected in order from high to low similarity. In order to avoid selecting external knowledge texts with low similarity, a threshold lower limit value can be set, and it is necessary to select external knowledge texts from external knowledge texts greater than or equal to the threshold lower limit value in order from high to low similarity as supplementary satirical context information.
[0106] According to an embodiment of the present invention, a method for sarcasm detection based on a large language model is provided. Figure 2 ,include:
[0107] S1. Fine-tune a context information sufficiency judgment model for sarcasm detection based on a large language model. The context information sufficiency judgment model is the first detection model.
[0108] S2. Fine-tune a sarcasm detection model based on a large language model and combined with context information, the sarcasm detection model is the second detection model;
[0109] S3, build context information retrieval library;
[0110] S4. Reasoning whether the text to be analyzed involves sarcasm, including using a context information sufficiency judgment model to determine whether the context is sufficient, performing sarcasm detection judgment on sufficient data, retrieving context information on insufficient data, and obtaining more context information to participate in the judgment.
[0111] According to an embodiment of the present invention, a method for detecting sarcasm in text is provided, and its main process is shown in FIG. Figure 3 The reasoning process of the text to be analyzed is shown in the irony identification flowchart, including:
[0112] S41: Obtain the text to be analyzed;
[0113] S42: judging the text to be analyzed according to the context sufficiency judgment model to determine whether the context information is sufficient. If the judgment result is "the context is insufficient", then proceed to S43; if the judgment result is "the context is sufficient" or "no context is required", then proceed to S44;
[0114] S43: searching from the context information retrieval library according to the text to be analyzed and other constraints, and retrieving the context information of the text to be analyzed, wherein if no more context information can be obtained, the determination result is "unable to determine", otherwise the retrieved supplementary context information and the text to be analyzed are retrieved and the process returns to step S42;
[0115] S44: performing sarcasm detection on the provided text to be analyzed and context information according to the sarcasm detection model, determining the text involving sarcasm as “sarcasm”, and determining the text not involving sarcasm as “non-sarcasm”.
[0116] In general, the present invention attempts to organize multi-source heterogeneous context information, determine the adequacy of context information with a simple and unified process, and then perform sarcasm detection. In the process of trying, the large language model has good multi-level semantic understanding ability and retrieval enhancement characteristics, which can be applied to the present invention.
[0117] Large Language Model (LLM) is a natural language processing technology based on deep learning. It learns the expression, semantics, grammar and context of natural language by training a large-scale corpus. It can generate high-quality text content and complete various natural language processing tasks. The characteristics of large language models include (1) a large number of parameters. Large language models usually contain billions to trillions of parameters and can capture the complexity of natural language; (2) strong generalization ability. Pre-trained large language models can be migrated to various downstream natural language tasks, including text generation, question answering, text summarization, etc.; (3) open domain knowledge. Large language models can absorb and integrate a large amount of world knowledge and perform well in answering open questions. (4) customizability. Large language models can be further optimized in specific domains or tasks through fine-tuning.
[0118] The large language model is trained based on massive amounts of text data. It can learn a wide range of semantic and pragmatic rules and can be better generalized to various sarcastic scenarios. The large model uses a deep neural network structure to capture the multi-level semantic information of the text, including vocabulary, sentence structure, context, etc., which helps to identify the sarcasm hidden under the literal meaning. The user combines the text to be analyzed with the prompt template for sarcasm recognition and provides it as input to the large model, which responds with the result of sarcasm detection. Using the trained large language model for end-to-end sarcasm detection is simpler and more convenient to use than training deep learning methods.
[0119] At the same time, external knowledge bases or business data can be easily connected to the large language model to assist the large language model in completing natural language understanding tasks. With this model, in the task of sarcasm identification, the large language model retrieval enhancement component can be used to provide context information, and the large language model can be tuned to determine whether the provided context information is sufficient, and sarcasm identification can be performed on the basis of sufficient context information; if the context information is insufficient, the large language model retrieval enhancement component and the external knowledge base can be used to find relevant context to supplement it, thereby improving the sarcasm detection effect.
[0120] It should be noted that although the above describes the various steps in a specific order, it does not mean that the various steps must be executed in the above specific order. In fact, some of these steps can be executed concurrently or even in a different order as long as the required functions can be achieved.
[0121] The present invention may be a system, a method and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present invention.
[0122] Computer readable storage medium can be a tangible device that holds and stores instructions used by an instruction execution device. Computer readable storage medium can include, for example, but is not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination thereof. More specific examples (non-exhaustive list) of computer readable storage medium include: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, for example, a punch card or a protruding structure in a groove on which instructions are stored, and any suitable combination thereof.
[0123] The embodiments of the present invention have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A method for detecting sarcasm in text, characterized in that: include: Obtaining a text to be analyzed and its ironic context information, wherein the ironic context information refers to context information used to assist in determining whether the text to be analyzed contains ironic emotions; Based on the text to be analyzed and its ironic context information, assess the adequacy of the ironic context information of the text to be analyzed; In the case that the sarcastic context information of the text to be analyzed is insufficient, supplementary context information is provided according to a preset context information retrieval library to obtain updated sarcastic context information; According to the text to be analyzed and its latest sarcastic context information, it is determined whether the text to be analyzed has sarcastic sentiment.
2. The method according to claim 1, characterized in that The results of evaluating the sufficiency of the ironic context information of the text to be analyzed include: sufficient, insufficient, and no context required, and the method further includes: When the sarcastic context information of the text to be analyzed is sufficient, determining whether the text to be analyzed has sarcastic emotions according to the text to be analyzed and its latest sarcastic context information; In the case where no context is needed, whether the text to be analyzed carries a sarcastic sentiment is determined based on the text to be analyzed and its latest sarcastic context information, where the latest sarcastic context information is a default value.
3. The method according to claim 1, characterized in that The process of evaluating the sufficiency of the sarcastic context information of the text to be analyzed includes: According to the text to be analyzed and its ironic context information, the sufficiency of the ironic context information of the text to be analyzed is determined by using a pre-trained first detection model.
4. The method according to claim 3, characterized in that The pre-trained first detection model is trained in the following manner: Obtain a first training set, the training set including multiple samples and their labels, wherein each sample includes a sample text and its sarcastic context, the label space includes at least three categories, namely, categories with sufficient context, insufficient context, and categories without context, and the label indicates the category to which the corresponding sample belongs; The first detection model is trained using the first training set to identify, based on the input sample, whether the corresponding text belongs to a category with sufficient context, insufficient context, or no context required.
5. The method according to claim 3, characterized in that: The pre-trained first detection model is trained in the following manner: Obtain a first detection model, where the first detection model is obtained by adding an adaptation layer to a portion of layers of a trained large language model; Obtain a first training set, the training set including multiple samples and their labels, wherein each sample includes a sample text and its sarcastic context, the label space includes at least three categories, namely, categories with sufficient context, insufficient context, and categories without context, and the label indicates the category to which the corresponding sample belongs; The first detection model is trained using the first training set to identify, based on the input sample, whether the corresponding text belongs to a category with sufficient context, insufficient context, or no context required, and only the parameters of the adaptation layer are updated during training.
6. The method according to claim 1, characterized in that The process of determining whether the text to be analyzed has a sarcastic sentiment includes: According to the text to be analyzed and its latest sarcastic context information, a second detection model is used to determine whether the text to be analyzed has sarcastic emotions. If so, the text to be analyzed is classified as sarcastic; if not, it is classified as non-sarcastic, wherein the second detection model is a large model.
7. The method according to claim 6, characterized in that The process of determining whether the text to be analyzed has a sarcastic sentiment includes: Obtain pre-designed interactive instructions to guide the large model to determine whether the text to be analyzed contains sarcastic emotions, wherein the interactive instructions include: Guide words are used to provide task descriptions to guide the large model to obtain task requirements; Examples are used to provide reference cases for the large model to guide the large model to understand the task requirements; The instruction format is used to provide an instruction template, carrying the text to be analyzed and its latest sarcastic context information that needs to be input into the large model, so as to determine whether the input text to be analyzed has sarcastic emotions.
8. The method according to any one of claims 1 to 6, characterized in that: The method further comprises: Constructing a context information retrieval library, which includes: a first sub-library and a second sub-library, wherein the first sub-library stores context information in the real context of the text to be analyzed, and the second sub-library stores an external knowledge base based on common sense; According to the context information retrieval library, supplementary context information is obtained from at least one of the first sub-library and the second sub-library.
9. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and the computer program can be executed by a processor to implement the steps of the method according to any one of claims 1 to 8.
10. An electronic device, characterized in that: include: one or more processors; as well as A memory, wherein the memory is used to store executable instructions; The one or more processors are configured to implement the steps of the method of any one of claims 1-8 by executing the executable instructions.