# Toroidal Logit Bias for Hallucination Reduction in Large Language Models

**Sylvain Cormier**
Paraxiom Research
February 2026

---

## Abstract

We present an inference-time intervention that imposes toroidal topological constraints on token selection in large language models. By mapping vocabulary tokens to positions on a 12×12 torus and biasing logits toward tokens "near" recently generated tokens in this toroidal space, we hypothesized measurable reductions in factual errors. Initial results on 100 factual completion tasks showed +40% error reduction on Qwen 2.5-7B-Instruct and +15.4% on OLMo 1.7-7B. **However, a comprehensive replication (March 2026) across 4 models, 3 benchmarks, and 6 experimental phases found that these results do not hold — the observed improvements were within LLM judge sampling variance.** A factorial decomposition identified the hardening system prompt, not the toroidal bias, as the active ingredient. The theoretical framework (toroidal topology for training-time drift reduction) remains valid; see Addendum.

---

## 1. Introduction

Large language models (LLMs) frequently generate plausible but factually incorrect content—a phenomenon termed "hallucination." Current mitigation strategies include retrieval-augmented generation (RAG), fine-tuning on curated data, and post-hoc fact-checking. These approaches require external knowledge bases, expensive retraining, or additional inference passes.

We propose an alternative: **toroidal logit bias**, an inference-time intervention that requires no external resources and minimal computational overhead. Our method is grounded in the hypothesis that semantic coherence can be encouraged by imposing geometric locality constraints on the token generation process.

### 1.1 Contributions

1. A novel logit bias mechanism based on toroidal (Tonnetz) topology
2. Empirical validation on two distinct model architectures (Qwen, OLMo)
3. Model-specific hyperparameter guidelines for deployment
4. A rigorous verification methodology for hallucination measurement

---

## 2. Methodology

### 2.1 Toroidal Token Mapping

We map each token ID to a position on a 12×12 torus using modular arithmetic:

```
position(token_id) = (token_id mod 12, (token_id // 12) mod 12)
```

The toroidal (wraparound) Manhattan distance between positions is:

```python
def toroidal_distance(i, j, grid_size=12):
    xi, yi = i % grid_size, (i // grid_size) % grid_size
    xj, yj = j % grid_size, (j // grid_size) % grid_size
    dx = min(abs(xi - xj), grid_size - abs(xi - xj))
    dy = min(abs(yi - yj), grid_size - abs(yi - yj))
    return dx + dy
```

### 2.2 Logit Bias Computation

At each generation step, we compute a bias vector added to the model's logits:

```python
def compute_toroidal_bias(vocab_size, recent_tokens, alpha, radius, max_tokens):
    bias = zeros(vocab_size)

    for offset, token_id in enumerate(recent_tokens[-5:]):
        token_pos = token_id % 144  # 12 × 12

        for vocab_id in range(min(vocab_size, max_tokens)):
            target_pos = vocab_id % 144
            dist = toroidal_distance(token_pos, target_pos)

            if dist <= radius:
                # Strong boost for nearby tokens
                bias[vocab_id] += alpha * (radius - dist + 1) / (offset + 1)
            elif dist <= radius * 2:
                # Weak boost for medium-distance tokens
                bias[vocab_id] += alpha * 0.5 / (offset + 1)

    return bias
```

**Parameters:**
- `alpha`: Bias strength (0.1–0.3 typical)
- `radius`: Neighborhood size on torus (2.0–3.0 typical)
- `max_tokens`: Number of vocabulary tokens to bias (1440–3000 typical)

### 2.3 Key Design Decisions

**Limited Vocabulary Bias**: We bias only the first N tokens of the vocabulary, not the full vocabulary. Empirically, biasing all tokens (50K–150K) provides no benefit or causes harm. High-frequency tokens (first 1K–3K) carry the semantic structure that benefits from toroidal locality.

**Recency Weighting**: More recent tokens receive stronger influence (divided by `offset + 1`), reflecting the intuition that immediate context is most relevant for coherence.

**Why a Torus?**: The torus provides wraparound connectivity, avoiding edge effects present in flat grids. This mirrors the Tonnetz structure from music theory, where pitch classes form a toroidal manifold.

---

## 3. Hallucination Verification Methodology

### 3.1 Definition of Hallucination

For this study, we define **hallucination** as the generation of factually incorrect information in response to prompts with objectively verifiable answers.

### 3.2 Benchmark Construction

We constructed a benchmark of **100 factual completion prompts** across five domains:

| Domain | Examples | Count |
|--------|----------|-------|
| Geography | "The capital of France is", "The Amazon River is in" | 20 |
| Science | "The chemical symbol for gold is", "The largest planet is" | 25 |
| History | "World War II ended in", "The Berlin Wall fell in" | 20 |
| Arts & Culture | "The Mona Lisa was painted by", "Shakespeare wrote" | 20 |
| Math & Computing | "A byte contains how many bits", "The square root of 144 is" | 15 |

Each prompt has one or more **ground truth answers** (e.g., "Paris" for capital of France).

### 3.3 Evaluation Protocol

**For each prompt:**

1. **Baseline Generation**: Generate response using unmodified model (greedy decoding, max 30 tokens)
2. **Toroidal Generation**: Generate response using toroidal logit bias (same decoding settings)
3. **Correctness Check**: Verify if any ground truth answer appears in the response (case-insensitive substring match)

**Metrics:**

- **Accuracy**: Proportion of correct responses
- **Error Rate**: 1 - Accuracy
- **Error Reduction**: (Baseline Errors - Toroidal Errors) / Baseline Errors × 100%

### 3.4 Why This Measures Hallucination

When a model responds to "The capital of France is" with anything other than "Paris," it is generating factually incorrect content—the definition of hallucination. Our benchmark specifically tests:

1. **Factual recall**: Does the model retrieve correct information?
2. **Coherent completion**: Does the model stay on-topic?
3. **Resistance to confabulation**: Does the model avoid plausible-but-wrong answers?

**Example Hallucinations Observed:**
- Prompt: "The first computer programmer was"
- Baseline (incorrect): "Charles Babbage" (he designed computers, didn't program them)
- Toroidal (correct): "Ada Lovelace"

### 3.5 Statistical Considerations

With 100 samples:
- Baseline accuracy 95%: 95% CI ≈ [88.7%, 98.4%] (binomial)
- Observed change of 2 percentage points (95% → 97%) represents moving from 5 errors to 3 errors
- For OLMo (87% → 89%), moving from 13 errors to 11 errors

While individual changes are small in absolute terms, the **error reduction percentage** provides a meaningful measure of improvement relative to the baseline error rate.

---

## 4. Results

### 4.1 Qwen 2.5-7B-Instruct

**Configuration**: α=0.3, radius=2.0, max_tokens=1440

| Condition | Correct | Accuracy | Error Reduction |
|-----------|---------|----------|-----------------|
| Baseline | 95/100 | 95.0% | — |
| Toroidal Bias | 97/100 | **97.0%** | **+40.0%** |

**Specific Fixes:**
- "Newton discovered" → "gravity" (baseline said "calculus")
- "Shakespeare wrote" → "Hamlet" (baseline gave incomplete answer)

### 4.2 OLMo 1.7-7B-hf

**Initial Attempt** (α=0.3, r=2.0, n=1440): 86% accuracy (−7.7% error reduction) — WORSE

**Parameter Sweep**: Tested 100 configurations across:
- Alpha: [0.05, 0.1, 0.15, 0.2, 0.25]
- Radius: [1.5, 2.0, 2.5, 3.0]
- Max tokens: [500, 1000, 1440, 2000, 3000]

**Optimal Configuration**: α=0.2, radius=3.0, max_tokens=3000

| Condition | Correct | Accuracy | Error Reduction |
|-----------|---------|----------|-----------------|
| Baseline | 87/100 | 87.0% | — |
| Toroidal Bias | 89/100 | **89.0%** | **+15.4%** |

**Specific Fixes:**
- "A decade is how many years" → "10" (baseline gave verbose incorrect answer)
- "The Great Pyramid was built in" → "Egypt" (baseline hallucinated wrong location)

### 4.3 Failure Modes

**Full Vocabulary Bias**: Biasing all tokens (50K–150K) either had no effect or caused significant harm:

| Model | Alpha | Bias Scope | Result |
|-------|-------|------------|--------|
| Qwen | 1.0 | Full (152K) | −80% error reduction |
| OLMo | 1.0 | Full (50K) | −61% error reduction |

**Interpretation**: Rare tokens in the vocabulary do not benefit from toroidal locality. Biasing them introduces noise that disrupts the model's learned patterns.

---

## 5. Analysis

### 5.1 Why Does It Work?

**Hypothesis 1: Semantic Clustering in Token Space**

High-frequency tokens (first 1K–3K in vocabulary) tend to be common words that carry core semantic content. By encouraging the model to select tokens "near" recent tokens on the torus, we promote local consistency in the semantic manifold.

**Hypothesis 2: Disruption of Hallucination Pathways**

Hallucination often occurs when the model's attention mechanism latches onto a spurious pattern. The toroidal bias provides a gentle "correction force" that steers generation back toward tokens consistent with recent context.

**Hypothesis 3: Regularization Effect**

The bias acts as a soft constraint that reduces the entropy of the next-token distribution, making the model more conservative and less likely to sample from low-probability (often incorrect) regions.

### 5.2 Why Different Parameters for Different Models?

| Model | Optimal Radius | Optimal Max Tokens | Interpretation |
|-------|----------------|-------------------|----------------|
| Qwen 2.5 | 2.0 | 1440 | Tighter vocabulary structure, smaller neighborhood needed |
| OLMo 1.7 | 3.0 | 3000 | Sparser vocabulary structure, wider neighborhood needed |

OLMo uses a different tokenizer (Dolma-based) with different vocabulary ordering. Important semantic tokens may be positioned further into the vocabulary, requiring both larger `max_tokens` and wider `radius` to capture them.

---

## 6. Practical Deployment

### 6.1 Implementation

```python
def generate_with_toroidal_bias(model, tokenizer, prompt, config):
    """
    config = {
        "alpha": 0.3,        # Bias strength
        "radius": 2.0,       # Neighborhood size
        "max_tokens": 1440,  # Tokens to bias
        "grid_size": 12      # Torus dimensions
    }
    """
    input_ids = tokenizer(prompt, return_tensors="pt").input_ids
    generated = input_ids[0].tolist()

    for _ in range(max_new_tokens):
        logits = model(input_ids).logits[0, -1, :]

        # Apply toroidal bias
        bias = compute_toroidal_bias(
            vocab_size=len(logits),
            recent_tokens=generated,
            **config
        )
        logits = logits + bias

        next_token = logits.argmax()
        generated.append(next_token)

        if next_token == tokenizer.eos_token_id:
            break

    return tokenizer.decode(generated)
```

### 6.2 Recommended Configurations

| Model Family | Alpha | Radius | Max Tokens |
|--------------|-------|--------|------------|
| Qwen 2.x | 0.3 | 2.0 | 1440 |
| OLMo 1.x | 0.2 | 3.0 | 3000 |
| Unknown | 0.2 | 2.5 | 2000 |

For new models, we recommend starting with the "Unknown" configuration and tuning on a small calibration set (20–50 prompts).

### 6.3 Computational Overhead

- **Memory**: O(max_tokens) additional tensor per generation step
- **Time**: ~5% increase in inference latency
- **No fine-tuning required**: Works with any pretrained model

---

## 7. Limitations

1. **Benchmark Scope**: Our 100-prompt benchmark covers factual completion. Performance on open-ended generation, creative writing, or reasoning tasks is untested.

2. **Model Coverage**: Tested on two 7B models. Behavior on larger (70B+) or smaller (1B) models may differ.

3. **Statistical Power**: With 100 samples, detecting small improvements (1–2 percentage points) is challenging. Larger benchmarks would provide stronger statistical confidence.

4. **Hyperparameter Sensitivity**: Each model family requires tuning. A universal configuration has not been found.

5. **Theoretical Grounding**: While results are consistent with the toroidal coherence hypothesis, the underlying mechanism is not fully understood.

---

## 8. Related Work

**Logit Manipulation**: Prior work has used logit biasing for controllable generation (e.g., reducing toxicity, enforcing style). Our work applies geometric constraints rather than content-based biases.

**Topological Methods in NLP**: Persistent homology has been applied to analyze word embeddings and document structure. We extend topological thinking to the generation process itself.

**Hallucination Mitigation**: RAG, fine-tuning, and chain-of-thought prompting are established methods. Our approach is complementary and can be combined with these techniques.

---

## 9. Conclusion (Original — see Addendum)

~~Toroidal logit bias provides a simple, effective, and deployable method for reducing factual hallucination in LLMs.~~ See Addendum below.

---

## Addendum: Replication Update (March 2026)

### Summary

A comprehensive independent replication across 6 experimental phases found that the inference-time toroidal logit bias **does not produce statistically significant hallucination reduction**. The results reported in Sections 4.1–4.2 were within sampling variance and do not replicate.

### Replication Methodology

We conducted exact replication using the same codebase (`benchmark_full.py`), parameters (α=0.3, radius=2.0, max_tokens=1440), decoding settings (temp=0.7, top_p=0.9), and T&I LLM judge methodology on Qwen 2.5-7B-Instruct.

### Phase 1: Greedy Decoding (4 models × 3 benchmarks)

All conditions showed identical results to baseline. At α=0.3, the maximum logit shift is ~0.9 — insufficient to change the argmax token under greedy decoding. This finding was not previously documented and explains why the original study required sampling.

### Phase 2: T&I Exact Replication (n=200)

| Metric | Baseline | Toroidal | Delta | p-value |
|--------|----------|----------|-------|---------|
| T&I % | 76.5% | 74.5% | −2.0pp | 0.22 (McNemar) |

Our baseline (76.5%) closely matches the original (75.6%), confirming correct methodology. The toroidal condition shows −2.0pp (opposite direction), with 5 of 6 discordant pairs going against the toroidal condition.

### Phase 3: Alpha Sweep

Testing α ∈ {0.3, 1.0, 3.0, 5.0, 10.0} with semantic torus mapping (n=100 per benchmark):

- α=0.3: No effect (±1pp, not significant)
- α=1.0: Slight degradation (+1pp)
- α≥3.0: Significant degradation
- α=10.0: Catastrophic (96% hallucination on TriviaQA vs 50% baseline)

**Conclusion**: Higher bias strength monotonically degrades output quality. There is no beneficial operating point.

### Phase 4: Factorial Decomposition

Decomposing the Coherence Shield pipeline into components:

| Component | TriviaQA Delta | NQ-Open Delta |
|-----------|---------------|---------------|
| Hardening prompt | **−14pp** (p=0.05) | **−8pp** (p=0.33) |
| Toroidal logit bias | 0pp (p=0.88) | 0pp (p>0.5) |
| Prompt + bias | −14pp | −8pp |

The system prompt ("Answer concisely and truthfully") is the active ingredient. The toroidal bias contributes nothing beyond the prompt.

### Phase 5: Semantic Torus Mapping

Replacing modular arithmetic (token_id % 144) with learned semantic embedding alignment (spectral Laplacian + Procrustes + Hungarian matching): consistent −1pp improvement on NQ-Open across Qwen models, but not statistically significant.

### Phase 6: Orthogonal Projection

Testing G = VVᵀ (SVD projector on hidden states) as an alternative to logit biasing:

- Question-only evidence basis: rank ~38/896 (4.3% of space) — too restrictive, increases hallucination
- Expanded with top-500 predicted tokens: rank ~538/896 (60% of space) — too permissive, no effect
- No useful operating point found without external retrieval (RAG)

### Corrected Conclusions

1. **Inference-time toroidal logit bias does not reduce hallucination** — confirmed across 6 experimental phases, 4 models, 3 benchmarks
2. **The v2 improvements (+0.2pp to +2.8pp) were LLM judge sampling variance** — exact replication shows −2.0pp
3. **The OLMo +15.4% was hyperparameter overfitting** — 100-configuration sweep on a 100-sample test set
4. **Prompt engineering is effective** — the hardening prompt produces −14pp hallucination reduction
5. **The theoretical framework remains valid** — toy model shows 40% drift reduction at training time; the gap is between theory (training-time constraints) and application (inference-time biasing)

### What Remains Valid

- Toroidal topology provides bounded drift in toy models (Section 3, negative control intact)
- Lean 4 formal proofs of spectral gap bounds
- Rust/Python library primitives for torus mapping and bias computation
- The Coherence Shield product value proposition (PQ attestation, audit trail, prompt hardening)

### Recommended Direction

Training-time Karmonic spectral regularization — integrating toroidal constraints into the loss function during fine-tuning — remains untested and is the natural next step suggested by the toy model results.

---

## Appendix A: Full Benchmark Prompts

### Geography (20 prompts)
1. The capital of France is [Paris]
2. The capital of Japan is [Tokyo]
3. The capital of Australia is [Canberra]
4. The capital of Brazil is [Brasilia]
5. The capital of Canada is [Ottawa]
6. Mount Everest is in [Nepal, Himalaya]
7. The Amazon River is in [South America, Brazil]
8. The Great Wall is in [China]
9. The Nile River flows through [Egypt, Africa]
10. The Sahara Desert is in [Africa]
11. The largest ocean is the [Pacific]
12. The longest river in the world is the [Nile, Amazon]
13. Australia is a [continent, country]
14. The Alps are in [Europe]
15. The Dead Sea is between [Israel, Jordan]
16. Venice is famous for its [canals, water]
17. The Eiffel Tower is in [Paris, France]
18. The Great Barrier Reef is near [Australia]
19. Tokyo is the capital of [Japan]
20. The Statue of Liberty is in [New York, USA]

### Science (25 prompts)
21. Water freezes at [0, 32, zero]
22. The largest planet is [Jupiter]
23. Einstein developed the theory of [relativity]
24. The chemical symbol for gold is [Au]
25. DNA stands for [deoxyribonucleic]
26. The atomic number of hydrogen is [1, one]
27. Photosynthesis converts [energy, glucose, sugar, sunlight]
28. Oxygen is about what percent of air [21, 20]
29. Pi equals approximately [3.14]
30. The speed of light is [300, 299, 186]
31. The human heart has [four, 4]
32. Newton discovered [gravity, motion]
33. The chemical symbol for water is [H2O]
34. The boiling point of water is [100, 212]
35. Electrons have a [negative]
36. The sun is a [star]
37. Diamonds are made of [carbon]
38. The human body has how many bones [206]
39. Sound travels faster in [water, solid]
40. The earth revolves around the [sun]
41. Gravity was discovered by [Newton]
42. The smallest unit of life is a [cell]
43. Mitochondria are the [powerhouse]
44. The pH of pure water is [7, seven, neutral]
45. The chemical symbol for iron is [Fe]

### History (20 prompts)
46. World War II ended in [1945]
47. The Declaration of Independence was signed in [1776]
48. The first human on the moon was [Armstrong, Neil]
49. The Berlin Wall fell in [1989]
50. World War I started in [1914]
51. The French Revolution began in [1789]
52. Columbus sailed to America in [1492]
53. The Roman Empire fell in [476, 5th]
54. The Renaissance began in [Italy, 14th, 15th]
55. The printing press was invented by [Gutenberg]
56. The American Civil War ended in [1865]
57. The Soviet Union collapsed in [1991]
58. The Titanic sank in [1912]
59. Martin Luther King Jr gave his famous speech in [1963]
60. The Great Depression started in [1929]
61. The first airplane flight was by the [Wright]
62. Mahatma Gandhi led [India, independence]
63. The Cold War was between [USA, Soviet, America, Russia]
64. Ancient Egypt was known for [pyramids, pharaohs]
65. The Industrial Revolution began in [Britain, England, 18th]

### Arts & Culture (20 prompts)
66. The Mona Lisa was painted by [Leonardo, Vinci]
67. Shakespeare wrote [Hamlet, Romeo, Macbeth]
68. Beethoven was a famous [composer, musician]
69. The currency of Japan is [yen]
70. Vincent van Gogh painted [Starry Night, sunflowers]
71. Romeo and Juliet was written by [Shakespeare]
72. The Sistine Chapel ceiling was painted by [Michelangelo]
73. Mozart was born in [Austria, Salzburg]
74. Harry Potter was written by [Rowling]
75. The Odyssey was written by [Homer]
76. Don Quixote was written by [Cervantes]
77. The currency of the UK is the [pound, sterling]
78. The currency of the EU is the [euro]
79. Picasso was a famous [painter, artist]
80. The Louvre is in [Paris, France]
81. The official language of Brazil is [Portuguese]
82. The Olympic Games originated in [Greece]
83. Coffee beans come from [plant, tree, cherry]
84. Bees produce [honey]
85. The Great Pyramid was built in [Egypt, Giza]

### Math & Computing (15 prompts)
86. Binary uses only [0, 1, two]
87. A triangle has how many sides [three, 3]
88. The square root of 144 is [12, twelve]
89. A byte contains how many bits [8, eight]
90. The programming language Python was created by [Guido, Rossum]
91. HTML stands for [HyperText, Markup]
92. The first computer programmer was [Ada, Lovelace]
93. A hexagon has how many sides [6, six]
94. The value of 2 to the power of 10 is [1024]
95. CPU stands for [Central, Processing]
96. A decade is how many years [10, ten]
97. A century is how many years [100, hundred]
98. The largest mammal is the [whale, blue]
99. The fastest land animal is the [cheetah]
100. Silk comes from [silkworm, worm]

---

## Appendix B: Parameter Sweep Results (OLMo)

Top 10 configurations from 100-configuration sweep:

| Rank | Alpha | Radius | Max Tokens | Accuracy | Error Reduction |
|------|-------|--------|------------|----------|-----------------|
| 1 | 0.20 | 3.0 | 3000 | 89.0% | +15.4% |
| 2 | 0.15 | 3.0 | 3000 | 88.5% | +11.5% |
| 3 | 0.20 | 2.5 | 3000 | 88.0% | +7.7% |
| 4 | 0.10 | 3.0 | 2000 | 88.0% | +7.7% |
| 5 | 0.25 | 3.0 | 3000 | 88.0% | +7.7% |
| 6 | 0.15 | 3.0 | 2000 | 87.5% | +3.8% |
| 7 | 0.20 | 3.0 | 2000 | 87.5% | +3.8% |
| 8 | 0.10 | 2.5 | 3000 | 87.0% | 0.0% |
| 9 | 0.05 | 3.0 | 3000 | 87.0% | 0.0% |
| 10 | 0.30 | 2.0 | 1440 | 86.0% | −7.7% |

**Observation**: OLMo requires larger radius (3.0) and more tokens (3000) compared to Qwen.

---

## Appendix C: Theoretical Foundation

The toroidal topology is inspired by the **Tonnetz** from music theory—a toroidal lattice representing pitch relationships. In the Tonnetz, moving along the torus corresponds to harmonic transformations (fifths, thirds).

We hypothesize an analogous structure exists in language: tokens that are "close" on an appropriately constructed manifold share semantic or syntactic properties. While the modulo mapping to a 12×12 torus is a simplification, it provides enough structure to create useful locality constraints.

The 12×12 grid (144 positions) was chosen for:
1. Alignment with musical theory (12 pitch classes)
2. Computational efficiency (small lookup space)
3. Sufficient granularity to differentiate token neighborhoods

Future work may explore learned manifolds or higher-dimensional tori.

---

*For questions or collaboration: sylvain@paraxiom.io*
