arXiv:2609.08200cs.LGSep 2026

Manuscript Offprint

arXiv:2609.08200

SIM: Subspace Interaction-based Method for Token-Level Text Anomaly Detection

Kehan Yan, Yue Tan, Qingfeng Chen, Shiyuan Li, Yu Zheng, Yixin Liu

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Kehan Yan1^{1}, Yue Tan2^{2}, Qingfeng Chen†1^{\dagger 1}, Shiyuan Li2^{2}, Yu Zheng2^{2}, and Yixin Liu‡2^{\ddagger 2}

1^{1} Guangxi University, Guangxi, China, 2^{2} Griffith University, Queensland, Australia

2413301048@st.gxu.edu.cn, {yue.tan, shiyuan.li, yu.zheng, yixin.liu}@griffith.edu.au, qingfeng@gxu.edu.cn

Abstract—Token-level text anomaly detection, as an emerging trend of text anomaly detection, moves beyond coarse-grained document-level detection by localizing anomalous tokens within text. By providing fine-grained abnormality prediction, token-level text anomaly detection plays a critical role in various real-world applications, such as spam filtering and fake news detection. However, existing methods still rely on the global distance calculation for scoring, during which the local anomaly signals are severely diluted by numerous redundant normal feature dimensions. Moreover, pre-trained language models used in these methods inevitably smooth out surface anomalies, further limiting their effectiveness in token-level anomaly detection. To address these limitations, we propose a Subspace Interaction-based Method (SIM for short) for token-level text anomaly detection. To prevent local signal dilution, SIM adopts a subspace interaction-based anomaly detector, which decouples high-dimensional token embeddings into multiple low-dimensional ones, amplifying localized anomaly signals hidden within specific dimensions. To counteract the over-smoothing effect, we design a hard pseudo-anomaly generation module to construct pseudo-anomalous tokens, simulating the subtle anomalies obscured by semantic smoothing. Also, a probabilistic boundary loss is developed to standardize anomaly scores into statistical distances, effectively enforcing anomalous instances to deviate significantly from the normal distribution center. Extensive experiments on multiple benchmark datasets verify the effectiveness of SIM and demonstrate its remarkable efficiency, robustness, and interpretability. The source code is available at: https://github.com/yankehan/SIM-TAD.

Index Terms—text anomaly detection, token-level anomaly detection, document-level anomaly detection.

I. INTRODUCTION

Anomaly detection is a foundational research problem that plays a critical role in numerous practical application scenarios [1]–[4]. For example, in tabular [5], [6] and graph data [7], [8], anomaly detection is commonly utilized to identify financial fraud or malicious nodes within social networks. However, textual data possesses highly unstructured, discrete, and complex semantic characteristics, limiting early progress in anomaly detection specifically targeting textual data [9]–[11]. These characteristics have motivated recent research on text anomaly detection, which aims to identify text instances that deviate from normal semantic or syntactic patterns [12], [13]. Due to the ubiquity of textual data, text anomaly detection has become increasingly important in scenarios such as spam filtering, fake news detection, and machine-generated content identification [14], [15].

Figure

(a) SMS_Spam

(b) Grammar

Fig. 1. t-SNE visualization of token embeddings on two datasets corresponding to different anomaly types: SMS_Spam (SMS gibberish corruption) and Grammar (grammatical anomalies).

In recent years, the rapid advancement of pre-trained language models (PLMs) [16], [17] has provided text anomaly detection with powerful contextual representations that encode rich semantic and syntactic information. By combining these high-quality text embeddings with mainstream anomaly detectors, existing methods have achieved promising performance in solving text anomaly detection problems [18]. However, most existing studies are restricted to document-level anomaly detection tasks that assign a single anomaly score to each document to indicate its overall abnormality [9], [10], [19]. This coarse-grained detection makes it difficult for users to understand the basis for anomaly determination and prevents the precise localization of problematic segments. In fact, practical applications are in urgent demand for fine-grained anomaly localization [20]. For example, practitioners may need to locate anomalous instructions that cause program crashes in massive website backend logs, while security analysts need to identify deceptive illegal links in phishing emails. In these scenarios, fine-grained anomaly localization not only facilitates rapid troubleshooting but also significantly enhances the transparency and trustworthiness of the detection system.

To achieve fine-grained text anomaly detection, Cao et al. [20] proposed the first token-level text anomaly detection framework, named TokenCore. This method utilizes PLMs to encode each token in a document into a high-dimensional numerical embedding, and then derives anomaly scores by calculating the nearest neighbor distance between the test token and the set of normal tokens. Because PLMs can capture

†^{\dagger} Qingfeng Chen and Yixin Liu are the corresponding authors.

10.960.570.530.510.570.57
am0.450.900.800.570.640.74
a0.410.760.880.560.610.70
good0.360.720.770.600.660.69
student0.450.710.730.680.900.69
0.520.740.740.590.680.95
1isastupidstudent

Fig. 2. Visualization of BERT embedding similarities. Grammatical variants ("am" vs. "is") show high latent similarity, whereas semantically distinct tokens ("good" vs. "stupid") show lower similarity scores.

rich semantic and syntactic features, anomalous tokens that deviate from normal patterns exhibit a significant distance shift from the distribution of normal tokens within the embedding space. Consequently, these anomalous tokens are assigned higher anomaly scores. Overall, TokenCore opens up a new direction for text anomaly detection by extending anomaly scoring from the document level to the token level.

Although TokenCore [20] shows promising potential in token-level anomaly detection, it highly relies on a distance-based scoring mechanism, which directly relies on the distance of embedding vectors in the feature space, inevitably introducing two inherent limitations. Limitation 1: Local anomaly signal dilution. While a small number of obvious anomalies, such as tokens with extreme contextual mismatches or strong negative sentiments, can be easily detected in the global embedding space, most subtle anomalies, such as text corruption, are only reflected in a few specific embedding dimensions, i.e., subspaces. During global distance calculation, these localized anomaly signals are severely diluted by numerous redundant normal feature dimensions [21]. Consequently, as illustrated in Figure 1, anomalous tokens remain close to normal-token clusters in the feature space, making them difficult to distinguish through global distance-based scoring. Limitation 2: Over-smoothing effect. Because PLMs such as BERT were originally designed to optimize semantic similarity rather than anomaly sensitivity [16], [22], their representations inevitably smooth out surface anomalies, such as grammatical errors. Taking the representation-level similarity in Figure 2 as an example, surface anomalous tokens (e.g., is) exhibit high similarity to normal tokens (e.g., am) in the latent space and are difficult to distinguish, leading to weak anomaly separability for such types of anomalous tokens. Motivated by these limitations, a natural question arises: Can we develop a token-level text anomaly detection framework capable of capturing local anomaly signals while counteracting the over-smoothing effect inherent in PLMs?

To answer this question, we propose SIM, a Subspace Interaction-based Method for token-level text anomaly detection. To address Limitation 1, we design a subspace interaction-based anomaly detector, which decouples high-

dimensional token embeddings into multiple low-dimensional feature subspaces and introduces a cross-subspace self-attention mechanism to dynamically capture interactions between subspaces. This subspace interaction mechanism endows the model with the ability to amplify local anomaly signals hidden within specific dimensions, enhancing its sensitivity to subtle token-level anomalies. To handle Limitation 2, we train the anomaly detector with two complementary strategies, namely hard pseudo-anomaly generation and probabilistic boundary loss, improving its sensitivity to surface anomalies that are smoothed out in the representation space. Specifically, given that smoothed surface anomalies are highly similar to normal tokens in the representation space, the hard pseudo-anomaly generation introduces a distance perturbation mechanism to artificially construct pseudo-anomalous tokens. These tokens are highly similar to normal tokens in the representation space, yet they lack meaningful semantic and syntactic structures; therefore, they can serve as suitable pseudo-anomalies. Training on these hard pseudo-anomalies discourages the detector from relying solely on semantic similarity and encourages it to capture subtle anomaly signals beyond global representation distance. Furthermore, we design a probabilistic boundary loss to guide anomaly score prediction. This loss utilizes the mean and variance of the anomaly scores of normal data to construct a statistical boundary, thereby enforcing that the scores of anomalous samples significantly deviate from normal instances in a statistical sense.

In summary, the contributions of this paper are threefold:

  • New Perspective: Going beyond the traditional perspective of global token embeddings, we are the first to explore the utilization of token subspace interaction information to achieve token-level text anomaly detection.
  • Novel Method: We propose SIM, a lightweight model using a subspace interaction-based anomaly detector to capture subspace anomaly signals. Moreover, we introduce a hard pseudo-anomaly generation module to overcome the over-smoothing effect, and design a probabilistic boundary loss to guide the learning of anomaly scores.
  • Extensive Experiments: Extensive experiments on three real-world datasets demonstrate that SIM achieves superior anomaly detection performance at both token and document levels compared to state-of-the-art approaches, while delivering remarkable efficiency, robustness, and interpretability.

References (43)