There is a newer version of the record available.

Published March 8, 2026 | Version v2.1

A Two-State Decoding Model for Hallucination-Resistant Language Generation: Context-Anchored Generation via Semantic Drift Control

Authors/Creators

  • 1. Independent Researcher

Description

Hallucinations in large language models (LLMs) arise primarily from uncontrolled semantic drift during autoregressive token generation: the model’s probability distribution gradually diverges from the prompt’s intended semantic frame, producing fluent but ungrounded continuations. Existing mitigation strategies largely operate outside decoding—via retrieval-augmented generation (RAG), reinforcement learning from human feedback (RLHF), or post-generation filtering—leaving the core inference-time process unconstrained.

This paper proposes Context-Anchored Generation (CAG), a lightweight, model-agnostic decoding governance layer that inserts a two-state control system between the model’s raw token probability distribution and final token selection. CAG maintains a persistent semantic frame (anchor) initialized from the prompt, and governs generation via two modes: Constraint Mode, which enforces semantic proximity via cosine similarity filtering; and Expansion Mode, which permits controlled divergence upon pivot detection. Transitions are governed by a drift coefficient δ_t and accumulated drift window D_t, both derived from embedding-space similarity to the anchor frame.

CAG operates purely at decoding time, adds only per-token similarity computation (near-linear overhead over the candidate set), requires no model retraining, and mitigates not only hallucinations but secondary drift-related pathologies: repetition loops, long-context incoherence, and premature topic abandonment. A fully validated reference implementation is provided, including a drop-in HuggingFace integration path and a mathematical validation suite (21/21 properties verified).

 

Files

cag code.pdf

Files (210.4 kB)

Name Size Download all
md5:74962fc3d5a06782a6735d758626619a
77.4 kB Preview Download
md5:47adf79e41f85330d1cacd51b99eee7f
133.0 kB Preview Download