SADGA: Structure-Aware Dual Graph Aggregation Network for Text-to-SQL

Ruichu Cai, Jinjie Yuan, Boyan Xu, Zhifeng Hao

TL;DR

SADGA (Structure-Aware Dual Graph Aggregation) is a novel framework for the Text-to-SQL task that treats both natural language questions and database schemas as graphs. By utilizing a dual-graph aggregation mechanism that considers both global and local structural information, SADGA significantly improves the model's ability to link questions to unseen database schemas, achieving 3rd place on the challenging Spider benchmark at the time of its release.

The Challenge of Cross-Domain Text-to-SQL

The Text-to-SQL task involves automatically translating a natural language question (e.g., "Which students are older than 25?") into a functional SQL query. The "holy grail" of this field is cross-domain generalization: the ability of a model to accurately generate queries for a database schema it has never encountered during training.

The authors identify two major hurdles in current approaches:

  1. The Structure Gap: Most models treat the input question as a simple 1D sequence of words, while treating the database schema as a complex relational graph. This structural mismatch makes it difficult for the model to align the two effectively.
  2. The Linking Problem: Mapping a word like "age" to the correct column is ambiguous when multiple tables (e.g., Student and Professor) have an "age" column. Existing methods often rely on simple string matching or global attention, which can lead to incorrect or "noisy" links.
Comparison of existing sequence-to-graph methods versus SADGA's graph-to-graph approach.

The SADGA Approach

To overcome these limitations, SADGA introduces a unified approach by representing both the question and the schema as graphs.

The SADGA architecture featuring Dual Graph Encoding and Structure-Aware Aggregation.

The processing pipeline follows three main stages:

  1. Dual-Graph Construction:
    • Question-Graph: Words are treated as nodes, connected by edges that represent word distance and grammatical dependencies (derived from parsing).
  2. Schema-Graph: Tables and columns act as nodes, connected by database relations such as primary-foreign key links.
  3. Dual-Graph Encoding: The model employs a Gated Graph Neural Network (GGNN) to learn initial representations for every node within its respective graph, capturing internal structural context.
  4. Structure-Aware Aggregation: This is the core innovation used to link the two graphs. It consists of three steps:
  5. Global Graph Linking: Each node in one graph attends to all nodes in the other graph to establish broad relevance.
  6. Local Graph Linking: Each node looks specifically at the neighbors of relevant nodes in the other graph. This provides crucial context (e.g., determining that "age" belongs to the Student table because the question node for "age" is structurally linked to "students").
  7. Dual-Graph Aggregation Mechanism: A gating mechanism dynamically decides how much information to integrate from the global versus local linking to create a final, unified representation.

Finally, a standard tree-based decoder transforms these enriched representations into a valid SQL query.

Key Insights

  • Question-as-a-Graph: By converting the natural language question into a graph based on its dependency parse, the authors effectively "pre-structure" the language to match the database's format. This eliminates the structural mismatch that plagues sequence-to-graph models.
  • Local Structure is the Tie-Breaker: Global attention is often too blunt for disambiguation. If two tables both have an "age" column, global attention struggles to pick the right one. By leveraging Local Graph Linking, the model observes that the question's "age" node is surrounded by nodes related to "Student," allowing it to correctly select Student.age over Professor.age.
  • Latent Association Discovery: The model can identify "latent" links—tables or columns that aren't explicitly named in the question but are necessary for the query (like intermediate join tables)—by observing how they relate to other identified nodes in the graph structure.

Results on the Spider Benchmark

The model was evaluated on Spider, the gold-standard benchmark for cross-domain Text-to-SQL containing over 10,000 questions and 200+ databases across 138 domains.

  • Leaderboard Performance: SADGA achieved 3rd place on the Spider leaderboard at the time of writing.
  • Accuracy Gains: On the Spider test set, SADGA combined with GAP (a pre-trained model) reached 70.1% accuracy, outperforming strong baselines like RATSQL.
  • Handling Complexity: The model demonstrated its greatest strength on Extra-Hard queries, outperforming the baseline by 6.5% on the development set. This proves that the structure-aware approach is particularly effective when SQL logic is deeply nested or requires multiple complex joins.

Limitations and Future Work

The authors note that while SADGA is a powerful "base model," it isn't a highly specialized solution tailored to every specific nuance of the Spider dataset, suggesting room for further domain-specific optimizations.

Looking ahead, they plan to extend the SADGA architecture to other "heterogeneous graph tasks"—problems where two different types of structured data need to be aligned or translated, such as code documentation generation or cross-lingual knowledge graph alignment.

Summary updated

BibTeX
@inproceedings{cai2021sadga,
  author = {Ruichu Cai and Jinjie Yuan and Boyan Xu and Zhifeng Hao},
  title = {{SADGA: Structure-Aware Dual Graph Aggregation Network for Text-to-SQL}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
  url = {https://openreview.net/forum?id=PiINWUTKz5},
}
Figure