TypeSQL: Knowledge-based Type-Aware Neural Text-to-SQL Generation
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
typesql
README.md
data_process_test.py
data_process_train_dev.py cleaned code added Jun 27, 2018
get_kg_entities.py
requirements.txt
test.py
train.py

README.md

TypeSQL

Source code accompanying our NAACL 2018 paper:TypeSQL: Knowledge-based Type-Aware Neural Text-to-SQL Generation

Environment Setup

  1. The code uses Python 2.7 and Pytorch 0.2.0 GPU.
  2. Install Python dependency: pip install -r requirements.txt

Download Data and Embeddings

  1. Download the zip data file at the Google Drive, and put it in the root dir.
  2. Download the pretrained Glove and the paraphrase embedding para-nmt-50m/data/paragram_sl999_czeng.txt. Put the unziped glove and para-nmt-50m folders in the root dir.

Train Models

  1. To use knowledge graph types:
  mkdir saved_model_kg
  python train.py --sd saved_model_kg
  1. To use DB content types:
   mkdir saved_model_con
   python train.py --sd saved_model_con --db_content 1

Test Models

  1. Test Model with knowledge graph types:
python test.py --sd saved_model_kg
  1. Test Model with knowledge graph types:
python test.py --sd saved_model_con --db_content 1

Get Data Types

  1. Get a Google Knowledge Graph Search API Key by following the link
  2. Search knowledge graph to get entities:
python get_kg_entities.py [Google freebase API Key] [input json file] [output json file]
  1. Use detected knowledge graph entites and DB content to group questions and create type attributes in data files:
python data_process_test.py --tok [output json file generated at step 2] --table TABLE_FILE --out OUTPUT_FILE [--data_dir DATA_DIRECTORY] [--out_dir OUTPUT_DIRECTORY]

python data_process_train_dev.py --tok [output json file generated at step 2] --table TABLE_FILE --out OUTPUT_FILE [--data_dir DATA_DIRECTORY] [--out_dir OUTPUT_DIRECTORY]

Acknowledgement

The implementation is based on SQLNet. Please cite it too if you use this code.