Transformers Run Bellman-Ford: What "The Geometry of Thought" Reveals
arxiv7 min readJanuary 16, 2026

Transformers Run Bellman-Ford: What "The Geometry of Thought" Reveals

According to "The Geometry of Thought" by Faruk Alpay and Bilge Senturk, Transformer self-attention operates as the Bellman-Ford pathfinding algorithm in high-confidence limits. This means Chain-of-Thought reasoning is fundamentally a shortest-path calculation on a latent token graph.

Yuval Avidani

Yuval Avidani

Author

Key Finding

According to the paper "The Geometry of Thought: Disclosing the Transformer as a Tropical Polynomial Circuit" by Faruk Alpay and Bilge Senturk, Transformer self-attention mechanisms converge to tropical matrix products in high-confidence regimes, effectively executing the Bellman-Ford shortest path algorithm. This has significant implications for how we understand, debug, and improve reasoning in our production language models.

What Does Tropical Geometry in Transformers Mean?

Tropical geometry is a mathematical framework where standard addition is replaced by the "max" operation, and multiplication is replaced by standard addition. The paper "The Geometry of Thought" tackles the fundamental interpretability challenge that we all face: understanding how Transformers generate coherent reasoning chains when we can't see what's happening inside the model.

When we deploy large language models in production, we observe impressive Chain-of-Thought reasoning - models that can break down complex problems into steps, maintain logical consistency, and arrive at correct answers. But this behavior has always seemed emergent and mysterious. We couldn't explain the mechanism driving it.

The Problem We All Face

We all deal with the "black box" problem in our transformer models. Our LLMs generate sophisticated reasoning chains, but we have no clear understanding of the computational structure producing these chains. This creates several challenges in production:

When our models fail at reasoning tasks, we can't pinpoint why. When they succeed, we can't explain how. This makes systematic improvement incredibly difficult. We end up doing trial-and-error prompt engineering or fine-tuning without understanding the underlying mechanisms.

Existing interpretability approaches have focused on attention visualization, probing classifiers, or mechanistic interpretability studies. These are valuable but limited - they show us what the model attends to without explaining the computational algorithm being executed. We needed a bridge between the neural network operations and classical algorithmic thinking.

What the Researchers Found

The breakthrough in this research comes from analyzing Transformers in what's called the "high-confidence regime" - meaning when the inverse temperature parameter β approaches infinity. In this limit, something remarkable happens mathematically.

The Softmax function that drives attention - meaning the mechanism that decides which tokens to focus on - converges to a tropical matrix product. Think of it like this: imagine you're navigating a city and looking for the shortest route between two points. In normal math, you'd add up distances along each path. In tropical geometry, you're always taking the maximum value and adding costs. This is exactly what Softmax becomes in high confidence - a "max" operation over weighted paths.

Here's what makes this profound: The tropical matrix product is mathematically equivalent to the Bellman-Ford algorithm - meaning a classic Dynamic Programming approach for finding shortest paths in graphs. The researchers prove that our Transformer's forward pass, layer by layer, is executing this exact algorithm.

In this framework, tokens are nodes in a latent graph. The attention weights represent edge costs between tokens. Each layer of the Transformer iteratively refines shortest path calculations, exactly like how Bellman-Ford propagates distance information across a graph structure.

Practical Implementation

Here's what this looks like when we analyze our models with this geometric lens:

# Example: Analyzing Transformer attention as graph paths
import torch
import networkx as nx

def extract_token_graph(attention_weights, tokens, layer_idx):
    """
    Extract the latent token graph from attention patterns
    Based on "The Geometry of Thought" framework
    """
    # Create directed graph where tokens are nodes
    G = nx.DiGraph()
    
    # Add nodes for each token
    for i, token in enumerate(tokens):
        G.add_node(i, token=token)
    
    # Add edges based on attention weights (costs)
    # In tropical geometry, attention weights are path costs
    for i in range(len(tokens)):
        for j in range(len(tokens)):
            weight = attention_weights[layer_idx, i, j].item()
            if weight > 0.01:  # Filter low-weight connections
                # Negative log converts to tropical addition
                cost = -torch.log(torch.tensor(weight)).item()
                G.add_edge(i, j, weight=cost)
    
    return G

def find_reasoning_path(graph, start_token_idx, end_token_idx):
    """
    Find the shortest reasoning path - what the Transformer computes
    This is the Bellman-Ford algorithm the model executes
    """
    try:
        path = nx.shortest_path(
            graph, 
            source=start_token_idx, 
            target=end_token_idx,
            weight='weight'
        )
        path_cost = nx.shortest_path_length(
            graph,
            source=start_token_idx,
            target=end_token_idx,
            weight='weight'
        )
        return path, path_cost
    except nx.NetworkXNoPath:
        return None, float('inf')

Another practical example - understanding how multi-layer refinement works:

# Analyzing layer-by-layer path refinement
def analyze_cot_as_bellman_ford(model, prompt, target_layers=[0, 6, 12]):
    """
    Track how reasoning paths get refined across layers
    Like Bellman-Ford iterations refining distance estimates
    """
    inputs = tokenizer(prompt, return_tensors='pt')
    
    # Extract attention patterns at different layers
    with torch.no_grad():
        outputs = model(**inputs, output_attentions=True)
    
    results = {}
    tokens = tokenizer.convert_ids_to_tokens(inputs['input_ids'][0])
    
    for layer_idx in target_layers:
        # Get attention weights for this layer
        attn = outputs.attentions[layer_idx][0].mean(dim=0)  # Average over heads
        
        # Build token graph
        graph = extract_token_graph(attn, tokens, 0)
        
        # Analyze reasoning paths from question to answer tokens
        question_idx = 0  # Typically first token
        answer_idx = len(tokens) - 1  # Typically last token
        
        path, cost = find_reasoning_path(graph, question_idx, answer_idx)
        
        results[f'layer_{layer_idx}'] = {
            'path': [tokens[i] for i in path] if path else None,
            'cost': cost,
            'graph_density': graph.number_of_edges() / (graph.number_of_nodes() ** 2)
        }
    
    return results

# Usage
reasoning_analysis = analyze_cot_as_bellman_ford(
    model=our_production_model,
    prompt="What is 15 * 23? Let's think step by step."
)

for layer, info in reasoning_analysis.items():
    print(f"{layer}: Path cost = {info['cost']:.3f}")
    print(f"Reasoning path: {' -> '.join(info['path']) if info['path'] else 'No path'}")

Key Results & Numbers

  • Mathematical Proof - This isn't an approximation. The convergence to tropical matrix product is proven rigorously as β → ∞ (inverse temperature approaches infinity), providing exact correspondence to Bellman-Ford.
  • Algorithmic Equivalence - Each Transformer layer performs one iteration of the Bellman-Ford algorithm. For an L-layer Transformer, we get L iterations of distance propagation across the token graph.
  • Geometric Structure - Chain-of-Thought reasoning emerges from computing shortest paths on a latent graph. The "chain" is literally the sequence of tokens along the shortest path from question to answer.

How This Fits Our Toolkit

This research complements our existing interpretability tools rather than replacing them. Attention visualization tools show us where models look - this geometric framework explains what computation they're performing when they look there.

When we use mechanistic interpretability to study specific behaviors, this framework gives us the algorithmic backbone. We can now hypothesize that certain circuits are implementing specific graph structures and path computations.

For prompt engineering, this suggests we should think about token arrangement as graph design. Placing tokens strategically might create more efficient paths for the model to traverse during reasoning.

My Take - Should We Pay Attention?

In my view, this is one of the most important interpretability results for practitioners. We finally have a rigorous connection between what seems like mysterious emergent reasoning and a classical algorithm we understand completely.

The practical implications are significant. We can now analyze our models' reasoning failures as graph pathfinding failures. When Chain-of-Thought breaks down, we can ask: Is the latent graph disconnected? Are there negative cycles? Is the shortest path actually leading to the wrong answer?

This gives us concrete debugging tools. Instead of blindly tweaking prompts or fine-tuning data, we can visualize the token graphs our models construct and identify structural problems.

The limitation is that this strictly applies to the high-confidence regime. In practice, our models operate at finite temperatures, so there's still work to understand how this tropical structure interacts with the stochastic sampling we use in production. But this is a massive step forward in making the black box more transparent.

Read the full paper: The Geometry of Thought: Disclosing the Transformer as a Tropical Polynomial Circuit

Frequently Asked Questions

What does "The Geometry of Thought" find?

The paper proves that Transformer self-attention converges to tropical matrix multiplication in high-confidence limits, which is mathematically equivalent to the Bellman-Ford shortest path algorithm operating on a latent token graph.

Who conducted this research?

The paper was authored by Faruk Alpay and Bilge Senturk and published on arXiv in January 2025. It bridges deep learning theory with classical algorithmic analysis.

Why does this matter for production systems?

This gives us a rigorous framework to debug and improve reasoning in our LLMs by analyzing them as graph algorithms rather than treating them as black boxes.

What should we do based on this research?

Start analyzing attention patterns as graph structures. When reasoning fails, investigate whether the token graph has the right connectivity and whether shortest paths lead to correct answers.

What are the limitations of this study?

The tropical geometry framework strictly applies in the high-confidence regime (β → ∞). Our production models operate at finite temperatures, so we need additional research to understand how this structure behaves under realistic sampling conditions.

Comments