# Syntactic Control of Language Models by Posterior Inference

Source: [Syntactic Control of Language Models by Posterior Inference](<https://www.sota2.com/research/paper/68fa79431e209131cea7cf1c>)

Collection index: [llms.txt](<https://www.sota2.com/research/llms.txt>)

Data updated: 2026-01-04T04:24:57.752Z

Authors: Vicky Xefteri, Tim Vieira, Ryan Cotterell, Afra Amini

Published: 2025-06-08T14:01:34.000Z

## Abstract

Controlling the syntactic structure of text generated by language models is valuable for applications requiring clarity, stylistic consistency, or interpretability, yet it remains a challenging task. In this paper, we argue that sampling algorithms based on the posterior inference can effectively enforce a target constituency structure during generation. Our approach combines sequential Monte Carlo, which estimates the posterior distribution by sampling from a proposal distribution, with a syntactic tagger that ensures that each generated token aligns with the desired syntactic structure. Our experiments with GPT2 and Llama3-8B models show that with an appropriate proposal distribution, we can improve syntactic accuracy, increasing the F1 score from $12.31$ (GPT2-large) and $35.33$ (Llama3-8B) to about $93$ in both cases without compromising the language model's fluency. These results underscore both the complexity of syntactic control and the effectiveness of sampling algorithms, offering a promising approach for applications where precise control over syntax is essential.

## Recorded benchmark results

A research result applies to its stated dataset, split, metric and evaluation configuration. Compare like-for-like settings, preserve the metric's unit and direction, and distinguish paper-reported results from independent reproduction. The best result recorded here is not a claim of exhaustive, current global coverage.

- [Controlled Text Generation on Syntactic Control (Q = p) (test)](<https://www.sota2.com/research/sota/controlled-text-generation-on-syntactic-control-q-p-test.md>): Controlled Text Generation; Syntactic Control (Q = p) (test); Log Probability p(y): -22.71.

- [Controlled Text Generation on Syntactic Control (Q ∝ pq) (test)](<https://www.sota2.com/research/sota/controlled-text-generation-on-syntactic-control-q-pq-test.md>): Controlled Text Generation; Syntactic Control (Q ∝ pq) (test); Log Probability Q(y): 0.0001.

## Original sources and implementation

[Original paper](<https://arxiv.org/abs/2506.07154>)

[PDF](<https://arxiv.org/pdf/2506.07154.pdf>)

[Implementation](<https://www.sota2.com/github.com/rycolab/syntactic-control>)
