Text detection method and device, electronic equipment and computer readable storage medium

By generating logically consistent reconstructed text and calculating similarity, the problem of low accuracy in sarcasm detection in existing technologies is solved, and efficient sarcasm text detection is achieved.

CN115204181BActive Publication Date: 2026-04-17HARBIN INST OF TECH SHENZHEN GRADUATE SCHOOL
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HARBIN INST OF TECH SHENZHEN GRADUATE SCHOOL
Filing Date
2022-07-22
Publication Date
2026-04-17

AI Technical Summary

Technical Problem

In existing technologies, satirical detection models rely on large amounts of labeled data and complex deep learning networks, resulting in low accuracy when detecting satirical text on social platforms and making them difficult to apply to real-world scenarios.

Method used

By masking positive and negative sentiment words in the text to be detected, a masked text is generated. Then, a text generation model is used to predict sentiment words, generating a logically consistent reconstructed text. The similarity between the reconstructed text and the original text is calculated to determine the satirical text.

Benefits of technology

It improves the accuracy of satirical text detection, saves data annotation work, realizes unsupervised satirical detection, and can be applied to real-world scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115204181B_ABST
    Figure CN115204181B_ABST
Patent Text Reader

Abstract

This application discloses a text detection method, apparatus, electronic device, and computer-readable storage medium. The text detection method includes: acquiring a text to be detected; masking each positive sentiment word in the text to be detected to obtain a first masked text; and masking each negative sentiment word in the text to be detected to obtain a second masked text; predicting the masked positive sentiment words in the first masked text to generate a first reconstructed text; and predicting the masked negative sentiment words in the second masked text to generate a second reconstructed text; determining a first similarity between the first reconstructed text and the text to be detected, and a second similarity between the second reconstructed text and the text to be detected; and determining the text to be detected as satirical text in response to the first similarity and / or the second similarity being less than a set threshold. This application not only improves the detection accuracy of satirical text but also saves a significant amount of data annotation work, achieving unsupervised satirical detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of natural language processing, and in particular to text detection methods, apparatus, electronic devices, and computer-readable storage media. Background Technology

[0002] With the rapid development of internet technology, people often use positive or positive-reinforcing words to express their sarcastic sentiments on social media. When text contains satirical content, it reverses the emotional polarity of the sentence, changing the actual implied emotion.

[0003] In existing technologies, irony detection methods mainly rely on a large amount of labeled data to model complex feature representations. Constructing contextual information requires the design and implementation of complex feature extraction, and the established models also require a large amount of labeled data and complex deep learning networks.

[0004] However, the heavy workload of data annotation and the complexity of model building make it difficult to apply satirical detection models to real-world scenarios. As a result, current detection methods are prone to making significant errors in identifying satirical texts appearing on social media platforms. The detection models have low accuracy in detecting satirical texts and are unable to meet detection requirements. Summary of the Invention

[0005] The main technical problem addressed by this application is to provide a text detection method, apparatus, electronic device, and computer-readable storage medium that can solve the problem that existing technologies cannot effectively detect satirical text.

[0006] To address the aforementioned technical problems, the first technical solution adopted in this application is to provide a text detection method, comprising: acquiring a text to be detected; masking each positive sentiment word in the text to be detected to obtain a first masked text; and masking each negative sentiment word in the text to be detected to obtain a second masked text; predicting the masked positive sentiment words in the first masked text to generate a first reconstructed text; and predicting the masked negative sentiment words in the second masked text to generate a second reconstructed text; determining a first similarity between the first reconstructed text and the text to be detected, and a second similarity between the second reconstructed text and the text to be detected; and determining that the text to be detected is satirical text in response to the first similarity and / or the second similarity being less than a set threshold.

[0007] The step of obtaining the text to be detected includes: performing part-of-speech tagging on each character in the text to be detected; masking each positive sentiment word in the text to be detected to obtain a first masked text; and masking each negative sentiment word in the text to be detected to obtain a second masked text, which includes: identifying each sentiment word from the labeled text to be detected, classifying the sentiment word as a positive sentiment word or a negative sentiment word based on the polarity of the sentiment word; identifying each verb and / or each noun that is not a sentiment word from the labeled text to be detected, and determining the verb and / or the noun as constituent words; using masking characters to cover the positive sentiment words and at least some constituent words in the text to be detected to generate the first masked text; and using masking characters to cover the negative sentiment words and the same constituent words in the text to be detected to generate the second masked text.

[0008] The process includes identifying each sentiment word from the labeled text to be tested, and classifying sentiment words into positive or negative sentiment words based on their polarity. This includes: using an external sentiment resource lexicon to identify each sentiment word as a positive or negative sentiment word from the labeled text to be tested, and assigning it to the corresponding positive or negative sentiment word set; and identifying each verb and / or noun that is not a sentiment word from the labeled text to be tested, and determining the verbs and / or nouns as constituent words. This includes: using natural language processing tools to obtain the grammatical information of the text to be tested; and based on the grammatical information, identifying each verb and / or noun that is not a sentiment word from the labeled text to be tested. The steps include: using masking characters to mask all characters included in the positive sentiment word set and one of its subsets to generate the first masked text; and using masking characters to mask all characters included in the negative sentiment word set and the same subsets to generate the second masked text.

[0009] The steps of predicting masked positive sentiment words in the first masked text to generate a first reconstructed text and predicting masked negative sentiment words in the second masked text to generate a second reconstructed text include: obtaining word embedding vectors for the first masked text and the second masked text respectively; wherein the word embedding vectors include character vectors and position vectors; concatenating the word embedding vectors corresponding to the first masked text and the second masked text respectively to obtain a first hidden sequence and a second hidden sequence with contextual features; and predicting each masked sentiment word and each constituent word in the first hidden sequence and the second hidden sequence respectively to obtain the first reconstructed text and the second reconstructed text.

[0010] The first and second reconstructed texts are generated through a text generation model, which includes a cascaded encoder, attention network, and decoder. The steps for obtaining the word embedding vectors of the first and second masked texts include: using the encoder of the text generation model to obtain the word embedding vectors of the first and second masked texts respectively; concatenating the word embedding vectors of the first and second masked texts to obtain a first hidden sequence and a second hidden sequence with contextual features, including: using the encoder to encode the word embedding vectors of the first and second masked texts respectively to obtain a first hidden sequence and a second hidden sequence with contextual features; and predicting each masked sentiment word and each component word in the first and second hidden sequences to obtain the first and second reconstructed texts, including: using the attention network and decoder in the text generation model to sequentially decode the first and second hidden sequences to predict each masked sentiment word and each component word, and outputting the first and second reconstructed texts.

[0011] The attention network includes a self-attention mechanism. The steps of using the attention network and decoder in the text generation model to sequentially decode the first hidden sequence and the second hidden sequence to predict each masked sentiment word and each component word, and outputting the first reconstructed text and the second reconstructed text, include: using the self-attention mechanism and decoder to sequentially perform autoregressive decoding on the first hidden sequence and the second hidden sequence to predict each masked sentiment word and each component word based on each time step, and outputting the first reconstructed text and the second reconstructed text.

[0012] The steps of determining the first similarity between the first reconstructed text and the text to be detected, and the second similarity between the second reconstructed text and the text to be detected, include: obtaining the word embedding vectors of the text to be detected, the first reconstructed text, and the second reconstructed text, respectively; concatenating the word embedding vectors corresponding to the text to be detected, the first reconstructed text, and the second reconstructed text, respectively, to obtain a text sequence to be detected, a first text sequence, and a second text sequence with contextual features; calculating the similarity between the text sequence to be detected and the first text sequence using at least one similarity algorithm to obtain the first similarity; and calculating the similarity between the text sequence to be detected and the second text sequence using a similarity algorithm to obtain the second similarity.

[0013] To address the aforementioned technical problems, the second technical solution adopted in this application is to provide a text detection device, comprising: an acquisition module for acquiring a text to be detected; a masking module for masking each positive sentiment word in the text to be detected to obtain a first masked text; and masking each negative sentiment word in the text to be detected to obtain a second masked text; a reconstructed text generation module for predicting the masked positive sentiment words in the first masked text to generate a first reconstructed text; and predicting the masked negative sentiment words in the second masked text to generate a second reconstructed text; a similarity calculation module for determining a first similarity between the first reconstructed text and the text to be detected, and a second similarity between the second reconstructed text and the text to be detected; and a determination module for determining that the text to be detected is satirical text in response to the first similarity and / or the second similarity being less than a set threshold.

[0014] To solve the above-mentioned technical problems, the third technical solution adopted in this application is to provide an electronic device, including: a memory for storing program data, wherein the program data, when executed, implements the steps in the text detection method described above; and a processor for executing the program data stored in the memory to implement the steps in the text detection method described above.

[0015] To solve the above-mentioned technical problems, the fourth technical solution adopted in this application is to provide a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a processor, it implements the steps in the text detection method described above.

[0016] The beneficial effects of this application are as follows: Unlike existing technologies, this application provides a text detection method, apparatus, electronic device, and computer-readable storage medium. By respectively masking positive and negative sentiment words in the text to be detected, it can generate a first masked text and a second masked text. Then, based on the masked positive and negative sentiment words, it predicts the first and second masked texts respectively, generating a first and second reconstructed text with consistent sentiment and semantics, following the logic of the unmasked text, thus maintaining consistency between contexts. Furthermore, by calculating the similarity between the text to be detected and the reconstructed text, and based on the matching degree between the similarity and a set threshold, it can determine whether the text to be detected is satirical. Through the above method, this application not only achieves better contextual satire detection and improves the detection accuracy of satirical text, but also saves a significant amount of data annotation work, realizing unsupervised satire detection, and thus can be applied to real-world scenarios to meet detection needs. Attached Figure Description

[0017] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0018] Figure 1 This is a flowchart illustrating the first embodiment of the text detection method of this application;

[0019] Figure 2 This is a flowchart illustrating the second embodiment of the text detection method of this application;

[0020] Figure 3 This is a flowchart illustrating the workflow of an application scenario in this application involving masking the text to be detected.

[0021] Figure 4 This is a flowchart illustrating the third embodiment of the text detection method of this application;

[0022] Figure 5 This is a flowchart illustrating the workflow of a scenario in which the masked text is reconstructed according to this application.

[0023] Figure 6 This is a flowchart illustrating the fourth embodiment of the text detection method of this application;

[0024] Figure 7 This is a flowchart illustrating the application scenario of the text detection method of this application;

[0025] Figure 8 This is a schematic diagram of one embodiment of the text detection device of this application;

[0026] Figure 9 This is a schematic diagram of the structure of one embodiment of the electronic device of this application;

[0027] Figure 10 This is a schematic diagram of a computer-readable storage medium according to an embodiment of the present invention. Detailed Implementation

[0028] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0029] The terminology used in the embodiments of this application is for the purpose of describing particular embodiments only and is not intended to limit the application. The singular forms “a,” “said,” and “the” used in the embodiments of this application and the appended claims are also intended to include the plural forms, unless otherwise clearly indicated above. “Multiple” generally includes at least two, but does not exclude the inclusion of at least one.

[0030] It should be understood that the term "and / or" used in this article is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, the character " / " in this article generally indicates that the preceding and following related objects have an "or" relationship.

[0031] It should be understood that the terms "comprising," "including," or any other variations used herein are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0032] Please see Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the text detection method of this application. In this embodiment, the text detection method includes:

[0033] S11: Obtain the text to be detected.

[0034] In this embodiment, the text to be detected is a comment posted by a user on the Internet regarding specific content under a certain topic, such as medical topics or education topics.

[0035] One method is to obtain a large amount of user comments from social media through web scraping as the text to be tested.

[0036] The text to be detected typically includes multiple words or phrases.

[0037] S12: Mask each positive sentiment word in the text to be detected to obtain the first masked text; and mask each negative sentiment word in the text to be detected to obtain the second masked text.

[0038] Among them, emotional words are words with emotional polarity, specifically adjectives, nouns, and verbs that express or involve emotions, such as "happy", "like", "respect", "sad", "crying", etc.

[0039] Positive words (PWs) are words that express positive emotions, such as "happy," "like," and "respect," and usually convey positive and affirmative emotions.

[0040] Among them, negative words (NW) are words that express negative emotions, such as "sad" and "crying," and the emotions they convey are usually negative.

[0041] S13: Predict the masked positive sentiment words in the first masked text to generate the first reconstructed text; and predict the masked negative sentiment words in the second masked text to generate the second reconstructed text.

[0042] In this embodiment, by predicting the positive sentiment words that are masked in the first masked text, a first reconstructed text with positive sentiment and semantic consistency can be generated based on the logic of the unmasked text in the text to be detected; by predicting the negative sentiment words that are masked in the second masked text, a second reconstructed text with negative sentiment and semantic consistency can be generated based on the logic of the unmasked text in the text to be detected, thereby maintaining consistency between contexts.

[0043] S14: Determine the first similarity between the first reconstructed text and the text to be detected, and the second similarity between the second reconstructed text and the text to be detected.

[0044] In this embodiment, any one of the following similarity algorithms can be used to determine the first similarity between the first reconstructed text and the text to be detected, and the second similarity between the second reconstructed text and the text to be detected. This application does not limit the specific algorithm used.

[0045] S15: In response to the first similarity and / or the second similarity being less than a set threshold, determine that the text to be detected is satirical text.

[0046] Understandably, if the text to be detected is not satirical and there is no discrepancy between the sentiment and semantics of its context, then the first and second reconstructed texts generated by prediction will have high similarity to the text to be detected, and consequently, both the first and second similarity scores will be relatively high.

[0047] Conversely, if the text to be detected is satirical, there will be discrepancies in the sentiment and semantics of its context. In this case, at least one of the first and second reconstructed texts generated by prediction will differ significantly from the text to be detected, resulting in the first similarity and / or the second similarity being less than the set threshold.

[0048] In a specific implementation scenario, the text to be detected is "Education, healthcare, and elderly care are the sources of happiness for modern young people; they're so happy they can hardly breathe." Here, "happiness" is a positive sentiment word, while "unable to breathe" is a negative sentiment word, indicating a difference in sentiment and semantics between "happiness" and "unable to breathe." If "happiness" is masked, and prediction is made based on the unmasked text "unable to breathe," it will generally generate "pain," meaning the first reconstructed text would be "so painful they can hardly breathe." Since the first reconstructed text differs significantly from the text to be detected, the first similarity will inevitably be less than the set threshold, thus determining the text to be detected as satirical.

[0049] Unlike existing technologies, this implementation generates a first masked text and a second masked text by separately masking positive and negative sentiment words in the text to be detected. Then, based on the masked positive and negative sentiment words, predictions are made for the first and second masked texts, respectively. This allows for the generation of a first reconstructed text and a second reconstructed text with consistent sentiment and semantics, following the logic of the unmasked text, thus maintaining contextual consistency. Furthermore, by calculating the similarity between the text to be detected and the reconstructed text, and based on the matching degree between the similarity and a set threshold, it is possible to determine whether the text to be detected is satirical. Through the above method, this implementation not only achieves better contextual satire detection and improves the accuracy of satirical text detection, but also saves a significant amount of data annotation work, realizing unsupervised satire detection, and thus can be applied to real-world scenarios to meet detection requirements.

[0050] Please see Figure 2 , Figure 2 This is a flowchart illustrating the second embodiment of the text detection method of this application. In this embodiment, the text detection method includes:

[0051] S21: Obtain the text to be detected and perform part-of-speech tagging on each character in the text to be detected.

[0052] In this embodiment, natural language processing tools are used to perform part-of-speech tagging and classification on each character in the input text to be detected.

[0053] Specifically, parts of speech can generally be divided into ten categories: nouns, pronouns, verbs, adjectives, measure words, adverbs, prepositions, conjunctions, articles, and interjections. Among them, the first six are content words, and the last four are function words.

[0054] S22: Identify each sentiment word from the labeled text to be detected, and classify the sentiment words into positive sentiment words or negative sentiment words based on their polarity; and identify each verb and / or each noun that is not a sentiment word from the labeled text to be detected, and determine the verbs and / or the nouns as constituent words.

[0055] In this embodiment, an external sentiment resource lexicon is used to identify each sentiment word as a positive or negative sentiment word from the labeled text to be detected, and then classifies it into the corresponding positive or negative sentiment word set.

[0056] The set of positive sentiment words is represented as PW = {pw1, pw2, ..., pw...} h}, representing negative sentiment words as NW={nw1, nw2, ..., nw h}

[0057] Among them, the external emotional resource vocabulary library is any resource library with emotional polarity labels.

[0058] In one specific implementation scenario, the external sentiment resource vocabulary is the SenticNet dictionary. In another specific implementation scenario, the external sentiment resource vocabulary is the HowNet dictionary; this application does not limit itself to this specific implementation.

[0059] In this embodiment, natural language processing tools are used to obtain the grammatical information of the text to be detected, and based on the grammatical information, each verb and / or noun that is not sentimental word is identified from the labeled text to be detected, and the verbs and / or nouns are identified as constituent words.

[0060] Among these, the natural language processing tools include Spacy. Spacy is the world's fastest industrial-grade natural language processing tool, supporting a variety of basic natural language processing functions, including word segmentation, part-of-speech tagging, stemming, named entity recognition, and noun phrase extraction.

[0061] Sentence components are generally an important part of a sentence. Besides verbs and nouns (non-emotional words), they also include adjectives (non-emotional words). However, sentence components do not include prepositions, conjunctions, articles, interjections, or other function words, nor do they include pronouns, measure words, or nouns such as personal names or place names.

[0062] In a specific implementation scenario, if the text to be detected is "I like watching football matches, and the results are always as expected", then after removing the sentiment word "like", the identified constituent words include {football, match, result, expected}.

[0063] In this embodiment, each constituent word is further divided into a constituent word set, and the constituent word set is divided into at least two subsets. The constituent word set is represented as SW = {sw1, sw2, ..., sw...} m}, representing the subsets as SW1, SW2, ..., SW n .

[0064] In a specific implementation scenario, the constituent word set SW is divided into two subsets, SW1 and SW2, with the number of constituent words in SW1 and SW2 being approximately equal. To ensure contextual coherence, the constituent words in each sentence of the text to be detected can be evenly distributed between the two subsets. For example, if a sentence contains 8 constituent words, 4 of them are assigned to SW1, and the remaining 4 are assigned to SW2.

[0065] Here, we take the text to be detected, “I like watching football matches, and the result is always as expected,” as an example. The word set of this text is SW = {football, match, result, expected}. We can divide “football” in the first sentence and “result” in the second sentence into SW1, and divide “match” in the first sentence and “expected” in the second sentence into SW2.

[0066] S23: Use masking characters to cover up positive sentiment words and at least some component words in the text to be detected, and generate a first masked text; and use masking characters to cover up negative sentiment words and the same component words in the text to be detected, and generate a second masked text.

[0067] In this embodiment, mask characters are used to cover all characters in the positive sentiment word set and one subset thereof to generate a first masked text. Similarly, mask characters are used to cover all characters in the negative sentiment word set and the same subset to generate a second masked text.

[0068] In a specific implementation scenario, mask characters are used to cover up the positive sentiment word set and all characters included in SW1 to generate the first masked text. Similarly, mask characters are used to cover up the negative sentiment word set and all characters included in SW1 to generate the second masked text.

[0069] In another specific implementation scenario, mask characters can be used to cover up the positive sentiment word set and all characters included in SW2 to generate the first masked text. Similarly, mask characters can be used to cover up the negative sentiment word set and all characters included in SW2 to generate the second masked text.

[0070] This example uses the text to be detected as "I like watching football matches, and the results are always as expected." The sentiment word is "like," and the word set SW = {football, match, result, expected}, SW1 = {football, result}, and SW2 = {match, expected}. After masking all characters in the positive sentiment word set and SW1, the first masked text is "I [MASK] watch [MASK] matches, and [MASK] is always as expected."

[0071] Understandably, constituent words are generally an important part of a sentence. If the constituent word set is not divided and all constituent words in the set are covered, too much information is lost from the text. The uncovered text contains too little information to guarantee sufficient logic for subsequent predictions. This implementation divides the constituent word set into multiple subsets and covers only the constituent words in a portion of these subsets, ensuring that the uncovered text still retains sufficient logic.

[0072] Please see Figure 3 , Figure 3 This is a flowchart illustrating an application scenario of masking the text to be detected, as described in this application. In this embodiment, after obtaining the text to be detected, each character in the input text is first tagged and classified using natural language processing tools. Next, each sentiment word is identified and classified from the tagged text using an external sentiment resource lexicon, and constituent words are obtained using natural language processing tools. Then, positive sentiment words and at least some constituent words in the text to be detected are masked using masking characters to generate a first masked text m1, and negative sentiment words and the same constituent words in the text to be detected are masked using masking characters to generate a second masked text m2.

[0073] S24: Predict the masked positive sentiment words in the first masked text to generate the first reconstructed text; and predict the masked negative sentiment words in the second masked text to generate the second reconstructed text.

[0074] Please refer to the description in S13 for the specific process, which will not be repeated here.

[0075] S25: Determine the first similarity between the first reconstructed text and the text to be detected, and the second similarity between the second reconstructed text and the text to be detected.

[0076] Please refer to the description in S14 for the specific process, which will not be repeated here.

[0077] S26: In response to the first similarity and / or the second similarity being less than a set threshold, determine that the text to be detected is satirical text.

[0078] Please refer to the description in S15 for the specific process, which will not be repeated here.

[0079] In existing technologies, accurately obtaining emotional polarity words and key component words within a sentence is quite difficult and requires a lot of manpower.

[0080] Unlike existing technologies, this implementation uses external sentiment resource vocabulary and natural language processing tools to approximate the sentiment words and main component words in a sentence, which can avoid the annotation of sentiment words and component words, thus saving a lot of manpower.

[0081] Please see Figure 4 , Figure 4 This is a flowchart illustrating the third embodiment of the text detection method of this application. In this embodiment, the first reconstructed text and the second reconstructed text are generated through a text generation model. The text generation model includes a cascaded encoder, an attention network, and a decoder. The attention network includes a self-attention mechanism. The text detection method includes:

[0082] S41: Obtain the text to be detected.

[0083] Please refer to the description in S11 for the specific process, which will not be repeated here.

[0084] S42: Mask each positive sentiment word in the text to be detected to obtain the first masked text; and mask each negative sentiment word in the text to be detected to obtain the second masked text.

[0085] For details, please refer to the descriptions in S12 or S21 to S23, which will not be repeated here.

[0086] S43: Obtain the word embedding vectors of the first masked text and the second masked text respectively; wherein, the word embedding vector includes character vectors and position vectors.

[0087] In this embodiment, the Transformer encoder of the text generation model is used to obtain the word embedding vectors of the first masked text and the second masked text, respectively.

[0088] The Transformer encoder is a sequence modeling model composed of a self-attention mechanism and a feedforward neural network.

[0089] The Transformer encoder processes the text to be detected into a text sequence X = {x1, x2, ..., x...}. n After that, the embedding mapping function is used to map the text sequence X = {x1, x2, ..., x}. n} is processed into word embedding vectors = {e1, e2, ..., e n}. Wherein, each word embedding vector e i It is formed by adding the corresponding character vector and position vector.

[0090] S44: Concatenate the word embedding vectors corresponding to the first masked text and the second masked text respectively to obtain the first hidden sequence and the second hidden sequence with contextual features.

[0091] In this embodiment, the Transformer encoder is used to encode the word embedding vectors corresponding to the first masked text and the second masked text respectively, so as to obtain the first hidden sequence and the second hidden sequence with context features.

[0092] Specifically, the Transformer encoder uses a context mapping function based on the position vector to encode the word embedding vectors corresponding to the first masked text and the second masked text respectively, so as to obtain the first hidden sequence and the second hidden sequence with context features.

[0093] The context mapping function is implemented using a multi-layered stacked neural network.

[0094] The first hidden sequence is represented as h1 = {h1, h2, ..., h...} n The second hidden sequence is represented as h2 = {h1, h2, ..., h}. m}

[0095] In this context, both the first hidden sequence and the second hidden sequence are semantic representation vectors. They are called hidden sequences because they contain mask characters.

[0096] S45: Predict each sentiment word and each constituent word that is masked in the first hidden sequence and the second hidden sequence respectively to obtain the first reconstructed text and the second reconstructed text.

[0097] In this embodiment, the attention network and decoder in the text generation model are used to decode the first hidden sequence and the second hidden sequence in sequence to predict each sentiment word and each constituent word that is masked, and output the first reconstructed text and the second reconstructed text.

[0098] Specifically, the self-attention mechanism and the Transformer decoder are used to perform autoregressive decoding on the first hidden sequence and the second hidden sequence in sequence, so as to predict each masked sentiment word and each component word based on each time step, and output the first reconstructed text and the second reconstructed text.

[0099] Specifically, after obtaining h1 = {h1, h2, ..., h...} n} and h2={h1,h2,…,h m After that, the Transformer decoder receives the hidden state and uses the decoding mapping function to continuously predict the next mask character w. i For each corresponding character, one output character can be predicted at each time step. Until the terminator is generated <eos>Then, the first and second reconstructed texts are output. Where h... i This refers to either the first hidden sequence h1 or the second hidden sequence h2.

[0100] In this embodiment, in order to ensure that the text generation model can generate sentences with consistent sentiment and semantics after following the logical structure of the masked text, the parameters of the pre-trained generative language model are used to initialize the Transformer encoder and Transformer decoder.

[0101] In one specific implementation scenario, the parameters of the BERT model can be used to initialize the Transformer encoder and decoder. In another specific implementation scenario, the parameters of the GPT-2 model can be used to initialize the Transformer encoder and decoder.

[0102] Please see Figure 5 , Figure 5 This is a flowchart illustrating an application scenario of the masked text reconstruction operation in this application. In this embodiment, after obtaining the first masked text m1 and the second masked text m2, the Transformer encoder is first used to process the text to be detected into a text sequence X = {x1, x2, ..., x...}. n Then, the embedding mapping function is used to map the text sequence X = {x1, x2, ..., x...} n } is processed into word embedding vectors = {e1, e2, ..., e n Then, based on the position vectors, the word embedding vectors corresponding to the first masked text m1 and the second masked text m2 are encoded using a context mapping function to obtain the first hidden sequence h1 and the second hidden sequence h2 with context features. Finally, the Transformer decoder is used to perform autoregressive decoding on the first hidden sequence h1 and the second hidden sequence h2 in sequence to predict each masked sentiment word and each component word at each time step, and output the first reconstructed text and the second reconstructed text.

[0103] S46: Determine the first similarity between the first reconstructed text and the text to be detected, and the second similarity between the second reconstructed text and the text to be detected.

[0104] Please refer to the description in S14 for the specific process, which will not be repeated here.

[0105] S47: In response to the first similarity and / or the second similarity being less than a set threshold, determine that the text to be detected is satirical text.

[0106] Please refer to the description in S15 for the specific process, which will not be repeated here.

[0107] Using the above method, this implementation can input the masked text into a pre-trained text generation model, so that the text generation model can generate sentences with consistent emotion and semantics by following the logical structure of the unmasked text.

[0108] Please see Figure 6 , Figure 6 This is a flowchart illustrating the fourth embodiment of the text detection method of this application. In this embodiment, the text to be detected is processed using a satire detection model, which is a finely tuned pre-trained language model. The text detection method includes:

[0109] S61: Obtain the text to be detected.

[0110] Please refer to the description in S11 for the specific process, which will not be repeated here.

[0111] S62: Mask each positive sentiment word in the text to be detected to obtain the first masked text; and mask each negative sentiment word in the text to be detected to obtain the second masked text.

[0112] For details, please refer to the descriptions in S12 or S21 to S23, which will not be repeated here.

[0113] S63: Predict the masked positive sentiment words in the first masked text to generate the first reconstructed text; and predict the masked negative sentiment words in the second masked text to generate the second reconstructed text.

[0114] For details, please refer to the descriptions in S13 or S43 to S45, which will not be repeated here.

[0115] S64: Obtain the word embedding vectors of the text to be detected, the first reconstructed text, and the second reconstructed text, respectively.

[0116] In this embodiment, the Transformer encoder in the irony detection model is used to obtain the word embedding vectors of the text to be detected, the first reconstructed text, and the second reconstructed text, respectively. The process of obtaining the word embedding vectors is described in detail in S43, and will not be repeated here.

[0117] S65: Concatenate the word embedding vectors corresponding to the text to be detected, the first reconstructed text, and the second reconstructed text respectively to obtain the text sequence to be detected, the first text sequence, and the second text sequence with contextual features.

[0118] In this embodiment, the Transformer encoder in the irony detection model is used to concatenate the word embedding vectors corresponding to the text to be detected, the first reconstructed text, and the second reconstructed text, respectively, to obtain a text sequence to be detected, a first text sequence, and a second text sequence with contextual features. The specific process is described in S44 and will not be repeated here.

[0119] S66: Calculate the similarity between the text sequence to be detected and the first text sequence using at least one similarity algorithm to obtain a first similarity; and calculate the similarity between the text sequence to be detected and the second text sequence using a similarity algorithm to obtain a second similarity.

[0120] In a specific implementation scenario, cosine similarity is used to calculate the similarity between the text sequence to be detected and the first text sequence to obtain the first similarity. Similarly, cosine similarity is used to calculate the similarity between the text sequence to be detected and the second text sequence to obtain the second similarity.

[0121] Cosine similarity, also known as cosine similarity, assesses the similarity between two vectors by calculating the cosine of the angle between them. The closer the value is to 1, the closer the angle is to 0°, meaning the two vectors are more similar, and this is called cosine similarity.

[0122] S67: In response to the first similarity and / or the second similarity being less than a set threshold, determine that the text to be detected is satirical text.

[0123] In this embodiment, the first similarity and the second similarity are compared with a set threshold, and the detection text is determined to be satirical text based on the two comparison results.

[0124] Specifically, the following detection formula is used to determine whether the text to be detected is satirical:

[0125] diff = conine(h x ,h ma )>threshold||conine(h x ,h mb )>threshold

[0126] y = I(diff)(1)

[0127] Where y = I(diff) indicates that the output text to be detected is satirical text, diff is satirical text, and conine(h) x ,h ma ) represents the first similarity, conine(h) x ,h mb ) represents the second similarity, threshold is the set threshold, and || represents the "OR" logic.

[0128] The threshold value can be any value less than 1 but not less than 0.5. In one specific implementation scenario, the threshold value can be 0.5. In another specific implementation scenario, the threshold value can be 0.8, and this application does not limit it.

[0129] Understandably, if the text to be detected is not satirical and there is no discrepancy between the sentiment and semantics of its context, then the first and second reconstructed texts generated by prediction will have high similarity to the text to be detected, and consequently, both the first and second similarity scores will be relatively high.

[0130] Conversely, if the text to be detected is satirical, there will be discrepancies in the sentiment and semantics of its context. In this case, at least one of the first and second reconstructed texts generated by prediction will differ significantly from the text to be detected, resulting in the first similarity and / or the second similarity being less than the set threshold.

[0131] In this implementation, the sarcasm detection model is the BERT model to obtain better sentence representation vectors. To further improve the quality of sentence representation, a contrastive learning algorithm is used to fine-tune BERT on an unlabeled dataset. The contrastive learning algorithm includes SimCSE.

[0132] Please see Figure 7 , Figure 7 This is a flowchart illustrating the application scenario of the text detection method of this application. In this embodiment, after obtaining the text to be detected, each character in the input text is first tagged and classified using natural language processing tools. Next, each sentiment word is identified and classified from the tagged text using an external sentiment resource lexicon, and constituent words are obtained using natural language processing tools. Then, positive sentiment words and at least some constituent words in the text to be detected are masked using masking characters to generate a first masked text m1, and negative sentiment words and the same constituent words in the text to be detected are masked using masking characters to generate a second masked text m2. Finally, the first masked text m1 and the second masked text m2 are input into a text generation model, which outputs a first reconstructed text and a second reconstructed text. The text to be detected, the first reconstructed text, and the second reconstructed text are then input into the irony detection model. The irony detection model transforms the text to be detected, the first reconstructed text, and the second reconstructed text into a text sequence to be detected, a first text sequence, and a second text sequence with contextual features. Cosine similarity is used to calculate the similarity between the text sequence to be detected and the first text sequence and the second text sequence, respectively, to obtain the first similarity and the second similarity. The detection formula is used to judge the first similarity and the second similarity, and based on the judgment result, it is determined whether the text to be detected is ironic text.

[0133] By employing the above method, this implementation can generate a first reconstructed text and a second reconstructed text that are consistent in sentiment and semantics, following the logic of the unmasked text, in order to maintain the consistency between contexts. Then, based on the similarity between the text to be detected and the first and second reconstructed texts, it can determine whether the text to be detected is satirical text. This not only achieves better contextual satire detection and improves the detection accuracy of satirical text, but also saves a lot of data annotation work, realizing unsupervised satire detection. Therefore, it can be applied to real-world scenarios to meet detection requirements.

[0134] The text detection method of this embodiment can be applied to social media text analysis systems, with its main application scenarios including Weibo satire detection systems and social sentiment analysis systems. By introducing the text detection method of this embodiment, Weibo satire detection systems can more accurately detect satire based on deep semantic consistency. In social sentiment analysis systems, the text detection method of this embodiment can be used as a sub-module to achieve better contextual satire detection, thereby improving the accuracy of satirical text detection.

[0135] Correspondingly, this application provides a text detection device.

[0136] Please see Figure 8 , Figure 8 This is a schematic diagram of one embodiment of the text detection device of this application. Figure 8 As shown, the text detection device 80 includes an acquisition module 81, a mask module 82, a reconstructed text generation module 83, a similarity calculation module 84, and a determination module 85.

[0137] The acquisition module 81 is used to acquire the text to be detected.

[0138] The masking module 82 is used to mask each positive sentiment word in the text to be detected to obtain the first masked text; and to mask each negative sentiment word in the text to be detected to obtain the second masked text.

[0139] The reconstructed text generation module 83 is used to predict the masked positive sentiment words in the first masked text to generate the first reconstructed text; and to predict the masked negative sentiment words in the second masked text to generate the second reconstructed text.

[0140] The similarity calculation module 84 is used to determine the first similarity between the first reconstructed text and the text to be detected, and the second similarity between the second reconstructed text and the text to be detected.

[0141] The determination module 85 is used to determine the text to be detected as satirical text in response to a first similarity and / or a second similarity being less than a set threshold.

[0142] For details of the process, please refer to the relevant textual descriptions in S11-S15, S21-S26, and S41-S47, which will not be repeated here.

[0143] Unlike existing technologies, this implementation uses a masking module 82 to mask positive and negative sentiment words in the text to be detected, generating a first masked text and a second masked text. Then, based on the masked positive and negative sentiment words, predictions are made for the first and second masked texts respectively. Following the logic of the unmasked text, the text reconstruction module 83 generates first and second reconstructed texts with consistent sentiment and semantics, thus maintaining contextual consistency. Furthermore, a similarity calculation module 84 calculates the similarity between the text to be detected and the reconstructed text. Based on the matching degree between the similarity and a set threshold, the determination module 85 determines whether the text to be detected is satirical. This implementation not only achieves better contextual satire detection and improves the accuracy of satirical text detection, but also saves a significant amount of data annotation work, achieving unsupervised satire detection, thus enabling its application in real-world scenarios to meet detection requirements.

[0144] Correspondingly, this application provides an electronic device.

[0145] Please see Figure 9 , Figure 9 This is a schematic diagram of one embodiment of the electronic device of this application. For example... Figure 9 As shown, the electronic device 90 includes a memory 91 and a processor 92.

[0146] In this embodiment, the memory 91 is used to store program data, and when the program data is executed, it implements the steps in the text detection method described above; the processor 92 is used to execute the program instructions stored in the memory 91 to implement the steps in the text detection method described above.

[0147] Specifically, processor 92 controls itself and memory 91 to implement the steps in the text detection method described above. Processor 92 can also be referred to as a CPU (Central Processing Unit). Processor 92 may be an integrated circuit chip with signal processing capabilities. Processor 92 can also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. A general-purpose processor can be a microprocessor or any conventional processor. Furthermore, processor 92 can be implemented using multiple integrated circuit chips.

[0148] Unlike existing technologies, this implementation uses processor 92 to mask positive and negative sentiment words in the text to be detected, generating a first masked text and a second masked text. Then, based on the masked positive and negative sentiment words, predictions are made for the first and second masked texts, respectively. This allows for the generation of a first reconstructed text and a second reconstructed text with consistent sentiment and semantics, following the logic of the unmasked text, thus maintaining contextual consistency. Furthermore, by calculating the similarity between the text to be detected and the reconstructed text, and based on the matching degree between the similarity and a set threshold, it is possible to determine whether the text to be detected is satirical. Through this method, this application not only achieves better contextual satire detection and improves the accuracy of satirical text detection, but also saves a significant amount of data annotation work, realizing unsupervised satire detection, and thus can be applied to real-world scenarios to meet detection requirements.

[0149] Correspondingly, this application provides a computer-readable storage medium.

[0150] Please see Figure 10 , Figure 10 This is a schematic diagram of a computer-readable storage medium according to an embodiment of the present invention.

[0151] The computer-readable storage medium 100 includes a computer program 1001 stored on it. When executed by the processor, the computer program 1001 implements the steps of the text detection method described above. Specifically, if the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium 100. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a computer-readable storage medium 100 and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods of various embodiments of this application. The aforementioned computer-readable storage medium 100 includes various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0152] In the several embodiments provided in this application, it should be understood that the disclosed methods and apparatus can be implemented in other ways. For example, the apparatus implementations described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.

[0153] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment, depending on actual needs.

[0154] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0155] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods of various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0156] The above description is merely an embodiment of this application and does not limit the patent scope of this application. Any equivalent structural or procedural transformations made using the content of this application's specification and drawings, or direct or indirect applications in other related technical fields, are similarly included within the patent protection scope of this application.< / eos>

Claims

1. A text detection method, characterized by, include: Obtain the text to be detected; By masking each positive sentiment word in the text to be detected, the first masked text is obtained; Furthermore, each negative sentiment word in the text to be detected is masked to obtain the second masked text; Predict the positive sentiment words that are masked in the first masked text to generate the first reconstructed text; And, predicting the masked negative sentiment words in the second masked text to generate a second reconstructed text, including: obtaining word embedding vectors of the first masked text and the second masked text respectively; wherein the word embedding vectors include character vectors and position vectors; concatenating the word embedding vectors corresponding to the first masked text and the second masked text respectively to obtain a first hidden sequence and a second hidden sequence with contextual features, including: encoding the word embedding vectors corresponding to the first masked text and the second masked text respectively to obtain the first hidden sequence and the second hidden sequence with contextual features; predicting each masked sentiment word and each constituent word in the first hidden sequence and the second hidden sequence respectively to obtain the first reconstructed text and the second reconstructed text; wherein the constituent words are verbs and / or nouns; Determine the first similarity between the first reconstructed text and the text to be detected, and the second similarity between the second reconstructed text and the text to be detected; In response to the first similarity and / or the second similarity being less than a set threshold, the text to be detected is determined to be satirical text.

2. The text detection method according to claim 1, characterized in that, After obtaining the text to be detected, the following steps are included: Part-of-speech tagging is performed on each character in the text to be detected; The steps of masking each positive sentiment word in the text to be detected to obtain a first masked text, and masking each negative sentiment word in the text to be detected to obtain a second masked text, include: Identify each sentiment word from the labeled text to be detected, and classify the sentiment words as positive sentiment words or negative sentiment words based on their polarity; and Identify each verb and / or each noun that is not a sentiment word from the labeled text to be detected, and determine the verb and / or the noun as the constituent word; The first masked text is generated by using mask characters to conceal the positive sentiment words and at least some of the constituent words in the text to be detected; and The negative sentiment words and the same constituent words in the text to be detected are masked using the mask characters to generate the second masked text.

3. The text detection method according to claim 2, characterized in that, The step of identifying each sentiment word from the labeled text to be detected, and classifying the sentiment words into positive sentiment words or negative sentiment words based on their polarity, includes: Using an external sentiment resource lexicon, each sentiment word in the labeled text to be detected is identified as either a positive sentiment word or a negative sentiment word, and then classified into the corresponding positive sentiment word set or negative sentiment word set; The step of identifying each verb and / or each noun that is not a sentiment word from the labeled text to be detected, and determining the verbs and / or nouns as constituent words, includes: The grammatical information of the text to be detected is obtained using natural language processing tools; Based on the grammatical information, each verb and / or each noun that is not a sentiment word is identified from the labeled text to be detected, and the verb and / or the noun are identified as the constituent words; Each of the constituent words is assigned to a constituent word set, and the constituent word set is divided into at least two subsets; The process involves using mask characters to conceal the positive sentiment words and at least some of the constituent words in the text to be detected, thereby generating the first masked text; and The step of generating the second masked text by using the mask characters to cover up the negative sentiment words and the same constituent words in the text to be detected includes: The mask characters are used to cover all characters included in the set of positive sentiment words and one of the subsets to generate the first masked text; and The mask characters are used to cover all characters included in the negative sentiment word set and the same subset to generate the second mask text.

4. The text detection method according to claim 2, characterized in that, The first reconstructed text and the second reconstructed text are generated by a text generation model, which includes an encoder, an attention network and a decoder that are cascaded together. The step of obtaining the word embedding vectors of the first masked text and the second masked text respectively includes: The word embedding vectors of the first masked text and the second masked text are obtained by the encoder of the text generation model. The step of concatenating the word embedding vectors corresponding to the first masked text and the second masked text respectively to obtain a first hidden sequence and a second hidden sequence with contextual features includes: The word embedding vectors corresponding to the first masked text and the second masked text are encoded using the encoder to obtain the first hidden sequence and the second hidden sequence with contextual features. The step of predicting each of the masked sentiment words and each of the component words in the first hidden sequence and the second hidden sequence respectively to obtain the first reconstructed text and the second reconstructed text includes: The attention network and the decoder in the text generation model are used to decode the first hidden sequence and the second hidden sequence in sequence to predict each of the masked sentiment words and each of the component words, and output the first reconstructed text and the second reconstructed text.

5. The text detection method according to claim 4, characterized in that, The attention network includes a self-attention mechanism; The step of using the attention network and the decoder in the text generation model to sequentially decode the first hidden sequence and the second hidden sequence to predict each of the masked sentiment words and each of the component words, and outputting the first reconstructed text and the second reconstructed text, includes: The self-attention mechanism and the decoder are used to perform autoregressive decoding on the first hidden sequence and the second hidden sequence in sequence, so as to predict each of the masked sentiment words and each of the constituent words based on each time step, and output the first reconstructed text and the second reconstructed text.

6. The text detection method according to claim 1 or 5, characterized in that, The step of determining the first similarity between the first reconstructed text and the text to be detected, and the second similarity between the second reconstructed text and the text to be detected, includes: Obtain the word embedding vectors of the text to be detected, the first reconstructed text, and the second reconstructed text, respectively; The word embedding vectors corresponding to the text to be detected, the first reconstructed text, and the second reconstructed text are concatenated to obtain a text sequence to be detected, a first text sequence, and a second text sequence with contextual features. The similarity between the text sequence to be detected and the first text sequence is calculated using at least one similarity algorithm to obtain the first similarity; and, The similarity algorithm is used to calculate the similarity between the text sequence to be detected and the second text sequence to obtain the second similarity.

7. A text detection apparatus characterized by comprising: include: The acquisition module is used to acquire the text to be detected; The masking module is used to mask each positive sentiment word in the text to be detected, thereby obtaining the first masked text; Furthermore, each negative sentiment word in the text to be detected is masked to obtain the second masked text; A reconstructed text generation module is used to predict the masked positive sentiment words in the first masked text to generate a first reconstructed text; and to predict the masked negative sentiment words in the second masked text to generate a second reconstructed text. Specifically, the reconstructed text generation module is used to obtain the word embedding vectors of the first masked text and the second masked text respectively; wherein the word embedding vectors include character vectors and position vectors; concatenating the word embedding vectors corresponding to the first masked text and the second masked text respectively to obtain a first hidden sequence and a second hidden sequence with contextual features, including: encoding the word embedding vectors corresponding to the first masked text and the second masked text respectively to obtain the first hidden sequence and the second hidden sequence with contextual features; predicting each masked sentiment word and each constituent word in the first hidden sequence and the second hidden sequence respectively to obtain the first reconstructed text and the second reconstructed text; wherein the constituent words are verbs and / or nouns; the first reconstructed text and the second reconstructed text are generated through a text generation model, the text generation model including a cascaded encoder, attention network, and decoder; A similarity calculation module is used to determine the first similarity between the first reconstructed text and the text to be detected, and the second similarity between the second reconstructed text and the text to be detected; A determination module is configured to determine the text to be detected as satirical text in response to the first similarity and / or the second similarity being less than a set threshold.

8. An electronic device, comprising: include: A memory for storing program data, which, when executed, implements the steps of the text detection method as described in any one of claims 1 to 6; A processor for executing the program data stored in the memory to implement the steps in the text detection method as described in any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the text detection method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Irony text collaborative recognition method, device and equipment and computer readable medium

    CN111859979A

  • Pre-training language model processing method based on comparative learning and intelligent question answering system

    CN114528383A