Improve model card with metadata, paper link, and usage example
#1
by
nielsr
HF Staff
- opened
README.md
CHANGED
|
@@ -1 +1,84 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pipeline_tag: text-ranking
|
| 3 |
+
library_name: transformers
|
| 4 |
+
---
|
| 5 |
+
|
| 6 |
+
# GRAST-SQL: Scaling Text-to-SQL via LLM-efficient Schema Filtering with Functional Dependency Graph Rerankers
|
| 7 |
+
|
| 8 |
+
GRAST-SQL is a lightweight, open-source schema-filtering framework that scales Text-to-SQL to real-world, very wide schemas by compacting prompts without sacrificing accuracy. It ranks columns with a query-aware LLM encoder enriched by values/metadata, reranks them via a graph transformer over a functional-dependency (FD) graph to capture inter-column structure, and then guarantees joinability with a Steiner-tree spanner to produce a small, connected sub-schema. Across Spider, BIRD, and Spider-2.0-lite, GRAST-SQL delivers near-perfect recall with substantially higher precision than CodeS, SchemaExP, Qwen rerankers, and embedding retrievers, maintains sub-second median latency on typical databases, scales to 23K+ columns, and cuts prompt tokens by up to 50% in end-to-end systems—often with slight accuracy gains—all while using compact models.
|
| 9 |
+
|
| 10 |
+
This model was presented in the paper [Scaling Text2SQL via LLM-efficient Schema Filtering with Functional Dependency Graph Rerankers](https://huggingface.co/papers/2512.16083).
|
| 11 |
+
|
| 12 |
+
Code: https://github.com/thanhdath/grast-sql
|
| 13 |
+
|
| 14 |
+
## System flow
|
| 15 |
+

|
| 16 |
+
|
| 17 |
+
### Datasets
|
| 18 |
+
- **Spider**: [Spider Evaluation Dataset](https://huggingface.co/datasets/griffith-bigdata/GRAST-SQL-Spider)
|
| 19 |
+
- **BIRD**: [BIRD Training/Evaluation Dataset](https://huggingface.co/datasets/griffith-bigdata/GRAST-SQL-BIRD)
|
| 20 |
+
- **Spider-2.0-lite**: [Spider 2.0-lite Eval Dataset](https://huggingface.co/datasets/griffith-bigdata/GRAST-SQL-Spider2.0-lite)
|
| 21 |
+
|
| 22 |
+
### Models
|
| 23 |
+
- **GRAST-SQL 0.6B**: [GRAST-SQL 0.6B BIRD](https://huggingface.co/griffith-bigdata/GRAST-SQL-0.6B-BIRD-Reranker)
|
| 24 |
+
- **GRAST-SQL 4B**: [GRAST-SQL 4B BIRD](https://huggingface.co/griffith-bigdata/GRAST-SQL-4B-BIRD-Reranker)
|
| 25 |
+
- **GRAST-SQL 8B**: [GRAST-SQL 8B BIRD](https://huggingface.co/griffith-bigdata/GRAST-SQL-8B-BIRD-Reranker)
|
| 26 |
+
|
| 27 |
+
More models can be found in [Huggingface collection](https://huggingface.co/collections/griffith-bigdata/grast-sql)
|
| 28 |
+
|
| 29 |
+
## Sample Usage
|
| 30 |
+
|
| 31 |
+
To apply GRAST-SQL to your own database, follow these two simple steps:
|
| 32 |
+
|
| 33 |
+
### Step 1: Initialize (ONE-TIME per database) - Functional Dependency Graph Construction & Metadata Completion
|
| 34 |
+
|
| 35 |
+
Extract schema information, generate table/column meanings, predict missing keys, and build the functional dependency graph:
|
| 36 |
+
|
| 37 |
+
```bash
|
| 38 |
+
python init_schema.py \
|
| 39 |
+
--db-path /home/datht/mats/data/spider/database/concert_singer/concert_singer.sqlite \
|
| 40 |
+
--output concert_singer.pkl \
|
| 41 |
+
--model gpt-4.1-mini
|
| 42 |
+
```
|
| 43 |
+
|
| 44 |
+
**Arguments:**
|
| 45 |
+
- `--db-path`: Path to your SQLite database file (required)
|
| 46 |
+
- `--output`: Output path for the graph pickle file (default: `schema_graph.pkl`)
|
| 47 |
+
- `--model`: OpenAI model to use for meaning generation and key prediction (default: `gpt-4.1-mini`)
|
| 48 |
+
|
| 49 |
+
**Note:** Make sure your OpenAI API key is set in `.env`.
|
| 50 |
+
|
| 51 |
+
### Step 2: Filter Top-K Columns
|
| 52 |
+
|
| 53 |
+
Use the GRAST-SQL model to filter the most relevant columns for a given question:
|
| 54 |
+
|
| 55 |
+
```bash
|
| 56 |
+
python filter_columns.py \
|
| 57 |
+
--graph concert_singer.pkl \
|
| 58 |
+
--question "Show name, country, age for all singers ordered by age from the oldest to the youngest." \
|
| 59 |
+
--top-k 5
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
**Arguments:**
|
| 63 |
+
- `--graph`: Path to the graph pickle file from Step 1 (required)
|
| 64 |
+
- `--question`: Natural language question about the database (required)
|
| 65 |
+
- `--top-k`: Number of top columns to retrieve (default: 10)
|
| 66 |
+
- `--checkpoint`: Path to GNN checkpoint (default: `griffith-bigdata/GRAST-SQL-0.6B-BIRD-Reranker/layer-3-hidden-2048.pt`)
|
| 67 |
+
- `--encoder-path`: Path to encoder model (default: `griffith-bigdata/GRAST-SQL-0.6B-BIRD-Reranker`)
|
| 68 |
+
- `--max-length`: Maximum sequence length (default: 4096)
|
| 69 |
+
- `--batch-size`: Batch size for embedding generation (default: 32)
|
| 70 |
+
- `--hidden-dim`: Hidden dimension for GNN (default: 2048)
|
| 71 |
+
- `--num-layers`: Number of GNN layers (default: 3)
|
| 72 |
+
|
| 73 |
+
## Citation
|
| 74 |
+
```bibtex
|
| 75 |
+
@misc{hoang2025scalingtext2sqlllmefficientschema,
|
| 76 |
+
title={Scaling Text2SQL via LLM-efficient Schema Filtering with Functional Dependency Graph Rerankers},
|
| 77 |
+
author={Thanh Dat Hoang and Thanh Tam Nguyen and Thanh Trung Huynh and Hongzhi Yin and Quoc Viet Hung Nguyen},
|
| 78 |
+
year={2025},
|
| 79 |
+
eprint={2512.16083},
|
| 80 |
+
archivePrefix={arXiv},
|
| 81 |
+
primaryClass={cs.DB},
|
| 82 |
+
url={https://arxiv.org/abs/2512.16083},
|
| 83 |
+
}
|
| 84 |
+
```
|