Syntactic Control of Language Models by Posterior Inference

Vicky Xefteri, Tim Vieira, Ryan Cotterell, Afra Amini


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.
Anthology ID:
2025.findings-acl.1300
Volume:
Findings of the Association for Computational Linguistics: ACL 2025
Month:
July
Year:
2025
Address:
Vienna, Austria
Editors:
Wanxiang Che, Joyce Nabende, Ekaterina Shutova, Mohammad Taher Pilehvar
Venue:
Findings
SIG:
Publisher:
Association for Computational Linguistics
Note:
Pages:
25350–25365
Language:
URL:
https://preview.aclanthology.org/display_plenaries/2025.findings-acl.1300/
DOI:
Bibkey:
Cite (ACL):
Vicky Xefteri, Tim Vieira, Ryan Cotterell, and Afra Amini. 2025. Syntactic Control of Language Models by Posterior Inference. In Findings of the Association for Computational Linguistics: ACL 2025, pages 25350–25365, Vienna, Austria. Association for Computational Linguistics.
Cite (Informal):
Syntactic Control of Language Models by Posterior Inference (Xefteri et al., Findings 2025)
Copy Citation:
PDF:
https://preview.aclanthology.org/display_plenaries/2025.findings-acl.1300.pdf