HABERTOR : An Efficient and Effective Deep Hatespeech Detector (2020)

Abstract: We present our HABERTOR model for detecting hatespeech in large scale user-generated content. Inspired by the recent success of the BERT model, we propose several modifications to BERT to enhance the performance on the downstream hatespeech classification task. HABERTOR inherits BERT’s architecture, but is different in four aspects: (i) it generates its own vocabularies and is pre-trained from the scratch using the largest scale hatespeech dataset; (ii) it consists of Quaternion-based factorized components, resulting in a much smaller number of parameters, faster training and inferencing, as well as less memory usage; (iii) it uses our proposed multi-source ensemble heads with a pooling layer for separate input sources, to further enhance its effectiveness; and (iv) it uses a regularized adversarial training with our proposed fine-grained and adaptive noise magnitude to enhance its robustness. Through experiments on the large-scale real-world hatespeech dataset with 1.4M annotated comments, we show that HABERTOR works better than 15 state-of-the-art hatespeech detection methods, including fine-tuning Language Models. In particular, comparing with BERT, our HABERTOR is 4 5 times faster in the training/inferencing phase, uses less than 1/3 of the memory, and has better performance, even though we pre-train it by using less than 1% of the number of words. Our generalizability analysis shows that HABERTOR transfers well to other unseen hatespeech datasets and is a more efficient and effective alternative to BERT for the hatespeech classification.

## introduction the occurrence of hatespeech has been increasing @xcite . it has become easier than before to reach a large audience quickly via social media, causing an increase of the temptation for inappropriate behaviors such as hatespeech, and potential damage to social systems. in particular, hatespeech interferes with civil discourse and turns good people away. furthermore, hatespeech in the virtual world can lead to physical violence against certain groups in the real world 12 , so it should not be ignored on the ground of freedom of speech. to detect hatespeech, researchers developed human-crafted feature-based classifiers @xcite @xcite , and proposed deep neural network architectures @xcite @xcite @xcite . however, they might not explore all possible important features for hatespeech detection, ignored pre-trained language model understanding, or proposed uni-directional language models by reading from left to right or right to left. recently, the bert (bidirectional encoder representations from transformers) model @xcite has achieved tremendous success in natural language processing . the key innovation of bert is in applying the transformer @xcite to language modeling tasks. a bert model pre-trained on these language modeling tasks forms a good basis for further fine-tuning on supervised tasks such as machine translation and question answering, etc. recent work on hatespeech detection @xcite has applied the bert model and has shown its prominent results over previous hatespeech classifiers. however, we point out its two limitations in hatespeech detection domain. first, the previous studies @xcite have shown that a hateful corpus owns distinguished linguistic/semantic characteristics compared to a non-hateful corpus. for instance, hatespeech sequences are often informal or even in-tentionally mis-spelled @xcite , so words in hateful sequences can sit in a long tail when ranking their uniqueness, and a comment can be hateful or non-hateful using the same words @xcite . for example, "dick" in the sentence "nobody knew dick about what that meant" is non-hateful, but "d1ck" in "you are a weak small-d1cked keyboard warrior" is hateful foot_2 . thus, to better understand hateful vocabularies and contexts, it is better to pre-train on a mixture of both hateful and non-hateful corpora. doing so helps to overcome the limitation of using bert models pre-trained on non-hateful corpora like english wikipedia and bookcorpus. second, even the smallest pre-trained bert "base" model contains 110m parameters. it takes a lot of computational resources to pre-train, fine-tune, and serve. some recent efforts aim to reduce the complexity of bert model with the knowledge distillation technique such as distillbert @xcite and tinybert @xcite . in these methods, a pre-trained bert-alike model is used as a teacher model, and a student (smaller) model (i.e. tinybert, distilbert, .etc) is trained to produce similar output to that of the teacher model. unfortunately, while their complexity is reduced, the performance is also degraded in nlp tasks compared to bert. another direction is to use cross-layer parameter sharing, such as albert @xcite . however, albert's computational time is similar to bert, since the number of layers remains the same as bert; likewise, its inference is equally expensive. based on the above observation and analysis, we aim to investigate whether it is possible to achieve a better hatespeech prediction performance than state-of-the-art machine learning classifiers, including classifiers based on publicly available bert model, while significantly reducing the number of parameters compared with the bert model. by doing so, we believe that performing pre-training tasks from the ground up and on a hatespeechrelated corpus would allow the model to understand hatespeech patterns better and enhance the predictive results. however, while language model pretraining tasks require a large scale corpus size, available hatespeech datasets are normally small: only 16k∼115k annotated comments @xcite . thus, we introduce a large annotated hatespeech dataset with 1.4m comments extracted from yahoo news and yahoo finance. to reduce the complexity, we reduce the number of layers and hidden size, and propose quaternion-based factorization mechanisms in bert architecture. to further improve the model effectiveness and robustness, we introduce a multi-source ensemble-head fine-tuning architecture, as well as a target-based adversarial training. the major contributions of our work are: ## related work some of the earlier works in hatespeech detection have applied a variety of classical machine learning algorithms @xcite @xcite . their intuition is to do feature engineering (i.e. manually generate features), then apply classification methods such as svm, random forest, and logistic regression. the features are mostly term-frequency inverse-document-frequency scores or bag-of-words vectors, and can be combined with additional features extracted from the user account's meta information and network structure (i.e., followers, followees, etc). those methods are suboptimal as they mainly rely on the quality and quantity of the human-crafted features. recent works have used deep neural network architectures for hatespeech detection @xcite such as cnn @xcite , rnn (i.e. lstm and gru) @xcite , combining cnn with rnn @xcite , or fine tuning a pretrained language models @xcite . another direction focuses on the testing generalization of the current hatespeech classifiers @xcite @xcite , where those methods are tested in other datasets and domains such as twitter data @xcite , wikipedia data @xcite , formspring data @xcite , and youtube comment data @xcite . unlike previous works, we pre-train a hateful language model, then build a multi-source multihead hatespeech classifier with regularized adversarial training to enhance the model's performance. ## problem definition given an input text sequence @xmath0, w 2 , ..., w n ] where {w 1 , w 2 , .., w n } are words and @xmath1. the hatespeech classification task aims to build a mapping function f : @xmath2, w 2 , ..., w n ] -→ @xmath3, 1], where f inputs s and returns a probability score p (@xmath4, 1], indicating how likely s is classified as hatespeech. in this paper, we approximate f by a deep neural classifier, where we first pretrain f with unsupervised language modeling tasks to enhance its language understanding. then, we train f with the hatespeech classification task to produce p (@xmath5. ## conclusion in this paper, we presented the habertor model for detecting hatespeech. habertor understands the language of the hatespeech datasets better, is 4-5 times faster, uses less than 1/3 of the memory, and has a better performance in hatespeech classification. overall, habertor outperforms 15 state-of-the-art hatespeech classifiers and generalizes well to unseen hatespeech datasets, verifying not only its efficiency but also its effectiveness. output dimensions. particularly, given a real-valued 4-dimensional vector [r in , a in , b in , c in ], we need to parameterize a weight matrix of 16 parameters (i.e. 16 degrees of freedom) to transform the 4dimensional input vector into a 4-dimensional output vector [r out , a out , b out , c out ]. however, with quaternion transformation, the input vector now is represented with 4 components, where r in is the value of the real component, a in , b in , c in are the corresponding value of the three imaginary parts i, j, k, respectively. because of the weight sharing nature of hamilton product, different output dimensions take different combinations with the same input with exactly same 4 weighting parameters {r w , a w , b w , c w }. thus, the quaternions transformation reduces 75% of the number of parameters compared to the real-valued representations in euclidean space. quaternion-euclidean conversion: another excellent property of using quaternion representations and quaternion transformations is that converting from quaternion to euclidean and vice versa are convenient. to convert a real-valued based vector @xmath6, we consider the first d/4 dimensions of v as the value of the real component, and the corresponding next three d/4 dimensions are for the three imaginary parts, respectively. similarly, to convert a quaternion vector @xmath7, we simply concatenate all four components of the quaternion vector, and treat the concatenated vector as a real-valued vector in euclidean space.