SlowGuess/NAACL_2022_OCR huggingface dataset:
Souvic Chakraborty\*, Parag Dutta\*\#, Sumegh Roychowdhury\*, Animesh Mukherjee
#Indian Institute of Science (IISc), Bangalore, KA, IN - 560012
parag Dutta@iisc.ac.in
$^{\dagger}$ Indian Institute of Technology (IIT), Kharagpur, WB, IN - 721302
{chakra.souvic,sumeghtech,animeshm}@gmail.com
The last decade has witnessed a surge in the interaction of people through social networking platforms. While there are several positive aspects of these social platforms, their proliferation has led them to become the breeding ground for cyber-bullying and hate speech. Recent advances in NLP have often been used to mitigate the spread of such hateful content. Since the task of hate speech detection is usually applicable in the context of social networks, we introduce CRUSH, a framework for hate speech detection using User Anchored self-supervision and contextual regularization. Our proposed approach secures  $\approx 1 - 12\%$  improvement in test set metrics over best performing previous approaches on two types of tasks and multiple popular English language social networking datasets.
Note: This paper contains materials that may be offensive or upsetting to some people.
Today, the world is more connected than ever in the history of mankind. This can primarily be attributed to: (i) the technological advancements that have made affordable internet connections and devices available to people, and (ii) the social networking platforms that have hosted and connected these people. As a result, even people divided by geography can seamlessly interact in real-time without stepping outside their homes. In fact, social networks are an integral part of today's society.
We, however, are more concerned about the pitfalls of this global widespread use of social networks. The unprecedented and rapid explosion in social networking and social media use has left many people — particularly the youth, women, and those from ethnic and religious minority groups — vulnerable to the negative aspects of the online world like sexual harassment, fake news and hate
Figure 1: [Best viewed in color] Hateful content tend to cluster together in common threads and usually come from few hateful users in social media. We stress on this informed assumption to learn better representations using self supervision and contextual regularization. In the sub-graph shown in the pic, the textual content is in the form of posts, comments on the posts (optional), and replies to the comments (optional).  $n_u$  is the total number of users in the network (dynamic), and each of the text sequences can be attributed to one of the users.
speech (Jakubowicz, 2017). The number of toxic users dumping their radically biased views and polarising content onto these networks have Burgeoned to such a level that they are causing political discord and communal disharmony. Therefore such posts must be intervened upon and filtered before they have the intended effect on the mass. With a huge number of posts on many popular social networking websites every second, manual filtering for hate speech does not scale. Hence, automating hate speech detection has been the primary focus of many researchers in recent years, both in academia and industry alike.
Figure 1 depicts and describes a sub-graph of a typical social network. It is essential to leverage this structure within social networks for infusing
<sup>1</sup>Work done while at IIT Kharagpur.
Findings of the Association for Computational Linguistics: NAACL 2022, pages 1874 - 1886
network context while identifying hate speech. We investigate and notice that the social graph context can be disentangled into two components: (i) Post context: the context in the neighborhood around the text sequence, i.e., the sub-graph consisting of posts, comments, and replies (see Figure 1) and (ii) User context: the context from all the existing text sequences in the network that originated from the same user (see, for instance, the connections emanating from users 1, 2,  $n_u$  etc. in the Figure 1). Relying on the echo-chamber effect, we accordingly propose a framework that uses self supervision from unlabelled data harnessed from the social networks (Gab & Reddit in our case), so that we can use contextual information (user & post context) to generate better representations from input sentences for hate speech related tasks. The main contributions of this paper are:
(i) First, we propose UA (User Anchored self-supervision), a self-supervised contrastive pre-training objective. Essentially we try to incorporate the mapping from text sequences to users into the language model. In addition, we provide a Robust UA strategy that incorporates the hate speech downstream task information into our proposed UA pre-training approach.
(ii) Next, we propose CR (Contextual Regularization), a regularization strategy based on the findings of Mathew et al. (2020). Here we introduce a loss based on the informed assumption that the neighboring comments and replies (in the social graph) of a hateful comment is more likely to be hateful than the comments/replies in the vicinity of a nonhateful comment. It helps us to regularize the supervised learning paradigm by learning better representations of text sequences in social network context.
(iii) We experiment with two types of hate speech tasks - classification and scoring - across three datasets. We show that our approach secures  $\approx 1 - 4\%$  improvement in F1-scores (for classification tasks) and  $\approx 12\%$  improvement in mean absolute error (for scoring task) when compared to best competing baselines.
To the best of our knowledge, we are the first to use text sequence based self-supervision in hate speech using user characteristics. One of the key technical contribution that this paper makes is to show that it is more advantageous to use context to regularize
a classification model than directly infusing the context into the model. Also, none of our proposed approaches require any additional annotation effort or introduce any extra parameter into the training pipeline, and are therefore scalable.
Hate speech is heavily reliant on linguistic complexity. Waseem (2016) showed that classification consensus is rare for certain text sequences even among human annotators. Automatic detection of hate speech is further strongly tied to the developments in machine learning based methods.
Until recently, feature engineering was one of the popularly used techniques. Gitari et al. (2015) designed several sentiment features and Del Vigna et al. (2017) used the sentimental value of words as the main feature to measure the hate constituted within a text sequence. Empirical evidence was provided by Malmasi and Zampieri (2017) indicating that n-gram features and sentiment features can be successfully applied to detect hate speech. Rodriguez et al. (2019) constructed a dataset of hate speech from Facebook, and consequently proposed a rich set of sentiment features, including negative sentiment words and negative sentiment symbols, for detecting hateful text sequences. As witnessed by the above works, it was widely believed that sentiment played an important role in detecting underlying hate.
More recently, deep learning based methods (Badjatiya et al., 2017) have garnered considerable success in detecting hate speech since they can extract the latent semantic features of text and provide the most direct cues for detecting hate speech. Zhang et al. (2018) developed a CNN+GRU based model to learn higher-level features. (Kshirsagar et al., 2018) passed pre-trained word embeddings through a fully connected layer, which achieved better performance than contemporary approaches despite its simplicity. Tekiroglu et al. (2020) constructed a large-scale dataset for hate speech and its responses and used the pre-trained language models (LM) for detection. These methods demonstrated the considerable advantages of interpreting words in the context of given sentences over static sentiment based methods.
Self-supervision and auxiliary supervision have also been explored for hate speech detection. HateBERT (Caselli et al., 2021) used the Masked Language Modelling (MLM) objective to learn con
textual hate semantics within text sequences from individual Reddit posts. HateXplain (Mathew et al., 2021) used human annotators to obtain rationale about the text containing hate speech and then applied the same for improving their language model. Researchers have previously tried context infusion in the inputs (Menini et al., 2021; Vidgen et al., 2021; Pavlopoulos et al., 2020). Del Tredici et al. (2019) showed that user context helps in downstream tasks. On the other hand, Menini et al. (2021) and Vidgen et al. (2021) show that contextual classification is harder given contextual annotations. A similar theme recurs when Pavlopoulos et al. (2020) shows that context infusion does not easily increase the performance of classifiers in context of toxicity detection in text. Alternatively instead of using context directly as input we use it as a regularizer to improve the classifier by learning better contextual representations while training. During inference, we use only the post text, thus adding no computation overhead.
We find that using self-supervision for hate speech detection systems leveraging the associated context within a social network is heavily underexplored. s demonstrated by Mathew et al. (2020), learning in a broader socio-personal context of the users and contemporary social situations is also very important. The authors showed the clustering tendency of hateful text sequences on specific hateful user timelines and after specific events (temporal clustering). However, to the best of our knowledge, no prior work in hate speech detection has explored self-supervision in these directions using the context information.
3 Proposed approaches
Assumptions about invariance(s) are required in all self-supervised learning objectives. We make the following two assumptions articulated below.
(i) In the masked language modeling (MLM) objective, the invariant is that the conditional probability distribution of the vocabulary tokens (or words) for each masked token can be reasonably estimated given the context (in the form of tokens) around the masked token.
(ii) In the User Anchored self-supervision (UA) objective, we assume that the users' writing style and bias (specifically cultural and in-group bias) are invariant (Hughes et al., 2012). Hence, the inverse mapping of a post to the corresponding user should be estimable sub
ject to the language understanding capability. We denote the model being trained for the downstream tasks as  $\mathcal{M}$ .  $\mathcal{M}$  has two modules: (a) an encoder for encoding the input sentences, and (b) a classifier or regressor for mapping the hidden representations generated by the encoder into one of  $\mathcal{K}$  classes and a single value respectively. For instance, the encoder in  $\mathcal{M}$  can be modeled by a transformer (Vaswani et al., 2017). See Figure 2 for block diagram of our proposed approaches.
3.1 Phase I: Incorporating hateful content into the language model through continual pre-training (CP)
We start with pre-trained language models and continue pre-training them by minimizing the standard MLM objective using text sequences (posts) accumulated from a variety of social network datasets. The procedure for domain adaptation in LMs can be found in Gururangan et al. (2020) and a procedure tailored for hateful words can be found in HateBERT. We use the text sequences available on Pushshift $^2$  in addition to RAL-E from HateBERT for pre-training our Hate-infused Language Model (HateLM).
3.2 Phase II: User Anchored self-supervision (UA)
Some users are more biased than others and hence are more prone to post toxic content (Mathew et al., 2020). We employ a User Anchored self-supervision (UA) objective in the next pre-training phase to compare the users' writing style. Hence, given an LM is capable of language understanding, it should also be able to distinguish between users' writing styles from their posts with high probability, when the pool of posts from various users is not very large.
Here we use a self-supervised method based on contrastive pre-training with negative samples to efficiently incorporate UA into an LM. This negative sampling makes the approach highly scalable<sup>3</sup>.
For the text sequence  $S$  corresponding to the  $i^{\mathrm{th}}$  sampled post and user  $u_{0}$ , we try to decrease some distance metric between representation of  $S$  and another sentence by  $u_{0}$  among the  $n_u$  available users while increasing the distance metric with sentences authored by other users in a contrastive fashion.
$^{2}$ https://files.pushshift.io/gab
3Owing to the extremely large number of users in a platform and the dynamic nature of the graph, it is infeasible to simply add a user classification network after the encoder
(c)
Figure 2: [Best viewed in color] An illustration of the various phases of training and inference for the classification task. The regression task will have a similar structure except for a regressor head instead of a classifier head in  $(c)$  and  $(d)$ . The blue arrows indicate the forward pass, and the orange arrows indicate the backward pass.  $(a)$  corresponds to Phase I, i.e. continual pre-training using self-supervised MLM objective on hateful sequences to incorporate contextual hate understanding.  $(b)$  corresponds to Phase II, i.e. the User Anchored self-supervised learning objective, it depicts the scalable contrastive objective model that does not add any additional parameters.  $(c)$  corresponds to Phase III, i.e. our contextual regularization procedure where we add post and user context. And finally  $(d)$  shows the inference phase which does not require any additional context.
Next, we sample  $k << n_u$  number of users uniformly at random, without repetition, from among the list of all users in the social network. Adding  $u_0$  along with the  $k$  sampled users in a set, we get:
$$
U _ {i} = \left\{u _ {i 0}, u _ {i 1}, \dots , u _ {i k} \mid \forall_ {j _ {1}, j _ {2} \in \{0,.., k \}} u _ {i j _ {1}} \neq u _ {i j _ {2}} \right\} \tag {1}
$$
The set of posts  $P_{i}$  made by users in  $U_{i}$ .
$$
P _ {i} = \left\{p _ {i 0}, p _ {i 1}, \dots , p _ {i k} \mid p _ {i 0} \neq \mathcal {S} \right\} \tag {2}
$$
$p_{i0}$  cannot be same as  $\mathcal{S}$  because our positive sample needs to be different from the original post. The remaining  $\forall_{j\in [k]}\{p_{ij}\}$  become negative samples.
For Phase II pre-training and updating the parameters  $\theta_{\mathcal{E}}$  of the encoder in  $\mathcal{M}$ , we start by sampling an anchor sequence  $a_i \equiv S$  from our dataset. We pass  $a_i$  through encoder in  $\mathcal{M}$  to obtain  $z_i$ .
$$
z _ {i} = \mathcal {F} _ {\theta_ {\varepsilon}} \left(a _ {i}\right) \tag {3}
$$
Next, we generate  $P_{i}$  by sampling as described above. We pass all of the  $p_{ij}$ 's  $\in P$  through our encoder as well, to get embeddings:
$$
Z _ {i} = \left\{z _ {i 0}, z _ {i 1}, \dots , z _ {i k} \right\} \tag {4}
$$
We use a self-supervised contrastive loss inspired from Khosla et al. (2020) and modify it for our purposes:
$$
\mathcal {L} _ {\mathrm {U A}} = \underset {i \sim \mathcal {U} ([ N ])} {\mathbb {E}} \left[ - l o g \left(\frac {\exp \left(z _ {i} \cdot z _ {i 0}\right)}{\sum_ {j \in [ k ]} \exp \left(z _ {i} \cdot z _ {i j}\right)}\right) \right] \tag {5}
$$
Here,  $\cdot$  represents the inner product and  $\mathcal{U}(.)$  represents discrete uniform distribution. Since there
are no additional models, only  $\theta_{\mathcal{E}}$  parameters need to be updated during backpropagation.
Robust UA: During training UA objective exhibits the problem of over-fitting. After a certain number of epochs, the information in the language model accumulated during the CP phase gets overshadowed by information obtained from the UA phase. In order to handle the problem, the model needs to be fine-tuned after every epoch. Since this is not feasible, we propose a method for a more robust training method aligned to our downstream task of hate speech classification. Since we already have the annotations in the target dataset, we add an auxiliary task to align the model parameter updates towards the downstream task rather than diverge as a consequence of over-fitting.
For an anchor sequence  $a_i \equiv S$  sampled from the training set, we get the original class label of the example and get a positive example  $p$  by sampling a new post from the training set belonging to the same class. Similarly, we sample two posts from each of the remaining classes in order to get a set of  $l = 2(n_c - 1)$  negative examples, where  $n_c$  is the number of classes in the downstream classification task. Hence similar to  $P_i$  in Equation 2, our auxiliary post set corresponding to the  $i^{\text{th}}$  sampled sequence is as follows:
$$
\bar {P} _ {i} = \left\{\bar {p} _ {i 0}, \bar {p} _ {i 1}, \dots , \bar {p} _ {i l} | \bar {p} _ {i 0} \neq \mathcal {S} \right\} \tag {6}
$$
Subsequently, we pass them through the encoder in  $\mathcal{M}$  and generate auxiliary embedding set:
$$
\bar {Z} _ {i} = \left\{\bar {z} _ {i 0}, \bar {z} _ {i 1}, \dots , \bar {z} _ {i l} \right\} \tag {7}
$$
Similar to the supervised contrastive loss described in Equation 5, we add the following auxiliary loss:
$$
\mathcal {L} _ {\mathrm {a u x}} = \underset {i \sim \mathcal {U} ([ N ])} {\mathbb {E}} \left[ - l o g \left(\frac {\exp \left(z _ {i} \cdot \bar {z} _ {i 0}\right)}{\sum_ {j \in [ l ]} \exp \left(z _ {i} \cdot \bar {z} _ {i j}\right)}\right) \right] \tag {8}
$$
Here, it is the same  $i$  that was being sampled in Equation 5. Finally we take a convex combination of both the losses to get:
$$
\mathcal {L} _ {\text {R o b u s t U A}} = \lambda \mathcal {L} _ {\mathrm {U A}} + (1 - \lambda) \mathcal {L} _ {\text {a u x}} \tag {9}
$$
where,  $0 < \lambda < 1$  is a hyper-parameter.
Note: We do not have classes for a regression task. Therefore, we group the labels into  $\kappa$  clusters by using K-means clustering where  $\kappa$  is a hyperparameter. Then we use the associated cluster labels as a proxy for the class labels.
3.3 Phase III: Contextual Regularization (CR)
Our primary assumption in this approach is that: A post is influenced by its context. We demonstrate how to exploit the intuition "hate begets hate" (Mathew et al., 2020) to our advantage.
3.3.1 CR in classification
HateLM and UA, i.e., the methods described in section 3.1 and 3.2 (with the exception of Robust UA training) were self-supervised; hence, no information about the annotations available in the training set was used. After getting the pre-trained model in Phase II, we fine-tune using the annotations available for the dataset. We consider a pair of text sequence and its corresponding label  $\langle S, y \rangle$  sampled from the training set uniformly at random, where  $y \in [\mathcal{K}]$  denotes the true class label of the sampled sequence  $S$ . Usually, we would get the vector embedding  $z$  by passing  $S$  through the encoder. We would then have used the classifier in  $\mathcal{M}$  to get the vector  $v$  of  $\mathcal{K}$  dimensions as follows:
$$
v = \mathcal {F} _ {\mathcal {C}} (z; \theta_ {\mathcal {C}}) \tag {10}
$$
where  $\theta_{\mathcal{C}}$  parameterizes the classifier in  $\mathcal{M}$ . According to the model, the probability of the sample belonging to  $j^{\mathrm{th}}$  class among  $\mathcal{K}$  classes would be as follows:
$$
\mathbb {P} [ \text {c l a s s} (\mathcal {S}) = j ] = \frac {\exp (v _ {j})}{\sum_ {k \in [ \mathcal {K} ]} \exp (v _ {k})} \tag {11}
$$
and the most likely class assignment would be
$$
\hat {\mathbf {y}} = \underset {j \in [ \mathcal {K} ]} {\arg \max } \mathbb {P} [ \text {c l a s s} (\mathcal {S}) = j ] \tag {12}
$$
The cross-entropy loss would be calculated as:
$$
L _ {\mathrm {C E}} = \underset {i \sim \mathcal {U} ([ N ])} {\mathbb {E}} [ - \log \mathbb {P} [ \text {c l a s s} (\mathcal {S}) = \mathrm {y} ] ] \tag {13}
$$
We propose an additional method for regularization of the model using the contextual information during fine-tuning. For the given  $S$  we sample at most  $n_a$  posts from the same thread (all comments-reply concerning the parent post) where the comment is posted (post context) and at most  $n_b$  more posts from the timeline of the user who posted  $S$  (user context). Both post and user context is sampled without replacement. So, we generate a context set  $C$  of  $S$  for the  $i^{\mathrm{th}}$  text sequence sampled from the dataset:
$$
C _ {i} = \left\{c _ {i 1}, \dots , c _ {i n _ {a}}, c _ {i \left(n _ {a} + 1\right)}, \dots , c _ {i \left(n _ {a} + n _ {b}\right)} \right\} \tag {14}
$$
We then generate the vector  $v$  using  $S$  as mentioned in Equation 10. Next we generate  $V_{i}$  from  $C_i$ :
$$
V _ {i} = \left\{v _ {i 1}, \dots , v _ {i m} | \forall_ {j \in [ m ]} v _ {i j} = \mathcal {M} \left(c _ {i j}\right) \right\} \tag {15}
$$
where  $m = n_{a} + n_{b}$  and,  $\mathcal{M}(.)\equiv \mathcal{F}_{\theta \mathcal{C}}(\mathcal{F}_{\theta \mathcal{E}}(.))$  Our contextual loss from  $V_{i}$  is as follows:
$$
\mathcal {L} _ {C C E, i} = \frac {- 1}{m} \sum_ {j \in [ m ]} \log \left(\frac {\exp (v _ {i j t})}{\sum_ {k \in [ \mathcal {K} ]} \exp (v _ {i j k})}\right) \tag {16}
$$
where  $t$  is the true class of the original labelled post. Therefore the auxiliary contextual cross-entropy loss is calculated as:
$$
\mathcal {L} _ {\mathrm {C C E}} = \underset {i \sim \mathcal {U} ([ N ])} {\mathbb {E}} \left[ \mathcal {L} _ {C C E, i} \right] \tag {17}
$$
Our final contextual regularization loss function is a linear combination of the losses mentioned in Equation 13 and 17 as described below:
$$
\mathcal {L} _ {\text {C o n t e x t u a l}} ^ {\text {c l a s s i f i c a t i o n}} = \lambda \mathcal {L} _ {\mathrm {C E}} + (1 - \lambda) \mathcal {L} _ {\mathrm {C C E}} \tag {18}
$$
Back-propagating this loss we update the parameters  $\theta_{\mathcal{C}}$  and  $\theta_{\mathcal{E}}$ , corresponding to the classifier and the encoder in  $\mathcal{M}$  respectively, as one might have done normally.
3.3.2 CR in regression
The regression task is almost similar to classification as mentioned in section 3.3.1 with the exception that the  $y \in \mathbb{R}$  in the tuple  $\langle S, y \rangle$  sampled from the training set, and the output of the model  $\mathcal{M}$  being a real value  $r$  rather than a vector  $v$  of  $\mathcal{K}$  dimensions. Since we use a regressor, Equation 10 changes to
$$
r = \mathcal {F} _ {\mathcal {R}} (z; \theta_ {\mathcal {R}}) \tag {19}
$$
where  $\theta_{\mathcal{R}}$  parameterizes the regressor in  $\mathcal{M}$ .
The cross-entropy loss in Equation 13 becomes
Dataset	Annotated samples	Total users	Labels	Max context sampled (per user)
HateXplain	10,000	3,300	Hate speech, Offensive, Normal	100
LTI-GAB	30,500	4,900	Toxic and Non-Toxic	50
Ruddit	6,000	4,200	Regression (-1 to +1)	20
Table 1: Dataset statistics for the datasets we used for performing the experiments along with the additional unsupervised data we collected. All datasets are in the English language.
squared loss as follows:
$$
L _ {\mathrm {M S E}} = \underset {i \sim \mathcal {U} ([ N ])} {\mathbb {E}} \left[ \left(\mathbf {y} _ {i} - r _ {i}\right) ^ {2} \right] \tag {20}
$$
where  $\mathbf{y}_i$  is the label associated with the  $i$ th example sampled from the training dataset,  $r_i$  is the predicted value by model  $\mathcal{M}$ .
The techniques for selection of the context discussed in section 3.3.1 remain unaltered since our post and user context is unsupervised. However, the set of vectors  $V_{i}$  becomes a set of real values  $R_{i}$  generated as follows:
$$
R _ {i} = \left\{r _ {i 1}, \dots , r _ {i m} \mid \forall_ {j \in [ m ]} r _ {i j} = \mathcal {M} \left(c _ {i j}\right) \right\} \tag {21}
$$
And our auxiliary contextual mean squared loss is calculated as the follows:
$$
\mathcal {L} _ {C M S E} = \underset {i \sim \mathcal {U} ([ N ])} {\mathbb {E}} \left[ \frac {- 1}{m} \sum_ {j \in [ m ]} \left(\mathrm {y} _ {i} - r _ {i j}\right) ^ {2} \right] \tag {22}
$$