Toward Code Generation: A Survey and Lessons from Semantic Parsing Celine Lee Justin Gottschlich Dan Roth Intel Labs, University of Pennsylvania Intel Labs, University of Pennsylvania University of Pennsylvania [email protected] [email protected] [email protected] Abstract With the growth of natural language processing techniques and demand for improved software engineering efficiency, there is an emerging interest in translating intention from human languages to programming languages. In this survey paper, we attempt to provide an overview of the growing body of research in this space. We begin by reviewing natu- ral language semantic parsing techniques and draw parallels with program synthesis efforts. We then consider seman- tic parsing works from an evolutionary perspective, with specific analyses on neuro-symbolic methods, architecture, and supervision. We then analyze advancements in frame- works for semantic parsing for code generation. In closing, Figure 1. The Three Pillars of Machine Programming (credit: we present what we believe are some of the emerging open Gottschlich et al. [28]). challenges in this domain. 1 Introduction In this survey paper, we first provide an overview of the Machine programming (MP) is the field concerned with the processes of NL semantic parsing and of code generation in automation of all aspects of software development [28]. Ac- Sections 2 and 3, respectively. In Section 4, we summarize cording to Gottschlich et al. [28], the field can be reasoned the evolution of techniques in NL and code semantic parsing about across three pillars: intention, invention, and adaptation from the 1970s onward. Section 5 explores the question of (Figure 1). Intention is concerned with capturing user intent, supervision for semantic parsing tasks, while Section 6 dis- whether by natural language, visual diagram, software code, cusses modern advances in neural semantic parsing for code or other techniques. Invention explores ways to construct generation. To conclude, we consider some possible future higher-order programs through the composition of exist- directions of semantic parsing for code generation. ing – or novel creation of – algorithms and data structures. Adaptation focuses on transforming higher-order program 2 Natural Language Semantic Parsing representations or legacy software programs to achieve cer- Natural language analysis can be segmented into at least two tain characteristics (e.g., performance, security, correctness, fundamental categories: syntax and semantics. In general, etc.) for the desired software and hardware ecosystem. syntax is the way a natural language phrase is structured; In this paper, we discuss (i) semantic parsing and (ii) code the order and arrangement of words and punctuation. The se- arXiv:2105.03317v1 [cs.SE] 26 Apr 2021 generation, which chiefly fall within the boundaries of the mantics is the meaning that can be derived from such syntax. intention and invention pillars, respectively. In the context For example, the two sentences “the boy cannot go” and “it of natural language (NL), semantic parsing is generally con- is not possible for the boy to go”, are semantically equivalent cerned with converting NL utterances (i.e., the smallest unit even though they are syntactically different. By lifting seman- of speech) to structured logical forms. Once done, these logi- tics from syntax, NL semantic parsers can map semantically cal forms can then be utilized to perform various tasks such equivalent sentences to the same logical form, even when as question answering [41, 42, 47, 80, 86], machine transla- they have different syntaxes. An example of this is shown tion [5, 81], or code generation [38, 49, 73, 87], amongst other in Figure 2, where two syntactically different sentences are things. For semantic parsing for code generation, the end shown to be semantically equivalent using an abstract mean- logical form will usually be some form of software code. This ing representation (AMR) as its logical form (more details may be the direct output program [41, 49, 90, 94] or an inter- in Section 2.4). For the remainder of this section, we dis- mediate representation of code [21, 42, 68, 87, 88], which can cuss how NL semantic parsers extract meaning from natural subsequently be fed into a program synthesis component to language utterances into various machine-understandable generate syntactically sound and functionally correct code. representations. Figure 3. An example of a CCG category. Syntax (the ADJ represents an adjective part of speech) is paired with seman- tics (the lambda term expression) (credit: Artzi et al. [7]). Figure 2. Abstract meaning representation (AMR) of two semantically equivalent, but syntactically different sentences (credit: Banarescu et al. [12]). 2.1 Purpose of Natural Language Semantic Parsing The general purpose of structured logical forms for natural language is to have a representation that enables natural language understanding (NLU) and automated reasoning, amongst other things. Historically, NL semantic parsers have Figure 4. Sample SQL query for a flight reservation enabled computers to query databases [89], play card games (credit: Iyer et al. [37]). [27], and even act as conversational agents such as Apple’s Siri and Amazon’s Alexa. Semantic parsing has taken on many forms. Early hand-crafted rules made way for super- The sentence “he eat apples” is grammatically incorrect be- vised learning techniques. Then, due to the labor-intensive cause a single noun acts with a verb that must end in ‘s.’ and error-prone process of hand-labeling data for paired nat- Likewise, in semantic parsing, a logical form can be gram- ural language and logical form datasets, researchers turned matically constrained to ensure well-formedness. A set of their attention toward weakly supervised [9, 20] and other grammatical rules constrains the search space of possible learning techniques that tend to require less labeled data. outputs. Combinatory categorical grammar (CCG) [76, 77] is one such example of a popular grammar formalism. It has 2.2 Components of a Semantic Parsing System historically made frequent appearances in semantic parsing Given an NL input, a NL semantic parsing system gener- models [45, 91, 92] due to its ability to jointly capture syn- ates its semantic representation as a structured logical form. tactic and semantic information of the constituents which it These logical forms are also known as meaning represen- label. Consider the example in Figure 3. By pairing syntactic tations or programs. To generate these outputs, semantic and semantic information, CCGs can describe textual input parsing pipelines usually trained by some learning algorithm for a machine to understand the semantics with the syntax. to produce a distribution over the output search space and then search for a best scoring logical form in that distribu- 2.4 Meaning Representations tion. This logical form can then be executed against some Meaning representations are the end product of NL semantic environment to carry out an intended task (e.g. to query a parsing. The output logical formula, or meaning represen- database). Because these logical forms are generally designed tation, grounds the semantics of the natural language input to be machine-understandable representations, they tend to in the target machine-understandable domain. A simple ex- have a structured nature, following an underlying formalism ample of logical forms is a database query. Popular datasets by which some grammar can be used to derive valid logical explored in semantic parsing include Geo880, Jobs640, ATIS, forms. Insight into the grammar of a set of logical forms and SQL itself [20, 37, 89]. An example of a SQL query is can be leveraged by different semantic parsing methods to shown in Figure 4. Another class of semantic parsing outputs improve performance. For example, semantic parsing for is NL instructions to actions, such as the model in Figure 5 for code generation should have a meaning representation that learning Freecell card game moves. Note that in these cases, can deterministically be transformed into valid code. There- the semantic parser is specific to a particular domain, and fore, the output space can be constrained by the underlying may not generalize to out-of-domain inquiries or differing grammar formalisms that define syntactically sound code. data structures. NL semantic parsing efforts have also translated natural 2.3 Grammars language input semantics into lambda calculus expressions. Grammar in the context of natural language processing is The expressive power of lambda calculus allows the incorpo- a set of rules that govern the formation of some structure ration of constants, logical connectors, quantifications, and (parsing of NL utterances) to ensure well-formedness. A fa- lambda expressions to represent functions [92]. miliar example is English grammar: number, tense, gender Sentence: what countries border France and other features must be consistent in an English sentence. Logical Form: _G.2>D=CA~¹Gº ^ 1>A34AB¹G, 퐹A0=24º 2 Many code recommendation systems use code similarity to retrieve different implementations of the same intention. Semantic code representations can provide a foundation on which to extract code similarity. Facebook et al.’s Aroma system for code recommendation [51] represents a program Figure 5. A natural language sentence (denoted x), a logical by a simplified parse tree (SPT): the parse tree is defined as formula corresponding to
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages12 Page
-
File Size-