{'fraction_non_alphanumeric': 0.03950806378953059, 'fraction_numerical': 0.019281016307775477, 'mean_word_length': 5.135710337202875, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Contextual-Lexicon Approach for Abusive Language Detection

Since a lexicon-based approach is more elegant scientifically, explaining the solution components and being easier to generalize to other applications, this paper provides a new approach for offensive language and hate speech detection on social media. Our approach embodies a lexicon of implicit and explicit offensive and swearing expressions annotated with contextual information. Due to the severity of the social media abusive comments in Brazil, and the lack of research in Portuguese, Brazilian Portuguese is the language used to validate the models. Nevertheless, our method may be applied to any other language. The conducted experiments show the effectiveness of the proposed approach, outperforming the current baseline methods for the Portuguese language.


Introduction
In Brazil, hate speech is prohibited. Nevertheless, in government and civil society, the regulation of hate speech is not effective due to the difficulty to identify, quantify and classify abusive comments. Indeed, this is rather a difficult requirement to satisfy. According to Mesquita (2018), the Safernet non-governmental organization, which operates in cooperation with public organizations in Brazil, as well as companies, such as Google, Facebook, and Twitter, proposed a collection of data on actions that violate human rights. The data is very worrisome: during the 2018 year's election period, denunciations with xenophobia content had an increase of 2,369.5%; apology and public incitement to violence and crimes against life, 630.52%; neo-nazism, 548.4%; homophobia, 350.2%; racism, 218.2%; and religious in-1 Proceedings of the 13th Recent Advances in Natural Language Processing, pages [1438][1439][1440][1441][1442][1443][1444][1445][1446][1447]2021. https: //aclanthology.org/2021.ranlp-1.161/ tolerance, 145.13% 2 . Figure 1 shows the hate crimes evolution that occurred in the most populous Brazilian state 3 . The data was collected from São Paulo public security government. The pink line provides data on religious intolerance crimes, red on homophobia/transphobia, blue on race/ethnicity/color, green on region/origin, yellow on political intolerance, and light green on other crimes. Indeed, it is generally agreed that the high incidence of hate crimes is boosted by the popularization of online social networks. In social media, people and organizations may use the language to defamation, oppression, and terrorism. The language used intentionally in order to disrespect, insult or attack the reader is denominated in literature by abusive language, unless otherwise stated such as offensive language (Çöltekin, 2020;Pitenis et al., 2020;Razavi et al., 2010), hate speech (Schmidt and Wiegand, 2017;Waseem and Hovy, 2016) and cyberbullying (Rosa et al., 2019).
According to Warner and Hirschberg (2012), hate speech is a particular form of abusive language considering stereotypes to express an ideology of hate. In the same settings, Nockleby (2000) defines 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 characteristic".
To the best of our knowledge, no previous methods exist in order to embody an offensive lexicon annotated with contextual information to automatically classify abusive language on social media. Therefore, the main contribution of this paper is providing a new method for abusive comment detection on social media. Moreover, as already mentioned, due to the severity of the hate crimes in Brazil, and the lack of research in this language, Brazilian Portuguese is the language used to evaluate the proposed method, which showed high performance, outperforming the current baseline methods for Portuguese. Despite the proposed approach has been orchestrated over Brazilian Portuguese comments, the method in this paper may be applied to any other language. Finally, this paper also presents the evaluation of algorithms used for feature selection.
The remainder of the paper is structured as follows. In Section 2, we briefly introduce the most relevant related work. Section 3 presents a overview of the data. Sections 4 and 5 describe the proposed method and the performed experiments. In Section 6, we report the evaluation results. In Section 7, we make some final remarks.

Related Work
Several efforts have been made to provide automated detection approaches for hate speech and offensive languages on social media (Gao and Huang, 2017;Davidson et al., 2017;Warner and Hirschberg, 2012). The basic state of the art framework consists of creating lists of words that contain sets of known hate keywords. Furthermore, corpora are manually annotated in order to construct training datasets labeled with hate speech and non-hate speech. At last, automated methods of learning, such as traditional machine learning or neural-based machine learning, are used to automatically detect hate speech in social media texts. However, most hate speech resources and models are proposed for English (Zampieri et al., 2019;Basile et al., 2019;Davidson et al., 2017;Njagi et al., 2015;Ting et al., 2013).
For Portuguese, Fortuna et al. (2019) adopted the definition of hate speech proposed by Fortuna and Nunes (2018), and proposed a new dataset composed of 5,668 tweets, as well as automated methods using a hierarchy of hate to identify social groups of discrimination. The authors have obtained 78% f1-score using a neural network (LSTM). Additionally, de Pelle and Moreira (2017) provide a new dataset composed of 1,250 comments collected from G1 Brazilian online newspaper 4 and annotated with offensive and non-offensive tags. In addition, the authors present classification results achieved by classical machine learning algorithms (SMV and NB), reporting results over 81% f1-score.

HateBR Corpus
HateBR was proposed by Vargas et al. (2021), and consists of the first large-scale dataset for hate speech and offensive language detection for the Portuguese language. HateBR corpus annotation presents 75% of human inter-annotator agreement. The corpus is composed of 7,000 Instagram comments annotated with three different layers: (i) binary classes (offensive and non-offensive); (ii) offense-levels (highly, moderately, and slightly offensive); and (iii) nine hate group targets (xenophobia, racism, homophobia, sexism, religious intolerance, partyism 5 , apology to dictatorship, antisemitism, and fatphobia).
The authors report that the comments were collected from six public Instagram accounts of the Brazilian political domain. Moreover, they selected three liberal-party accounts followed by three conservative-party accounts, being four women and two men. Due to the degree of complexity of the offensive language and hate speech detection tasks, mainly because it involves a highly politicized domain, the authors decided to enroll annotators at higher levels of education (Ph.D.), which are from different political orientations and colors in order to minimize bias.

MOL -Multilingual Offensive Lexicon
MOL (Multilingual Offensive Lexicon) 6 consists of a multilingual offensive lexicon, composed of 1,000 explicit and implicit offensive and swearing expressions, which were annotated with a binary class: context-dependent and context-independent offensive. For example, the term ''vadia" ("slut") consists of a context-independent offensive term. On other hand, the term inútil ("useless") is a context-dependent offensive term. Note that this last term is classified as context-dependent offensive because it also may be employed in a nonoffensive context, such as "this smartphone is useless" or "the process is useless for this task". The MOL was extracted from HateBR corpus (Vargas et al., 2021), and each term or expression was annotated by three different annotators obtaining a high human agreement score (73% Kappa). Furthermore, as already mentioned, implicit content also was extracted using "clue terms or expressions". For example, the expression voltar 6 https://github.com/francielleavargas/ MOL para a jaula ("go back to the cage") consists of a "clue expression" to identify the implicit offensive term ladrão ("thief"). Finally, terms that showed explicit potential to indicate hate speech targets were also annotated, for instance, vadia ("slut") and judeus dos infernos ("jews from hell"). Note that the occurrence of these cases may indicate sexist and antisemitism comments.

The Proposed Approach
We present a new approach to detect abusive comments on the web and social media. Our method embodies an offensive lexicon, which provides contextual information on hate speech and offenses. We show in detail our approach in Sections 4.1, 4.2, and 4.3.

Tasks
In this paper, we assume that abusive language detection may be divided into two main tasks: (i) offensive language detection, (ii) hate speech detection. Considering this premise, we train two different classifiers. The first classifier automatically identifies offensive comments. On the other hand, the second classifier automatically identifies comments that present hate speech content. Note that a hate speech comment is always an offensive comment, however, an offensive comment may present or not hate speech content. Figure 2 shows each of these different tasks in detail.

The Feature Set
Defining the most appropriate textual representation is a crucial task that directly influences the performance of the predictive model built by the classification algorithms. In this paper, we modeled hate speech and offensive language through different representation paradigms and features. We describe each one in what follows.

Lexical and Morphosyntactic Features
We selected lexical elements (each word into the document without stopwords), as well as part-ofspeech-based features, using the Stanford Stanza POS tagger 7 for Portuguese.
2. Contextual Lexicon: we evaluated features based on an offensive lexicon (MOL) annotated with contextual (context-dependent and context-independent) labels.

Word Embedding Features
We also evaluated word embedding-based features. Different from other language models, BERT (Bidirectional Encoder Representations from Transformers) is usually used to pre-train deep bidirectional representations from unlabeled texts by jointly conditioning on both left and right contexts in all internal network layers (Devlin et al., 2019). In a similar setting, we also used fastText, the Facebook pre-trained models (Joulin et al., 2016).

Feature Set Overview
We summarize in Table 4 the five feature representations used in this paper. 1. POS+S: we extracted the occurrence of partof-speech tags for each comment. In addition, we extracted the occurrence of positive and negative words for each comment using the sentiment (Silva et al., 2012) and emotion (Pasqualotti, 2008) lexicons.
2. BOW: we created a bag-of-words representation or, in other words, we generated a text representation that describes the occurrence of dataset vocabulary for each comment. We simply calculate how many times each word of our dataset vocabulary (features) appears in each comment.
3. MOL: in this representation, a bag-of-words was generated using the terms or expressions extracted from the offensive lexicon (MOL), which were used as features. Therefore, for each comment, the occurrence of the MOL's terms was counted. Additionally, context labels (context-independent and context-dependent) have been considered in order to compute different weights to context-independent and context-dependent features. The frequency of the terms with context-independent labels were multiplied by 2, while the frequency of the terms with context-dependent features remained the same. Specifically for hate speech detection task, we also checked if a term presented any markers that identify hate speech content, and, if this condition was true, an additional weight was accounted. Therefore, in the MOL representation, the value of a term x in the document (comment) y for the offensive comment detection (task 1) is defined according to where f req is the frequency of the term in the document, weightH = 2 when the term is a marker that identifies hate speech and weightH = 1 otherwise, weightC = 1 for context-dependent terms and weightC = 2 when the term is context-independent.
4. B+M: we generated a bag-of-words representation, which embodies context label information from the offensive lexicon (MOL). In other words, we firstly generated a bag-ofwords from all comments into the dataset. Then, we performed the match with terms into MOL, and then we assigned a weight for terms or expressions labeled with contextdependent (weaker weight) and contextindependent (stronger weight). The contextual labels are provided by MOL. Therefore, in B+M representation, the value of a term x into the document (comment) y is defined according to where f req is the frequency of the term in the document, weightC = 2 for contextdependent terms and weightC = 3 when the term is context-independent.
5. In a different setting, the feature extraction for the BERT and fastText followed state of the art text classification with a maximum size of 500. For the fastText classifier, we set the maximum size equal to 64 and the maximum number of features equal to 10,000. We used the standard processor model and evaluated the n-gram range for unigram, bigram, and trigram.

The Learning Methods
In general, previous works on hate speech detection use neural networks or traditional machine learning techniques on specific communities (Davidson et al., 2017;Founta et al., 2019;Del Vigna et al., 2017;Njagi et al., 2015;Djuric et al., 2015). In order to evaluate the performance of neural networks and traditional machine learning techniques, we used the following learning methods: Support Vector Machine (SVM) (Scholkopf and Smola, 2001) with linear kernel; Multinomial Naive Bayes (NB) (McCallum et al., 1998;Eyheramendy et al., 2003); Multilayer Perceptron (MLP) (Haykin, 2009) with one hidden layer (with 100 neurons), and ReLU activation function; Long Short-Term Memory (LSTM) (Hochreiter and Schmidhuber, 1997) with two hidden layers (with 200 and 50 neurons, respectively) and a softmax output unit for the binary classification. ReLU was used as the activation function, as well as number of epochs equal to 10, and a random batch size of 100 documents. Moreover, we also used pre-trained models of word embeddings, such as BERT (Devlin et al., 2019) and fastText (Joulin et al., 2016).

Experiments
We carried out a wide variety of experiments. We describe the entire process in Sections 5.1, 5.2, 5.3 and 5.4.

Data Preparing
We accomplished an approach for data preparation, as shown in Figure 3 Firstly, we normalized our dataset using the normalization tool for Brazilian Portuguese proposed by Bertaglia and Nunes (2016). The normalization process consists of identifying noise, which is very common in User-Generated Content (UGC), such as orthographic errors, often phonetically-motivated, abbreviations and expressions often used informally by web users, proper names and acronyms wrongly or not at all capitalized, agglutinated words that should be split, and wrong use of sentence delimiters; and suggesting possible substitutions.
Moving forward, in the second step, we remove emoticons, special characters, accounts, hyperlinks, and websites. In step 3, we lemmatize our dataset using Spacy 8 . Finally, in step 4, accentuation is removed.

Feature Selection
Feature selection (FS) allows the removal of irrelevant and redundant features. In this paper, in order to select the best feature set, we applied the following FS algorithms: (i) Correlation-based Feature Selection (CFS) (Hall, 1998), which selects characteristics that are highly correlated with the class and not correlated with each other using Pearson coefficient 9 as criteria, and (ii) Information Gain Analysis (InfoGain) (Witten et al., 2016), which quantifies and chooses the characteristics that have the maximum information gain concerning the class. We apply both FS techniques on the NB, SVM, MLP and LSTM models. For BERT and fastText features, we do not apply FS techniques. Finally, we evaluated the performance of the FS techniques for each feature representation. More specifically, we measure the potential of the algorithms to help in the gain and loss of accuracy, precision, recall, and f1-score. Results are shown in Table 7.

Class Balancing
The most common class balancing methods are oversampling (Chawla et al., 2002) andundersampling (Witten et al., 2016). In undersampling, the number of examples of each class is maintained based on the number of examples from the minority class. Differently, in oversampling, the approach involves the construction of examples for the minority class, although these examples may not add any new information to the model. In our experiments, we adopted the undersampling on the unbalanced classes of hate speech, specially due to the fact that this approach makes overfitting unlikely. Note that, in our dataset (the HateBR), there are 727 labeled hate speech samples versus 2,227 labeled non-hate speech samples. As a result of the undersampling approach, we obtained 727 labeled samples for hate speech and 727 samples for non-hate speech.

Evaluation
Our models were trained and tested using 10-fold cross-validation (Stone, 1974). We have computed the classical machine learning evaluation measures of Precision, Recall and F1-Score. We present these evaluative measures for each class involved, as well as simple arithmetic means. The results are shown in Table 5. Moreover, we evaluated BERT and fastText pre-trained models, and show the obtained results in Table 6.
We also present the evaluation of the methods with feature selection (FS). We measure the gain and loss of precision, recall, and f1-score for each selected algorithm (CFS and InfoGain) in both tasks: offensive language detection and hate speech detection, as well as for each representations: POS+S, BOW, MOL and B+M. Table  7 shows the results. We should point out that T1 is the sum of each representation, and T2 is the sum for each FS algorithm.
Finally, Table 8 shows the comparison of the results with the current baseline methods for Portuguese.

Results
As shown in Table 5, the B+M proposed method in this paper obtained better results of precision, recall, and f1-score in both tasks -offensive language and hate speech detection. The worse results were obtained using the POS+S approach, which combines part-of-speech and sentiment lexicon features. We should point out the considerable impact of an offensive lexicon for abusive language detection, when compared to the impact of a sentiment lexicon. Our results showed that sentiment lexicon approach present weak performance for abusive language detection on the web and social media.
Moving forward, the conducted experiments also show that the traditional machine learning techniques presented better performance than neural-based classifiers for offensive language tasks. Nevertheless, for the hate speech detection task, the neural-based classifier overcame the traditional machine learning methods.
In general, BERT and fastText, as shown in Table 6, presented a high performance for both tasks (offensive language and hate speech detection), even though our approach (B+M) has overcome the fastText (trigrams) in 2% (f1-score) for hate speech detection, as well as presented better precision performance, and the same recall and f1-score performances for offensive language detection.
Considering the feature selection (FS) performance, as shown in Table 7, the InfoGain algorithm produced better results for precision, recall, and f1-score than CFS algorithm for offensive language detection (task 1). On other hand, for hate speech detection (task 2), CFS algorithm obtained better performance than InfoGain in recall and f1-score. Moreover, for offensive language de-    Table 8 shows a comparison of results between our new proposed method and baseline methods for Portuguese. Although a direct comparison is unfair (as the authors use different datasets), it offers an idea of the general performance of the methods.

Comparing Results
de Pelle and Moreira (2017) report a f1-score of 81% using SVM and NB algorithms. For the same algorithms, our approach presented 88% of f1-score, improving the performance. In the same settings, Fortuna et al. (2019) report a f1-score of 78% using the LSTM algorithm. In our experiments, we obtained an f1-score of 86%, also using the LSTM algorithm, consequently, our approach presented better performance.

Conclusions
In this work, we provide a new approach for the automatic detection of abusive comments on social media. Our approach embodies an offensive lexicon that provides contextual information. Due to the increase of abusive comments on social media in Brazil, as well as the lack of research in Portuguese, we decided to use an Brazilian annotated dataset to evaluate the models. The proposed approach obtains high performances: 88% f1-score for offensive comments detection, and 85% for comments with hate speech, which overcame the current baseline methods for Portuguese. We also evaluated the performance of feature selection (FS) methods, and conclude that InfoGain algorithm is the best algorithm for the offensive comment detection task, considering the obtained gains in recall and f1-score. For the hate speech detection task, CFS algorithm obtained better performance. Accordingly, based on the obtained results, we concluded that the proposed approach in this paper for automated detection of abusive comments is efficient and highly relevant, bearing in mind the current Brazilian social scenario, in which hateful comments are a very relevant social problem. Moreover, in the next year (2022), there will be presidential elections in Brazil, and this paper may provide a reliable automated approach for abusive comments detection in order to minimize political polarization, as well as hate crimes on social media.