Transformers meet Neural Algorithmic Reasoners
Wilfried Bounsi, Borja Ibarz, Andrew Dudzik, Jessica B. Hamrick, Larisa Markeeva, Alex Vitvitskyi, Razvan Pascanu, Petar Veličković
TL;DR
Transformers struggle with precise, algorithmic reasoning, especially out-of-distribution. The authors propose TransNAR, a hybrid model that fuses a decoder-only Transformer with a frozen, pre-trained graph neural network-based NAR via cross-attention to NAR embeddings, enabling robust algorithmic computation on CLRS-Text. Empirically, TransNAR yields significant out-of-distribution gains and better shape/generalisation properties over Transformer baselines, while revealing limitations and avenues for distillation to unimodal models. This work demonstrates a viable path to combining strong language understanding with robust algorithmic reasoning by integrating specialized symbolic-like modules into LLMs, with broad implications for reasoning-heavy tasks.
Abstract
Transformers have revolutionized machine learning with their simple yet effective architecture. Pre-training Transformers on massive text datasets from the Internet has led to unmatched generalization for natural language understanding (NLU) tasks. However, such language models remain fragile when tasked with algorithmic forms of reasoning, where computations must be precise and robust. To address this limitation, we propose a novel approach that combines the Transformer's language understanding with the robustness of graph neural network (GNN)-based neural algorithmic reasoners (NARs). Such NARs proved effective as generic solvers for algorithmic tasks, when specified in graph form. To make their embeddings accessible to a Transformer, we propose a hybrid architecture with a two-phase training procedure, allowing the tokens in the language model to cross-attend to the node embeddings from the NAR. We evaluate our resulting TransNAR model on CLRS-Text, the text-based version of the CLRS-30 benchmark, and demonstrate significant gains over Transformer-only models for algorithmic reasoning, both in and out of distribution.
