Elamur Research

API-Assisted Code Generation for Question Answering on Varied Table Structures

Paper · 2023 · Yihan Cao, Shuyi Chen, Ryan Liu et al.

Summary

A table can express a relationship through its layout. A percentage may sit under a disease name nested inside a broader heading, and the age group it describes may appear at the end of a separate chain of row labels. To answer a question about that percentage, a system has to read both chains and choose the right cells before doing any arithmetic. Other tables present their own challenges. A database can spread the relevant information across linked tables, while a simple Wikipedia table can ask about a fact that its cells leave implicit. Cao and colleagues study whether the same approach to question answering can handle these different cases.

Their framework represents table headers as paths and uses those paths as indexes in Pandas, a Python library for working with tabular data. A cell in a hierarchical table can then be addressed by its full row and column labels, and a flat table fits the same scheme with shorter paths. The authors show a code generator a question, a description of the table, and examples of questions paired with programs. The generator produces Python, which runs against the table to obtain an answer. The generated program can also call helper functions. The comparison helpers return the label associated with a larger or smaller value. A separate helper can ask factual questions about individual table entries and use the answers to filter rows.

The evaluation measures execution accuracy, the share of questions for which the selected program returns the correct answer. With Codex, the full Python system reaches 69.3 on the HiTab test split, compared with 59.6 for the authors’ plain Codex baseline and 40.7 for MAPO. It also leads the reported comparisons on the full AIT-QA evaluation and the Spider validation split. WikiTableQuestions is the exception. The full Python system scores 42.4 in the main WikiTableQuestions comparison, where BINDER scores 54.8. A separate experiment raises the Codex result to 46.7 by using SQL with the helpers on that benchmark.

The HiTab ablation shows how much the contribution of the table layout depends on the rest of the system. With the helpers absent, flattening the headings gives higher accuracy than preserving their hierarchy as separate index levels. With both helper types available, the hierarchical representation gives the higher score. The experiments also show gains from the framework with StarCoder, although its scores remain below those of Codex. The evidence therefore supports a shared way to represent tables and execute queries, with the gains depending on the generator, the structure of the table, and the operations the question calls for.

Deep dive: API-Assisted Code Generation for Question Answering on Varied Table Structures

Cao and colleagues turn questions about varied tables into executable Python and test when hierarchical indexes and helper functions improve answers. · about 35 minutes to read

The problem and its context

When a table’s layout carries meaning

A person reading a table can often tell which labels apply to a value by looking up and to the left. A heading that spans several columns applies to every column underneath it. A group label above several rows continues to apply even when it appears only once. The positions and groupings help a reader see the same labels without having to read them again on every line. For a system that has to select a value, those relationships determine what the value means. Reading only the final heading can leave several plausible choices.

The paper illustrates the point with a table about illnesses. The column for the percentage of people with cancer and the column for the percentage of people with a cold share a label for the kind of measurement. The disease heading distinguishes them. The table also distinguishes older and younger patients under a heading for the patient population. A question about which group is more likely to have cancer refers to a measure, a disease, and a set of groups at once. The required comparison becomes straightforward once those references have located the right values.

A flat relational table usually gives each column a single name. Its rows can be located with a row identifier or selected by a condition on a column. That shape supports a familiar kind of query, such as selecting the rows that meet a condition and summing their values. A database with several relational tables adds a different problem. The collection may contain a table for instructors and one for departments. The field identifying a department can occur in both, allowing a query to connect a person with information stored in the department table. The fields needed for the answer can thus be distributed across several tables even when each table is individually simple.

These layouts place different demands on the query. A hierarchical matrix can have meaningful levels on both axes. A relational database can require a relationship between records in separate tables. A single flat table can still require a sequence of operations, such as selecting rows and then aggregating values. The authors’ problem is to support these cases through a common way of representing the data and writing executable queries. How a table lays out its information and what a particular question asks the program to do remain distinct parts of that problem.

A further difficulty arises when the table assumes the reader knows something about the world. One of the paper’s examples has separate rows for Winnipeg and the rest of Manitoba. A question about Manitoba requires the two rows to be considered together. The table supplies the quantities and the row labels. The fact that Winnipeg belongs to Manitoba supplies the relationship needed to select them. A procedure that only checks whether a row label contains the province name can recover the explicitly named part and miss the city.

From a question to a program

The paper situates the work in semantic parsing, the task of expressing the meaning of a natural-language request in a form a computer can use. In the symbolic approach the authors describe, the immediate prediction is a program. The program identifies the rows or cells it needs and performs any calculations or comparisons. Its execution produces the answer. A different program can arrive at the same result, since several sequences of operations may implement the same request.

Earlier systems frequently chose a query language or an intermediate representation to suit a particular domain. The paper discusses SQL as an effective option for relational data and points to work on cross-domain text-to-SQL for examples of adapting the representation to difficult queries. A domain-specific logical form can give a parser convenient expressions for the operations that matter on its target data. Its usefulness elsewhere depends on whether it can express the new operations and refer to the new kinds of structure.

The paper uses Neural Symbolic Machines to illustrate the transfer problem. It describes the approach as designed for relational tables and reports 29.2% accuracy when it is used on the hierarchical matrix data in HiTab. The authors attribute that result to logical forms that handle hierarchical tables poorly. The example motivates a representation in which the levels of a header are explicit and can be addressed in the query. Neural Symbolic Machines

The authors also place their work alongside earlier uses of executable programs in visual question answering and planning. Visual questions can be decomposed into operations grounded in an image, while planning systems can produce code that refers to actions in an environment. Those applications illustrate the broader idea of generating a program that operates on information outside the question itself. In this paper, that environment consists mainly of tabular data, and the program can delegate certain judgments to helpers. Inferring and Executing Programs for Visual Reasoning · ProgPrompt

Why combine a table representation and a function interface?

An executable language gives the system a way to express operations. The data representation determines which parts of the table those operations can reach conveniently. If a hierarchical header is reduced to a string, the program can still use that string as a label. If the path is kept as a tuple, the program can use the individual levels when it selects data. The authors build their system around this latter choice. Python provides the language for expressing the query, and Pandas provides indexed tables on which the code can operate.

A general programming language also gives the authors the option of adding functions directly. A developer could write a comparison using ordinary Python on each occasion. A helper gives the generator a reusable way to express that intent, including the step of returning the entity label associated with the winning value. A factual helper serves another role. It can ask whether an entry belongs to a category the table leaves implicit, returning a judgment that the Python code can use during selection.

The paper credits BINDER with the idea of calling a language system as part of an executable query. Cao and colleagues carry that idea into their Python and Pandas setup and pair it with helpers that perform deterministic table operations. They also draw on earlier work showing that a prompt can teach a new task by demonstration and that a pretrained generator can produce code. The examples in this framework show how questions refer to indexed data and when a program can call an available helper. BINDER · Language Models are Few-Shot Learners · Evaluating Large Language Models Trained on Code

The experiments put both kinds of generality under pressure. The same basic design must accommodate Wikipedia tables, hierarchical matrices, airline documents, and databases with several related tables. The query generator must also decide what to do with each input. Tables that can be represented uniformly can still differ in what their questions demand. The ability to write a program for a table and the likelihood of writing the right program for a question are separate concerns.

The method, step by step

From a table and question to an answer

The method begins by identifying the headings that give table entries their meaning. It turns the row headings and column headings into paths, then attaches those paths as labels to the table’s values in Pandas. It presents the code generator with a textual view of the table, the current question, and demonstrations of solved questions. The generator proposes Python code that can refer to the actual Pandas table. The selected program runs against that table and may call a helper function while it runs.

From table headers and a question to an answer

The steps in order.

From table headers and a question to an answerStep 1: Build trees for row and column headings1. Build trees for row and column headingsStep 2: Collect paths from roots to leaf headings2. Collect paths from roots to leaf headingsStep 3: Index table values with those paths3. Index table values with those pathsStep 4: Prompt with table details, question, and demonstrations4. Prompt with table details, question, and demonstrationsStep 5: Generate and select an executable query5. Generate and select an executable queryStep 6: Run the query and any helper calls6. Run the query and any helper callsStep 7: Return the result as the answer7. Return the result as the answer

Consider the illness example from the opening figure. The system needs the cancer percentages for the two patient groups. It uses the column path through illness, cancer, and percentage, then chooses the row path for each group. The values in those cells are the inputs to the comparison. The row labels travel alongside them so that the helper can return the name of the group with the larger percentage. The answer is an age-group label, even though the decision that yields it compares numbers.

The same example separates the work done before the question from work specific to it. The header hierarchy can be represented before the system knows which disease or measurement a question will mention. The program then uses that structure to request the relevant cells. A question about counts can use the same table representation and follow a different column path. A question about a different disease changes a different part of the address. The labels make these choices visible in the generated program.

What the program predicts

The authors first give the usual symbolic setup for table question answering. An instance supplies a table and a question, and the system has to produce an answer. Both the question and the reference answer are textual sequences in this formulation. The intermediate prediction is written as follows.

p = M(q, t)

Here q is the natural-language question and t is the table. M is the generator that takes them as inputs. p is the program it produces. The parentheses and comma indicate that the generator takes the question and table together, and the equality names its output.

The predicted answer comes from executing the generated program.

a′ = exec(p, t)

Here exec is the operation that runs p, the generated program, on t, the table. a′ is the predicted answer. The prime distinguishes the prediction from a, the correct answer for the question. This formulation puts the program between the natural-language question and the result that will be scored.

The implementation specializes that general description. The execution environment is a Pandas table, and the generator receives a textual prompt that gives it enough information to refer to that environment. Its input describes the indexes and shows sample rows. At runtime, the code can compute over the data in the Pandas object. The distinction matters for a question that asks for an aggregate. A demonstration can teach the generator how to write an aggregation, while execution supplies the values on which the aggregation depends.

Turning header trees into indexes

The authors describe the structural intermediate representation with a tuple.

b = (T, L, V)

b is the representation built from the raw table. T is the tree for the top headings, which address columns. L is the tree for the left headings, which address rows. V is the collection of values in the table body. The parentheses group the trees and the data into a single representation. The paper calls the Pandas representation built from these components m.

A tree records the parent and child relationships between headings. In the illness table, the branch for a disease can have children for the count and percentage measures. The row tree has its own branch structure. The two axes play different roles even when they use the same kind of tree. One path identifies which measurement is being read, and the other identifies the group to which it applies. The body of the table holds the values at their intersections.

The next step walks each tree in preorder. That means the walk visits a heading before visiting the headings nested beneath it. As it descends, it builds the path of labels encountered so far. At a leaf, it records that path as a tuple, an ordered grouping of the labels. When it moves into another branch, the path reflects that branch’s ancestors. The tree’s artificial root serves as the start of the walk and is omitted from the stored labels.

This procedure produces a list of row paths from the left tree and a list of column paths from the top tree. The authors use the corresponding lists as the indexes of the body values in Pandas. In the illness table, the path that passes through illness, cold, and total becomes a column label with those successive levels. The word denoting the total has a precise meaning because the earlier elements of the tuple identify its branch. The paper’s additional hierarchical example uses the same procedure for headings about sources and mechanisms on one axis and kinds of full-time work on the other.

The order of the labels in a path records the hierarchy. Having illness and cancer somewhere in a concatenated heading can help a generator identify a column. Keeping them at separate index levels also records which heading contains the other and provides an address the program can use directly. The authors’ flattening comparison later tests whether this extra structure helps in practice under different helper settings.

A flat relational table uses the same representation with shallow trees. The column headings can be recorded without additional levels, and the row index can be represented similarly. For an instance with several relational tables, the method description says that the tables are converted to indexed objects and presented to the generator, which chooses the parts needed for the answer. In the instructor and department example, the relation between the tables resides in the data and their key fields. The generator has to write a query that uses those fields when the question crosses the table boundary.

The overview figure describes the representation for a multi-table input as a single hierarchical table, whereas the detailed walkthrough describes individual indexed objects supplied to the generator. The detailed account makes clear that the relevant tables are exposed to generation in the indexed representation. The paper leaves the precise packaging of every multi-table prompt less explicit than the traversal it gives for a single hierarchical table. The mechanics of building index paths are easiest to see in its examples where top and left headings are already organized as trees.

Showing the generator how to query the table

The Python prompt supplies a table description, a question, and worked examples of question-to-program mappings. For hierarchical tables, the prompt example includes a table title and the top and left paths. The method description also says the prompt includes a few rows in textual form. Together these pieces tell the generator what kinds of values and labels the table uses. An instruction to generate Python specifies the kind of completion expected.

The examples illustrate both programs that use ordinary Pandas operations and programs that call an assistant function. The instructions describe situations where the helpers are appropriate. The authors aim for a mix that teaches the available calls while encouraging ordinary table operations where they suffice. The prompt thus teaches an interface as well as a task. The generator has to produce code that uses the right table names, addressing conventions, and function arguments.

This use of examples is a form of few-shot learning. The authors condition generation on annotated solutions in the prompt. They use pretrained generators and supply the table-specific behavior at inference time. The annotations matter because they show what code is expected, including how to use an index path and how to pass arguments to a helper. The paper’s account of learning the APIs in context refers to this use of instructions and demonstrations.

The primary experiments use Codex, specifically code-davinci-002. The paper also evaluates StarCoder, an open-source code generator. Both are described as having been trained on natural-language and code sequences. Their role here is to bridge the ordinary wording of a question and the syntax of the query. Evaluation with both tests whether the representation and helper conventions can be used with different generators.

For the main configuration, the authors use five demonstrations for WikiTableQuestions, HiTab, and Spider, and eight for AIT-QA. The sampling temperature is 0.7 for both generators. For each question, they generate five candidate programs and select the one with the highest log probability. The ranking uses the generator’s assigned probability. With that selection made, execution determines the answer the evaluation will judge.

The number of demonstrations and the number of candidate programs describe different stages. The demonstrations are solved examples that appear before the question. The candidates are possible programs for the question being evaluated. Additional demonstrations change the information available during generation. Multiple candidates give the authors a set of possible outputs from which to choose. The appendix varies the demonstration count on two benchmarks, while the main implementation describes the same candidate selection rule for the generators it uses.

Operations that return a label

The operation APIs are Python functions called by the generated code. The authors demonstrate them with helpers for choosing the label associated with a maximum or minimum. Each helper receives a list of values and a corresponding list of labels. It finds the position of the relevant extreme in the values and returns the label at the same position. The shown implementation uses the first occurrence if there is a tie.

The need for the label motivates the design. In the illness example, finding the larger percentage is part of answering the question. A program must then associate the percentage with the correct group. The helper takes care of both steps using the alignment between the value list and the label list. The generator still chooses which cells to read and how to align them with the labels. If the program reads counts when the question asks about likelihood, a correctly implemented comparison will faithfully answer the wrong comparison.

The authors say they chose these helpers after observing that Codex handled requests for numeric values more easily than some questions asking which named entity came out on top. The functions give the generator a compact pattern to reuse for the latter cases. They show how a small piece of ordinary Python can make a recurring intent easier to express at the point of generation. The demonstrated interface can accommodate additional functions, whose behavior and teaching examples would have to be supplied.

Asking a factual question during execution

The QA API serves questions whose answer depends on outside knowledge. The generated program can create a question about each entry in a relevant part of the table and submit those questions to a language system. The responses are requested as Boolean judgments, true or false. The program associates the responses with the corresponding entries and uses the true cases for subsequent selection or computation. This procedure adapts an idea the authors credit to BINDER.

The paper illustrates the call with a column of cities and a request involving Canada. The program embeds each city name in a factual question about whether that city is in Canada. The answers form a column of judgments that lines up with the original table entries. The selected rows then support whatever operation the original question requires. The generator formulates the factual test as part of writing the code, and the factual judgments are obtained when that code runs.

The HiTab immigration example shows how this works on an evaluated kind of question. The question concerns the change in the share of immigrants who intended to settle in Manitoba. Winnipeg appears separately from the rest of the province. The appendix illustrates a helper call that yields affirmative answers for both the city and the row covering the rest of Manitoba. The program can then combine the appropriate values to answer the question. The table supplies the quantities. The factual calls supply the membership decisions that determine which quantities to combine.

This arrangement places the external judgment at a specific point in the computation. The program determines the predicate to ask about, the entries to test, and the calculation after filtering. A correct answer requires these choices to fit together. A factual call can give the correct location of a city and still contribute to a wrong answer if the program asks about the wrong province. Similarly, a suitable predicate can lead to the wrong selection if the answers to the factual calls are mistaken. The helper adds capabilities and also introduces another source of decisions.

Using SQL inside the same setup

The authors also test a version that asks the generator for SQL where the table is relational. They carry out this experiment on WikiTableQuestions using the pandasql extension. Generated queries run through SQLite and return Pandas data frames, so the surrounding Python framework can still use helper functions on the results. The SQL experiment changes the query language while keeping the table and execution setup compatible with the rest of the method.

The SQL prompt calls attention to data types. It says the columns begin as strings and asks for conversion where the operation needs another type. This instruction addresses a distinction that matters for questions about values. An operation such as taking a maximum has to compare values in the appropriate form. The generator must take the form of the data into account as well as the wording of the question. The authors relate some of the extra length of the Python solutions to the need to handle different kinds of input values.

This use of SQL is also a test of the framework’s modularity. Relational queries can use a different language for the part of the task that selects and transforms table data. The result still takes the form used by the Python helpers. The experiment asks whether an alternative query language can improve execution accuracy on the kind of table for which the authors considered it a natural fit.

Experiments and results

What the benchmarks test

The experiments cover different data sources, shapes, and kinds of questions. The authors use existing evaluation splits where they can and describe departures where the benchmark interface or dataset size leads them to choose another setting. These details matter when reading the headline results. The Spider comparison, for example, comes from validation questions, while AIT-QA is evaluated as a single test set.

WikiTableQuestions draws single relational tables from Wikipedia. The questions include operations such as finding a sum or maximum, as well as questions that require several operations to be composed. The paper lists 2,381 samples in the standard validation split and 4,344 in the standard test split and says it uses both. The main score table and the SQL comparison each give a single WikiTableQuestions score for each setting, with the split of those individual scores left unspecified. The comparisons can be read as reported benchmark results without assigning a split the score tables leave unlabeled.

HiTab contains hierarchical matrix tables drawn from statistical reports and Wikipedia. Its subjects include topics such as education, economics, and health. The authors report that the dataset contains 3,597 hierarchical tables and 10,672 questions. Their evaluation uses the test split of 1,584 samples. HiTab is also the benchmark for the main representation and helper ablation, making it the place where the paper connects the hierarchical-table results most directly to changes in the system.

AIT-QA is drawn from documents in the airline industry. It includes tables with hierarchical headings and matrix layouts, as well as domain-specific vocabulary. The dataset has 515 questions across 116 tables. The authors use all 515 as the test set. A result on this benchmark therefore reflects the particular mix of table structures and questions in that collection. The authors’ expectation that some of its questions suit the comparison helpers is discussed alongside the results.

Spider contains 200 databases spanning 138 domains. The databases have multiple relational tables linked by primary and foreign keys. A primary key identifies a record in its table, and a foreign key can refer to a record in another table. Questions can therefore require the query to follow a relationship across tables. The hidden evaluation accepts SQL programs through its online interface. The authors evaluate their Python system on the validation split, which contains 1,034 questions.

The range of benchmarks gives the paper several ways to assess its design. HiTab and AIT-QA expose difficulties with complex headers. Spider exposes the need to combine information held in separate tables. WikiTableQuestions tests whether the shared approach is also competitive on a well-established single-table task where ordinary relational queries are already a strong option. Because their sources and questions differ, the benchmarks compare complete task settings. The HiTab ablation gives a more direct comparison of representations within the same benchmark.

What counts as a correct program

The authors measure execution accuracy, or EA. A question counts as correct when the selected program runs and returns the expected answer. The metric judges a program through the result it produces on the input table. Two programs can use different syntax or different sequences of steps and still receive credit for returning the same answer.

The paper explains its choice in relation to exact match. Comparing generated code directly with a reference query can reject a correct alternative expression of the same computation. Most of the benchmarks also lack reference Python queries. Execution accuracy provides a common outcome measure for Python, SQL, and other systems whose internal representations differ. It lets the authors compare questions answered successfully across methods that produce different kinds of programs.

The choice leaves the program’s behavior on the supplied table as the basis for credit. A plausible program that returns the wrong value receives no credit under this metric. A program that reaches the expected value through a shortcut can receive credit on that example. The experiments report answers obtained after the generator’s probability ranking, so the scores describe the end-to-end procedure with its selection rule. They give no separate count of how many questions had a correct program among the other sampled candidates.

The main Codex comparisons

The main results compare the full Python framework with a plain few-shot Codex baseline and a previously reported system for each benchmark. The authors describe the plain Codex baseline as omitting the multi-index representation and assistant functions. The comparison with that baseline measures the effect of enabling the framework components together. The comparison with prior systems addresses how competitive the complete approach is under the reported evaluation conditions.

Execution accuracy on the HiTab test split

The full Python framework leads both plain Codex prompting and MAPO on hierarchical tables.

Execution accuracy on the HiTab test splitMAPO: 40.7MAPO40.7Plain Codex: 59.6Plain Codex59.6Full Python framework (this paper): 69.3Full Python framework (this paper)69.3
The numbers
System or settingexecution accuracy %
MAPO40.7
Plain Codex59.6
Full Python framework (this paper)69.3

On HiTab, MAPO is the earlier training-based system from the benchmark’s comparisons. The plain Codex baseline already reaches 59.6 execution accuracy on the test split, ahead of MAPO at 40.7. The full framework reaches 69.3. The ranking supports two conclusions at the level of complete systems. Few-shot Python generation is already a strong baseline for this setting, and the combination of structured indexes and helpers adds a further gain. The component comparisons below examine how that gain arises.

The AIT-QA comparison has a different shape. RCI, the earlier baseline, scores 51.8 execution accuracy on the full evaluation set. Plain Codex scores 77.8, and the full Python framework scores 78.0. The full system leads the three-way comparison, with the plain Codex baseline already close to it. The distinction matters when attributing the result. The performance of the complete approach is well ahead of the earlier baseline, while the incremental improvement over plain Codex on this dataset is modest in the main table.

On the Spider validation split, the earlier DIN-SQL baseline scores 61.5 execution accuracy. Plain Codex scores 61.2 and the full Python system scores 63.8. Here the complete framework places ahead of both. The paper also reports the improvement over the published comparison as 2.3%. These figures concern validation, the split the authors can use to execute Python programs. The hidden SQL-only evaluation remains outside this comparison.

WikiTableQuestions reverses the ordering against the strongest prior baseline. Plain Codex scores 41.7 execution accuracy and the full Python system scores 42.4. BINDER reaches 54.8 in the comparison. The paper uses 5-shot prompting for BINDER to align the number of examples with the authors’ setup, and it notes that this configuration scores below the 12-shot result from the BINDER work. The authors suggest that BINDER’s use of an external-knowledge API fits the benchmark’s questions better. That is their interpretation of the result, based on the kinds of questions WikiTableQuestions contains.

The paper’s introduction separately describes gains over earlier few-shot baselines and reports 24.5% for HiTab. The main HiTab table names the training-based MAPO comparison and reports its own scores. The two descriptions use different baseline framings. The table gives the identifiable comparison for the HiTab test split, so the MAPO and Codex scores are the clearest basis for reading that experiment.

Changing the code generator

The authors repeat comparisons with StarCoder to see whether the framework can be used beyond Codex. Their dedicated StarCoder table reports a base setting and a setting with APIs for HiTab, AIT-QA, and WikiTableQuestions. The API setting is higher in each row. Absolute accuracy with StarCoder remains below the corresponding Codex accuracies. The experiment supports compatibility across generators while showing that the generator affects the resulting system’s performance.

On the HiTab test split, the StarCoder comparison gives 29.0 execution accuracy in the base setting and 30.1 with the APIs. These scores show a gain under the helper setting alongside a large gap from the Codex system on the same benchmark. The indices and functions provide an interface that both generators can use. The results indicate that using that interface successfully still depends on writing a suitable query.

StarCoder execution accuracy on the full AIT-QA test set

The API setting answers more airline-table questions correctly than the StarCoder base setting.

StarCoder execution accuracy on the full AIT-QA test setStarCoder base: 4.0StarCoder base4.0StarCoder with APIs (this paper): 26.1StarCoder with APIs (this paper)26.1
The numbers
System or settingexecution accuracy %
StarCoder base4.0
StarCoder with APIs (this paper)26.1

AIT-QA is the largest change in the dedicated StarCoder comparison. The base setting scores 4.0 execution accuracy, and the setting with APIs scores 26.1 on the full set. The authors suggest that a substantial share of the questions may be easier to solve with the available helpers. The benchmark-level result is consistent with that explanation. It leaves open which individual questions benefit and which kinds of program errors the helpers prevented. The main Codex table also shows that the incremental effect of the framework can look quite different with another generator on the same data.

The dedicated StarCoder table reports 22.4 and 23.2 execution accuracy for the base and API settings on WikiTableQuestions. Those same numbers appear under the StarCoder SQL settings in the separate query-language comparison, which gives 15.6 for each of its StarCoder Python settings. The paper’s tables present these under different configurations without explaining the overlap in the figures. The query-language comparison gives the most explicit labels for interpreting the Python and SQL variants.

Changing the query language

The WikiTableQuestions query-language comparison tests Python and SQL, each with and without access to the APIs, for both generators. SQL has the higher execution accuracy in each matched comparison. With Codex, the Python scores are 41.7 without the APIs and 42.4 with them. The SQL scores are 45.4 without the APIs and 46.7 with them. This places the Codex SQL and API configuration at the top of the reported query-language comparison.

Codex execution accuracy by query language on WikiTableQuestions

SQL leads in both matched comparisons, with the SQL and API setting giving the highest accuracy.

Codex execution accuracy by query language on WikiTableQuestionsPython: 41.7Python41.7Python with APIs: 42.4Python with APIs42.4SQL: 45.4SQL45.4SQL with APIs (this paper): 46.7SQL with APIs (this paper)46.7
The numbers
System or settingexecution accuracy %
Python41.7
Python with APIs42.4
SQL45.4
SQL with APIs (this paper)46.7

For StarCoder in the same comparison, Python scores 15.6 execution accuracy whether the APIs are enabled or absent. SQL scores 22.4 without the APIs and 23.2 with them. The table therefore records both a query-language effect and a setting where enabling helpers leaves the reported accuracy unchanged. The paper describes helper gains in nearly all of these settings, with the unchanged StarCoder Python result marking the exception.

The authors suspect that the relational shape of WikiTableQuestions favors short SQL queries and that these are easier for the generators to produce than longer Python functions. They point specifically to the Python code needed to account for input types. The results show that the SQL configuration worked better on this benchmark. The proposed explanation concerns query length, conversion, and the generators’ exposure to SQL. Those factors are discussed together and are not measured separately in the experiment.

The broader result is about the ability to swap a part of the method. The same data-frame environment can accept the results of SQL execution and continue using Python helpers. The paper tests that combination on WikiTableQuestions. Its numerical evidence for the SQL experiment is specific to that single-table relational benchmark.

What the ablations show

What changes when a hierarchy is flattened

The main ablation keeps the focus on HiTab and on execution accuracy with Codex. The authors compare the tree-path representation with a flattened representation used in earlier work. For the flattened version, they join the strings on each top-header path into a single column name. The left headings are then treated as ordinary cells. The effect is to present the table as a flat collection of columns. The paths in the top header can still leave a textual trace in the joined names, while the row hierarchy is available in a different form.

This is a substantive alternative to multi-indexing. A flattened column name can make the full column label easy for the generator to write as a string. A multi-index can expose more of the organization on each axis, but it also requires code that uses the appropriate tuple or index levels. The comparison tests which input and query conventions produced the better final answers under a given helper setting.

On the HiTab test split with neither helper type enabled, flattening gives 59.6 execution accuracy, while multi-indexing gives 56.0. The authors report the decrease for the multi-index representation as 3.6%. Preserving a hierarchy by itself therefore yields a lower result in this comparison. The experiment is especially informative because the full system’s HiTab advantage could otherwise be read as evidence that a richer index automatically improves generation.

The ordering changes with both kinds of helpers enabled. The flattened setting gives 59.1 execution accuracy, while the multi-index setting gives 69.4. The paper reports the improvement with multi-indexing here as 10.3%. The main results table lists the full HiTab system at 69.3, while the corresponding full setting in the ablation table is 69.4. The paper gives both values without an explanation for their discrepancy. The comparisons within each table use the value reported for that experiment.

The interaction between representation and helper availability is the strongest result of the ablation. Multi-indexing exposes more of the table’s organization, and its measured benefit depends on what the rest of the system can do with that organization. Flattening gives the better result when the program uses only the ordinary operations in the tested setting. With the demonstrated helpers in place, the indexed version gives the better result. The authors interpret the joint configuration as helping programs make use of the structural information preserved in the indexes.

What changes when a helper is added

The same ablation tests the QA API by itself, then the QA API and operation APIs together. On the multi-indexed version of HiTab, execution accuracy is 56.0 with neither helper type, 58.7 with the QA API alone, and 69.4 with both. The authors report the gain for adding the QA API as 2.7%, and the further gain for adding operation helpers alongside it as 10.7%. These are changes within the multi-indexed test conditions.

The operation comparison has a specific interpretation. The reported table adds operation helpers to a setup in which the QA helper is already available. The measured gain is therefore for adding comparison functions in that context. A setting with operation helpers alone is absent from the table. The experiment identifies the better tested combination and the contribution of each successive addition, with the standalone effect of the comparison helpers left open.

The flattened variant behaves differently. Without helpers, it scores 59.6 execution accuracy. With the QA API alone, it scores 57.4. With both types of helper, it scores 59.1. Adding comparison operations improves on the QA-only setting, while the flattened no-helper setting still has the higher reported score among the flattened configurations. The paper’s broad claim that both kinds of helper are useful is best read alongside these cells. The APIs help in the joint indexed setup, and their effects vary with how the program can address the data.

This variation gives a concrete reading of the authors’ claim about modularity. A helper can be attached to the program environment independently of the core query language, but providing it does not guarantee that the generator will choose it well. The generator can change its program in response to the new instructions and demonstrations. The reported metric measures the results of those generated programs, which can change in several ways after a helper becomes available. The ablation tracks the outcome of making the option available in context. It does not break the change down into call frequency, argument quality, or the accuracy of returned factual judgments.

The Manitoba example explains one route by which the QA helper can help. A program can recognize a geographic relationship absent from the table and include an otherwise missed row. The comparison helpers illustrate a different route. They support a deterministic selection and return the corresponding label. These cases explain why the two API types can be valuable without assuming that they contribute equally to every question. The HiTab ablation reports their aggregate behavior over the test split.

What the prompt-size comparison adds

The appendix varies the number of worked examples. It compares 5 shots with 12 shots on HiTab and WikiTableQuestions. On the HiTab test split, execution accuracy goes from 69.3 in the 5-shot setting to 70.0 in the 12-shot setting. On WikiTableQuestions, the corresponding scores are 42.4 and 42.8, with the particular split unlabeled in the appendix table. The larger prompt has the higher reported result on both datasets.

This comparison helps put the main prompting setup in context. The authors’ smaller prompt already gives scores close to those of the larger tested prompt on these two benchmarks. The appendix changes the amount of demonstration material. It leaves open which demonstrations explain the gains, whether the result depends on their ordering, and how a larger prompt would affect AIT-QA or Spider. The test measures the effect of these particular prompt settings under the reported evaluation.

The StarCoder and SQL experiments provide related checks at the level of the complete method. Changing the generator tests whether another system can work with the same broad interface. Changing the query language on WikiTableQuestions tests whether relational operations can benefit from a different form while the framework continues to use Pandas and the helpers. Together with the HiTab ablation, these results show that the table representation, available operations, and way of expressing the query can affect accuracy in combination.

Limitations

Limits the authors identify

The authors state that separate components can reduce performance under some conditions, even though the components can improve the complete system in combination. The HiTab comparisons provide direct examples. Multi-indexing produces a lower score than flattening when the helpers are absent, and the QA-only setting produces a lower score than the no-helper setting on flattened tables. The authors accordingly describe their framework as a step towards broad TableQA coverage.

They also identify manual API design as a limit. The comparison helpers were chosen for a kind of question the authors found difficult for Codex. The QA helper addresses selected cases where factual information is missing from a table. A dataset with different operations or a setting grounded in additional sources could require different functions. The framework can accept new Python functions, while the selection and implementation of useful functions remain work for the designer in the reported system.

The authors propose automating that work in future research. They describe a possible interactive framework that would use feedback about questions it handles poorly to construct new APIs for those questions. That proposal would extend the existing idea of teaching a supplied interface through examples. The reported implementation uses hand-designed functions and demonstrations, and its experiments evaluate the behavior of those choices.

The paper also recognizes the compensating strengths of other methods. Its full Python approach trails BINDER on WikiTableQuestions, where the authors suspect that the earlier system’s API is better suited to the demand for external knowledge. The SQL experiment shows that another query language can give better results within the framework there. These findings bound the claim for a single Python query form even where the data representation and execution setup can be shared.

Limits visible in the experimental setup

Table type, subject, and question distribution vary together across the benchmarks. HiTab draws from statistical reports and Wikipedia, while AIT-QA comes from airline documents, and Spider uses databases from many domains. The main configurations also use different numbers of demonstrations on some datasets. Cross-benchmark differences therefore combine several factors. The direct evidence about the effect of multi-indexing comes from the controlled HiTab comparison, and the SQL evidence comes from its own experiment on WikiTableQuestions.

The method description starts from tables whose top and left heading relationships can be turned into trees. The experiments assess question answering with the adopted representations of the benchmark tables. They provide no separate accuracy measure for identifying headers, reconstructing merged cells, or resolving ambiguous headings from arbitrary documents. Those input problems would affect which paths are available to the generated code. A mistaken header path can undermine an otherwise sensible query.

Attention to the evaluation splits also limits comparisons. The Spider result is for validation because the hidden evaluation accepts SQL submissions. AIT-QA is treated as one test set covering the complete dataset. The WikiTableQuestions score tables leave the split of their single reported figures unspecified even though the authors list validation and test sets. These conditions define which comparisons the supplied figures support. They matter especially when comparing the reported values with results obtained under other evaluation interfaces or prompt settings.

The aggregate scores give a practical measure of answer quality but a limited view of internal errors. A wrong answer can come from reading the wrong header path, mishandling a cell type, selecting unsuitable rows, combining tables incorrectly, or asking a factual question whose answer is wrong. The execution accuracy comparisons count the resulting answers. A systematic breakdown of these error types would be needed to identify how often each mechanism succeeds or fails.

The factual helper has a further dependence on the quality of the generated predicate and the responses to it. In the Manitoba example, the system can ask the right question about the right labels and receive affirmative judgments for both rows it needs. The experiments include no separate evaluation of the factual responses as a collection, so their reliability across subjects remains open. The method describes obtaining answers from a language system. It gives no process for attaching independent evidence to the individual judgments. The table computation can make clear which values were used while the factual judgments still require verification of their own.

Execution accuracy has a corresponding limit when used as evidence of reasoning. A correct output on the supplied table shows that the generated program returned the target answer on that instance. Establishing that the program implements the intended interpretation across possible table contents would require assessing its behavior beyond the observed output. That distinction is particularly relevant for comparisons and aggregations, where different computations can happen to yield the same result.

The demonstration-count experiment is similarly specific. The authors compare particular prompts with 5 and 12 shots. The results leave the sensitivity to the identity and order of examples open. The implementation also samples five candidates and chooses by log probability. The paper reports the resulting execution accuracy, leaving the quality of the discarded candidates and the effect of alternative selection procedures unmeasured. The available results describe the tested combination of prompting, sampling, and ranking.

The external calls can also change the amount of work a question requires. The illustrated factual API asks a question for each relevant entry, so broader selections can entail more calls during execution. The paper provides outcome comparisons and describes the call structure, with no measurement of how this changes runtime or cost. Its evidence is clearest about whether an answer is obtained under the experimental configuration. Efficiency on larger tables or on workloads with frequent factual calls remains to be established.

What came after

The later citing work includes a study centered on how a system moves through a table and surveys with two different scopes. Those scopes give the paper several points of contact with later research. Its programs have to find the relevant values in a table, its inference procedure produces and selects executable code, and its experiments compare approaches across different benchmarks. The citations establish that the work appears in these later discussions. The titles establish the focus of each later work more clearly than they establish the precise role of the citation.

RoT studies table reasoning through iterative row-wise traversal. This puts the emphasis on a different part of answering questions over tables. Cao and colleagues give generated programs indexed addresses and operations with which to select and combine table entries. RoT’s stated focus is how reasoning moves through rows over successive steps. The relationship visible from that focus is the shared problem of locating and organizing table evidence for a question. The citation by itself leaves the reuse of Cao and colleagues’ indexes, Python programs, or helpers unspecified. RoT

The survey of inference scaling, learning to reason, and agentic systems places the citation within a broader discussion of reasoning. Cao and colleagues offer a table-specific example in which work at inference time includes producing several candidate programs, choosing one, and executing it. A selected program can also make factual calls during that execution. Those features explain the connection between the paper’s design and the themes named in the survey. The chapter, category, and claim associated with the citation are unspecified. A Survey of Frontiers in LLM Reasoning

The later survey of table question answering addresses tasks, methods, and evaluation. Cao and colleagues’ study connects those subjects in one experiment. It treats a variety of table layouts as instances of the same task, uses executable queries and helpers as its method, and evaluates the answers returned by those queries. Its choice of evaluation splits and its comparisons between Python and SQL are pertinent to that survey’s stated scope. The citation establishes a place for the paper in the later survey of the field, while the survey’s title leaves its classification of the framework unspecified. Table Question Answering in the Era of Large Language Models

These later citations trace attention to the problem from a focused table-reasoning study through a field survey and a broader reasoning survey. The concrete contribution they cite is an experimentally evaluated combination of indexed table representations, executable queries, and callable functions. In Cao and colleagues’ results, the value of that combination is clearest where answering a question requires a program to exploit relationships that the table’s layout already expresses.

Cite

Cite as Yihan Cao, Shuyi Chen, Ryan Liu, Zhiruo Wang and Daniel Fried. 2023. API-Assisted Code Generation for Question Answering on Varied Table Structures. Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing.

The paper itself, not this page. BibTeX from the library's record of the work. DOI 10.18653/v1/2023.emnlp-main.897

@inproceedings{cao2023api,
  title = {{API-Assisted Code Generation for Question Answering on Varied Table Structures}},
  author = {Yihan Cao, Shuyi Chen, Ryan Liu, Zhiruo Wang and Daniel Fried},
  booktitle = {Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  doi = {10.18653/v1/2023.emnlp-main.897},
  url = {https://doi.org/10.18653/v1/2023.emnlp-main.897}
}

↑ back to top

This page in Markdown https://md.research.elamur.ai/free/en/papers/cao-2023-api-assisted-code-generation-question/