Knowledge-enhanced multi-task learning-based implicit tactic harmful text detection method

Through the method of enhancing multi-task learning based on knowledge, an implicit harmful text detection model is constructed, which solves the problem of implicit euphemistic harmful text detection in the existing technology, and achieves efficient and accurate detection effects.

CN119577585AActive Publication Date: 2025-03-07SICHUAN UNIV

Patent Information

Application Number
CN202411762618.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-03
Publication Date
2025-03-07
Estimated Expiration
2044-12-03

AI Technical Summary

Technical Problem

The prior art is difficult to effectively detect implicit euphemistic harmful texts, resulting in low detection rates and limited accuracy.

Method used

Using a detection method based on knowledge-enhanced multi-task learning, we can identify and detect implicit euphemistic harmful texts by constructing an implicit harmful text detection model, including euphemistic vocabulary feature fusion module, potential meaning knowledge enhancement module and multi-task learning framework.

Benefits of technology

It realizes efficient detection of implicit euphemistic harmful texts, has a high detection rate and accuracy rate, and improves detection efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119577585A_ABST
    Figure CN119577585A_ABST
Patent Text Reader

Abstract

The invention provides an implicit harmful text detection method based on knowledge enhancement multi-task learning, and relates to the technical field of network security. The method comprises the following steps: crawling keywords of a preset theme through a social media platform, and constructing an original data set; performing data filtering and data labeling on the original data set in sequence, and generating a classification data set classified according to a preset label; constructing an implicit harmful text detection model, and training the implicit harmful text detection model through the classification data set; wherein the implicit harmful text detection model comprises a gentle vocabulary feature fusion module, a potential meaning knowledge enhancement module and a multi-task learning framework; and inputting a to-be-detected text into the trained implicit harmful text detection model, and outputting a detection result. According to the method, efficient detection of the implicit harmful text can be achieved through knowledge enhancement and multi-task learning, the detection rate and accuracy are high, and the detection efficiency is high.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of network security, and in particular to a method for detecting implicit euphemistic harmful text based on knowledge-enhanced multi-task learning. Background Art

[0002] With the rapid development of the Internet, the rise of social media has led to the proliferation of a large amount of harmful text content. Harmful text refers to rude, disrespectful or unreasonable speech that is likely to cause others to leave the discussion and cause psychological trauma to others. It usually includes offensive language and hate speech. In order to circumvent the detection of the platform content review mechanism, malicious users usually consciously choose to use implicit euphemisms when posting harmful texts to avoid obvious abusive language. Implicitly expressed harmful texts usually contain euphemisms, which are constructed in ways such as deformation, homophony, irony, abbreviations, metaphors, and mixtures. This type of harmful text not only has a negative impact on society, but is also very difficult to detect. Under existing detection methods, the detection rate of implicitly expressed harmful texts is low and the accuracy is limited. 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 texts 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: filtering and labeling the original data set in turn to generate a classified data set classified by preset labels;

[0007] Step S3: constructing an implicit harmful text detection model, and training the implicit harmful text detection model through a classification data set;

[0008] Among them, the implicit harmful text detection model includes a euphemism feature fusion module, a potential 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 that only contain word forms and auxiliary verbs, 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 data set obtained by the toxicity classifier is divided into a preset number of buckets, and the data in 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 data set;

[0019] Otherwise, manually label the data in the corresponding bucket and then add it to the classification data set;

[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 vocabulary of dirty words based on the WSR dataset and the ToxiCN dataset.

[0023] Match the dirty words text containing dirty words through regular expressions, and collect other dirty words in the dirty words text;

[0024] Assign a pseudo label to each swear word text;

[0025] Iterate the preset rounds and assign the “non-toxic text” label to the texts that are not assigned pseudo labels.

[0026] Furthermore, step S1 also includes data enhancement;

[0027] (1) Generate implicit harmful text:

[0028] Get sample text with the “harmful text” label 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]w 1 ,w 2 ,...,<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 sample text, l is the number of words in the sample text, i = 1, 2, ... l, [sMASK] is the mask tag;

[0033] Detect the toxicity of implicitly harmful texts through toxicity classifiers;

[0034] (2) Restricted beam search against decoding:

[0035] Based on the language model, the Topk algorithm is used to sample implicitly harmful texts that have been tested for toxicity, and a vocabulary toxicity table is obtained;

[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 implicit harmful text and candidate word concatenation, and detect the toxicity of adversarial text through toxicity classifier;

[0038] Compare the candidate words with the adversarial text to see if they are toxic;

[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] In the formula, 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 corresponding to 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 recognition 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={w 1 ,w 2 ,...,w j ,...,w n };

[0056] Where V Ω represents the ontology of semantic relations between words in the vocabulary V, E is the set of unordered tuples of elements in the classification dataset, and 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] In the formula, is a word vector set, d is a 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=[q 1 ,q 2 ,...,q j ,...,q n ], q j ∈R d ;

[0065] In the formula, α j and β jk To control the word vector and word vectors The relative strength 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] Encode the original input text from the classification dataset based on the improved word vector set Q to generate an initial text representation vector;

[0067] A euphemism dictionary is introduced, and based on the words w that belong 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] In the formula, The text representation vector x of the mth input in the current batch m The positive sample, x p represents the pth text representation vector input in the current batch, 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 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, and I [·] represents the indicator function, τ is the scalar temperature parameter;

[0075] Calculate the loss function corresponding to invisible harmful text detection

[0076]

[0077] Where λ is the weight coefficient, L ce is the cross entropy loss function;

[0078]

[0079] In the formula, 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., the harmful latent feature;

[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 latent features z h and potential features 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 Through the euphemism detector f eup Predict euphemism labels for each harmful text;

[0087] Harmful labels based on harmful text Constructing multi-label learning data with euphemistic labels in,

[0088]

[0089]

[0090] In the formula, Represents the concatenation operator, f is the euphemism detector eup For a text sample x h Original euphemistic label prediction, is a sharpened pseudo-euphemism label,

[0091]

[0092] Where T is the second temperature hyperparameter;

[0093] Learning data with multiple labels Training the parent harmful text detector f super , 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 trainable parameters;

[0097] Among them, the basic block includes two layers of fully connected networks,

[0098]

[0099] In the formula, x represents the input, are trainable parameters, δ(·) and σ(·) are activation functions;

[0100] By minimizing harmful text and harmful labels for harmful text The difference between 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 focal 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 realize efficient detection of implicit harmful text through knowledge enhancement and multi-task learning, has a high detection rate and accuracy, and has a high detection efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0104] Figure 1 It is a schematic diagram of the process framework of data enhancement 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 between 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 detail with reference to 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] 1.1. Data collection strategy

[0114] The diversity of data sets is increased mainly through two methods: existing data sets and keyword crawling.

[0115] The real-world data crawls published posts from three public online media platforms that have a large number of users and active communities on specific topics.

[0116] The 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 investigated 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 that only contain word forms and auxiliary verbs. In addition, we delete some useless data, including duplicate samples and irrelevant advertisements. In the data cleaning stage, the unique expressions in the network text are normalized. In addition, the extra line break characters and spaces in the original text are also deleted. In order to prevent the data set from causing privacy leakage, the crawled data are desensitized and @ users, attached links and pictures are filtered out. Since emoticons may carry important emotional information, they are retained for the detection of harmful content.

[0128] The data collected by the language model crawler and related academic datasets are used as prompts to generate synthetic data, and their quality varies. Therefore, for the synthetic data generated by the language model, the perplexity index is used to filter out the unfluent generated texts, and only the synthetic data with perplexity values ​​between 10 and 100 are retained. This part of machine sentences is largely indistinguishable from human-written sentences.

[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 index of the average negative log-likelihood of the sequence. If there is a tokenized sequence X = (x 0 ,x 1 ,...,x t ), its perplexity PPL(X) is:

[0130]

[0131] In the formula, log θ (x i |x <i ) is the previous token x <i The log-likelihood of the ith token conditioned on . Intuitively, this is an assessment of the model’s ability to make uniform predictions across a given set of tags 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. It is also equivalent to the power of the cross entropy between the data and the model’s predictions.

[0132] (2) Data Labeling

[0133] The data generated by the large language model is used for data enhancement training in the present invention, rather than for the final test set, so 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 use 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 explicit harmful text, we established an explicit swear word vocabulary that integrates existing Chinese insult word resources including SWSR and ToxiCN. An iterative approach is adopted to match text content with profanity using regular expressions, and further collect the profanity contained in these samples that are not in the vocabulary. Each sentence containing insults is assigned a harmful pseudo-label, and after several rounds of iterations, the remaining samples are directly pseudo-labeled as harmless to be re-labeled in a hierarchical manner.

[0135] 1.3 Data Augmentation Methods

[0136] The present invention designs a data augmentation framework GENIMP (Generate Implicit Harmful Textdata augmentation framework), adopts a data augmentation method based on prompt learning, designs two sets of prompt templates for the scope and type of data sets, and adds adversarial learning scenarios to control the implicitness of harmful data. Synthetic data with a small amount 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. First, an example-based hint learning method is used to motivate the language model to generate implicit euphemisms that do not use explicit insulting words. 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 and 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 implicit harmful texts that have been toxicity-checked 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 implicit harmful text and candidate words, and detect the toxicity of adversarial text through toxicity classifier;

[0141] GENIMP expands and enriches the scope and diversity of data by prompting language models to generate euphemistic harmful text, mainly generating insulting speech with implicit language rather than explicit foul language. To achieve this goal, this framework performs example-based prompt engineering, with examples from seed samples with harmful labels in the ToxiCN dataset and CDialBias dataset. The seed example sentences are obtained and passed to the generative language model using the prompt template 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 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 given by the language model in a given context 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 probability 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 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 (ChineseOffensiveLanguageDetection, 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 representation ability of implicit meaning; then, the potential meaning knowledge enhancement based on contrastive learning is studied to learn the common features of implicit harmful speech with shared meaning; finally, the euphemism recognition task and the harmful text detection task are combined to construct a multi-task learning framework, and the detection performance of the model is improved through multi-task parameter sharing and multi-feature fusion loss function. The technical architecture diagram of implicit harmful text detection based on knowledge-enhanced multi-task learning is shown in the figure below: Figure 2 shown.

[0147] 2.1 Fusion of euphemism features

[0148] Implicitly expressed harmful texts usually contain euphemisms, so knowledge of euphemism vocabulary is very important for identifying such harmful texts. The present invention proposes a method for improving vector space representation by using relational information in a semantic dictionary, and by stimulating related words to have similar vector representations, euphemism vocabulary features are incorporated into word vector representation.

[0149] The word embedding is enhanced by modifying the original word vector to fit the semantic dictionary. This method extracts synonym relationships from the semantic dictionary and "modifies" the word embedding through belief propagation so that the vectors of synonyms are closer in the vector space. The vocabulary in the corpus is defined as V = {w 1 ,...,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 edges Indicates a related semantic relationship, which is a synonym relationship 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 the vector representation Where d is the length of the word vector. The goal of this method is to learn the matrix Q = (q 1 ,...,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 Figure 1, 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 nodes are the improved Q vectors (with the dictionary relationship V Ω correspond).

[0150] The Euclidean distance is used to define the similarity distance between a pair of vectors. Since we want the inferred word vector to be 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 related to a q i The first derivative of the vector is set to zero, resulting in the following online update:

[0153]

[0154] In the formula, α j and β jk To control the word vector and word vectors The relative strength value of the correlation between them. 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.

[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, the euphemistic vocabulary feature fusion method can be applied to word vector representations obtained from any model. By improving the representation vectors in implicitly expressed harmful texts, the detection performance of identifying such euphemistic harmful texts can be improved.

[0156] 2.2 Potential Meaning Knowledge Enhancement

[0157] Although implicit harmful texts differ in form and language, most of them have common latent meanings, such as discrimination against women or specific regions. The present invention proposes a positive sample sampling strategy based on hidden meaning: that is, using generated texts with the same latent meaning as positive samples for given implicit harmful speech. Despite different presentation forms, some implicit harmful speech implies similar harmful biases. People who post harmful speech often project a meaning into posts in various lexical forms. Inspired by the relationship between meaning and implicit harmful speech in various lexical forms, we propose to use the latent meaning of harmful speech as positive samples. By linking an implicit harmful speech and 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 implicit meaning, thereby achieving a more efficient harmful speech detector. We design a prompt word template that contains input samples and harmful data categories (such as sexism). By revealing the examples of input samples and their harmful categories, the large language model ChatGLM is encouraged to output generated text with the same latent meaning as the given sample. This generated text can be used as a positive sample for potential meaning knowledge enhancement.

[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, fine-tuning using only the cross-entropy loss may lead to suboptimal generalization due to the limitations of the cross-entropy loss in producing large inter-class margins or intra-class compactness. Our proposed implicit harmful text detection framework IHTD-KML utilizes a contrastive learning approach to achieve knowledge enhancement of the implicit meaning of harmful texts, and jointly trains the contrastive loss with the 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 each sample has a positive 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 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] Where · 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 that uses 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 the present invention uses multi-task learning and selects the euphemism detection task as an auxiliary task, aiming to integrate the prior knowledge of euphemism language and jointly learn commonalities through shared features to increase the performance of the model.

[0170] Through careful analysis, we found that the implicit harmful data set contains a large number of euphemistic sentences, such as various homophones, similar forms, and euphemisms with cryptic meanings. Based on this premise, the euphemism detection task is selected as an auxiliary task in this framework to improve the detection performance of implicit harmful text by sharing useful information.

[0171] This framework explores implicit harmful text detection from the perspective of multi-label learning (MLL), where each training sample 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 to generate harmful text label predictions enhanced by euphemism knowledge. To address the problem that euphemism labels are actually unknown, this framework integrates the 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, which connects harmfulness prediction and euphemism prediction as latent features, and connects the real harmfulness label 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 latent 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 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] In the formula, is the concatenation operator, q he Yes he The sharpened version of the 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] In the formula, Π={Π 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 the two is used to train the parent harmful text detector as follows:

[0190]

[0191] Where β∈[0,1] is a hyperparameter, FL(·) represents the focal loss, MSE(·) represents the mean square error, and They represent the harmful text prediction component and the euphemistic sentence prediction component respectively.

[0192] Finally, IHTD-KML enables harmful speech and euphemisms to be exchanged not only at a low-sharing 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 thus 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 targets three domestic public online media platforms, including Topic 1, Topic 2, Topic 3 and Main 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. In order 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, which contains samples with hidden language attack behaviors that are difficult for the detector to handle, such as euphemistic harmful text, to specifically evaluate the performance of the model on implicit samples.

[0196] 3.2 Baseline Methods

[0197] In order to verify the performance of the proposed IHTD-KML framework on the hidden harmful detection task, we considered the following baseline methods to conduct model comparison experiments. The specific details are as follows:

[0198] Keyword matching (KEYMAT):

[0199] Keyword matching is a common method used by domestic social platforms to filter harmful text. In this experiment, 14k sensitive words published on Github were used as harmful keywords, and text containing any keyword in the word list was considered harmful text.

[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 whether the text is harmful for binary classification.

[0202] Bi-LSTM (Bidirectional Long Short-Term Memory): Bi-LSTM is a commonly used neural network baseline model in text classification tasks. In this experiment, the word embedding trained by AI Lab with static word embeddings with 200-dimensional features is used as the embedding layer. Bi-LSTM is used to integrate context information to connect the last hidden states in the forward and reverse directions 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 convolution-gated recurrent units, applied to extract latent semantic features using word embeddings to detect hate speech. The model captures word sequence and order information in the text to better identify latent semantic features.

[0204] BERT: A commonly used Chinese pre-trained language model based on Transformer encoder, widely used as a baseline method in harmful text research. In this experiment, the bert-based-chinese pre-trained model is used, and the hidden layer connection output of the encoder is used as the input of the fully connected layer connection classifier.

[0205] RoBERTa (Robustly Optimized BERT Pretraining Approach, a natural language processing model): RoBERTa is an improved model of the BERT model, which has been optimized in terms of MASK strategy, training data volume, and pre-training tasks. This experiment uses the pre-training parameters in roberta-base-chinese.

[0206] COLDetector (Chinese Offensive Language Detection): An offensive language detection model. The model uses a Transformer-based architecture and is based on the pre-trained model BERT. All parameters of the COLDetector model are trained on the COLDataset using the cross-entropy loss function. COLDetector takes the first hidden state of the last layer of BERT (corresponding to the [CLS] tag) as the 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 an insult vocabulary that attacks different target groups. Based on the insult vocabulary, Lu et al. designed a toxic knowledge-enhanced baseline TKE model that includes lexical features to enrich text representation for harmful text detection.

[0208] GPT-3: The internal knowledge stored by the model during pre-training can be used to detect offensive language. In this experiment, the detection performance based on prompt learning in a zero-shot setting is explored. Given the text TEXT to be evaluated, the input of the model is constructed as: "TEXT" Please judge whether the above content is malicious or offensive? Answer: [MASK]. Use the GPT-3 model to predict the score of the [MASK] tag. The scores of the yes and no candidate words are used as the self-detection 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 was trained using the AdamW optimizer, with the batch size set to 64 and the learning rate set to 1e-5. It was trained for 10 epochs (iterations), and the early stopping mechanism was applied during the training phase. Ten-fold cross validation was used for training in the experiment, and the average results were reported. This experiment fine-tuned all baseline models, selected the best performing model and hyperparameters on the validation set, and evaluated the performance on the test set. The same experiment was repeated 5 times by changing the random seed to reduce the error. Model training and all experiments in this work were 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 are 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 the performance of the model against nine baseline methods on the IMPTOX dataset. Table 2 below shows the harmful text detectability 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 can be seen from the table, compared with the other models, the IHTD-KML proposed in this invention shows the best results in each indicator, and is significantly ahead of the previous most advanced model TKE model by 4.9% in F1 value, and exceeds the baseline model BERT commonly used in harmful text detection tasks by 6.5%. Compared with the TKE model, which simply enhances the insult vocabulary knowledge based on harmful categories, IHTD-KML runs belief propagation on the graph constructed by the relationship information derived from the harmful dictionary to update the word vector, which can better introduce euphemism knowledge. In addition, IHTD-KML combines the auxiliary task of euphemism detection, and jointly learns commonalities through shared features to increase the harmful text detection performance of the model.

[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 the detection accuracy. However, with the continuous emergence of new words and the diversification of vocabulary in harmful texts, it is almost impossible to achieve complete coverage, which leads to a low recall rate of only 0.552 for harmful texts. Second, it is inaccurate to filter potential harmful samples only by matching keywords. This is because these words may appear in both harmful and harmless samples, leading to misclassification.

[0218] Compared with text censorship, deep learning-based methods perform better. A reasonable explanation is that similar online API filtering mechanisms mainly rely on keyword dictionaries and are therefore easily affected by sensitive words. For example, words of praise are identified as harmful text by text censorship because of sensitive words. These false recalls lead to relatively low accuracy in detecting harmful content. In addition, it cannot effectively detect harmful text containing euphemisms.

[0219] For the large language model GPT-3, its accuracy is 0.665, which is better than KEYMAT and close to text auditing, showing the potential of mining the internal knowledge of language models for harmful text detection tasks. However, its contribution is far less than that of supervised learning-based methods (BERT's accuracy is 0.796). One possible reason is that GPT-3's training data lacks annotations for harmful text, making it difficult to understand the characteristics of harmful text.

[0220] In addition, in general, the performance of pre-trained language models based on dynamic word embeddings (BERT, RoBERTa) is worse than that of models based on static word embeddings (Bi-LSTM, CNN-GRU). Among these baseline models, RoBERTa is relatively more effective in the harmful text detection task. COLDetector trained on COLDataset is not as effective as the BERT baseline model trained on the IMPTOX dataset. This shows that the IMPTOX dataset is of higher quality and has less data noise, which effectively alleviates the current dataset resource limitations and is helpful for the research on harmful text detection in Chinese.

[0221] Experimental results show that the IHTD-KML model proposed in this paper is significantly superior to various advanced keyword models and neural network models in harmful text detection, which proves 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 is conducted on the more difficult implicit euphemism test set HardTest, which contains samples with hidden language attack behaviors that are difficult for the detector to handle, such as euphemistic harmful text, 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 of baseline model and IHTD-KML

[0225]

[0226] As can be seen from the table, except for the IHTD-KML model proposed in this invention, the detection accuracy of the remaining models on the implicit euphemism test set is significantly reduced compared with the harmful text detection in the previous experiment, with an average decrease of about 4%. The reason is that many implicit harmful samples containing euphemisms are mistakenly classified as harmless due to the lack of clear insulting words. It can be seen that difficult samples still pose a major challenge to current harmful text detectors. This shows that understanding and detecting difficult samples deserves further research to develop more powerful detectors.

[0227] like Figure 4 As shown in the figure, according to the overall accuracy index, the IHTD-KML model has a significant lead among all the comparison models (accuracy is 0.852). The IHTD-KML model introduces euphemism vocabulary features, potential meaning knowledge enhancement, and a multi-task learning framework to improve the model's ability to recognize implicit meanings, thereby enhancing the ability to detect implicit harmful texts. Therefore, on the implicit euphemism test set HardTest, the detection accuracy of the IHTD-KML model only slightly decreased (about 0.01), and it was significantly ahead of the previous most advanced TKE model by 6.9% and ahead of text review by 24.4%.

[0228] In general, 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 texts, but also identify implicit euphemisms and implicit harmful texts, effectively improving the detection performance in current research.

[0229] 3.5 Module Ablation Experiment

[0230] In order to evaluate the detection effect improvement brought by the fusion of euphemistic vocabulary features, the enhancement of latent meaning knowledge, and the multi-task learning mechanism proposed in this chapter, this experiment conducted 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): remove euphemistic vocabulary feature fusion and keep the rest;

[0232] 2) IHTD-KML (-imp): removes the latent meaning knowledge enhancement and retains the rest;

[0233] 3) IHTD-KML(-MTL): remove the multi-task learning framework and keep 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] It can be seen that the complete IHTD-KML framework performs best, indicating that the various mechanisms proposed in this invention can improve the detection effect of implicit harmful text from multiple angles. Specifically, after removing the euphemistic vocabulary feature fusion, the F1 value dropped by 0.6%; after removing the potential meaning knowledge enhancement, the F1 value dropped by 1.8%; after removing the multi-task learning framework, the F1 value dropped by 3.8%. However, the detection effect of the ablation model after removing any module is better than the previous state-of-the-art TKE baseline model.

[0238] It is observed that IHTD-KML (-MTL) has the worst effect, which shows that multi-task learning is of great significance for implicit harmful text detection. Since the euphemism detection task is used as an auxiliary task in the multi-task learning framework, it can integrate the prior knowledge of euphemisms and jointly learn commonalities through shared features in the task, thereby improving the performance of the implicit harmful text detection task. The multi-task learning framework further improves the detection rate of the model through multi-task parameter sharing and multi-feature fusion loss function, so that the model can effectively identify and understand euphemisms in Chinese implicit harmful texts.

[0239] In addition, the difference between IHTD-KML (-lexicon) and complete IHTD-KML is the smallest, indicating that the fusion of euphemism features has the smallest contribution to harmful text detection, but it also improves the model detection rate. One possible reason is that the BERT model used to extract sentence semantics has been pre-trained with euphemism knowledge enhancement, so the improvement of euphemism features fusion in sentence vectors alone is relatively weak.

[0240] After removing the latent meaning knowledge enhancement, the detection effect 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 meanings 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 bar graph is used for visualization, showing the comparison between the ablation model and the previous most advanced model TKE, as well as the comparison between the ablation models. It can be seen that each module has different contributions to the hidden harmful text detection task, and the ablation model after removing any module is better than the TKE baseline model.

[0242] 3.6 Model Generalization Experiment

[0243] To verify that the proposed model IHTD-KML has good generalization ability, the model generalization experiment was conducted using the SWSR dataset. The SWSR dataset contains 8969 comments marked as sexist or non-sexist. Sexist comments cover subcategories such as stereotypes based on appearance or cultural background, micro-insults, and sexual attacks.

[0244] This paper explores whether the IHTD-KML model designed for implicit harmful text detection can effectively detect gender discrimination datasets, so as to study the generalization ability of the model. In the experiment, the SWSR dataset is divided into 8:1:1, and the generalization ability of the model that performs well in the implicit harmful text detection task is evaluated on the SWSR test set.

[0245] Due to the adaptation of the model architecture and the dataset, some baseline models, such as the TKE model, were deleted 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, which is much higher than the accuracy of 0.797 of the most advanced model RoBERTa in the SWSR paper, and compared with other models, it has a large leading advantage in all indicators, with an F1 value 7.4% higher than the BERT model and 18.4% higher than 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 harmful text detection baseline model is lower than 0.8. However, the IHTD-KML model still achieved relatively ideal detection results, which shows that the IHTD-KML model designed for implicit harmful text detection based on knowledge-enhanced multi-task learning also performs well when applied to the field of sexism and has strong generalization.

[0248] Table 5 Experimental results of IHTD-KML model on SWSR dataset

[0249]

[0250] 3.7 Dataset Enhancement Experiment

[0251] In order to verify the effectiveness of the enhanced data generated by the language model in the IMPTOX dataset, a dataset enhancement experiment was conducted in this experiment.

[0252] This experiment investigates how augmented data can improve the detection ability of each classifier for implicitly harmful text. Specifically, in this experiment, each baseline model in the harmfulness experiment, including Bi-LSTM, CNN-GRU, RoBERTa, and TKE models, is further trained and fine-tuned using 240k augmented data in the IMPTOX dataset, and then the improvement results are 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, illustrating 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 cope with 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 the present invention 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 large-scale augmented data brings rich vocabulary information, which can improve the model's ability to detect harmful text in different expressions. Because these data generated by the pre-trained language model can provide different language expressions, including a large amount of data that the detector has not seen, it brings a more significant performance improvement, which is 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 has 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 detection accuracy and detection efficiency; euphemistic vocabulary feature fusion, potential meaning knowledge enhancement and task learning framework can all help detection efficiency and detection accuracy.< / text> < / topic>

Claims

1. An implicit euphemism-based harmful text detection method based on knowledge-enhanced multi-task learning, characterized in that: The following steps are involved: Step S1: crawl keywords of preset topics through social network platforms to construct original data sets; Step S2: filtering and labeling the original data set in turn to generate a classified data set classified by preset labels; Step S3: constructing an implicit harmful text detection model, and training the implicit harmful text detection model through a classification data set; 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.

2. The implicit euphemism harmful text detection method based on knowledge enhanced multi-task learning as claimed in claim 1 is characterized in that: Step S1 also includes: When constructing the original dataset, at least one of the SWSR dataset, the COLD dataset, and the CDialBias dataset is introduced.

3. The implicit euphemism harmful text detection method based on knowledge enhanced multi-task learning as claimed in claim 1 is characterized in that: The data filtering includes: Remove repeated sentences, advertisements, extra line breaks, spaces, and phrases that only contain word forms and auxiliary verbs, remove "@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 implicit euphemism harmful text detection method based on knowledge enhanced multi-task learning as claimed in claim 1 is 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 data set obtained by the toxicity classifier is divided into a preset number of buckets, and the data in 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 data set; Otherwise, manually label the data in the corresponding bucket and then add it to the classification data set; 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 vocabulary of dirty words based on the WSR dataset and the ToxiCN dataset. Match the dirty words text containing dirty words through regular expressions, and collect other dirty words in the dirty words text; 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: Step S1 also includes data enhancement; (1) Generate implicit harmful text: Get sample text with the "harmful text" label 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: P(text,topic)=[CLS]w1,w2,...,<topic>,...,<text>,w l [sMASK]; 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 sample text, l is the number of words in the sample text, i = 1, 2, ... l, [sMASK] is the mask tag;< / text> < / topic> Detect the toxicity of implicitly harmful texts through toxicity classifiers; (2) Restricted beam search against decoding: Based on the language model, the Topk algorithm is used to sample implicitly harmful texts that have been tested for toxicity, and a vocabulary toxicity table is obtained; Perform restricted beam search decoding of size 2 on the lexical toxicity table and decode the candidate words obtained; Generate adversarial text based on implicit harmful text and candidate word concatenation, and detect the toxicity of adversarial text through toxicity classifier; The candidate words are compared with the adversarial text to compare their toxicity; Among them, soft constraints are imposed on the toxicity classifier. logp(in i+1 |in 0:i )∝λ L log p LM (In i+1 |in 0:i )+λ C log p CLF (In 0:i+1 ); In the formula, 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; (3) Based on the results of toxicity confrontation, the vocabulary corresponding to 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.

7. The method for detecting implicit euphemisms and harmful texts based on knowledge-enhanced multi-task learning as claimed in claim 6, characterized in that: The prompt template includes a range prompt template and a type prompt template; The language model is a GLM language model; The toxicity classification is a fine-tuned COLDETECTOR model; λ C =λ L = 0.5, the maximum generation length is 30 tokens, the bundle size is 10, and the first temperature hyperparameter is 0.

9.

8. The method for detecting implicit euphemisms and harmful texts based on knowledge-enhanced multi-task learning as claimed in claim 1, characterized in that: 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 contrast learning layer and a shared encoding layer; The multi-task learning framework includes a harmful text detection subtask, a euphemism recognition subtask and a loss function.

9. The method for detecting implicit euphemisms and harmful texts based on knowledge-enhanced multi-task learning as claimed in claim 1, characterized in that: In step S3, the training specifically includes: (1) Euphemism feature fusion module: For the vocabulary V in the classification dataset, there exists V Ω =(V,E); V={w1,w2,...,w j ,...,In n }; Where V Ω represents the ontology of semantic relations between words in the vocabulary V, E is the set of unordered tuples of elements in the classification dataset, and w j is the jth word in the vocabulary V, n is the number of words in the vocabulary V, i = 1, 2, ..., n; For each word w in the vocabulary V j , use BERT to learn the corresponding word vector In the formula, is a word vector set, d is a word vector The length, R d 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 the improved word vector q j , minimize the objective function Ψ(Q), Q=[q1,q2,...,q j ,...,q n ],q j ∈R d ; In the formula, α j and β jk To control the word vector and word vectors The relative strength 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; Encode the original input text from the classification dataset based on the improved word vector set Q to generate an initial text representation vector; A euphemism dictionary is introduced, and based on the words w that belong 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; (2) Potential meaning knowledge enhancement module: Perform positive sample sampling on the set of text representation vectors generated based on the classification dataset, In the formula, The text representation vector x of the mth input in the current batch m The positive sample, x p represents the pth text representation vector input in the current batch, IMP(·) represents the positive sample sampling; if m≤N, then p=m+N; if m>N, then p=mN; Use the latent meaning as positive sample for contrastive learning, generating contrastive loss 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, and I [·] represents the indicator function, τ is the scalar temperature parameter; Calculate the loss function corresponding to invisible harmful text detection Where λ is the weight coefficient, L ce is the cross entropy loss function; In the formula, 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 Minimize the loss function Output the text representation vector enhanced by the latent meaning knowledge, i.e., the harmful latent feature; (3) Multi-task learning framework: Includes sub harmful text detector f sub , euphemism detector f eup and parent harmful text detector f super : x h and euphemism text x e Input BERT shared encoding layer, corresponding to the output of harmful potential features z h and potential features of euphemisms e ; 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; 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; By sub harmful text detector f sub Predict the harmful label for each harmful text Through the euphemism detector eup Predict euphemism labels for each harmful text; Harmful labels based on harmful text Constructing multi-label learning data with euphemistic labels in, In the formula, Represents the concatenation operator, f is the euphemism detector eup For a text sample x h Original euphemistic label prediction, is a sharpened pseudo-euphemism label, Where T is the second temperature hyperparameter; Learning data with multiple labels Training the parent harmful text detector f super , specifically including: By Parent Harmful Text Detector f super Predicting harmful potential traits Enhanced original harmful label prediction Where η represents the parent harmful text detector f super The number of basic blocks included, Π = {Π 1 …Π η } represents trainable parameters; Among them, the basic block includes two layers of fully connected networks, In the formula, x represents the input, are trainable parameters, δ(·) and σ(·) are activation functions; By minimizing harmful text and harmful labels for harmful text The difference between the parent harmful text detector f super , 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 focal loss, is the harmful text prediction component, MSE(·) represents the mean square error loss, Predicting components for euphemisms.

Citation Information

Patent Citations

  • Social network sensitive gensis detection method based on supervised learning

    CN116257698A

  • 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

  • System and method for identification, detection and investigation of maleficent acts

    US20050043961A1

Cited By

  • Multi-source fusion prediction method, device and equipment for karst geological disaster and storage medium

    CN121234175A

  • Artificial consciousness credible interaction control method based on semantic space

    CN121615796A