about
A Logic for Expressing Transformers (arxiv.org)
2 points by lambdaviking on May 26, 2023 | hide | past | pdf | 6 comments on HN

In plain words: Transformers that store numbers with about log n bits can be written exactly as logic sentences adding majority-vote counting to 'all' and 'some' quantifiers. This gives the tightest known description and the first logic for such models, which unlike finite-precision ones can attend broadly.

Abstract · A Logic for Expressing Log-Precision Transformers

One way to interpret the reasoning power of transformer-based language models is to describe the types of logical rules they can resolve over some input text. Recently, Chiang et al. (2023) showed that finite-precision transformers can be equivalently expressed in a generalization of first-order logic. However, finite-precision transformers are a weak transformer variant because, as we show, a single head can only attend to a constant number of tokens and, in particular, cannot represent uniform attention. Since attending broadly is a core capability for transformers, we ask whether a minimally more expressive model that can attend universally can also be characterized in logic. To this end, we analyze transformers whose forward pass is computed in $\log n$ precision on contexts of length $n$. We prove that any log-precision transformer can be equivalently expressed as a first-order logic sentence that, in addition to standard universal and existential quantifiers, may also contain majority-vote quantifiers. This is the tightest known upper bound and first logical characterization of log-precision transformers.

William Merrill, Ashish Sabharwal
arXiv:2210.02671 · cs.LG, cs.CC · submitted Oct 6, 2022 · updated Sep 10, 2025
abstract · pdf · html · May 24, 2023: Restructured version of old preprint. Oct 12, 2023: To appear at NeurIPS. Sept 10, 2025: minor technical corrections

add comment on HN

Our recent paper proves that transformers can be translated to sentences in first-order logic with majority-vote quantifiers (FOM).

FOM is a symbolic language that can capture computation inside transformers!

If some method becomes popular (like transformers in this case) there are so many waves of papers where people 'interpret' the new thing by saying how it's really [their own research project / grant / area of study]. It's like when 'deep learning' came there were also waves of papers like this. Is yours different from these kinds of papers?
Good question! A key use for this type of analysis is that it acts as an upper bound on transformers, rather just demonstrating "transformers are like logic". That is, it allows us to fairly easily identify problems that transformers cannot solve. Some examples are graph connectivity, linear programming, various forms of state tracking, etc.

Definitely finding negative results like this is tough by just doing experiments, since it could be that the model might have succeeded if you had just trained it for more time/made it bigger/etc.

Our prior paper discusses how this works more in depth: https://arxiv.org/abs/2207.00729

> "Definitely finding negative results like this is tough by just doing experiments, since it could be that the model might have succeeded if you had just trained it for more time/made it bigger/etc."

This is interesting to me because I've been impressed by how we have unlocked so many cognitive abilities just by scaling token predictors. It seems like every time the perplexity is significantly reduced, a whole new set of capabilities are unlocked. How do the results of your work inform these predictions that stack-more-layers token-prediction scaling will keep unlocking new abilities? For example, how would it affect a prediction of the nature and capabilities of a hypothetical 'GPT-5'-like model that reduces perplexity by a comparable about to the reduction that happened between 'GPT-3' and 'GPT-4' (maybe comparable on some nonlinear scale)?

> How do the results of your work inform these predictions that stack-more-layers token-prediction scaling will keep unlocking new abilities?

The short answer is that scaling up alone probably won't fix these shortcomings. Better decoding strategies like CoT may help, but the issue we're identifying is a limitation of any transformer (no matter the size) arising from its parallelism (the property that enables scaling to large model size/data volume).

As some evidence of this, we were able to use these results to find simple problems that ChatGPT and GPT4 get chance performance on. Moreover, the questions seem to lead these models to hallucinate supporting evidence for the incorrect answers:

https://arxiv.org/abs/2305.13534

Thanks that one is very interesting. I especially like how GPT4 performs worse (zero shot greedy decoding) than ChatGPT on those questions. I wonder have you thought about how it relates to 'inverse scaling' (https://github.com/inverse-scaling/prize)? As I was reading it I was thinking how that kind of 'hallucination' is exactly the problem that beam search (as opposed to greedy decoding) is designed to solve, and I see this was addressed later in the paper - unfortunately you guys didn't have access to it on the API and also no access to other things like log likelihoods.

A related question I had, is to decompose the blame for the problems these LLMs were having into two parts: (1) the weaknesses of the model size and data size and architecture caused for example by parallelism tradeoffs versus (2) the inherent problems of greedy token prediction. For example I could imagine that even an 'oracular' (kolmogorov or solomonoff or whoever absolute minimum theoretical perplexity) single-token-at-a-time-predictor could have related errors purely as a result of greedy decoding, which would be in no way attributable to any kind of size issue or architectural property or parallelism property of the model. As I guess you already know, the reason is just that 'the most likely next token of the response' isn't necessarily the same as 'the next token of the most likely response'.