Method, device, electronic device and storage medium for identifying bad language
Through the combination of single-hot encoding and neural network model, the accurate identification and filtering of bad terms on the Internet platform is achieved, and the problem of difficult to effectively identify and filter bad terms in the existing technology is solved, and the security and user experience of the Internet environment are improved.
Patent Information
- Application Number
- CN202010038769.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-01-14
- Publication Date
- 2025-03-28
- Estimated Expiration
- 2040-01-14
AI Technical Summary
There are bad terms on the Internet platform that endanger the physical and mental health of netizens and reduce the user experience. It is difficult for the existing technology to effectively identify and filter these contents.
By encoded text information alone, the feature vectors of each word are obtained, and the pre-trained word vector model is used to process these feature vectors. Then the word vector information is input into the neural network model to obtain the output result, and the probability calculation is performed through the shallow neural network. Finally, the calculated probability and the set probability threshold are compared to the set probability threshold to determine whether the text information is a bad term.
It realizes accurate identification and filtering of bad terms in text information, improves the security and user experience of the Internet environment, and can identify deformed words related to bad terms, improving the recognition rate.
Smart Images

Figure CN111241820B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for identifying bad language. Background Art
[0002] In the past two years, the Internet has maintained its past strong growth momentum and has penetrated further into all aspects of people's lives. For example, various live broadcast software have emerged, such as Douyu Live and Huya Live, and various information flow applications have emerged, such as Douyin and Toutiao. The emergence of these software or applications has brought people an increasingly colorful spiritual life, but due to their openness, they have also brought some problems. For example, insulting, discriminatory and violent bad remarks will appear in the above software or applications. If bad remarks or bad articles become mainstream, it will seriously endanger the physical and mental health and personality growth of immature netizens, and also greatly reduce the user experience of Internet products. Therefore, the maintenance of the order of the network environment is becoming increasingly important, and it is necessary and legitimate to filter the information output by users. Summary of the invention
[0003] In view of the above, it is necessary to propose a method, device, electronic device and storage medium for identifying bad language, which can accurately identify bad language in text information.
[0004] A first aspect of the present invention provides a method for identifying bad language, the method comprising:
[0005] Get text information;
[0006] One-hot encode each word in the text information to obtain a feature vector of each word;
[0007] Processing the feature vector through a pre-trained word vector model to obtain word vector information;
[0008] Inputting the word vector information of each word in the text information into the neural network model in sequence to obtain an output result;
[0009] Inputting the output result into a shallow neural network to complete probability calculation; and
[0010] The calculated probability is compared with a probability threshold to determine whether the text information is an offensive term.
[0011] Preferably, the method further comprises:
[0012] The text information is preprocessed, wherein the preprocessing includes at least one of removing stop words and removing noise words.
[0013] Preferably, the neural network model is a bidirectional GRU neural network model, which is used to obtain semantic information of the text information.
[0014] Preferably, comparing the calculated probability with the probability threshold to determine whether the text information is a bad word includes:
[0015] When the probability is greater than or equal to the probability threshold, confirming that the text information is bad language;
[0016] When the probability is less than the probability threshold, it is confirmed that the text information is not an offensive term.
[0017] Preferably, the shallow neural network is a DNN neural network, and the probability threshold is optimized by a cross entropy loss value.
[0018] Preferably, the method further comprises:
[0019] Extracting the bad words;
[0020] According to the bad words, deformed words related to the bad words in the text information are identified.
[0021] Preferably, the step of identifying, according to the bad words, deformed words related to the bad words in the text information comprises:
[0022] Extracting suspected deformed words related to the bad words in the text information;
[0023] Converting the bad words and the suspected deformed words into phonetic codes;
[0024] Calculating the similarity between the phonetic code of the bad words and the phonetic code of the suspected deformed words by using the edit distance;
[0025] When the similarity is greater than or equal to a preset value, confirming that the suspected deformed word is a deformed form of the bad word;
[0026] When the similarity is less than the preset value, it is confirmed that the suspected deformed word is not a deformed form of the bad word.
[0027] A second aspect of the present invention provides a device for identifying bad language, the device comprising:
[0028] An acquisition module is used to acquire text information;
[0029] An encoding module, used for one-hot encoding each word in the text information to obtain a feature vector of each word;
[0030] A processing module, used for processing the feature vector by a pre-trained word vector model to obtain word vector information;
[0031] An input module, used to input the word vector information of each word in the text information into the neural network model in sequence to obtain an output result;
[0032] A calculation module, used for inputting the output result into a shallow neural network to complete probability calculation; and
[0033] The comparison module is used to compare the calculated probability with the probability threshold to determine whether the text information is a bad word.
[0034] A third aspect of the present invention provides an electronic device, comprising a processor and a memory, wherein the processor is configured to implement the method for identifying bad language when executing a computer program stored in the memory.
[0035] A fourth aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, and the computer program implements the method for identifying bad language when executed by a processor.
[0036] The method, device, electronic device and storage medium for identifying bad language described in the present invention. Obtain a feature vector of each word by one-hot encoding each word in the text information; then process the feature vector with a pre-trained word vector model to obtain word vector information; input the word vector information of each word in the text information into a neural network model in sequence to obtain an output result; input the output result into a shallow neural network to complete probability calculation; and compare the calculated probability with a probability threshold to determine whether the text information is bad language. Thus, bad language in the text information can be identified. The bad language identification method can also identify deformed words related to the bad language in the text information, thereby improving the recognition rate of bad language. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0038] Figure 1 This is a flow chart of a method for identifying bad language provided in Example 1 of the present invention.
[0039] Figure 2 It is a functional module diagram of the device for identifying bad language provided in the second embodiment of the present invention.
[0040] Figure 3 It is a schematic diagram of an electronic device provided in Embodiment 3 of the present invention.
[0041] The following specific implementation manner will further illustrate the present invention in conjunction with the above-mentioned drawings. DETAILED DESCRIPTION
[0042] In order to more clearly understand the above-mentioned purpose, features and advantages of the present invention, the present invention is described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be noted that the embodiments of the present invention and the features in the embodiments can be combined with each other without conflict.
[0043] In the following description, many specific details are set forth to facilitate a full understanding of the present invention. The embodiments described are only a part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0044] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used in the specification of the present invention herein are only for the purpose of describing specific embodiments and are not intended to limit the present invention.
[0045] The terms "first", "second", "third", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the term "comprising" and any variation thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device comprising a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units that are inherent to these processes, methods, products or devices.
[0046] The method for identifying bad language according to the embodiment of the present invention is applied in an electronic device. For the electronic device that needs to identify bad language, the function of identifying bad language provided by the method of the present invention can be directly integrated on the electronic device, or a client for implementing the method of the present invention can be installed. For another example, the method provided by the present invention can also be run on a server or other device in the form of a software development kit (SDK), and an interface for the function of identifying bad language is provided in the form of SDK, and the electronic device or other device can realize the function of identifying bad language through the provided interface.
[0047] Embodiment 1
[0048] Figure 1This is a flow chart of the method for identifying bad language provided by the first embodiment of the present invention. According to different requirements, the execution order in the flow chart can be changed, and some steps can be omitted.
[0049] Step S1, obtaining text information.
[0050] In this embodiment, the text information may be text information input by a user, or may be text information obtained by performing text conversion based on collected voice information.
[0051] For example, when the bad language identification method is used to identify whether user comments in live broadcast software such as Douyu Live or Huya Live include bad language, the user comments entered by the user in the live broadcast software can be collected as the text information.
[0052] For another example, when the spam recognition method is used to identify whether someone uses bad language in a certain environment, the user's voice information can be collected through a microphone, and then the collected voice information can be converted into text information.
[0053] Preferably, the method for identifying bad language further comprises: a step of preprocessing the text information, wherein the preprocessing includes removing stop words and noise words.
[0054] Step S2, one-hot encode each word in the text information to obtain a feature vector corresponding to each word.
[0055] The one-hot encoding is also called a single-bit effective encoding, which mainly uses an N-bit state register to encode N states, each state is represented by its own independent register bit, and only one bit is valid at any time. One-hot encoding is the representation of a categorical variable as a binary vector. In this embodiment, by performing one-hot encoding on the text information, when the text information is classified and machine-learned, the distance calculation between the vector corresponding to the text information and the vector corresponding to the non-bad words can be made more reasonable. Thereby more accurately identifying whether the text information includes bad words.
[0056] Step S3, processing the feature vector through a pre-trained word vector model to obtain word vector information.
[0057] In this embodiment, the pre-trained word vector model is a Bert pre-trained model. The Bert pre-trained model is a more complex and accurate word vector generation model. When the feature vector corresponding to the word is input in units of words, the Bert pre-trained model can output the corresponding word vector according to the feature vector. It should be noted that the feature vector corresponding to the word is the vector obtained after the word is uniquely encoded.
[0058] The word vector generated by the Bert pre-training model is a further processing of the vector obtained after the one-hot encoding process. Since the length of the one-hot encoding is tens of thousands, there will be a situation where the information redundancy is extremely high. When the corpus is large, for example, there are tens of thousands of words, each one-hot encoding length is tens of thousands, there will be a situation where the information redundancy is extremely high. Word2vec, bert and other word embedding representation models are based on deep learning models to compress these tens of thousands of word vector representations into word vector representations that may be only a few hundred in length. The Bert pre-training model is an open source large-scale general pre-training word vector model that supports Chinese. Therefore, this application can use the Bert pre-training model in the selection of pre-training word vector models. The Bert pre-training model is a prior art and will not be introduced in detail here.
[0059] Step S4, inputting the word vector information corresponding to each word in the text information into the neural network model in sequence to obtain an output result.
[0060] In this embodiment, the neural network model is a bidirectional GRU neural network model, which is used to obtain the semantic information of the text information. The bidirectional GRU neural network model is a pre-trained network model. After the word vector information is input into the bidirectional GRU neural network model, the output result corresponding to the text information can be obtained.
[0061] GRU (Gated Recurrent Unit) is a variant of LSTM, which makes many simplifications to LSTM. GRU neural network is a simplified version of LSTM. Compared with LSTM, it has only two gates: update gate and reset gate. The update gate is used to control the degree to which the state information of the previous moment is brought into the current state. The larger the value of the update gate, the more state information of the previous moment is brought in; the reset gate is used to control the degree to which the state information of the previous moment is ignored. The smaller the reset gate, the more information is ignored. The parameters of the GRU neural network are reduced by 1 / 3 compared with LSTM, and it is not easy to overfit. In addition, the GRU neural network is better in convergence time and the number of iterations required. GRU can make the structure of the model simpler while maintaining the effect of LSTM.
[0062] The forward propagation formula of the GRU neural network is as follows:
[0063] r t =σ(W r ×[h t-1 , x t ])
[0064] z t =σ(W z ×[h t-1 , xt ])
[0065]
[0066]
[0067] y t =σ(W0×h t )
[0068] Among them, x t Represents the input at the current moment; h t-1 Indicates the output at the previous moment; W r , W z , and W0 are the corresponding weight matrices; z t and r t are update gate and reset gate respectively; σ represents sigmoid activation function; Indicates the output at the update time; h t Represents the output at the current moment; y t Indicates the output result.
[0069] Step S5, input the output result into a shallow neural network to complete probability calculation.
[0070] In this embodiment, the shallow neural network may be a DNN neural network. In this application, the probability value output by the shallow neural network DNN is compared with the probability threshold to determine whether the text information contains bad words or trash talk.
[0071] Preferably, the method can optimize network parameters through cross entropy loss value, so as to obtain more accurate probability value. The calculation formula of the cross entropy loss value is as follows:
[0072] Where x is the probability value output by the shallow neural network DNN.
[0073] Step S6, comparing the calculated probability with the probability threshold to determine whether the text information is bad language.
[0074] In this embodiment, when the probability is greater than or equal to the probability threshold, the text information is confirmed to be an inappropriate term; when the probability is less than the probability threshold, the text information is confirmed not to be an inappropriate term.
[0075] In one embodiment, each word in the text information can also be uniquely encoded to obtain a feature vector of each word; the feature vector is processed by a pre-trained word vector model to obtain word vector information; the word vector information of each word in the text information is input into a neural network model in sequence to obtain an output result; the output result is input into a shallow neural network to complete a probability calculation; and the calculated probability is compared with a probability threshold to determine whether the text information is a bad word.
[0076] For example, when the text information obtained is "The weather is good today", each word in the text information "The weather is good today" is uniquely encoded to obtain the feature vector corresponding to each word, and the word vector information corresponding to the feature vector is obtained according to the pre-trained word vector model, that is, the word vector information of length N corresponding to each word is obtained. For example, by processing "today" through unique hot encoding and the word vector model, a word vector V0 of length N can be obtained, and by processing "day" through unique hot encoding and the word vector model, a word vector V1 of length N can be obtained. By analogy, by processing "the weather is good today" through unique hot encoding and the word vector model, word vectors V0, V1, V2, V3 and V4 can be obtained. Then, the word vectors V0, V1, V2, V3 and V4 are input into the GRU recurrent neural network model in turn to obtain the output result S4. Then, the output result S4 is input into the shallow neural network to complete the probability calculation to obtain the probability of whether the text information "the weather is good today" is a bad word.
[0077] In this embodiment, the judgment of whether the text information is bad language is modeled based on the idea of two classifications, so the final classification result is a probability value. Based on this probability value, it is necessary to define a probability threshold as a decision criterion, for example, a probability greater than 0.7 or greater than 0.9 is used as a criterion for judging bad language. The setting of the probability threshold will have a great impact on the model performance and user experience. In practical applications, it is generally adjusted and optimized by trying different reasonable values for many times. Sometimes a more severe situation may be encountered, that is, the probability of bad language and non-bad language is 0.5 respectively. In this case, it actually means that the model cannot distinguish and judge whether the text information is bad language well. For this case, rules can be set to save such corpus, and the relevant corpus annotation personnel will annotate it, and finally use it as training material to feed back the model training process.
[0078] Another situation is the emergence of new words and new sentence patterns. The terms and sentence patterns on the Internet are endless and changing with each passing day. When the existing database cannot cover them, new words and new sentence patterns can be added to the knowledge base and the neural network can be retrained at the appropriate time, which provides users with great flexibility. In addition, new corpora can be tracked and collected in real time, which is a condition to ensure that the model can achieve the ultimate performance.
[0079] Preferably, the method further comprises: extracting the bad words, and identifying the deformed words related to the bad words in the text message according to the bad words. In one embodiment, some malicious users often deform bad words to avoid the messages they send being filtered by the system. For example, "go to death" is written as "go to shit".
[0080] In this embodiment, the deformed words related to the bad words in the text information can be identified according to the pinyin pattern of the word. Specifically, the suspected deformed words related to the bad words in the text information are first extracted, and then the bad words and the suspected deformed words are converted into phonetic codes, and the similarity between the phonetic code of the bad words and the phonetic code of the suspected deformed words is calculated by editing distance. When the similarity is greater than or equal to a preset value, it is confirmed that the suspected deformed words are the deformed bodies of the bad words. In this embodiment, the suspected deformed words are words obtained by deforming the bad words, for example, words obtained according to the same pinyin of the bad words, or words after inserting special characters into the bad words.
[0081] In this embodiment, the phonetic code is a coding method for Chinese character pinyin, which can express the pinyin characteristics of Chinese characters by coding, thereby expressing the pronunciation characteristics of Chinese characters. Based on the phonetic code, the pinyin of Chinese characters can be converted into corresponding character sequences.
[0082] In other implementations, the deformed words related to the bad words in the text information may also be identified through word abbreviation patterns and word splitting patterns.
[0083] In summary, the method for identifying bad language provided by the present invention includes obtaining text information; uniquely encoding each word in the text information to obtain a feature vector of each word; processing the feature vector through a pre-trained word vector model to obtain word vector information; inputting the word vector information of each word in the text information into a neural network model in sequence to obtain an output result; inputting the output result into a shallow neural network to complete probability calculation; and comparing the calculated probability with the probability threshold to determine whether the text information is a bad language. Thus, bad language in text information can be identified. This method can also continuously maintain and update the model in a virtuous cycle through data collection and updating, so that the model maintains a dynamically changing adaptability, can promptly and quickly determine whether the text information includes bad language, and will not be easily eliminated by the rapid development of the network. Since there is no need to build your own statistical corpus for modeling, developers do not need a lot of professional knowledge, nor do they need to maintain a professional statistical corpus, which greatly reduces the difficulty of modeling and the time of development.
[0084] The above is only a specific implementation of the present invention, but the protection scope of the present invention is not limited thereto. For ordinary technicians in this field, improvements can be made without departing from the creative concept of the present invention, but these all belong to the protection scope of the present invention.
[0085] Combine the following Figure 2 and Figure 3 , the functional modules and hardware structure of the electronic device that implements the above-mentioned method for identifying bad language are introduced respectively.
[0086] Embodiment 2
[0087] Figure 2 This is a functional module diagram of a preferred embodiment of the device for identifying bad language of the present invention.
[0088] In some embodiments, the bad language recognition device 20 (for ease of description, referred to as "recognition device") runs in an electronic device. The recognition device 20 may include a plurality of functional modules composed of program code segments. The program code of each program segment in the recognition device 20 may be stored in a memory and executed by at least one processor to perform the function of bad language recognition.
[0089] In this embodiment, the recognition device 20 can be divided into multiple functional modules according to the functions it performs. The functional modules may include: an acquisition module 201, an encoding module 202, a processing module 203, an input module 204, a calculation module 205 and a comparison module 206. The module referred to in the present invention refers to a series of computer program segments that can be executed by at least one processor and can complete fixed functions, which are stored in a memory. In some embodiments, the functions of each module will be described in detail in subsequent embodiments.
[0090] The acquisition module 201 is used to acquire text information.
[0091] In this embodiment, the text information may be text information input by a user, or may be text information obtained by performing text conversion based on collected voice information.
[0092] For example, when the identification device 20 is used to identify whether user comments in live broadcast software such as Douyu Live or Huya Live include bad words, the user comments entered by the user in the live broadcast software can be collected as the text information.
[0093] For another example, when the recognition device 20 is used to recognize whether someone uses bad language in a certain environment scene, the user's voice information can be collected through a microphone, and then the collected voice information is converted into text information.
[0094] Preferably, the recognition device 20 may further include: a step of preprocessing the text information, wherein the preprocessing includes removing stop words and noise words.
[0095] The encoding module 202 is used to one-hot encode each word in the text information to obtain a feature vector corresponding to each word.
[0096] The one-hot encoding is also called a single-bit effective encoding, which mainly uses an N-bit state register to encode N states, each state is represented by its own independent register bit, and only one bit is valid at any time. One-hot encoding is the representation of a categorical variable as a binary vector. In this embodiment, by performing one-hot encoding on the text information, when the text information is classified and machine-learned, the distance calculation between the vector corresponding to the text information and the vector corresponding to the non-bad words can be made more reasonable. Thereby more accurately identifying whether the text information includes bad words.
[0097] The processing module 203 is used to process the feature vector through a pre-trained word vector model to obtain word vector information.
[0098] In this embodiment, the pre-trained word vector model is a Bert pre-trained model. The Bert pre-trained model is a more complex and accurate word vector generation model. When the feature vector corresponding to the word is input in units of words, the Bert pre-trained model can output the corresponding word vector according to the feature vector. It should be noted that the feature vector corresponding to the word is the vector obtained after the word is uniquely encoded.
[0099] The input module 204 is used to input the word vector information corresponding to each word in the text information into the neural network model in sequence to obtain an output result.
[0100] In this embodiment, the neural network model is a bidirectional GRU neural network model, which is used to obtain the semantic information of the text information. The bidirectional GRU neural network model is a pre-trained network model. After the word vector information is input into the bidirectional GRU neural network model, the output result corresponding to the text information can be obtained.
[0101] GRU (Gated Recurrent Unit) is a variant of LSTM, which makes many simplifications to LSTM. GRU neural network is a simplified version of LSTM. Compared with LSTM, it has only two gates: update gate and reset gate. The update gate is used to control the degree to which the state information of the previous moment is brought into the current state. The larger the value of the update gate, the more state information of the previous moment is brought in; the reset gate is used to control the degree to which the state information of the previous moment is ignored. The smaller the reset gate, the more information is ignored. The parameters of the GRU neural network are reduced by 1 / 3 compared with LSTM, and it is not easy to overfit. In addition, the GRU neural network is better in convergence time and the number of iterations required. GRU can make the structure of the model simpler while maintaining the effect of LSTM.
[0102] The forward propagation formula of the GRU neural network is as follows:
[0103] The forward propagation formula of the GRU neural network is as follows:
[0104] r t =σ(W r ×[h t-1 , x t ])
[0105] z t =σ(W z ×[h t-1 ,x t ])
[0106]
[0107]
[0108] y t =σ(W0×h t )
[0109] Among them, x t Represents the input at the current moment; h t-1 Indicates the output at the previous moment; W r , W z , and W0 are the corresponding weight matrices; z t and r t are update gate and reset gate respectively; σ represents sigmoid activation function; Indicates the output at the update time; h t Represents the output at the current moment; y t Indicates the output result.
[0110] The calculation module 205 is used to input the output result into a shallow neural network to complete the probability calculation.
[0111] In this embodiment, the shallow neural network may be a DNN neural network. In this application, the probability value output by the shallow neural network DNN is compared with the probability threshold to determine whether the text information contains bad words or trash talk.
[0112] Preferably, the calculation module 205 can optimize the network parameters by the cross entropy loss value, so as to obtain a more accurate probability value. The calculation formula of the cross entropy loss value is as follows:
[0113] Where x is the probability value output by the shallow neural network DNN.
[0114] The comparison module 206 is used to compare the calculated probability with a probability threshold to determine whether the text information is an offensive term.
[0115] In this embodiment, when the probability is greater than or equal to the probability threshold, the text information is confirmed to be an inappropriate term; when the probability is less than the probability threshold, the text information is confirmed not to be an inappropriate term.
[0116] In one embodiment, each word in the text information can also be uniquely encoded to obtain a feature vector of each word; the feature vector is processed by a pre-trained word vector model to obtain word vector information; the word vector information of each word in the text information is input into a neural network model in sequence to obtain an output result; the output result is input into a shallow neural network to complete a probability calculation; and the calculated probability is compared with a probability threshold to determine whether the text information is a bad word.
[0117] For example, when the text information obtained is "The weather is good today", each word in the text information "The weather is good today" is uniquely encoded to obtain the feature vector corresponding to each word, and the word vector information corresponding to the feature vector is obtained according to the pre-trained word vector model, that is, the word vector information of length N corresponding to each word is obtained. For example, by processing "today" through unique hot encoding and the word vector model, a word vector V0 of length N can be obtained, and by processing "day" through unique hot encoding and the word vector model, a word vector V1 of length N can be obtained. By analogy, by processing "the weather is good today" through unique hot encoding and the word vector model, word vectors V0, V1, V2, V3 and V4 can be obtained. Then, the word vectors V0, V1, V2, V3 and V4 are input into the GRU recurrent neural network model in turn to obtain the output result S4. Then, the output result S4 is input into the shallow neural network to complete the probability calculation to obtain the probability of whether the text information "the weather is good today" is a bad word.
[0118] In this embodiment, the judgment of whether the text information is bad language is modeled based on the idea of two classifications, so the final classification result is a probability value. Based on this probability value, it is necessary to define a probability threshold as a decision criterion, for example, a probability greater than 0.7 or greater than 0.9 is used as a criterion for judging bad language. The setting of the probability threshold will have a great impact on the model performance and user experience. In practical applications, it is generally adjusted and optimized by trying different reasonable values for many times. Sometimes a more severe situation may be encountered, that is, the probability of bad language and non-bad language is 0.5 respectively. In this case, it actually means that the model cannot distinguish and judge whether the text information is bad language well. For this case, rules can be set to save such corpus, and the relevant corpus annotation personnel will annotate it, and finally use it as training material to feed back the model training process.
[0119] Another situation is the emergence of new words and new sentence patterns. The terms and sentence patterns on the Internet are endless and changing with each passing day. When the existing database cannot cover them, new words and new sentence patterns can be added to the knowledge base and the neural network can be retrained at the appropriate time, which provides users with great flexibility. In addition, new corpora can be tracked and collected in real time, which is a condition to ensure that the model can achieve the ultimate performance.
[0120] Preferably, the recognition device 20 can also: extract the bad words, and identify the deformed words related to the bad words in the text information according to the bad words. In one embodiment, some malicious users often deform bad words to avoid the messages they send being filtered by the system. For example, "go to death" is written as "go to shit".
[0121] In this embodiment, the deformed words related to the bad words in the text information can be identified according to the pinyin pattern of the word. Specifically, the suspected deformed words related to the bad words in the text information are first extracted, and then the bad words and the suspected deformed words are converted into phonetic codes, and the similarity between the phonetic code of the bad words and the phonetic code of the suspected deformed words is calculated by editing distance. When the similarity is greater than or equal to a preset value, it is confirmed that the suspected deformed words are the deformed bodies of the bad words. In this embodiment, the suspected deformed words are words obtained by deforming the bad words, for example, words obtained according to the same pinyin of the bad words, or words after inserting special characters into the bad words.
[0122] In this embodiment, the phonetic code is a coding method for Chinese character pinyin, which can express the pinyin characteristics of Chinese characters by coding, thereby expressing the pronunciation characteristics of Chinese characters. Based on the phonetic code, the pinyin of Chinese characters can be converted into corresponding character sequences.
[0123] In other implementations, the deformed words related to the bad words in the text information may also be identified through word abbreviation patterns and word splitting patterns.
[0124] The recognition device 20 can more accurately recognize the bad words in the text information by recognizing the transformed words of the bad words, thereby maintaining network security.
[0125] In summary, the recognition device 20 of the present invention includes an acquisition module 201, an encoding module 202, a processing module 203, an input module 204, a calculation module 205 and a comparison module 206. The acquisition module 201 is used to acquire text information; the encoding module 202 is used to uniquely encode each word in the text information to obtain the feature vector of each word; the processing module 203 is used to process the feature vector through a pre-trained word vector model to obtain word vector information; the input module 204 is used to input the word vector information of each word in the text information into a neural network model in sequence to obtain an output result; the calculation module 205 is used to input the output result into a shallow neural network to complete the probability calculation; and the comparison module 206 is used to compare the calculated probability with the probability threshold to determine whether the text information is a bad word. Thus, bad words in text information can be identified. The device can also continuously maintain and update the model in a virtuous cycle through data collection and updating, so that the model maintains a dynamic adaptability, can quickly determine whether the text information contains bad words, and will not be easily eliminated by the rapid development of the network. Since there is no need to build your own statistical corpus for modeling, developers do not need a lot of professional knowledge, nor do they need to maintain a professional statistical corpus, which greatly reduces the difficulty of modeling and development time.
[0126] The above-mentioned integrated unit implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, and includes a number of instructions for enabling a computer device (which can be a personal computer, a dual-screen device, or a network device, etc.) or a processor to execute a part of the method described in each embodiment of the present invention.
[0127] Figure 3 This is a schematic diagram of an electronic device provided in Embodiment 3 of the present invention.
[0128] The electronic device 3 includes: a memory 31 , at least one processor 32 , a computer program 33 stored in the memory 31 and executable on the at least one processor 32 , at least one communication bus 34 , and a database 35 .
[0129] When the at least one processor 32 executes the computer program 33 , the steps in the above-mentioned method for identifying bad language are implemented.
[0130] Exemplarily, the computer program 33 may be divided into one or more modules / units, which are stored in the memory 31 and executed by the at least one processor 32 to implement the present invention. The one or more modules / units may be a series of computer program instruction segments capable of implementing specific functions, and the instruction segments are used to describe the execution process of the computer program 33 in the electronic device 3.
[0131] The electronic device 3 may be a mobile phone, a tablet computer, a personal digital assistant (PDA), or other device with an application installed. Figure 3 It is only an example of the electronic device 3 and does not constitute a limitation of the electronic device 3. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, the electronic device 3 may also include input and output devices, network access devices, buses, etc.
[0132] The at least one processor 32 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The processor 32 may be a microprocessor or any conventional processor, etc. The processor 32 is the control center of the electronic device 3, and various parts of the entire electronic device 3 are connected using various interfaces and lines.
[0133] The memory 31 can be used to store the computer program 33 and / or modules / units. The processor 32 implements various functions of the electronic device 3 by running or executing the computer program and / or modules / units stored in the memory 31 and calling the data stored in the memory 31. The memory 31 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the electronic device 3 (such as audio data, etc.), etc. In addition, the memory 31 can include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), at least one disk storage device, a flash memory device, or other non-volatile solid-state storage devices.
[0134] The memory 31 stores program codes, and the at least one processor 32 can call the program codes stored in the memory 31 to execute related functions. For example, Figure 2 The various modules described in (acquisition module 201, encoding module 202, processing module 203, input module 204, calculation module 205 and comparison module 206) are program codes stored in the memory 31 and executed by the at least one processor 32, thereby realizing the functions of the various modules to achieve the purpose of identifying bad language.
[0135] The acquisition module 201 is used to acquire text information;
[0136] The encoding module 202 is used to one-hot encode each word in the text information to obtain a feature vector of each word;
[0137] The processing module 203 is used to process the feature vector through a pre-trained word vector model to obtain word vector information;
[0138] The input module 204 is used to input the word vector information of each word in the text information into the neural network model in sequence to obtain an output result;
[0139] The calculation module 205 is used to input the output result into a shallow neural network to complete probability calculation; and
[0140] The comparison module 206 is used to compare the calculated probability with a probability threshold to determine whether the text information is an offensive term.
[0141] The database 35 is a warehouse established on the electronic device 3 to organize, store and manage data according to a data structure. Databases are generally divided into three types: hierarchical databases, network databases and relational databases. In this embodiment, the database 35 is used to store text information.
[0142] If the module / unit integrated in the electronic device 3 is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the process in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of the above-mentioned method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device that can carry the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), etc.
[0143] In the several embodiments provided by the present invention, it should be understood that the disclosed electronic device and method can be implemented in other ways. For example, the electronic device embodiments described above are only schematic, for example, the division of the units is only a logical function division, and there may be other division methods in actual implementation.
[0144] In addition, each functional unit in each embodiment of the present invention may be integrated into the same processing unit, or each unit may exist physically separately, or two or more units may be integrated into the same unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional modules.
[0145] It is obvious to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the present invention can be implemented in other specific forms without departing from the spirit or essential features of the present invention. Therefore, from any point of view, the embodiments should be regarded as exemplary and non-restrictive, and the scope of the present invention is defined by the appended claims rather than the above description, and it is intended that all changes falling within the meaning and scope of the equivalent elements of the claims are included in the present invention. Any figure mark in the claims should not be regarded as limiting the claims involved. In addition, it is obvious that the word "comprising" does not exclude other units or, and the singular does not exclude the plural. Multiple units or devices stated in the system claim may also be implemented by one unit or device through software or hardware. The words first, second, etc. are used to indicate names, and do not indicate any particular order.
[0146] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the spirit and scope of the technical solution of the present invention.
Claims
1. A method for identifying bad language, characterized in that: The method comprises: Get text information; One-hot encode each word in the text information to obtain a feature vector of each word; Processing the feature vector through a pre-trained word vector model to obtain word vector information; Inputting the word vector information of each word in the text information into the neural network model in sequence to obtain an output result, wherein the neural network model is a bidirectional GRU neural network model for obtaining the semantic information of the text information; Inputting the output result into a shallow neural network to complete probability calculation, the shallow neural network is a DNN neural network; and Comparing the calculated probability with a probability threshold to determine whether the text information is a bad word, and optimizing the probability threshold by a cross entropy loss value; Extracting the bad words; Identifying deformed words related to the bad words in the text information according to the bad words includes: extracting suspected deformed words related to the bad words in the text information; converting the bad words and the suspected deformed words into phonetic codes; calculating the similarity between the phonetic codes of the bad words and the phonetic codes of the suspected deformed words through edit distance; when the similarity is greater than or equal to a preset value, confirming that the suspected deformed words are deformed bodies of the bad words; when the similarity is less than the preset value, confirming that the suspected deformed words are not deformed bodies of the bad words.
2. The method for identifying bad language according to claim 1, wherein: The method further comprises: The text information is preprocessed, wherein the preprocessing includes at least one of removing stop words and removing noise words.
3. The method for identifying bad language according to claim 1, wherein: The comparison of the calculated probability and the probability threshold to determine whether the text information is a bad word includes: When the calculated probability is greater than or equal to the probability threshold, confirming that the text information is bad language; When the calculated probability is less than the probability threshold, it is confirmed that the text information is not an offensive term.
4. A device for identifying bad language, characterized in that: The device comprises: An acquisition module is used to acquire text information; An encoding module, used for one-hot encoding each word in the text information to obtain a feature vector of each word; A processing module, used for processing the feature vector by a pre-trained word vector model to obtain word vector information; An input module, used to input the word vector information of each word in the text information into the neural network model in sequence to obtain an output result, wherein the neural network model is a bidirectional GRU neural network model, used to obtain the semantic information of the text information; A calculation module, used for inputting the output result into a shallow neural network to complete probability calculation, wherein the shallow neural network is a DNN neural network; and The comparison module is used to compare the calculated probability with the probability threshold to determine whether the text information is a bad word, and optimize the probability threshold through a cross entropy loss value; extract the bad word; and identify the deformed words related to the bad word in the text information according to the bad word, including: extracting the suspected deformed words related to the bad word in the text information; converting the bad word and the suspected deformed words into phonetic codes; calculating the similarity between the phonetic code of the bad word and the phonetic code of the suspected deformed words through the edit distance; when the similarity is greater than or equal to a preset value, confirming that the suspected deformed words are the deformed body of the bad word; when the similarity is less than the preset value, confirming that the suspected deformed words are not the deformed body of the bad word.
5. An electronic device, characterized in that: The electronic device includes a processor and a memory, and the processor is used to implement the method for identifying bad language as claimed in any one of claims 1 to 3 when executing a computer program stored in the memory.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method for identifying offensive language according to any one of claims 1 to 3 is implemented.
Citation Information
Patent Citations
Text analysis method and device, computer device and computer storage medium
CN110427610A