Findings of ACL 2024

SPIN: Sparsifying and Integrating Internal Neurons in Large Language Models for Text Classification

We introduce SPIN, a framework that reads a frozen language model’s internal representations for text classification. It reduces classification errors by up to 71.4% compared with classifiers that use only the final layer. SPIN approaches fully fine-tuned state-of-the-art performance while training thousands of times fewer parameters; it can also skip 40% of the model’s layers at inference with little or no loss in accuracy.

A conventional text classifier reads the model’s final layer. SPIN sparsifies and integrates internal neurons across layers: we train a small linear probe at each layer to select task-relevant neurons, then combine their representations in a classification head. The model’s weights stay untouched; only the probes and the head are trained.

Performance across model families

We evaluate SPIN on IMDb movie reviews, SST-2 sentiment classification and EDOS sexism detection. The eight pretrained backbones cover encoder, decoder and encoder-decoder architectures. In each comparison, the baseline and SPIN use the same frozen backbone and train a classifier with the dataset’s labels. The difference is which internal representations they read.

Final layerSPIN

IMDb: Up to 59.2% fewer errors

SST-2: Up to 71.4% fewer errors

EDOS: Up to 25.0% higher macro-F1

Each version of SPIN outperforms its corresponding baseline on all three benchmarks. For Flan-T5-S on EDOS, macro-F1 rises from 59.62 to 74.51, a relative improvement of about 25%.2 SPIN also improves models whose baseline performance is already high: GPT2-XL’s IMDb accuracy increases from 91.86% to 94.92%.

With Flan-T5-XL, SPIN reaches 96.12% accuracy on IMDb, compared with 96.21% for fully fine-tuned XLNet, the published state-of-the-art reference used in the paper. Compared with Flan-T5-XL’s own final-layer classifier, SPIN reduces the error rate from 9.50% to 3.88%, a 59.2% reduction.

Full benchmark results
BackboneIMDbSST-2EDOS
BaseSPINBaseSPINBaseSPIN
DistilBERT86.9589.7881.8883.9465.0975.79
RoBERTa89.6793.6184.0690.5968.8173.50
GPT287.7291.9485.8987.7368.5776.08
GPT2-M88.5993.9286.1290.2571.1775.74
GPT2-XL91.8694.9290.0293.2372.5676.79
Flan-T5-S84.0891.1577.1788.9959.6274.51
Flan-T590.0194.1478.2692.3266.6478.04
Flan-T5-XL90.5096.1284.7595.6470.0881.48
Fine-tuned reference (2024)96.2197.5082.35
All eight pretrained backbones on the three main benchmarks. IMDb and SST-2 report accuracy; EDOS reports macro-F1. All scores are percentages. Base uses final-layer representations. The final row gives the published fine-tuned reference results reported in the 2024 paper. Source: Table 1.

Further experiments extend the comparison to larger models and more classes. On LLaMA2-13B, IMDb accuracy rises from 94.55% to 96.06%. On AG News, SPIN improves all three tested backbones using multinomial logistic regression as the probe and classification head.

Larger models and multiclass results
BackboneDatasetBaseSPIN
LLaMA2-7BIMDb94.0495.76
LLaMA2-13BIMDb94.5596.06
DistilBERTAG News91.1892.21
GPT2AG News90.6492.19
Flan-T5-SAG News85.6891.89
Accuracy on pretrained LLaMA2 models for IMDb and on three backbones for AG News topic classification.

Lower training cost, earlier predictions

SPIN never backpropagates through the language model. Training consists of forward passes with frozen weights to record the representations, then fitting the linear probes and classification head on those recordings. For GPT2-XL, that means training about one million parameters instead of 1.6 billion.

Trainable parameters

Parameters trained by SPIN compared with all parameters in the backbone, labeled Base, across six models on a log scale.

Estimated training compute

Estimated training FLOPs for the final-layer baseline, SPIN and full fine-tuning across six backbones, on a log scale.
Left: parameters trained by SPIN compared with updating the full backbone (Base). Right: estimated training operations for a final-layer classifier (Base), SPIN and one epoch of full fine-tuning on IMDb. Both plots use a log scale; SPIN uses feed-forward activations with a sparsification threshold of 0.5.

The forward passes dominate SPIN’s training cost. It uses only slightly more compute than training a final-layer classifier, and less than half the estimated operations of a single epoch of full fine-tuning. The probes can be fitted independently on the recorded representations.

At inference, SPIN can classify text using only the layers up to a chosen exit point. With 60% of its layers, GPT2-XL reaches 94.73% IMDb accuracy, compared with 94.92% at full depth. Flan-T5 and Flan-T5-XL reach their full-depth accuracy at 60%. The useful exit point depends on the backbone: DistilBERT loses more than two points at the same depth.

Accuracy at each exit depth
Backbone20%40%60%80%100%
DistilBERT85.2084.7387.4588.6789.78
RoBERTa87.0689.7293.1393.5093.61
GPT287.5189.0091.1091.8891.94
GPT2-M88.5291.3693.3693.9293.92
GPT2-XL89.6693.1594.7394.9294.92
Flan-T5-S82.8887.7490.9391.3291.32
Flan-T584.5892.5594.1494.1494.14
Flan-T5-XL89.2195.2896.1296.1296.12
IMDb accuracy when SPIN exits after the given percentage of each backbone’s layers.

Further gains after fine-tuning

SPIN needs only access to a model’s internal representations, so it can also be applied after the model has been fine-tuned for a task. On publicly available fine-tuned DistilBERT, RoBERTa and GPT2 checkpoints, SPIN improves on the model’s own classifier in every available comparison.

BackboneIMDbSST-2EDOS
BaseSPINBaseSPINBaseSPIN
DistilBERT92.8092.8891.0591.1978.7481.12
RoBERTa94.6795.6894.0394.3880.4880.88
GPT294.0694.5091.5192.32n/an/a
Public fine-tuned checkpoints with their own classifier (Base) and with SPIN on top. IMDb and SST-2 report accuracy; EDOS reports macro-F1. GPT2 fine-tuned on EDOS was not publicly available.

The gains here are smaller, often under one point, because the fine-tuned model has already adapted to the task. Five-fold cross-validation on IMDb confirms that all three improvements are significant at p < 0.05. On a LoRA-fine-tuned DistilBERT, SPIN raises IMDb accuracy from 87.71% to 90.58%.

Reading the prediction through a text

A classifier trained on pooled sentence representations can also be applied token by token. In the IMDb review below, both classifiers track shifts in sentiment as the text unfolds.3 SPIN shows clearer changes at turns such as “yet somehow”, “despite” and “nonetheless”.

A movie review with each token shaded red or green by the baseline classifier's token-wise sentiment prediction. The overall baseline score is 0.76. (a) Baseline
The same movie review shaded by SPIN's token-wise sentiment prediction, with clearer shifts at contrastive words. The overall SPIN score is 0.99. (b) SPIN
The same IMDb review, read token by token by the baseline (top) and SPIN (bottom). Red marks negative sentiment and green marks positive sentiment. Both classifiers use GPT2-XL with max pooling; the score after the text is the sentence-level prediction.

For encoder models, SPIN’s use of representations from all tokens also allows direct transfer to token-wise predictions; a conventional [CLS]-based classifier needs repeated passes over sliding windows.

What the selected neurons reveal

SPIN can be inspected at two levels: the individual neurons selected by the probes, and the classifier built from them. In this GPT2-XL example, later-layer neurons distinguish positive and negative reviews more clearly, while combining neurons across layers separates the classes more cleanly than any individual neuron shown.

Sentiment prediction distributions at increasing GPT2-XL layer depths. The upper row shows integrated SPIN classifiers and their accuracy; the lower rows show the most salient individual neurons. Red denotes negative reviews and green positive reviews.
Integrated classifiers (top row) and selected individual neurons (rows below) at different depths of GPT2-XL. Red denotes negative reviews and green denotes positive reviews. More separated distributions distinguish the classes more clearly.

Why look beyond the final layer?

Interpretability research has repeatedly found task-relevant information inside language models. Radford et al. (2017) identified a single neuron that classifies sentiment;4 later work used selected transformer neurons as classifiers. SPIN builds on these observations to make a general classification method that works across model families.

A final-layer classifier uses a single representation of the text. SPIN gives the classifier access to selected features from several depths, combining simpler features in lower layers with more abstract ones higher up. Filtering matters: irrelevant neurons add noise that dilutes the features useful for the task.

The baseline sends final-layer hidden states to a classifier. SPIN selects neurons within each layer and combines their representations in a classification head.
The baseline reads the final hidden states. SPIN selects internal neurons within each layer and combines their representations in a classification head. The backbone stays frozen.

Both parts of SPIN contribute. On GPT2-XL and IMDb, selecting one neuron per layer with the probes gives 93.71% accuracy, compared with 69.90% for random selection.5 Combining layers also outperforms the best individual layer at every exit depth we tested.

Neuron selection and integration in more detail

We pool each layer’s hidden states or feed-forward activations over tokens to obtain a fixed-size vector. An L1-regularized logistic regression then predicts the task label from that layer’s representations. The penalty pushes many weights to zero; we normalize the remaining weight magnitudes and keep the smallest set whose cumulative weight reaches a chosen threshold.

At a threshold of 0.4, SPIN keeps about 3% of the neurons in each layer in this analysis. The selected representations are concatenated into one feature vector, and a linear classification head is trained on it.

Top: IMDb accuracy against the sparsification threshold for eight backbones; the curves rise until a threshold of about 0.2 and then flatten. Bottom: stacked bars showing the share of neurons selected at each threshold, which stays small.
IMDb accuracy (top) and the fraction of neurons selected (bottom) as the sparsification threshold increases. A small set of neurons carries most of the usable classification signal.
Neurons per layerRandomProbe (SPIN)
169.9093.71
574.7894.24
1082.7594.42
5087.0194.47
10090.9894.63

IMDb accuracy of GPT2-XL with neurons selected by the probes or at random.

Layers usedBest single layerIntegrated (SPIN)
887.1788.34
1689.8492.09
2492.7294.70
3294.1294.91
4892.4194.92

IMDb accuracy of GPT2-XL using the best individual layer or the integrated neurons up to each depth.

The approach requires access to internal representations, so it cannot be used through a text-only API. We kept the classification head linear to match prior work and make its inputs inspectable; a more sophisticated head could improve accuracy. The paper includes the mathematical formulation, hyperparameter settings and remaining experiments.

For the tasks we studied, intermediate representations provide useful features even when the backbone’s weights stay fixed. SPIN shows how selecting and combining those features can improve classification, reduce adaptation cost and make predictions before the final layer.