NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Self-Attentive, Multi-Context One-Class Classification for Unsupervised Anomaly Detection on Text

Lukas Ruff, Yury Zemlyanskiy, Robert A. Vandermeulen, Thomas Schnake, Marius Kloft

Introduction

Anomaly Detection (AD) is the critical task of identifying rare, unusual samples within a large dataset—often described as finding "needles in a haystack." In the context of natural language processing, effective AD is essential for applications ranging from spam filtering and content moderation to the discovery of novel news topics. This paper introduces Context Vector Data Description (CVDD), a novel unsupervised method designed to overcome the limitations of traditional text anomaly detection by leveraging modern deep learning architectures.

The Challenge: Beyond Bag-of-Words

The authors identify two primary deficiencies in existing text AD research. First, many methods still rely on outdated Bag-of-Words (BoW) representations. These models ignore the rich semantic relationships captured by modern pre-trained word embeddings (like GloVe or fastText) and struggle with the high dimensionality and sparsity of text.

Second, traditional AD methods often assume a single "mode of normalcy." In reality, a corpus is typically composed of multiple thematic contexts. For instance, in a dataset of movie reviews, "normal" content might include plot summaries, technical critiques of cinematography, or emotional expressions of sentiment. Squashing these diverse themes into a single definition of normalcy leads to poor detection performance and a lack of interpretability.

Methodology: Context Vector Data Description (CVDD)

CVDD addresses these gaps by combining pre-trained word embeddings with a multi-head self-attention mechanism. The architecture is built on several key components:

  • Multi-Head Self-Attention: Instead of simple averaging, CVDD uses multiple attention heads to focus on different types of words simultaneously. One head might learn to attend to sentiment-bearing adjectives, while another focuses on topical nouns.
  • Context Vectors ($c_k$): The model learns a set of vectors that act as "prototypes" or centers of normalcy for each attention head. These vectors represent the distinct themes discovered within the data.
  • Objective and Regularization: The model is trained to minimize the cosine distance between document representations and their nearest context vectors. To prevent all heads from collapsing onto the same theme, an orthogonality penalty is applied to ensure the context vectors remain diverse.
  • Anomaly Scoring: A document is assigned an anomaly score based on its distance from these learned centers. If a sample does not align with any of the established modes of normalcy, it is flagged as an outlier.
Table 2: Semantic modes captured by different context vectors ($c_1, c_2, c_3$) in the IMDB dataset, demonstrating the model's ability to disentangle sentiment from plot.

Experimental Results

The model was rigorously evaluated on the Reuters-21578 and 20 Newsgroups datasets using a "one-vs-rest" experimental setup. In this configuration, the model is trained on a single category (the "normal" class) and tasked with detecting samples from all other categories as anomalies.

As shown in the performance data, CVDD consistently outperforms or matches strong baselines like One-Class SVMs (OC-SVM). Notably, on several Reuters categories, CVDD achieved AUC scores exceeding 95%. The results indicate that the multi-context approach ($r > 1$) is particularly effective at capturing the nuances of complex text categories.

Table 1: Quantitative performance (AUC) comparison between CVDD and OC-SVM baselines across Reuters and 20 Newsgroups datasets using GloVe and fastText embeddings.

Interpretability and Disentanglement

A major advantage of CVDD is its inherent interpretability. Because the model utilizes attention weights, it can provide human-readable explanations by highlighting the specific words that contributed to a document's classification.

Qualitative analysis on the IMDB dataset revealed that CVDD successfully "disentangled" different thematic elements without manual labeling. As illustrated in the context vector word clusters, the model separated positive sentiment ($c_1$), negative sentiment ($c_2$), and narrative elements ($c_3$) into distinct heads. This allows users to see not just that a document is anomalous, but why it fails to fit the established patterns of the corpus.

Conclusion and Future Work

CVDD represents a significant step forward for unsupervised text anomaly detection. By moving away from single-centroid models and embracing the multi-faceted nature of language, it provides both high performance and much-needed transparency. While the model is dependent on the quality of pre-trained embeddings, its robustness across different datasets makes it a versatile tool for real-world applications. Future research may explore integrating CVDD with transformer-based models like BERT or adapting it for semi-supervised environments where limited labeled anomaly data is available.

Summary updated

BibTeX
@inproceedings{ruff2019self,
  author = {Lukas Ruff and Yury Zemlyanskiy and Robert A. Vandermeulen and Thomas Schnake and Marius Kloft},
  title = {{Self-Attentive, Multi-Context One-Class Classification for Unsupervised Anomaly Detection on Text}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2019},
  doi = {10.18653/v1/p19-1398},
}
Figure