SlowGuess/NAACL_2021_OCR huggingface dataset:
Jing Qian†, Hong Wang†, Mai ElSherief*, Xifeng Yan†
† University of California, Santa Barbara
* Georgia Institute of Technology
{jing_qian,hongwang600,xyan}@cs.ucsb.edu
mai.h.sherief@gmail.com
Existing work on automated hate speech classification assumes that the dataset is fixed and the classes are pre-defined. However, the amount of data in social media increases every day, and the hot topics changes rapidly, requiring the classifiers to be able to continuously adapt to new data without forgetting the previously learned knowledge. This ability, referred to as lifelong learning, is crucial for the real-word application of hate speech classifiers in social media. In this work, we propose lifelong learning of hate speech classification on social media. To alleviate catastrophic forgetting, we propose to use Variational Representation Learning (VRL) along with a memory module based on LB-SOINN (Load-Balancing Self-Organizing Incremental Neural Network). Experimentally, we show that combining variational representation learning and the LB-SOINN memory module achieves better performance than the commonly-used lifelong learning techniques.
With the rapid rise in user-generated web content, the scale and complexity of online hate have reached unprecedented levels in recent years. ADL (Anti-Defamation League) conducted a nationally representative survey of Americans in December 2018 and the report shows that over half  $(53\%)$  of Americans experienced some type of online harassment. $^{1}$  This number is higher than the  $41\%$  reported to a comparable question asked in 2017 by the Pew Research Center (Center, 2017). To address the growing online hate, a great deal of research has focused on automatic hate speech classification. Most of the previous work focuses on binary classification (Warner and Hirschberg, 2012; Zhong et al., 2016; Nobata et al., 2016; Gao et al., 2017; Qian et al., 2018b) or coarse-grained multi
Figure 1: An illustration of our proposed task.  $h g_{i}$ : the  $i$ th hate group. The model is trained on a sequence of sub-datasets, split by their hate ideologies, e.g., anti-Muslim and Kuklux Klan. The task on each sub-dataset is to identify the hate group given the tweet.
class classification (Waseem and Hovy, 2016; Badjatiya et al., 2017; Davidson et al., 2017). Qian et al. (2018a) argue that fine-grained classification is necessary for fine-grained hate speech analysis. The Southern Poverty Law Center (SPLC) monitors hate groups throughout the United States by a variety of methodologies to determine the activities of groups and individuals, including reviewing hate group publications. Therefore, instead of differentiating normal posts from the other offensive ones, Qian et al. (2018a) propose a more fine-grained hate speech classification task that attributes hate groups to individual tweets. However, a common limitation of all the research mentioned above is that they assume the dataset to be static and train the classifiers on each isolated dataset, i.e., isolate learning, ignoring the rapid increase of the amount of data in social media and the rapid change of the hot topic.
A report from L1ght, a company that specializes in measuring online toxicity, suggests that
$^{2}$ https://www.splcenter.org/fighting-hate/extremist-files/ideology
<sup>3</sup>https://l1ght.com/Toxicity_during-coronavirus_Report-L1ght.pdf
<sup>1</sup>https://www.adl.org/onlineharassment
Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pages 2304-2314 June 6-11, 2021. ©2021 Association for Computational Linguistics
amid the growing threat of the coronavirus, there has been a  $900\%$  growth in hate speech towards China and Chinese people on Twitter since February 2020. As a result of the rapid change of social media content, the hate speech classifiers are required to be able to continuously learn and accumulate knowledge from a stream of data, i.e., lifelong learning. Learning on each portion of the data is considered as a task, so a stream of tasks are joined to be trained sequentially. In this work, we propose a novel lifelong fine-grained hate speech classification task, as illustrated in Figure 1. The models trained by isolate learning tend to face catastrophic forgetting (McCloskey and Cohen, 1989; Ratcliff, 1990; McClelland et al., 1995; French, 1999) due to a non-stationary data distribution in lifelong learning. To address this problem, an extensive body of work has been proposed for various lifelong learning tasks. However, our experiments show that the commonly-used lifelong learning methods still exhibit catastrophic forgetting in our proposed tasks. One important difference between the Twitter hate group dataset and the other image datasets commonly used in lifelong learning study is that the similarity among the different tasks is unstable and relatively low, as indicated by the low average Jaccard Indexes of the topic words in Table 1. To alleviate this problem, we introduce VRL to distill the knowledge from each task into a latent variable distribution. We also augment the model with a memory module and adapt the clustering algorithm, LB-SOINN, to select the most important samples from the training dataset of each task.
- This is the first paper on lifelong learning of fine-grained hate speech classification.
- We propose a novel method that utilizes VRL along with an LB-SOINN memory module to alleviate catastrophic forgetting resulted from a severe change of data distribution.
- Experimental results show that our proposed method outperforms the state-of-the-art significantly on the average F1 scores.
Most research on lifelong learning alleviates catastrophic forgetting in the following three directions. Regularization-based Methods: These methods impose constraints on the weight update. The goal
Ideology	Avg. JI	Keywords
Christian Identity	0.019	Jesus, Yahuwshua
Radical Tr. Catholic	0.031	catholic, remnant
Neo Confederate	0.039	southern, Free Dixie
Anti-Semitism	0.047	Israel, Trump
Anti Catholic	0.049	Texe Marrs, truth
Hate Music	0.049	death, radio
Anti Muslim	0.064	Muslim, Islam
Black Separatist	0.071	black, panther
Racist Skinhead	0.074	shirt, white
Anti Immigration	0.075	immigration, border
Holocaust Identity	0.078	Jewish, Trump
Neo Nazi	0.091	Hitler, white
Kuklux Klan	0.100	ni**a, f**king
Anti LGBTQ	0.100	family, marriage
White Nationalist	0.105	white, America
Table 1: Information about the 15 hate ideologies. Tr.: Traditional. Avg JI: the average of the Jaccard Index between the topic words of one ideology and those of another ideology. The topic words are extracted by Latent Dirichlet Allocation (LDA) (Blei et al., 2003). The top 2 most frequent topic words are selected as keywords.
of the constraints is to minimize deviation from trained weights when training on a new task. The constraints are generally modeled by additional regularization terms (Kirkpatrick et al., 2017; Zenke et al., 2017; Fernando et al., 2017; Liu et al., 2018; Ritter et al., 2018). Elastic Weight Consolidation (EWC) (Kirkpatrick et al., 2017) alleviates catastrophic forgetting by slowing down learning on the model parameters which are important to the previous task. The importance of the parameters is estimated by the Fisher information matrix. Instead of the Fisher information matrix, PathNet (Fernando et al., 2017) uses agents embedded in the neural network to determine which parameters of the neural network can be reused for new tasks and the task-relevant pathways are frozen during training on new tasks.
Architecture-based Methods: The main idea of this approach is to change architectural properties to dynamically accommodating new tasks, such as assigning a dedicated capacity inside a model for each task. Rusu et al. (2016) propose Progressive Neural Networks, where the model architecture is expanded by allocating a new column of neural network for each new task. Part and Lemon (2016, 2017) combine Convolutional Neural Network with LB-SOINN for incremental online learning of object classes. Although they also use LB-SOINN in their work, the usage of LB-SOINN in this work is completely different. They use LB-SOINN to predict object class while our proposed method adapts the original LB-SOINN to calculate the importance
of the training samples without making any prediction on the class. A problem with the methods in this category is that the available computational resources are limited in practice. As a result, the model expansion will be prohibited when the number of tasks increases to a certain degree.
Data-based Methods: These methods alleviate catastrophic forgetting by utilizing a memory module, which either stores a small number of real samples from previous tasks or distills knowledge from previous tasks. The main feature of Gradient Episodic Memory (GEM) (Lopez-Paz and Ranzato, 2017) is the episodic memory, storing a subset of the samples from the observed tasks. GEM computes the losses on the episodic memories and treats them as inequality constraints, avoiding them to increase. Averaged GEM (Chaudhry et al., 2019) is a more efficient version of GEM. de Masson d'Autume et al. (2019) propose a lifelong language learning model using a key-value memory module for sparse experience replay and local adaptation. Sun et al. (2020) formulate lifelong language learning as a language modeling task and replay the generated pseudo-samples of previous tasks during training.
There are also studies combining multiples methods above. Xia et al. (2017) combine the architecture-based method and the data-based method. Wang et al. (2019) combine the regularization method and the data-based method for lifelong learning on relation extraction. Our proposed method is also a combination of the regularization method and the data-based method but in a different way.
We use the dataset as in Qian et al. (2018a), where the tweet handles are collected based on the hate groups identified by SPLC. SPLC categorizes these hate groups according to their hate ideologies. For each hate ideology, the top three Twitter handles are selected in terms of the number of followers. The dataset includes all the content (tweets, retweets, and replies) posted with each Twitter account from the group's inception date, as early as 2009, until 2017. Altogether, the dataset consists of 42 hate groups from 15 different ideologies. Table 1 shows the 15 ideologies. Each instance in the dataset is a text tuple of (tweet, hate group name, hate ideology).
We separate the dataset by ideology. The rea
son is that various existing hate speech datasets collect data using keywords or hashtags (Waseem and Hovy, 2016; Davidson et al., 2017; Golbeck et al., 2017), which have a strong relationship with hate ideologies or topics. We also observe that the hot spots of society can lead to a significant shift of major hate speech topics or the emergence of new hate ideologies on social media as mentioned in section 1, indicating that the expansion of the hate speech dataset may be accompanied by the emergence of new hate ideologies.
Therefore, we separate the collected data into a sequence of 15 subsets according to their ideologies and sort them by the date of the first tweet post in each subset, from the earliest to the latest. The task on each subset is to identify the hate group given the tweet text. Qian et al. (2018a) propose a hierarchical Conditional Variational Autoencoder model for the fine-grained hate speech classification task. The architecture and the training process of their model require the number of classes to be pre-defined. However, we do not pre-define the number of classes in our task since such kind of information is not available in the real-world application of lifelong learning. The model should be able to incorporate emerging hate groups at any time of training. In order to satisfy this condition, we formulate the task of identifying the group as a ranking task, instead of a classification task. For each tweet, we provide the model with a set of candidate groups, consisting of all the previously seen hate groups, including the ground truth group. The model takes each combination of the tweet and the candidate group as input and outputs a score. The corresponding loss function is:
$$
\mathcal {L} _ {r} = \sum_ {(x, y _ {s}) \in D} \sum_ {y _ {i} \in Y \backslash \{y _ {s} \}} h \left(f _ {\theta} (x, y _ {s}) - f _ {\theta} (x, y _ {i})\right) \tag {1}
$$
where  $x$  is the tweet text,  $y_{s}$  is the ground truth group of  $x$ .  $Y$  is candidate group set of  $x$ , which consists of all the seen hate groups until  $x$  is observed by the model, including the ground truth group  $y_{s}$  of  $x$ , so  $y_{i} \in Y \setminus \{y_{s}\}$  is the negative candidate group of  $x$ .  $f_{\theta}$  is the scoring model parameterized by  $\theta$ .  $h(a) = \max (0,m - a)$ ,  $m$  is the chosen margin.
Same as in other lifelong learning studies, we consider learning on each of the hate ideologies in the sequence as a task, so we have a sequence of 15 tasks. As mentioned in section 1, the similarity among our tasks is unstable and relatively low.
Therefore, when the model is continuously trained on the tasks, it may encounter a sudden change of vocabulary, topic, and input data distribution. This makes our tasks more challenging compared to the other lifelong learning tasks because the abrupt change can make the catastrophic forgetting problem more severe. This is also the reason that some techniques achieving significant improvement in the image classification tasks do not perform well on our task (see section 5).
As mentioned in section 2, one way to alleviate catastrophic forgetting is to use a memory module, storing a small number of real samples from previous tasks and a simple way to utilize the memorized samples is to replay the memory when training on a new task, such as mixing them with the training samples from the current task. The idea behind this approach is that the memorized samples should reflect the data distribution so that the replay of the memory can help the model make invariant predictions on the samples of the previous tasks. However, this approach may not work well when the size of the memory is small. The reason is that when there is only a small amount of data memorized, the memory is not able to reflect the data distribution of the previous task and thus the model can easily overfit on the memorized samples instead of generalizing to all the samples in the previous task.
We address this problem from two aspects. First, since the memory size is limited, it is beneficial to select the most representative training samples in the previous tasks to memorize. Second, simply storing the real training samples in the memory may not be sufficient to represent the knowledge of the previous tasks, so we need a better way to distill knowledge from the observed samples along with a method to utilize it when training on a new task. We combine two techniques: Variational Representation Learning (VRL) and Load-Balancing Self-Organizing Incremental Neural Network (LB-SOINN) to achieve these goals. We propose a supervised version of LB-SOINN to select the most important training samples in the current task. VRL not only distills the knowledge from the current training task but also provides an appropriate hidden representation as input for the LB-SOINN, so we introduce VRL first.
4.1 Variational Representation Learning
The distilled knowledge of previous tasks can take various forms, but the key point is that it should be related to the data distribution of the corresponding task so that it can be utilized to alleviate catastrophic forgetting. Inspired by the Variational Autoencoder (VAE) (Kingma and Welling, 2013), we consider the distribution of the hidden representation of the input data as the distilled knowledge.
The original VAE model is proposed for data generation, so the objective of the original VAE is:
$$
O b j = \sum_ {x \in X} \log p (x) \tag {2}
$$
$$
p (x) = \int_ {z} p (x | z) p (z) d z \tag {3}
$$
$z$  is the latent variable, i.e., the hidden representation of the input. Since the integration over  $z$  is intractable, we instead try to maximize the corresponding evidence lower bound (ELBO) and the corresponding loss function is as follows:
$$
\mathcal {L} _ {v a e} = \sum_ {x \in X} E _ {z \sim p _ {\alpha} (z | x)} [ - \log p _ {\varphi} (x | z) ] + \tag {4}
$$
$$
D _ {K L} [ q _ {\alpha} (z | x) | | p _ {\beta} (z) ]
$$
$p(x|z)$ ,  $q(z|x)$ , and  $p(z)$  are the likelihood distribution, posterior distribution, and prior distribution.  $\alpha, \varphi$ , and  $\beta$  indicate parameterization. The loss function can be separated into two parts. The first part  $E[-\log p(x|z)]$  is the reconstruction loss, trying to reconstruct the input text from the latent variable. It pushes  $z$  to reserve as much information of the input as possible. This is consistent with our goal to learn the knowledge of the data distribution. The second part is  $D_{KL}[q(z|x)||p(z)]$ , where  $D_{KL}$  is the Kullback-Leibler (KL) divergence. Minimizing it pushes the posterior and the prior distributions to be close to each other. By assuming the posterior  $p(z|x)$  to be a multivariate Gaussian distribution  $\mathcal{N}(\mu_z, \Sigma_z)$ , the latent variable  $z$  is sampled from  $\mathcal{N}(\mu_z, \Sigma_z)$ .
In the original VAE,  $p(z)$  is chosen to be a simple Gaussian distribution  $\mathcal{N}(0,1)$ . However, this is over-simplified in our task because different from the unsupervised generation task of the original VAE, our ranking task is supervised. Our task not only requires  $z$  to contain information of the tweet text itself but also requires it to indicate the group information of the tweet. In other words, the distilled distribution should be conditioned on both the
Figure 2: An illustration of our method. The dotted arrows indicate the computation of the loss. The light-colored dashed arrows illustrate the update of the memory module. Note that the layers in the rounded rectangle share parameter weight. There is only one encoder for the group input, followed by two linear layers. We make a copy of it in the figure just for a clear illustration of loss computation.  $\hat{x}$ : the reconstructed tweet input.  $s_1$ ,  $s_2$ : scores of  $(x,y_s)$  and  $(x,y_i)$  separately.  $\mu_z^*$  and  $\Sigma_z^*$  are the previously memorized distribution on the latent variable of  $x$ .  $L_{rec}$  is the reconstruction loss, which is the first term in equation 4. Please refer to section 4 for the meaning of other variables in the figure.
tweet and its group label to reflect the data distribution in a supervised task. Setting the prior to be the same for all the hate groups pushes  $z$  or the distribution of  $z$  to ignore the label information. Instead, the prior should be different for each hate group, so we replace  $p(z)$  with  $p(u|y_s)$ , where  $y_s$  is the group label of  $x$  and  $u$  is the latent variable.  $p(u|y_s)$  is assumed to be a multivariate Gaussian distribution  $\mathcal{N}(\mu_u, \Sigma_u)$ . Note that the replacement itself can not guarantee  $p(u|y_s)$  to be different for each hate group because the loss function in equation 4 does not push  $p(u|y_s)$  to satisfy this condition. However, the ranking loss function 1 fills in the gap. Therefore, our loss function on the current training task is a combination of these two.
$$
\begin{array}{r l} \mathcal {L} _ {c u r} = & \sum_ {(x, y _ {s}) \in D} \sum_ {y _ {i} \in Y \backslash \{y _ {s} \}} h \left(f _ {\theta} (x, y _ {s}) - f _ {\theta} (x, y _ {i})\right) \\ & + E _ {z \sim p _ {\alpha} (z | x)} [ - \log p _ {\varphi} (x | z) ] \\ & + D _ {K L} \left[ q _ {\alpha} (z | x) \mid \mid p _ {\beta} (u | y _ {s}) \right] \end{array} \tag {5}
$$
The right part of Figure 2 illustrates the computation process of VRL.
4.2 LB-SOINN Memory Module
VRL provides a way to summarize knowledge into latent variable distributions. However, we still need a method to utilize the learned distribution to allevi
ate catastrophic forgetting. We do this by incorporating a memory module  $D_{mem}$  to store a small subset of important training samples along with their latent variable distributions, so each sample stored in the memory is a tuple of  $(x,y_z,q_{\alpha'}(z|x))$ . Here  $q_{\alpha'}(z|x)$  is the distribution computed when the model completes training on the task that  $(x,y_z)$  belongs to. The memorized samples are taken as anchor points when training on a new task. We introduce a memory KL divergence loss to push  $q_{\alpha}(z|x)$  computed when training on a new task to be close to the memorized distribution  $q_{\alpha'}(z|x)$ . Therefore, the complete loss function is:
$$
\begin{array}{l} \mathcal {L} = \mathcal {L} _ {c u r} + D _ {K L m e m} \\ = \mathcal {L} _ {c u r} + \sum_ {(x, y _ {s}) \in D _ {m e m}} D _ {K L} \left[ q _ {\alpha} (z | x) \right| \left| q _ {\alpha^ {\prime}} (z | x)\right) ] \tag {6} \\ \end{array}
$$
Since the size of the memory is limited, we introduce a supervised version of LB-SOINN to select the most important training samples in the current task. The input for the LB-SOINN is the hidden representation of the tweet text, which is  $z$  in the case of Variational Representation Learning (see Figure 2). We refer readers to Zhang et al. (2013) for the detailed explanation of LB-SOINN. The original LB-SOINN is an unsupervised clustering algorithm that clusters unlabeled data by topology
learning. We utilize the topology learning of LB-SOINN instead of clustering since our task is supervised. Therefore, we make the following adjustments to the original LB-SOINN.
1) The criteria to add a new node: Add a new node to the node set if one of the following conditions is satisfied: a) The distance between the input and the winner is larger than the winner's threshold. b) The distance between the input and the second winner is larger than the second winner's threshold. c) The label of the input sample is not the same as the label of the winner.
2) Build connections between nodes: Connect the two nodes with an edge only if the winner and the second winner belong to the same class.
3) We disable the removal of edges whose ages are greater than a predefined parameter. We disable the deleting of nodes and the algorithm of updating the subclass labels of every node. The node label is the label of the instances assigned to it. Our adjusted algorithm guarantees that each node will only be assigned the samples from one class.
LB-SOINN keeps track of the density of each node, which is defined as the mean accumulated points of a node. A node gets points when there is an input sample assigned to it. If the mean distance of the node from its neighbors is large, we give low points to the node. In contrast, if the mean distance of the node from its neighbors is small, we give high points to the node. Therefore, the density of the node reflects the number of nodes close to it and also the number of samples assigned to it. We take the density of the node as a measurement of the importance of the samples assigned to the node. After the LB-SOINN finishes training on the samples from the current task, we sort the samples according to the density of the node they are assigned to and the top  $K$  samples are selected to write to the memory. We divide the memory equally for each of the previous tasks, so  $K = M / t$ , where  $M$  is the total memory size and  $t$  is the number of observed tasks, including the current task. The old memory consists of samples from the previous  $t - 1$  tasks and each task keeps  $M / (t - 1)$  samples in the old memory. For each of the  $t - 1$  tasks, the  $M / (t - 1) - M / t$  samples with the lowest node densities are deleted, resulting in  $K$  empty slots in the memory, which is then rewritten by the selected  $K$  samples in the current task.
For each task, we randomly sample 5000 tweets from the  $80\%$  of the collected data for training,  $10\%$  of the collected data for testing, and the rest  $10\%$  for development. We allow the model to make more than one pass over the training samples in the current task or the current memory during training. We use average macro F1 score and average micro F1 score for evaluation.