← Back to feed
2026-06-24agentsdatacode

Weave of Formal Thought

Alexandre Bouayad

PDF preview for Weave of Formal Thought
Read on arXiv →

Key claim

Fine-tuning with latent syntax improves code generation accuracy.

In plain English

Imagine you're building a tool that generates code automatically. You want it to not only sound fluent but also be syntactically correct, meaning it should follow the rules of the programming language. Currently, many models can produce code that looks good on the surface, but they often fail to ensure that the code is valid, leading to errors when you try to run it. This is a significant issue because if the generated code isn't valid, it can waste time and resources during development. This problem is known as syntactic validity failure, where the model outputs code that looks right but doesn't actually work due to structural issues. Existing methods try to enforce rules, but they often miss out on important details, like how to handle different contexts in the code, which is where they fall short. This paper introduces a new method called Weave of Formal Thought (WoFT) that combines rigorous checks for syntactic correctness with a learning approach that helps the model understand the structure of the code better. It uses a formal engine to validate the code while also training the model to incorporate grammar symbols directly into its output. The result is a model that not only generates code that is more likely to be correct but also learns to retain important structural information that other methods might overlook. Practically, this means that developers can rely on the generated code to be more accurate, reducing the time spent debugging and improving overall productivity.

Novelty
8.5/10

The paper introduces a new paradigm for syntactic validation in code generation, significantly extending existing constrained-decoding frameworks.

Reliability
8.0/10

The claims are supported by empirical results showing a notable reduction in cross-entropy, with a clear methodology for fine-tuning.

Deep reliability assessment

The paper supports two narrower claims: a formal constrained-decoding construction intended to be sound/complete for Tree-sitter-style grammars, and a Python-only fine-tuning result showing lower surface-token cross-entropy for StarCoder2-3B versus a text-only SFT baseline. It overclaims somewhat on practical code-generation impact because the provided evaluation does not show downstream pass rates, compile rates, latency, developer usefulness, or comparisons against the strongest constrained decoding and grammar-aware training baselines.

Reproducibility

Code is reported as public at https://github.com/alexbouayad/formal. The provided text does not specify the training dataset, preprocessing details, evaluation split, or enough experimental configuration to fully reproduce the 14.3% cross-entropy result from the excerpt alone.

Key figure

The key architecture is a two-part WoFT pipeline: a formal Tree-sitter/GLR-based constrained decoder that validates prefixes during generation, paired with an RWS-trained latent syntax mechanism that lets the model interleave grammar non-terminals with surface code tokens.

Benchmark results

~Python corpus, not specified in the provided excerptrelative reduction in per-token cross-entropy versus text-only SFT: 14.3vs StarCoder2-3B text-only SFT baseline-14.3% per-token cross-entropy
GitHub1 repo
alexbouayad/formalOfficial
Weave of Formal Thought — Frontier Papers