Transformer Feed-Forward Layers Build Predictions by Promoting Concepts in the Vocabulary Space

Mor Geva, Avi Caciularu, Kevin Ro Wang, Yoav Goldberg
3/28/2022
cs.CL
transformer-attention

Official code: aviclu/ffn-values (68 stars, Jupyter Notebook, last commit 2023-05-18).

Abstract

Transformer-based language models (LMs) are at the core of modern NLP, but their internal prediction construction process is opaque and largely not understood. In this work, we make a substantial step towards unveiling this underlying prediction process, by reverse-engineering the operation of the feed-forward network (FFN) layers, one of the building blocks of transformer models.

Show full abstract

We view the token representation as a changing distribution over the vocabulary, and the output from each FFN layer as an additive update to that distribution. Then, we analyze the FFN updates in the vocabulary space, showing that each update can be decomposed to sub-updates corresponding to single FFN parameter vectors, each promoting concepts that are often human-interpretable. We then leverage these findings for controlling LM predictions, where we reduce the toxicity of GPT2 by almost 50%, and for improving computation efficiency with a simple early exit rule, saving 20% of computation on average.

View on arXivView PDF

Code Implementations(1)

aviclu/ffn-valuesOfficial100%
688Jupyter Notebook, PythonMar 20, 20223 years ago

Similar Papers

Cite this paper

@article{geva2022transformer,
  title  = {Transformer Feed-Forward Layers Build Predictions by Promoting Concepts in the Vocabulary Space},
  author = {Mor Geva and Avi Caciularu and Kevin Ro Wang and Yoav Goldberg},
  year   = {2022},
  eprint = {2203.14680},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2203.14680}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2203.14680.svg)](https://codeofpaper.com/paper/2203.14680)

Discussion