Encoding and Propagation of Grammatical Number in Large Language Models
Organizations: University of Minnesota
Abstract
Sparse autoencoders (SAEs) have become an increasingly popular means of translating Large Language Model (LLM) hidden state vectors into a human-comprehensible list of features or symbols. As such, SAEs may provide insight into an LLM's knowledge representation and internal mental'' grammar - topics of pragmatic interest for mechanistic interpretation of AI behavior and of theoretical interest for the study of in silico representations of human language. Language models with fewer than 100M parameters, trained on small corpora, nonetheless exhibit strong grammatical competence and discourse coherence, despite producing content of limited reliability. We use SAEs that we trained on one such model (Pythia-70M) to conduct an in-depth examination of how a single grammatical phenomenon, number agreement, is represented and processed in an LLM. We demonstrate the mechanism and the methodology by which SAEs can be used to find and propagate plural noun'', plural matrix subject'', and generate a plural verb'' features which cause the LLM to produce plural verb forms such as are'', do'', or have'' instead of is'', does'', and has'' in response to prompts such as the men in the park''. We show that intervening to remove these features from the hidden states of plural subject noun tokens causes the model to produce singular verbs instead, and vice versa. We also show that corresponding singular noun'' and ``generate a singular verb'' features are not as effective for this task. This asymmetry suggests that Pythia-70m makes use of a privative representation of grammatical number in English. These findings replicated with larger LLMs Gemma-2-2b and Llama-3.1-8b yielded similar results. Our main contribution is a novel approach to the use of SAEs to understanding how LLMs encode human language that addresses a number of technical and methodological challenges.
Figures & tables
| LLM | Dataset | Feature | ||
| Gemma-2-2b | rc | we:533 | 0.56 | 0.26 |
| ” | ” | we:18 | 0.34 | 0.03 |
| ” | ” | we:2645 | 0.22 | 0.01 |
| ” | nounpp | we:533 | 0.47 | 0.25 |
| ” | within_rc | we:533 | 1.10 | 0.37 |
| ” | ” | we:18 | 0.64 | -0.04 |
Appendix figures & tables5 assets
Supplementary material from the paper’s appendix.
Appendix
| Name | Variable | Dimension |
|---|---|---|
| Token vocabulary | ||
| Embedding matrix | ||
| Unembedding matrix | ||
| Query matrix at attention sublayer in head | ||
| Query bias at “ | ||
| Key matrix at “ |
| Name | Variable | Dimension |
|---|---|---|
| Prompt Token indices | or | prompt length |
| Initial embeddings for token at index or for token “ man” | \color[rgb]{1,0,1}{r_{j}^{0}} or \color[rgb]{1,0,1}{r_{\text{`` man''}}^{0}} | |
| Residual stream for token /“ man” after layer | \color[rgb]{1,0,1}{r_{j}^{\ell}} or \color[rgb]{1,0,1}{r_{\text{`` man''}}^{\ell}} | |
| Normed attention layer input for layer | {\color[rgb]{1,0.5,0}r_{j}^{{\ell-1}:attnnorm}} or {\color[rgb]{1,0.5,0}r_{\text{`` man''}}^{{\ell-1}:attnnorm}} | |
| Key for ” at attention head of layer | \color[rgb]{0,0,1}{k_{j}^{(n,\ell)}} or \color[rgb]{0,0,1}{k_{\text{`` man''}}^{(n,\ell)}} | |
| Query for ” | \color[rgb]{0,0.6,0}{q_{j}^{(n,\ell)}} or \color[rgb]{0,0.6,0}{q_{\text{`` man''}}^{(n,\ell)}} |
| Name | Index Variable | Size variable | Size in Pythia-70m |
| Vocab size | 50304 | ||
| Hidden size | 512 | ||
| Number of layers | 6 | ||
| Number of attention heads | 8 | ||
| Attention head size | |||
| MLP Intermediate size | 2048 |
LLM Interpretability
Large language model (LLM) interpretability studies how internal representations and computations produce outputs, and how they can be explained or controlled.
See all 806 papers