
Read the paper
Weave of Formal Thought
on GitHub
You know how a GPS navigator works? It doesn't just suggest roads — it maintains a live model of every legal turn from your current position, pruning illegal U-turns and one-way violations in real time. Now imagine a second, deeper system: instead of just blocking illegal moves, it teaches the driver to internalize the road network so they start *wanting* to take legal routes. That's the two-part architecture of Weave of Formal Thought. The committed claim: WoFT is the first constrained-decoding system that is provably sound AND complete with respect to the full Tree-sitter grammar specification — handling context-sensitive lexing, maximal-munch tokenization, and keyword extraction that prior frameworks like Synchromesh, PICARD, and GrammarFormer either approximate or ignore. Existing decoders sacrifice completeness (they reject some valid tokens) to avoid the complexity of real-world lexer behavior. WoFT does not. The mechanism is a speculative-lexing construction layered on top of generalized LR parsing. Where a standard constrained decoder maintains one parser state and one lexer state, WoFT maintains concurrent lexer-state hypotheses synchronized with a GLR graph-structured stack. Think of it as running multiple parallel lexer futures at each decoding step, then collapsing them once the next subword token resolves the ambiguity. This is what buys completeness — every subword token that could extend to a valid program prefix is admitted, and every token that cannot is rejected. No approximation, no vocabulary masking heuristics. The second contribution is orthogonal and arguably more interesting for the ML crowd. Rather than just constraining the decoder externally, WoFT trains the language model to interleave non-terminal grammar symbols — the parse tree's internal nodes — directly into its generation stream. The model treats these symbols as latent variables, optimized via the reweighted wake-sleep (RWS) algorithm targeting the importance-weighted evidence lower bound (IW-ELBO) of the surface text. The model learns which structural annotations help prediction and which are noise, creating what the authors call an "adaptive structural scratchpad." The headline number: fine-tuning StarCoder2-3B with the RWS objective on Python reduces per-token cross-entropy by 14.3% relative to a text-only supervised fine-tuning baseline. That's a meaningful signal that flat autoregressive training genuinely discards structural information that the model can recover when given the right inductive bias. The baseline here is SFT on the same data — not a stale comparison, but also not a comparison against the strongest code models available today (GPT-4, Claude, DeepSeek-Coder-33B). The integrity picture is mixed in the way single-author papers often are. The formal engine claims are backed by mathematical proof — soundness and completeness with respect to Tree-sitter's specification — which is strong. The ML results are empirical on one language (Python), one model (StarCoder2-3B), and one metric (cross-entropy). No downstream task evaluation (HumanEval, MBPP, SWE-bench) is reported. Code is released on GitHub, which is a significant plus. But the absence of pass@k or functional correctness numbers means we're measuring the model's surprise, not its actual coding ability. The obvious next experiment is evaluating on downstream code-generation benchmarks — HumanEval pass@1, MBPP, or similar. The 14.3% cross-entropy improvement is suggestive but not dispositive: lower perplexity doesn't always translate to better functional correctness. My honest read is (c) — the authors are saving this for the next paper, because the formal-engine contribution is already substantial and mixing in benchmark results would dilute the theoretical narrative. But it also might be (b): the cross-entropy gains may not fully transfer to pass@k, and reporting that would undercut the story.
The analogy
Like a GPS that both blocks illegal turns in real time AND gradually teaches the driver to internalize the road network — so over time the driver wants to take legal routes, not just gets prevented from illegal ones.
GPS navigator
Maintains a live model of every legal turn from the current position, pruning illegal moves while the driver learns the road network
WoFT decoder
Maintains concurrent lexer-state hypotheses over a GLR stack, pruning invalid tokens while the LLM learns to internalize parse-tree structure as latent variables
Honest assessment
WoFT is two papers stapled together, and both halves are interesting. The formal-engine contribution — provably sound and complete constrained decoding for full Tree-sitter grammars — is genuinely novel and solves a real gap in existing frameworks. The latent-syntax fine-tuning via RWS is a clever mechanism with a strong signal (14.3% CE reduction), but without downstream task evaluation it remains a promissory note. Single-author, single-language, single-model, single-metric. The code release is a strong counterweight. If you build constrained-decoding infrastructure, the formal engine matters today. If you train code models, wait for the HumanEval numbers.
What Is CLAIMS?
70
/ 100
BedrockNews applies a structured analytical framework called CLAIMS to academic papers and technical research releases.
How CLAIMS worksClaim
4/5
Ladder
3/5
Architecture
4/5
Integrity
3/5
Milestone
3/5
Successor
4/5
What is this paper actually committing to?
Two-part claim, both real. Sound+complete constrained decoding for full Tree-sitter is a genuine first. Latent-syntax fine-tuning via RWS is a significant new mechanism. The formal guarantee is the stronger half.
The field fight
Should code LLMs enforce syntax externally via constrained decoding, or learn structural awareness internally?
Side A
External grammar masks at decode time are sufficient; the model doesn't need to understand syntax, just be prevented from violating it
Held by: Synchromesh, PICARD, GrammarFormer, Outlines
Side B
The model should internalize grammatical structure as part of its representations; external constraints alone leave performance on the table
Held by: Grammar-prompting, structured fine-tuning approaches
Milestone tracker
Unlocks: Practical constrained+aware code generation that provably never produces syntax errors while also coding better
Current
14.3
% CE reduction
StarCoder2-3B on Python
Next
5+
% pass@1 gain
HumanEval improvement
1-2 papers if the cross-entropy gains transfer to functional correctness
Verified Facts (5)
Fine-tuning StarCoder2-3B with our RWS objective reduces per-token cross-entropy by 14.3% relative to a text-only SFT baseline
Sound and complete with respect to the full Tree-sitter specification
Augmenting generalized LR (GLR) parsing with a speculative-lexing construction that maintains concurrent lexer-state hypotheses synchronized with a GLR graph-structured stack
Utilizing the reweighted wake-sleep (RWS) algorithm to optimize the importance-weighted evidence lower bound (IW-ELBO) of the surface text
Code is available at https://github.com/alexbouayad/formal
Practical Implications (4)
Teams building constrained-decoding pipelines for code generation now have a formal specification to target — sound and complete w.r.t. Tree-sitter — rather than ad hoc grammar masks that sacrifice completeness
The speculative-lexing construction could be adopted by existing libraries like Outlines or llama.cpp grammar sampling to handle context-sensitive lexing correctly
The latent-syntax training method suggests a new fine-tuning paradigm: let the model learn which parse-tree annotations help, rather than forcing a fixed structural policy
For production code-generation systems, the formal guarantee means zero syntax errors in output — a real deployment concern that current systems handle with retry loops
More latest news
Read all