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

NeuroX Library for Neuron Analysis of Deep NLP Models

Fahim Dalvi, Hassan Sajjad, Nadir Durrani

Abstract

Deep NLP models, particularly Transformer-based architectures like BERT and GPT, are often criticized for their lack of interpretability. While attention mechanisms and feature attribution provide some insight into model behavior, understanding the role of individual neurons remains a significant challenge. This paper introduces NeuroX, an open-source Python toolkit designed to facilitate neuron-level analysis. NeuroX unifies disparate interpretation methods—ranging from linear probing to redundancy analysis—into a single, scalable pipeline. By addressing practical hurdles such as subword de-segmentation and computational efficiency, NeuroX enables researchers to identify, visualize, and manipulate the internal representations of state-of-the-art models.

1. Introduction

The rapid advancement of deep learning in Natural Language Processing (NLP) has led to models of unprecedented complexity. Despite their performance, these models remain "black boxes," where the internal logic governing their predictions is difficult to decipher. Existing interpretability research has largely focused on two areas: feature attribution (identifying which input tokens are important) and attention visualization (mapping relationships between tokens). However, there is a critical gap in tools that perform neuron analysis—the process of identifying and ranking individual dimensions in a representation based on their contribution to specific linguistic properties.

NeuroX addresses this gap by providing a comprehensive suite of tools to analyze deep NLP models at the individual neuron level. It allows researchers to move beyond "what" a model predicts to "how" specific components within the architecture represent knowledge.

2. The NeuroX Framework

NeuroX is structured as a modular pipeline designed to handle the end-to-end process of neuron interpretation. The library is divided into three primary modules: Data Processing, Interpretation, and Analysis.

2.1 Data Processing and De-segmentation

One of the primary challenges in analyzing modern NLP models is the use of subword tokenization (e.g., Byte-Pair Encoding). Because different models segment the same word differently, mapping internal activations back to human-readable linguistic annotations is non-trivial. NeuroX includes a De-segmentation utility that aligns subword activations back to whole words, ensuring that representations can be compared across different architectures. Additionally, the library provides an Annotation Helper to label datasets using regex or custom functions, facilitating the study of specific linguistic phenomena even when pre-annotated corpora are unavailable.

2.2 Interpretation and Ranking

The core of NeuroX lies in its ability to rank neurons based on their relevance to a given task or concept. The library implements several state-of-the-art methods:

  • Linear Probes: Training simple classifiers to determine if a neuron's activation can predict a specific linguistic label (e.g., part-of-speech).
  • Probeless/Mean Select: Unsupervised methods that rank neurons based on activation patterns without the need for auxiliary model training.
  • Redundancy Analysis: A clustering-based approach used to identify groups of neurons that perform similar functions, helping to simplify the model's internal logic.

2.3 Analysis and Evaluation

Once neurons are ranked, NeuroX provides tools to validate these findings. This includes Ablation (systematically suppressing neurons to observe the impact on model performance), Classifier Accuracy (measuring how well a subset of neurons represents a concept), and Visualization (generating heatmaps of neuron activity over raw text).

3. Key Insights and Design Principles

NeuroX was developed with several practical considerations for the modern NLP researcher:

  • Redundancy as a Feature: The library recognizes that large networks often learn redundant representations to ensure robustness. NeuroX’s redundancy tools allow researchers to quantify this overlap and identify the "minimal set" of neurons required for a specific task.
  • Computational Efficiency: Analyzing thousands of neurons across massive datasets is resource-intensive. NeuroX introduces a 16-bit precision mode (FP16), significantly reducing memory and disk usage while maintaining the integrity of the interpretation results.
  • Unified API: By providing a single interface for multiple probing and ranking methods, NeuroX enables "plug-and-play" experimentation. This allows researchers to easily verify if different interpretation methods converge on the same set of "important" neurons.

4. Experimental Demonstration

The utility of NeuroX has been demonstrated across several models, including BERT, RoBERTa, XLNet, and GPT-2. The toolkit has successfully identified "specialist" neurons that capture specific linguistic concepts. For example, in RoBERTa, NeuroX identified Layer 2, Neuron 343 as a specialist for "Years of the Century," and Layer 2, Neuron 750 as a specialist for "Gerund Verbs."

Furthermore, the library enables cross-model comparisons, showing how different architectures distribute linguistic information across their layers. Because NeuroX is fully compatible with the HuggingFace transformers ecosystem, it can be applied to thousands of pre-trained models with minimal configuration.

5. Conclusion and Future Work

NeuroX provides a standardized, scalable foundation for neuron-level interpretability in NLP. While the current version focuses on correlation and probing, future iterations aim to expand into attribution-based saliency methods and more sophisticated causal interventions. By lowering the barrier to entry for neuron analysis, NeuroX empowers the research community to better understand the internal mechanics of the models that define the current state of the art.

Summary updated

BibTeX
@inproceedings{dalvi2023neurox,
  author = {Fahim Dalvi and Hassan Sajjad and Nadir Durrani},
  title = {{NeuroX Library for Neuron Analysis of Deep NLP Models}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.acl-demo.21},
}
Figure