A method for detecting offensive comments based on multi-dimensional semantic representation
By using a multi-dimensional semantic representation method in offensive comment detection, text vectors for targets and semantic content are generated, and the semantic information relevance is enhanced through the cross-coding mechanism, the problem of single information representation dimensions and weak correlation information in the prior art is solved, and a more efficient offensive comment detection effect is achieved.
Patent Information
- Application Number
- CN202210571526.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-24
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2042-05-24
AI Technical Summary
In the prior art, in offensive comment detection, there are problems such as single information representation dimension, weak correlation information, and poor satirical comment detection.
An offensive comment detection method based on multi-dimensional semantic representation is proposed. The text multi-dimensional semantic vector generation module generates text vectors from two dimensions for the target and semantic content, and mines the user's historical correlation information to realize the metaphor-level semantic information representation. Then, the multi-dimensional semantic vector cross-coding mechanism is used to enhance the degree of correlation between literal hierarchy and metaphorical hierarchy semantic information, and finally use a hierarchical fusion classifier for detection.
This method can deeply explore the semantic information at the metaphorical level, improve the detection effect of offensive comments in social media, enhance the correlation between semantic information at the literal level and metaphorical level, and maximize the semantic information expressed by text vectors in various dimensions.
Smart Images

Figure CN114861082B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to an offensive comment detection method based on multi-dimensional semantic representation. The method can be used in the detection of offensive language on an Internet social platform, and belongs to the technical field of Internet and artificial intelligence. Background Art
[0002] With the rapid development of social media platforms, online social networking has become the mainstream way for people to communicate. Convenient communication platforms can enrich the user's thought market, and the diversity and popularity of social media also allow users from different industries and different knowledge bases to speak freely. However, due to many factors such as the anonymity of user identities on social platforms, emotional blockage in the real world, and the media effect of social networks, detecting offensive comments posted by social users is an important task in cyberspace content governance.
[0003] For user comment data collected from social media, researchers first simply cleaned the text data; then used the language representation model to represent the preprocessed text data, that is, to convert the text data into a form that can be understood by the computer, and extracted the features of the classified data in the process; then constructed a classifier to select the optimal classification match for classification. At present, most of the common methods for detecting offensive language on social media use machine learning, deep learning, and pre-trained models. Traditional machine learning methods process complex offensive language on social media, which not only consumes computer computing power and memory, but also has limited room for improvement in algorithm accuracy. In addition, traditional machine learning methods cannot model the long-range dependency relationship between words and have data sparsity problems. The deep learning-based method can effectively identify but is difficult to accurately classify offensive language, and does not analyze the positive impact of different word embedding information on the detection of offensive language from multiple dimensions, nor does it mine the historical information association and stylistic characteristics of social users.
[0004] Aiming at the problems of single information representation dimension, weak correlation information and poor detection effect of sarcastic comments in offensive comment detection, this paper proposes a method for detecting offensive comments based on multi-dimensional semantic representation (User-Offensive Comment Detection based on Multi-dimensional SemanticRepresentation, UOCD-MSR). Firstly, the present invention proposes a text multi-dimensional semantic vector generation module to generate text vectors at the literal level for the input comment text from two dimensions of target and semantic content, and mines the user's historical correlation information to realize the semantic information representation at the metaphor level; then, according to the cross-coding mechanism of multi-dimensional semantic vectors, the correlation between the semantic information at the literal level and the metaphor level is enhanced; finally, the hierarchical fusion classifier is used to fully guarantee the potential interaction information and semantic retention between the encoded target and content, so as to improve the detection result of offensive comments. Summary of the invention
[0005] In view of the problems and shortcomings of the prior art, the present invention proposes an offensive comment detection method UOCD-MSR based on multi-dimensional semantic representation, which can accurately detect offensive comment texts posted by users in social media.
[0006] In order to achieve the above purpose, the technical solution of the present invention is as follows: a method for detecting offensive comments based on multi-dimensional semantic representation, which mainly includes the process of collecting and preprocessing comment text data, generating multi-dimensional semantic vectors of text, cross-coding of multi-dimensional semantic vectors and predicting detection results by hierarchical fusion classifiers, etc., which can perform multi-dimensional semantic analysis on text and accurately detect offensive comments in social media. The method mainly includes four steps, as follows:
[0007] Step 1: Collection and preprocessing of comment text data. First, collect user comment data through the API of each social media platform to accumulate a user comment data set. Each sample in the data set contains the comment content and user ID. Then, preprocess each sample in the data set, including operations such as word segmentation, replacement, segmentation and removal;
[0008] Step 2: Generate multi-dimensional semantic vectors for text. After preprocessing, conduct in-depth mining of the review text from two dimensions: target and semantic content. Generate word vector representation of the text from four perspectives: direct target, generalized target, explicit semantics, and implicit semantics. Also, mine the user's historical association information to generate the user's personality characteristics and stylistic characteristics to achieve semantic information representation at the metaphor level, so as to achieve high-accuracy detection of sarcastic text.
[0009] Step 3: Multi-dimensional semantic vector cross encoding: Based on the text word vector generated in step 2, the attention mechanism cross encoding method is used to enhance the correlation between the target dimension and the semantic dimension.
[0010] Step 4: Hierarchical fusion classifier predicts the detection result. Based on the target vector and semantic vector obtained in step 3, the hierarchical fusion classifier is used to fuse the two vectors with inconsistent dimensions, and the original meaning of the text is restored to the greatest extent, and finally sent to the classifier to obtain the prediction result.
[0011] Compared with the prior art, the beneficial effects of the present invention are as follows:
[0012] 1. The UOCD-MSR model proposed by this method can perform multi-dimensional semantic analysis on comment texts, deeply mine semantic information at the metaphor level, and improve the detection effect of offensive comments in social media.
[0013] 2. The UOCD-MSR model adopts a multi-dimensional semantic vector encoding mechanism to accurately identify the directional targets in the sentence and comprehensively consider the semantic information at the literal level and the metaphorical level to achieve the effect of enhancing the correlation between the two and maximize the use of the semantic information expressed by the text vectors of each dimension.
[0014] 3. This method introduces the aggressive comment detection scenarios of various social media users, which can effectively improve the generalization ability of the model and at the same time improve the evaluation standard value of aggressive comment detection to a higher level. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 The figure is a general framework diagram of the method according to the embodiment of the present invention.
[0016] Figure 2 The figure is a flow chart of a method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0017] In order to deepen the understanding of the present invention, the present invention is further explained in conjunction with specific examples. Figure 1 and Figure 2 As shown, the specific implementation steps are as follows:
[0018] Step 1: Collection and preprocessing of comment text data. The details are as follows: First, collect user comment data through the API of each social media platform to accumulate a user comment data set. Each sample in the data set contains the comment content and user ID. Then, preprocess the comment data set, use the emoticon library in Python to convert the emoticons in each comment into the corresponding meaning text; use the third-party library word segment in Python to split the tags by identifying uppercase characters; replace all @USER fields with an @USER token to remove redundant words while retaining necessary information; map a large number of common spelling variants of offensive words to standard forms according to the list of insulting words frequently used on social media platforms; delete trailing spaces and useless punctuation.
[0019] Step 2: Generate multi-dimensional semantic vectors of text. Assume that the user comment dataset on a social platform is D s ={s1,s2,…,s L}, where s i is the i-th sentence in the dataset, and L is the length of the dataset. Given a word sequence W = {w1,w2,…,w n} represents a text sentence. Offensive language detection can be defined as assigning a label y to each sentence det_i ∈{OFF,NOT} to distinguish whether the sentence is offensive; then assign a label y to each offensive sentence (OFF) cla_i ∈{UNT,TIN}, indicating whether the sentence is a targeted attack or a non-targeted attack. The implementation process of this step is divided into 4 sub-steps:
[0020] Sub-step 2-1, specific target attack vector representation. The target refers to a specific person or entity. The named entity recognition method trained with ELMo and BiLSTM is used to represent the text with a specific target attack vector. For the input text sequence W = {w1,w2,…,w n}, firstly, we use the BIOES method to annotate and obtain the annotated word vector sequence x = {x1, x2, …, x n}. For the annotated sequence, the text multi-dimensional semantic vector generator uses CNN and ELMo to extract its features. CNN mainly extracts character-level features, while ELMo extracts dynamic features of words. Finally, the character-based word vector extracted by CNN and the dynamic word vector extracted by ELMo are concatenated together to form a new vector x ′ ={x′1,x′2,…,x′ n} is sent to BiLSTM, which decodes the features of each word into the logarithmic probability of each corresponding label category as the named entity label score at the output layer, and outputs the optimal label sequence as the specific target attack vector representation ST , as shown in formula (1), where is the specific target vector representation of the i-th word in the text sequence W.
[0021]
[0022] Sub-step 2-2, generalized target attack vector representation. Generalized target attacks are generally targeted at people belonging to a small number of categories, and research has found that they are mainly gender. A gender debiasing model is used to learn gender-preserving debiased word embedding from a given corpus as the generalized target attack vector representation G T , as shown in formula (2), where is the generalized target vector representation of the i-th word in the text sequence W.
[0023]
[0024] Sub-step 2-3, explicit semantic attack vector representation. For explicit attacks, whether the target is specific or general, explicit attacks are usually represented by specific keywords in the insulting vocabulary. Use dict2vec to define strong and weak pairs of words in a given text, and each word is represented by a vector. Strongly paired words have more similar vectors than weakly paired words, and weakly paired words have more similar vectors than unrelated words. If the k nearest neighbors of two words are between a certain weak pair, then the weak pair can be promoted to a strong pair. The closest K words are selected based on the cosine distance to the pre-trained word embedding, and it is found that using K=5 can well balance semantic and syntactic extraction information. Under this mechanism, the explicit semantic attack vector representation of a text, namely E, can be learned. S , as shown in formula (3), where is the explicit semantic vector representation of the corresponding i-th word in the text sequence W.
[0025]
[0026] Sub-step 2-4, implicit semantic attack vector representation. Implicit offensive language does not directly represent insults, and a content- and context-driven hybrid modeling approach is needed to detect sarcasm in online social media discussions. First, all the user's comments and historical comment data are collected and created by appending them using special separators. Each user document and all the words in it are first mapped into a unique vector, each of which is represented by the matrix and Here, d sDenotes the embedding size, and |V| denotes the size of the vocabulary. Then, the unsupervised representation learning method of the paragraph vector is used for training. The document vectors of the user are learned through the training document D. These document vectors represent the user's style characteristics and preference characteristics. Then, the pre-trained CNN is used to extract the user's personality characteristics and include the personality characteristics in the user embedding. By extracting the activation of the last hidden layer vector of the CNN, that is, the personality characteristics The user's expectation of the personality traits of all comments is then defined as the overall personality trait vector The user's stylistic features and personality features are fused through the multi-view fusion CCA, and finally the intrinsic semantic irony vector representation I trained according to the dataset of this paper is obtained. s , as shown in formula (4), where is the explicit semantic vector representation of the corresponding i-th word in the text sequence W.
[0027]
[0028] Step 3: Multi-dimensional semantic vector cross encoding. For the four text representations {S T ,G T ,E S ,I S}, first use the concatenation function to convert {S T ,G T} concatenated into the target vector representation X T ; Similarly, {E S ,I S} are concatenated into a content vector representation X S After the splicing is completed, X T and X S As input, it is sent to the Transformer mechanism. In order to enhance the correlation between the two dimensions of target and semantics, the target and semantics are cross-calculated to obtain the encoding representation Z of the text T and Z S , as shown in formulas (5) and (6).
[0029]
[0030] Among them, d k Represents the dimension of K value in the attention mechanism, V S and V T Represent the V values of the semantic and target dimensions respectively.
[0031] After multi-head attention, the result Z of the target dimension is T and the encoding result Z of the semantic content SIt is sent to the residual connection and normalization layer (Add&Norm) for residual connection calculation and layer normalization. In the multi-dimensional semantic vector cross encoding mechanism, the specific calculation of the target and semantic content in the Add&Norm layer is shown in formulas (7) and (8):
[0032] O T =LayerNorm(FNN(Z S )+Z T ) (7)
[0033] O S =LayerNorm(FNN(Z T )+Z S ) (8)
[0034] Finally, we get two outputs of Transformer encoder, O and T and O S ,in Here, n represents the length of the sequence, T d and S d They represent the word embedding dimension from the target perspective and the word embedding dimension from the semantic content perspective respectively.
[0035] Step 4: Hierarchical fusion classifier predicts the detection results. In order to restore the original meaning of the text to the greatest extent, the target vector and semantic content vector with inconsistent dimensions are fused, and a hierarchical fusion classifier algorithm is proposed. Specifically, the target vector O obtained in step 3 is firstly T and the semantic content vector O S It is compressed from multi-dimensional to one-dimensional, as shown in formulas (9) and (10), and then passes through a Dense layer and applies the Softmax function to obtain the d-dimensional probability vector of the corresponding target angle and content angle, that is, V T and V S , where d is the number of categories. The specific calculation formulas (11) and (12) are as follows:
[0036]
[0037] in,
[0038] Then V T and V S Feed them into the fuser separately to obtain equal-dimensional target representation and semantic content representation As shown in formulas (13) and (14):
[0039]
[0040] in, represents the connection function, (V T ,…,V T ) and (V S ,…,V S ) respectively represent V T and V S Broadcast to N words, get V′ T and V′ S .
[0041] From the target point of view, V′ is converted into T and O S Splice together to generate an augmented semantic content state And then pass through the Flatten layer for compression and the Dense layer for calculation again, and finally get the output matrix P of the target angle S Similarly, we can also get an output matrix P from the semantic content dimension T , as shown in formulas (15) and (16).
[0042]
[0043] in,
[0044] Finally, the two output matrices P obtained from the target perspective and the semantic perspective are T and P S The concatenated matrix is compressed and sent to the hierarchical fusion classifier to obtain the probability C of each category to be predicted. The calculation of the hierarchical fusion classifier is shown in formulas (17), (18) and (19).
[0045] L1=ReLU(PW1+b1) (17)
[0046] L2=ReLU(L1W2+b2) (18)
[0047] C = Softmax(L2W3+b3) (19)
[0048] Based on the same inventive concept, an embodiment of the present invention discloses an offensive comment detection method and device based on multi-dimensional semantic representation, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is loaded into the processor, the method and device for detecting offensive comments based on multi-dimensional semantic representation are implemented.
[0049] It should be noted that the above embodiments are only used to illustrate the present invention and are not used to limit the scope of the present invention. After reading the present invention, various equivalent modifications of the present invention by those skilled in the art all fall within the scope defined by the claims attached to this application.
Claims
1. A method for detecting offensive comments based on multi-dimensional semantic representation, characterized in that: The method comprises the following steps: Step 1: Review text data collection and preprocessing; Step 2: Generate multi-dimensional semantic vector of text; Step 3: Multi-dimensional semantic vector cross encoding; Step 4: Hierarchical fusion classifiers predict aggressiveness detection results; Among them, step 2: text multi-dimensional semantic vector generation, the pre-processed comment text is deeply mined from the two dimensions of target and semantic content, and the word vector representation of the text is generated from four perspectives: direct target, generalized target, explicit semantics and implicit semantics; and the user's historical association information is mined to generate the user's personality characteristics and stylistic characteristics to realize the semantic information representation at the metaphor level; Step 3: Multi-dimensional semantic vector cross encoding. According to the text word vector generated in step 2, the attention mechanism cross encoding method is used to enhance the correlation between the target dimension and the semantic dimension. Step 4: The hierarchical fusion classifier predicts the detection results. According to the target vector and semantic vector obtained in step 3, the hierarchical fusion classifier is used to fuse the two vectors with inconsistent dimensions, and the original meaning of the text is restored to the greatest extent. Finally, the vectors are sent to the classifier to obtain the prediction results. Step 2: Generate multi-dimensional semantic vectors of text. The details are as follows: Assume that the user comment dataset on a social platform is D s ={s1,s2,…,s L }, where s i is the i-th sentence in the dataset, L is the length of the dataset, given a word sequence W = {w1,w2,…,w n } represents a text sentence, and offensive language detection is defined as assigning a label y to each sentence det_i ∈{OFF,NOT} to distinguish whether the sentence is offensive; then assign a label y to each offensive sentence cla_i ∈{UNT,TIN}, indicating whether the sentence is a targeted attack or a non-targeted attack. The implementation process is divided into 4 sub-steps: Sub-step 2-1, specific target attack vector representation, the target refers to a specific person or entity, the named entity recognition method trained with ELMo and BiLSTM is used to represent the text with a specific target attack vector. For the input text sequence W = {w1,w2,…,w n }, firstly, we use the BIOES method to annotate and obtain the annotated word vector sequence x = {x1, x2, …, x n }, for the annotated sequence, the text multi-dimensional semantic vector generator uses CNN and ELMo to extract its features respectively. CNN mainly extracts character-level features, while ELMo extracts dynamic features of words. Finally, the character-based word vector extracted by CNN and the dynamic word vector extracted by ELMo are concatenated together to form a new vector x′={x′1,x′2,…,x′ n } is sent to BiLSTM, which decodes the features of each word into the logarithmic probability of each corresponding label category as the named entity label score at the output layer, and outputs the optimal label sequence as the specific target attack vector representation S T , as shown in formula (1), where is the specific target vector representation of the i-th word in the text sequence W: Sub-step 2-2, generalized target attack vector representation, learns gender-preserving debiased word embedding from a given corpus through a gender debiasing model as the generalized target attack vector representation G T , as shown in formula (2), where is the generalized target vector representation of the i-th word in the text sequence W, Sub-step 2-3, explicit semantic attack vector representation. For explicit attacks, dict2vec is used to define strong and weak pairs of words in a given text. Each word is represented by a vector. If the k nearest neighbors of two words are between a certain weak pair, then the weak pair is promoted to a strong pair. The closest K words are selected based on the cosine distance with the pre-trained word embedding. Under this mechanism, the explicit semantic attack vector representation of a text, namely E, can be learned. S , as shown in formula (3), where is the explicit semantic vector representation of the i-th word in the text sequence W, Sub-steps 2-4, implicit semantic attack vector representation, implicit offensive language does not directly represent insults, and a content- and context-driven hybrid modeling approach is needed to detect sarcasm in online social media discussions. First, all user comments and historical comment data are collected and created by appending them using special separators. Each user document and all words in it are first mapped into a unique vector, each of which is represented by the matrix and A column in indicates that, here, d s Denotes the embedding size, |V| denotes the size of the vocabulary, and then the unsupervised representation learning method of the paragraph vector is used for training. The document vectors of the user are learned through the training document D. These document vectors represent the user's stylistic features and preference features. Then, the pre-trained CNN is used to extract the user's personality features and include the personality features in the user embedding. By extracting the activation of the last hidden layer vector of the CNN, that is, the personality features The user's expectation of the personality traits of all comments is then defined as the overall personality trait vector The user's stylistic features and personality features are fused through the multi-view fusion CCA, and finally the intrinsic semantic irony vector representation I trained according to the dataset of this paper is obtained. S , as shown in formula (4), where is the explicit semantic vector representation of the i-th word in the text sequence W, 2. The method for detecting offensive comments based on multi-dimensional semantic representation according to claim 1 is characterized in that: Step 1: Comment text data collection and preprocessing, as follows: First, collect user comment data through the API of each social media platform to accumulate a user comment data set. Each sample in the data set contains the comment content and user ID. Then, preprocess each sample in the data set, including word segmentation, replacement, segmentation and removal operations.
3. The method for detecting offensive comments based on multi-dimensional semantic representation according to claim 1 is characterized in that: Step 3: Multi-dimensional semantic vector cross encoding. For the four text representations {S T ,G T ,E S ,I S }, first use the concatenation function to convert {S T ,G T } concatenated into the target vector representation X T ; Similarly, {E S ,I S } are concatenated into a content vector representation X S After the splicing is completed, X T and X S As input, it is sent to the Transformer mechanism. In order to enhance the correlation between the two dimensions of target and semantics, the target and semantics are cross-calculated to obtain the encoded representation of the text, as shown in formulas (5) and (6). Among them, d k Represents the dimension of K value in the attention mechanism, V S and V T Represent the V values of semantic and target dimensions respectively; After multi-head attention, the result Z of the target dimension is T and the encoding result Z of the semantic content S It is sent to the residual connection and normalization layer for residual connection calculation and layer normalization. In the multi-dimensional semantic vector cross encoding mechanism, the specific calculation of the target and semantic content in the Add&Norm layer is shown in formulas (7) and (8): About T =ayerNorm(FNN(Z S )+Z T ) (7) O S =LayerNorm(FNN(Z T )+Z S ) (8) Finally, we get two outputs of Transformer encoder, O and T and O S ,in Here, n represents the length of the sequence, T d and S d They represent the word embedding dimension from the target perspective and the word embedding dimension from the semantic content perspective respectively.
Citation Information
Patent Citations
User abnormal comment detection method and system based on hierarchical multi-channel attention
CN112015862A
Method and apparatus for real time semantic filtering of posts to an internet social network
US20110137845A1