How Do Transformers Align Tokens?
Abstract
How can language models align words in translated sentences with different syntactic structures? Can they compute edit distances—or even sort arbitrary sequences? These tasks are examples of *assignment problems*. We prove a carefully engineered prompt enables a transformer to approximate the solution of assignment. This prompt induces attention layers to simulate gradient descent on the dual objective of assignment. We establish an **explicit approximation bound** that improves with transformer depth. A striking implication is that a single transformer can sort inputs of **arbitrary** length—proving a form of *out-of-distribution generalization*.
BibTeX
@inproceedings{daneshmand2025how,
author = {Hadi Daneshmand},
title = {{How Do Transformers Align Tokens?}},
booktitle = {DiffCoALG @ NeurIPS},
year = {2025},
url = {https://openreview.net/forum?id=eulUHNBpmx},
}Ask Althea to put this paper to the test.
Loading related content...