Anvil compiler separates language models and reliable code for optimization
Where the LLM Ends and Reliable Decisions Begin
Programming Languages
Summary
It can be tricky to turn a problem described in normal language into code that computers use to find the best solution. This paper explains a way to use language models just once to write a math formula, then a carefully designed program turns that formula into code without relying on the language model again. The authors show this method works well on many example problems, with very fast and reliable code creation. Most errors come from mistakes in the math formula, not the translation to code. This approach uses language models only where they work best and avoids relying on them too much.
What this means in practice
- •For software developers: Convert natural language optimization problem descriptions into reliable executable code faster and more predictably by using the ANVIL compiler architecture.
- •For operations research teams: Generate solver-ready optimization models from human-friendly problem statements with high accuracy and minimal runtime errors.
Authors
Priyadarshan Patil, Abhishek Basu, Vikas Reddy, Abhinav Gupta
Abstract
Systems that turn natural-language descriptions of optimization problems into solver-ready code generally use a language model at every stage, including the final translation from a mathematical formulation into executable model-building code. We propose the ANVIL compiler architecture, where we separate these concerns. A language model is called only once, assisted by constraint guidance based on problem type, to produce a LaTeX formulation. A deterministic compiler then translates that LaTeX into code with no language model involvement. We describe the deterministic compiler (a normalizer, a recursive-descent parser producing a typed intermediate representation, analysis passes that bind symbols to a dataset schema, and a code emitter) and evaluate it on the 354 easy and hard problems of the NLP4LP benchmark. The compiler produced code for 329 of 354 formulations (92.9%), taking the deterministic path in every one of those cases and never falling back to model-generated code. Median compile time was below the 10ms resolution of our timer. Overall, our formulations achieved an accuracy of 98.9% over easy problems and 91.1% for hard problems. The gap between these compilation and accuracy figures is a key point of analysis, and we analyze it: formulations that failed to compile, problems that returned as infeasible, problems raising errors at runtime, and problems returning a wrong objective. Almost all of these errors trace back to the formulation rather than to the translation. ANVIL performs exceptionally well on leading benchmarks by using language models purely where they are effective, rather than as a catch-all tool.