Knowledge Neurons in Pretrained Transformers

Damai Dai, Li Dong, Yaru Hao, Zhifang Sui, Furu Wei

Large language models (LLMs) like BERT and GPT act as massive digital encyclopedias, capable of recalling facts such as the capital of Ireland or the team a specific athlete plays for. However, the internal mechanism of how this information is stored has long remained a "black box." Researchers from Peking University and Microsoft Research have identified specific units within the Feed-Forward Network (FFN) layers of Transformers, termed knowledge neurons, that appear responsible for storing and expressing individual factual relations.

Identifying the "Brain Cells" of Facts

To pinpoint these neurons, the authors developed a two-step "knowledge attribution" method:

  1. Knowledge Attribution: Inspired by Integrated Gradients, the researchers calculate an attribution score for each neuron by integrating the gradients of the correct output probability as a neuron's activation is scaled from zero to its original value. High scores indicate a significant influence on the model's factual prediction.
  2. Knowledge Neuron Refining: To filter out neurons responsible for general syntax or grammar, they test facts using multiple diverse prompts (e.g., "Dublin is the capital of [X]" vs. "[X]'s capital city is Dublin"). Only neurons consistently ranked highly across different formulations are identified as true knowledge neurons.
Overview of knowledge attribution, linking factual knowledge to specific neurons in the Feed-Forward Network.

Insights into Knowledge Storage

The study reinforces the hypothesis that FFN layers—which comprise roughly two-thirds of a Transformer's parameters—function as the model's primary key-value memory for factual data.

One of the most striking findings is the top-heavy distribution of these neurons. Knowledge neurons are not evenly distributed throughout the model; instead, they are predominantly concentrated in the topmost layers. This suggests a functional hierarchy where lower layers handle general linguistic features and syntax, while higher layers specialize in factual retrieval and semantic expression.

Distribution of identified knowledge neurons across Transformer layers, showing a concentration in the upper layers.

Furthermore, facts are surprisingly localized. On average, only 2 to 5 neurons are responsible for a specific relational fact. There is a clear causal link: suppressing these few neurons drastically reduces the model's ability to recall the fact, while amplifying their activation increases the model's confidence.

Knowledge Surgery and Results

Identifying these neurons enables "Knowledge Surgery"—the ability to update or erase specific facts without expensive retraining. By modifying only about four neurons, the researchers achieved a 34.4% success rate in updating a fact to a new target (e.g., changing a person's place of birth) with negligible impact on unrelated knowledge.

In suppression tests, turning off identified knowledge neurons decreased the probability of the correct answer by 29.03% on average, significantly outperforming baseline methods. Conversely, zeroing out neurons associated with an entire relation (like place_of_birth) effectively "erased" that type of knowledge from the model, increasing uncertainty for those specific facts by over 100%.

Conclusion and Future Directions

This research provides a significant step forward in model interpretability. By locating the specific parameters where facts reside, we move closer to models that can be edited, corrected, and audited for factual accuracy. Future work will look to extend these methods to multi-token entities and explore whether knowledge neurons for the same facts are shared across different languages in multilingual models.

Summary updated

BibTeX
@inproceedings{dai2022knowledge,
  author = {Damai Dai and Li Dong and Yaru Hao and Zhifang Sui and Furu Wei},
  title = {{Knowledge Neurons in Pretrained Transformers}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2022},
  doi = {10.18653/v1/2022.acl-long.581},
}
Figure