Implicit euphemistic harmful text detection method based on knowledge enhanced multi-task learning
By constructing an implicitly malicious text detection model using a knowledge-enhanced multi-task learning approach, the low accuracy of implicitly malicious text detection in existing technologies is solved, achieving efficient identification and accurate detection of implicitly malicious text.
Patent Information
- Application Number
- CN202411762618.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-03
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2044-12-03
AI Technical Summary
Existing detection methods struggle to accurately identify implicitly harmful texts, resulting in low detection and accuracy rates, and are unable to effectively address implicitly expressed harmful speech on social media.
We adopt a knowledge-enhanced multi-task learning approach to construct an implicitly harmful text detection model, which includes a euphemism feature fusion module, a latent meaning knowledge enhancement module, and a multi-task learning framework. By combining data filtering, annotation, and enhancement techniques, and utilizing BERT word vectors and contrastive learning, we construct a multi-task learning framework for detection.
It improves the detection accuracy and detection rate of implicitly harmful text, and achieves efficient identification of implicitly malicious text, with high detection efficiency and accuracy.
Smart Images

Figure CN119577585B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of network security technology, and in particular to a method for detecting implicit euphemisms and harmful texts based on knowledge-enhanced multi-task learning. Background Art
[0002] The rapid development of the internet and the rise of social media have led to the proliferation of a large amount of harmful content. Harmful content refers to rude, disrespectful, or unreasonable speech that can cause others to leave a discussion and cause psychological trauma. It typically includes offensive language and hate speech. To circumvent platform content review mechanisms, malicious users often deliberately choose to use implicit and euphemistic expressions when posting harmful content, avoiding overtly abusive language. Implicitly expressed harmful content often contains euphemisms, which are constructed using methods such as distortion, homophones, irony, abbreviations, metaphors, and hybrids. This type of harmful content not only has a negative impact on society but is also very difficult to detect. Existing detection methods have a low detection rate for implicitly expressed harmful content and limited accuracy. Summary of the Invention
[0003] In order to solve the above technical problems existing in the prior art, the present invention aims to provide a detection method that can accurately and comprehensively detect implicit euphemisms and harmful texts.
[0004] Specifically, the present invention provides a method for detecting implicit euphemisms and harmful text based on knowledge-enhanced multi-task learning. The specific technical solution includes the following steps:
[0005] Step S1: Crawl keywords of preset topics through social media platforms to construct the original data set;
[0006] Step S2: Filter and label the original data set in sequence to generate a classified data set classified by preset labels;
[0007] Step S3: Build a hidden harmful text detection model and train the hidden harmful text detection model using a classification dataset;
[0008] The implicit harmful text detection model includes a euphemism feature fusion module, a latent meaning knowledge enhancement module, and a multi-task learning framework.
[0009] Step S4: Input the text to be detected into the trained implicit harmful text detection model and output the detection result.
[0010] Preferably, step S1 further includes:
[0011] When constructing the original dataset, at least one of the SWSR dataset, the COLD dataset, and the CDialBias dataset is introduced.
[0012] Preferably, data filtering includes:
[0013] Remove repeated sentences, advertisements, extra line breaks, spaces, and phrases containing only word forms and auxiliary verbs, and remove "@user", links, and images;
[0014] Delete the synthetic data generated by the language model with perplexity values less than 10 and greater than 100.
[0015] Preferably, data annotation includes:
[0016] For the original data set that has been filtered, a preset number of data are classified through manual labeling and classification;
[0017] Use the classified data to initialize the classifier, and then use the toxicity classifier to classify the unlabeled data;
[0018] The dataset obtained by the toxicity classifier is divided into a preset number of buckets, and data from each bucket is randomly extracted according to a preset ratio. If the labeling accuracy of the extracted data is not lower than the preset value, the data in the corresponding bucket is added to the classification dataset.
[0019] Otherwise, manually label the data in the corresponding bucket and then add it to the classification dataset;
[0020] Among them, the labels used for classification include "harmful text" and "harmless text".
[0021] Preferably, data annotation also includes:
[0022] For harmful texts, we build a swear word vocabulary based on the WSR dataset and the ToxiCN dataset.
[0023] Use regular expressions to match profanity texts containing profanity words, and include other profanity words in the profanity texts;
[0024] Assign a pseudo-label to each swear word text;
[0025] Iterate the preset rounds and assign the “non-toxic text” label to the text that has not been assigned a pseudo label.
[0026] Furthermore, step S1 also includes data enhancement;
[0027] (1) Generate implicit harmful text:
[0028] Get example text labeled "harmful text" from the ToxiCN dataset or the CDialBias dataset;
[0029] Passing sample text to the language model through the prompt module to generate implicit harmful text;
[0030] The transfer formula of the prompt module is as follows:
[0031] P(text,topic)=[CLS]w1,w2,...,<topic>,...,<text>,w l [sMASK];
[0032] Where p(·) represents the probability distribution of implicit harmful text, [CLS] represents the special classification mark, and w i represents the i-th word in the sample text, <topic>Indicates the subject of the sample text, <text>Represents the label of the example text, l is the number of words in the example text, i = 1, 2, ... l, [sMASK] is the mask tag;
[0033] Detect toxicity of implicitly harmful texts through toxicity classifiers;
[0034] (2) Restricted beam search adversarial decoding:
[0035] Based on the language model, the Topk algorithm is used to sample implicitly harmful texts that have been tested for toxicity to obtain a vocabulary toxicity table.
[0036] Perform restricted beam search decoding of size 2 on the lexical toxicity table and decode the candidate words obtained;
[0037] Generate adversarial text based on implicitly harmful text and candidate word concatenation, and detect the toxicity of the adversarial text through a toxicity classifier;
[0038] Compare the toxicity of the candidate word with the adversarial text, that is, compare the toxicity;
[0039] Among them, soft constraints are imposed on the toxicity classifier.
[0040] log p(w i+1 |w 0:i )∝λ L log p LM (w i+1 |w 0:i )+λ C log p CLF (w 0:i+1 );
[0041] Where w 0:i represents the word sequence from the beginning of the sequence to the i-th word, λ L is the hyperparameter of the language model’s contribution to the decoding score function, λ C is the hyperparameter of the classifier’s contribution to the decoding score function, p LM is the probability of a word in a given context given by the language model, p CLF The probability that the entire sequence belongs to the corresponding class given to the toxicity classifier;
[0042] (3) Based on the results of toxicity confrontation, the vocabulary with the minimum probability of harmfulness is selected, and the implicit harmful enhancement text is generated through the language model, that is, the harmful text expressed implicitly in a euphemistic way.
[0043] Preferably, the prompt template includes a range prompt template and a category prompt template;
[0044] (4) The language model is the GLM (General Language Model);
[0045] (5) Toxicity classification is to fine-tune the COLDETECTOR model (Chinese Offensive Language Detection);
[0046] λ C =λ L = 0.5, the maximum generation length is 30 tokens, the bundle size is 10, and the first temperature hyperparameter is 0.9.
[0047] Preferably, in step S3,
[0048] The euphemism feature fusion module includes input layer, encoding layer and feature fusion layer;
[0049] The latent meaning knowledge enhancement module includes a contrastive learning layer and a shared encoding layer;
[0050] The multi-task learning framework includes harmful text detection subtask, euphemism identification subtask and loss function.
[0051] Preferably, the training specifically includes:
[0052] (1) Euphemism feature fusion module:
[0053] For the vocabulary V in the classification dataset, there exists
[0054] V Ω =(V,E);
[0055] V={w1,w2,...,w j ,...,w n };
[0056] Where V Ω represents the ontology of semantic relationships between words in the vocabulary V, E is the set of unordered tuples consisting of elements in the classification dataset, w j is the jth word in the vocabulary V, n is the number of words in the vocabulary V, i = 1, 2, ..., n;
[0057] For each word w in the vocabulary V j , use BERT (Bidirectional Encoder Representation from Transformers, bidirectional encoder based on Transformer) to learn the corresponding word vector
[0058]
[0059] Where, is the word vector set, d is the word vector The length, R d Representing word vectors Dimensions;
[0060] Extract the synonym relationship in its word meaning dictionary, that is, extract all the word vectors from all unordered bigrams and its semantic neighbor word vectors The two-tuple formed;
[0061] Iteratively correct word vectors Get the improved word vector q j , minimize the objective function Ψ(Q),
[0062]
[0063]
[0064] Q=[q1,q2,...,q j ,...,q n ],q j ∈R d ;
[0065] Where, α j and β jk To control the word vector and word vectors The relative strength value of the correlation between k For word vector The improved word vector, Q is the improved word vector q j A set of; Among them, the initial values of all elements in the improved word vector set Q and the word vector set The corresponding word vectors are equal;
[0066] Based on the improved word vector set Q encoding, the original input text from the classification dataset is generated to generate the initial text representation vector;
[0067] Introducing a euphemism dictionary, based on the word w that belongs to both the original input text and the euphemism dictionary, the initial text representation vector is fused with the euphemism feature vector corresponding to the word w to generate a text representation vector x;
[0068] (2) Potential meaning knowledge enhancement module:
[0069] Perform positive sample sampling on the set of text representation vectors generated based on the classification dataset,
[0070]
[0071] Where, The text representation vector x of the mth input in the current batch m Positive sample, x p represents the p-th text representation vector input in the current batch, and IMP(·) represents the positive sample sampling; if m≤N, then p=m+N; if m>N, then p=m=N;
[0072] Use the latent meaning as a positive sample for contrastive learning, generating contrastive loss
[0073]
[0074] Where N is the number of input text representation vectors, r is the common serial number of the text representation vector and the positive sample input sampling module IMP, and x r represents the rth text representation vector input in the current batch, h(·) represents the encoding representation, I [·] represents the indicator function, τ is the scalar temperature parameter;
[0075] Calculate the loss function corresponding to hidden harmful text detection
[0076]
[0077] Where λ is the weight coefficient, L ce is the cross entropy loss function;
[0078]
[0079] Where, is the text representation vector x m The model predicts the probability, y m is the text representation vector x m The true label of
[0080] Minimize the loss function Output the text representation vector enhanced by the latent meaning knowledge, i.e., harmful latent features;
[0081] (3) Multi-task learning framework:
[0082] Includes sub harmful text detector f sub , euphemism detector f eup and parent harmful text detector f super :
[0083] x h and euphemism text x e Input BERT shared encoding layer, corresponding to the output of harmful potential features z h and potential characteristics of euphemisms e ;
[0084] based on Training harmful text detector f sub ; Among them, s is the harmful sequence number, N h is the number of harmful texts input, s=1,2,...,N h , is the harmful potential feature corresponding to the s-th harmful text, is the pseudo label corresponding to the s-th harmful text, which is obtained by pre-combining the harmful label and the enhanced euphemism label;
[0085] based on Training euphemism detector f eup ; where t is the text number of the euphemism, N e is the number of euphemism texts input, t=1,2,...,N e , is the potential feature of the euphemism corresponding to the euphemism text, For the euphemism text corresponding to;
[0086] By sub harmful text detector f sub Predict the harmful label for each harmful text By using euphemism detector f eup Predict euphemism labels for each harmful text;
[0087] Harmfulness labels based on harmful text Constructing multi-label learning data with euphemistic labels in,
[0088]
[0089]
[0090] Where, Represents the concatenation operator, f is the euphemism detector eup For a text sample x h Original euphemism label prediction, is a sharpened pseudo-euphemism label,
[0091]
[0092] Where T is the second temperature hyperparameter;
[0093] Learning from multi-label data Train the parent harmful text detector f super , specifically including:
[0094] By parent harmful text detector f super Predicting harmful potential traits Enhanced original harmful label prediction
[0095]
[0096] Where η represents the parent harmful text detector f super The number of basic blocks included, Π={Π 1 …Π η } represents a trainable parameter;
[0097] Among them, the basic block includes two layers of fully connected networks,
[0098]
[0099] Where x represents the input, are trainable parameters, δ(·) and σ(·) are activation functions;
[0100] By minimizing harmful text and harmfulness labels for harmful text The difference between the two, training the parent harmful text detector f super ,
[0101]
[0102] Where, L E_H (∏) is the parent harmful text detector f super The loss, D h is the set of harmful texts, FL(·) represents the focus loss, is the harmful text prediction component, MSE(·) represents the mean square error loss, Predicting components for euphemisms.
[0103] The technical solution provided by the present invention can achieve efficient detection of implicit harmful text through knowledge enhancement and multi-task learning, with high detection rate and accuracy, and high detection efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0104] Figure 1 Schematic diagram of the data enhancement process framework in the present invention.
[0105] Figure 2 Schematic diagram of the detection process of the implicit harmful text detection model in the present invention.
[0106] Figure 3 This is an example diagram of euphemism feature enhancement in the present invention.
[0107] Figure 4 This is a comparison chart of the hidden harmful text detection results of the detection method provided by the present invention and the existing detection methods.
[0108] Figure 5 This is a comparison chart of the ablation experiment results of the implicit harmful text detection model in the present invention and the TKE model. DETAILED DESCRIPTION
[0109] Hereinafter, the technical solution provided by the present invention will be further elaborated in conjunction with the accompanying drawings.
[0110] 1. Dataset Construction Method
[0111] Current Chinese research lacks a theoretically based framework and a large-scale dataset to better understand implicitly harmful texts and their various manifestations.
[0112] To fill this gap, the present invention establishes a new benchmark dataset IMPTOX (Implicit Toxic Text).
[0113] Data Collection Strategy
[0114] The diversity of the data set is mainly increased through two methods: existing data sets and keyword crawling.
[0115] The real-world data are crawled from published posts on three public online media platforms that have a large number of users and active communities around specific topics.
[0116] Keyword matching method is used to collect data:
[0117] Table 1 lists the keywords of various topics of crawled posts.
[0118] In addition to obtaining data through keyword crawling, we also researched existing relevant academic datasets, which can be used as candidates for further fine-grained annotation, thus making the IMPTOX dataset more diverse.
[0119] include:
[0120] 1) SWSR dataset (Chinese gender discrimination dataset);
[0121] 2) COLD dataset (Chinese offensive text dataset);
[0122] 3) CDialBias dataset (a high-quality annotated Chinese dialogue system social bias dataset).
[0123] Table 1 Theme and keyword information of crawled data
[0124]
[0125] 1.2 Data filtering and labeling
[0126] (1) Data filtering
[0127] For the data collected by the crawler, we first filter out samples that are too short to have actual semantics, such as phrases containing only word forms and auxiliary verbs. In addition, we delete some useless data, including duplicate samples and irrelevant advertisements. During the data cleaning phase, we normalize the unique expressions in online text. In addition, extra line breaks and spaces in the original text are also removed. To prevent privacy leaks caused by the dataset, the crawled data is desensitized, filtering out @ users, attached links, and images. Because emoticons can carry important emotional information, they are retained for the detection of harmful content.
[0128] The quality of synthetic data generated by language model crawlers and related academic datasets varies. Therefore, we use the perplexity metric to filter out unsmooth generated text and retain only synthetic data with perplexity values between 10 and 100. These machine-generated sentences are largely indistinguishable from human-written ones.
[0129] Among them, perplexity (PPL) is one of the most common indicators for evaluating language models. This indicator is specifically applicable to classical language models (autoregressive or causal language models) and is defined as the exponent of the average negative log-likelihood of the sequence. If there is a tokenized sequence X = (x0, x1, ..., x t ), its perplexity PPL(X) is:
[0130]
[0131] Where, log θ (x i |x <i ) is the previous token x <i The log-likelihood of the i-th token conditioned on . Intuitively, this is an assessment of the model's ability to make uniform predictions across a given set of tokens in the corpus. Importantly, the tokenization process has a direct impact on the complexity of the model, which should always be taken into account when comparing different models. This is equivalent to the power of the cross-entropy between the data and the model's predictions.
[0132] (2) Data annotation
[0133] The data generated by the large language model is used for data augmentation training in this invention, rather than for the final test set. Therefore, there is no need for manual labeling for verification. The prompt labels in the data generation process can be directly used as a proxy for its true harmfulness label.
[0134] To improve the efficiency of the data annotation process and reduce the burden of manual annotation, we use a model-assisted approach to assist manual annotation, train a classifier to discover target data from candidate data, and adopt different annotation strategies to improve annotation efficiency. First, 500 samples were manually annotated as training data to initialize the classifier. Then, the classifier was used to predict whether a batch of unlabeled data was harmful. Next, the data was ranked according to the harmfulness prediction score and divided into multiple data buckets for sample inspection. About 10% of the data was sampled from each bucket and manually annotated according to the following strategy: (1) If the accuracy of the predicted label reaches 90%, the data in the bucket is directly added to the training set; (2) Otherwise, the entire bucket is manually re-annotated and then added to the training set. In this way, the classifier and training set are updated in multiple rounds of iterations. In addition, for explicitly harmful texts, we established a clear swear word vocabulary that integrates existing Chinese insult word resources including SWSR and ToxiCN. An iterative approach uses regular expressions to match textual content containing profanity, and further collects profanity contained in these samples that are not in the vocabulary. Each sentence containing an insult is assigned a pseudo-label of "harmful". After several rounds of iteration, the remaining samples are directly pseudo-labeled as "harmless" to be re-labeled in a hierarchical manner.
[0135] 1.3 Data Augmentation Methods
[0136] This paper designs a data augmentation framework, GENIMP (Generate Implicit Harmful Textdata Augmentation Framework), which uses a data augmentation method based on prompt learning. Two sets of prompt templates are designed for the scope and type of datasets, respectively, and adversarial learning scenarios are added to control the implicitness of harmful data. Synthetic data with a small number of prompts is generated on the GLM (General Language Model)-10B and GLM-large models, and complexity is used to control the fluency of the data.
[0137] The GENIMP data enhancement framework is mainly divided into two steps, namely the harmful text generation part and the implicit degree control part, such as Figure 1 As shown in the figure, an example-based hint learning method is first used to incentivize the language model to generate implicit euphemisms that do not use explicit insults. Subsequently, this framework introduces a detector recurrent decoding method based on restricted beam search, which adjusts the harmfulness of samples generated by the pre-trained language model. This method helps generate challenging subsets of the IMPTOX dataset for data augmentation.
[0138] Based on the language model, the TopK algorithm (implemented by calling torch.topk) is used to sample implicitly harmful texts that have passed toxicity detection to obtain a vocabulary toxicity table.
[0139] Perform restricted beam search decoding of size 2 on the lexical toxicity table and decode the candidate words obtained;
[0140] Generate adversarial text based on implicitly harmful text and candidate words, and detect the toxicity of the adversarial text through a toxicity classifier;
[0141] GENIMP expands and enriches the scope and diversity of data by prompting language models to generate euphemistically expressed harmful text. This approach primarily generates insulting speech using implicit language rather than explicit profanity. To achieve this goal, the framework employs example-based prompting, using seed samples with harmful labels from the ToxiCN and CDialBias datasets. This takes the seed example sentences and passes them to the generative language model using prompt templates, forcing it to generate similar text.
[0142] The prompt information template is designed as follows:
[0143] log p(w i+1 |w 0:i )∝λ L log p LM (w i+1 |w 0:i )+λ C log p CLF (w 0:i+1 );
[0144] where λ L and λ C It is a hyperparameter that determines the contribution of the language model and classifier to the decoding score function. i+1 Indicates the i+1th word. 0:i Represents the word sequence from the beginning of the sequence to the i-th word. The probability p of the next word in a given context given by the language model LM And the probability p that the entire sequence belongs to a certain category given by the toxicity classifier CLF Using this weighted combination, generation can be directed towards higher or lower harmfulness probabilities p without sacrificing the coherence of the language model. This method uses hint learning to encourage the language model to generate harmful outputs, and then maximizes the classifier probability of the benign class during the beam search. For the language model, this framework uses the GLM language model; for the toxicity classifier CLF, this framework selects the fine-tuned COLDETECTOR (Chinese Offensive Language Detection, Chinese offensive speech detection) model; for decoding, this framework uses λ C =λ L = 0.5, the maximum generation length is 30 tokens, the beam size is 10, and the temperature hyperparameter is 0.9.
[0145] 2. Implicit Harmful Text Detection Model
[0146] The present invention constructs an implicit harmful text detection framework based on implicit meaning enhancement and multi-task learning. The framework is mainly divided into three key steps: euphemism vocabulary feature fusion, potential meaning knowledge enhancement and multi-task learning framework. First, the present invention studies the euphemism vocabulary feature fusion method to improve the model's ability to represent implicit meanings; then, it studies the potential meaning knowledge enhancement based on contrastive learning to learn the common features of implicit harmful speech with shared meanings; finally, it combines the euphemism recognition task and the harmful text detection task to construct a multi-task learning framework, and improves the detection performance of the model through multi-task parameter sharing and multi-feature fusion loss function. The technical architecture diagram of implicit harmful text detection based on knowledge enhancement multi-task learning is as follows: Figure 2 shown.
[0147] 2.1 Fusion of euphemism features
[0148] Implicitly expressed harmful text often contains euphemisms, so knowledge of euphemisms is crucial for identifying such harmful text. This paper proposes a method that leverages relational information from a semantic dictionary to improve vector space representations. By encouraging related words to have similar vector representations, euphemisms are incorporated into word vector representations.
[0149] This method enhances word embeddings by modifying the original word vectors to fit the semantic dictionary. This method extracts synonym relationships from the semantic dictionary and "modifies" the word embeddings through belief propagation so that the vectors of synonyms are closer in the vector space. The vocabulary in the corpus is defined as V = {w1,...,w n }, Ω is an ontology that encodes the semantic relations between words in a vocabulary V. We represent Ω as an undirected graph (V, E), where each word has a vertex, E is the set of unordered tuples of elements in V, and the edges are Indicates related semantic relationships, which are synonymous relationships in the euphemism dictionary of the present invention. will be the set of word vector representations, for each word w in the vocabulary V i ∈V, use BERT to learn vector representation Where d is the length of the word vector. The goal of this method is to learn the matrix Q = (q1,...,q n ), so that the vector column is close to its The corresponding columns in are close to the adjacent vertices in Ω. Figure 3 As shown in the figure, an example of a word graph with edge connections is shown. The shaded nodes in the figure are learned by the BERT method. The white node is the improved Q vector (with the dictionary relationship V Ω correspond).
[0150] Euclidean distance is used to define the similarity distance between a pair of vectors. Since we hope that the inferred word vector is close to the observed value q j , for all (i, j)∈E, the objective Ψ(Q) to be minimized is defined as:
[0151]
[0152] The values of the scaling coefficients α and β control the relative strength of the correlation. First, we use BERT to train word vectors based on information independent of the semantic dictionary, and then perform fusion improvements on euphemistic vocabulary features. Ψ is a convex function in Q, and its solution can be found by solving a system of linear equations. Referring to related research, we use an efficient iterative update method, where the vectors in Q are initialized to be the same as The vectors in are equal, and then Ψ is about a q i The first derivative of the vector is set to zero, resulting in the following online update:
[0153]
[0154] Where, α j and β jk To control the word vector and word vectors The relative strength value of the correlation between the improved word vector set Q and the word vector set Q. The corresponding word vectors are equal.
[0155] After running this process for 10 iterations, the change in the Euclidean distance between adjacent vertices in the semantic dictionary will be less than 10 -2 Since the above updates are independent of the original vector training model's objectives, this euphemism feature fusion method can be applied to word vector representations obtained from any model. By improving the representation vectors of implicitly expressed harmful text, the detection performance of such euphemisms can be improved.
[0156] 2.2 Potential Meaning Knowledge Enhancement
[0157] Although implicitly harmful texts vary in form and language, most share common underlying meanings, such as discrimination against women or specific regions. This paper proposes a positive sample sampling strategy based on hidden meaning: using generated text with the same underlying meaning as positive samples for a given implicitly harmful speech. Despite different presentation forms, some implicitly harmful speech implies similar harmful biases. Those who post harmful speech often project a single meaning onto posts with various lexical forms. Inspired by the relationship between the meaning and the underlying harmful speech in its various lexical forms, we propose using the underlying meaning of harmful speech as positive samples. By linking a implicitly harmful speech with its meaning during training, a meaning can serve as an anchor for its corresponding harmful speech. This enables the model to learn the relationship between harmful speech and its underlying meaning, resulting in a more efficient harmful speech detector. We design a cue word template that contains an input sample and a harmful data category (e.g., sexism). By revealing examples of the input sample and its harmful category, we incentivize the large language model, ChatGLM, to output generated text with the same underlying meaning as the given sample. This generated text can then be used as positive samples for knowledge enhancement of the underlying meaning.
[0158] Specifically, the general harmful speech detection model is based on the following cross entropy loss function L ce Perform supervised training:
[0159]
[0160] Where N is the number of input samples in a batch, Represents the i-th input x i The model predicts the probability, y i is x i However, due to the limitations of cross-entropy loss in producing large inter-class margins or intra-class compactness, fine-tuning using only cross-entropy loss may lead to suboptimal generalization. Our proposed implicit harmful text detection framework IHTD-KML utilizes a contrastive learning method to enhance the knowledge of the implicit meaning of harmful texts, jointly training contrastive loss with cross-entropy loss.
[0161] For a positive sample sampling module IMP(·), its i-th input x i The positive sample is defined as:
[0162]
[0163] Given N training samples in a batch, assuming that there is a positive sample for each sample, there are a total of 2 N samples. is the jth input in the batch, that is, If i≤N, then j=i+N, otherwise j=iN. All samples except the input sample and the positive sample are considered as negative samples. For i≤N, if x i is harmful speech, then IMP(x i ) represents x i The potential meaning of enhanced samples; if x i Harmful speech, IMP(x i ) represents x i A synonym replacement enhanced version of . Contrastive loss using latent meaning as positive samples for contrastive learning It is expressed as follows:
[0164]
[0165] Among them, · represents the dot product operation, h(x i )∈R H is the input x i The encoding representation of , H is the size of the hidden dimension. [·] is an indicator function, and τ is a scalar temperature parameter. Finally, the overall objective of the harmful text detector using a combination of cross entropy loss and contrastive learning loss is expressed as follows:
[0166]
[0167] Among them, λ is the weight coefficient.
[0168] 2.3 Multi-task Learning Framework
[0169] The implicit harmful text detection framework IHTD-KML proposed in this paper uses multi-task learning and selects the euphemism detection task as an auxiliary task, aiming to integrate prior knowledge of euphemisms and jointly learn commonalities through shared features to increase the performance of the model.
[0170] Through careful analysis, we discovered that the implicitly harmful dataset contains a large number of euphemisms, such as homophones, similar words, and euphemisms with cryptic meanings. Based on this premise, this framework uses euphemism detection as an auxiliary task, sharing useful information to improve the detection performance of implicitly harmful text.
[0171] This framework explores implicitly harmful text detection from the perspective of multi-label learning (MLL), where each training example is assigned both a euphemism label and a harmful text label. An MLL classifier can be trained by capturing the correlation between harmful text and euphemism labels, resulting in harmful text label predictions enhanced by euphemism knowledge. To address the problem of euphemism labels being virtually unknown, this framework integrates a detector into the multi-task learning (MLL) framework and uses the euphemism detector to generate pseudo labels.
[0172] In the harmful text dataset and auxiliary euphemism dataset The multi-task learning in the IHTD-KML framework consists of three prediction components, including the sub-harmful text detector f sub , euphemism detector f eup and parent harmful text detector f super .
[0173] The harmful text detector and the euphemistic sentence detector are jointly trained through a shared encoder. For harmful speech samples, f sub and f eup To predict their harmful and euphemistic labels. super A self-training paradigm is adopted for training, and the harmfulness prediction and euphemism prediction are connected as latent features. The real harmfulness label is connected with the enhanced euphemism prediction as pseudo multi-label, thus forming pseudo MLL data for training to capture the correlation between pseudo multi-labels.
[0174] The specific training steps are as follows:
[0175] 1) The shared encoding layer receives text samples as input, including harmful text x h ∈D h and euphemism text x e ∈D e , and then output their potential features z h =f emb (x h ) and z e =f emb (x e ).
[0176] 2) Sub harmful text detector Training on.
[0177] 3) Euphemism detector in Training on.
[0178] 4) The parent harmful text detector is trained using a self-training paradigm. Specifically, the child harmful text detector and euphemism detector are used to predict the harmfulness label p of each harmful text sample. h =f sub (z h ) and euphemism label p he =f eup (z h ), and then use them to construct pseudo multi-label learning data
[0179] in,
[0180]
[0181] Where, is the concatenation operator, q he It is p he The sharpened pseudo-euphemistic label is calculated as follows:
[0182]
[0183] This sharpening algorithm is a common technique for generating pseudo labels based on predicted values, where T is a temperature hyperparameter, which is empirically set to 0.5 in this framework.
[0184] 5) The parent harmful text detector is trained on pseudo multi-label learning data to capture the correlation between euphemism information and harmful text and enhance the original label prediction. Given a latent feature Predictions of the Parent Harmful Text Detector As shown below:
[0185]
[0186] Where, Π={Π 1 …Π n } denotes trainable parameters. The parent harmful text detector consists of n stacked basic blocks, each of which is a two-layer fully connected network.
[0187] The specific expressions are as follows:
[0188]
[0189] Where x represents the input, are trainable parameters, δ(·) and σ(·) are activation functions. and The difference between them is used to train the parent harmful text detector as follows:
[0190]
[0191] Where β∈[0,1] is a hyperparameter, FL(·) represents the focal loss, and MSE(·) represents the mean square error. and They represent the harmful text prediction component and the euphemistic sentence prediction component respectively.
[0192] Ultimately, IHTD-KML enables the exchange of harmful speech and euphemisms not only at a low-level shared level, but also at a higher level of semantic interaction through multi-label learning. This multi-task framework can be trained in an end-to-end manner and can be used to predict untrained harmful speech samples.
[0193] 3. Experiment
[0194] 3.1 Dataset
[0195] The dataset used in the experiment comes from the fine-grained implicit euphemism harmful text dataset IMPTOX constructed in Section 1. This dataset is based on three domestic public online media platforms, including topics 1, 2, 3, and 4. Figure 4 The data was collected and labeled, and then the implicit harmful text data was enhanced based on prompt learning. Among them, the data based on keyword crawling totaled 77,431, and the data enhanced based on the generative language model totaled 240k. The detailed statistical information of the IMPTOX dataset is shown in Table 3.6 in Chapter 3. In this experiment, the dataset was randomly divided into training set, validation set, and test set in a ratio of 8:1:1. To further evaluate the robustness of each model, 1,315 samples were manually annotated in this experiment, and a more difficult implicit euphemism dataset test set HardTest was constructed. It contains samples with hidden language attack behaviors that are difficult for detectors to handle, such as euphemistic harmful text, to specifically evaluate the performance of the model on implicit samples.
[0196] 3.2 Baseline Methods
[0197] To verify the performance of the proposed IHTD-KML framework on the hidden harmful object detection task, we considered the following baseline methods and conducted model comparison experiments. The specific details are as follows:
[0198] Keyword matching (KEYMAT):
[0199] Keyword matching is a common method used by domestic social media platforms to filter harmful content. In this experiment, we used 14,000 sensitive words published on Github as harmful keywords. Text containing any of the keywords in this list was considered harmful.
[0200] Text Censor (TC):
[0201] An online API tool is used to identify harmful text content, including pornography, violence, terrorism, political sensitivity, and abuse. In this experiment, it is used to review and identify whether the text is harmful using binary classification.
[0202] Bi-LSTM (Bidirectional Long Short-Term Memory): Bi-LSTM is a commonly used neural network baseline model for text classification tasks. This experiment uses static word embeddings trained by AI Lab with 200-dimensional features as the embedding layer. Bi-LSTM is used to integrate contextual information. The final hidden states of the forward and reverse directions are concatenated to obtain the final sentence embedding, and a fully connected layer is used as the classifier.
[0203] CNN-GRU (Convolutional Neural Networks-Gated Recurrent Unit): A deep neural network based on convolutional and gated recurrent units, used to extract latent semantic features using word embeddings for hate speech detection. This model captures word sequence and order information in text to better identify latent semantic features.
[0204] BERT: A commonly used pre-trained Chinese language model based on a Transformer encoder, it is widely used as a baseline method in harmful text research. In this experiment, we use the BERT-based-Chinese pre-trained model and use the hidden layer output of the encoder as the input of the fully connected layer classifier.
[0205] RoBERTa (Robustly Optimized BERT Pretraining Approach, a natural language processing model): RoBERTa is an improved version of the BERT model, with optimizations made to the MASK (single-chip masking) strategy, training data size, and pretraining tasks. This experiment used the pretrained parameters in roberta-base-chinese.
[0206] COLDetector (Chinese Offensive Language Detection): A model for detecting offensive language. This model uses a Transformer-based architecture and is based on the pre-trained BERT model. All COLDetector model parameters are trained on the COLDataset using a cross-entropy loss function. COLDetector extracts the first hidden state of BERT's last layer (corresponding to the [CLS] token) as a sentence representation, which is then further processed through a linear layer to generate the final prediction.
[0207] TKE (Chinese Offensive Language Detection): A toxic knowledge-enhanced harmful speech detector. To facilitate the detection of toxic language, Lu et al. constructed a vocabulary of insults targeting different target groups. Based on this vocabulary, Lu et al. designed a toxic knowledge-enhanced baseline TKE model that incorporates lexical features to enrich text representations for harmful text detection.
[0208] GPT-3: The internal knowledge stored by the model during pre-training can be used to detect offensive language. This experiment explores the detection performance of hint-based learning in a zero-shot setting. Given the text to be evaluated, the model input is constructed as follows: "TEXT" Please tell me whether the above content is malicious or offensive. The answer is [MASK]. The GPT-3 model predicts the score of the [MASK] token. The scores of the yes and no candidate words are used as the self-test results.
[0209] In this experiment, the word vectors trained by AI Lab are used as the embedding layer of the non-BERT-based model. The IHTD-KML model is trained with the AdamW optimizer, the batch size is set to 64, the learning rate is set to 1e-5, and 10 epochs (iterations) are trained. The early stopping mechanism is applied in the training phase. The experiment uses ten-fold cross-validation for training, and the average results are reported. This experiment fine-tunes all baseline models, selects the model and hyperparameters that perform best on the validation set, and evaluates the performance on the test set. The same experiment is repeated 5 times by changing the random seed to reduce the error. Model training and all experiments in this work are performed on a server with two Tesla-V10032G GPUs.
[0210] In order to objectively evaluate the detection effects of all baseline models, the hyperparameters of all baseline experiments were obtained by grid search on the validation set to achieve the optimal effect.
[0211] 3.3 Harmful Text Detection Experiment
[0212] To demonstrate the effectiveness of the proposed model IHTD-KML, we tested its performance against nine baseline methods on the IMPTOX dataset. Table 2 below shows the harmful text detection performance of different models on the IMPTOX dataset.
[0213] Table 2 Experimental results of harmful text detection using baseline models and IHTD-KML
[0214]
[0215]
[0216] As shown in the table, compared to other models, the proposed IHTD-KML achieves the best results in every metric. Its F1 score significantly outperforms the previous state-of-the-art model, the TKE model, by 4.9%, and surpasses the BERT model, a commonly used baseline model for harmful text detection, by 6.5%. Compared to the TKE model, which simply augments insult vocabulary knowledge based on harmful categories, IHTD-KML updates word embeddings using belief propagation on a graph constructed from relational information derived from harmful lexicons, effectively incorporating euphemism knowledge. Furthermore, IHTD-KML incorporates an auxiliary euphemism detection task, jointly learning commonalities through shared features to enhance the model's harmful text detection performance.
[0217] The results in the table show the poor performance of keyword matching (KEYMAT), with an accuracy of only 0.56. First, the coverage and quality of the keyword list are crucial to detection accuracy. However, with the constant emergence of new words and the diversification of vocabulary in harmful text, achieving complete coverage is almost impossible, resulting in a low recall rate of only 0.552 for harmful text. Second, filtering potentially harmful samples solely by matching keywords is inaccurate. This is because these words may appear in both harmful and harmless samples, leading to misclassification.
[0218] Compared to text censorship, deep learning-based methods perform better. One plausible explanation is that online API filtering mechanisms rely primarily on keyword dictionaries and are therefore susceptible to sensitive terms. For example, words of praise may be identified as harmful by text censorship due to sensitive terms. These false positives result in relatively low accuracy in detecting harmful content. Furthermore, they are ineffective in detecting harmful content containing euphemisms.
[0219] The large language model GPT-3 achieved an accuracy of 0.665, surpassing KEYMAT and approaching Text Moderation, demonstrating the potential of leveraging language model internal knowledge for harmful text detection. However, its contribution is far less than that of supervised learning-based methods (BERT, which achieved an accuracy of 0.796). One possible reason for this is that GPT-3's training data lacked annotations for harmful text, making it difficult for it to understand its characteristics.
[0220] Furthermore, pre-trained language models based on dynamic word embeddings (BERT and RoBERTa) generally outperform models based on static word embeddings (Bi-LSTM and CNN-GRU). Among these baseline models, RoBERTa is relatively more effective in detecting harmful text. COLDetector trained on the COLDataset performs worse than the BERT baseline model trained on the IMPTOX dataset. This demonstrates the higher quality and less noise of the IMPTOX dataset, effectively alleviating current dataset resource constraints and contributing to research on harmful text detection in Chinese.
[0221] Experimental results show that the IHTD-KML model proposed in this paper significantly outperforms various advanced keyword models and neural network models in harmful text detection, demonstrating the effectiveness of euphemism feature fusion, potential meaning knowledge enhancement, and multi-task learning training in IHTD-KML.
[0222] 3.4 Hidden Harmful Text Detection Experiment
[0223] This experiment was conducted on the more difficult implicit euphemism test set HardTest, which contains samples with hidden language attack behaviors that are difficult for detectors to handle, such as euphemistic harmful texts, in order to analyze the detection performance of the implicit harmful text task. The results are shown in Table 3 and are Figure 4 A more vivid comparison is given in .
[0224] Table 3 Experimental results of hidden harmful text detection using baseline model and IHTD-KML
[0225]
[0226] As shown in the table, with the exception of the proposed IHTD-KML model, the detection accuracy of the remaining models on the implicit euphemism test set decreased significantly compared to the previous experiment's detection of harmful text, dropping by an average of approximately 4%. This is because many implicitly harmful examples containing euphemisms are incorrectly classified as harmless due to the lack of explicit insulting words. This shows that difficult examples still pose a significant challenge to current harmful text detectors. This suggests that understanding and detecting difficult examples warrants further research to develop more robust detectors.
[0227] like Figure 4 As shown in the figure, based on the overall accuracy metric, the IHTD-KML model achieved a significant lead over all compared models (with an accuracy of 0.852). By incorporating euphemism lexical features, enhanced knowledge of latent meanings, and a multi-task learning framework, the IHTD-KML model improves its ability to discern implicit meanings, thereby enhancing its ability to detect implicitly harmful text. Consequently, on the implicit euphemism test set, HardTest, the IHTD-KML model's detection accuracy only slightly decreased (approximately 0.01%), significantly outperforming the previous state-of-the-art TKE model by 6.9% and leading the text censorship model by 24.4%.
[0228] Overall, the IHTD-KML model achieved experimental performance significantly better than the other methods on both test sets, proving that the IHTD-KML model can not only effectively detect conventional explicit harmful text, but also identify implicit euphemisms and implicit harmful text, effectively improving the detection performance in current research.
[0229] 3.5 Module Ablation Experiment
[0230] To evaluate the improved detection performance brought about by the euphemism feature fusion, latent meaning knowledge enhancement, and multi-task learning mechanism proposed in this chapter, this experiment conducts a module ablation experiment of the IHTD-KML framework on the IMPTOX dataset to show the contribution of each component and mechanism to the harmful text detection task. The specific ablation comparison model settings are as follows:
[0231] 1) IHTD-KML(-lexicon): removes euphemistic vocabulary feature fusion and retains the rest;
[0232] 2) IHTD-KML(-imp): removes the latent meaning knowledge enhancement and retains the rest;
[0233] 3) IHTD-KML(-MTL): removes the multi-task learning framework and retains the rest;
[0234] Table 4 Ablation experiment results of IHTD-KML model
[0235] Model Accuracy Precision Recall F1 IHTD-KML(Ours) 0.863 0.865 0.859 0.862 TKE 0.814 0.816 0.811 0.813 IHTD-KML(-lexicon) 0.857 0.861 0.851 0.856 IHTD-KML(-imp) 0.845 0.847 0.842 0.844 IHTD-KML(-MTL) 0.821 0.816 0.829 0.824
[0236] The ablation experiment results of each component of the IHTD-KML framework are shown in Table 4.
[0237] As can be seen, the complete IHTD-KML framework performs best, demonstrating that the various mechanisms proposed in this paper can improve the detection of implicitly harmful text from multiple perspectives. Specifically, after removing the euphemism feature fusion, the F1 score dropped by 0.6%; after removing the latent meaning knowledge enhancement, the F1 score dropped by 1.8%; and after removing the multi-task learning framework, the F1 score dropped by 3.8%. However, the ablation model with any module removed outperformed the previous state-of-the-art TKE baseline model.
[0238] The observation that IHTD-KML(-MTL) performed the worst demonstrates the importance of multi-task learning for implicitly harmful text detection. Because euphemism detection is used as an auxiliary task within the multi-task learning framework, it integrates prior knowledge of euphemisms and jointly learns commonalities through shared features across tasks, thereby improving the performance of implicitly harmful text detection. The multi-task learning framework further improves the model's detection rate through multi-task parameter sharing and a multi-feature fusion loss function, enabling the model to effectively identify and understand euphemisms in implicitly harmful Chinese text.
[0239] In addition, the performance gap between IHTD-KML (-lexicon) and the full IHTD-KML is minimal, indicating that euphemism feature integration contributes minimally to harmful text detection, but it also improves the model's detection rate. One possible reason is that the BERT model used to extract sentence semantics has been pre-trained with euphemism knowledge, so integrating euphemism features into sentence embeddings alone only marginally improves performance.
[0240] After removing the latent meaning knowledge enhancement, the detection performance of IHTD-KML(-lexicon) decreased significantly, which indicates that IHTD-KML can benefit from the common features among a group of implicit harmful speeches with shared meaning when detecting implicit harmful sentences expressed in euphemisms.
[0241] In order to more intuitively display the results of the IHTD-KML module ablation experiment, Figure 5 The results are visualized using bar charts, showing the comparison between the ablated model and the previous state-of-the-art model, TKE, as well as the comparison between the ablated models themselves. It can be seen that each module contributes differently to the hidden harmful text detection task, and the ablated model with any module removed outperforms the TKE baseline model.
[0242] 3.6 Model Generalization Experiment
[0243] To verify that the proposed model IHTD-KML has good generalization ability, a model generalization experiment was conducted using the SWSR dataset. The SWSR dataset contains 8,969 comments labeled as sexist or non-sexist. Sexist comments cover subcategories such as stereotypes based on appearance or cultural background, micro-insults, and sexual aggression.
[0244] Explore whether the IHTD-KML model designed for implicit harmful text detection can effectively detect the sexist dataset for studying the generalization ability of the model. In the experiment, the SWSR dataset was divided into 8:1:1. The generalization ability of the models that performed well in the implicit harmful text detection task was evaluated on the SWSR test set.
[0245] Due to the adaptation of the model architecture to the dataset, some baseline models, such as the TKE model, were removed in this experiment.
[0246] The experimental results are shown in Table 5. It can be seen that the accuracy of the IHTD-KML model on the SWSR test set reached 0.858, far higher than the accuracy of the most advanced model RoBERTa in the SWSR paper, which is 0.797. And the IHTD-KML model has a large leading advantage in all metrics compared with other models. The F1 value is 7.4% higher than that of the BERT model and 18.4% higher than that of the BAIDUTC model.
[0247] Since the sexist language in the SWSR dataset contains a large number of euphemisms, such as "green tea bitch" and "corpse hanging", the detection accuracy of each baseline model for harmful text detection is lower than 0.8. However, the IHTD-KML model still achieved relatively ideal detection results. This shows that the IHTD-KML model designed for implicit harmful text detection based on knowledge-enhanced multi-task learning also performs well and has strong generalization ability when applied to the field of sexism.
[0248] Table 5 Experimental Results of the IHTD-KML Model on the SWSR Dataset
[0249]
[0250] 3.7 Dataset Augmentation Experiment
[0251] To verify the effectiveness of the augmented data generated by the language model in the IMPTOX dataset, a dataset augmentation experiment was conducted in this experiment.
[0252] This experiment investigated how augmented data improves each classifier's ability to detect implicitly harmful text. Specifically, each baseline model from the harmfulness experiment, including the Bi-LSTM, CNN-GRU, RoBERTa, and TKE models, was further trained and fine-tuned using 240,000 augmented data items from the IMPTOX dataset. The improved performance was then compared on the test set, as shown in Table 6.
[0253] Among them, the "*" indicates the results of each model after further training on the enhanced dataset.
[0254] As shown in Table 6, overall, fine-tuning the baseline model on the IMPTOX augmented data improves the performance of all models, including our proposed IHTD-KML model, demonstrating the effectiveness of using language models to generate augmented data.
[0255] Specifically, in terms of the F1 value indicator, the Bi-LSTM model improved by 3.4%, the CNN-GRU model improved by 2.2%, the RoBERTa model improved by 2.1%, the TKE model improved by 2.4%, and the IHTD-KML model improved by 3%.
[0256] The improved performance on the test set demonstrates that IMPTOX-augmented data can be used to improve existing classifiers, helping them better tackle the challenging task of detecting harmful text using implicit euphemisms.
[0257] The further fine-tuned IHTD-KML model performed strongly on the test set, with an F1 value of 0.892, indicating that the dataset and detection model proposed in this paper can successfully help detect harmful text.
[0258] Table 6 Experimental results of baseline model and IHTD-KML dataset enhancement
[0259]
[0260]
[0261] One possible reason for this improvement is that the large-scale augmented data provides rich lexical information, which improves the model's ability to detect harmful text in a variety of expressions. Because this data, generated by the pre-trained language model, provides diverse language expressions, including a large amount of data that the detector has never seen, it leads to significant performance improvements, a view confirmed in this experiment.
[0262] In summary, the technical solution provided by the present invention can achieve efficient detection of implicit harmful text through knowledge enhancement and multi-task learning, with high detection rate and accuracy, and high detection efficiency.
[0263] Furthermore, on the basis of achieving the above-mentioned beneficial effects, each preferred scheme also achieved the following beneficial effects: introducing existing data sets can improve training efficiency and the accuracy of the trained model; data filtering and data enhancement can help improve the accuracy of model detection; training the model can ensure the accuracy and efficiency of detection; the fusion of euphemism features, the enhancement of potential meaning knowledge and the task learning framework can all help improve detection efficiency and accuracy.< / text> < / topic>
Claims
1. A method for detecting implicit euphemisms and harmful texts based on knowledge-enhanced multi-task learning, characterized by: The following steps are involved: Step S1: crawl the keywords of the preset topic through the social network platform to construct the original data set; Step S2: Filter and label the original data set in sequence to generate a classified data set classified by preset labels; Step S3: Build a hidden harmful text detection model and train the hidden harmful text detection model using a classification dataset; The implicit harmful text detection model includes a euphemism feature fusion module, a potential meaning knowledge enhancement module and a multi-task learning framework; Step S4: Input the text to be detected into the trained implicit harmful text detection model and output the detection result; Step S1 also includes data enhancement; (1) Generate implicit harmful text: Get sample text labeled "harmful text" from the ToxiCN dataset or the CDialBias dataset; Passing sample text to the language model through the prompt module to generate implicit harmful text; The transfer formula of the prompt module is as follows: ; Where, represents the probability distribution of implicitly harmful text, Indicates a special classification mark. Indicates the first vocabulary, Indicates the subject of the sample text, a label representing the sample text, is the number of words in the sample text, , is the mask mark; Detect toxicity of implicitly harmful texts through toxicity classifiers; (2) Restricted beam search adversarial decoding: Based on the language model, the Topk algorithm is used to sample implicitly harmful texts that have been tested for toxicity to obtain a vocabulary toxicity table. Perform restricted beam search decoding of size 2 on the lexical toxicity table and decode the candidate words obtained; Generate adversarial text based on implicitly harmful text and candidate word concatenation, and detect the toxicity of the adversarial text through a toxicity classifier; Compare the candidate words with the adversarial text to see if they are toxic; Among them, soft constraints are imposed on the toxicity classifier. ; Where, From the beginning of the sequence to A sequence of words, is the hyperparameter of the language model’s contribution to the decoding score function, is the hyperparameter of the classifier’s contribution to the decoding score function, The probability of a word in a given context given by the language model, The probability that the entire sequence belongs to the corresponding class given to the toxicity classifier; Based on the results of toxicity countermeasures, we select words with the lowest probability of being harmful and generate implicitly harmful enhanced texts through language models, i.e., harmful texts that are implicitly euphemistically expressed. In step S3, The euphemism feature fusion module includes an input layer, an encoding layer and a feature fusion layer; The potential meaning knowledge enhancement module includes a contrastive learning layer and a shared encoding layer; The multi-task learning framework includes a harmful text detection subtask, a euphemism identification subtask, and a loss function; In step S3, the training specifically includes: (1) Euphemism feature fusion module: Vocabulary in classification dataset ,exist ; ; Where, Representation vocabulary Ontology of semantic relations between words in is a set of unordered tuples consisting of elements in the classification data set, For vocabulary Middle vocabulary, For vocabulary The number of words in ; Vocabulary Every word in , use BERT to learn the corresponding word vector , ; Where, is the word vector set, For word vector length, Representing word vectors Dimensions; Extract the synonym relationship in its word meaning dictionary, that is, extract all the word vectors from all unordered bigrams and its semantic neighbor word vectors The two-tuple formed; Iteratively correct word vectors , get improved word vector , minimize the objective function , ; ; ; Where, and To control the word vector and word vectors The relative strength of the correlation between For word vector Improved word vectors, To improve word vectors A set of improved word vector sets The initial values and word vector sets of all elements in The corresponding word vectors are equal; Based on improved word vector set Encode the original input text from the classification dataset to generate the initial text representation vector; Introduce a euphemism dictionary, based on the words that belong to the original input text and the euphemism dictionary , integrating the initial text representation vector with the vocabulary The corresponding euphemism word feature vector generates the text representation vector ; (2) Potential meaning knowledge enhancement module: Perform positive sample sampling on the set of text representation vectors generated based on the classification dataset, ; Where, For the current batch Input text representation vector The positive sample of Indicates the first text representation vectors, Represents positive sample sampling; if ,but ;like ,but ; Use the latent meaning as a positive sample for contrastive learning, generating contrastive loss , ; Where, is the number of input text representation vectors, It is the common serial number of the text representation vector and the positive sample input sampling module IMP, Indicates the first text representation vectors, Indicates the encoding representation, represents the indicator function, is the scalar temperature parameter; Calculate the loss function corresponding to hidden harmful text detection , ; Where, is the weight coefficient, is the cross entropy loss function; ; Where, Representing vectors for text The model predicts the probability of Representing vectors for text The true label of Minimize the loss function , output the text representation vector enhanced by the knowledge of latent meaning, i.e., harmful latent features; (3) Multi-task learning framework: Includes harmful text detector , euphemism detector and parent harmful text detector : Harmful text and euphemism text Input BERT shared encoding layer, corresponding output harmful potential features and potential characteristics of euphemisms ; based on Training a Harmful Text Detector ;in, Is a harmful sequence number, is the number of harmful texts entered, , For the The harmful potential features corresponding to harmful texts, For the The pseudo labels corresponding to harmful texts are obtained by pre-combining the harmful labels and the enhanced euphemism labels; based on Training a euphemism detector ;in, is the text number of the euphemism sentence, is the number of euphemism texts input, , is the potential feature of the euphemism corresponding to the euphemism text, For the euphemism text corresponding to; By using harmful text detector Predict the harmful label for each harmful text , through the euphemism detector Predict euphemism labels for each harmful text; Harmfulness labels based on harmful text Constructing multi-label learning data with euphemistic labels ;in, ; ; Where, Represents the concatenation operator, Euphemism Detector For text samples Original euphemism label prediction, is a sharpened pseudo-euphemism label, ; Where, is the second temperature hyperparameter; Learning data with multi-label Training the Parent Harmful Text Detector , specifically including: By Parent Harmful Text Detector Predicting harmful potential traits Enhanced original harmful label prediction , ; Where, Represents the parent harmful text detector The number of basic blocks included, Represents trainable parameters; Among them, the basic block includes two layers of fully connected networks, ; Where, Indicates input, is a trainable parameter, and Both are activation functions; By minimizing harmful text and harmfulness labels for harmful text The difference between the two, training the parent harmful text detector , ; Where, Harmful Text Detector for Parents losses, For harmful text collection, represents the focal loss, For harmful text prediction components, represents the mean square error loss, Predicting components for euphemisms.
2. The method for detecting implicit euphemisms and harmful texts based on knowledge-enhanced multi-task learning as claimed in claim 1, characterized in that: Step S1 further includes: When constructing the original dataset, at least one of the SWSR dataset, the COLD dataset, and the CDialBias dataset is introduced.
3. The method for detecting implicit euphemisms and harmful texts based on knowledge-enhanced multi-task learning as claimed in claim 1, characterized in that: The data filtering includes: Remove repeated sentences, advertisements, extra line breaks, spaces, and phrases containing only word forms and auxiliary verbs, as well as "@user", links, and images; Delete the synthetic data generated by the language model with perplexity values less than 10 and greater than 100.
4. The method for detecting implicit euphemisms and harmful texts based on knowledge-enhanced multi-task learning as claimed in claim 1, characterized in that: The data annotation includes: For the original data set that has been filtered, a preset number of data are classified through manual labeling and classification; Use the classified data to initialize the classifier, and then use the toxicity classifier to classify the unlabeled data; The dataset obtained by the toxicity classifier is divided into a preset number of buckets, and data from each bucket is randomly extracted according to a preset ratio. If the labeling accuracy of the extracted data is not lower than the preset value, the data in the corresponding bucket is added to the classification dataset. Otherwise, manually label the data in the corresponding bucket and then add it to the classification dataset; Among them, the labels used for classification include "harmful text" and "harmless text".
5. The method for detecting implicit euphemisms and harmful texts based on knowledge-enhanced multi-task learning as claimed in claim 4, characterized in that: The data annotation also includes: For harmful texts, we build a swear word vocabulary based on the WSR dataset and the ToxiCN dataset. Use regular expressions to match swear words in the text and include other swear words in the swear words; Assign a pseudo-label to each swear word text; Iterate the preset rounds and assign the "non-toxic text" label to the text that has not been assigned a pseudo label.
6. The method for detecting implicit euphemisms and harmful texts based on knowledge-enhanced multi-task learning as claimed in claim 1, characterized in that: The prompt template includes a range prompt template and a category prompt template; The language model is a GLM language model; The toxicity classification is a fine-tuned COLDETECTOR model; , the maximum generation length is 30 tokens, the bundle size is 10, and the first temperature hyperparameter is 0.9.
Citation Information
Patent Citations
Hidden hatred speech detection and fine classification method and device based on combined comparative learning
CN116303995A
Chinese social media few-sample standing detection method based on theme enhancement
CN117910466A