A Semi-Supervised Approach to Detect Toxic Comments (2021)

Abstract: Toxic comments contain forms of non-acceptable language targeted towards groups or individuals. These types of comments become a serious concern for government organizations, online communities, and social media platforms. Although there are some approaches to handle non-acceptable language, most of them focus on supervised learning and the English language. In this paper, we deal with toxic comment detection as a semi-supervised strategy over a heterogeneous graph. We evaluate the approach on a toxic dataset of the Portuguese language, outperforming several graph-based methods and achieving competitive results compared to transformer architectures.

## introduction toxic comments, posts, and other types of content became more common in social media nowadays. they contain forms of non-acceptable language (profanity), which may be concealed or explicit, including insults and threats directed to a group or individual @xcite . these comments spread rapidly on the internet, especially on social networks where they find acceptance, and may culminate in several threats to individuals, becoming a serious concern for government organizations, online communities, and social media platforms. the term toxic comment is commonly found in literature as harmful speech, hate speech, or offensive language. toxic comment may be viewed as negative online behaviors, i.e., comments that are rude, disrespectful, may contain hate speech, or otherwise likely to make someone leave a discussion foot_0 . @xcite define hate speech as any communication that disparages a person or a group based on some characteristic such as race, color, ethnicity, gender, sexual orientation, nationality, religion, or other characteristics. also, it may occur with different linguistic styles, even in subtle forms or when humour is used @xcite . it is important to highlight that fighting these types of comments is of utmost importance since they are a crime in several countries. to deal with toxic comments, most approaches adopt supervised-machine learning techniques and are mainly focused on the english language @xcite . these approaches range from surface-level features, as bag-of-words @xcite , linguistics features, as part-of-speech information @xcite , deep neural networks, as long short-term memory (lstm) @xcite and convolutional neural networks (cnn) @xcite to transformer architectures @xcite . despite interesting results achieved by transformer architectures, there are still several rooms to be explored in this research area. in this paper, we developed a semi-supervised strategy to detect toxic comments in the brazilian portuguese language. semi-supervision is the problem of learning from labeled and unlabeled data @xcite , in which given a point set @xmath0, ..., x l , x l+1 , ..., x n } and a label set @xmath1, ..., c}, the first l points have labels {y 1 , ..., y l } ∈ l and the remaining points are unlabeled @xcite . we modeled that problem as a heterogeneous network. the structure of our graph was inspired by @xcite and @xcite . these authors modeled the tasks of helpfulness prediction and paraphrase identification as a heterogeneous network, respectively. for that, they defined an undirected unweighted graph with two node types: sentence and token. however, we have created a weighted graph based on pre-trained word embeddings. the weight between sentence and token nodes is the average of the embedding values for that token. figure 1 depicts an example of a sentence modeled as a graph. from this figure, we may see two node types: token and sentence, and an undirected and weighted edges between the sentence and tokens nodes. sentence midnight miss holy shit i playing club e(t) e(t) e(t) e(t) e(t) e(t) e(t) to extract features from the graph structure, we used a regularization algorithm that propagates labels from a small set of labeled nodes to the entire graph. we evaluated the approach using the told-br corpus @xcite . it has twenty-one thousand annotated tweets as either toxic or non-toxic language. also, we compared our strategy with different graph-based methods and with transformerbased methods. our method outperformed all graph-based approaches and achieved competitive results compared to transformer-based methods, using only 10% of labeled nodes. the reminder of this paper is structured as follows: section 2 briefly presents related work. in section 3, we show the used corpora. section 4 details our developed approach. in section 5, we analyze the conducted experiments. finally, section 6 concludes the paper, presenting future directions. ## related word as aforementioned, the main approaches to detect toxic comments are based on supervised machine learning. here, we briefly present the main works. most of the works that study this task commonly point first to surface-level features, such as bag of words and lexicon-based approaches, with negative words as features @xcite @xcite . more recently, neural networks-based strategies and transformer-based architectures has been applied to hate speech detection due to the good results achieved in various tasks. banerjee et al. (2020) evaluated pre-trained word embeddings with cnn networks to hate speech detection for the indian language. rizwan et al. (2020) explored transfer-learning of embeddings models to roman urdu and developed a cnn-gram network to hate speech classification for that language. duwairi et al. (2021) investigated the ability of cnn, cnn-lstm, and bilstm-cnn to classify hate speech in arabic. plaza-del arco et al. ( 2021 ) compared two pre-trained language models, such as bert @xcite and xlm (conneau and lample, 2019) trained to detect hate speech in the spanish language. for the portuguese language, most of the works follow the trend of supervised approaches. de pelle and moreira (2017) created a dataset consist of 1, 250 offensive comments and developed a baseline method based on n-gram features to classify offensive comments in their dataset. @xcite created a hate speech dataset composed of 5, 668 tweets and developed a baseline classification using pre-trained word embeddings and lstm in their dataset. coutinho and malheiros (2020) trained a logistic regression using superficial features for sentiment analysis. then, they evaluated that model into a homophobia corpus to detect homophobic posts. although there are some efforts to detect nonacceptable language in portuguese, they evaluate the developed approach in their own corpus, making a fair comparison among the models difficult. moreover, these corpora are much smaller when compared to corpora of other languages @xcite and than the told-br corpus. this fact makes the development of robust strategies to handle toxic comments difficult, as they usually require a large corpus. besides seven categories, the authors released a binary version of the corpus for the binary classification task, as shown in ## experiments and results in order to produce coordinate values for each object from the regularizer, we ranged the number of pre-labeled nodes from 5% to 30%. then, we applied the machine learning algorithms to train and classifier toxic comments. we achieved the best result with the gradient boosting classifier foot_5 using only 10% of the prelabeled nodes i.e., the classification does not improve after this percentage. besides our approach, we evaluated other graph models of different structures. first, we used the network graph developed by @xcite . that graph does not use weight between the nodes. second, we used the term frequency-inverse document frequency (tf-idf) as weight instead of the average of embeddings. third, we used bigrams and trigrams as nodes rather than token nodes. finally, we used the pointwise mutual information (pmi) measure @xcite as the weight between the bi and trigrams nodes. for these approaches, we adopted the same regularization algorithm, ranging the pre-labeled nodes from 5% to 30%. in from this table, our graph modeling and the gradient boosting classifier achieved better results than these other graphs, as well as classifier variations. this, we think, is because of the embedding value among the graph nodes since it is able to capture morphological, syntactic, and semantic knowledge of a word. as we used the average word embedding value, it includes information from all of the individual vector values, working as an overall summary of all vector values. we further compared our strategy with other graph-based approaches: text graph convolutional network (textgcn) @xcite and heterogeneous graph attention network (hgat) @xcite . the former models the whole text corpus as a document-word graph with word co-occurrence relations and applies gcn for classification. the latter models the texts using a heterogeneous information network framework and adopts heterogeneous graph attention to embed that framework for text classification based on a dual-level attention mechanism. finally, we compared our approach with a transformer-based method as it has achieved remarkable results in several areas of natural language processing (nlp). we compared our strategy with br-bert (leite et al., 2020), which is a monolingual bert, and m-bert (leite et al., 2020), which is a multilingual bert. as we can see from our approach is available at https://github.c om/rafaelanchieta/toxic . ## conclusion and future work in this paper, we explored a semi-supervised strategy to deal with toxic comments from twitter. we modeled the texts as a heterogeneous network graph with two node types and weighted edges among nodes. then, we applied a regularization algorithm to extract features related to the toxic texts. finally, we used these features to feed a classifier to identify and predict toxic comments. our approach outperformed several graph-based methods and achieved a competitive result compared to the bert model, using only 10% of the corpus. we hope that this graph model brings insights to hate speech detection research, helping to improve the results. furthermore, our strategy may be employed in other languages, as it only requires an embedding representation. as future work, we intend to explore the graph structure, analyzing some network measures, such as degree, centrality, community identification, and others. also, we aim to examine contextual embeddings rather than traditional embeddings.