Topic > The use of artificial intelligence in hate speech detection

One of the biggest problems facing companies working with user-generated online content in the modern era is moderating offensive speech and hate speech. incitement to hatred. The current approach to dealing with the issue is to manually maintain a list of all possible words and phrases that can be considered offensive or hateful and use this to filter out objectionable content. This approach presents a couple of problems: first, such an approach is not sustainable; having to manually maintain a list of offensive and hateful words and phrases makes the list get quite large very quickly, and keeping track of which variations of words and phrases have been added to the list becomes too manual to be worth the effort. With this project, the goal was to create an AI model that can detect hate speech and offensive words and phrases in textual data without the need for manually maintained lists of all possible words and phrases that qualify as offensive hate speech. We say no to plagiarism. Get a tailor-made essay on "Why Violent Video Games Shouldn't Be Banned"? Get an original essay For this project, the dataset used for training and testing the AI ​​model was obtained from Github; this dataset was first generated by Davidson, Thomas and Warmsley, Dana and Macy, Michael and Weber, Ingmar for their paper titled “Automated Hate Speech Detection and the Offensive Language Problem”; the article was first published in “Proceedings of the 11th AAAI International Conference on Web and Social Media.” The original dataset consists of 24,783 unique tweets extracted from Twitter and is stored as a CSV file. This file contains six columns for each tweet: the full text of the tweet, the number of people who manually classified each tweet as offensive, hate speech or normal, the number of users who rate the tweet as offensive, the number of users which classifies the tweet as hate speech, the number of users who rate the tweet as normal, and the majority class for each tweet based on user ratings. The dataset is also limited to only showing tweets that had at least three users rating whether they were offensive, hateful, or normal; this allows for a higher probability that classifications are legitimate and reduces noise in the model. Since the data originally comes from Twitter, the length of each text is limited; the average tweet length is 85 characters, with a maximum length of 754 characters and a minimum length of 5 characters. Furthermore, since the texts are Twitter tweets, they contain special and foreign characters, retweet information, URLs and user mentions; none of this data is useful for the purposes of this project, so it was handled in the data preprocessing phase. Another important note about the dataset is that all tweets are in English, or colloquial social media English. The original raw dataset is also imbalanced in terms of classes; 77% of the documents were classified as offensive speech, 6% as hate speech, and the remaining 17% were classified as neither hate speech nor offensive. When entering data in Python, most of the columns were removed as they were not needed for this project; the only two columns retained were the tweets and the class they belonged to. Once the dataset was loaded, a significant amount of preprocessing was required to prepare the data to be used for training and testing a modelof artificial intelligence; much of the data cleaning was done using the Regex library in Python. The first step was to remove any mentions included in the tweets in the dataset; this was done by compiling a regex pattern that looked for any "at" symbol followed by characters and then whitespace. The next step was to remove any retweet information; this was done using regex to eliminate any substring containing "RT" and followed by whitespace characters. So all URLs within the tweets were removed; furthermore, all foreign characters present in the tweets were removed to reduce the complexity of the model's vocabulary. Additionally, all digits have been removed from the tweets in the dataset, as the numbers add nothing of value to the objective of this model. The next step was to remove all possible stop words from the tweets; in natural language processing, there is a concept known as stop-words, which are words that typically add no significant meaning or value to the overall meaning of the text; in this project, the NLTK library was used to remove all possible buzzwords from the tweets to ensure that the AI ​​model was not negatively affected by noise in the data. At this point, the tweets in the dataset are as clean as possible, so the last step in preparing the dataset for the model is to remove excess whitespace in the tweets and remove any tweets in the dataset that after all they have become empty strings of the above cleaning processes have been completed. After all this data preprocessing was completed, 24,768 clean tweets remained in the dataset for training and testing the model; these remaining tweets averaged 54 characters long, with the longest being 343 characters and the shortest being three characters. In order to promote the value and generalizability of the AI ​​model under construction, the dataset was enriched with more hate speech and offensive words and phrases identified by the Cludo Data Science team. These additional examples of hate speech and offensive words and phrases were compiled in twenty-five different languages ​​by the Cludo Data Science team during 2018; Cludo is a website research company that provides in-depth analytics and search solutions to clients for their websites. To incorporate these new examples into the original dataset and keep them in line with the rest of the dataset, Cludo was developed a feature to generate new fake tweets with these examples of hate speech and offensive words and phrases inserted into them. This was achieved by creating a list of the most common words from the original, clean dataset of tweets and randomly sampling a random number of words based on the length distribution of tweets in the original dataset. Once these new imputed tweets were created, words and phrases were randomly sampled from the offensive and hate speech identified by Cludo and randomly inserted into the new imputed tweets. To further augment the original dataset and prevent the AI ​​model from mislearning relationships, the dataset was augmented by copying tweets and mixing the word order in each tweet. One possible problem a model like this might run into is incorrectly memorizing specific word order as a way of classifying which words or phrases are offensive or hateful, instead of actually learning what is and isn't hate speech. hateful or offensive. To avoid this, the cleaned dataset was copied multiple times and each of the tweets within the copies had the order ofwords within the tweet randomly mixed; this process purposely added some noise to the dataset, as well as forcing the model to actually learn from the data instead of memorizing it. Once this process was completed, all duplicate records in the new dataset were eliminated to reduce the risk of overfitting. At the end of this phase, the new dataset consisted of 131,941 observations with more or less the same distribution across classes as the original dataset; with a significantly larger and expanded dataset, the AI ​​model can learn better and generalize to new future examples. Now that the dataset has been cleaned, preprocessed, and augmented, it's time to prepare the data for training and evaluating the AI ​​model. The first step was to split the data set into variables X and Y; in the case of this model, our variable X represents the clean and preprocessed tweets and our variable Y was the class indicator column. After splitting the dataset into X and Y variables, the Tokenizer functionality of the Keras text preprocessing library was applied to the X variable; This Tokenizer used TFIDF to convert tweet texts into arrays of numbers that indicated each word in each tweet. The next step was to split the X and Y variables into training and test datasets; this was achieved using the train_test_split function from sklearn's model_selection library. Because this model was built to predict multiple classes, the dataset was randomly split using stratified sampling to ensure that each of the three classes was more or less equally distributed in both the training and testing datasets ; the chosen split between train and test was that 70% would go to training and 30% to testing. The final step in preparing the data for training and testing the model was to integrate the now sequential data to standardize its length; To reduce the complexity of model training, sequences were padded and/or limited to 500 units in length. Also, at this point the Y variable has been changed from an integer value representing the class to a hot-coded variation on it, using Keras' to_categorical function. A couple of different variations on neural networks were tested on a small subset of the training data to determine the best combination of architecture and hyperparameters to solve this problem; ultimately, a bidirectional LSTM was chosen as the core of the model. The shape of the input data for the model was 92,359 observations with 500 features, while the shape of the test data was 39,583 observations and 500 features. The first layer after the input layer was an embedding layer with a hidden layer size of 256 nodes; by making the first hidden layer an embedding layer, it allows the AI ​​to learn more about the data by setting contextually related words to an embedding representation that encodes their relationship. After the embedding layer is the bidirectional LSTM layer; this layer had 256 nodes and a 30% dropout rate to reduce the chances of overfitting and returned sequences; the bidirectional variant of the LSTM model was chosen because bidirectional LSTMs are better at learning context from natural language data than a standard LSTM. The bidirectional LSTM layer inserted into a Flattened layer, to allow subsequent layers to use the dense Keras layers. After the Flatten layer, the Dense layer was implemented using 256 hidden nodes andthe ReLU activation function; ReLU was chosen for the speed performance associated with it in larger networks, as well as its ability to learn nonlinear relationships. This Dense layer is inserted into another Dropout layer to reduce the likelihood of over-fitting the model; this attrition level was set to a 30% attrition rate. After this combination of Dense and Dropout layers, another set of Dense and Dropout layers was used, with the same settings as the previous combination; Dense layer with ReLU activation and 256 hidden nodes and a Dropout layer with 30% Dropout rate. The goal was to build an AI model that was robust and powerful enough to successfully learn from the dataset, without over-fitting the model and keeping the model training time at an acceptable level. The final layer of the model was a Dense output layer with 3 nodes (one for each class) and a Softmax activation; the Softmax activation function was chosen for the Output layer because it maps the output for each class in such a way that the sum of the outputs will sum to 1, giving what is essentially the probability for each class. After building the model, the model was compiled with a loss function of categorical_crossentropy (since the model is for a multiclass classification problem), an Adam optimization function, and categorical_accuracy chosen as the value metric. Adam was chosen as the optimization function because it is relatively efficient in computation while being robust to this type of data, and categorical_accuracy was chosen as the training metric because we want to make sure that the model is actually classifying the inputs correctly and not just the bucket all the inputs into a class and calling it "accurate". Other important parameters to note for this AI were the batch size of 64 observations and 100 epochs; Typically, AI models learn better when presented with smaller batch sizes, but you need to balance this with training time and computational efficiency, so the batch size was set to 64. Additionally, 100 epochs chosen for ensure that the model had enough training time to learn everything it could about the data, but Early Stopping was also implemented to ensure that the model did not train longer than necessary. For the Early Stopping parameters, the model was directed to monitor the validation loss metric with the aim of minimizing it and was assigned a “Patience” parameter of 10 epochs; this means that the model would automatically stop if the validation loss did not improve significantly over the course of any 10 epochs during training. Overall, this model had 72,549,379 trainable parameters. Model training was performed locally on an MSI brand laptop using the integrated NVIDIA GeForce GTX1060 GPU. Initially, model training was started using only the CPU, but this showed that training would take approximately 19 hours per epoch, which is not sustainable; By switching to GPU training, training time dropped to about an hour per epoch. This, combined with the early stopping, meant that the model trained for 48 epochs, which took around two and a half days to reach a conclusion at the early stopping point. The system was also set up to record the model's performance in each epoch in a CSV file, for easy reference later on the model's accuracy and loss. At the beginning of training, at the end of the first epoch,.