<?xml version="1.0"?><!DOCTYPE article SYSTEM "/project/take/software/searchbench_offline_processing/paperxml_generator/aclextractor/src/python/../resource/dtd/paperxml.dtd"><article><header><firstpageheader><page local="1" global="191"/><title>Programming With Unrestricted Natural Language</title><pubinfo>Proceedings of the Australasian Language Technology Workshop 2005,pages 191-199, Sydney, Australia, December 2005.</pubinfo><author surname="Vadas" givenname="David"><org  name="University of Sydney" country="Australia" city="Sydney"/></author><author surname="Curran" givenname="James R."><org  name="University of Sydney" country="Australia" city="Sydney"/></author></firstpageheader><frontmatter><p><b>Programming With Unrestricted Natural Language</b></p><p><b>David Vadas </b>and <b>James R. Curran</b></p><p>School of Information Technologies University of Sydney NSW 2006, Australia {dvadasl,james}@it.usyd.edu.au</p></frontmatter><abstract>We argue it is better to program in a natural lan­guage such as English, instead of a programming language like Java. A natural language interface for programming should result in greater readabil­ity, as well as making possible a more intuitive way of writing code. In contrast to previous controlled language systems, we allow unrestricted syntax, us­ing wide-coverage syntactic and semantic methods to extract information from the user's instructions. We also look at how people actually give pro­gramming instructions in English, collecting and annotating a corpus of such statements. We identify differences between sentences in this corpus and in typical newspaper text, and the effect they have on how we process the natural language input. Finally, we demonstrate a prototype system, that is capable of translating some English instructions into exe­cutable code. </abstract></header><body><section number="1" title="Introduction"><p>Programming is hard. It requires a number of spe­cialised skills and knowledge of the syntax of the particular programming language being used. Pro­grammers need to know a number of different lan­guages, that can vary in control structures, syntax, and standard libraries. In order to reduce these dif­ficulties, we would like to express the steps of the algorithm we are writing in a more natural manner, without being forced into a particular syntax. Ide­ally, we want a <i>plain English description.</i></p><p>We have built an initial prototype of such a system, taking unrestricted English as input, and outputting code in the Python programming lan­guage. There are many advantages of such a system. Firstly, any person that can write English, but not a programming language, would still be able to pro­gram. Also, it is often easier to write an English sen­tence describing what is to be done, than to figure out the equivalent code. Many programmers write in a pseudocode style that is almost English before elaborating on the details of an algorithm. There are also many tasks that can easily be described using English sentences, but are much harder to express as code, such as negation and quantification.</p><p>Another advantage is that code written in English will be much easier to read and understand than in a traditional programming language. Quite often, it is a difficult task to read another programmer's code. Even understanding one's own code can be hard af­ter a period of time. This is because without suffi­cient commenting — this is an explanation in plain English — one cannot tell what individual steps are meant to do together. In our system, the comments become the code.</p><p>Novice programmers could make great use out of such a system. They make simple syntax er­rors because they do not know the language well enough. Similarly, a novice programmer may know what function they want to use, but not its specific name and required arguments.</p><p>Finally, standard programming languages exhibit numerous technical details that are not evident in natural languages. Examples of this include typing, integer division and variable declarations. When we say in English |, we expect the result to be 0.6, not 0, as will result in many programming languages. These complications are a result of the computer's implementation, rather than the algorithm we are trying to describe. We would like to abstract away these issues, using information present in the En­glish sentences to figure out the correct action to take.</p></section><section number="2" title="An Example"><p>We can see in Figure 1 two example programs that could be entered by a user. The code for the first program matches what is outputted by the current system, but the second is more complicated and does yet work correctly.</p><p>Looking at the these examples, we can see a num­ber of difficulties that make the problem hard, as well as form some intuitions that can help to solve the task. For example, the first line of both programs involves three function calls because of variable typing.<page local="2" global="192"/> In Python, we must first read in a string, then strip away the newline character, and finally convert it to an integer. We can tell that integer conversion is required, firstly because of the name of the variable itself, and secondly, because a mathematical opera­tion is applied to it later on. Of course, it is still am­biguous. The user may have expected the number to be a string, and to have the string 2 concatenated to what was read in. However, the code in Figure 1 is more likely to be correct, and if the user wants to use a string representation, then they could specify as much by saying: read in a number as a string.</p><p>Another problem to deal with is the referencing of variables. In the first program, it is fairly easy to know that number is the same variable in all three sentences, but this is not as easy in the second. For the first sentence of the second program, the system needs to interpret 2 numbers correctly, and map it to multiple lines of code. Another complication is them, which references the previously mentioned variables. Finally, result, which does not appear in the second line, must still be part of the equivalent code, so that it can be used later.</p><p>One possibility that we could use to simplify the task that we are undertaking is to use a restricted natural language. However, we do not want to re­strict the vocabulary available to a user, or force them to construct sentences in a specific way, as is the case for existing restricted natural languages (Fuchs and Schwitter, 1996). Of course, this means that we must then deal with the inherent ambigu­ity and the great breadth of unrestricted natural En­glish. For this reason, we employ wide-coverage syntactic and semantic processing, that is able to process this extensive range of inputs. In order to resolve ambiguities, we can apply the intuitions we have described above. We may not be sure that the number should be treated as an integer, but this is more likely than treating it as a string. This is the conclusion that our system should come to as well.</p></section><section number="3" title="Background"><p>Clearly, the task we are undertaking is not trivial. Though there are a number of related systems to the one we propose, which have had success imple­menting a natural language interface for some task.</p><subsection number="3.1" title="Natural Language Interfaces to Databases"><p>The most popular task is a Natural Language In­terface for a Database (NLIDB) (Androutsopoulos et al., 1995). This is because databases present a large amount of information, which both novice and expert users need to query. A specific query lan­guage such as SQL must be used, which requires one to understand the syntax for entering a query, and also the way to join the underlying tables to ex­tract data that is needed. A NLIDB simplifies the task, by not requiring any knowledge of a specific query language, or of the underlying table structure of the database. We can see how this is similar to the English programming system that we are con­structing. Both take a natural language as input, and map to some output that a computer can process.</p><p>There are a number of problems that exist with NLIDBs. Firstly, it is not easy to understand all the ambiguity of natural language, and as such, a NLIDB can simply respond with the wrong an­swers. As a result of this, many NLIDBs only ac­cept a restricted subset of natural language. For ex­ample, in the NLIDB PRE (Epstein, 1985), relative clauses must come directly after the noun phrases they are attached to.</p><p>One feature of many NLIDBs, is the ability to engage the user in a dialogue, so that past events and previously mentioned objects can be referenced more easily. Two examples of this, anaphora and elliptical sentences, are shown in Figure 2.</p><p>Understanding that <i>it </i>refers to the ship, and that the female manager's degrees are again the subject of the question, reduces the amount of effort re­quired by the user, and makes the discourse more natural. We also intend to maintain a discourse be­tween the user and the computer for our own sys<i>&gt; Is there a ship whose destination is unknown?</i><page local="3" global="193"/>• Anaphora</p><table caption="Figure 1: Some example English sentences and their Python translations." class="main" frame="box" rules="all" border="1" regular="False"><tr class="row"><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p>English</p></td><td class="cell"><p>Python</p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p>read in a number add 2 to the number print out the number</p></td><td class="cell"><p>number = int (sys.stdin.readline().strip () ) number += 2 print number</p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p>read in 2 numbers</p><p>add them together print out the result</p></td><td class="cell"><p>numberl = int(sys.stdin.readline().strip () ) number2 = int(sys.stdin.readline().strip()) result = numberl + number2 print result</p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td></tr></table><p><i> </i>Yes.</p><doubt alpha="61.5" length="13" tooSmall="False" monospace="0.0">&gt; What is it?</doubt><p>What is  [the ship whose</p><p>destination is unknown]? Saratoga</p><p>• Elliptical Sentence</p><p><i>&gt; Does the highest paid female manager have any degrees from Harvard?</i></p><p>Yes, 1.</p><p><i>&gt; How about MIT? </i>No, none.</p><figure caption="Figure 2: An example of anaphora and an elliptical sentence"></figure><p>tem. This would also allow us to resolve much of the ambiguity involved in natural language by ask­ing the user which possibility they actually meant.</p></subsection><subsection number="3.2" title="Early Systems"><p>One of the first natural language interfaces is SHRDLU (Winograd, 1972), which allows users to interact with a number of objects in what was called <i>Blocksworld. </i>This system is capable of discriminat­ing between objects, fulfilling goals, and answering questions entered by the user. it also uses discourse in order to better interpret sentences from the user.</p><p>There were also a handful of systems that at­tempted to build a system similar to what we de­scribe in this paper (Heidorn, 1976; Biermann et al., 1983). Most of these used a restricted syntax, or de­fined a specific domain over which they could be used. Our system should have much greater cover­age, and be able to interpret most instructions from the user in some way.</p><p>More generally, we can look at a system that in­terprets natural language utterances about planetary bodies (Frost and Launchbury, 1989). This system processes queries about its knowledge base, but is restricted to sentences that are covered by its vocab­ulary and grammar. it deals with ambiguous ques­tions by providing answers to each possible reading, even when those readings would be easily dismissed by humans. With our system, we will determine the most likely reading, and process the sentence ac­cordingly.</p></subsection><subsection number="3.3" title="Understanding Natural Language"><p>One thing that we have not yet considered is how people would describe a task to be carried out, if they could use English to do so. The constructs and formalisms required by traditional program­ming languages do not apply when using a natu­ral language. in fact, there are many differences between the way non-programmers describe a task, to the method that would be employed if one were using a typical programming language (pane et al., 2001). Firstly, loops are hardly ever used explicitly, and instead, aggregate operations are applied to an entire list. These two methods for describing the same action are shown in Figure 3.</p><p>• Aggregate</p><p>sum up all the values in the list</p><p>• Iteration</p><p>start the sum at 0 for each in value in the list add this value to the sum</p><p>Figure 3 : Finding the sum of the values in a list</p><p>Another point of difference comes in the way people use logical connectives such as and and or, which are not neccesarily meant in the strictly logi­cal way that is the case when using a programming language. There are also differences in the way that people describe conditions, remember the state of objects, and the way they reference those objects.</p><p>HANDS (Pane et al., 2002) is a programming lan­guage that has been designed with this information, and with the idea of providing a programming in­terface that is more natural to a human user. This system takes a controlled language as input, but still demonstrates a number of methods, such as the ag­gregate operations described above, which make it possible for people to describe the actions they want performed as if they were writing in English.</p><p>There are actually many ways in which natu­ral language constructions map onto programming concepts. These <i>programmatic semantics </i>(Liu and Lieberman, 2004) can be seen in syntactic types, where nouns map to objects or classes, verbs map to methods, and adjectives to attributes of the classes. Using these concepts could allow us to more eas­ily understand an English sentence, and map it to a corresponding code output.</p><p>Metafor (Liu and Lieberman, 2005) is a system that uses these ideas, taking a natural language de­scription as input.<page local="4" global="194"/> As output, the system provides <i>scaffolding code, </i>that is, the outline for classes and methods, and only a small amount of actual con­tent. The code is not immediately executable, but can help the programmer in getting started.</p><p>NaturalJava (Price et al., 2000) is another natural language programming system that allows users to create and edit Java programs using English com­mands. Each sentence in the natural language input given to the system is mapped to one of 400 man­ually created case frames, which then extracts the triggering word and the arguments required for that frame. The frame can generate a change in the Ab­stract Syntax Tree (AST), an intermediate represen­tation of the code, which is turned in Java code later.</p><p>This system has a number of problems that we intend to improve on. Firstly, it can only handle one action per sentence. Our prototype can detect multiple verbs in a sentence, and generate code for each of them. Also, the AST representation Natu-ralJava uses makes it hard to navigate around a large amount of code, since only simple movement oper­ations are available.</p><p>Another problem with NaturalJava is that it maps to specific operations that are included in Java, rather than more general programming language concepts. This means that it is not adaptable to different programming languages. We intend to be more language-neutral. A user of our system should not need to look at the underlying code at all, just as a programmer writing in C does not need to look at the machine code.</p></subsection></section><section number="4" title="Combinatory Categorial Grammar"><p>Combinatory Categorial Grammar (ccg) is a type-driven, lexicalised theory of grammar (Steedman, 2000). Each word receives a syntactic category that defines its predicate-argument relationship with sur­rounding words. We can see a simple example of this in Figure 4.</p><p>Each word is assigned a category that defines how it is involved with other words in the sentence. These relationships are carried out through a num­ber of rules, such as forward and backward applica­tion, which can be seen in the example. Additional rules such as composition and conjuction also al­low the formalism to easily capture long-range de­pendencies. This is particularly important for our system, as the constructions used to describe pro­gramming instructions often contain non-standard constituents such as extraction, relativization, and coordination.</p><p>These possiblities result in a large number of interpretations, as a single word can be assigned a different category depending on how it is used, and the words that surround it. However, the ap­plication of statistical parsing techniques for ccg have shown that it is capable of performing wide-coverage parsing at state-of-the-art levels (Clark and</p><p>Curran, 2004).</p></section><section number="5" title="English Code Corpus"><p>In order to investigate the way that people would use English to describe a programming task, we el-licited responses from programmers, asking them to describe how they would solve sample tasks. These tasks included finding the smallest number in a list, splitting a string on a character and finding all primes less than 100. The respondents were all experienced programmers, since computer science staff were all that were easily available. As a re­sult of this, they tended to impose typical program­ming constructs on what they wanted to do, rather than using a simpler English sentence. For example, one respondent wrote For each number in the list compare to min., when Compare each number in the list to the min. is more straightforward. This demonstrates quite well the way that programming languages force us to use a specific unnatural syn­tax, rather than the freer style that a natural language allows. It also shows that experienced programmers can supply utterances that are less grammatically correct and therefore <i>harder </i>to process than what novices would be expected to write.</p><p>The corpus is comprised of 370 sentences, from 12 different respondents. They range in style quite significantly, with some using typically procedural constructs such as loops and ifs (complete with the non-sensical English statement: end loop in some cases), while others used a more declarative style.</p><p>We have semi-automatically tagged the entire corpus with ccg categories (called <i>supertags). </i>This process consisted of running the parser on the cor­pus, and then manually correcting each parse. Cor­rections were required in most sentences, as the way people express programming statements varies sig­nificantly from sentences found in newspaper text. An example of this is in Figure 5.</p><p>This sentence uses an imperative construction, beginning with a verb, which is quite different from declarative sentences found in newspaper text, and the earlier example in Figure 4. We can also notice that the final category for the sentence is <i>S[b]\NP </i>, rather than simply S. Another differ­ence is in the vocabulary used for programming tasks, compared to Wall Street Journal (WSJ) text. We find if, loop, and variables in the former, and <i>NP NP NP</i> <i>Initialise min variable     to zero</i><page local="5" global="195"/></p><doubt alpha="39.6" length="53" tooSmall="False" monospace="0.0">John               hit Mary       with        the bat</doubt><doubt alpha="53.5" length="43" tooSmall="False" monospace="0.0">~N~ ((S[dcl]\NP)/PP)/NP~~ÎVPP/NP NP[nb]/N N</doubt><doubt alpha="20.0" length="10" tooSmall="False" monospace="0.0">—&lt;T -&lt;T -&gt;</doubt><doubt alpha="55.2" length="29" tooSmall="False" monospace="0.0">(S [dcl]\NP)/PP PP S[dd]\NP S</doubt><doubt alpha="0.0" length="1" tooSmall="False" monospace="0.0">&gt;</doubt><doubt alpha="0.0" length="1" tooSmall="False" monospace="0.0">&lt;</doubt><figure caption="Figure 4: An example CCG derivation"></figure><doubt alpha="54.8" length="31" tooSmall="False" monospace="0.0">((S[b]\NP)/PP)/NP N/N~~ÎVPP/NPW</doubt><doubt alpha="42.9" length="14" tooSmall="False" monospace="0.0">((S[b]\NP)/PP)</doubt><doubt alpha="57.1" length="7" tooSmall="False" monospace="0.0">S[b]\NP</doubt><doubt alpha="75.0" length="4" tooSmall="False" monospace="0.0">N NP</doubt><doubt alpha="20.0" length="5" tooSmall="False" monospace="0.0">-&lt;T -</doubt><doubt alpha="80.0" length="5" tooSmall="False" monospace="0.0">NP PP</doubt><figure caption="Figure 5: A CCG derivation for an English programming instruction"></figure><p>million, dollars, and executives in the latter. Par­ticular words can also have different grammatical functions. For example: print is usually a noun in the WSJ, but mostly a verb while programming.</p></section><section number="6" title="System Architecture"><p>The system architecture and its components are shown in Figure 6.</p><doubt alpha="55.6" length="9" tooSmall="False" monospace="0.0">IUser \*—</doubt><p>Natural Language Input</p><doubt alpha="100.0" length="1" tooSmall="False" monospace="0.0">I</doubt><p>Firstly, the user will enter text that will be parsed by the ccg parser. We then translate the predicate-argument structure generated by the parser into a first-order logic representation of DRS predicates.</p><p>This gives us a more generic representation of the sentence, rather than the specific wording chosen by the user. The final step is to generate the code itself.</p><p>Throughout these three phases, we also intend to use a dialogue system that will interact with the user in order to resolve ambiguity in their input. For ex­ample, if the probability with which the parser gives its output is too low, we may ask the user to con­firm the main verb or noun. This is especially im­portant, as we do not intend for the system to be foolproof, but we do intend that the user should be able to solve the problems that they encounter, ei­ther through greater specification or rephrasing.</p><p>There are also a number of smaller tasks to be dealt with, such as anaphora resolution, and GUI construction. At this current stage though, we have only dealt with basic functionality.</p><p>We will now describe each of the components of the system in detail. Also, as we progress through each stage, we will follow the example previously shown in Figure 5. We will see how the processing we do manages to begin with this English input, and eventually output working Python code.</p></section><section number="7" title="Parser"><p>We use the C&amp;C ccg parser (Clark and Curran, 2004) for this first stage of processing. This has the advantage of being a broad coverage, robust parser, that is able to extract long range dependancies re­liably. We also have access to the code, and are thus able to make changes if needed, and are able to build new training models. In fact, we found that we did indeed need to train a new model for the parser as a result of the differences between programming statements and typical newspaper text, as described above.<page local="6" global="196"/> If we look at our example sentence, we can see some of the problems quite well. Figure 7 shows the parse provided by the original model.</p><table caption="Figure 6: The system architechture" class="main" frame="box" rules="all" border="1" regular="False"><tr class="row"><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p></p></td><td class="cell"><p>Syntactic Analysis</p></td><td class="cell"><p></p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p></p></td><td class="cell"><p></p></td><td class="cell"><p></p></td><td class="cell"><p></p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p></p></td><td class="cell"><p>Semantic Analysis</p></td><td class="cell"><p></p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p></p></td><td class="cell"><p></p></td><td class="cell"><p></p></td><td class="cell"><p></p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p>Function Identification</p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p></p></td><td class="cell"><p></p></td><td class="cell"><p></p></td><td class="cell"><p></p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p></p></td><td class="cell"><p>Code</p></td><td class="cell"><p></p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td></tr></table><p>We can see that Initialise not been identified as a verb, but is instead tagged as a proper noun. min is also misclassified as a verb, when it is the noun. This highlights the fact that the parser does not ex­pect the first word in a sentence to be a verb. We could not use this parse and expect to perform ade­quately in the following stages of the system.</p><p>For this reason we created and annotated the En­glish code corpus, in order to provide training data and allow us to build a new, and better perform­ing model. A similar process had been followed in Question Answering (QA) (Clark et al., 2004), be­cause questions also show quite different syntactic properties to newspaper text. This technique pro­duced a significant improvement for QA, and so we have reused this idea.</p><p>Following Clark et al., we used multiples of the English corpus, as it is quite small in comparison to the entire WSJ. These results are shown in Fig­ure 8, for training with just the WSJ (original), with the WSJ and the English code corpus (1x code), and with the WSJ and multiples of the English corpus (5x, 10x, 20x). We show results for POS tagging and supertagging, on a word-by-word basis, and also the proportion of whole lines that are tagged correctly. We can see that as we add more copies of the English code corpus, all accuracies continue to improve.</p><p>These results come from both training and testing on the English corpus, and thus are not completely rigourous. However, it does demonstrate the data is fairly consistently annotated. As a fairer compar­ison, we conducted 10-fold cross validation on the 20x corpus, where each fold contained the 20 copies of one-tenth of the English code corpus, together with sentences from sections 2-21 of the WSJ. Each fold contained lines from throughout the English corpus and the WSJ. The results show that the ac­curacies from training with the English code cor­pus were still significantly greater than the original model. Finally, with this new model, our example sentence is parsed correctly, as shown in Figure 5.</p></section><section number="8" title="Semantics"><p>From the syntactic representation of the sentence, we wish to build a more semantically abstracted ver­sion of what the user wants to translate into code. The advantage of this is that we can more readily ex-</p><p>%%% Initialise 'min'  variable to zero .</p><doubt alpha="33.3" length="18" tooSmall="False" monospace="0.0">| x4 x3 x5 xl x2 |</doubt><doubt alpha="46.2" length="13" tooSmall="False" monospace="0.0">| thing(x4) |</doubt><doubt alpha="30.8" length="13" tooSmall="False" monospace="0.0">| 'min'(x5) |</doubt><doubt alpha="30.8" length="13" tooSmall="False" monospace="0.0">| nn(x5,x3) |</doubt><doubt alpha="56.2" length="16" tooSmall="False" monospace="0.0">| variable(x3) |</doubt><doubt alpha="66.7" length="18" tooSmall="False" monospace="0.0">| initialise(xl) |</doubt><doubt alpha="50.0" length="16" tooSmall="False" monospace="0.0">| agent(xl,x4) |</doubt><doubt alpha="55.6" length="18" tooSmall="False" monospace="0.0">| patient(xl,x3) |</doubt><doubt alpha="10.0" length="10" tooSmall="False" monospace="0.0">| |x2|&gt;0 |</doubt><doubt alpha="30.8" length="13" tooSmall="False" monospace="0.0">| to(x1,x2) |</doubt><doubt alpha="53.8" length="13" tooSmall="False" monospace="0.0">| event(xl) |</doubt><figure caption="Figure 9: DRS for example sentence"></figure><p>tract the particular verbs and nouns that will become functions and their arguments respectively. Having a logical form also means we can apply inference tools, and thereby detect anomolies in the user's descriptions, as well as including other sources of knowledge into the system.</p><p>The ccg2sem system (Bos et al., 2004; Black­burn and Bos, 2005) performs this task, taking ccg parse trees as input, and outputting DRS logical predicates. A single unambiguous reading is always outputted for each sentence. The DRS for our ex­ample sentence is shown in Figure 9. We can see that the verb (xl) is identified by an event predicate, while the agent (x4) and patient (x3) are also found. One particular discriminating feature of the imper­ative sentences that we see, is that the agent has no representation in the sentence. We can also find the preposition (x2) attached to the verb, and this be­comes an additional argument for the function.</p><p>This logical form also extracts conditions that would be found in if statements and loops very well. Figure 10 shows the DRSs for the sentence: If num is -1, quit. We can see the proposition DRS (the middle box) and the proposition itself (x2), which entails another verb (x3) to be interpreted. That is, we should carry out the verb quit (x1), ifthe propo­sition is true. Almost all if statements in the corpus are identified in this way.</p></section><section number="9" title="Generation"><p>Having extracted the functional verb and its argu­ments, we then need to find a mapping onto an equivalent line of code. The simplest technique, which the current system uses, consists of a list of primitives, each of which describes the specific verb in question as well as a number of arguments. If the semantic information matches perfectly with a <i>Initialise</i> <i>variable to zero</i><page local="7" global="197"/></p><doubt alpha="100.0" length="3" tooSmall="False" monospace="0.0">min</doubt><doubt alpha="49.1" length="53" tooSmall="False" monospace="0.0">N      (S[dcl]\NP)/(S[adj]\NP) (S[adj]\NP)/PP PP/NP N</doubt><doubt alpha="100.0" length="2" tooSmall="False" monospace="0.0">nP</doubt><doubt alpha="50.0" length="4" tooSmall="False" monospace="0.0">_PP&gt;</doubt><doubt alpha="60.0" length="10" tooSmall="False" monospace="0.0">S[adj]\NP&gt;</doubt><doubt alpha="58.8" length="17" tooSmall="False" monospace="0.0">S[dcl]\NP S [del]</doubt><figure caption="Figure 7: The original, incorrect CCG derivation"></figure><doubt alpha="45.8" length="24" tooSmall="False" monospace="0.0">%%% If num is -1  , quit</doubt><doubt alpha="28.6" length="14" tooSmall="False" monospace="0.0">|   x6 xl x2 |</doubt><doubt alpha="0.0" length="29" tooSmall="False" monospace="0.0">|---------------------------|</doubt><doubt alpha="54.5" length="11" tooSmall="False" monospace="0.0">| thing(x6)</doubt><doubt alpha="60.0" length="10" tooSmall="False" monospace="0.0">| quit(xl)</doubt><doubt alpha="57.1" length="14" tooSmall="False" monospace="0.0">| agent(xl,x6)</doubt><p>| proposition(x2)</p><doubt alpha="36.4" length="11" tooSmall="False" monospace="0.0">| if(x!,x2)</doubt><doubt alpha="10.0" length="30" tooSmall="False" monospace="0.0">|             |   x4 x5 x3 | |</doubt><doubt alpha="3.0" length="33" tooSmall="False" monospace="0.0">|       x2:|------------------| |</doubt><doubt alpha="26.7" length="15" tooSmall="False" monospace="0.0">| | num(x4) | |</doubt><doubt alpha="11.1" length="9" tooSmall="False" monospace="0.0">| |x5|&gt;-1</doubt><doubt alpha="0.0" length="1" tooSmall="False" monospace="0.0">|</doubt><doubt alpha="0.0" length="28" tooSmall="False" monospace="0.0">| |                    | | |</doubt><doubt alpha="3.3" length="30" tooSmall="False" monospace="0.0">|   x3:|---------        | | |</doubt><doubt alpha="11.8" length="17" tooSmall="False" monospace="0.0">| | x4 = x5 | | |</doubt><doubt alpha="0.0" length="9" tooSmall="False" monospace="0.0">| |_| | |</doubt><doubt alpha="54.5" length="11" tooSmall="False" monospace="0.0">| event(x3)</doubt><doubt alpha="0.0" length="2" tooSmall="False" monospace="0.0">||</doubt><doubt alpha="0.0" length="7" tooSmall="False" monospace="0.0">| |_| |</doubt><doubt alpha="40.0" length="15" tooSmall="False" monospace="0.0">|   event(x1) |</doubt><doubt alpha="0.0" length="3" tooSmall="False" monospace="0.0">|_|</doubt><figure caption="Figure 10: DRS for if statement"></figure><p>primitive, then the equivalent code is generated. At present, there exist only a few primitives, shown in Figure 11. These primitives are made up of the functional verb, the list ofarguments they take, and a code template that the arguments are used in.</p><p>This system obviously has a number of weak­nesses. Firstly, that if the user chooses a verb that is not listed in a primitive, then no code can be generated. Also, some primitives would be described with the same verb and arguments, but require dif­ferent code, such as adding two numbers together, compared to adding one number to a list. This is similar to operator overloading, a feature present in a number of programming languages such as C++.</p><p>We can make a number of observations that can help us improve this step in the system. Firstly, we can reduce the number of possibilities by look­ing at the program as a whole, rather than as in­dividual lines. For example, for the second prob­lem mentioned above, if the user had previously de­clared that the second argument was a list, then we would know which of the two primitive operations was correct. We can also constrain the number of possibilities by using intuitive notions, such as not being able to output a previously unseen variable.</p><p>Also, we can take advantage of the limited do­main of programming. Rather than trying to list every sense of every verb in the English language together with its equivalent programming concept, we could create a much smaller set ofprogramming primitives, and simply map everything onto one of those. Considering the small number ofchoices and the constraints mentioned above, this may be possi­ble using a machine learning approach.</p><p>Of course, we must consider what to do when a function that is not one of the primitives is referred to. In such a case, and assuming it can be detected, we believe the most sensible thing to do is to ask the user to describe how to carry out such a func­tion, using the more basic primitive functions that already exist. Thus we would allow the creation<page local="8" global="198"/></p><table caption="Figure 8: Parser results" class="main" frame="box" rules="all" border="1" regular="False"><tr class="row"><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p>Training Data</p></td><td class="cell"><p>Coverage</p></td><td class="cell"><p>POS Word</p></td><td class="cell"><p>Super Word</p></td><td class="cell"><p>POS Line</p></td><td class="cell"><p>Super Line</p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p>Original model</p></td><td class="cell"><p>95.6757%</p></td><td class="cell"><p>0.873</p></td><td class="cell"><p>0.736</p></td><td class="cell"><p>0.359</p></td><td class="cell"><p>0.197</p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p>lx code</p></td><td class="cell"><p>93.2432%</p></td><td class="cell"><p>0.975</p></td><td class="cell"><p>0.848</p></td><td class="cell"><p>0.829</p></td><td class="cell"><p>0.510</p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p>5x code</p></td><td class="cell"><p>85.9459%</p></td><td class="cell"><p>0.994</p></td><td class="cell"><p>0.931</p></td><td class="cell"><p>0.962</p></td><td class="cell"><p>0.708</p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p>lOx code</p></td><td class="cell"><p>82.4324%</p></td><td class="cell"><p>0.996</p></td><td class="cell"><p>0.962</p></td><td class="cell"><p>0.975</p></td><td class="cell"><p>0.821</p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p>20x code</p></td><td class="cell"><p>82.7027%</p></td><td class="cell"><p>0.998</p></td><td class="cell"><p>0.978</p></td><td class="cell"><p>0.986</p></td><td class="cell"><p>0.889</p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p>20x code, 10-fold cross validation</p></td><td class="cell"><p>85.40542%</p></td><td class="cell"><p>0.974</p></td><td class="cell"><p>0.896</p></td><td class="cell"><p>0.840</p></td><td class="cell"><p>0.624</p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td></tr></table><p>Figure 11 : Primitives used for generation of user-defined functions, just as a normal program­ming language would.</p><p>Looking back to our example sentence once more, we proceed to extract the predicate (initialise) and argument information (min variable, 0) from the DRS. This maps to the initialise primitive in Fig­ure 11. The matching code, stored in the primitive, then comes out as:</p><p>min_variable = 0</p><p>This is clearly a suitable outcome, and we can say that for this case, the system has worked perfectly.</p></section><section number="10" title="Future Work"><p>There is a great deal of work still to be done, be­fore we will have constructed a usable system. We intend to progress initially by expanding the gener­ation component to be able to process most of the commands contained in the English code corpus. We also expect to do more work with the parser and semantic engine. For example, if we ind that the coverage or accuracy of the parser is insuficient, then we can create more data for our corpus, or de­sign specialised features to help disambiguate cer­tain word types. Similarly, we may ind that some information is not relevant or simply missing from the DRSs that are currently produced, in which case we would be required to extend the current system so that it can extract what is needed.</p><p>Once the three basic components described above function at a satisfactory level, then we will be­gin work on other components of the system. The largest of these is a dialogue component, which should solve a wide range of problems. These could include simple questions about the parse for a sen­tence:</p><p><i>&gt; Blerg the number </i>Is Blerg a verb?</p><p>It could also help in resolving some ambiguity, or inquire about some missing information.</p><p><i>&gt; Read in 2 numbers</i></p><doubt alpha="66.7" length="21" tooSmall="False" monospace="0.0">&gt; Add 2 to the number</doubt><p>Which number do you mean?</p><p><i>&gt; Open a file for reading</i></p><p>What is the name of the file?</p><p>Anaphora resolution is another problem fre­quently encountered in the English code corpus we have collected. As discovered previously in the case ofNLIDBs, having a system capable ofdealing with this phenonemon makes it a great deal easier to use. For this reason, we intend to implement such a com­ponent for our inal system.</p><p>Lastly, we intend to develop a GUI that allows a user to interact more easily with the system. Inte­grating the syntactic, semantic and generation com­ponents, together with a text editor, would allow the system to highlight certain functions and arguments. This would make it clearer to the user what the sys­tem is doing. The dialogue component in particu­lar would gain a great deal from this, as it could be made clear what sentence or word was being clari-ied, as well as the context it was in.</p></section><section number="11" title="Conclusion"><p>Programming is a very complicated task, and any way in which it can be simpliied will be of great beneit. The system we have outlined and proto­typed aims to allow a user describe their instructions in a natural language. For this, a user may be asked to clarify or rephrase a number of points, but will not have to corrrect syntax errors as when using a normal programming language.</p><p>Using modern parsing techniques, and a bet­ter understanding of just how programmers would write English code, we have built a prototype that is capable of translating natural language input to working code. More complicated sentences that de­scribe typical programming structures, such as if statements and loops, are also understood. Indeed, much of the work to be done involves increasing the coverage of the system in a general manner, so that it is able to understand a wider variety of user input. Once we have built a complete system that can make some understanding of almost any input, we expect it to be usable by novice and experienced program­mers alike.<page local="9" global="199"/></p><table class="main" frame="box" rules="all" border="1" regular="False"><tr class="row"><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p>Functional Verb</p></td><td class="cell"><p>Arguments</p></td><td class="cell"><p>Code Template</p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"><p>read print add initialise set assign iterate</p></td><td class="cell"><p>input output addAmount, addTo variable, setting variable, setting variable, setting item, list</p></td><td class="cell"><p>&lt;input&gt; = int(sys.stdin.readline()) print &lt;output&gt; &lt;addTo&gt; += &lt;addAmount&gt; &lt;variable&gt; = &lt;setting&gt; &lt;variable&gt; = &lt;setting&gt; &lt;variable&gt; = &lt;setting&gt; for &lt;item&gt; in &lt;list&gt;:</p></td><td class="cell"></td></tr><tr class="row"><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td><td class="cell"></td></tr></table></section><section title="Acknowledgements"><p>We would like to thank members of the Language Technology Research Group and the anonymous re­viewers for their helpful feedback. This work has been supported by the Australian Research Council under Discovery Project DP0453131.</p></section><references><p>I. Androutsopoulos, G.D. Ritchie, and P. Thanisch. 1995. Natural language interfaces to databases-an introduction. <i>Journal of Language Engineer­ing, </i>1(1):29-81.</p><p>A. Biermann, B. Ballard, and A. Sigmon. 1983. An experimental study of natural language program­ming. <i>International Journal of Man-Machine Studies, </i>18:71-87.</p><p>P. Blackburn and J. Bos. 2005. <i>Representation and Inference for Natural Language. A First Course in Computational Semantics. </i>CSLI Publications.</p><p>J. Bos, S. Clark, M. Steedman, J.R. Curran, and J. Hockenmaier. 2004. Wide-coverage seman­tic representations from a CCG parser. In <i>Pro­ceedings of the 20th International Conference on Computational Linguistics (COLING '04), </i>Geneva, Switzerland.</p><p>S. Clark and J.R. Curran. 2004. Parsing the WSJ using CCG and log-linear models. In <i>Proceed­ings of the 42nd Meeting of the ACL, </i>Barcelona, Spain.</p><p>S. Clark, M. Steedman, and J.R. Curran. 2004. Object-extraction and question-parsing using CCG. In <i>Proceedings of the SIGDAT Conference on Empirical Methods in Natural Language Pro­cessing (EMNLP-04), </i>pages 111-118, Barcelona, Spain.</p><p>S.S. Epstein. 1985. Transportable natural language processing through simplicity - the PRE system. <i>ACM Transactions on Office Information Sys­tems, </i>3:107-120.</p><p>R. Frost and J. Launchbury. 1989. Constructing natural language interpreters in a lazy functional language. <i>The Computer Journal. Special issue on lazy functional programming, </i>32(2): 108-121, April.</p><p>N. E. Fuchs and R. Schwitter. 1996. Attempto controlled English (ACE). In <i>Proceedings ofthe First International Workshop on Controlled Lan­guage Applications, </i>pages 124-136.</p><p>G. E. Heidorn. 1976. Automatic programming though natural language dialogue:   A survey.</p><p><i>IBM Journal of Research and Development, </i>20(4):302-313, July.</p><p>H. Liu and H. Lieberman. 2004. Toward a pro­grammatic semantics of natural language. In <i>Proceedings ofVL/HCC '04: the 20th IEEE Sym­posium on Visual Languages and Human-Centric Computing, </i>pages 281-282, Rome, September.</p><p>H. Liu and H. Lieberman. 2005. Metafor: Visual­izing stories as code. In <i>Proceedings ofthe ACM International Conference on Intelligent User In­terfaces, </i>pages 305-307, San Diego, CA, USA, January.</p><p>J.F. Pane, C.A. Ratanamahatana, and B.A. My­ers. 2001. Studying the language and struc­ture in non-programmers' solutions to program­ming problems. <i>International Journal ofHuman-Computer Studies, </i>54(2):237-264, February.</p><p>J F Pane, B A Myers, and L B Miller 2002 Us­ing hci techniques to design a more usable pro­gramming system. In <i>Proceedings ofIEEE 2002 Symposia on Human Centric Computing Lan­guages and Environments (HCC 2002), </i>pages 198-206, Arlington, VA, September.</p><p>D. Price, E. Riloff, J. Zachary, and B. Harvey. 2000. NaturalJava: A natural language interface for programming in Java. In <i>Proceedings ofthe 2000 International Conference on Intelligent User In­terfaces, </i>pages 207-211.</p><p>M. Steedman. 2000. <i>The Syntactic Process. </i>The MIT Press, Cambridge, MA.</p><p>T. Winograd. 1972. <i>Understanding Natural Lan­guage. </i>Academic Press.</p></references></body></article>