Uni-Parser: Unified Semantic Parser for Question Answering on Knowledge Base and Database (2022)

Abstract: Parsing natural language questions into executable logical forms is a useful and interpretable way to perform question answering on structured data such as knowledge bases (KB) or databases (DB). However, existing approaches on semantic parsing cannot adapt to both modalities, as they suffer from the exponential growth of the logical form candidates and can hardly generalize to unseen data.In this work, we propose Uni-Parser, a unified semantic parser for question answering (QA) on both KB and DB. We define the primitive (relation and entity in KB, and table name, column name and cell value in DB) as the essential element in our framework. The number of primitives grows only at a linear rate to the number of retrieved relations in KB and DB, preventing us from exponential logic form candidates. We leverage the generator to predict final logical forms by altering and composing top-ranked primitives with different operations (e.g. select, where, count). With sufficiently pruned search space by a contrastive primitive ranker, the generator is empowered to capture the composition of primitives enhancing its generalization ability. We achieve competitive results on multiple KB and DB QA benchmarks with more efficiency, especially in the compositional and zero-shot settings.

## introduction with the recent advances in deep neural networks, question answering (qa) systems enable users to interact with massive data using queries in natural language. however, it remains challenging to assess structured data, such as knowledge bases and databases. semantic parsing is a core step of question answering for structured data. the goal is to convert a natural language question to an executable logical form @xcite , e.g., sql for databases and s-expression for knowledge bases. to improve the accuracy and faithfulness in execution of semantic parsing, recent kbqa studies propose to generate logical form candidates by enumerating and selecting the best logical form by ranking @xcite @xcite . however, the number of logical form candidates may grow exponentially with the increase of reasoning depth for complex questions. thus this approach can suffer from poor runtime performance due to the timeconsuming logical form enumeration @xcite and inefficient candidate ranking @xcite . for example, given an entity in a kb, we collect its logical form candidates by enumerating paths up to two hops. if the first hop with respect to the given entity contains n relations and the second hop contains m relations, the enumeration would result in n × m logical forms. as kbs typically contain massive structured knowledge, an entity can have hundreds of linked relations @xcite . moreover, for complex questions, which require combining logic or aggregation operations, such as count, argmin, or argmax, into the logical form, the situation could be even worse. therefore, traditional enumeration methods may fail in cases requiring complicated reasoning (e.g., involving large amounts of entities and long reasoning chains). the situation becomes more severe and prohibitive if one wants to apply the enumeration method to other structured data with dense connections between entities such as in databases. designing a unified semantic parsing method for various modalities of structured data have significant theoretical and practical value, yet it is still an understudied topic. to avoid the problem of exponential growth in the logical form enumeration, we consider logical forms composed of two types of elements -primitives and operations. primitives are defined by the schema of the structured data source and operations are a set of grammars associated with primitives. for example, in the context of knowledge bases, primitives are defined as relations and entities in the knowledge graph. whereas in databases, primitives are presented as tables, columns, and cells. through this formulation, the number of candidates can be greatly reduced, going down from n × m to n + m . in this study, we present uni-parser, a unified semantic parser for question answering on both knowledge bases (kbs) and databases (dbs). our model follows the framework of enumeration-ranker-generator proposed in rng-kbqa @xcite . we first enumerate possible questionrelevant primitives of a given kb or db. then a cross-encoder ranker is utilized to select the best candidates with contrastive learning @xcite , and it is further enhanced by a special hard negative sampling strategy. after getting the top-k ranked primitives for each hop, we filter out the high-order primitives that cannot be reached from the kb or do not exist in the db through selected low-order primitives. next, we introduce a generator that consumes both the question and filtered top-k primitives with predicted operations to compose the final logical form. starting from primitives rather than logical forms, our generator needs to understand the semantic meaning of each primitive to compose them into the logical form. our contributions can be summarized as follows: • we propose a unified semantic parser working for both kb and db question answering. ## problem formulation given a structured data source d and a question x in natural language, a semantic parser model is tasked to generate the corresponding logical form y . specifically, we illustrate the details de- ## methodology our model first obtains the relevant primitives from the given structured data and question, and sets them into different categories (sec 3.1). then a ranker filters out the irrelevant primitives (sec 3.2) and provides the top-ranked primitives to the gen- uni-parser (ranker) (jo ar question : how many students attend course statistics? question : what currency did new york central park use in its construction? <tb_cl>: students.studentid students.studentname … courses.@xmath0: courses.@xmath1: architecture.construction_cost central_park architecture.landscape_project central_park … travel.near_travel_destination @xmath2: travel.get_destination money_unit.currency … visual_art.art_form central park knowledge base construction_cost currency landscape_project architect s w uni-parser (generator) [cls] what currency … [sep] 
 architecture.construction_cost central park, travel.near_travel_destination… 
 money_unit.currency, travel.get_destination, … [cls] how many… [sep] 
 course.coursename, students.studentname … 
 course.@xmath3.@xmath4.studentid … erator to produce the final logical form (sec 3.3). we'll first explain how to extract the primitive candidates from kb or db based on the question. ## conclusion for unified semantic parsing on both kb and db structured data, we propose uni-parser, which has three modules: primitive enumeration, ranker, and compositional generator. our enumeration at the primitive level rather than the logical-form level produces a smaller number of potential candidates, leading to high efficiency in the enumeration and ranker steps. moreover, training a generator to produce the logical form from the primitives leads to a more generalized and robust compositional generator. experimental results on both kb and db qa demonstrate the advantages of uni-parser, especially in the compositional and zero-shot settings.