Improve model card: Add metadata, paper link, and sample usage
#1
by
nielsr
HF Staff
- opened
README.md
CHANGED
|
@@ -1 +1,71 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
pipeline_tag: text-ranking
|
| 4 |
+
library_name: transformers
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
# GRAST-SQL: Scaling Text-to-SQL via LLM-efficient Schema Filtering with Functional Dependency Graph Rerankers
|
| 8 |
+
|
| 9 |
+
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. This approach delivers near-perfect recall with substantially higher precision and maintains sub-second median latency while scaling to schemas with 23,000+ columns.
|
| 10 |
+
|
| 11 |
+
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).
|
| 12 |
+
|
| 13 |
+
For more details, code, and further usage instructions, please visit the [official GitHub repository](https://github.com/thanhdath/grast-sql).
|
| 14 |
+
|
| 15 |
+
## Sample Usage
|
| 16 |
+
|
| 17 |
+
To apply GRAST-SQL to your own database and filter the most relevant columns for a given question, follow these two simple steps. Ensure your environment is set up as described in the [GitHub repository](https://github.com/thanhdath/grast-sql).
|
| 18 |
+
|
| 19 |
+
### Step 1: Initialize (ONE-TIME per database) - Functional Dependency Graph Construction & Metadata Completion
|
| 20 |
+
|
| 21 |
+
Extract schema information, generate table/column meanings, predict missing keys, and build the functional dependency graph. Make sure your OpenAI API key is set in `.env` if you are using an OpenAI model for meaning generation.
|
| 22 |
+
|
| 23 |
+
```bash
|
| 24 |
+
python init_schema.py \
|
| 25 |
+
--db-path /path/to/your/database.sqlite \
|
| 26 |
+
--output your_database.pkl \
|
| 27 |
+
--model gpt-4.1-mini
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
**Arguments:**
|
| 31 |
+
- `--db-path`: Path to your SQLite database file (required)
|
| 32 |
+
- `--output`: Output path for the graph pickle file (default: `schema_graph.pkl`)
|
| 33 |
+
- `--model`: OpenAI model to use for meaning generation and key prediction (default: `gpt-4.1-mini`)
|
| 34 |
+
|
| 35 |
+
### Step 2: Filter Top-K Columns
|
| 36 |
+
|
| 37 |
+
Use the GRAST-SQL model to filter the most relevant columns for a given question:
|
| 38 |
+
|
| 39 |
+
```bash
|
| 40 |
+
python filter_columns.py \
|
| 41 |
+
--graph your_database.pkl \
|
| 42 |
+
--question "Show name, country, age for all singers ordered by age from the oldest to the youngest." \
|
| 43 |
+
--top-k 5
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
**Arguments:**
|
| 47 |
+
- `--graph`: Path to the graph pickle file from Step 1 (required)
|
| 48 |
+
- `--question`: Natural language question about the database (required)
|
| 49 |
+
- `--top-k`: Number of top columns to retrieve (default: 10)
|
| 50 |
+
- `--checkpoint`: Path to GNN checkpoint (default: `griffith-bigdata/GRAST-SQL-0.6B-BIRD-Reranker/layer-3-hidden-2048.pt`)
|
| 51 |
+
- `--encoder-path`: Path to encoder model (default: `griffith-bigdata/GRAST-SQL-0.6B-BIRD-Reranker`)
|
| 52 |
+
- `--max-length`: Maximum sequence length (default: 4096)
|
| 53 |
+
- `--batch-size`: Batch size for embedding generation (default: 32)
|
| 54 |
+
- `--hidden-dim`: Hidden dimension for GNN (default: 2048)
|
| 55 |
+
- `--num-layers`: Number of GNN layers (default: 3)
|
| 56 |
+
|
| 57 |
+
## Citation
|
| 58 |
+
|
| 59 |
+
If you use GRAST-SQL in your research, please cite the following paper:
|
| 60 |
+
|
| 61 |
+
```bibtex
|
| 62 |
+
@misc{hoang2025scalingtext2sqlllmefficientschema,
|
| 63 |
+
title={Scaling Text2SQL via LLM-efficient Schema Filtering with Functional Dependency Graph Rerankers},
|
| 64 |
+
author={Thanh Dat Hoang and Thanh Tam Nguyen and Thanh Trung Huynh and Hongzhi Yin and Quoc Viet Hung Nguyen},
|
| 65 |
+
year={2025},
|
| 66 |
+
eprint={2512.16083},
|
| 67 |
+
archivePrefix={arXiv},
|
| 68 |
+
primaryClass={cs.DB},
|
| 69 |
+
url={https://arxiv.org/abs/2512.16083},
|
| 70 |
+
}
|
| 71 |
+
```
|