A little goes a long way: Improving toxic language classification despite data scarcity (2020)

Abstract: Detection of some types of toxic language is hampered by extreme scarcity of labeled training data. Data augmentation – generating new synthetic data from a labeled seed dataset – can help. The efficacy of data augmentation on toxic language classification has not been fully explored. We present the first systematic study on how data augmentation techniques impact performance across toxic language classifiers, ranging from shallow logistic regression architectures to BERT – a state-of-the-art pretrained Transformer network. We compare the performance of eight techniques on very scarce seed datasets. We show that while BERT performed the best, shallow classifiers performed comparably when trained on data augmented with a combination of three techniques, including GPT-2-generated sentences. We discuss the interplay of performance and computational overhead, which can inform the choice of techniques under different constraints.

## introduction toxic language is an increasingly urgent challenge in online communities @xcite . although there are several datasets, most commonly from twitter or forum discussions @xcite @xcite @xcite , high class imbalance is a problem with certain classes of toxic language @xcite . manual labeling of toxic content is onerous, hazardous @xcite , and thus expensive. one strategy for mitigating these problems is data augmentation @xcite @xcite : complementing the manually labeled seed data with new synthetic documents. the effectiveness of data augmentation for toxic language classification has not yet been thoroughly explored. on relatively small toxic language datasets, shallow classifiers have been shown to perform well @xcite . at the same time, pre-trained transformer networks @xcite have led to impressive results in several nlp tasks @xcite . comparing the effects of data augmentation between shallow classifiers and pre-trained transformers is thus of particular interest. we systematically compared eight augmentation techniques on four classifiers, ranging from shallow architectures to bert @xcite , a popular pre-trained transformer network. we used downsampled variants of the kaggle toxic comment classification challenge dataset @xcite ; §3) as our seed dataset. we focused on the threat class, but also replicated our results on another toxic class ( §4.6). with some classifiers, we reached the same f1-score as when training on the original dataset, which is 20x larger. however, performance varied markedly between classifiers. we obtained the highest overall results with bert, increasing the f1-score up to 21% compared to training on seed data alone. however, augmentation using a fine-tuned gpt-2 ( §3.2.4)a pre-trained transformer language model (radford et al., 2019) -reached almost bert-level performance even with shallow classifiers. combining multiple augmentation techniques, such as adding majority class sentences to minority class documents ( §3.2.3) and replacing subwords with embedding-space neighbors @xcite ( §3.2.2), improved performance on all classifiers. we discuss the interplay of performance and computational requirements like memory and run-time costs ( §4.5). we release our source code. 1 2 preliminaries data augmentation arises naturally from the problem of filling in missing values @xcite . in classification, data augmentation is applied to available training data. classifier performance is measured on a separate (non-augmented) test set @xcite . data augmentation can decrease overfitting @xcite , and broaden the input feature range by increasing the vocabulary @xcite . simple oversampling is the most basic augmentation technique: copying minority class datapoints to appear multiple times. this increases the relevance of minority class features for computing the loss during training @xcite . eda is a prior technique combining four text transformations to improve classification with cnn and rnn architectures @xcite . it uses (i) synonym replacement from wordnet ( §3.2.1), (ii) random insertion of a synonym, (iii) random swap of two words, and (iv) random word deletion. word replacement has been applied in several data augmentation studies @xcite @xcite @xcite . we compared four techniques, two based on semantic knowledge bases ( §3.2.1) and two on pre-trained (sub)word embeddings ( §3.2.2). pre-trained transformer networks feature prominently in state-of-the-art nlp research. they are able to learn contextual embeddings, which depend on neighboring subwords @xcite . fine-tuning -adapting the weights of a pre-trained transformer to a specific corpus -has been highly effective in improving classification performance @xcite and language modeling @xcite @xcite . state-of-the-art networks are trained on large corpora: gpt-2's corpus contains 8m web pages, while bert's training corpus contains 3.3b words. ## methodology we now describe the data (3.1), augmentation techniques (3.2), and classifiers (3.3) we used. ## results we compared precision and recall for the minority class (threat), and the macro-averaged f1-score for each classifier and augmentation technique. (for brevity, we use "f1-score" from now on.) the majority class f1-score remained 1.00 (two digit rounding) across all our experiments. all classifiers are binary, and we assigned predictions to the class with the highest conditional probability. we relax this assumption in §4.4, to report area under the curve (auc) values @xcite . to validate our results, we performed repeated experiments with the common random numbers technique @xcite , by which we controlled the sampling of seed, initial random weights of classifiers, and the optimization procedure. we repeated the experiments 30 times, and report confidence intervals. ## related work toxic language classification has been conducted in a number of studies @xcite @xcite @xcite . nlp applications of data augmentation include text classification @xcite @xcite , user behavior categorization (wang and yang, 2015), dependency parsing @xcite , and machine translation @xcite . related techniques are also used in automatic paraphrasing @xcite and writing style transfer @xcite @xcite . @xcite produced text with controlled target attributes via variational autoencoders. @xcite generated artificial sentences for adverse drug reactions using reddit and twitter data. similarly to their work, we generated novel toxic sentences from a language model. @xcite compared several pre-trained language models on their ability to understand factual and commonsense reasoning. bert models consistently outperformed other language models. petroni et al. suggest that large pre-trained language models may become alternatives to knowledge bases in the future. ## discussion and conclusions our results highlight the relationship between classification performance and computational overhead. overall, bert performed the best with data augmentation. however, it is highly resource-intensive ( §4.5). abg yielded almost bert-level f1-and roc-auc scores on all classifiers. while using gpt-2 is more expensive than other augmentation techniques, it has significantly less requirements than bert. additionally, augmentation is a one-time upfront cost in contrast to ongoing costs for classifiers. thus, the trade-off between performance and computational resources can influence which technique is optimal in a given setting. we identify the following further topics that we leave for future work. seed coverage. our results show that data augmentation can increase coverage, leading to better toxic language classifiers when starting with very small seed datasets. the effects of data augmentation will likely differ with larger seed datasets. languages. some augmentation techniques are limited in their applicability across languages. gpt-2, wordnet, ppdb and glove are available for certain other languages, but with less coverage than in english. bpemb is nominally available in 275 languages, but has not been thoroughly tested on less prominent languages. transformers. bert has inspired work on other pre-trained transformer classifiers, leading to better classification performance @xcite and better trade-offs between memory consumption and classification performance @xcite . exploring the effects of augmentation on these transformer classifiers is left for future work. attacks. training classifiers with augmented data may influence their vulnerability for model extraction attacks @xcite , model evasion @xcite , or backdoors @xcite . we leave such considerations for future work.