[Paper Review] Self-Supervised Losses for One-Class Textual Anomaly Detection
This paper proposes a simple yet effective self-supervised approach for one-class textual anomaly detection by fine-tuning BERT on inlier data using masked language modeling (MLM), causal language modeling (CLM), or contrastive learning (SimCSE), then using the model's loss as an anomaly score. The method improves AUROC by 11.6% on semantic anomalies and 22.8% on syntactic anomalies compared to prior methods, with performance depending on the anomaly type and representation characteristics.
Current deep learning methods for anomaly detection in text rely on supervisory signals in inliers that may be unobtainable or bespoke architectures that are difficult to tune. We study a simpler alternative: fine-tuning Transformers on the inlier data with self-supervised objectives and using the losses as an anomaly score. Overall, the self-supervision approach outperforms other methods under various anomaly detection scenarios, improving the AUROC score on semantic anomalies by 11.6% and on syntactic anomalies by 22.8% on average. Additionally, the optimal objective and resultant learnt representation depend on the type of downstream anomaly. The separability of anomalies and inliers signals that a representation is more effective for detecting semantic anomalies, whilst the presence of narrow feature directions signals a representation that is effective for detecting syntactic anomalies.
Motivation & Objective
- To address the challenge of one-class textual anomaly detection where only inlier data are available at training time.
- To evaluate whether self-supervised fine-tuning objectives can serve as effective anomaly detectors without requiring supervisory signals or complex architectures.
- To investigate how different self-supervised objectives influence detection performance based on anomaly type (semantic vs. syntactic).
- To analyze the underlying representation properties—such as separability and feature brittleness—that correlate with detection performance.
Proposed method
- Fine-tune a pre-trained BERT BASE encoder with three self-supervised objectives: masked language modeling (MLM), causal language modeling (CLM), and contrastive learning (SimCSE).
- Use the cross-entropy loss from each fine-tuned model as the anomaly score during inference, with higher loss indicating higher anomaly likelihood.
- Evaluate performance using AUROC on two anomaly types: semantic anomalies (created by class partitioning) and syntactic anomalies (created by sentence shuffling).
- Extract last-layer hidden representations and analyze their properties: separability via logistic classification accuracy and feature brittleness via average L2 gradient norms.
- Compare the end-to-end loss-based scoring to using the embeddings as features in a k-NN classifier to assess representation utility.
- Conduct ablation studies on permutation strength (1-gram to 4-gram shuffling) to evaluate robustness of different objectives under increasing syntactic disturbance.
Experimental results
Research questions
- RQ1Can self-supervised fine-tuning of a pre-trained Transformer using loss as an anomaly score outperform more complex, supervised anomaly detection methods in one-class settings?
- RQ2How does the choice of self-supervised objective (MLM, CLM, SimCSE) affect performance on semantic versus syntactic anomalies?
- RQ3What representation properties—such as class separability or feature brittleness—predict better anomaly detection performance?
- RQ4Is using the model's loss directly a better anomaly score than using the learned embeddings as features in downstream classifiers?
Key findings
- Fine-tuning BERT with self-supervised objectives improves AUROC by 11.6% on average for semantic anomalies and 22.8% for syntactic anomalies compared to existing methods.
- The CLM objective achieves the most stable performance across increasing syntactic anomaly difficulty, with only a 4% drop in AUROC from 1-gram to 4-gram shuffling, outperforming MLM and SimCSE.
- Representation separability between inliers and anomalies is a strong predictor of performance for semantic anomaly detection, as shown by high correlation between classification accuracy and AUROC.
- For syntactic anomalies, higher gradient norm (indicating more brittle features) correlates strongly with better detection performance, especially for CLM-based models.
- End-to-end use of the loss as an anomaly score consistently outperforms using the learned embeddings as features in a k-NN classifier.
- The SimCSE objective produces the most isotropic representations, while CLM yields the most anisotropic and brittle features, aligning with its superior performance on syntactic anomalies.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.