Profile

Settings

Loading…

← Papers

Help

FAQ

Which features require signing in?

You can read the commentary, paper info, Model Structure and related papers of public papers without signing in. Sign in to manage your account or contact us about your inquiries.

Can I upload a PDF file?

Upload papers with an arXiv or DOI link; the commentary is public to everyone. Papers whose source and terms of use can't be verified, so the commentary can't be made public, can't be uploaded. Uploading PDF files and keeping papers private are for subscribers only, and a paper uploaded as a file is saved as private only. Searching for official info by title runs only when you press the button.

Are the figures and AI commentary accurate?

Figures come only from the original paper, and only those whose terms of use are verified are shown. The commentary is written by AI and may be wrong. Check important claims, numbers and figure context against the evidence in the original paper.

I want to report a copyright issue.

Terms of use and the source of the original paper are on the Paper info tab. If there's a problem, choose "Paper content, figures and copyright" under Contact us and send the paper link, the part in question, and evidence that you hold the rights. Receiving your report doesn't confirm any rights or remove anything right away. You can see the result of the review under My inquiries.

I forgot my password.

If you signed up with email, use Forgot password in the sign-in window to reset it with your verified email. If you signed up with Google, Naver or Kakao, change your password with that service.

What should I include in an inquiry?

Tell us which screen you were on and what you were doing when the problem happened, along with the paper link. Don't include personal information such as passwords, API keys, verification codes or phone numbers. Inquiries and replies are stored in Refivu and you can see them under My inquiries.

How do I delete my account?

In Settings, under My account, press Delete account. Review what will be deleted and complete identity verification to delete your account. For other requests, choose "Account" under Contact us.

Paper commentary

Transformers Provably Learn Algorithmic Solutions for Graph Connectivity, But Only with the Right Data

Transformers learn exact graph connectivity algorithms when training data stays within capacity

  • Problem Transformers trained on random graphs learn a node-degree shortcut that fails on adversarial graphs such as two-chain graphs.
  • Method The authors train only on graphs whose diameter stays within the model's capacity, instead of mixing in beyond-capacity graphs.
  • Results Restricting training to diameter at most 9 lets a 2-layer standard Transformer learn the exact algorithm, unlike unrestricted training.

Where standard Transformers go wrong

Graph connectivity asks, for each pair of nodes, whether some path joins them, and the target is a connectivity matrix. The task has a clean algorithm, matrix powering of the adjacency matrix, and it also has a degree-based shortcut. That shortcut looks right on typical random graphs but fails on adversarial instances. The authors train a 2-layer standard Transformer on ER(n = 20, p = 0.08) graphs and check it on held-out graphs from the same distribution.

It reaches almost perfect exact match accuracy in distribution, where a graph counts as correct only if every node pair is right. On 2Chain and 2Clique graphs, with n = 20 and k = 10, the same model falls to nearly zero. The authors read this as over-fitted heuristics taking over the predictions.

So the open question isn't whether Transformers can express the algorithm, since earlier theory says they can. The question is whether gradient descent actually finds that algorithm. The authors trace the failure to the training distribution rather than the architecture. Their reason is that the distribution holds too many graphs beyond the model's capacity.

A 3^L diameter ceiling for depth L

The capacity bound measures a model by graph diameter rather than by node count, which changes what the result says. Diameter is the longest shortest path inside a connected component, and the authors take the maximum over components, so the value stays finite on disconnected graphs. Because of this convention, the bound applies to graphs that contain several components, such as the two-chain test graphs.

The upper-bound side of the argument is what makes the threshold a ceiling rather than a lower estimate. The authors show that for any nonnegative weights, a graph with diameter 3L + 1 exists on which the model fails. They give two proof cases: a false positive across components at some intermediate layer, and a case with no false positives.

In the second case, the information spreads no faster than 3L steps, so the model can't predict a connection beyond that distance.

On the expressivity side, a Disentangled Transformer with identity weights implements a positively weighted sum of adjacency powers. That construction is perfect on every graph with diameter at most 3^L, so the bound is tight from both sides. The authors define capacity as the largest d for which some weights are perfect on all graphs with diam(G) at most d.

Under nonnegative weights, the capacity of an L-layer model is 3^L, and the authors call this quantity the model's capacity.

The authors contrast this exact bound with an asymptotic depth relation, which they say gives weaker predictions. An asymptotic result such as O(exp(L)) from Merrill and Sabharwal wouldn't yield such clear predictive implications. Because the exact threshold is known, the authors can split training graphs into within-capacity and beyond-capacity pairs.

Measured capacity follows the 3^L bound

The authors train 2-layer Disentangled Transformers on ER(n=24) graphs and 3-layer ones on ER(n=64) graphs. On hold-out sets, both models predict reliably, at least 99% accuracy, only for node pairs at distance at most 3^L. Figure 2 plots the largest perfectly predicted path length against training steps, with the 3^2 and 3^3 capacity levels marked.

Figure 2: Capacity of Disentangled Transformers. We train
2-layer (top) and 3-layer (bottom) Disentangled Transformers
on ER(n = 24) and ER(n = 64) graphs re…

Figure 2 . Capacity of Disentangled Transformers. We train 2-layer (top) and 3-layer (bottom) Disentangled Transformers on ER(n = 24) and ER(n = 64) graphs respectively. When evaluated on hold-out sets, both models can only make reliable predictions (≥ 99% accuracy) on node pairs u, v if and only if dG(u, v) ≤ 3 L . These findings resonate with our theoretical observations in Theorem 4.5.

Original paper · CC BY 4.0 · Qilin Ye, Deqing Fu, Robin Jia, Vatsal Sharan · Transformers Provably Learn Algorithmic Solutions for Graph Connectivity, But Only with the Right Data · Original paper figure · Extracted the figure area from page 4 of the original PDF.

Neither model makes reliable predictions on pairs whose distance exceeds 3^L, yet its accuracy on closer pairs stays above 99%. The authors say a 2-layer standard Transformer shows the same empirical capacity, as shown in Figure 10. This matches the exact bound: Theorem 4.5 says an L-layer model fails on a graph with diameter 3^L + 1. Training doesn't enforce nonnegative weights, but the authors find the theory still predicts model capacity.

For any graph, the authors argue the decisive factor for depth is log3 of the diameter, not the asymptotic log of the node count. Rather than an order-of-growth statement, this gives an exact threshold for each depth. The footnote notes that the 2Chain graphs with n=20 and k=10 have maximum path length 9. Since 9 is 3^2, a 2-layer model should in principle learn them, so the earlier failure isn't a capacity limit.

The authors state that the bound holds once n is at least (7/3) · 3^L + 2.

Splitting the weights into two channels

The weights of a trained Disentangled Transformer split into two channels, once the model is assumed to be symmetric under relabeling of nodes. The authors' symmetry requirement covers both the data and the targets, since the ground truth maps A to R and PAP⊤ to PRP⊤ for any permutation P. With nonnegative weights, a layer is layerwise permutation-equivariant exactly when each layer weight decomposes as Aℓ ⊗ In + Bℓ ⊗ Jn.

Here ⊗ is the Kronecker product and Jn is the all-ones n × n matrix. Sufficiency is easy to see, because conjugating by a permutation P leaves In and Jn unchanged. Necessity needs more work, since the layer map becomes bilinear in h once ReLU is inactive under nonnegativity. The family is closed under gradient updates, so the authors can track training dynamics inside it.

The In-channel Aℓ ⊗ In only combines features of nodes that share graph neighbors. Stacking layers composes multi-hop information, so the In-channel effectively computes powers of the adjacency matrix A. After L layers, the readout is a weighted sum of powers of A with nonnegative coefficients, which is the matrix powering algorithm that solves connectivity.

The J-channel Bℓ ⊗ Jn ignores graph structure, because Jn is rank-one and sums all entries of a vector before broadcasting that sum to every node. With the adjacency matrix in front, AJn equals d1⊤, where d is the degree vector. So the J-channel computes global degree statistics, and it fails on adversarial graphs.

The authors use this split to track the two parameters, Aℓ and Bℓ, under gradient descent. Their analysis assumes the data distribution gives a positive chance of disconnected graphs, and it uses a surrogate cross-entropy loss. Under this loss, projected gradient descent converges to KKT points, so the analysis covers where training settles.

The next question is which channel wins, and the answer depends on the data distribution.

Why the data decides the winner

The training analysis starts from projected gradient descent on a regularized population risk, using a cross-entropy surrogate with link ϕ(z) = 1 − e^(−αz). The analysis assumes that disconnected graphs occur with positive probability under the Erdős-Rényi distribution. Under this assumption, the authors can track how the two parameters Aℓ and Bℓ evolve during gradient descent.

Under suitable conditions, the penalty from disconnected graphs can outweigh the reward from connected ones. In that case, the only KKT-compliant value for the heuristic channel is B*ℓ = 0, so the model learns the fully algorithmic matrix-powering solution.

Training has two phases, and the first one is short. In Phase 1, both channels pick up easy examples, because plenty of within-component, within-capacity pairs exist. Disconnected graphs supply the suppression force, because the heuristic generates false positives there and pushes Bℓ to zero. Connected graphs supply the promotion force, because the heuristic correctly identifies connected pairs and earns a reward gradient.

The outcome depends on whether batches are dominated by within-capacity graphs or by beyond-capacity ones. When batches are dominated by within-capacity graphs, the algorithmic I-channel is consistently rewarded. Disconnected graphs in this regime penalize the J-channel for false connections, which drives Bℓ to 0 and leaves only the algorithmic solution.

When a significant share of connected beyond-capacity graphs (diam(G) > 3L) appears, the algorithmic channel cannot bridge the distance. These samples make the model rely on the global J-channel, which promotes the degree-counting shortcut. So the learned solution depends on the proportion of beyond-capacity connected graphs in the training distribution, as visualized in Figure 6.

The section's dynamics result is the link between this training analysis and the data lever tested in the next section. The experiments in §5.2 up-weight within-capacity graphs and check whether this suppresses the heuristic channel.

Restricting the data moves the weight energy toward the algorithm

The data lever trains only on ER≤, the graphs with diameter at most 3^L, and leaves out the rest of the distribution. The authors test it with a 1-layer Disentangled Transformer on ER(n=8, p=0.2) graphs, the same setup as the unrestricted run. Restricted training also keeps the growth of the heuristic portion, the B⊗J_n channel, from building up.

Without restriction, the In-channel share grows during training, while the Jn-channel share first increases and then decreases.

The mixture experiment asks how much beyond-capacity data the algorithm can tolerate. At small ρ(G), the model keeps high energy in the algorithm channel and makes perfect predictions on out-of-distribution 2Chain graphs. The authors read this as a small threshold ρ⋆ > 0 existing, below which the algorithm channel still drives predictions.

The mixture figure shows the A In-channel share against the proportion of beyond-capacity graphs. The model still performs perfectly when the I-channel energy share dominates, beyond roughly 90%.

Does the restriction carry over to standard Transformers?

The authors test whether the data lever also helps a standard Transformer, not only the Disentangled model. They retrain the same 2-layer standard Transformer from the preliminary study on the restricted distribution ER≤. In this restricted set, every graph has diameter at most 9, which is 3 to the power 2. The unrestricted baseline is trained on the full ER distribution, so the only change is the training data.

The model trained on the unconstrained distribution ER doesn't generalize to the same test set. The restricted run reaches high accuracy while the unrestricted run stays low across training.

Figure 7: Standard Transformer models learn generalizable
solutions from within capacity data.We train a 2-layer standard
Transformer model on ER(n= 20) graphs…

Figure 7 .Standard Transformer models learn generalizable solutions from within capacity data.We train a 2-layer standard Transformer model on ER(n= 20) graphs, with and without restricting graph diameters. When tested on OOD 2Chain graphs, the one trained withthe right datais able to generalize.

Original paper · CC BY 4.0

The authors also report that the restricted training helps the model generalize to OOD 2Clique graphs, shown in their Figure 11. This matches the Disentangled result, where the algorithmic channel took over once the training graphs stayed within capacity. The authors read Figure 7 as evidence that within-capacity data alone can teach a standard Transformer a generalizable solution.

Their discussion ties this to the claim that the failures come from training mass beyond 3L pushing learning toward a global shortcut.

What these results do not cover

The Disentangled Transformer runs don't enforce nonnegative weights during training, so the capacity proof, which assumes them, is only matched empirically. The authors still report that their theoretical analysis remains predictive of model capacity in these runs.

With the diameter capped at 2, the models failed to length-generalize, and the authors attribute this to Transformers' poor length generalization abilities. The paper's own statement is that simply scaling up depth doesn't equip a model with algorithmic capabilities. Generalization is reported only on 2Chain and 2Clique graphs, so other out-of-distribution families weren't tested.

The standard Transformer results come from a 2-layer model with 2Chain at maximum chain length 10, so deeper standard models weren't shown on that setup. The data lever was tested on a 1-layer Disentangled Transformer with ER(n=8, p=0.2), and its effect on larger graphs isn't covered by these runs.

Paper info

Authors
Qilin Ye, Deqing Fu, Robin Jia, Vatsal Sharan
Venue
arXiv · Preprint
First published
2025-10-22
Added
2026-10-29
Updated
2026-2-17
Version
v2
arXiv
2510.19753
Category
cs.LG
Original paper terms
CC BY 4.0
What we show
Paper info, commentary and permitted figures from the original paper

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

Abstract

Transformers often fail to learn generalizable algorithms, instead relying on brittle heuristics. Using graph connectivity as a testbed, we explain this phenomenon both theoretically and empirically. We consider a simplified Transformer architecture, the Disentangled Transformer, and prove that an $L$-layer model can compute connectivity in graphs with diameters up to $3^L$, implementing an algorithm equivalent to computing powers of the adjacency matrix. By analyzing training dynamics, we prove that whether the model learns this strategy hinges on whether most training instances are within this model capacity. Within-capacity graphs (diameter $\leq 3^L$) drive the learning of the algorithmic solution while beyond-capacity graphs drive the learning of a simple heuristic based on node degrees. Finally, we empirically show that restricting training data to stay within a model's capacity makes both standard and Disentangled Transformers learn the exact algorithm.

Quote from the paper

Qilin Ye, Deqing Fu, Robin Jia, Vatsal Sharan (2025). Transformers Provably Learn Algorithmic Solutions for Graph Connectivity, But Only with the Right Data. arXiv:2510.19753v2. https://arxiv.org/abs/2510.19753v2

BibTeX
@misc{ye2025transformers,
  title = {{Transformers Provably Learn Algorithmic Solutions for Graph Connectivity, But Only with the Right Data}},
  author = {Qilin Ye and Deqing Fu and Robin Jia and Vatsal Sharan},
  year = {2025},
  eprint = {2510.19753},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2510.19753v2}
}

See related papersBrowse other papers

Paper preview
Account security

Connect Google account

If you connect a Google account, you can sign in with it too.

Refivu

Delete account

Refivu
Refivu

Sign up