A method and device for mining illegal words in text

By performing character-level violation analysis and word segmentation filtering on text, the problem of the lack of interpretability in text violation recognition is solved, and more reliable and clear violation judgment is achieved.

CN115422359BActive Publication Date: 2025-09-02GUANGZHOU QUWAN NETWORK TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211071495.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-09-02
Publication Date
2025-09-02
Estimated Expiration
2042-09-02

AI Technical Summary

Technical Problem

Existing deep learning models cannot specifically analyze the type of violation from the text structure in the identification of text violation content, resulting in the lack of interpretability and unreliability of the identification results.

Method used

By dividing the text to be mined into multiple characters to be mined, the pre-established violation character recognition model is used to encode and transform each character in a model, calculate the character violation probability, and filter the violation category probability based on the word segmentation to obtain the filtered violation word.

Benefits of technology

It improves the interpretability and reliability of the violation judgment of text content, clearly analyzes the violation type and probability of each participle, and improves the accuracy of violation judgment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115422359B_ABST
    Figure CN115422359B_ABST
Patent Text Reader

Abstract

The present application discloses a method and device for mining illegal words in text, the method comprising: segmenting the text to be mined input by the user to obtain a plurality of characters to be mined, encoding the characters to be mined by a model through an illegal character recognition model to obtain a character vector, performing a dimension transformation on each character vector to obtain the character violation probability of each character to be mined relative to each violation category, calculating the single category violation probability of each word to be mined obtained by segmenting the text to be mined in each violation category, filtering each word to be mined by a preset threshold value, and obtaining the illegal words under each violation category. It can be seen that starting from each character to be mined in the text to be mined, the violation type possibility of each character is analyzed, and the violation type possibility of the word composed of the character is obtained. On this basis, the word under each violation category is finally obtained by filtering by the threshold value, so that the final result has a high interpretability, which improves the reliability of the judgment of text content violation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of text content security review, and more specifically, to a method and device for mining illegal words in text. Background Art

[0002] With the continuous advancement of science and technology, the internet is becoming increasingly sophisticated, attracting more and more people to participate in online life. However, due to the large number of netizens and the complexity of the online world, some illegal content is inevitable, which can easily mislead good netizens. Moreover, text messaging is the most common form of communication online today. Therefore, the supervision of safe text content is urgent.

[0003] Currently, in the technology for identifying text violations, text classification is directly performed through deep learning models. Deep learning models can recognize the semantics in the text and match the corresponding violation types based on the recognized semantics. However, this method of identifying violation content only recognizes and judges the entire text, and is unable to specifically analyze the violation type from the structure of the text. As a result, the obtained text content violation judgment results lack interpretability and are unreliable. Summary of the Invention

[0004] In view of the above problems, the present application is proposed to provide a method and device for mining illegal words in text, so as to provide illegal analysis of each word that constitutes the text, and improve the interpretability and reliability of the results of illegal judgment of text content.

[0005] In order to achieve the above objectives, the following specific plans are proposed:

[0006] A method for mining illegal words in a text, comprising:

[0007] Segmenting the text to be mined input by the user to obtain multiple characters to be mined in the text to be mined;

[0008] Performing model encoding on each of the characters to be mined using a pre-established illegal character recognition model to obtain a character vector corresponding to each of the characters to be mined, wherein each of the character vectors has multiple illegal category dimensions;

[0009] Performing dimension transformation on each of the character vectors using the illegal character recognition model to obtain a character violation probability of each to-be-mined character relative to each violation category;

[0010] For each violation category, averaging the character violation probabilities of each to-be-mined character in each to-be-mined segmented word in the violation category to obtain a single-category violation probability of each to-be-mined segmented word in the violation category, wherein each to-be-mined segmented word is obtained by segmenting the to-be-mined text, and each to-be-mined segmented word contains one or more to-be-mined characters;

[0011] Based on the single-category violation probability of each violation category of each of the to-be-mined segmented words, each to-be-mined segmented word is filtered through a preset violation probability threshold to obtain the filtered to-be-mined segmented words under each violation category, and the filtered to-be-mined segmented words under each violation category are determined as the violation words of the to-be-mined text.

[0012] Optionally, based on the single-category violation probability of each violation category of each of the to-be-mined segmented words, filtering each to-be-mined segmented word by a preset violation probability threshold to obtain filtered segmented words to be mined under each violation category includes:

[0013] Generate a word violation category probability distribution for each to-be-mined segmentation based on each to-be-mined segmentation and the single-category violation probability of each violation category of each to-be-mined segmentation;

[0014] On the probability distribution of word violation categories of each to-be-mined segmented word, each to-be-mined segmented word is filtered using a preset violation probability threshold to obtain the filtered violation words under each violation category.

[0015] Optionally, after performing dimension transformation on each character vector using the illegal character recognition model to obtain the character violation probability of each to-be-mined character relative to each violation category, the method further includes:

[0016] By using the illegal character recognition model, a linear normalized exponential transformation is performed on the character violation probability of each illegal category of each to-be-mined character to obtain the probability of each illegal category.

[0017] Optionally, the process of establishing the illegal character recognition model includes:

[0018] Based on the existing training character data and the existing labels of each violation category, calculate the total loss value of the constraint violation character recognition model training;

[0019] Under the constraint of the total loss value, the training character data is used as training samples, and the various violation category labels are used as sample labels to train and obtain a violation character recognition model.

[0020] Optionally, the calculating of the total loss value of the training of the constraint violation character recognition model based on the existing training character data and the existing violation category labels includes:

[0021] The loss formula for training the constraint violation character recognition model is calculated using the following formulas:

[0022]

[0023] Wherein, L is the total loss value, zij is the logit value of the jth violation category label in each violation category label hit by the i-th training character in the training character data, m is the preset asymmetric loss ASL hard threshold boundary, y j is the jth violation category label, γ is the preset ASL soft threshold parameter, k is the total number of violation category labels, n is the total number of characters in the character sample, and λ is the preset regularization coefficient.

[0024] Optionally, after performing dimension transformation on each character vector using the illegal character recognition model to obtain the character violation probability of each to-be-mined character relative to each violation category, the method further includes:

[0025] According to each character to be mined and the character violation probability of each violation category of each character to be mined, a character violation category probability distribution of each character to be mined is generated.

[0026] Optionally, the method further includes:

[0027] Determine a word segmentation knowledge matrix for a sentence composed of existing training character data;

[0028] The character violation category probability distribution of each training character in the training character data and the word segmentation knowledge matrix between each character in each training word segmentation are used as model learning training information to train the violation character recognition model and obtain the violation word segmentation recognition model.

[0029] Optionally, the character violation category probability distribution of each training character in the training character data and the word segmentation knowledge matrix between each character in each training word segmentation are used as model learning training information to train the violation character recognition model to obtain the violation word segmentation recognition model, including:

[0030] The probability distribution matrix of word segmentation violation categories is determined using the following formula:

[0031]

[0032] Among them, W k is the word segmentation knowledge matrix, is the probability distribution matrix of word segmentation violation categories, and P is the matrix information of the probability distribution of character violation categories of each training character in the training character data;

[0033] The illegal word segmentation category probability distribution matrix is ​​used as a training target to train the illegal character recognition model to obtain an illegal word segmentation recognition model.

[0034] Optionally, the method further includes:

[0035] Performing model encoding on each character to be mined using the illegal word segmentation recognition model to obtain multiple extracted word segments and a word segmentation vector corresponding to each extracted word segment with each illegal category dimension;

[0036] Performing dimension transformation on each of the word segmentation vectors using the illegal word segmentation identification model to obtain a word segmentation violation probability for each violation category of the extracted word segmentation corresponding to the word segmentation vector;

[0037] Generate a probability distribution of the extracted segmentation violation category for each extracted segmentation word based on the segmentation violation probability of each violation category of each extracted segmentation word;

[0038] On the probability distribution of the extracted segmentation violation categories of the extracted segmentation, the extracted segmentation are filtered by the violation probability threshold to obtain filtered extracted segmentation under each violation category.

[0039] A device for mining illegal words in a text, comprising:

[0040] A text segmentation unit, configured to segment the text to be mined input by the user and obtain a plurality of characters to be mined in the text to be mined;

[0041] A character encoding unit, configured to perform model encoding on each of the characters to be mined using a pre-established illegal character recognition model to obtain a character vector corresponding to each of the characters to be mined, wherein each of the character vectors has multiple illegal category dimensions;

[0042] A vector dimension transformation unit, configured to perform dimension transformation on each of the character vectors using the illegal character recognition model to obtain a character violation probability of each to-be-mined character relative to each violation category;

[0043] a probability accumulation unit configured to average, for each violation category, the character violation probabilities of each to-be-mined character in each to-be-mined segmented word in the violation category to obtain a single-category violation probability of each to-be-mined segmented word in the violation category, wherein each to-be-mined segmented word is obtained by segmenting the to-be-mined text, and each to-be-mined segmented word contains one or more to-be-mined characters;

[0044] A word segmentation filtering unit is used to filter each word to be mined based on the single-category violation probability of each violation category of each word to be mined, using a preset violation probability threshold to obtain the filtered word to be mined under each violation category, and determine the filtered word to be mined under each violation category as the violation word of the text to be mined.

[0045] Optionally, the word segmentation filtering unit includes:

[0046] A probability distribution generating unit is used to generate a word violation category probability distribution of each to-be-mined segmented word according to each to-be-mined segmented word and the single category violation probability of each violation category of each to-be-mined segmented word;

[0047] The probability distribution filtering unit is used to filter each to-be-mined segmented word by a preset violation probability threshold value on the probability distribution of word violation categories of each to-be-mined segmented word, obtain the filtered violation words under each violation category, and determine the to-be-mined segmented word under each filtered violation category as the violation word of the to-be-mined text.

[0048] Optionally, the device further includes:

[0049] The normalization transformation unit is used to perform dimension transformation on each of the character vectors in the vector dimension transformation unit through the illegal character recognition model to obtain the character violation probability of each character to be mined relative to each violation category, and then perform linear normalized exponential transformation on the character violation probability of each violation category of each character to be mined in each character to be mined through the illegal character recognition model to obtain the probability of each violation category.

[0050] Optionally, the device further includes:

[0051] A total loss calculation unit, used to calculate the total loss value of the constraint violation character recognition model training based on the existing training character data and the existing violation category labels;

[0052] The model training unit is used to train a violation character recognition model using the training character data as training samples and the violation category labels as sample labels under the constraint of the total loss value.

[0053] Optionally, the total loss calculation unit includes:

[0054] The total loss calculation subunit is used to calculate the loss formula for constraint violation character recognition model training using the following formulas:

[0055]

[0056] Wherein, L is the total loss value, z ij is the logit value of the jth violation category label in each violation category label hit by the i-th training character in the training character data, m is the preset asymmetric loss ASL hard threshold boundary, y j is the jth violation category label, γ is the preset ASL soft threshold parameter, k is the total number of violation category labels, n is the total number of characters in the character sample, and λ is the preset regularization coefficient.

[0057] Optionally, the device further includes:

[0058] The character violation distribution generating unit is used to perform dimension transformation on each of the character vectors by the illegal character recognition model in the vector dimension transformation unit to obtain the character violation probability of each character to be mined relative to each violation category, and then generate the character violation category probability distribution of each character to be mined according to each character to be mined and the character violation probability of each violation category of each character to be mined.

[0059] Optionally, the device further includes:

[0060] A word segmentation knowledge matrix determination unit, used to determine the word segmentation knowledge matrix of a sentence composed of existing training character data;

[0061] The word segmentation recognition model training unit is used to use the character violation category probability distribution of each training character in the training character data and the word segmentation knowledge matrix between each character in each training word segment as model learning training information to train the violation character recognition model and obtain the violation word segmentation recognition model.

[0062] Optionally, the word segmentation recognition model training unit includes:

[0063] The first word segmentation recognition model training subunit is used to determine the word segmentation violation category probability distribution matrix using the following formula:

[0064]

[0065] Among them, W k is the word segmentation knowledge matrix, is the probability distribution matrix of word segmentation violation categories, and P is the matrix information of the probability distribution of character violation categories of each training character in the training character data;

[0066] The second word segmentation recognition model training subunit is used to train the illegal character recognition model using the word segmentation violation category probability distribution matrix as a training target to obtain an illegal word segmentation recognition model.

[0067] Optionally, the device further includes:

[0068] A word segmentation vector determination unit is used to perform model encoding on each character to be mined using the illegal word segmentation recognition model to obtain multiple extracted word segments and a word segmentation vector corresponding to each extracted word segment with each violation category dimension;

[0069] A word segmentation vector transformation unit is used to perform dimensionality transformation on each of the word segmentation vectors using the illegal word segmentation identification model to obtain a word segmentation violation probability for each violation category of the extracted word corresponding to the word segmentation vector;

[0070] A word segmentation probability distribution generating unit is used to generate a probability distribution of an extracted word violation category for each extracted word based on each extracted word and the word segmentation violation probability of each violation category of each extracted word;

[0071] The extracted word filtering unit is used to filter each extracted word according to the violation probability threshold on the probability distribution of the extracted word violation category of each extracted word, so as to obtain the filtered extracted words under each violation category.

[0072] By means of the above technical solution, the present application obtains multiple characters to be mined in the text to be mined by segmenting the text to be mined input by the user, performs model encoding on each character to be mined using a pre-established violation character recognition model, obtains a character vector corresponding to each character to be mined, each character vector having multiple violation category dimensions, performs dimension transformation on each character vector using the violation character recognition model, obtains a character violation probability of each character to be mined relative to each violation category, averages the character violation probabilities of each character to be mined in each word to be mined in the violation category, and obtains a single-category violation probability of each word to be mined in the violation category, each word to be mined is obtained by word segmentation processing the text to be mined, and each word to be mined contains one or more characters to be mined, and further, based on the single-category violation probabilities of each violation category of each word to be mined, each word to be mined is filtered using a preset violation probability threshold to obtain filtered word to be mined under each violation category, and the filtered word to be mined under each violation category is determined as a violation word in the text to be mined. It can be seen that starting from each character to be mined in the text to be mined, the possibility of the violation type of each character is analyzed, so as to obtain the possibility of the violation type of the word composed of the character, and clearly analyze the violation type to which each word belongs and the reason for the high or low probability of the violation type to which the word belongs. On this basis, the word segments under each violation category are finally obtained by filtering through the violation probability threshold, so that the final word segments under each violation category have high interpretability, which improves the reliability of the judgment of text content violation. BRIEF DESCRIPTION OF THE DRAWINGS

[0073] Various other advantages and benefits will become apparent to those skilled in the art upon reading the detailed description of the preferred embodiment below. The accompanying drawings are for illustration purposes only and are not to be considered as limiting the present application. The same reference symbols are used throughout the drawings to represent the same components. In the drawings:

[0074] Figure 1 A schematic diagram of a process for mining illegal words in text provided by an embodiment of the present application;

[0075] Figure 2 A schematic diagram of a process for mining illegal words in text based on an illegal word segmentation identification model provided in an embodiment of the present application;

[0076] Figure 3 A schematic diagram of the structure of a device for mining illegal words in text provided by an embodiment of the present application;

[0077] Figure 4 A schematic diagram of the structure of a device for mining illegal words in text provided in an embodiment of the present application. DETAILED DESCRIPTION

[0078] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0079] The present application solution can be implemented based on a terminal with data processing capabilities, which can be a computer, server, cloud, etc.

[0080] Next, combine Figure 1 The text illegal word mining method of the present application may include the following steps:

[0081] Step S110: segment the text to be mined input by the user to obtain multiple characters to be mined in the text to be mined.

[0082] Specifically, the text input by the user can be determined as the text to be mined by responding to the text input by the user. The text to be mined can be segmented to obtain multiple character tokens to be mined. A single character to be mined can be a single Chinese character, a single English letter, or a single punctuation mark.

[0083] Step S120 , performing model encoding on each of the characters to be mined using a pre-established illegal character recognition model to obtain a character vector corresponding to each of the characters to be mined, wherein each of the character vectors carries multiple illegal category dimensions.

[0084] Specifically, the pre-established illegal character recognition model can be a model of the deep learning type, such as a BERT (Bidirectional Encoder Representations from Transformer) model, an LSTM (long-short term memory) model, etc. Each character to be mined can be input into the pre-established illegal character recognition model, which then performs illegal character recognition on the character to be mined, and determines the score of each illegal category expressed by the character to be mined in a plurality of pre-defined illegal categories. After determining the scores of each illegal category for each character to be mined, the scores of each illegal category are expressed in the form of character vectors (Tokens Embeddings) through model encoding, and the scores are output as the model results.

[0085] Step S130: Performing dimension transformation on each of the character vectors using the illegal character recognition model to obtain a character violation probability of each to-be-mined character relative to each violation category.

[0086] Specifically, each character vector can normalize the modulus of the dimension corresponding to the expression score of each violation category and convert it into a value between 0 and 1. The normalized standard object can refer to the dimension with the longest modulus on each violation category dimension, thereby obtaining the character violation probability of each character to be mined relative to each violation category.

[0087] Step S140 : For each violation category, average the character violation probabilities of each to-be-mined character in each to-be-mined segmented word in the violation category to obtain the single-category violation probability of each to-be-mined segmented word in the violation category.

[0088] Specifically, each of the to-be-mined word segments may be obtained by word segmentation processing of the to-be-mined text, and each of the to-be-mined word segments may contain one or more to-be-mined characters.

[0089] For example, the violation categories are A, B, and C, and the word to be mined X contains three characters to be mined, x1, x2, and x3. The character violation probability of x1 in category A is 0, the character violation probability of x1 in category B is 0.2, the character violation probability of x1 in category C is 0.3, the character violation probability of x2 in category A is 0.1, the character violation probability of x2 in category B is 0.2, the character violation probability of x2 in category C is 0, the character violation probability of x3 in category A is 0.1, the character violation probability of x3 in category B is 0.1, and the character violation probability of x3 in category C is 0.1. Then the single-category violation probability of the to-be-mined word X in the violation category A is (0+0.1+0.1) / 3=0.067, then the single-category violation probability of the to-be-mined word X in the violation category B is (0.2+0.2+0.1) / 3=0.167, then the single-category violation probability of the to-be-mined word X in the violation category C is (0.3+0+0.1) / 3=0.133.

[0090] Step S150: Based on the single-category violation probability of each violation category of each of the to-be-mined segmented words, each to-be-mined segmented word is filtered by a preset violation probability threshold to obtain the filtered to-be-mined segmented words under each violation category, and the filtered to-be-mined segmented words under each violation category are determined as the violation words of the to-be-mined text.

[0091] Specifically, the preset violation probability threshold can represent the probability limit for determining that the word to be mined belongs to the violation category, that is, when the single-category violation probability of the word to be mined relative to the violation category A exceeds the preset violation probability threshold, it can be determined that the word to be mined belongs to the violation category A, and the word to be mined is determined to be a violation word.

[0092] The method for mining illegal words in a text provided by this embodiment segments a text to be mined input by a user to obtain multiple characters to be mined in the text to be mined. Each character to be mined is model-encoded using a pre-established illegal character recognition model to obtain a character vector corresponding to each character to be mined, each character vector having multiple illegal category dimensions. Each character vector is dimensionally transformed using the illegal character recognition model to obtain a character violation probability for each character to be mined relative to each illegal category. For each illegal category, the character violation probabilities of each character to be mined in each segmented word to be mined in the illegal category are averaged to obtain a single-category violation probability for each segmented word to be mined in the illegal category. Each segmented word to be mined is obtained by segmenting the text to be mined, and each segmented word to be mined contains one or more characters to be mined. Furthermore, based on the single-category violation probabilities of each illegal category of each segmented word to be mined, each segmented word to be mined is filtered using a preset violation probability threshold to obtain filtered segmented words to be mined in each illegal category, and the filtered segmented words to be mined in each illegal category are determined as illegal words in the text to be mined. It can be seen that starting from each character to be mined in the text to be mined, the possibility of the violation type of each character is analyzed, so as to obtain the possibility of the violation type of the word composed of the character, and clearly analyze the violation type to which each word belongs and the reason for the high or low probability of the violation type to which the word belongs. On this basis, the word segments under each violation category are finally obtained by filtering through the violation probability threshold, so that the final word segments under each violation category have high interpretability, which improves the reliability of the judgment of text content violation.

[0093] In some embodiments of the present application, the process of filtering each to-be-mined segmented word based on the single-category violation probability of each violation category of each to-be-mined segmented word mentioned in the above embodiment by a preset violation probability threshold to obtain the filtered to-be-mined segmented words under each violation category is introduced. This process may include:

[0094] S1. Generate a word violation category probability distribution for each to-be-mined segmented word according to each to-be-mined segmented word and the single-category violation probability of each violation category of each to-be-mined segmented word.

[0095] Specifically, each word segment to be mined can be used as the horizontal axis and each violation category as the vertical axis. The color plate can be used to fill in the color corresponding to each violation category of each word segment to be mined, thereby drawing the probability distribution of the word violation category of each word segment to be mined.

[0096] S2. Filter each to-be-mined segmented word based on the probability distribution of the word violation category of each to-be-mined segmented word by a preset violation probability threshold to obtain the filtered violation words under each violation category.

[0097] Specifically, a color depth threshold corresponding to a preset violation probability threshold can be set. When the color depth filled at one position in the probability distribution exceeds the color depth threshold, it can be determined that the word to be mined corresponding to the horizontal coordinate of the position belongs to the violation category corresponding to the vertical coordinate of the position, that is, the word to be mined under the violation category corresponding to the position is obtained.

[0098] The method for mining illegal words in text provided in this embodiment constructs a probability distribution of word violation categories for each word segment to be mined, and sets a color depth threshold to filter and obtain illegal words under each violation category. This method can more clearly and intuitively analyze the violation type of each word segment to be mined.

[0099] In order to analyze the violation of the text input by the user in more detail, in some embodiments of the present application, violation analysis can also be performed on each character to be mined. Based on this, after performing dimensionality transformation on each character vector using the violation character recognition model in the above step S130 to obtain the character violation probability of each character to be mined relative to each violation category, the following can be included:

[0100] By using the illegal character recognition model, a linear normalized exponential transformation is performed on the character violation probability of each illegal category of each to-be-mined character to obtain the probability of each illegal category.

[0101] Specifically, the character violation probabilities of each violation category of each character to be mined can be accumulated to obtain the cumulative probability value under the violation category, and the cumulative probability values ​​under other violation categories can be calculated in this way. Then, the cumulative probability values ​​under each violation category are linearly normalized exponentially transformed (Linear softmax) to obtain the probability of each violation category between 0 and 1.

[0102] The method for mining illegal words in text provided in this embodiment uses the illegal character recognition model to perform a linear normalized exponential transformation on the character violation probability of each illegal category of each character to be mined, thereby obtaining the probability of each illegal category. This allows for a more detailed analysis of which illegal category the text to be mined input by the user is more inclined to, thereby classifying the illegal text.

[0103] In some embodiments of the present application, the process of establishing the illegal character recognition model mentioned in the above embodiment is introduced, and the process may include:

[0104] S1. Based on the existing training character data and the existing violation category labels, calculate the total loss value of the constraint violation character recognition model training.

[0105] Specifically, the loss formula for training the constraint violation character recognition model can be calculated using the following formulas:

[0106]

[0107] Wherein, L is the total loss value, z ij is the logit value of the jth violation category label in each violation category label hit by the i-th training character in the training character data, m is the preset asymmetric loss ASL hard threshold boundary, y j is the jth violation category label, γ is the preset ASL soft threshold parameter, k is the total number of violation category labels, n is the total number of characters in the character sample, and λ is the preset regularization coefficient.

[0108] S2. Under the constraint of the total loss value, the training character data is used as training samples, and the various violation category labels are used as sample labels to train and obtain a violation character recognition model.

[0109] Specifically, the model can be trained by deep learning.

[0110] The method for mining illegal words in text provided in this embodiment calculates the total loss value of the training of the constraint illegal character recognition model, and trains the illegal character recognition model under the constraint of the total loss value.

[0111] In order to more clearly analyze the violations of the text input by the user, some embodiments of the present application may also generate a probability distribution of violation categories based on characters. Based on this, after performing dimensionality transformation on each of the character vectors using the violation character recognition model in the above step S130 to obtain the character violation probability of each character to be mined relative to each violation category, the following may be included:

[0112] According to each character to be mined and the character violation probability of each violation category of each character to be mined, a character violation category probability distribution of each character to be mined is generated.

[0113] Specifically, each character to be mined can be used as the horizontal axis and each violation category as the vertical axis. The position corresponding to each violation category of each character to be mined can be filled with color through the color plate indication method, thereby drawing the character violation category probability distribution of each character to be mined.

[0114] The method for mining illegal words in text provided in this embodiment can more intuitively and clearly analyze the illegality of the text input by the user by plotting the probability distribution of the character illegal category of each character to be mined.

[0115] Considering that the model directly analyzes word segmentation, the obtained analysis results are more interpretable. The function of the model can be extended to analyze word segmentation. The word segmentation information can be used as training knowledge and injected into the illegal character recognition model, so that an illegal word segmentation recognition model with word segmentation analysis function can be obtained based on the illegal character recognition model. Therefore, in some embodiments of the present application, the proposed text illegal word mining method can also include:

[0116] S1. Determine the word segmentation knowledge matrix of the sentence composed of the existing training character data.

[0117] For example, for the sentence "The weather is nice", the corresponding participles are "weather", "nice", and "ah". The closeness between the characters can be obtained as shown in the following table:

[0118] sky gas No wrong ah sky 1 1 0 0 0 gas 1 1 0 0 0 No 0 0 1 1 0 wrong 0 0 1 1 0 ah 0 0 0 0 1

[0119] Then, the word segmentation knowledge matrix corresponding to the sentence "The weather is nice" is:

[0120]

[0121] S2. Using the probability distribution of character violation categories of each training character in the training character data and the word segmentation knowledge matrix between each character in each training word segmentation as model learning training information, the illegal character recognition model is trained to obtain an illegal word segmentation recognition model.

[0122] Specifically, the probability distribution matrix of word segmentation violation categories can be determined using the following formula:

[0123]

[0124] Among them, W k is the word segmentation knowledge matrix, is the probability distribution matrix of word segmentation violation categories, and P is the matrix information of the character violation category probability distribution of each training character in the training character data.

[0125] It is understandable that it is more reasonable to perform a weighted average of all characters in the sentence after probability superposition, so W k Perform weighted averaging to obtain the weighted average word segmentation knowledge matrix, and use the weighted average word segmentation knowledge matrix to determine the probability distribution matrix of word segmentation violation categories, that is,

[0126] Among them, δ is the weighted average coefficient, which can be expressed as W kij is the value of the element in the i-th row and j-th column of the word segmentation knowledge matrix, and n is the dimension of the word segmentation knowledge matrix.

[0127] For example, So

[0128] Furthermore, the illegal word segmentation category probability distribution matrix is ​​used as a training target to train the illegal character recognition model to obtain an illegal word segmentation recognition model.

[0129] The method for mining illegal words in text provided in this embodiment introduces a word segmentation knowledge matrix to obtain a probability distribution matrix of word segmentation violation categories, and trains an illegal word segmentation recognition model, so that the illegal word segmentation recognition model can directly analyze the word segmentations, and the obtained analysis results are more interpretable.

[0130] Considering that after obtaining the illegal word segmentation recognition model, the probability distribution of illegal categories based on word segmentation can be obtained without the need for word segmentation processing of the text to be mined, so as to better determine the illegal words in the text, in some embodiments of the present application, combined with Figure 2 As shown, the proposed text violation word mining method can include:

[0131] Step S210: Model encoding is performed on each character to be mined through the illegal word segmentation recognition model to obtain multiple extracted word segments and a word segmentation vector with various illegal category dimensions corresponding to each extracted word segment.

[0132] Step S220: Perform dimension transformation on each of the word segmentation vectors using the illegal word segmentation identification model to obtain the word segmentation violation probability of each violation category of the extracted word segmentation corresponding to the word segmentation vector.

[0133] Step S230: Generate a probability distribution of the extracted word violation category for each extracted word according to each extracted word and the word violation probability of each violation category of each extracted word.

[0134] Specifically, this step can be implemented through an illegal word segmentation recognition model.

[0135] Step S240 : filtering each extracted word by the violation probability threshold based on the probability distribution of the extracted word violation category of each extracted word to obtain filtered extracted words under each violation category.

[0136] The method for mining illegal words in text provided by this embodiment analyzes each character to be mined in the text to be mined through an illegal word segmentation recognition model, and can directly obtain the probability distribution of the illegal category of each extracted word segmentation, making the illegal category of the mined illegal words more explainable.

[0137] The following describes an apparatus for mining text violation words provided in an embodiment of the present application. The apparatus for mining text violation words described below and the method for mining text violation words described above can be referenced to each other.

[0138] See also Figure 3 , Figure 3 This is a schematic diagram of the structure of a device for mining illegal words in text disclosed in an embodiment of the present application.

[0139] like Figure 3 As shown, the device may include:

[0140] The text segmentation unit 11 is used to segment the text to be mined input by the user and obtain multiple characters to be mined in the text to be mined;

[0141] A character encoding unit 12 is configured to perform model encoding on each of the characters to be mined using a pre-established illegal character recognition model to obtain a character vector corresponding to each of the characters to be mined, wherein each character vector has multiple illegal category dimensions;

[0142] A vector dimension transformation unit 13 is used to perform dimension transformation on each character vector using the illegal character recognition model to obtain a character violation probability of each to-be-mined character relative to each violation category;

[0143] a probability accumulation unit 14 configured to average, for each violation category, the character violation probabilities of each to-be-mined character in each to-be-mined segmented word in the violation category to obtain a single-category violation probability of each to-be-mined segmented word in the violation category, wherein each to-be-mined segmented word is obtained by segmenting the to-be-mined text and each to-be-mined segmented word contains one or more to-be-mined characters;

[0144] The word segmentation filtering unit 15 is used to filter each word segmentation to be mined based on the single-category violation probability of each violation category of each word segmentation to be mined by a preset violation probability threshold to obtain the filtered word segmentation to be mined under each violation category, and determine the filtered word segmentation to be mined under each violation category as the violation word of the text to be mined.

[0145] Optionally, the word segmentation filtering unit includes:

[0146] A probability distribution generating unit is used to generate a word violation category probability distribution of each to-be-mined segmented word according to each to-be-mined segmented word and the single category violation probability of each violation category of each to-be-mined segmented word;

[0147] The probability distribution filtering unit is used to filter each to-be-mined segmented word by a preset violation probability threshold value on the probability distribution of word violation categories of each to-be-mined segmented word, obtain the filtered violation words under each violation category, and determine the to-be-mined segmented word under each filtered violation category as the violation word of the to-be-mined text.

[0148] Optionally, the device further includes:

[0149] The normalization transformation unit is used to perform dimension transformation on each of the character vectors in the vector dimension transformation unit through the illegal character recognition model to obtain the character violation probability of each character to be mined relative to each violation category, and then perform linear normalized exponential transformation on the character violation probability of each violation category of each character to be mined in each character to be mined through the illegal character recognition model to obtain the probability of each violation category.

[0150] Optionally, the device further includes:

[0151] A total loss calculation unit, used to calculate the total loss value of the constraint violation character recognition model training based on the existing training character data and the existing violation category labels;

[0152] The model training unit is used to train a violation character recognition model using the training character data as training samples and the violation category labels as sample labels under the constraint of the total loss value.

[0153] Optionally, the total loss calculation unit includes:

[0154] The total loss calculation subunit is used to calculate the loss formula for constraint violation character recognition model training using the following formulas:

[0155]

[0156] Wherein, L is the total loss value, z ij is the logit value of the jth violation category label in each violation category label hit by the i-th training character in the training character data, m is the preset asymmetric loss ASL hard threshold boundary, y j is the jth violation category label, γ is the preset ASL soft threshold parameter, k is the total number of violation category labels, n is the total number of characters in the character sample, and λ is the preset regularization coefficient.

[0157] Optionally, the device further includes:

[0158] The character violation distribution generating unit is used to perform dimension transformation on each of the character vectors by the illegal character recognition model in the vector dimension transformation unit to obtain the character violation probability of each character to be mined relative to each violation category, and then generate the character violation category probability distribution of each character to be mined according to each character to be mined and the character violation probability of each violation category of each character to be mined.

[0159] Optionally, the device further includes:

[0160] A word segmentation knowledge matrix determination unit, used to determine the word segmentation knowledge matrix of a sentence composed of existing training character data;

[0161] The word segmentation recognition model training unit is used to use the character violation category probability distribution of each training character in the training character data and the word segmentation knowledge matrix between each character in each training word segment as model learning training information to train the violation character recognition model and obtain the violation word segmentation recognition model.

[0162] Optionally, the word segmentation recognition model training unit includes:

[0163] The first word segmentation recognition model training subunit is used to determine the word segmentation violation category probability distribution matrix using the following formula:

[0164]

[0165] Among them, W k is the word segmentation knowledge matrix, is the probability distribution matrix of word segmentation violation categories, and P is the matrix information of the probability distribution of character violation categories of each training character in the training character data;

[0166] The second word segmentation recognition model training subunit is used to train the illegal character recognition model using the word segmentation violation category probability distribution matrix as a training target to obtain an illegal word segmentation recognition model.

[0167] Optionally, the device further includes:

[0168] A word segmentation vector determination unit is used to perform model encoding on each character to be mined using the illegal word segmentation recognition model to obtain multiple extracted word segments and a word segmentation vector corresponding to each extracted word segment with each violation category dimension;

[0169] A word segmentation vector transformation unit is used to perform dimensionality transformation on each of the word segmentation vectors using the illegal word segmentation identification model to obtain a word segmentation violation probability for each violation category of the extracted word corresponding to the word segmentation vector;

[0170] A word segmentation probability distribution generating unit is used to generate a probability distribution of an extracted word violation category for each extracted word based on each extracted word and the word segmentation violation probability of each violation category of each extracted word;

[0171] The extracted word filtering unit is used to filter each extracted word according to the violation probability threshold on the probability distribution of the extracted word violation category of each extracted word, so as to obtain the filtered extracted words under each violation category.

[0172] The apparatus for mining text violation words provided in the embodiment of the present application can be applied to devices for mining text violation words, such as terminals: mobile phones, computers, etc. Optionally, Figure 4 The hardware structure diagram of the device for mining illegal words in text is shown. Figure 4 ,The hardware structure of the device for mining illegal words in text may include: at least one processor 1, at least one communication interface 2, at least one memory 3 and at least one communication bus 4;

[0173] In the embodiment of the present application, the number of the processor 1, the communication interface 2, the memory 3, and the communication bus 4 is at least one, and the processor 1, the communication interface 2, and the memory 3 communicate with each other through the communication bus 4;

[0174] The processor 1 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention;

[0175] The memory 3 may include a high-speed RAM memory, and may also include a non-volatile memory, such as at least one disk memory;

[0176] The memory stores a program, and the processor can call the program stored in the memory, wherein the program is used to:

[0177] Segmenting the text to be mined input by the user to obtain multiple characters to be mined in the text to be mined;

[0178] Performing model encoding on each of the characters to be mined using a pre-established illegal character recognition model to obtain a character vector corresponding to each of the characters to be mined, wherein each of the character vectors has multiple illegal category dimensions;

[0179] Performing dimension transformation on each of the character vectors using the illegal character recognition model to obtain a character violation probability of each to-be-mined character relative to each violation category;

[0180] For each violation category, averaging the character violation probabilities of each to-be-mined character in each to-be-mined segmented word in the violation category to obtain a single-category violation probability of each to-be-mined segmented word in the violation category, wherein each to-be-mined segmented word is obtained by segmenting the to-be-mined text, and each to-be-mined segmented word contains one or more to-be-mined characters;

[0181] Based on the single-category violation probability of each violation category of each of the to-be-mined segmented words, each to-be-mined segmented word is filtered through a preset violation probability threshold to obtain the filtered to-be-mined segmented words under each violation category, and the filtered to-be-mined segmented words under each violation category are determined as the violation words of the to-be-mined text.

[0182] Optionally, the detailed functions and extended functions of the program may refer to the above description.

[0183] An embodiment of the present application further provides a storage medium, which may store a program suitable for execution by a processor, wherein the program is used to:

[0184] Segmenting the text to be mined input by the user to obtain multiple characters to be mined in the text to be mined;

[0185] Performing model encoding on each of the characters to be mined using a pre-established illegal character recognition model to obtain a character vector corresponding to each of the characters to be mined, wherein each of the character vectors has multiple illegal category dimensions;

[0186] Performing dimension transformation on each of the character vectors using the illegal character recognition model to obtain a character violation probability of each to-be-mined character relative to each violation category;

[0187] For each violation category, averaging the character violation probabilities of each to-be-mined character in each to-be-mined segmented word in the violation category to obtain a single-category violation probability of each to-be-mined segmented word in the violation category, wherein each to-be-mined segmented word is obtained by segmenting the to-be-mined text, and each to-be-mined segmented word contains one or more to-be-mined characters;

[0188] Based on the single-category violation probability of each violation category of each of the to-be-mined segmented words, each to-be-mined segmented word is filtered through a preset violation probability threshold to obtain the filtered to-be-mined segmented words under each violation category, and the filtered to-be-mined segmented words under each violation category are determined as the violation words of the to-be-mined text.

[0189] Optionally, the detailed functions and extended functions of the program may refer to the above description.

[0190] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device comprising the element.

[0191] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can be referenced to each other.

[0192] The above description of the disclosed embodiments is intended to enable one skilled in the art to implement or use the present application. Various modifications to these embodiments will be readily apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application is not limited to the embodiments shown herein, but is intended to conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for mining illegal words in text, characterized by: include: Segmenting the text to be mined input by the user to obtain multiple characters to be mined in the text to be mined; Performing model encoding on each of the characters to be mined using a pre-established illegal character recognition model to obtain a character vector corresponding to each of the characters to be mined, wherein each of the character vectors has multiple illegal category dimensions; Performing dimension transformation on each of the character vectors using the illegal character recognition model to obtain a character violation probability of each to-be-mined character relative to each violation category; For each violation category, averaging the character violation probabilities of each to-be-mined character in each to-be-mined segmented word in the violation category to obtain a single-category violation probability of each to-be-mined segmented word in the violation category, wherein each to-be-mined segmented word is obtained by segmenting the to-be-mined text, and each to-be-mined segmented word contains one or more to-be-mined characters; Based on the single-category violation probability of each violation category of each of the to-be-mined segmented words, filtering each to-be-mined segmented word by a preset violation probability threshold to obtain filtered segmented words under each violation category, and determining the to-be-mined segmented words under each violation category after filtering as the violation words of the to-be-mined text; The method further includes: Each character to be mined is model-encoded using a violation word segmentation recognition model to obtain a plurality of extracted word segments and a word segmentation vector corresponding to each extracted word segment with each violation category dimension. The training process of the violation word segmentation recognition model includes: determining a word segmentation knowledge matrix of a sentence composed of existing training character data; using the character violation category probability distribution of each training character in the training character data and the word segmentation knowledge matrix between each character in each training word segment as model learning training information, training the violation character recognition model to obtain a violation word segmentation recognition model; Performing dimension transformation on each of the word segmentation vectors using the illegal word segmentation identification model to obtain a word segmentation violation probability for each violation category of the extracted word segmentation corresponding to the word segmentation vector; Generate a probability distribution of the extracted segmentation violation category for each extracted segmentation word based on the segmentation violation probability of each violation category of each extracted segmentation word; On the probability distribution of the extracted segmentation violation categories of the extracted segmentation, the extracted segmentation are filtered by the violation probability threshold to obtain filtered extracted segmentation under each violation category.

2. The method according to claim 1, characterized in that The single-category violation probability of each violation category of each of the to-be-mined segmented words is filtered by a preset violation probability threshold to obtain the filtered to-be-mined segmented words under each violation category, including: Generate a word violation category probability distribution for each to-be-mined segmentation based on each to-be-mined segmentation and the single-category violation probability of each violation category of each to-be-mined segmentation; On the probability distribution of word violation categories of each to-be-mined segmented word, each to-be-mined segmented word is filtered using a preset violation probability threshold to obtain the filtered violation words under each violation category.

3. The method according to claim 1, characterized in that After performing dimension transformation on each character vector using the illegal character recognition model to obtain the character violation probability of each to-be-mined character relative to each violation category, the method further includes: By using the illegal character recognition model, a linear normalized exponential transformation is performed on the character violation probability of each illegal category of each to-be-mined character to obtain the probability of each illegal category.

4. The method according to claim 1, wherein The process of establishing the illegal character recognition model includes: Based on the existing training character data and the existing labels of each violation category, calculate the total loss value of the constraint violation character recognition model training; Under the constraint of the total loss value, the training character data is used as training samples, and the various violation category labels are used as sample labels to train and obtain a violation character recognition model.

5. The method according to claim 4, characterized in that The method of calculating the total loss value of the training of the constraint violation character recognition model based on the existing training character data and the existing violation category labels includes: The loss formula for training the constraint violation character recognition model is calculated using the following formulas: ; in, is the total loss value, is the logit value of the jth violation category label in each violation category label hit by the i-th training character in the training character data, m is the preset asymmetric loss ASL hard threshold boundary, is the jth violation category label, is the preset ASL soft threshold parameter, k is the total number of violation category labels, n is the total number of characters in the character sample, is the preset regularization coefficient.

6. The method according to claim 1, characterized in that After performing dimension transformation on each character vector using the illegal character recognition model to obtain the character violation probability of each to-be-mined character relative to each violation category, the method further includes: According to each character to be mined and the character violation probability of each violation category of each character to be mined, a character violation category probability distribution of each character to be mined is generated.

7. The method according to claim 1, characterized in that The illegal character recognition model is trained using the character violation category probability distribution of each training character in the training character data and the word segmentation knowledge matrix between each character in each training word segmentation as model learning training information to obtain the illegal word segmentation recognition model, including: The probability distribution matrix of word segmentation violation categories is determined using the following formula: ; in, is the word segmentation knowledge matrix, is the probability distribution matrix of word segmentation violation categories, Matrix information of character violation category probability distribution of each training character in the training character data; The illegal word segmentation category probability distribution matrix is ​​used as a training target to train the illegal character recognition model to obtain an illegal word segmentation recognition model.

8. A device for mining illegal words in text, characterized by: The method for mining illegal words in a text as claimed in claim 1, wherein the device comprises: A text segmentation unit, configured to segment the text to be mined input by the user and obtain a plurality of characters to be mined in the text to be mined; A character encoding unit, configured to perform model encoding on each of the characters to be mined using a pre-established illegal character recognition model to obtain a character vector corresponding to each of the characters to be mined, wherein each of the character vectors has multiple illegal category dimensions; A vector dimension transformation unit, configured to perform dimension transformation on each of the character vectors using the illegal character recognition model to obtain a character violation probability of each to-be-mined character relative to each violation category; a probability accumulation unit configured to average, for each violation category, the character violation probabilities of each to-be-mined character in each to-be-mined segmented word in the violation category to obtain a single-category violation probability of each to-be-mined segmented word in the violation category, wherein each to-be-mined segmented word is obtained by segmenting the to-be-mined text, and each to-be-mined segmented word contains one or more to-be-mined characters; A word segmentation filtering unit is used to filter each word to be mined based on the single-category violation probability of each violation category of each word to be mined, using a preset violation probability threshold to obtain the filtered word to be mined under each violation category, and determine the filtered word to be mined under each violation category as the violation word of the text to be mined.

Citation Information

Patent Citations

  • Illegal text recognition algorithm and device based on BERT

    CN113011171A

  • Illegal text detection method and device, equipment and storage medium

    CN114238570A