Formal Algorithms for Transformers

Authors: Mary Phuong, Marcus Hutter

Latest 2022 version at http://www.hutter1.net/publ/transalg.pdf
Submitted to arXiv on 19 Jul. 2022
License: CC BY 4.0
Abstract

This document aims to be a self-contained, mathematically precise overview of transformer architectures and algorithms (*not* results). It covers what transformers are, how they are trained, what they are used for, their key architectural components, and a preview of the most prominent models. The reader is assumed to be familiar with basic ML terminology and simpler neural network architectures such as MLPs.

The papers around it, by date and closeness

Higher is closer to this paper; left is older. Lines join papers close to each other: groups of lines are sub-topics. Select a point to see why it is there. Back to the summary of this paper

How to read this map? Illustrated guide

Closest papers Prior work it builds on Papers that cite it

Papers around this one

Ranked by how close their title and abstract are to this paper’s. Select some to read them together.

Closest papers

  1. Very close
    Introduction to Transformers: an NLP Perspective
    Tong Xiao, Jing-Bo Zhu · 2023 · arXiv.org · preprint, not peer reviewed · cited 37 times · Not summarized yet
    Abstract

    Transformers have dominated empirical machine learning models of natural language processing. In this paper, we introduce basic concepts of Transformers and present key techniques that form the recent advances of these models. This includes a description of the standard Transformer architecture, a series of model refinements, and common applications. Given that Transformers and related deep learning techniques might be evolving in ways we have never seen, we cannot dive into all the model details or cover all the technical areas. Instead, we focus on just those concepts that are helpful for gaining a good understanding of Transformers and their variants. We also summarize the key ideas that …

  2. Very close Cites this paper
    An Introduction to Transformers
    Richard E. Turner · 2023 · Machine Learning · preprint, not peer reviewed · AI summary available
    Abstract

    The transformer is a neural network component that can be used to learn useful representations of sequences or sets of datapoints. The transformer has driven recent advances in natural language processing, computer vision, and spatio-temporal modelling. There are many introductions to transformers, but most do not contain precise mathematical descriptions of the architecture and the intuitions behind the design choices are often also missing. Moreover, as research takes a winding path, the explanations for the components of the transformer can be idiosyncratic. In this note we aim for a mathematically precise, intuitive, and clean description of the transformer architecture.

  3. Very close
    On the Universality of Transformer Architectures; How Much Attention Is Enough?
    Amirreza Abbasi, M. Hooshmand · 2025 · arXiv.org · preprint, not peer reviewed · Not summarized yet
    Abstract

    Transformers are crucial across many AI fields, such as large language models, computer vision, and reinforcement learning. This prominence stems from the architecture's perceived universality and scalability compared to alternatives. This work examines the problem of universality in Transformers, reviews recent progress, including architectural refinements such as structural minimality and approximation rates, and surveys state-of-the-art advances that inform both theoretical and practical understanding. Our aim is to clarify what is currently known about Transformers expressiveness, separate robust guarantees from fragile ones, and identify key directions for future theoretical research.

  4. Very close Cites this paper
    What Formal Languages Can Transformers Express? A Survey
    Lena Strobl, William Merrill, G. Weiss et al. · 2023 · Transactions of the Association for Computational Linguistics · cited 172 times · Not summarized yet
    Abstract

    As transformers have gained prominence in natural language processing, some researchers have investigated theoretically what problems they can and cannot solve, by treating problems as formal languages. Exploring such questions can help clarify the power of transformers relative to other models of computation, their fundamental capabilities and limits, and the impact of architectural choices. Work in this subarea has made considerable progress in recent years. Here, we undertake a comprehensive survey of this work, documenting the diverse assumptions that underlie different results and providing a unified framework for harmonizing seemingly contradictory findings.

  5. Close
    Automata Extraction from Transformers
    Yi-Hao Zhang, Zeming Wei, Meng Sun · 2024 · arXiv.org · preprint, not peer reviewed · cited 2 times · Not summarized yet
    Abstract

    In modern machine (ML) learning systems, Transformer-based architectures have achieved milestone success across a broad spectrum of tasks, yet understanding their operational mechanisms remains an open problem. To improve the transparency of ML systems, automata extraction methods, which interpret stateful ML models as automata typically through formal languages, have proven effective for explaining the mechanism of recurrent neural networks (RNNs). However, few works have been applied to this paradigm to Transformer models. In particular, understanding their processing of formal languages and identifying their limitations in this area remains unexplored. In this paper, we propose an automat…

  6. Close Cites this paper
    Transformadores: Fundamentos teoricos y Aplicaciones
    J. de la Torre · 2023 · arXiv.org · preprint, not peer reviewed · Not summarized yet
    Abstract

    Transformers are a neural network architecture originally developed for natural language processing, which have since become a foundational tool for solving a wide range of problems, including text, audio, image processing, reinforcement learning, and other tasks involving heterogeneous input data. Their hallmark is the self-attention mechanism, which allows the model to weigh different parts of the input sequence dynamically, and is an evolution of earlier attention-based approaches. This article provides readers with the necessary background to understand recent research on transformer models, and presents the mathematical and algorithmic foundations of their core components. It also explo…

  7. Close Cited by this paper
    A Survey of Transformers
    Tianyang Lin, Yuxin Wang, Xiangyang Liu et al. · 2021 · Machine Learning · cited 1,624 times · AI summary available
    Abstract

    Transformers have achieved great success in many artificial intelligence fields, such as natural language processing, computer vision, and audio processing. Therefore, it is natural to attract lots of interest from academic and industry researchers. Up to the present, a great variety of Transformer variants (a.k.a. X-formers) have been proposed, however, a systematic and comprehensive literature review on these Transformer variants is still missing. In this survey, we provide a comprehensive review of various X-formers. We first briefly introduce the vanilla Transformer and then propose a new taxonomy of X-formers. Next, we introduce the various X-formers from three perspectives: architectur…

  8. Close
    The Role of Logic and Automata in Understanding Transformers
    A. Lin, P. Barceló · 2025 · Reachability Problems · cited 1 time · Not summarized yet
    Abstract

    The advent of transformers has in recent years led to powerful and revolutionary Large Language Models (LLMs). Despite this, our understanding on the capability of transformers is still meager. In this invited contribution, we recount the rapid progress in the last few years to the question of what transformers can do. In particular, we will see the integral role of logic and automata (also with some help from circuit complexity) in answering this question. We also mention several open problems at the intersection of logic, automata, verification and transformers.

Prior work it builds on

  1. Related Used in depth by this paper
    Attention is All you Need
    Ashish Vaswani, Noam Shazeer, N. Parmar et al. · 2017 · Neural Information Processing Systems · cited 201,745 times · AI summary available
    Abstract

    The dominant sequence transduction models are based on complex recurrent or convolutional neural networks in an encoder-decoder configuration. The best performing models also connect the encoder and decoder through an attention mechanism. We propose a new simple network architecture, the Transformer, based solely on attention mechanisms, dispensing with recurrence and convolutions entirely. Experiments on two machine translation tasks show these models to be superior in quality while being more parallelizable and requiring significantly less time to train. Our model achieves 28.4 BLEU on the WMT 2014 English-to-German translation task, improving over the existing best results, including ense…

  2. Related
    Scaling Language Models: Methods, Analysis & Insights from Training Gopher
    Jack W. Rae, Sebastian Borgeaud, Trevor Cai et al. · 2021 · arXiv.org · preprint, not peer reviewed · cited 1,698 times · AI summary available
    Abstract

    Language modelling provides a step towards intelligent communication systems by harnessing large repositories of written human knowledge to better predict and understand the world. In this paper, we present an analysis of Transformer-based language model performance across a wide range of model scales -- from models with tens of millions of parameters up to a 280 billion parameter model called Gopher. These models are evaluated on 152 diverse tasks, achieving state-of-the-art performance across the majority. Gains from scale are largest in areas such as reading comprehension, fact-checking, and the identification of toxic language, but logical and mathematical reasoning see less benefit. We …

  3. Related*
    A Brief Overview of Deep Learning
    Tomohiro Mashita · 2018 · The Journal of The Institute of Image Information and Television Engineers · cited 3 times · Not summarized yet
  4. Related Used in depth by this paper
    BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
    J. Devlin, Ming-Wei Chang, Kenton Lee et al. · 2019 · North American Chapter of the Association for Computational Linguistics · cited 125,205 times · AI summary available
    Abstract

    We introduce a new language representation model called BERT, which stands for Bidirectional Encoder Representations from Transformers. Unlike recent language representation models (Peters et al., 2018a; Radford et al., 2018), BERT is designed to pre-train deep bidirectional representations from unlabeled text by jointly conditioning on both left and right context in all layers. As a result, the pre-trained BERT model can be fine-tuned with just one additional output layer to create state-of-the-art models for a wide range of tasks, such as question answering and language inference, without substantial task-specific architecture modifications. BERT is conceptually simple and empirically powe…

  5. Related
    Inductive Biases and Variable Creation in Self-Attention Mechanisms
    Benjamin L. Edelman, Surbhi Goel, S. Kakade et al. · 2021 · International Conference on Machine Learning · cited 185 times · Not summarized yet
    Abstract

    Self-attention, an architectural motif designed to model long-range interactions in sequential data, has driven numerous recent breakthroughs in natural language processing and beyond. This work provides a theoretical analysis of the inductive biases of self-attention modules. Our focus is to rigorously establish which functions and long-range dependencies self-attention blocks prefer to represent. Our main result shows that bounded-norm Transformer networks"create sparse variables": a single self-attention head can represent a sparse function of the input sequence, with sample complexity scaling only logarithmically with the context length. To support our analysis, we present synthetic expe…

Papers that cite it

  1. Close
    Fundamental Limitations on Subquadratic Alternatives to Transformers
    Josh Alman, Han-Tao Yu · 2024 · International Conference on Learning Representations · cited 13 times · Not summarized yet
    Abstract

    The Transformer architecture is widely deployed in many popular and impactful Large Language Models. At its core is the attention mechanism for calculating correlations between pairs of tokens. Performing an attention computation takes quadratic time in the input size, and had become the time bottleneck for transformer operations. In order to circumvent this, researchers have used a variety of approaches, including designing heuristic algorithms for performing attention computations faster, and proposing alternatives to the attention mechanism which can be computed more quickly. For instance, state space models such as Mamba were designed to replace attention with an almost linear time alter…

  2. Close
    Can Transformers Learn to Solve Problems Recursively?
    S. Zhang, Curt Tigges, Stella Biderman et al. · 2023 · arXiv.org · preprint, not peer reviewed · cited 22 times · Not summarized yet
    Abstract

    Neural networks have in recent years shown promise for helping software engineers write programs and even formally verify them. While semantic information plays a crucial part in these processes, it remains unclear to what degree popular neural architectures like transformers are capable of modeling that information. This paper examines the behavior of neural networks learning algorithms relevant to programs and formal verification proofs through the lens of mechanistic interpretability, focusing in particular on structural recursion. Structural recursion is at the heart of tasks on which symbolic tools currently outperform neural models, like inferring semantic relations between datatypes a…

  3. Close*
    Dual Filter: A Mathematical Framework for Inference using Transformer-like Architectures
    Heng-Sheng Chang, Prashant G. Mehta · 2025 · arXiv.org · preprint, not peer reviewed · cited 6 times · Not summarized yet
  4. Close
    LLMs: Their Past, Promise, and Problems
    George F. Luger · 2024 · International Journal of Semantic Computing · cited 3 times · Not summarized yet
    Abstract

    Transformer-based large language models are currently at the forefront of modern artificial intelligence. Their prominence followed from the seminal paper Attention is All You Need [1]. Vaswani and his colleagues suggested placing attention mechanisms within the encoder and decoder modules of autoencoders rather than using them to focus between these two modules. In this paper we present first the seminal insights of early AI that lead to deep learning. We then describe the mathematical tools necessary for understanding the current generation of LLMs and follow this with a brief description of the transformer architecture. We then provide examples of LLMs in action and conclude with some obser…

  5. Close
    Synthesizing Physics Formulae with Transformers
    Shu-Wei Wang, Vadim Bulitko, M. Youngblood et al. · 2026 · cited 1 time · Not summarized yet
    Abstract

    Finding a compact formula that fits a set of input-output pairs and predicts outputs on unseen inputs is a fundamental problem in science. Symbolic regression automates the search for such formulae: search-based methods explore the space of possible formulae directly, while transformers pre-trained on synthetic data produce formulae of comparable quality substantially faster. Existing transformers, however, are prone to overfitting --- they find formulae that fit the training data well but do not extrapolate to input ranges unseen during training. We address this by shaping the set of formulae used to train a transformer, and show that the resulting formulae extrapolate substantially better.…

How are these papers found?

We compare the title and abstract of this paper with those of every paper summarized on this site, and with the papers Semantic Scholar recommends, those it cites and those citing it (for a much-cited paper, its most recent citations and, from OpenAlex, the most cited ones). Among the prior work and the follow-ups, the papers that use each other in depth, a method it uses and the much-cited follow-ups come a little higher. The levels (very close, close, related) come from the similarity of the texts, not from a judgment of quality; * marks a paper without an abstract, compared by its title. The sentence under a paper is written by an AI from the two abstracts: check it in the papers. A paper marked not relevant by three readers leaves the list.

Updated on 6 November 2026.

The illustrated guide to the papers around a paper