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

BERTops: Studying BERT Representations under a Topological Lens

Jatin Chauhan, Manohar Kaul

Abstract

Proposing scoring functions to effectively understand, analyze, and learn various properties of high-dimensional hidden representations of large-scale transformer models like BERT can be a challenging task. In this work, we explore a new direction by studying the topological features of BERT hidden representations using persistent homology (PH). We propose a novel scoring function named "persistence scoring function (PSF)" which: (i) accurately captures the homology of the high-dimensional hidden representations and correlates well with the test set accuracy of a wide range of datasets and outperforms existing scoring metrics, (ii) captures interesting post fine-tuning "per-class" level properties from both qualitative and quantitative viewpoints, (iii) is more stable to perturbations as compared to the baseline functions, which makes it a very robust proxy, and (iv) finally, also serves as a predictor of the attack success rates for a wide category of black-box and white-box adversarial attack methods. Our extensive correlation experiments demonstrate the practical utility of PSF on various NLP tasks relevant to BERT.

Introduction

Large-scale transformer models like BERT have revolutionized natural language processing, yet they remain notoriously difficult to interpret. These "black boxes" are typically evaluated using held-out test sets or by running computationally expensive adversarial attacks—simulations that can take upwards of 15 hours for a small sample of sentences. There is a critical need for intrinsic metrics that can evaluate a model's generalization and vulnerability without relying on external labels or exhaustive simulations.

BERTops addresses this by examining the "shape" of BERT’s hidden representations through the lens of Topological Data Analysis (TDA). By analyzing the underlying connectivity and structure of data in high-dimensional space, the authors provide a more robust proxy for model performance and safety.

Methodology: Persistent Homology and PSF

The core innovation of this research is the application of Persistent Homology (PH) to transformer latent spaces. PH functions by imagining "balls" of increasing radii around data points. As these balls expand and merge, they form topological features such as connected components (0-dimensional) and loops or tunnels (1-dimensional).

Persistence Scoring Function (PSF)

The "birth" and "death" of these topological features are recorded in persistence diagrams. Features that persist over a wide range of scales are considered true structural properties, while short-lived features are dismissed as noise. The authors propose the Persistence Scoring Function (PSF), a novel metric that aggregates these birth-death pairs into a single score. This score effectively measures the compactness and structural integrity of the data clusters in the hidden layers.

Computational Efficiency

To ensure the method scales to large NLP datasets, the researchers utilize Kernel Density Estimation (KDE). This allows for intelligent downsampling of data points before running the topological analysis, maintaining the structural essence of the representation while significantly reducing the computational burden.

Experimental Results

The authors validated PSF across 10 diverse NLP datasets, including multi-class classification (e.g., AG News, Yahoo Answers) and sentiment polarity tasks (e.g., SST-2, IMDB).

1. Accuracy Estimation

PSF demonstrated a strong negative correlation with test accuracy (Spearman rank correlation of -0.515). This indicates that as the PSF score decreases—meaning the topological representation becomes more compact and well-defined—the model's performance improves. PSF outperformed standard baselines such as the Silhouette Coefficient and the Davies Bouldin Index in this regard.

2. Adversarial Vulnerability Prediction

PSF proved to be a powerful predictor of a model's susceptibility to adversarial attacks. High PSF scores indicate "looser" representations where data points reside near decision boundaries, making them easy targets for manipulation. PSF outperformed the state-of-the-art baseline (ALID) by over 200% across four major attack categories, including TextFooler and Genetic Algorithms.

3. Stability and Robustness

Unlike traditional metrics, PSF is remarkably stable under noise. In tests where Gaussian noise was added to input embeddings, PSF’s correlation with performance dropped by only 0.014, whereas other metrics fluctuated significantly. This makes PSF a highly reliable "thermometer" for assessing model health in real-world, noisy environments.

4. Class-Level Insights

PSF allows for granular, per-class analysis. For instance, in the DBPedia 14 dataset, the researchers found that classes with high PSF scores (indicating loose topological shapes) consistently yielded lower F1-scores, while compact classes like "Sports" showed high performance. This allows developers to identify exactly which categories a model is struggling to represent internally.

Conclusion and Future Work

BERTops introduces a robust topological framework for peering into the hidden mechanics of BERT. By quantifying the "shape" of representations through PSF, researchers can predict accuracy and adversarial risk without the need for labeled test data. While the metric currently struggles with specific attack types like Universal Adversarial Triggers (UAT), future work aims to extend this topological lens to other architectures like T5 and GPT, and to more complex tasks such as machine translation and summarization.

Summary updated

Abstract

Proposing scoring functions to effectively understand, analyze and learn various properties of high dimensional hidden representations of large-scale transformer models like BERT can be a challenging task. In this work, we explore a new direction by studying the topological features of BERT hidden representations using persistent homology (PH). We propose a novel scoring function named "persistence scoring function (PSF)" which: (i) accurately captures the homology of the high-dimensional hidden representations and correlates well with the test set accuracy of a wide range of datasets and outperforms existing scoring metrics, (ii) captures interesting post fine-tuning "per-class" level properties from both qualitative and quantitative viewpoints, (iii) is more stable to perturbations as compared to the baseline functions, which makes it a very robust proxy, and (iv) finally, also serves as a predictor of the attack success rates for a wide category of black-box and white-box adversarial attack methods. Our extensive correlation experiments demonstrate the practical utility of PSF on various NLP tasks relevant to BERT.

Empirical ResultsBrowse all benchmarks →

BenchmarkMethodMetricScoreProtocol / Evidence
Multiple datasets · Test set accuracy across datasetsPersistence scoring function (PSF)Spearman rank correlation (ρ)-0.515Image Classification · split: test · fine-tuned
Source quote
L128: As baselines, we compare to the popular Silhouette coefficient (SC) \cite{rousseeuw_198753}, where we subtract the value of SC on each dataset from 1 to ensure consistency in experiments, and the Davies Bouldin index (DBI) \cite{davies_bouldin_4766909}. Both these methods have been widely used in the literature to assess the quality of the learned representations of the data by machine learning models. For reference, we point the reader to the works by\cite{chauhan2020FEW, article_dbi}. Figure \ref{fig:acc_predictor} shows the dataset accuracies versus the PSF values of the different estimator functions. We can observe that PSF, with a stronger negative correlation of -0.515, outperforms both SC and DBI with a correlation of -0.442, thus affirming our claims.
Multiple datasets · Class-label F1-scores across datasetsPersistence scoring function (PSF)Spearman correlation (ρ) between classwise PSF and F1-scores-0.685Image Classification · fine-tuned
Source quote
L135: We further conduct experiments to show that PSF can also be used for a more fine-grained analysis at a class-wise level and capture interesting properties about the same class labels across multiple datasets. This is done by calculating the Spearman correlation (\rho) of the f1-scores of the class labels to the corresponding class-wise PSF values. Similar to the previous experiment, we expect a strong negative correlation. Note that here we concatenate the PSF of the class labels across all the datasets in a single array (as opposed to averaging over an entire dataset). As shown in figure \ref{fig:label_wise}, PSF achieves a strong negative correlation of -0.685.
BibTeX
@misc{chauhan2022bertops,
  author = {Jatin Chauhan and Manohar Kaul},
  title = {{BERTops: Studying BERT Representations under a Topological Lens}},
  year = {2022},
  eprint = {2205.00953},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2205.00953},
}
Figure