A Lightweight Yet Robust Approach to Textual Anomaly Detection (2022)

Abstract: Highly imbalanced textual datasets continue to pose a challenge for supervised learning models. However, viewing such imbalanced text data as an anomaly detection (AD) problem has advantages for certain tasks such as detecting hate speech, or inappropriate and/or offensive language in large social media feeds. There the unwanted content tends to be both rare and non-uniform with respect to its thematic character, and better fits the definition of an anomaly than a class. Several recent approaches to textual AD use transformer models, achieving good results but with trade-offs in pre-training and inflexibility with respect to new domains. In this paper we compare two linear models within the NMF family, which also have a recent history in textual AD. We introduce a new approach based on an alternative regularization of the NMF objective. Our results surpass other linear AD models and are on par with deep models, performing comparably well even in very small outlier concentrations.

## introduction anomaly detection (ad), also known as outlier detection, is a well-researched area of machine learning. traditional machine learning approaches to ad include proximity-based models where points that are separated from the rest of the data by a certain distance are considered outliers. these fall into several subclasses. there are cluster-based methods, such as k-means @xcite , where the point is an outlier if there is a large distance between the point and the nearest cluster, densitybased methods, such as lof @xcite and dbscan @xcite , where an object is an outlier if its density is lower than that of its neighbors and distance-based methods, such as k-nn @xcite , where the outlier neighborhood has few other points. most recently, transformer models @xcite and word embeddings with multi-head selfattention @xcite have been applied in textual ad models, surpassing previously top-performing reconstruction-based approaches using non-negative matrix factorization (nmf) as in @xcite . but detecting hate speech and offensive language is a challenging task because these may take various forms, change dynamically and be found in only a small minority of relatively short texts. recent studies @xcite have pointed to concerns about generalizing results where even the best performing models show large variances in quality from one dataset to another in this domain. we propose a new nmf-based approach as an alternative to recent transformer models. we improve upon previous nmf outlier detection approaches by replacing the usual squared norm of the error term in the objective function by a correntropy-based metric, which we argue is better tailored for textual outliers. this approach, we argue, is not only well-suited to the task of textual ad in general due to its lightweight architecture and flexibility but is also the better choice versus recent supervised models for hate-speech detection. this paper is organized as follows: previous approaches are discussed in section 2, data and methods are discussed in section 3, our results are in section 4 and the conclusion and plans for future work in section 5. code to reproduce our results can be found here: (github repo provided upon acceptance) ## previous work while anomaly detection in text does not have a particularly deep history in the literature, there is some notable research. for example, @xcite and @xcite consider texts that are unusual because of author, genre, style or emotional tone. @xcite , analyzed idiom recognition as a type of outlier detection. idioms have certain key properties that make detection more likely using methods for finding outliers. examples in english include "kick the bucket" or "have a cow" where the non-compositionality yields highly unusual lexical properties that can be recognized as anomalies. other studies @xcite , @xcite al. (2017), barrett et al. (2019), ruff et al. (2019), manolache et al. (2021) ), treat textual anomalies as topical intrusions, where the texts from one topic constitute the "inliers" and a smaller set of intrusion texts constitute the "outliers". we use this data definition for our anomaly detection task. among topic-intrusion type models, the cur-rently best-performing is the transformer approach in @xcite , a discriminator-generator model that outperformed the previously top performing ocsvm approach in @xcite . a non-negative matrix factorization model was used in @xcite . all three approaches have outperformed traditional ad models like isolation forests @xcite ) on text. ## proposed methods we propose a lightweight alternative non-negative matrix factorization (nmf) model that improves upon the results of kannan and also provides comparable results to deep models without pre-training, or attention layers. we use simple frequency-based document representations and do not rely on trained embeddings. we show results on benchmark datasets and also on a dataset of hate speech in order to show the power and adaptability of our approach to an important nlp problem. overall, our model is tested on four datasets in multiple combinations with different outlier-inlier concentrations. matrix factorization models like tonmf find outliers through a reconstruction process that isolates outlier documents as residual noise. in this approach, a is the term-document matrix where terms correspond to rows and documents correspond to columns, w is the term-topic matrix and h is the topic-document matrix. the residual matrix z is intended to capture outliers depending on the configuration of its norm. the idea is that if a document is not representable as a linear combination of topics, the corresponding column in z will have more entries. the quality of the result depends on manipulating norms on both the residual matrix and the low-rank approximation of the input matrix. @xcite for example use the following optimization: here, the standard frobenius norm is applied to the main error term. the ℓ 1,2 penalty norm is applied to the outlier matrix z in order to minimize the sum of ℓ 2 column norms, which can be seen as the outlier scores of each document. the last term is added for regularization, to produce a more interpretable low rank matrix wh with sparse coefficients. the α and β parameters control the weight of the residual and regularization terms over the recovery of a low-rank approximation to a. ## experimental results below we describe the datasets and preparation. all models were run on four public datasets representing distinct genres (listserv, news, wiki and hate speech). we used three outlier-inlier concentrations for each. ## conclusion and future work although recent approaches to textual anomaly detection using deep models are very robust, our model performs comparably and even outperforms the state of the art on the majority of ad datasets including a hate speech dataset. we improve upon recent nmfbased ad by combining a row-centric approach with a separate residual matrix. our approach requires no pretraining or fine tuning, making it highly adaptable to different data sets with different concentrations of anomalous texts in a low compute resource setting. the model is well-suited both to the task of identifying hate speech and topical-intrusion-type textual anomalies in general. we plan to continue further experiments on new ad data sets, including those containing hate speech and offensive language.