{'fraction_non_alphanumeric': 0.034756588790424675, 'fraction_numerical': 0.015076533548164345, 'mean_word_length': 5.030187369882026, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Fight Fire with Fire: Fine-tuning Hate Detectors using Large Samples of Generated Hate Speech

Automatic hate speech detection is hampered by the scarcity of labeled datasetd, leading to poor generalization. We employ pretrained language models (LMs) to alleviate this data bottleneck. We utilize the GPT LM for generating large amounts of synthetic hate speech sequences from available labeled examples, and leverage the generated data in fine-tuning large pretrained LMs on hate detection. An empirical study using the models of BERT, RoBERTa and ALBERT, shows that this approach improves generalization significantly and consistently within and across data distributions. In fact, we find that generating relevant labeled hate speech sequences is preferable to using out-of-domain, and sometimes also within-domain, human-labeled examples.


Introduction
Hate speech refers to the expression of hateful or violent attitudes based on group affiliation such as race, nationality, religion, or sexual orientation. In light of the increasing prevalence of hate speech on social media, there is a pressing need to develop automatic methods that detect hate speech manifestation at scale (Fortuna and Nunes, 2018).
Automatic methods of hate speech detection typically take a supervised approach that heavily depends on labeled datasets. However, the difficulty of collecting hate speech samples often leads to biased data sampling techniques, focusing on a specific subset of hateful terms or accounts. Consequently, relevant available datasets are limited in size, highly imbalanced, and exhibit topical and lexical biases. Several recent works have indicated these shortcomings, and shown that classification models trained on those datasets merely memorize keywords, where this results in poor generalization (Wiegand et al., 2019;Kennedy et al., 2020).
In this work, we seek to improve hate speech generalization using large pretrained language models (LMs). We focus our attention on the transformerbased language encoder of BERT (Devlin et al., 2019) and its variants, all of which have been pretrained on massive heterogeneous corpora. In classification, the network parameters of the pretrained models are adapted to a target task using supervised training via a model finetuning procedure (Devlin et al., 2019). Due to the deep language representations encoded in these large LMs, they typically achieve improved performance in low-resource classification settings (Kennedy et al., 2020). Yet, large volumes of high-quality labeled examples must be provided to achieve high model generalization on the target task. In order to improve the performance of pretrained LM classifiers when labeled data is limited, it has been suggested to continue pretraining the models using unlabeled in-domain text, or expose the models to unlabeled task-related data (Gururangan et al., 2020). As hate speech is scarce and diverse, constructing a large and representative corpus of relevant texts is nontrivial, and attempts to continue pretraining BERT using some of the existing datasets have not yielded improvements so far (Isaksen and Gambäck, 2020).
In this work, we rather extend the available manually-curated hate speech datasets with large amounts of generated labeled examples. We employ synthetic text sequences generated using the LM of GPT2 (Radford et al., 2019), having it been biased to generate hate (and non-hate) speech using the human-labeled examples (Wullach et al., 2021). We then augment the existing gold-labeled datasets with large amounts of synthetic examples, increasing their size from tens to hundreds of thousands of labeled examples. In experiments using the LMs of BERT, RoBERTa (Liu et al., 2019) and ALBERT (Lan et al., 2020), we show substantial and consistent improvements using the synthetic data. Remarkably, we observe improved generalization in cross-dataset evaluation, sometimes even surpassing the respective within-dataset results, and show gains in comparison to out-of-domain authentic labeled examples. As of today, it is not common practice to incorporate mass amounts of synthetic data for finetuning LM classification models. Our findings therefore have implications for text classification in general, and hate detection in particular.

Related work
A recent related work (Anaby-Tavor et al., 2020) synthesized new examples from existing training data with the objective of improving multi-class classification. They finetuned GPT2 by prepending the class label to text samples, and used the finetuned model to generate new labeled sentences conditioned on the class label. A BERT classifier was then trained on both the existing and the synthesized data. While similar to our approach, they focused on balancing topical multi-class datasets, generating a small number of examples per class from a handful samples. Another work generated up to several thousands of examples per class with the goal of dataset balancing (Tepper et al., 2020) .
Previous attempts to augment hate speech datasets using synthetic examples similarly focused on remedying the class imbalance within those datasets as means for improving generalization. Rizos et al (2019) proposed several data augmentation techniques, including word swapping and replacement, and class-conditional recurrent neural language generation. They achieved limited performance gains. Cao and Lee (2020) proposed a GAN architecture to guide the generation of hateful texts, and showed average 5% improvement in terms of hate detection F1 using LSTM and CNN classifiers. They too focused on dataset balancing, using limited amounts of synthetic data.
In this work, we apply sequence generation at large scale, increasing the original dataset size by magnitudes of order. We previously observed that this data augmentation approach improves the performance of a CNN-based hate speech classifier (Wullach et al., 2021). Here, we apply pretrained LMs for extensive data synthesis, and then leverage this data in finetuning pretrained LM text classifiers. Performance-wise, classifiers based on pretrained LMs achieve favorable results in resource limited settings, and we show that largescale data generation and augmentation further boosts performance, significantly improving the generalization of hate speech detection.

Methods
We follow the approach by Wullach et al. (2021), comprised of the following steps. (i) Given a dataset d i that consists of hate and non-hate labeled examples {d i h , d i nh }, we generate additional classconditioned synthetic text sequences. We utilize GPT2, a LM that had been pretrained using mass amounts of Web text for this purpose. 1 In order to bias the model towards the genre of micro-posts, hate speech, and the topics and terms that characterise each dataset, we continue training GPT2 from its distribution checkpoint, serving it with the labeled text sequences. Concretely, we adapt distinct GPT2 models per dataset and class, i.e., for each dataset d i , we obtain two models, G i h and G i nh . (ii) In text synthesis, we provide no prompt to the respective GPT2 model, that is, the token sequences are generated unconditionally, starting from the empty string. Similar to the labeled datasets, we generate sequences that are relatively short, up to 30 tokens. (iii) Presumably, not all of the text sequences generated by G i h are hateful. We utilize the labeled examples d i for finetuning a BERT classifier on hate detection, and apply the resulting classifier to the sequences generated by G i h . We then only maintain those sequences that are perceived as hateful by the model, setting a threshold over the classifier confidence scores. In our experiments, following manual tuning, we set the threshold to 0.7, discarding about two thirds of the generated hate speech sequences. Finally, we augment the labeled examples d i with an equal number of hate and non-hate synthetic examples. Additional technical details are given in the appendix.
pretrained LMs We consider the popular transformer-based model of BERT, that has been pretrained on the texts of books and English Wikipedia. We also experiment with RoBERTa, that has been trained on ten times more data, including news articles and Web content. Due to this augmentation of training data, and other modifications to the pretraining procedure and cost function, RoBERTa has been shown to outperform BERT on multiple benchmark datasets (Liu et al., 2019). We apply the base configurations of BERT and RoBERTa, which both include 110 million parameters. We also consider the model of ALBERT, a light architecture of BERT with fewer parameters due to factorized embeddings and cross-layer pa-Dataset Size [K] Hate ratio DV (Davidson et al., 2017) 6 0.24 FT (Founta et al., 2018) 53 0.11 WS (Waseem and Hovy, 2016) 13 0.15 SF (StormFront) (de Gibert et al., 2018) 9.6 0.11 SE (SemEval) (Basile et al., 2019) 10 0.40 Table 1: The experimental hate speech datasets rameter sharing. ALBERT has been pretrained using similar data to RoBERTa, and further introduced inter-sentence coherence as optimization goal (Lan et al., 2020). 2 In all cases, we follow the standard practice of passing the final layer [CLS] embedding to a taskspecific feedforward layer, while finetuning the pretrained models using labeled examples (Devlin et al., 2019). In finetuning, we extend d i with varying amounts of generated sequences.

Experiments
We wish to assess whether and to what extent the generated synthetic data is sufficiently relevant and diverse for improving the generalization of pretrained LMs on the hate detection task. We therefore consider both within-and cross-dataset setups.
Datasets Table 1 provides details about the experimental datasets. Some of datasets originally used a fine annotation scheme, e.g., distinguishing between hate speech and abusive language. Since we perform transfer learning across datasets, we maintain the examples strictly annotated as hate and non-hate, and discard the examples assigned to other categories. As shown, the datasets are small  Table 2 presents our results on the held-out test examples, having finetuned the models using the labeled train exam-ples within the same dataset d i ('base'), and additional balanced amounts of synthetic examples (10/80/240K overall) generated by G i h and G i nh . We report precision, recall, and F1 performance with respect to the hate class. The table highlights the best F1 results per method and dataset, and summarizes the average improvements per model and data augmentation setup. As shown, substantial improvements are achieved using as few as 10K synthetic examples. Further gains are obtained with additional generated data, where augmentation of 240K generated examples achieves the best results in most cases. The improvements in F1 are mainly due to a boost in recall (8.3-23.6% relative improvement), yet precision is not severely compromised, and even improves in some cases (-1.7-4.7% relative change).

Within-dataset results
Interestingly, there are large differences in the performances of BERT, AlBERT and RoBERTa. As noted in Sec. 2, the models have been trained on different data and use different training goals and parameters, where we use these models 'out of the box'. Nevertheless, following finetuning using large amounts of synthetic data, the differences between the models are greatly reduced.
In another experiment, we contrast data augmentation using the synthetic weakly-labeled examples generated from the target dataset  Table 1.) The results are detailed in Table 2 ('GL'). As shown, F1 improves by -0.7-7.0% across datasets in this setup. However, using as few as 10K in-domain synthetic examples gives preferable results in all cases, yielding 1.1-8.1% relative improvement in F1. And, the gap is larger when contrasted with 80K synthetic examples, leading to 2.8-11.3% change in F1.

Cross-dataset results
In practice, the target distribution of hate speech may differ or vary over time from the train set distribution. A more realistic evaluation of model generalization is therefore transfer learning, training and testing the models across datasets. Similar to other works (Wiegand et al., 2019), we observed steep degradation in performance in this setup for some dataset pairs.
Since the target data distribution is typically   Table 3: Cross-dataset learning strategies, evaluated on FT test set, before ('base') and post augmentation unknown apriori, and considering that finetuning generally benefits from larger amounts of labeled examples, we opt for a resource-inclusive crossdataset strategy, where a model is trained using multiple (4) datasets, and then applied to the test examples of a single held-out dataset. In our experiments, we found that this strategy is generally favorable to training the models using some individual source dataset. For example, Table 3 details cross-dataset classification results using the different models, applied to the held-out test examples of the FT dataset. As shown, our approach ('4 vs 1') is favorable to training using individual source datasets ('1 vs 1'), as summarized by a sizeweighted average of the respective results, and also exceeds the results obtained by the best performing dataset pair (DV-FT, in this case.) We observed similar trends while targeting the other datasets.  Table 4: Detailed cross-dataset (4-vs-1) hate-F1 results pre-and post-augmentation. Cross-dataset results that exceed within-dataset performance (see Table 2: 'base') are underlined.
augmentation in the 4-vs-1 cross-dataset experiments. While this setup is more challenging compared with within-dataset training, incorporating additional 240K synthetic examples that are balanced across source dataset and class leads to a steep rise in recall, and overall large improvements in F1 (6.7-31.7%). As indicated in the table, a striking outcome is that in a third of the experiments (5/15), data augmentation in this setup leads to superior hate speech detection, i.e., better generalization, compared to within-dataset training.  (2021), we obtain better results both prior and post augmentation in most cases.

Additional Analyses
Number of generated examples As illustrated in Figure 1, we found that adding synthetic sequences beyond 240K examples maintains a positive trend, where F1 performance continues to rise for some models, albeit at a slower pace. Indeed, it is reasonable that the marginal gains obtained due to increased data diversity get smaller as more sequences are added. Nevertheless, the fact that performance keeps improving across this range, even if slowly, suggests that large scale data augmentation is beneficial.
Qualitative evaluation To assess the impact of data augmentation qualitatively, we examined the top words that characterized the hate class in the original vs. augmented datasets based on the PMI measure (Wiegand et al., 2019). Improved generalization is expected if the language observed in training is richer and more diverse. Indeed, we found many high-scoring hate-related terms in the synthetic tweets that were not included in the original data, e.g., 'ghetto', 'barbarians', 'terrorizing', 'detest', 'deranged', 'asshats', 'commies', 'pakis' etc. Furthermore, hateful terms typically appear a small number of times in the original data, and many more times in the synthetic data, providing more distinctive lexical statistics to learn from. We note however that existing models are limited in the contextual understanding of hateful language, including sarcasm and implicit hate speech acts. We believe that our approach mainly contributes to generalization by means of lexical diversification.
Stability of the results While Table 2 reports the results of fixed train-test data splits, we also conducted 5-fold experiments (where this involved repeated data generation for the different train sets) using the BERT model and all (5) datasets. The standard deviation of hate-F1 was roughly 1.5 point (0.015) with no augmentation, and smaller at 0.8 points using augmentation of 240K additional examples. We also ran 5 repeated runs using the fixed 80-20 data splits, where this yielded a standard deviation of roughly 0.7 absolute points in hate-F1 across datasets and augmentation levels. Thus, the variance is negligibly small compared with the large improvements in hate-F1. Overall, we have shown large gains in hate speech detection across multiple models, datasets and augmentation levels.

Conclusion
We evaluated several large transformer-based language models, which yield state-of-the-art hate detection results when finetuned using existing labeled datasets, and boosted their performance by augmenting those datasets with large amounts of generated data. We demonstrated strong positive impact of data augmentation across models and datasets, improving hate detection generalization on unseen examples. While large amounts of authentic task-related data may be available for finetuning in some domains or tasks, this is not the case for hate speech. Our main finding is that large LMs can be used for synthetic data enrichment, and yield even better results than related humanlabeled datasets. These results hold promise for overcoming sparsity and biases of labeled data.
Ethical statement Hate speech generation is sensitive and must not be maliciously misused.