Comment Toxicity Classification Report
Comment Toxicity Classification Report
BELAGAVI, KARNATAKA
A Seminar Report on
“Comment Toxicity Classification Using Deep Learning”
Submitted in the partial fulfillment for the requirements for the conferment of Degree of
BACHELOR OF ENGINEERING
in
By
Miss. BHAVYATHA M 1BY20IS040
2023-2024
VISVESVARAYA TECHNOLOGICAL UNIVERSITY
BELAGAVI, KARNATAKA
BMS INSTITUTE OF TECHNOLOGY & MANAGEMENT
YELAHANKA, BENGALURU-560064
CERTIFICATE
This is to certify that the Seminar (18ISS86) entitled “COMMENT TOXICITY CLASSIFICATION
USING DEEP LEARNING” is a bonafide work carried out by “BHAVYATHA M (1BY20IS040)
partial fulfillment for the award of Bachelor of Engineering Degree in Information Science and
Engineering of the Visvesvaraya Technological University, Belagavi during the year 2023-2024. It
is certified that all corrections/suggestions indicated for Internal Assessment have been incorporated
in this report. The seminar report has been approved as it satisfies the academic requirements with
respect to seminar work for the B.E Degree.
I am happy to present this Technical Seminar after completing it successfully. This seminar
would not have been possible without the guidance, assistance and suggestions of many
individuals. I would like to express our deep sense of gratitude and indebtedness to each and
every one who has helped us make this project a success.
I heartily thank our Principal, Dr. Sanjay H A, BMS Institute of Technology &
Management for his constant encouragement and inspiration in taking up this seminar.
I heartily thank our Head of Department Dr. Pushpa S K, Dept. of Information Science
and Engineering, BMS Institute of Technology & Management for her constant
encouragement and inspiration in taking up this seminar.
I gracefully thank our seminar guide, “Dr. Shanti D. L, Associate Professor”, Dept. of
Information Science and Engineering, for her encouragement and advice throughout the
course of the seminar.
Special thanks to all the staff members of Information Science Department for their help and
kind co-operation.
Lastly, I thank our parents and friends for their encouragement and support given to us in order
to finish this precious work.
By,
Bhavyatha M
i
BMS INSTITUTE OF TECHNOLOGY & MANAGEMENT YELAHANKA,
BANGALORE-64
Declaration
I also declare that this project report has not been submitted for the award of any degree,
diploma, associate ship, fellowship or other title anywhere else.
USN 1BY20IS040
Name BHAVYATHA M
Signature
ii
ABSTRACT
With the growing use of social media platforms, there's been a significant rise in toxic
comments, highlighting the need to reduce toxicity. The field of classifying toxic comments
has seen considerable progress, with several new approaches emerging. These
developments showcase innovative applications of Natural Language Processing (NLP) for
identifying various types of toxicity in comments. The objective is to discern and
categorize different types of toxic behavior, such as obscenity, identity-based hate, threats,
general toxicity, insults, and severe toxicity. Our algorithm uses comments from online
platforms to classify them as toxic or non-toxic.
The objective is to create a deep learning model which can detect different forms of
toxicity, including threats, obscenity, insults, and identity-based hate. Online discussions on
topics people care about can be challenging due to the risk of abuse and harassment, which
causes many to stop expressing their opinions or shy away from seeking diverse
perspectives. Social media platforms struggle to manage these issues effectively, leading
some to limit or completely shut down user comments. To address these challenges, we aim
to offer publicly available models via Perspective APIs, including one for detecting toxicity.
iii
INDEX
ACKNOWLEDGEMENT……………………………… i
DECLARATION………………………………………... ii
ABSTRACT……………………………………………... iii
LIST OF FIGURES………………………………….….. v
1 Introduction [1-3]
1.2 Motivation 3
1.3 Objective 3
2 Literature Survey [4-7]
2.1 Existing system 7
2.2 Problem Statement 7
2.3 Proposed System 7
3 Requirement Specification [8]
3.1 Functional Requirements 8
3.2 Non-Functional Requirements 8
3.3 Software & hardware Requirements 9
4 Design and Analysis [10-11]
4.1 Design 10 -11
5 Implementation [12-14]
6 Application [15]
7 Conclusion and Future Work [16]
8 References [17 – 18]
LIST OF FIGURES
2
Age group with the highest
1.2
exposure to cyberbullying
10
4.1
Model Architecture
5.2 Output 14
v
Comment Toxicity Classification Using Deep Learning Introduction
CHAPTER I
INTRODUCTION
The rise in use of online platforms enables people to connect with each other, sharing their
feelings and opinions on various events and leaving comments to express their views. For
example, in the figure 1.1, On Facebook, Alek Minassian, the accused individual in the
Toronto van attack, expressed admiration for the "incel rebellion” [2]. The internet can also
serve as a breeding ground for negativity, providing a space for individuals to explore extreme
ideologies and amplify their hatred without facing immediate consequences—until those
sentiments manifest in real-world violence, as noted by Shannon Martinez of the Free
Radicals Project.
[1] The goal of the project is to create a safer online environment by detecting and removing
toxic comments from social media platforms. This approach aims to foster better
communication and connection among users in an increasingly digital world. A neural
network serves as an excellent solution to this issue because human speech patterns can be
challenging for traditional hard-coded algorithms to process, and it's not cost-effective for
companies to hire human moderators to review all content. [1] NLP with neural networks have
emerged as the most effective approach, with the market for this technology projected to reach
US$ 26.4 billion by 2024.
According to the research findings depicted in the figure 1.2, it is evident that
cyberbullying predominantly affects the millennial cohort (born between 1980 and 1995),
with a prevalence of 54%. Following closely are the members of Generation Z (born
between 1997 and 2012), comprising 47% of reported cases, trailed by Generation X (born
between 1965 and 1980) at 39%, and lastly, baby boomers (born between 1946 and 1964)
at 18%. Concurrently, data from Polda Metro Jaya indicates a daily average of 25 reported
cyberbullying incidents, a figure anticipated to escalate due to the growing number of
internet users and the inadequate measures in place to address such cases.
1.2 MOTIVATION
Harmful remarks on social media can create a hostile atmosphere, leading to more
negativity, harassment, and abuse. By identifying and minimizing toxic behavior, we can
create a more welcoming and respectful online space where people feel safe to share
their views.
Toxicity often targets specific individuals or groups based on race, religion, gender,
sexual orientation or other identifying characteristics. Effective toxicity classification
can safeguard these vulnerable groups from harmful hate speech. and discrimination,
promoting social justice and equality.
Manually moderating comments is time-consuming and costly for social media
platforms. Developing automated toxicity classification systems can streamline the
moderation process, reduce costs, and improve efficiency, allowing platforms to focus
on other critical aspects of user experience and community building.
1.3 OBJECTIVES
The primary objective is to create a deep learning model which can accurately classify
toxic comments from different social media platforms. This model ought to be capable
of distinguishing different types of toxicity, such as threats, obscenity, insults, identity-
based hate, and severe toxicity, with high precision and recall.
To minimize the rate of wrong positives and wrong negatives in toxicity classification.
This involves fine-tuning the model to avoid misclassifying benign comments as toxic
and ensuring that genuinely toxic comments are accurately identified.
CHAPTER II
LITERATURE SURVEY
[1] A. Garlapati, N. Malisetty and G. Narayanan, "Classification of Toxicity in
Comments using NLP and LSTM," 2022 8th International Conference on Advanced
Computing and Communication Systems (ICACCS), Coimbatore, India, 2022.
The document discusses various Natural Language Processing and Machine Learning
techniques used for toxicity classification in online comments. It highlights specific methods
and tools commonly used in NLP, including parts of speech (POS), named entity recognition
(NER), and text preprocessing techniques such as stop word removal and stemming. The
document also explores the deployment of deep learning models, specifically Long Short
Term Memory and Gated Recurrent Unit, for classifying toxic comments. Additionally, it
mentions the use of Spacy NLP for text processing and PyLDAVis, a visualization tool for
topic modeling. These are the key points outlined in the provided excerpts.
[2] K. A. Kumar and B. Kanisha, "Analysis of Multiple Toxicities Using ML Algorithms
to Detect Toxic Comments," 2022 2nd International Conference on Advance Computing
and Innovative Technologies in Engineering (ICACITE),2022.
The document outlines a comprehensive approach to developing a deep learning model for toxic
comment classification. It uses the jigsaw toxic comments dataset from Kaggle and employs TF-
IDF for text vectorization during preprocessing. The neural network is built with Keras,
integrating layers like Embedding, Bidirectional LSTM, and Fully Connected Layers to process
and classify comments. The training process involves using backpropagation and gradient descent
optimization, with dataset splitting for training and validation, and cross-validation for
hyperparameter tuning. Potential avenues for future research involve improving the model with
additional features, addressing ethical considerations like bias mitigation, and exploring evolving
communication dynamics. The document concludes by emphasizing the need for ethical
deployment of content moderation systems, balancing toxicity moderation with the principles of
free speech.
[3] Rahul, H. Kajla, J. Hooda and G. Saini, "Classification of Online Toxic Comments
Using Machine Learning Algorithms," 2020 4th International Conference on Intelligent
Computing and Control Systems (ICICCS), Madurai, India, 2020.
The document explores the classification of toxic online comments through various machine
learning algorithms. It emphasizes the significance of this task to mitigate harm in society,
referring to instances where people have been detained due to harmful content on social
media. It underscores the importance of identifying and removing harmful content before
publishing to prevent further incidents. The paper discusses six machine learning
techniques—logistic regression, random forest, SVM classifier, naive bayes, decision tree,
and KNN classification—used to classify toxic comments within the Kaggle dataset. It
describes the process of data cleaning and exploratory visualization to extract features for
model development. The document details how ML techniques were applied and then
compares their results using evaluation metrics such as accuracy, hamming loss, and log loss
to determine their effectiveness in detecting toxic comments.
[4] M. Husnain, A. Khalid and N. Shafi, "A Novel Preprocessing Technique for Toxic
Comment Classification," 2021 International Conference on Artificial Intelligence
(ICAI), Islamabad, Pakistan, 2021.
The document outlines a preprocessing technique for toxic comment classification,
emphasizing the importance of feature extraction and engineering. Key steps in this process
include tokenization, removing stop words, stemming, and analysing n-grams. By applying
these methods, a dataset was created with ten thousand word vectors for each comments to
train and evaluate ML algorithms. The document presents results from cross-validation with
various classification models, including Logistic Regression and Naive Bayes, with box plots
to compare model accuracies and variations. These results demonstrate the different machine
learning models and approaches in classifying toxic comments while addressing the potential
for overfitting and other challenges.
[5] M. Aquino et al., "Toxic Comment Detection: Analyzing the Combination of Text
and Emojis," 2021 IEEE 18th International Conference on Mobile Ad Hoc and Smart
Systems (MASS), Denver, CO, USA, 2021.
The document explores the combination of textual data and emoticons to identify comments
that may be toxic or harmful within a specific context. It investigates the patterns in text and
emojis that could indicate toxic content, providing a more comprehensive approach to
comment analysis. The document also outlines various algorithms and techniques used for
detecting and categorizing toxic comments. These methodologies could be instrumental in
developing novel approaches for comment moderation on online platforms, allowing for
better identification of harmful content that may not be captured through text-based analysis
alone.
[6] V. Swetha, R. Anuhya, E. S. Sowmya and A. Geethanjali, "Building a Toxic Comments
Classification Model," 2021 5th International Conference on Electronics,
Communication and Aerospace Technology (ICECA), Coimbatore, India, 2021.
The document explores the process of building a toxic comments classification model that
employs a range of machine learning algorithms. It discusses the importance of accuracy and
hamming loss metrics in evaluating the performance of these algorithms and determining the
most toxic comment. Information design principles are highlighted as crucial for bridging the
gap between data frameworks and clients, ensuring effective information availability and
exchange strategies. The dataset from Kaggle, specifically the Kaggle Toxic Comments
dataset, is utilized for calculations to identify the most precise technique. The document
outlines the system structure, including dataset handling, module implementation such as
Count Vectorizer, and the utilization of ML algorithms like SVM, Naive Bayes, Logistic
Regression, Random Forest, Decision Tree, and KNN. It emphasizes the significance of
assessment measurements in gauging the quality of these machine learning algorithms.
[7] I. Gladwin, E. V. Renjiro, B. Valerian, I. S. Edbert and D. Suhartono, "Toxic Comment
Identification and Classification using BERT and SVM," 2022 8th International
Conference on Science and Technology (ICST), Yogyakarta, Indonesia, 2022.
SVM is recognized for its strong performance in text classification, often achieving higher
accuracy compared to other classification algorithms. It accomplishes this by reducing
empirical misclassification and maximizing geometric margins through predefined
hyperplanes. The document outlines the BERT architecture, which employs a two-way,
multi-layer Transformer encoder with a self-attention mechanism. BERT uses specific tokens
like [CLS] and [SEP] for sequence classification tasks. The classification process
encompasses several stages, which includes folding, tokenizing, filtering, stemming, and
splitting the data into train and test sets. These preprocessing steps are important for
preparing text for both SVM and BERT model.
[8] K. Dubey, R. Nair, M. U. Khan and P. S. Shaikh, "Toxic Comment Detection using
Comment Toxicity Classification Using Deep Learning Literature Survey
3 Classification of Online Rahul, Jatin Hooda, The methodology involved data specific models and
Toxic Comments Using Harsh Kajla, Gajanand preprocessing steps such as algorithms, such as
Machine Learning Saini converting short phrases to their NLP, LTS M, CNN, and
Algorithms,2020. original forms, removing stop Logistic Regression are
words, eliminating links and used, but it might not
hashtags, lemmatization, parts of cover all existing
speech tagging, and converting models and algorithms
words to lowercase. used in toxic comment
classification.
CHAPTER III
System Input: The model should accept text comments as input for analysis.
Toxicity Classification: The model should classify the input comments into various
categories of toxicity, possibly including "Severe Toxic," "Insult," and others.
Natural Language Processing (NLP) Techniques: The modelshould utilize NLP
techniques like TF-IDF (Term Frequency-Inverse Document Frequency) to process
and also understand the comments.
Machine Learning Model: The model should employ a Long Short-Term Memory
(LSTM) based ML model to perform the comment toxicity classification.
Performance: The system must efficiently process large datasets of tweets and
comments and deliver classification results quickly.
Accuracy: The system should achieve a high level of accuracy in classifying toxic
and non-toxic comments to make sure the toxicity classifier works effectively.
Scalability: The system should be scalable to handle increasing volumes of data
and users without a significant degradation in performance.
Usability: The model should have user-friendly interface and be easily accessible
for users to input and retrieve information without the need for specialized training.
Reliability: The system should be reliable, with consistent and dependable
performance in classifying toxic comments across different datasets.
generation.
Hard Disk: The storage capacity of the computer, measuring 256GB.
Ram: The amount of system memory available for running programs, which is 8GB.
Software Requirements:
Operating system: The base software environment used for running programs, in
this case, Windows.
Software Tool: The specific software application utilized for data handling and
analysis, which is Microsoft Excel 2013.
Dataset: The collection of data used for analysis or model training, sourced from
[Link].
Programming Language: The coding language used to implement and run the
project, specified as Python 3.6.9.
Platform: The cloud-based development environment for coding and collaborating,
identified as Google Colaboratory.
CHAPTER IV
SYSTEM ARCHITECTURE
According to the figure 4.1, the system architecture utilizes a combination of Natural Language
Processing and Long Short-Term Memory networks to classify the toxicity of comments. First,
comments are likely retrieved from a source and preprocessed for removing unnecessary
information and standardize the text format. This preprocessing might involve removal of
special characters, converting text to lowercase, and applying stemming or lemmatization
techniques.
[4] Next, the comments are broken down into individual words or phrases, known as tokens.
Each token is then converted into a numerical representation using a pre-trained word
embedding technique, such as GloVe, which captures the semantic relationships between
words. This allows the model to understand the meaning conveyed by the words in a format
suitable for machine learning algorithms.
The core of model lies in its use of LSTMs, a type of RNN adept at handling sequential data
like text. Unlike traditional neural networks, LSTMs can learn long-term dependencies
within sequences. This is crucial for comment classification, as the meaning of a word can
be influenced by its position in the sentence and the overall context of the comment. For
instance, the word "bad" might not be inherently toxic, but it could be indicative of toxicity
when used in a certain context, like "you're bad at this game." The LSTM layer in the model
is designed to capture these subtleties.
Following the word embeddings, the architecture might include convolutional layers, which
are commonly used in image processing but can also be effective for text classification. [5]
These layers aim to extract local features from the sequence of word embeddings, such as n-
grams (sequences of consecutive words) that might be indicative of toxicity. If convolutional
layers are present, they might be followed by max pooling layers reduces the number of
parameters in the model and help prevent overfitting, a condition where the model performs
well on training data but poorly on unseen data.
Finally, the output from the LSTM layer is fed into a fully connected layer. This layer maps
the information from the LSTM to a set of output neurons, typically two in this case - one
for "toxic" and one for "non-toxic”. [6] A sigmoid activation function is applied to the
output of this layer, transforming the values between 0 and 1. This value represents the
probability of the input text belonging to the "toxic" class. A value closer to 1 signifies a
higher likelihood of toxicity.
By combining NLP techniques for text representation and LSTMs for capturing context, this
system architecture aims to effectively classify comments as toxic or non-toxic, promoting a
healthier online environment.
CHAPTER V
IMPLEMENTATION
2. Train-Test Split:
Pre-processed data is then split into two sets: a training set and a test set.
Training set is used to train the LSTM model to identify toxic comments.
Test dataset is employed to assess how well the trained model performs.
3. Text Preparation:
Tokenization: The comments from the training set are split into individual words or tokens.
Text-to-Sequence Conversion: Every comment is transformed into a sequence of numbers,
with each number representing a word in the vocabulary.
Word-Index Dictionary: A dictionary is created that maps each word in the vocabulary to a
unique integer. This dictionary is employed to convert the text comments into sequences of
numbers.
Sequence Padding: The Number sequences are extended with padding to make sure they are
all the same length. This is important for the LSTM model, which expects to receive inputs of
a fixed size.
4. Training:
The training data is fed into the LSTM model. The model learns to identify patterns in the
sequences of word vectors that are indicative of toxic comments.
5. Evaluation:
The test data is fed into the trained model. The model predicts whether each comment in the
test set is toxic or non-toxic. The model’s performance is evaluated by comparing its
predictions to the actual labels of the comments in the test set.
6. Output:
In the below figure, the model outputs a dictionary with labels like “toxic” and “insult”
marked as “True,” while “threat” is marked as “False.” This indicates that the model has
classified the provided comment as toxic and insulting, but not threatening.
CHAPTER VI
APPLICATIONS
Promoting Healthy Discussions: Similar to social media, forums and chat rooms can
benefit from real-time toxicity detection. This fosters a more respectful and productive
conversation space.
Spam and Bot Detection: Toxic comments are often used by spammers and bots. Real
time analysis can help identify and filter out such malicious activity.
CHAPTER VII
While various techniques can be used for text classification, Long Short-Term Memory
(LSTM) neural networks have proven particularly adept at this task. Their ability to handle
sequential data, like the order of words in a sentence, makes them well-suited for
understanding the nuances of language. When trained on a comprehensive and relevant dataset,
LSTM models can achieve results on unseen data. In this instance, the model successfully
classified sentences as toxic or non-toxic, and even went a step further by estimating the
probability of each classification. This probabilistic output, often represented as a percentage,
provides valuable insights into the model's confidence level. The evaluation metrics, with a
precision of 94.49%, recall of 92.79%, and accuracy of 94.94%, demonstrate the model's
effectiveness in identifying toxic language on the test data. These results are promising and
suggest that the model has the potential to be valuable tool for tasks like content moderation or
sentiment analysis.
Future work: