Syntactic and Semantic Control of Large Language Models via Sequential Monte Carlo
Authors:
- João LoulaJLJoão Loula
- Benjamin LeBrunBLBenjamin LeBrun
- Li DuLDLi Du
- Ben LipkinBLBen Lipkin
- Clemente PastiCPClemente Pasti
- Gabriel GrandGGGabriel Grand
- Tianyu LiuTLTianyu Liu
- Yahya EmaraYEYahya Emara
- Marjorie FreedmanMFMarjorie Freedman
- Jason EisnerJEJason Eisner
- Ryan CotterellRCRyan Cotterell
- Vikash MansinghkaVMVikash Mansinghka
Preprint
Abstract
A wide range of LM applications require generating text that conforms to syntactic or semantic constraints. Imposing such constraints can be naturally framed as probabilistic conditioning, but exact generation from the resulting distribution -- which can differ substantially from the LM's base distribution -- is generally intractable. In this work, we develop an architecture for controlled LM generation based on sequential Monte Carlo (SMC). Our SMC framework allows us to flexibly incorporate domain- and problem-specific constraints at inference time, and efficiently reallocate computational resources in light of new information during the course of generation. By comparing to a number of alternatives and ablations on four challenging domains -- Python code generation for data science, text-to-SQL, goal inference, and molecule synthesis -- we demonstrate that, with little overhead, our approach allows small open-source language models to outperform models over 8x larger, as well as closed-source, fine-tuned ones. In support of the probabilistic perspective, we show that these performance improvements are driven by better approximation to the posterior distribution. Our system builds on the framework of Lew et al. (2023) and integrates with its language model probabilistic programming language, giving users a simple, programmable way to apply SMC to a broad variety of controlled generation problems.Keywords
All Related Versions
This publication has 15 references indexed in Scilit:
- Constructing a BPE Tokenization DFA2024
- Language models can learn complex molecular distributionsNature Communications, 2022
- An Introduction to Sequential Monte Carlo2020
- Elements of Sequential Monte CarloFoundations and Trends® in Machine Learning, 2019
- Probabilistic programming with programmable inference2018
- The sample size required in importance samplingThe Annals of Applied Probability, 2018
- Enumeration of 166 Billion Organic Small Molecules in the Chemical Universe Database GDB-17Journal of Chemical Information and Modeling, 2012
- Whole-sentence exponential language models: a vehicle for linguistic-statistical integrationComputer Speech & Language, 2001
- SMILES, a chemical language and information system. 1. Introduction to methodology and encoding rulesJournal of Chemical Information and Computer Sciences, 1988
- An efficient context-free parsing algorithmCommunications of the ACM, 1970