Search papers, labs, and topics across Lattice.
This paper introduces Autogrammar, an agent that autonomously learns context-free grammars from documentation and execution data to enhance language model (LM) performance in generating syntactically valid programs in domain-specific languages (DSLs). By formalizing Autogrammar as a Kripke structure and employing linear temporal logic constraints, the authors demonstrate that their approach can achieve near-perfect precision on unseen data while significantly reducing execution time. The results show that grammar-constrained decoding using Autogrammar-generated grammars outperforms existing LM baselines and formal techniques, achieving superior performance on real-world tasks with minimal loss in precision.
Autogrammar can automatically learn context-free grammars that boost language model performance, achieving near-perfect precision and tripling execution speed on DSL tasks.
Language models (LMs) are increasingly used to interact with external services via programs written in domain-specific languages (DSLs). Unfortunately, since DSLs are often low-resource and esoteric, LMs frequently produce syntactically invalid programs in these languages. Grammar-constrained decoding can eliminate such failures, but requires syntactic constraints. These are usually in the form of a context-free grammar for the target language, an artifact that is hard to come by for third-party DSLs. In this work, we define an agent, called Autogrammar, that automatically learns context-free grammars from documentation and execution data. Autogrammar is formalized as a Kripke structure whose nondeterministic choices are resolved by a language model, enabling declarative control of agent behavior via linear temporal logic constraints. We evaluate four versions of Autogrammar on three DSLs (i.e., Amazon CloudWatch Logs Insights, Dynatrace Query Language, and Datadog Search Syntax) and find that it generates grammars that achieve near perfect precision on unseen data; that temporal restrictions reduce execution time by 3.8x without incurring statistically-significant loss in precision; that execution data is crucial while documentation is dispensable; and that grammar-constrained decoding using Autogrammar-generated grammars significantly improves end-to-end LM performance on eight out of ten real tasks, matching or exceeding the performance of a professionally-maintained grammar. In comparison, the context-free grammars generated by existing LM baselines and a state-of-the-art formal technique perform significantly worse over the same evaluation.