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