Sensitive word determination method, device, equipment, storage medium and program product
By training the word vector extraction model and utilizing the word and subword features in the corpus text, we can identify and block sensitive word deformations in phonetic characters, solving the problem of sensitive words being difficult to identify after deformation and improving the sensitive word blocking effect.
Patent Information
- Application Number
- CN202111319256.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-09
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2041-11-09
AI Technical Summary
In the context of phonetic characters, the existing technology makes it difficult to effectively identify and block sensitive words after they are deformed, resulting in poor sensitive word blocking effects.
By training the word vector extraction model, using the words and subwords in the corpus text as training samples, extracting the feature vectors of candidate words and sensitive words, and calculating the vector similarity to identify sensitive word variations, the recognition rate is improved.
The recognition rate of sensitive word variations in phonetic text scenarios has been improved, enhancing the effectiveness of sensitive word shielding.
Smart Images

Figure CN114036260B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of artificial intelligence, and in particular to a method, apparatus, device, storage medium, and program product for determining sensitive words. Background Art
[0002] In order to ensure a good Internet environment, sensitive words will be blocked in Internet products such as websites, forums, and applications.
[0003] In related technologies, sensitive words are usually identified based on a pre-set sensitive word vocabulary, and the identified sensitive words are then blocked. For example, if a comment consists of word 1, word 2, and word 3, if word 1 belongs to the sensitive word vocabulary, the comment will be blocked.
[0004] However, for phonetic characters, criminals may distort sensitive words to avoid being blocked, resulting in poor effectiveness of vocabulary-based sensitive word blocking. For example, in the English context, the distortion of sensitive words may include adjusting the order of letters or omitting some letters. Summary of the Invention
[0005] The present application provides a method, apparatus, device, storage medium, and program product for determining sensitive words. The technical solution is as follows:
[0006] In one aspect, an embodiment of the present application provides a method for determining sensitive words, the method comprising:
[0007] A word vector extraction model is trained based on a corpus text and subwords of each word in the corpus text, wherein the corpus text is a phonetic text;
[0008] Perform feature extraction on the candidate words corresponding to the corpus text using the word vector extraction model to obtain a candidate word vector corresponding to each candidate word, wherein the candidate word is composed of at least one word;
[0009] Extract features of the original sensitive word using the word vector extraction model to obtain a word vector for the sensitive word, where the original sensitive word is composed of at least one word;
[0010] Based on the sensitive word word vector and the candidate word word vector, a candidate sensitive word among the candidate words is determined, wherein the candidate sensitive word includes at least one of the original sensitive word or the transformed sensitive word, and the transformed sensitive word is obtained by transforming the original sensitive word.
[0011] On the other hand, an embodiment of the present application provides a device for determining sensitive words, the device comprising:
[0012] A training module, configured to train a word vector extraction model based on a corpus text and subwords of each word in the corpus text, wherein the corpus text is a phonetic text;
[0013] A first extraction module is configured to perform feature extraction on the candidate words corresponding to the corpus text using the word vector extraction model to obtain a candidate word vector corresponding to each candidate word, wherein the candidate word is composed of at least one word;
[0014] A second extraction module is configured to extract features of the original sensitive word using the word vector extraction model to obtain a word vector for the sensitive word, where the original sensitive word is composed of at least one word;
[0015] A determination module is used to determine a candidate sensitive word among the candidate words based on the sensitive word word vector and the candidate word word vector, wherein the candidate sensitive word includes at least one of the original sensitive word or the transformed sensitive word, and the transformed sensitive word is obtained by transforming the original sensitive word.
[0016] On the other hand, an embodiment of the present application provides a computer device, which includes a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the method for determining sensitive words as described in the above aspects.
[0017] On the other hand, an embodiment of the present application provides a computer-readable storage medium, which stores at least one instruction, and the instruction is loaded and executed by a processor to implement the method for determining sensitive words provided in various aspects of the present application.
[0018] On the other hand, an embodiment of the present application provides a computer program product, which includes computer instructions. When the computer instructions are executed by a processor, the method for determining sensitive words described in the above aspects is implemented.
[0019] In an embodiment of the present application, when training the word vector extraction model, in addition to using the corpus text as a training sample, the subwords of each word in the corpus text are also used as training samples, thereby improving the word vector extraction model's ability to recognize deformed words; subsequently, after using the trained word vector extraction model to perform feature extraction on the candidate words and the original sensitive words in the corpus text, sensitive words can be identified based on the word vectors corresponding to the candidate words and the original sensitive words. The solution provided in the embodiment of the present application helps to improve the recognition rate of deformed sensitive words in phonetic text scenarios, thereby improving the effect of sensitive word shielding. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly introduce the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0021] Figure 1 is a schematic diagram of an implementation environment provided by an exemplary embodiment of the present application;
[0022] Figure 2 A flowchart of a method for determining sensitive words provided by an exemplary embodiment of the present application is shown;
[0023] Figure 3 This is a schematic diagram illustrating the principle of a sensitive word determination process according to an exemplary embodiment of the present application;
[0024] Figure 4 A flowchart of a method for determining sensitive words provided by another exemplary embodiment of the present application is shown;
[0025] Figure 5 is a schematic diagram of a word vector determination process output by an exemplary embodiment;
[0026] Figure 6 This is a schematic diagram illustrating an implementation of a sensitive word determination process according to an exemplary embodiment of the present application;
[0027] Figure 7 A structural block diagram of a device for determining sensitive words provided by an exemplary embodiment of the present application is shown. DETAILED DESCRIPTION
[0028] Figure 1 1 is a schematic diagram of an implementation environment provided by an exemplary embodiment of the present application, wherein the implementation environment includes a terminal 110 and a server 120 .
[0029] The terminal 110 is an electronic device used to set a sensitive word recognition task, and the electronic device may be a smart phone, a tablet computer, a personal computer, a personal workstation, or the like. Figure 1 The terminal 110 is described as a personal computer as an example, but this is not a limitation.
[0030] Optionally, terminal 110 is configured to publish a sensitive word recognition task to server 120. The sensitive word recognition task may include the original sensitive word and the sensitive word length of the sensitive word to be recognized. The original sensitive word may be published in the form of a vocabulary. Illustratively, the sensitive word recognition task published by the terminal includes the vocabulary of the original sensitive word and the sensitive word length 2, i.e., mining sensitive words consisting of two words.
[0031] Server 120 is a server used to perform sensitive word recognition tasks. It can be a single server or a server group composed of multiple servers; it can be a physical server or a cloud server, which is not limited in this embodiment of the present application.
[0032] Optionally, server 120 is a website's backend server, configured to identify sensitive words in website content; server 120 is an application's backend server, configured to identify sensitive words in text content posted by users in the application; or server 120 is a forum's backend server, configured to identify sensitive words in posts or comments posted by users in the forum. The embodiments of this application do not limit the specific type of server.
[0033] Optionally, server 120 collects corpus text in advance and trains a word vector extraction model based on the corpus text. The word vector extraction model is used to output word vectors corresponding to the input text. After receiving the sensitive word identification task issued by terminal 110, server 120 uses the word vector extraction model to extract features from the corpus text and the original sensitive words to obtain their corresponding word vectors, and then identifies candidate sensitive words in the corpus text based on the word vectors.
[0034] In one possible implementation, the server 120 shields the corpus text containing the candidate sensitive words, or feeds back the identified candidate sensitive words to the terminal 110, which further confirms the candidate sensitive words. For example, the candidate sensitive words can be further screened through manual review.
[0035] It should be noted that the above embodiment is only described by taking the word vector extraction model and sensitive word identification performed by the server as an example. In other possible implementations, the terminal can also train the word vector extraction model and perform sensitive word identification, and this embodiment does not constitute a limitation. For ease of description, the following embodiments are described by taking the method of determining sensitive words performed by a computer device as an example.
[0036] Please refer to Figure 2 , which shows a flowchart of a method for determining sensitive words provided by an exemplary embodiment of the present application. The method may include the following steps.
[0037] Step 201 : training a word vector extraction model based on a corpus text and subwords of each word in the corpus text, where the corpus text is a phonetic text.
[0038] In one possible implementation, a computer device first collects corpus text for training a word vector extraction model. The corpus text may be a phonetic text captured from the Internet. The phonetic text may be a text using Latin letters, such as English text or French text, a Russian text using Cyrillic letters, an Arabic text using Arabic letters, and the like. The present embodiment of the application does not limit the specific language of the phonetic text. For ease of description, the following embodiment is described using English text as an example, but this is not intended to be limiting.
[0039] Optionally, the corpus text includes compliant corpus text and non-compliant corpus text, wherein the non-compliant corpus text contains at least one of the original sensitive words or the inflected sensitive words, and the compliant corpus text does not contain the original sensitive words or the inflected sensitive words.
[0040] In the embodiment of the present application, the word vector extraction model is used to extract features from the input text and output the word vectors corresponding to the words in the text. In addition, in order to improve the recognition ability of inflected words, when training the word vector extraction model, in addition to using the corpus text as a training sample, the subwords of each word in the corpus text are also used as training samples. Accordingly, the word vector corresponding to the word in the expected text is calculated by the vector of the word itself and the vector of each subword, that is, the features of the subword are integrated into the word vector, thereby improving the expression ability of the word vector for the subword in the word.
[0041] A subword is composed of at least two consecutive letters in a word. For example, for the word learning, its corresponding subwords may include lea, ear, ari, rin, and ing.
[0042] Step 202: Feature extraction is performed on the candidate words corresponding to the corpus text through a word vector extraction model to obtain a candidate word vector corresponding to each candidate word, where the candidate word is composed of at least one word.
[0043] In one possible implementation, after completing word vector extraction model training and receiving a sensitive word identification task, the computer device uses the word vector extraction model to extract features from the corpus text. Optionally, based on the sensitive word identification task, the computer device identifies candidate words in the corpus text, and then uses the word vector extraction model to extract features from the candidate words to obtain candidate word vectors corresponding to the candidate words.
[0044] Optionally, the candidate word is a single word or a phrase consisting of at least two words. Correspondingly, when the candidate word is a single word, the candidate word vector is the word vector of the word; when the candidate word is a phrase, the candidate word vector is the word vector of the phrase. The following embodiment describes in detail how to determine the word vector corresponding to a phrase.
[0045] Step 203: extract features of the original sensitive word through a word vector extraction model to obtain a word vector of the sensitive word, where the original sensitive word is composed of at least one word.
[0046] In one possible implementation, after completing the word vector extraction model training and receiving the sensitive word recognition task, the computer device performs feature extraction on the original sensitive word through the word vector extraction model, wherein the original sensitive word can be included in the vocabulary indicated by the sensitive word recognition task, and the sensitive word recognition task is used to indicate the original sensitive word contained in the recognition corpus text, as well as the sensitive word deformed word obtained by deforming the original sensitive word.
[0047] Optionally, the original sensitive word is a single word or a phrase consisting of at least two words. Correspondingly, when the original sensitive word is a single word, the word vector of the sensitive word is the word vector of the word; when the original sensitive word is a phrase, the word vector of the sensitive word is the word vector of the phrase.
[0048] It should be noted that there is no strict execution sequence between the above steps 202 and 203, that is, step 202 and step 203 can be executed successively or simultaneously, and this embodiment does not limit this.
[0049] Step 204: Based on the sensitive word vector and the candidate word vector, determine the candidate sensitive word among the candidate words. The candidate sensitive word includes at least one of the original sensitive word or the transformed sensitive word. The transformed sensitive word is obtained by transforming the original sensitive word.
[0050] Furthermore, the computer device selects a candidate sensitive word from the candidate words based on the sensitive word vector and the candidate word vector. The candidate sensitive word can be the same as the original sensitive word or a modified sensitive word obtained by modifying the original sensitive word. The modification of the original sensitive word can include letter substitution, letter sequence substitution, or letter omission, etc.
[0051] In one possible implementation, the computer device determines the candidate sensitive word by calculating the vector similarity between the sensitive word vector and the candidate word vector.
[0052] Taking English text as an example, when the original sensitive word includes "stupidjerk", the determined candidate sensitive words may include "stupidjxxk" and so on.
[0053] Indicatively, the process of determining sensitive words is as follows: Figure 3As shown. The computer device first trains a word vector extraction model 33 based on a corpus text 31 and subwords 32 of words in the corpus text, then determines a candidate word 34 from the corpus text 31, inputs the candidate word 34 into the word vector extraction model 33 for feature extraction, and obtains a candidate word vector 35, and inputs the original sensitive word 36 into the word vector extraction model 33 for feature extraction, and obtains a sensitive word vector 37. Then, based on the candidate word vector 35 and the sensitive word vector 37, the computer device determines a candidate sensitive word 38 corresponding to the original sensitive word from the candidate word 34.
[0054] To sum up, in the embodiment of the present application, when training the word vector extraction model, in addition to using the corpus text as a training sample, the subwords of each word in the corpus text are also used as training samples, thereby improving the word vector extraction model's ability to recognize deformed words; subsequently, after using the trained word vector extraction model to perform feature extraction on the candidate words and the original sensitive words in the corpus text, sensitive words can be identified based on the word vectors corresponding to the candidate words and the original sensitive words. The solution provided in the embodiment of the present application helps to improve the recognition rate of deformed sensitive words in phonetic text scenarios, thereby improving the effect of sensitive word shielding.
[0055] Please refer to Figure 4 , which shows a flowchart of a method for determining sensitive words provided by another exemplary embodiment of the present application, and the method may include the following steps.
[0056] Step 401: Perform n-gram segmentation on each word in the corpus text to obtain subwords, where n is an integer greater than or equal to 2.
[0057] In one possible implementation, before using corpus text for model training, the computer device first performs n-gram segmentation (character-level segmentation) on each word in the same corpus text to obtain several subwords corresponding to the word, where each subword consists of n characters (letters or symbols).
[0058] Here, n can be a default value or a custom value, which is not limited in this embodiment.
[0059] Optionally, the computer device uses at least one word segmentation method to segment words so that the word vector extraction model can learn the characteristics of subwords in different dimensions during subsequent model training. For example, words can be segmented into 2-gram and 3-gram.
[0060] Optionally, before performing n-gram segmentation, the computer device adds special symbols before and after the word to indicate the beginning and end of the word. The special symbols may be "<" and ">". In an illustrative example, the word jxxk is segmented by 3-gram, and the segmented words obtained include<jx、jxx、xxk、xk> .
[0061] Step 402: Generate a word sequence based on the words and subwords in the corpus text.
[0062] After completing the word segmentation, the computer device generates a word sequence corresponding to the corpus text based on each word in the same corpus text and the subwords corresponding to each word for subsequent model training.
[0063] In an illustrative example, when the corpus text is stupidjxxk, the word sequence generated by the computer device is {stupid, jxxk,<st,stu,tup,upi,pid,id> ,<jx、jxx、xxk、xk>}.
[0064] Step 403: training a word vector extraction model based on word sequences and contextual relationships between words in the corpus text.
[0065] Since there must be correlation between words in the same corpus text (for example, some words may appear in combination), the computer device can use an unsupervised method to train the word vector extraction model based on the contextual relationship of the words in the corpus text.
[0066] Optionally, the computer device predicts the word vector of the context word corresponding to a certain word in the corpus text based on the word vector corresponding to the word; or, the computer device can predict the word vector of the words between the context words based on the word vector of the context words in the corpus text.
[0067] The word vector of a word is obtained by superimposing the word vector corresponding to the word itself and the word vectors of each subword corresponding to the word. Figure 5 As shown, for word jxxk, its corresponding word vector can be expressed as V <jxxk>< / jxxk> +V <jx +V jxx +V xxk +V xk> .
[0068] In one possible implementation, the computer device trains a word vector extraction model using a skip-gram algorithm based on word sequences and contextual relationships between words in the corpus text. The skip-gram algorithm is used to perform context prediction based on the central word.
[0069] For example, when the corpus text consists of word A, word B, word C, and word D, when the model is trained based on the context relationship, word A and word C can be predicted based on word B (i.e., the central word), and word B and word D can be predicted based on word C (i.e., the central word).
[0070] In another possible implementation, the computer device trains a word vector extraction model based on word sequences and contextual relationships of words in the corpus text using a CBOW (Continuous Bag-Of-Words model) algorithm, where the CBOW algorithm is used to predict central words based on the context.
[0071] For example, when the corpus text consists of word A, word B, word C, and word D, when the model is trained based on the context relationship, word B (i.e., the central word) can be predicted based on word A and word C, and word C (i.e., the central word) can be predicted based on word B and word D.
[0072] Optionally, when the skip-gram algorithm or the CBOW algorithm is used for model training, the computer may use a hierarchical softmax or negative sampling method to perform model training, which is not limited in this embodiment.
[0073] In some embodiments, the word vector extraction model trained by the computer device can be a Fasttext word vector model. Of course, other word vector extraction models that can output word vectors containing subword features can also be used, and the embodiments of the present application are not limited to this.
[0074] In an illustrative example, the parameters from the input layer to the hidden layer of the word vector extraction model include a matrix W, which has a size of N×V, where V is the size of the vocabulary (i.e., the vector dimension of the one-hot vectors corresponding to the words and subwords in the input word sequence), N is the dimension of the word vector to be generated, and N is the number of hidden nodes in the hidden layer (the first layer). Each iteration of training adjusts the matrix W. Due to the nature of one-hot, each adjustment of the matrix W only modifies the row containing parameter 1 in the one-hot.
[0075] After completing the word vector extraction model training through steps 401 to 403 above, the computer device performs feature extraction on the candidate words through steps 404 to 406 below, and performs feature extraction on the original sensitive words through steps 407 to 408 below. It should be noted that there is no strict sequence between steps 404 to 406 and steps 407 to 408. This embodiment uses the example of the simultaneous execution of steps 404 to 406 and steps 407 to 408 as an example for explanation.
[0076] Step 404: Obtain the target word quantity of the candidate sensitive words, where the target word quantity is the number of words contained in the candidate sensitive words.
[0077] In one possible implementation, the sensitive word identification task includes a target word count, which indicates the number of words contained in the candidate sensitive words to be mined. For example, when mining sensitive words consisting of a single word or a sensitive word consisting of two words, the target word count can be set to 1 or 2.
[0078] Optionally, the target word quantity may be a default value or customized data, which is not limited in this embodiment.
[0079] Step 405 : performing word segmentation processing on the corpus text based on the number of target words to obtain at least one candidate word, where the candidate word is composed of words of the target number of words, and the words in the candidate word are continuous in the corpus text.
[0080] Furthermore, the computer device performs word segmentation processing on the corpus text based on the target word number to obtain candidate words consisting of the target word number. In a possible implementation, the computer device performs n-gram word segmentation processing on the corpus text based on the target word number to obtain candidate words.
[0081] Indicative, such as Figure 6 As shown, when the number of target words is 2, that is, a phrase consisting of two words needs to be mined, the computer device performs 2-gram segmentation on the corpus sample 61 (Youstupidjerk) to obtain the first candidate word 611 (Youstupid) and the second candidate word 612 (stupidjerk).
[0082] Step 406: Perform feature extraction on the candidate words corresponding to the corpus text using a word vector extraction model to obtain a candidate word vector corresponding to each candidate word.
[0083] For each candidate word, the computer device inputs the candidate word into the word vector extraction model, and the word vector extraction model extracts features of each word in the candidate word to obtain the word vector corresponding to each word, and then determines the candidate word vector based on the word vector of each word.
[0084] In one possible implementation, when the candidate word is a single word, the candidate word vector is the word vector of the single word; when the candidate word is at least two words, the candidate word vector is the superposition of the corresponding word vectors of each word.
[0085] Indicative, such as Figure 6As shown, the computer device inputs the first candidate word 611 and the second candidate word 612 into the word vector extraction model 62 respectively, and obtains the first candidate word word vector 631 corresponding to the first candidate word 611 and the second candidate word word vector 632 corresponding to the second candidate word 612, wherein the first candidate word word vector 631 is V you +V stupid , the second candidate word vector 632 is V stupid +V jxxk .
[0086] Step 407: Perform feature extraction on each word in the sensitive word original word through the word vector extraction model to obtain the word vector of each word.
[0087] In one possible implementation, the computer device inputs the original sensitive word into a word vector extraction model, and the word vector extraction model performs feature extraction on each word in the original sensitive word to obtain a word vector. It should be noted that when performing feature extraction on the original sensitive word, it is not necessary to perform word segmentation on the original sensitive word.
[0088] Step 408: Determine the sensitive word vector based on the word vector of each word in the sensitive word original word.
[0089] In a possible implementation, the computer device superimposes the word vectors of each single word in the original sensitive word, thereby determining the superimposed vector as the sensitive word vector.
[0090] Indicative, such as Figure 6 As shown, the computer device uses the word vector extraction model 62 to extract features of the first sensitive word original word 641, the second sensitive word original word 642 and the third sensitive word original word 643 in the sensitive word original word table 64, and obtains the first sensitive word word vector 651, the second sensitive word word vector 652 and the third sensitive word word vector 653 respectively.
[0091] Step 409: For each sensitive word vector, calculate the vector similarity between the sensitive word vector and each candidate word vector.
[0092] Through the above steps, the computer device obtains a first word vector set containing candidate word vectors corresponding to candidate words, and a second word vector set containing sensitive word vectors corresponding to sensitive word original words. Further, the computer device determines the candidate sensitive words among the candidate words by calculating the vector similarity between the vectors.
[0093] In one possible implementation, the computer device determines the vector similarity between the candidate word vector and the sensitive word vector by calculating the vector distance between the two. The smaller the vector distance, the higher the vector similarity between the vectors, and accordingly, the higher the probability that the candidate word is a sensitive word. The vector distance between the candidate word vector and the sensitive word vector can be Euclidean distance, cosine distance, etc., which is not limited in this embodiment of the present application.
[0094] Furthermore, in order to reduce the time consumption of mining sensitive words, in one possible implementation, the computer device uses the FAISS (Facebook AI Similarity Search) framework to perform vector similarity retrieval.
[0095] Indicative, such as Figure 6 As shown, the computer device calculates the first vector similarity between the first candidate word vector 631 and the first sensitive word vector 651, the second vector similarity between the first candidate word vector 631 and the second sensitive word vector 652, the third vector similarity between the first candidate word vector 631 and the third sensitive word vector 653, the fourth vector similarity between the second candidate word vector 632 and the first sensitive word vector 651, the fourth vector similarity between the second candidate word vector 632 and the first sensitive word vector 651, the fifth vector similarity between the second candidate word vector 632 and the second sensitive word vector 652, and the sixth vector similarity between the second candidate word vector 632 and the third sensitive word vector 653.
[0096] In some embodiments, to improve the efficiency of sensitive word recognition and reduce the amount of computation, the computer device only calculates the vector similarity between candidate words and original sensitive words with the same number of words. For example, the computer device calculates the vector similarity between a candidate word consisting of three words and an original sensitive word consisting of three words, and calculates the vector similarity between a candidate word consisting of two words and an original sensitive word consisting of two words.
[0097] Step 410: Determine the first k candidate words whose vector similarity is greater than a similarity threshold as candidate sensitive words, where k is a positive integer.
[0098] In one possible implementation, the computer device sorts the candidate words in descending order according to the calculated vector similarity, thereby determining the candidate words with similarity greater than a similarity threshold and the top k candidate words as the candidate sensitive words corresponding to the original sensitive words.
[0099] For example, the computer device determines the top 10 candidate words with the highest similarity greater than 0.85 as candidate sensitive words. Figure 6As shown, the computer device determines the second candidate word 612 as the sensitive word variant word corresponding to the second sensitive word original word 642 based on the fifth vector similarity.
[0100] In this embodiment, the computer device performs n-gram segmentation on the words in the corpus text to obtain several sub-words, and uses the word sequence composed of the words and sub-words in the corpus text as training samples to train the model, so that the model can learn the characteristics of the sub-words during the training process, thereby improving the expression ability of the word vector extraction model for the sub-word characteristics.
[0101] In addition, during the training process, the skip-gram or CBOW algorithm is used to train the model based on the contextual relationship of words in the corpus text, realizing unsupervised model training without the need to annotate the corpus text, thereby improving the efficiency of model training.
[0102] At the same time, by segmenting the corpus text, we obtain candidate words consisting of the target number of words, and perform feature extraction on the candidate words, which can realize the mining of single-word sensitive words and multi-word sensitive word phrases, thereby improving the comprehensiveness of sensitive word mining.
[0103] Please refer to Figure 7 , which shows a structural block diagram of a device for determining sensitive words provided by an exemplary embodiment of the present application. The device includes:
[0104] A training module 701 is configured to train a word vector extraction model based on a corpus text and subwords of each word in the corpus text, wherein the corpus text is a phonetic text;
[0105] A first extraction module 702 is configured to perform feature extraction on the candidate words corresponding to the corpus text using the word vector extraction model to obtain a candidate word vector corresponding to each candidate word, wherein the candidate word is composed of at least one word;
[0106] The second extraction module 703 is configured to extract features of the original sensitive word using the word vector extraction model to obtain a word vector for the sensitive word, where the original sensitive word is composed of at least one word;
[0107] The determination module 704 is used to determine a candidate sensitive word among the candidate words based on the sensitive word word vector and the candidate word vector, wherein the candidate sensitive word includes at least one of the original sensitive word or the transformed sensitive word, and the transformed sensitive word is obtained by transforming the original sensitive word.
[0108] Optionally, the training module 701 includes:
[0109] A word segmentation unit, configured to perform n-gram segmentation on each word in the corpus text to obtain the subwords, where n is an integer greater than or equal to 2;
[0110] A generating unit, configured to generate a word sequence based on the words in the corpus text and the subwords;
[0111] A training unit is used to train the word vector extraction model based on the word sequence and the contextual relationship of the words in the corpus text.
[0112] Optionally, the training unit is used to:
[0113] Based on the word sequence and the contextual relationship of the words in the corpus text, the word vector extraction model is trained by a skip-gram algorithm, wherein the skip-gram algorithm is used to perform context prediction based on the central word;
[0114] or,
[0115] Based on the word sequence and the contextual relationship of the words in the corpus text, the word vector extraction model is trained by the CBOW algorithm, and the CBOW algorithm is used to predict the central word according to the context.
[0116] Optionally, the word vector extraction model is a Fasttext word vector extraction model.
[0117] Optionally, the device further includes:
[0118] An acquisition module is used to acquire the target word quantity of the candidate sensitive word, where the target word quantity is the number of words contained in the candidate sensitive word;
[0119] The word segmentation module is used to perform word segmentation processing on the corpus text based on the number of target words to obtain at least one candidate word, where the candidate word is composed of words of the target number, and the words in the candidate word are continuous in the corpus text.
[0120] Optionally, the second extraction module 703 includes:
[0121] An extraction unit, configured to extract features of each word in the sensitive word original word using the word vector extraction model to obtain a word vector for each word;
[0122] The first determining unit is used to determine the sensitive word vector based on the word vector of each word in the sensitive word original word.
[0123] Optionally, the determining module includes:
[0124] a calculation unit, configured to calculate, for each of the sensitive word vectors, a vector similarity between the sensitive word vector and each of the candidate word vectors;
[0125] The second determining unit is configured to determine the first k candidate words whose vector similarity is greater than a similarity threshold as the candidate sensitive words, where k is a positive integer.
[0126] To sum up, in the embodiment of the present application, when training the word vector extraction model, in addition to using the corpus text as a training sample, the subwords of each word in the corpus text are also used as training samples, thereby improving the word vector extraction model's ability to recognize deformed words; subsequently, after using the trained word vector extraction model to perform feature extraction on the candidate words and the original sensitive words in the corpus text, sensitive words can be identified based on the word vectors corresponding to the candidate words and the original sensitive words. The solution provided in the embodiment of the present application helps to improve the recognition rate of deformed sensitive words in phonetic text scenarios, thereby improving the effect of sensitive word shielding.
[0127] In this embodiment, the computer device performs n-gram segmentation on the words in the corpus text to obtain several sub-words, and uses the word sequence composed of the words and sub-words in the corpus text as training samples to train the model, so that the model can learn the characteristics of the sub-words during the training process, thereby improving the expression ability of the word vector extraction model for the sub-word characteristics.
[0128] In addition, during the training process, the skip-gram or CBOW algorithm is used to train the model based on the contextual relationship of words in the corpus text, realizing unsupervised model training without the need to annotate the corpus text, thereby improving the efficiency of model training.
[0129] At the same time, by segmenting the corpus text, we obtain candidate words consisting of the target number of words, and perform feature extraction on the candidate words, which can realize the mining of single-word sensitive words and multi-word sensitive word phrases, thereby improving the comprehensiveness of sensitive word mining.
[0130] In an exemplary embodiment, the embodiment of the present application also provides a computer device, which includes a processor and a memory, wherein the memory stores a computer program, and the computer program is loaded and executed by the processor to implement the method for determining sensitive words provided in the above embodiments.
[0131] An embodiment of the present application also provides a computer-readable storage medium, which stores at least one instruction, and the at least one instruction is loaded and executed by a processor to implement the method for determining sensitive words as described in the above embodiments.
[0132] According to one aspect of the present application, a computer program product or computer program is provided, comprising computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the sensitive word determination method provided in various optional implementations of the above aspects.
[0133] Those skilled in the art will appreciate that in one or more of the above examples, the functions described in the embodiments of the present application can be implemented using hardware, software, firmware, or any combination thereof. When implemented using software, these functions can be stored in a computer-readable storage medium or transmitted as one or more instructions or codes on a computer-readable storage medium. Computer-readable storage media include computer storage media and communication media, wherein communication media include any media that facilitates the transmission of computer programs from one place to another. The storage medium can be any available medium that can be accessed by a general-purpose or special-purpose computer.
[0134] The above description is merely an optional embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.
Claims
1. A method for determining sensitive words, characterized in that: The method comprises: Perform n-gram segmentation on each word in the corpus text to obtain subwords, where n is an integer greater than or equal to 2, and the corpus text is a phonetic text; Generate a word sequence based on the words in the corpus text and the subwords; Training a word vector extraction model based on the word sequence and the contextual relationship of the words in the corpus text; Obtaining the target word number of candidate sensitive words, where the target word number is the number of words included in the candidate sensitive words, the candidate sensitive words including at least one of an original sensitive word or a modified sensitive word, the modified sensitive word being obtained by modifying the original sensitive word through at least one of letter replacement, letter sequence replacement, and letter omission, and the original sensitive word being a phrase consisting of at least two words; Performing word segmentation on the corpus text based on the number of target words to obtain at least one candidate word, wherein the candidate word is composed of the number of target words, the words in the candidate word are continuous in the corpus text, and the candidate word is a phrase consisting of at least two words; Performing feature extraction on the candidate words corresponding to the corpus text using the word vector extraction model to obtain a candidate word vector corresponding to each candidate word, wherein the candidate word vector is a superposition of word vectors corresponding to at least two words constituting the candidate word; Perform feature extraction on the original sensitive word using the word vector extraction model to obtain a sensitive word vector; For each of the sensitive word vectors, if the candidate word and the original sensitive word have the same number of words, calculate the vector similarity between the sensitive word vector and the candidate word vector; The first k candidate words whose vector similarity is greater than a similarity threshold are determined as the candidate sensitive words, where k is a positive integer.
2. The method according to claim 1, characterized in that The step of training the word vector extraction model based on the word sequence and the contextual relationship of the words in the corpus text includes: Based on the word sequence and the contextual relationship of the words in the corpus text, the word vector extraction model is trained by a skip-gram algorithm, wherein the skip-gram algorithm is used to perform context prediction based on the central word; or, Based on the word sequence and the contextual relationship of the words in the corpus text, the word vector extraction model is trained by the CBOW algorithm, and the CBOW algorithm is used to predict the central word according to the context.
3. The method according to claim 1, characterized in that The word vector extraction model is a Fasttext word vector extraction model.
4. The method according to any one of claims 1 to 3, characterized in that: The extracting features of the sensitive word original word by the word vector extraction model to obtain the sensitive word word vector includes: Perform feature extraction on each word in the sensitive word original word through the word vector extraction model to obtain the word vector of each word; The sensitive word vector is determined based on the word vectors of each word in the sensitive word original word.
5. A device for determining sensitive words, characterized in that: The device comprises: A training module is used to perform n-gram segmentation on each word in the corpus text to obtain subwords, where n is an integer greater than or equal to 2, and the corpus text is a phonetic text; Generate a word sequence based on the words in the corpus text and the subwords; Training a word vector extraction model based on the word sequence and the contextual relationship of the words in the corpus text; an acquisition module, configured to acquire a target word number of candidate sensitive words, where the target word number is the number of words contained in the candidate sensitive words, the candidate sensitive words including at least one of an original sensitive word or a modified sensitive word, the modified sensitive word being obtained by deforming the original sensitive word through at least one of letter replacement, letter sequence replacement, and letter omission, and the original sensitive word being a phrase consisting of at least two words; a word segmentation module, configured to perform word segmentation processing on the corpus text based on the number of target words to obtain at least one candidate word, wherein the candidate word is composed of words of the target number of words, and the words in the candidate word are continuous in the corpus text, and the candidate word is a phrase consisting of at least two words; A first extraction module is configured to perform feature extraction on the candidate words corresponding to the corpus text using the word vector extraction model to obtain a candidate word vector corresponding to each candidate word, wherein the candidate word vector is a superposition of word vectors corresponding to at least two words constituting the candidate word; A second extraction module is used to extract features of the sensitive word original word through the word vector extraction model to obtain a sensitive word vector; a determination module, configured to calculate, for each of the sensitive word vectors, a vector similarity between the sensitive word vector and the candidate word vector when the candidate word and the original sensitive word have the same number of words; The first k candidate words whose vector similarity is greater than a similarity threshold are determined as the candidate sensitive words, where k is a positive integer.
6. A computer device, characterized in that: The computer device includes a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the method for determining sensitive words as described in any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that The readable storage medium stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the method for determining sensitive words as described in any one of claims 1 to 4.
8. A computer program product, characterized in that The computer program product includes computer instructions, and when the computer instructions are executed by a processor, the method for determining sensitive words according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Map checking method and device
CN113094459A
Word vector representation method and device
CN113536800A