This project implements a multi-stage pipeline for predicting schema links (tables and columns) from natural language questions, targeting the SNAILS dataset. The system uses a modular approach with specialized LoRA adapters for question decomposition, table prediction, and column prediction.
For an overview of the problem statement and motivation, check out the Technical Report under report/.
The pipeline consists of four main stages:
- Question Decomposition: Complex questions are broken down into simpler sub-questions.
- Table Prediction: Relevant tables are identified for each sub-question.
- Column Prediction: Specific columns are identified for the predicted tables.
- Schema Refinement (4th Stage): A final pass aggregates predictions and performs a refinement step using the original question and the filtered schema.
For a deep dive into the technical details, check out the Technical Report under report/.
.
├── config/ # Configuration files
│ ├── data/ # Dataset generation configs
│ ├── models/ # Model and LoRA configs
│ ├── training/ # Training hyperparameters
│ └── inference/ # Inference execution configs
├── data/
│ ├── adapter/ # Saved LoRA adapters
│ ├── datasets/ # Generated training/validation sets
│ ├── evaluation/ # Inference outputs and metrics
│ └── schemas/ # Spider-format database schemas
├── src/
│ ├── data/ # Data preparation scripts
│ ├── training/ # Training implementation
│ ├── inference/ # Multi-stage inference logic
│ ├── evaluation/ # Evaluation scripts (P/R/F1)
│ └── utils/ # Shared utilities
├── main.py # Entry point for inference and evaluation
├── generate_full_summary.py # Utility to aggregate results across runs
└── requirements.txt # Project dependencies
Create a virtual environment and install dependencies:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtOnce the virtual environment is set up, directly run main.py (it has all the default argument values specified). You must provide the input and output file names. You have an option to run it with --run_eval and --debug mode. If you run it with --run_eval, the --gold file must be provided too.
Example command
python3 main.py --input data/datasets/val/full/validation_input.json --output data/evaluation/test_run/full/validation_input/output.json [--run_eval] --gold data/datasets/val/full/validation_gold_schema_links.json [--debug]DB schemas are located at data/schemas. Please ensure that you keep the schemas structure as given in this directory because the inference pipeline tries to find them under data/schemas and also computes an FK graph using the schema. If you require schema to be at the top level for evaluation, you can copy the schemas directory at the top level too, but keep the copy at data/schemas too.
The inference config used (hard-coded as inference-config param in main.py) is config/inference/inference-config-11. It contains the batch sizes for various adapters as they were tested on the UCSD-provided AWS device. They have been tested to not give an OOM error on the validation dataset using that device. If they give an OOM on your device, you can pass --inference_config_id inference-config-10 to the command to use a lower batch size but inference will take longer.
Please add your HF access token to access the model Qwen/Qwen2.5-Coder-1.5B-Instruct in the .env (as HF_TOKEN) and it will be picked up from it directly.
The adapters are set to be automatically downloaded from the Google drive link (also hard-coded as default in main.py).
The inference time will count the time starting from model predictions i.e. not including downloading adapters and it will be printed at the end.
The validation output is at ./output.json. The training dataset for Q decomposition task is located at data/datasets/train/full/data-prep-5-question-decomposition. The prepared datasets for tables and columns adapters are located at data/datasets/train/full/data-prep-3. The entire schema is located at data/schemas/
Prepare specialized datasets for each adapter type using the scripts in src/data/. These scripts use the configurations in config/data/.
# Prepare Table Prediction dataset
python src/data/prepare_tables_only_dataset.py --config_id data-config-4-tables
# Prepare Column Prediction dataset
python src/data/prepare_columns_only_dataset.py --config_id data-config-4-columns
# Prepare Question Decomposition dataset
python src/data/prepare_decomposition_dataset.py --config_id data-config-5-question-decompositionTrain specialized LoRA adapters for each stage.
# Train Table Adapter
python src/training/train.py \
--data_config_id data-config-4-tables \
--model_config_id model-config-2-tables \
--train_config_id train-config-2-tables \
--run_id run_tables_v1
# Train Column Adapter
python src/training/train.py \
--data_config_id data-config-4-columns \
--model_config_id model-config-2-columns \
--train_config_id train-config-2-columns \
--run_id run_columns_v1
# Train Decomposition Adapter
python src/training/train.py \
--data_config_id data-config-5-question-decomposition \
--model_config_id model-config-4-question-decomposition \
--train_config_id train-config-3-question-decomposition \
--run_id run_decomp_v1The main.py script serves as the unified inference engine. It supports several pipeline types:
Directly predict schema links using a single adapter.
python main.py --input data/datasets/val/val_set.json \
--output data/evaluation/single_stage/output.json \
--adapter_id run_combined_v1 \
--inference_config_id inference-config-1python main.py --input data/datasets/val/val_set.json \
--output data/evaluation/two_stage/output.json \
--tables_adapter_id run_tables_v1 \
--columns_adapter_id run_columns_v1 \
--inference_type two-stageThis is the most advanced pipeline, incorporating question decomposition and final refinement.
python main.py --input data/datasets/val/val_set.json \
--output data/evaluation/four_stage/output.json \
--decomp_adapter_id run_decomp_v1 \
--tables_adapter_id run_tables_v1 \
--columns_adapter_id run_columns_v1 \
--inference_type four-stage \
--run_eval \
--gold data/datasets/val/val_gold.jsonEvaluation is integrated into main.py via the --run_eval flag. It computes:
- Table P/R/F1
- Column P/R/F1
- Overall Schema Link Score
To run evaluation on existing predictions:
python src/evaluation/eval.py \
--predictions data/evaluation/run_x/output.json \
--gold data/datasets/val/val_gold.json \
--schemas_dir data/schemas \
--questions_input data/datasets/val/val_set.json- Database IDs: Four
db_idvalues contain spaces and map to underscored filenames (e.g.,"SBODemoUS-Business Partners"→schemas/SBODemoUS-Business_Partners.json). - Spider Format: Schemas use the Spider format. The
column_names_originalfield contains[table_index, column_name]pairs. Index0(synthetic*entry) should be ignored. - Wildcard Treatment: The gold ground-truth treats SQL
*as a syntactic wildcard, not as "all columns". If a table is referenced without specific columns (e.g.,SELECT COUNT(*) FROM T), the output should be{"T": []}.
- Hallucination Filtering: Identifiers predicted by the model that do not exist in the target schema should be dropped to improve precision.
- Foreign Key Injection: The three-stage and four-stage pipelines automatically inject foreign key columns required to join the predicted tables, improving connectivity.
The project includes a naturalness_mapper.py to transform schema identifiers into more natural language equivalents during prompting, which can improve model performance on obscurely named schemas. Use the --use_natural_language_modifiers flag in main.py to enable this.