TextTopoOOD: Topological OOD Detection
- TextTopoOOD is a research program that uses topological features from self-attention and text-rich networks to detect out-of-distribution (OOD) data.
- In transformer settings, it converts self-attention maps into graphs and applies persistent homology to capture structural regularities for effective far-OOD detection.
- In graph settings, frameworks like TNT-OOD and LG-Plug jointly model text and topology to evaluate diverse OOD shifts in complex, text-attributed networks.
TextTopoOOD denotes a line of research that uses topological structure together with text representations for out-of-distribution (OOD) detection, but the term has been used in two distinct senses. In transformer-based text classification, it refers to an OOD detector built from persistent-homology features of self-attention maps, evaluated on BERT for distinguishing in-distribution text from far-, near-, and same-domain shifts (Pollano et al., 2023). In text-rich networks, it refers to a framework for constructing and evaluating OOD shifts that jointly affect textual attributes, graph structure, labels, and domains, introduced together with the TNT-OOD detector for text-rich networks (Wang et al., 25 Aug 2025). A later TAG study, LG-Plug, situates itself against both topology-driven and LLM-guided approaches, arguing that both topology and text matter for OOD detection on text-attributed graphs (Zhu et al., 12 Feb 2026).
1. Terminological scope and research setting
The earlier usage of TextTopoOOD is centered on plain textual inputs processed by transformer-based LLMs. Its motivating problem is that machine learning systems operating on textual data may exhibit unpredictable behaviour under OOD inputs, and the proposed remedy is to detect such inputs using topological features extracted from self-attention maps (Pollano et al., 2023). The method is presented as, in principle, applicable to any transformer-based LLM with multihead self-attention, because self-attention dynamically assigns vectors to words based on context.
The later usage broadens the term from a detector into an evaluation framework for text-rich networks. In that setting, a graph is written as with node-text embeddings , adjacency , and labels , and the core claim is that OOD may arise from multiple coupled sources rather than from a single label-shift or domain-split mechanism (Wang et al., 25 Aug 2025). This framework is paired with TNT-OOD, which explicitly models the interplay between text and topology through cross-attention and a HyperNetwork.
A concise way to distinguish the two uses is as follows.
| Usage of “TextTopoOOD” | Data modality | Primary object |
|---|---|---|
| Transformer-text setting | Text processed by BERT | OOD detector from topological features of self-attention (Pollano et al., 2023) |
| Text-rich network setting | Text-attributed graph data | Evaluation framework for diverse OOD shifts, paired with TNT-OOD (Wang et al., 25 Aug 2025) |
This dual usage suggests that the unifying idea is not a single architecture but a research program: OOD detection benefits from modeling structural regularities that accompany textual content, whether those regularities arise inside transformer attention or in graph topology.
2. Persistent-homology formulation on transformer self-attention
In the transformer-based formulation, TextTopoOOD begins by converting each self-attention map into an undirected weighted graph. Given an input of tokens, an attention head produces an matrix $W^{\attn}$ with entries $w_{ij}^{\attn}$ satisfying $\sum_{j=1}^n w_{ij}^{\attn}=1$ and $w_{ij}^{\attn}\ge 0$. From this map, the method defines a symmetric distance
0
so that strong attentions become short edges and weak attentions become long edges (Pollano et al., 2023). For BERT1, this construction is applied to all 144 heads, corresponding to 12 layers times 12 heads.
The resulting distance matrix is then used to build a Vietoris–Rips filtration. At scale 2, the complex is
3
yielding a nested filtration as 4 increases. For each simplicial complex and each homology dimension 5, the method computes
6
with Betti number
7
where 8 counts connected components, 9 loops, and so forth. Persistent homology tracks each homology class by its birth scale 0 and death scale 1, producing a persistence diagram as a multiset of points 2, with never-dying classes assigned 3.
Feature extraction is performed per attention head and per homology dimension 4. The method computes persistence entropy,
5
as well as amplitude under bottleneck and Wasserstein metrics. The bottleneck amplitude is 6, and the Wasserstein amplitude uses 7. Concatenating these quantities over the four homology dimensions and over all 144 heads yields a high-dimensional topological embedding 8, with 9 described as a few hundred in practice. The features are standardized to zero mean and unit variance using an ID validation set.
This pipeline operationalizes a specific hypothesis: topological summaries of attention graphs encode distributional regularities in textual structure that are not identical to the semantic information captured by conventional sentence embeddings. The paper’s later results support that interpretation mainly for far OOD rather than for subtle domain shifts.
3. Training protocol, scoring rules, and empirical profile in text OOD
The transformer-text study trains and validates on headlines and abstracts of “Politics” and “Entertainment” articles from HuffPost News, then evaluates on three OOD regimes: IMDB reviews as far-out-of-domain, CNN/DailyMail article abstracts as near-out-of-domain, and HuffPost “Business” articles as a same-domain shift (Pollano et al., 2023). The comparison baseline is a traditional OOD approach using CLS embeddings, denoted 0 in the detailed description.
Two distance-based scoring functions are used for either the topological embedding 1 or the CLS embedding 2. The first is 3-NN distance with 4, and the second is Mahalanobis distance to class centroids with pooled covariance. The threshold 5 is set so that 95% of ID samples score below 6; any test sample with 7 is flagged OOD. Evaluation uses FPR@95, where lower is better, and AUROC, where higher is better.
Using the pre-trained BERT model and the 8-NN scoring function, the reported results are:
| OOD set | Method | AUROC / FPR95 |
|---|---|---|
| IMDB (far) | TDA | 0.940 / 0.090 |
| IMDB (far) | CLS | 0.680 / 0.875 |
| CNN/DailyMail (near) | TDA | 0.572 / 0.890 |
| CNN/DailyMail (near) | CLS | 0.875 / 0.591 |
| HuffPost Business (same-domain) | TDA | 0.527 / 0.929 |
| HuffPost Business (same-domain) | CLS | 0.580 / 0.921 |
The central empirical pattern is sharply asymmetric. For far OOD, the topological method outperforms CLS embeddings by a large margin, with the IMDB case described as nearly perfect separation at FPR95 of approximately 9%, while CLS fails with FPR95 of approximately 87% (Pollano et al., 2023). For near OOD, the relation reverses: CLS embeddings excel, and TDA cannot distinguish the shift effectively. For same-domain shift, both methods struggle, although CLS improves slightly after fine-tuning on Politics and Entertainment, whereas TDA is described as essentially unchanged under fine-tuning.
The paper interprets this disparity in terms of informational bias. TDA on attention graphs is said to capture grammatical and flow patterns, hence sentence structure, but little lexical semantics. CLS embeddings are semantically sensitive, yet may be “fooled” by topic overlap, as in the reported overlap between IMDB movie-review semantics and entertainment news. A plausible implication is that TextTopoOOD, in this first sense, is not a generic replacement for semantic embeddings but a detector specialized for structural deviations.
4. TextTopoOOD as a benchmark for text-rich networks
In the later graph-centered work, TextTopoOOD is no longer merely a detector; it is a framework for evaluating OOD detection across four families of shifts in text-rich networks (Wang et al., 25 Aug 2025). The motivation is that existing methods mainly address label shifts or rudimentary domain-based splits while overlooking the combined textual-structural diversity present in settings such as social networks, citation graphs, and e-commerce graphs.
The first family is attribute-level shift. One mechanism is text augmentation, written as
9
where 0 controls the fraction of words replaced and 1 controls character-level edits including insert, delete, replace, and swap. Another mechanism is feature mixing on frozen embeddings:
2
As 3, the mixed feature increasingly departs from ID-like representations.
The second family is structural shift. One mechanism rewires structure through a stochastic block model fitted on 4, producing
5
with original graph density preserved and 6 controlling shift intensity. A second mechanism imposes semantic connection by rewiring according to cosine similarity 7 and selecting exactly 8 edges via
9
A third mechanism is text swap, which permutes texts across nodes through a random permutation matrix 0 while controlling the eligible partner pool through “intra-class,” “inter-class,” and “random” variants.
The third family is thematically-guided label shift. Given a full label set 1, a subset 2 of approximately 10–40% of classes is selected and 3. Selection can be random, based on thematic similarity, or based on thematic dissimilarity; in the latter two, an LLM determines lexical or conceptual closeness. At test time, all nodes with labels in 4 are treated as OOD.
The fourth family is domain-based splits derived from natural meta-properties such as publication year:
5
with disjoint time ranges. For Arxiv, the reported setup uses ID from 1960–2015 and OOD from 2017–18, 2018–19, and 2019–20.
This benchmark construction makes an explicit methodological point: OOD in text-rich networks is not reducible to either textual corruption or graph perturbation alone. The framework therefore treats text and topology as jointly shifting modalities rather than as independent nuisance factors.
5. TNT-OOD: joint modeling of text and topology
TNT-OOD is the detector introduced alongside the graph-based TextTopoOOD benchmark. Its architecture combines a structure encoder, cross-attentional fusion, and a HyperNetwork projection to align topological and semantic information for ID nodes and to expose their misalignment for OOD nodes (Wang et al., 25 Aug 2025).
The structure encoder is an 6-layer GCN:
7
This produces structure-aware node features 8.
Cross-attentional fusion then mixes each node’s text embedding 9 with the text of its neighbors $W^{\attn}$0 under guidance from the structure-aware feature $W^{\attn}$1. The mechanism is
$W^{\attn}$2
$W^{\attn}$3
This fuses local structure into node-level text representations.
Instead of a single global projection head, TNT-OOD uses a HyperNetwork to generate node-specific transformation parameters from $W^{\attn}$4. One form is
$W^{\attn}$5
while a factorized alternative is
$W^{\attn}$6
with projected text
$W^{\attn}$7
The projected text is re-injected into a small GCN to re-mix structure and semantic context before classification.
Training uses two losses. The supervised classification term is
$W^{\attn}$8
and the symmetric contrastive loss aligns projected text and post-fusion GCN embedding for ID nodes:
$W^{\attn}$9
with total loss
$w_{ij}^{\attn}$0
At test time, OOD scoring combines energy and alignment:
$w_{ij}^{\attn}$1
$w_{ij}^{\attn}$2
Optional score propagation performs
$w_{ij}^{\attn}$3
The reported experiments span 11 datasets from citation, e-commerce, knowledge, and social domains, using AUROC, AUPR, FPR95, and ID accuracy. Aggregated results state that TNT-OOD achieves the highest average AUROC and AUPR on 9 of 11 datasets and the lowest FPR95 on 8 of 11. On Arxiv semantic and structural shifts, the no-propagation variant “TNT-wo” outperforms all propagation-based baselines, and on Reddit and WikiCS, where text-structure coupling is strong, TNT-OOD improves AUROC by over 20 points (Wang et al., 25 Aug 2025). Ablations report that cross-attention alone raises AUROC by 3–5 points over GNNSafe, that adding the contrastive objective and alignment score further improves separation of $w_{ij}^{\attn}$4 and $w_{ij}^{\attn}$5, and that the HyperNetwork yields the greatest reduction in FPR95, exemplified by ElePhoto moving from 64 to 51 percent.
6. Relation to subsequent TAG OOD work and recurring limitations
The 2026 TAG study “Both Topology and Text Matter” positions itself relative to two strands of prior work: topology-driven methods and LLM-guided methods (Zhu et al., 12 Feb 2026). Its critique of earlier topology-driven approaches is that they typically encode node texts as shallow vector features, while its critique of recent LLM-based methods is a reliability–informativeness imbalance in synthesized OOD priors and dependence on specialized architectures. Although the paper does not use the term TextTopoOOD in the same way as the 2025 benchmark paper, it addresses the same general problem class: OOD detection on text-attributed graphs under interacting textual and structural variation.
LG-Plug first aligns graph and text representations. With graph encoder $w_{ij}^{\attn}$6 and text encoder $w_{ij}^{\attn}$7, it defines a node-level symmetric contrastive loss using
$w_{ij}^{\attn}$8
and an edge-level alignment loss from $w_{ij}^{\attn}$9 and $\sum_{j=1}^n w_{ij}^{\attn}=1$0. It then clusters unlabeled embeddings, applies clustered iterative LLM prompting with a lightweight codebook, and generates a pseudo-OOD exposure set $\sum_{j=1}^n w_{ij}^{\attn}=1$1. This set regularizes any base detector through a margin-based penalty on the OOD score $\sum_{j=1}^n w_{ij}^{\attn}=1$2, while leaving the detector architecture unchanged.
The study reports six benchmarks and compares against classical, topology-driven, and LLM-based baselines. Its key findings are that topology-driven methods outperform classical Euclidean OOD detectors, pure LLM-based priors remain less accurate than strong topology methods, LG-Plug + GNNSafe reduces FPR95 by approximately 7–30% over GNNSafe alone, and LG-Plug + GRASP achieves new state-of-the-art with 5–15% FPR95 gains over all baselines (Zhu et al., 12 Feb 2026). These results reinforce the broader claim that neither topology-only nor text-only signals suffice in general.
Across the three papers, several limitations recur. In the transformer-text setting, TDA features capture structural regularities but show limited lexical awareness, which degrades performance on near-domain and same-domain shifts (Pollano et al., 2023). In the text-rich network setting, TNT-OOD is motivated precisely by the need to close the gap between semantic and structural modalities, implying that unimodal or weakly coupled treatments are insufficient (Wang et al., 25 Aug 2025). In LG-Plug, cluster quality and prompt engineering remain explicit practical concerns, indicating that topology-text alignment alone does not eliminate all sources of uncertainty (Zhu et al., 12 Feb 2026).
Taken together, these works suggest a stable conceptual lesson. TextTopoOOD, whether understood as attention-topology OOD detection for transformer text or as a benchmark for text-rich networks, marks a shift from purely semantic or purely geometric detection toward representations that preserve structural organization. The empirical record in the provided studies indicates that this shift is most effective when topology and text are modeled jointly rather than treated as interchangeable surrogates.