Don’t Generate, Discriminate: A Proposal for Grounding Language Models to Real-World Environments (2023)

Abstract: A key missing capacity of current language models (LMs) is grounding to real-world environments. Most existing work for grounded language understanding uses LMs to directly generate plans that can be executed in the environment to achieve the desired effects. It thereby casts the burden of ensuring grammaticality, faithfulness, and controllability all on the LMs. We propose Pangu, a generic framework for grounded language understanding that capitalizes on the discriminative ability of LMs instead of their generative ability. Pangu consists of a symbolic agent and a neural LM working in a concerted fashion: The agent explores the environment to incrementally construct valid plans, and the LM evaluates the plausibility of the candidate plans to guide the search process. A case study on the challenging problem of knowledge base question answering (KBQA), which features a massive environment, demonstrates the remarkable effectiveness and flexibility of Pangu: A BERT-base LM is sufficient for setting a new record on standard KBQA datasets, and larger LMs further bring substantial gains.Pangu also enables, for the first time, effective few-shot in-context learning for KBQA with large LMs such as Codex.

## introduction language models (lms) such as bert @xcite , @xcite , and codex @xcite have demonstrated an extraordinary capacity in understanding and generating both natural language @xcite and generic programs (e.g., python) @xcite @xcite . the recent release of chatgpt and similar large lms is elevating this paradigm to a new level. it seems to point us towards a future where natural language serves as a universal device, powered by lms, for automated problem solving and interacting with the (computing) world. 1 the pangu library: osu-nlp-group/pangu. however, a key missing piece in realizing this future is the connection between lms and realworld environments, including both digital environments (e.g., databases, knowledge bases, excel spreadsheets, software, websites, among others) and physical environments (e.g., instruction following robots @xcite ). such environments are where many real problems lie. for example, a biologist may need to find all the species of a certain butterfly genus and their geographic distribution from a biology knowledge base, a local grocery store owner may want to visualize the historical sales of different item categories in excel to decide what and how much to restock before the holiday season, and a physician may need to find patients with specific conditions in a large database of electronic medical records to inform the current diagnosis. how can lms enable solving all these problems, which involve seeking information or taking actions in a specific environment, with natural language? each environment is a unique context for interpreting natural language requests from users. grounding, i.e., linking of (natural language) con-cepts to contexts @xcite , therefore becomes the fundamental problem. more precisely, we need to produce a plan that can be executed in an environment to achieve the desired effects of the corresponding language request. when a plan is described in a formal language (e.g., sql for relational databases @xcite or apis for web services @xcite ), it is also called a program. the unique challenge of such grounded language understanding problems stems from 1) the vast heterogeneity of environments and their planning languages (e.g., sql, graphql/rest apis, λ-calculus, and robot planning languages), and 2) the vast, oftentimes infinite, number of possible instantiations (or states) of each environment. some environments can also be dynamic, e.g., a database that is constantly updated or a physical environment with moving objects. most existing methods for grounded language understanding follow the popular sequence-tosequence framework @xcite and generate the plans/programs in an autoregressive fashion @xcite @xcite . a core thesis of this paper is that directly generating plans may not be the optimal way of using lms for grounded language understanding. it requires lms to have intimate knowledge about each specific planning language and environment, neither of which may be part of an lm's pre-training, to ensure the grammaticality and faithfulness of the generated plans. 2 the infinite and dynamic environment states also reduce the potential effectiveness of pre-training for improving faithfulness, even if one manages to do so. furthermore, autoregressive generation with a neural lm lacks fine-grained control over planning; it is cumbersome, though not impossible, to factor preferences, business logic, and other values and constraints into the plan generation process. a focus of recent work is to alleviate (some of) these limitations by augmenting autoregressive generation with environment-specific pretraining @xcite or constrained decoding @xcite @xcite . however, the fundamental challenges still largely remain. mathematically, an lm is simply a joint distribu-tion p(x 1 , x 2 , ..., x n ) that factors as a product of conditional distributions n @xmath0, ..., x i-1 ). existing work leverages the conditional distribution formulation to generate the plan. it thereby casts the burden of ensuring grammaticality, faithfulness, and controllability all on the lm. the main proposal of this paper is to disentangle lms from these responsibilities and let lms be what they originally are-a model that assigns a probability to a sequence of tokens. in other words, we advocate for using the joint distribution formulation of lms to evaluate the plausibility of (utterance, candidate plan) pairs instead of directly generating the plan. to this end, we propose pangu, a generic framework for grounded language understanding that capitalizes on the discriminative ability of lms instead of their generative ability (figure 1 ). 3 pangu consists of a symbolic agent and a neural lm working in a concerted fashion. the symbolic agent explores the environment to propose candidate plans, which are guaranteed by design to be both grammatical and faithful. for most real-world environments, due to the size of the search space or partial observability, it is necessary for the agent to search in the environment and incrementally extend or refine the plans. the lm plays a key role in this search process-it evaluates the candidate (partial) plans at each search step and guides the agent towards promising search directions; it also determines when the search ends. finally, it is also easier to control the search process of a symbolic agent than the generation process of a neural lm. as a case study, we instantiate the proposed framework for complex question answering over knowledge bases (kbqa). kbqa provides an ideal testbed for grounded language understanding because of its massive environment-direct generation with lms often fails dramatically @xcite . we show that simply using bert-base with pangu is sufficient for setting a new record on standard kbqa datasets, and larger lms further bring substantial gains. pangu also enables, for the first time, few-shot kbqa by prompting large language models (e.g., codex): using only 10 labeled examples, it outperforms all prior methods on graphq @xcite . it provides unprecedented uniformity for using lms-one can easily plug encoder-only lms, encoder-decoder lms, or decoder-only lms into pangu, through either fine-tuning or in-context learning. these results highlight the remarkable effectiveness and flexibility of pangu and validate the proposal of using lms for discrimination instead of generation. ## approach an overview of the pangu framework is presented in algorithm 1. an overarching assumption of pangu is that a complex plan can be incrementally constructed by an agent through its exploration in an environment. such an agent can be a robot doing household tasks in a physical environment @xcite , or a virtual agent that orchestrates api calls of different web services @xcite or traverses a database/kb @xcite . starting from a set of initial plans p 0 (may be empty), at each step, the agent interacts with the environment e to extend the current plans into a new set of candidate plans (line 4). the candidate plans are guaranteed to be valid (i.e., both grammatical and faithful). an lm then scores the candidate plans, and the top k (the beam size) plans are retained for further exploration in the next step (line 5). the same procedure loops until a termination check is passed (line 6); the best plan is then returned. pangu mainly shines in that a symbolic agent explores the environment to propose valid plans and shields the lm from having to handle the large search space for valid plan generation. instead, the lm only focuses on evaluating the plausibility of the proposed plans. an lm can be easily finetuned to excel at this assignment, or, in the case of llms such as codex, they come with such ability out of the box, which enables few-shot in-context lm scores and prunes plans 5 pt ← top-k(q, ct) 6 if check-termination() = true then 7 return top-scored plan 8 t ← t + 1 ## conclusions in this paper, we proposed to capitalize on the discriminative ability of language models (lms) instead of their generative ability for grounded language understanding. building on this proposal, we proposed a generic framework, pangu, which consists of a symbolic agent and a neural lm working in a concerted fashion and creates a better separation between the realm of the neural and the symbolic. this work opens the door for developing versatile and sample-efficient grounded language understanding systems that fully capitalize on the language understanding ability of lms while avoiding their limitations. it also sheds light on developing better neuro-symbolic systems in general.