0% found this document useful (0 votes)
18 views6 pages

Classificationof Toxicityin Comments Using NLPand LSTM

The document presents research on classifying toxicity in online comments using Natural Language Processing (NLP) and Long Short-Term Memory (LSTM) networks. It details a two-phase methodology where Phase I utilizes LSTM for training and predicting comment toxicity, while Phase II employs Gated Recurrent Units (GRU) for further analysis. The study aims to enhance online conversations by effectively identifying and categorizing toxic comments to mitigate their impact on social media interactions.

Uploaded by

saumyavenkatesh3
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views6 pages

Classificationof Toxicityin Comments Using NLPand LSTM

The document presents research on classifying toxicity in online comments using Natural Language Processing (NLP) and Long Short-Term Memory (LSTM) networks. It details a two-phase methodology where Phase I utilizes LSTM for training and predicting comment toxicity, while Phase II employs Gated Recurrent Units (GRU) for further analysis. The study aims to enhance online conversations by effectively identifying and categorizing toxic comments to mitigate their impact on social media interactions.

Uploaded by

saumyavenkatesh3
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

2022 8th International Conference on Advanced Computing and Communication Systems (ICACCS)

Classification of Toxicity in Comments using NLP


and LSTM
Anusha Garlapati, Neeraj Malisetty, Gayathri Narayanan

garlapatianusha@[Link], neerajmalisetty@[Link], gayathrin@[Link]

Dept of Electronics and Communication Engineering, Amrita Vishwa Vidyapeetham, Amritapuri, India

Abstract – With the increased usage of online social media most influential tool that is useful for users to analyze and
platforms, there has been a sharp hike in toxic comments. classify several parameters from text-based comments by
Toxicity must be reduced. Classification of toxicity in comments extracting the data. The aim was to develop a model that can
has been an effective research field with various newly proposed predict to classify the types of comments.
approaches. This research and analysis provide a novel usage of
the Natural Language Processing approach to classify the type II. LITERATURE REVIEW
of toxicity in comments. This analysis intends to interpret the
Various Machine learning and Deep learning methods are
type of comment and determine the various types of toxic classes
such as obscene, identity hate, threat, toxic, insult, severe toxic. used for classifying the type of toxicity by using neural
The input to our algorithm is comments from online platforms networks. There are various papers on toxicity classification
like toxic or non-toxic. Our model aims to predict the toxicity but, they have used the constant model to predict accuracy.
[Link] project intends to analyze in phases. In Phase I, the Conversational AI Team, that’s a research initiative that was
objective is to evaluate the toxicity in comments by giving data established by Jigsaw and Google to protect the conversation
through various techniques like TDIDF, spacy that helps data to voices by building a technology [9]. It’s easy for humans to
perceive how every word in a comment is classified into a divide or classify the text or images but it’s difficult for
particular category of toxic class. Here, Algorithm will take computers as it deals with only binary values or numbers. Any
comments from test data and predict the type of toxicity for test data must be converted to a numeric type before applying it to
data like a toxic, threat, and so on. In Phase II, Data is analyzed the model. Classification of text uses NLP and various
to organize the comments into toxic and non-toxic categories. machine learning methods to classify comments.
This promotes us to perceive the particular comment is toxic or
not. Here, the intention is to explore the visualization of comments
in different ways by utilizing some unique visualization
Keywords - Toxicity, Comments, NLP, TFIDF, Severe Toxic, techniques. LSTM and GRU are algorithms used for
Insult, Text Classification classifying the type of toxicity and prediction of test data in
comments. Our analysis is to enhance online conversation by
I. INTRODUCTION inspecting various techniques in NLP to create an authentic
Increasing in usage of online platforms that also permits model that is adequate for detecting types of comments such
people to get across with each other, by exchanging feelings as toxic or non-toxic and that model will be deployed using
or attitudes about several events and they leave comments Heroku.
about their opinion. This has contributed to the evolution of III. DATA SET
Natural Language Processing (NLP). The background for the
problem statement arises from the crowd of online comments. The data set consists of nearly 109449 rows and 8 columns
Identifying the toxicity in comments has been a tremendous such as comment text, insult, id, toxic, insult, identity hate,
challenge for users. In a few cases, these online conversations obscene, severe toxic. Each class in the data set has binary
include certain language that can be divided into different values 0 and 1, inferring whether a particular comment is
types like toxic, insult, obscenity, severe toxic, threat, identity related to that particular class or not. The sample of data
hate. Here, data has multi-labels to classify, each having including rows and columns is as follows:
binary classifications (0 and 1). So, the problem statement is TABLE1: Sample Data
considered to be a Multi-label classification problem.
Unintended bias in these online conversations must be Comment Text Toxic Severe Toxic Obscene
decreased. Although social media offers a lot of positive news
to world it also has negative aspects. That’s all bullshit, 1 0 1
and you know it.
Toxic comments are examined like comments that are
insulting, disrespectful which results in people leaving the And how to delete the 0 0 0
conversations. Toxicity is like an argument that can point to wrong or unwanted
that people both to stop honestly communicating themselves images uploaded.
and to stop seeking others' points of view out of fear of TABLE2: Sample Data
indignity. Automatic examining of toxicity in comments on
social media platforms is helpful for people on social media Id Threat Insult Identity Hate
users who could get warnings or unwanted messages [10]. 27aafc4eb33071b0 0 0 0
Natural Language Processing with efficient algorithms is the
2022 8th International Conference on Advanced Computing and Communication Systems (ICACCS)
27d42ae876c0010a 0 0 0 It's an easy and most adequate form of pre-processing in any
text data. It's relevant to most NLP analyses. It converts data
Exploratory Data Analysis to lowercase to have the same case preferably.
Following data cleansing, the next step in any project is to get TABLE4: Data after Lowering Text
familiarized with data using EDA. Using a variety of features
is one method to get this level of familiarization. Like by using Comment Text Lowering Text
pie charts, bar graphs, correlation maps.
Thats all Bullshit and you thats all Bullshit and you
know it know it
And how to delete the and how to delete the wrong
wrong or unwanted images or unwanted images
uploaded in 2018 June uploaded in 2018 june
Tokenization:
Here, the text will be divided into minor units. Like sentences
are converted into words. It divides a phrase or paragraphs into
minor units, like words. Each minor word is called a token.
Before pre-processing, it's necessary to classify the words that
create a string. Tokenization is decisive because the essence
of text could be efficiently understood here by inspecting
words in a text.
Figure1 – Pie chart distribution from data collected
TABLE5: Data after Tokenization
Here, each slice in the chart is concerning the size of that
particular class in the data set. Figure1 infers that most Comment Text Tokenization
comments in data are toxic.
thats all bullshit and you [thats, all, bullshit, and, you,
know it know, it]
and how to delete the wrong [and, how, to, delete, the
or unwanted images wrong, or, unwanted,
uploaded in 2018 june images, uploaded, in, 2018,
June]
Figure2 – Bar graph distribution from data collected.
Stop Word Removal:
IV. DATA PRE-PROCESSING
This helps us to remove unnecessary words from the text like
This is also known as Data Transformation. This includes she, them, he, for, it. The most commonly used words are
data cleaning, dealing with null values, feature scaling, and removed here. These are eradicated from the text data before
so on. This is part of the data pipeline. As this project deals training any models since they appear in plenty. This is done
with text data, some more pre-processing techniques are by classifying text data into words and then removing words
mandatory to apply to get efficient accuracy for the model. if they appear in stop words, which is an inbuilt function in
They are like dealing with punctuation removal, stop words NLP that contains a lot of unnecessary words. This also helps
removal, stemming, and so on. in focusing more on necessary data.
TABLE6: Data after Stop Word Removal
Punctuation Removal:
Comment Text Stop Word Removal
In this step, all punctuation from the text data is removed. thats all bullshit and you bullshit know
There is an inbuilt library called a “string” in python which know it
helps to remove punctuation from text data. It has some
predefined characters such as @, (), [], +, -, /, *, # and so on. and how to delete the wrong delete wrong unwanted
or unwanted images images uploaded june
TABLE3: Data after Punctuation Removal uploaded in 2018 june

Comment Text Punctuation Removal


Stemming:
That’s all Bullshit, and you Thats all Bullshit and you
know it. know it It mostly expels the suffix from a word and diminishes it to its
And, how to delete the And how to delete the root word. This is a normalizing method in NLP for text data.
wrong or unwanted Images wrong or unwanted Images It’s a rule-based method since it divides the words from
uploaded in 2018, June uploaded in 2018 June prefixes as per the necessity of words.
Spacy NLP:
It’s an open-source library utilized in progressive NLP and
Lowering Text: ML to extract important information from data.
2022 8th International Conference on Advanced Computing and Communication Systems (ICACCS)
It’s a method used in python to excerpt information from
unregulated data to identify special features such as parts of
speech (pos), Name entity recognition (ner), tokens, and so on.
Spacy is a flagrant and easily implemented NLP library. It
provides efficiency and dexterity and has a pro-active source.
A relatively new technique for NLP was acquired by Matt
Hannibal. It has many tasks utilized in NLP like parts of
speech (pos), name entity recognition (ner), tokenization,
word2vec, and so on.
Parts of speech (pos): It's like the development of semantics
like a verb, noun, adjectives, adverb.
Name entity recognition (ner): It's like the dominant method
of classifying name entities identified in the text to pre-defined
clusters like the place, dates, persons. Spacy utilizes statistical
techniques to classify the name entity recognition (ner).
TABLE7: Spacy Features
Comment Text Parts of Speech Name Entity
Recognition
thats all bullshit [adverb, det, verb, []
and you know it CON, pronoun, verb,
PREP]
And how to [CON, adverb, PREP, [2018. june]
delete the wrong verb, det, adjective,
or unwanted CON, adjective,
images uploaded adjective] Figure4 – Visualization of Circles in PyLDAVis
in 2018 june
Bar Graph:
When no topic is chosen, the bar graph basically will be in
Visualization with PyLDAVis: blue. When a particular class is selected it will be shown in red
It’s a python library for collective topic model analysis. color. From this, the overall frequency of words in a particular
PyLDAVis is skeptical about how the algorithm was class concerning overall data can be inferred, and also overall
evaluated. To anticipate it equips topic-term distributions and frequency alone can be inferred.
elementary content about a corpus that the algorithm was
evaluated on. Here, the predominant parameter is ‘prepared’
that will convert text data to other formats that are necessary
for the analysis of PyLDAVis.
It’s mainly developed to illustrate the different types of data
that have been fit into the corpus of data. It’s like the bilateral
web-based analysis.

Figure3 – Overall Visualization of PyLDAVis


Default Topic Circles:
These are from the left side of the above Figure3, they
represent each topic in the data set.
Figure5 - Visualization of Bar Graph in PyLDAVis
2022 8th International Conference on Advanced Computing and Communication Systems (ICACCS)
V. METHODOLOGY Here, Wo, b o are weights and biases concerning output gates.
Interpretation of data was done in two phases. In Phase I, Output parameters h t depend on output cell (O t). Here, the
LSTM is applied data for training and to predict the test data sigmoid function determines which part is needed to make
parameters like type of class. And in Phase II, GRU is applied output and that output is multiplied by new parameters that are
to data. After all analysis, this project is deployed using acquired by tanh layer from cell state (C t).
Heroku.
TABLE8: Results From LSTM
LSTM:
Precision Recall F1-Score Support
LSTM is called Long Short-term memory. LSTM’s are easily
implemented to avoid the long-term dependency 0 0.81 1.00 0.95 39733
complication. LSTM is combined of different states such as 1 0.76 0.98 0.01 3385
cell state and hidden state. It’s like a distinct neural network.
Data can be added or eradicated by using various gates [3]. A Accuracy ---- ---- 0.94 36118
gate is analogous to layers that consist of various weights.
Macro 0.45 0.50 0.48 36118
Here, Algorithm analyzes the unnecessary information and it avg
will be eradicated from the cell. This part of elimination was
decided by the sigmoid function. It has mainly four Weighted 0.82 0.91 0.86 36118
components. They are Input gate, Output gate, Forget gate, avg
and cell state. On the last time step for the dense layer, LSTM
delivers a feature set, that may be utilized to generate results.
From TABLE8, it is found that the LSTM model has obtained
an accuracy of 94%.
TABLE9: Sample Data of Predicted Test Data from LSTM
Id Toxic Severe toxic
00001cee341fdb12 1.0 0.0
0000247867823ef7 0.0 0.0

TABLE10: Sample Data of Predicted Test Data from LSTM


Obscene Threat Insult Identity hate
1.0 0.0 1.0 0.0
0.0 0.0 0.0 0.0
Figure6 – Structure of LSTM
f t = σ (W f [h t-1, x t] + b f) From TABLE9 and TABLE10, these are the prediction results
σ is the Sigmoid function, Weights matrices and bias are W f obtained for test data from LSTM.
and b f. GRU:
f t is the vector with values ranging from 0 to 1, concerning GRUs are enhanced versions of neural networks. In this
each number in cell state C t-1. Sigmoid function determines if
analysis update and reset gates are utilized to solve the
new data is necessary or not, and tanh analyses weights to
problem of vanishing gradient.
parameters that passed by, analyzing their level of necessity.
These values are multiplied to renew the new cells. This is
then joined to old memory C t-1 ensuring C t.

it = σ (Wi [h t-1, x t] + bi)


N t = tanh (W n [h t-1, x t] + bn)
C t = C t-1 f t + N t I t

Here, C t-1 and C t are cells concerning time periods t 1 and t.


W and b are weights and biases.

O t = σ (W o [h t-1, x t] + b o)
h t = O t tanh (C t)
Figure7 – Structure of GRU
2022 8th International Conference on Advanced Computing and Communication Systems (ICACCS)
Here, the update gate controls the instructions that are VII. CONCLUSION
progressing to memory, and the reset gate analyzes the data In this Paper, Analysis was done on toxic comments by using
that flows out of memory [7]. These GRUs achieve well in
NLP. This is done in two phases. In Phase I, the model is
sequence tasks. The architecture of GRU is simple as a neural
network. evaluated by using LSTM, and the class of toxicity is
predicted for test data from LSTM trained model. The model
The weights are updated using back-propagation. Each gate is performed well with an accuracy of 94%.
determined by using hidden state and bias from previous cell In Phase II, the model is evaluated using GRU and got an
states by reduction of variables. The activation function of accuracy of 92%. This project application is tested using a
GRU from previous and current states (h t-1) and h t will flask and deployed in the Heroku app that gives ultimate
operate at time-periods t-1 and t respectively. results.
h t = (1 – z t) h t-1 + z t h t
VIII. FUTURE SCOPE
Here, z t is an update gate that determines the necessity of a NLP is mostly like dealing with text data with various
unit that amends the activation function.
techniques. The future scope of this project is to develop a
TABLE11: Results From GRU Classification of toxicity on images by enhancing and
collecting image data from various social media platforms
Precision Recall F1-Score Support
such as restaurant reviews, Facebook comments, and so on.
0 0.95 1.00 0.92 2576 Classifying the image data as toxic or non-toxic by utilizing
Optical Character Recognition (OCR) is to be done in the
1 1.00 0.98 0.92 2636 future.
Accuracy ---- ----- 0.92 5212
REFERENCES
Macro 0.93 0.93 0.92 5212
[1] R. Vinaya Kumar, K.P. Soman and P. Poorna Chandran,
avg
“Long short-term memory based operating log anomaly
Weighted 0.93 0.93 0.92 5212 detection,” 2017 International Conference on Advances in
avg Communicating, Communications and Informatics
(ICACCI), 2017, pp. 236-242.

From the TABLE11, it can be inferred that GRU model has [2] R. Vinaya Kumar “Amrita-CEN-Senti-DB: Twitter
acquired an accuracy of 92%. Dataset for Sentimental Analysis and Application of
Classical Machine Learning and Deep Learning.”, TechRxiv
VI. DEPLOYMENT (2020).
It’s a method of consolidating our models to an environment
where they can be deployed to a web app. Data is analyzed [3] Viswanathan S, Anand Kumar, Soman K.P, “A Sequence-
and evaluated using models like LSTM and GRU. Now, the Based Machine Comprehension Modelling Using LSTM and
model is ready for deployment. The testing application was GRU.” Emerging Research in Electronics, Computer Science
done by using flask in vs code. Deployment was done by and Technology. Lecture Notes in Electrical Engineering, vol
using Heroku and Git-hub. 545, Springer, Singapore.

[4] P. Ram Manohar, “Toxicity of Ayurvedic Medicines and


Safety Concerns: Ancient and Modern Perspectives, In
History of Toxicology and Environment Health, Toxicology
in Antiquity” (Second Addition), Academic Press, 2019,
ISBN 9780128153390.

[5] Se, S., Vinaya Kumar, R., Kumar, M.A., Soman, K.P.
Figure8 – Web Page of our Project “AMRITA – CEN@SAIL2015: Sentiment Analysis in Indian
Languages. MIKE (2015).

[6] Kakuthota Rakshitha, Ramalingam HM, M Pavithra,


Advi HD, Maithri Hedge, “Sentiment Analysis of Indian
regional languages on social media,” Global Transitions
Proceedings, Volume 2, Issue 2, 2021, Pages 414-420.

[7] Guizhu Shen, Qingping Tan, Haoyu Zhang, Ping Zeng,


Jianjun Xu, “Deep Learning with Gated Recurrent Unit
Networks for Financial Sequence Predictions”, 8th
International Congress of Information and Communication
Technology (ICICT – 2018).
Figure9 – Results from Web Page
2022 8th International Conference on Advanced Computing and Communication Systems (ICACCS)
[8] R. Dey and F.M Salem, “Gate-Variants of Gated
Recurrent Unit (GRU) Neural Networks,” International
Midwest Symposium on Circuits and Systems (MWSCAS),
2017, pp. 1597 – 1600.

[9] A. Akshith Sagar, J. Sai Kiran, “Toxic Comment


Classification using Natural Language Processing,”
International Research Journal of Engineering and
Technology (IRJET – 2020)

[10] Navoneel Chakrabarty, “A Machine Learning Approach


to Comment Toxicity Classification,” International
Conference on Computational Intelligence in Pattern
Recognition (CIPR 2019).

[11] P. Vidyullatha, Satya Narayanan Padhy, Javvaji Geetha


Priya, Kakarlapudi Srija, Sri Satyanjani Koppisetti,
“Identification and Classification of Toxic Comments Using
Machine Learning Methods,” International Journal of
Research and Innovation in Applied Science (IJRIAS – 2021)

[12] Spiros V. Georgakopoulos, Sotiris K. Tasoulis Aristidis


G. Vrahatis, Vassills P. Plagianakos, “Convolutional Neural
Networks for toxic comment classification”, Hellenic
Conference (2018).

[13] Sara Zaheri, Jeff Leath, David Stroud, “Toxic Comment


Classification,” SMU Scholar, 2020.

You might also like