Method of Profanity DetectionUsingWord Embedding and LSTM

Department of Software Convergence Engineering, Chosun University, 309 Pilmun-Daero, Dong-Gu, Gwangju 61452, Republic of Korea Department of Computer Engineering, Chosun University, 309 Pilmun-Daero, Dong-Gu, Gwangju 61452, Republic of Korea IT Research Institute, Chosun University, 309 Pilmun-Daero, Dong-Gu, Gwangju 61452, Republic of Korea Department of New Industry Convergence, Chosun University, 309 Pilmun-Daero, Dong-Gu, Gwangju 61452, Republic of Korea


Introduction
Cyberbullying refers to a criminal act that inflicts mental and material harm on others by the repeated use of hostile expressions, such as text, images, and voices, online through IT devices including computers [1]. Of late, the age of cyberbullying perpetrators is gradually decreasing due to the proliferation of smart devices. Such perpetrators do not realize that cyberbullying is a crime and exhibit reckless behavior considering it as simple play [2]. In addition, there are cases of suicide by the victims of cyberbullying, rendering it a serious social problem [3]. According to the Communications Commission's 2019 Cyberbullying Investigation Results Presentation, the representative types of cyberbullying include cyber verbal abuse, cyber defamation, cyberstalking, cyber sexual harassment, personal information leakage, social exclusion online, cyber extortion, and cyber coercion [4]. Among them, cyber verbal abuse has the highest ratio of 36.7% [5][6][7]. In order to prevent cyber verbal abuse, the government has blocked certain sentences related to profanity [8]. However, Internet users are modifying the nucleus of a word to avoid blockage or using new profanity [9], even if profanity is modified accordingly. Many studies are being conducted to accurately determine profanity. Currently, deliberate typos and profanity using special characters can be discriminated. However, if the meaning of words and the flow of sentences are not understood, standard words such as "Sibaljeom (starting point, a Korean word that sounds similar to a swear word)" and "Saekkibalgalag (little toe, a Korean word that sounds similar to another swear word)" are less accurately determined as profane. erefore, in this study, we attempt to accurately identify profanity in the following two cases: (1) when Internet users use profanity by modifying the nucleus of a word to avoid being blocked as profane and (2) when the morphology of a word is similar to profanity but is a standard language that is not profane in context. In order to improve the accuracy of profanity discrimination, we propose a method for discriminating profanity using the FastText model for word embedding by learning the meaning and form information of words and the LSTM model for learning the flow of context.

Related Work
2.1. Natural Language Processing. Natural language refers to a language that has formed and evolved naturally over a long period, such as Korean and English, and is commonly spoken and used [10]. Natural language processing analyzes the meaning of natural language to enable computers to process the language. Natural language processing is applied in areas such as text classification, sentiment analysis, summarization, and text clustering [11,12]. is processing includes four steps: text collection, text preprocessing, word embedding, and machine learning modelling [13,14].
In the first step (text collection), the texts to be processed are collected. e second step (text preprocessing) involves the standardization of unstructured texts to increase the accuracy of natural language processing. e text collected from SNS contains many elements that are difficult to analyze, such as typos, emoticons, abbreviations, and newly coined words. Most are expressed as if speaking in a carefree manner, in terms of the vocabulary or the structural order of the sentence. erefore, after text processing, including changing the uppercase to lowercase, deleting special characters and emoticons, and text normalization such as word tokenization and stop word removal, preprocessing is performed according to the requirement. In the third step (word embedding), the words are converted to vectors such that computers can understand and process the natural language efficiently. In this study, we use the FastText model in which word embedding is performed by training using the morphology information of Korean letters, among several models. Finally, in the machine learning modelling stage, a supervised learning model is established, and training and prediction are performed using vectorized number-type data. In this study, we use the LSTM model for training and prediction, for profanity detection.

Embedding Algorithm.
For a computer to understand and process natural language efficiently, the language needs to be transformed into numbers that can be processed by the computer. As the performance of natural language processing varies considerably depending on word representation, the conversion of words into number types is being extensively studied. Among these, the commonly used method is word embedding, which represents a word as a dense vector [15]. Methods of representing a word by a vector include sparse representation and dense representation. One-hot encoding is a method of representing a vector with sparse representation. e vector value expressed in spare representation mostly includes the number "0," and the number of dimensions is equal to the number of words to be trained. However, as sparse representation includes as many dimensions as the number of words for training, considerable space is wasted and the meaning of words cannot be appropriately represented. Of late, several algorithms that represent vectors through dense representation by improving the above disadvantages have emerged [16]. With dense representation, the vector dimension can be matched with the numbers set by the user, and the vectors, called dense vectors, have real values [16]. As indicated by the concept, word embedding refers to a method of representing words in the form of dense vectors [17]. Representative algorithm models that can adopt word embedding include Word2Vec [15], GloVe [18], and Fast-Text. e Word2Vec model represents words in the vector space through distributed representation using their semantics and syntactic characteristics. However, this model is disadvantageous because the vector values cannot be obtained for OOV and training is not possible for infrequent words [19][20][21]. In the FastText model, training is performed by dividing words into character-level to supplement such limitations. As in the case of the Word2Vec model, the FastText model examines the preceding and subsequent contexts with reference to the target word and performs training on words; however, because it also learns words by dividing them to character-level, the model can also be trained on word morphology information. FastText model training is performed by representing words using the Bagof-Words (BoW) or n-gram model. At the beginning and end of the words to be learned, "<", ">" is inserted as separators, and the entire word is also contained in the BoW with the separator to enable the model to learn the overall meaning [22]. A new scoring function using the BoW is defined as follows: where v c is the vector of a word forming context and z T g is the vector corresponding to 1 BoW.
With the above change in the model, it can learn information on the semantics, syntax, and morphology of the target words [23]. In this study, for training the FastText model more effectively on the morphology information suited to the characteristics of Korean letters, each word is divided into onset, nucleus, and coda for analysis. In case of the absence of coda, symbol "−" is added.

LSTM Model.
e LSTM model is a model devised to solve the long-term dependency problem of RNN. LSTM uses switchgear designed to allow you to forget previous information or store information for a long period of time through a memory cell, which is an internal node: (2) e combination of the input value (x t ) at the same time point and the hidden node value (h t−1 ) at the previous time point is used to calculate the internal storage node candidate (c t ), and the storage node candidate is combined with the storage node value (c t−1 ) at the previous time point and calculate the current value (c t ) of the internal storage node. At this time, the input gate (i t ) and forget gate (f t ) act as weights to adjust how the new information is passed and how the information is passed to the value in the previous state. Finally, using the tanh valid function, the value of the hidden node is output by adjusting how to pass the value of the current internal storage node by output gate (o t ). e value of each input gate, output gate, and forget gate is represented by a combination of a linear function of the input value at the current time point and the secret node value at the previous time point [24].

Profanity Detection with Word Embedding and LSTM
3.1. System Architecture. Figure 1 illustrates the system architecture of the proposed profanity detection method, which is divided into the Training Data Process that trains data, and the Testing Data Process that detects profanity in the texts written by users.
In Training Data Process, a model is trained for profanity detection. is process involves preprocessing, FastText model training, and LSTM model training. In the text preprocessing step, normalization is performed on the collected texts, and in order to include the morphology information of Hangul in the training of the FastText model, each character is divided into the onset, nucleus, and coda.
erefore, the FastText model is trained using such divided text data. e trained FastText model contains the vector information of the text data, and word embedding is performed on the text data using the vector information. In the LSTM model learning step, binary classification supervised learning is performed to detect whether a sentence contains profanity. While training the LSTM model, the presence of profanity in a sentence is first checked, and labeling is performed, where "1" is assigned to a sentence with profanity and "0" is assigned to a sentence without profanity. Further, training is performed using the numerical data with word embedding.
In the Testing Data Process, when a sentence is input, the model detects the presence of profanity and provides the output. For result prediction with the trained model, the data format should be the same as that used for training. erefore, the same text preprocessing step performed in the Training Data Process is repeated, and through the word embedding step, profanity is predicted using the LSTM model. In the predicted result, "0" indicates a sentence without profanity and "1" indicates a sentence with profanity.

Preprocessing and Word Embedding.
is section describes in detail the (1) preprocessing step that facilitates computerized analysis on texts collected from Twitter and Naver movie review posts and the (2) word embedding step using the FastText model.

Text Preprocessing.
First, remove special symbols and emoticons. Text data were collected from Twitter posts and Naver movie reviews. Many of the collected data began with special characters, emoticons, "kieukkieukkieukkieuk (LOL)," and "@," and such texts were removed as they hinder profanity detection.
Second, remove one syllable. With reference to word spacing, the collected sentences contained numerous onesyllable words such as "geos (thing)," "a (Ah)," "geu (that)," "tto (again)," and "i (this)." On examining these one-syllable words, it was determined that, in many cases, these words were typed due to mistakes in word spacing when the user was writing the posts; furthermore, there was no profanity comprising one-syllable. Considering these aspects, onesyllable words were excluded from the analysis.
ird, remove sentences with less than five words. e texts collected from Twitter included many sentences that did not have proper spacing between words, such as sentence "nunapaije lenjeuppaenda (I am taking the lens out because my eyes are sore, written without spacing)." Preprocessing can be performed only by knowing the rules of the sentences that do not have proper spacing. Investigation of the rules of sentences revealed that there were fewer words in these sentences, compared to normal sentences when the number of words was counted with reference to spacing. In addition, for training the LSTM model, the number of words in all the sentences needs to be adjusted; sentences with less number of words need to be filled with "0," resulting in sentences with many "0"s. erefore, sentences with less than five words were removed through preprocessing. ereby, high accuracy was realized in profanity detection.
Fourth, the onset, nucleus, and coda are separated. In this study, the FastText model was trained after separating Hangul into the onset, nucleus, and coda to enable profanity detection, even when the user deliberately makes a typo and changes the morphology of the profanity. Here, the absence of coda was indicated by adding "-." Table 1 presents the source code that separates the onset, nucleus, and coda.

Word Embedding Using the FastText Model.
e preprocessed text data were used for training the FastText model. is training was performed with skip-gram, at a learning rate of 0.05, dimension (vector space) of 100, window size of 5, epoch of 50, and n-gram of 1-6. As shown in Table 2, in the training result, the character vectors substrings are formed with n-gram and the character vectors strings are formed by adding the character vector substrings.
In the FastText model, character vector strings are formed by adding the substrings of the character vectors; similarly, the morphology information is used for training.
e FastText model trained based on this method generates a vector similar to the word before it was changed, even if the word nucleus is changed.

Data Set Configuration for LSTM Training.
To conduct supervised learning with the LSTM model, word embedding in which data are mapped to vectors must be performed, for which the trained FastText model can be used. As shown in Table 3 Figure 1: Overview of the system architecture.   words based on the spacing, and a word becomes a onedimensional vector when vectorized using the trained FastText model. In this case, the number of vectors for one word is set as the dimension value when training the FastText model. erefore, as the vector of a sentence is a combination of several words, this vector is two-dimensional, and the vector of all the sentences is three-dimensional. In the word embedding algorithm, the number of words in a sentence is matched with the number of vectors. When the number of vectors is different, "0"s are prepended to fill the number of lacking words, for matching with the number of vectors. In addition, for supervised learning of the LSTM model, each data requires a label. In this study, if a sentence contained profanity, the label was set as "1," and if there was no profanity, the label was set as "0".

LSTM Training Method.
To train the LSTM model, a 3D vector was set as X, and a label comprising "0" and "1" was set as y. For the LSTM hyperparameters, as shown in Figure 2 and Table 4, the units were set to "1," the time step was set to 25, which is the number of words, and the feature was set to 100, which is the number of dimensions used for training FastText. For the hyperparameters of Dense, the units were set to "1," and the Sigmoid function was set as the activation function.

Profanity Detection.
e following tables demonstrate that the profanity detection results are accurate. Table 5 shows the results of sentences with and without profanity. In Table 6, even for cases where the nucleus of the word "Ssibal (f * * k)" is transformed to words such as "Ssuibal" or "Ssuibal-namah," the results show correct profanity detection.
Finally, if a standard word and not profanity is used in context, the results accurately display the message, "Profanity is not contained." Table 7 shows the standard word detection result for "Sibaljeom (starting point)" and "Saekkibalgalag (little toe)."

Results and Discussion
In this section, the process of collecting texts and data sets used for testing is described. For demonstrating the effectiveness of the profanity detection method proposed in this study and for comparative analysis with a prior study, the accuracy, recall, and precision were measured for performance assessment utilizing the classification performance assessment indicators.

Data Collection.
For the application and performance assessment of the profanity detection method proposed in this study, SNS posts and Naver movie review data were collected. SNS data include features written freely without being restrained by any specific format; among the various types of SNS, Twitter, which has more pronounced free writing, was used for data collection. e data collected from Twitter were searched with specific keywords and the search period was set from January 01, 2016. e number of sentences collected from Twitter was approximately 4.4 million. Naver movie review data were relatively refined; therefore, approximately 500,000 sentences were collected.

Data Sets.
e data sets used for testing the models are described here. e number of data sets collected from Twitter was approximately 4.4 million, as shown in Table 8; however, as they contained many duplicate tweets, such duplicates were removed. As a result, the number of Twitter posts decreased to approximately 1.3 million.
Due to the characteristics of the FastText model, it can learn the meaning and morphology information of words more accurately as the number of data increases. Hence, 1.3 million tweets and 500,000 Naver movie reviews were used as data to train the FastText model. e data set for training the LSTM model did not contain all the collected data, and for accurate profanity detection, the data sets were composed with a ratio of 1 : 1 between the number of sentences with profanity and the number of sentences without. ereby, the composed data sets included 600,000 sentences, each, with and without profanity.

Test Assessment Method.
To evaluate the accuracy, recall, and precision of profanity detection and to determine the superiority of the proposed method, the edit distance algorithm proposed in a previous study and the CNN, GRU, and LSTM models used in this study were comparatively analyzed. Equation (3) was used for calculating the accuracy, recall, and precision using the confusion matrix:  [25].

Test Result Analysis.
In this study, the correct answer for a sentence containing profanity was set as "1," and for a sentence without profanity, it was set as "0"; thus in the test, Positive � 1 and Negative � 0. Table 9 and Figure 3 outline the analysis results. For prediction using the CNN model, the accuracy is 53%, recall is 13%, and precision is 79%. It can be observed that the overall accuracy and recall of the CNN model for profanity detection are considerably lower compared to other models. e GRU model shows high performance with an accuracy of 94.74%, recall of 95.18%, and a precision of 94.32% but is still slightly inferior to the LSTM model. e LSTM model proposed in this study has the highest performance with an accuracy of 96.15%, recall of 96.29%, and precision of 96%. e cross-verification score using the LSTM model is 96%. Table 10 shows the results of the comparative analysis between the edit distance algorithm proposed in a previous study, and the CNN, LSTM, and GRU models tested in this study, demonstrating the superior performance of the proposed method.
Transformed profanities such as "Ssuibal" and "Junna" and "Yabal" and "Sseubal" are accurately detected by the previously proposed algorithm as well as the proposed method in this study. Words such as "Sinbal," "Sibaljeom," and "Saekkibalgalag" have forms similar to profanities "Sibal" and "Saekki (bastard)"; hence, they are detected as profane by the previously proposed algorithm, but the LSTM model proposed in this study correctly detects it is not profane because it has been trained on the flow of context.

Conclusions
In this study, we proposed a profanity detection method using word embedding and the LSTM model. e proposed method divides the text for training into the onset, nucleus, and coda. Further, it considers not only the semantics of the words but also the morphology information using the FastText model. Moreover, by training on the flow of context using the LSTM model, it can detect profanity that cannot be detected by the methodologies proposed in previous studies. Among the 40,005 sentences with profanity and 40,254 sentences without profanity, 40,126 sentences were predicted as profane and 40,133 sentences were predicted as not profane by the proposed method. According to the classification performance test indicators, the accuracy was 96.15%, recall rate was 96.29%, and precision was 96%, indicating high performance. e result of comparative analysis between the edit distance algorithm proposed in a previous study and the proposed method in this study confirmed that the proposed method was capable of more accurate profanity detection.
For follow-up research, it is necessary to add a more diverse range of profanities, in addition to the seven profanities "Sibal (F * * k)," "Ssibal (F * * k)," "Byeongsin (dickhead)," "Jonna (f * * * king)," "Jotna (f * * * king)," "Gaesaekki (son of a b * * * h)," and "Saekki (bastard)" used in this study, in order to find a method that can detect all the profanities with improved accuracy. Furthermore, an extended study needs to be performed that can detect profanity considering emoticons and special characters with meanings as well as social issues. If immense text data can be collected, all the profanities can be accurately detected through the proposed method. Furthermore, cyber verbal abuse can be expected to decrease by the introduction of a profanity blocking system based on the findings of this study.

Data Availability
e data used to support the findings of this study have been deposited in the NAS (Network Attached Storage) repository (http://gofile.me/5RqDr/b85bbrzd0).

Conflicts of Interest
e authors declare that they have no conflicts of interest.