Home

Awesome

WikiSQL

Build Status

A large crowd-sourced dataset for developing natural language interfaces for relational databases. WikiSQL is the dataset released along with our work Seq2SQL: Generating Structured Queries from Natural Language using Reinforcement Learning.

Citation

If you use WikiSQL, please cite the following work:

Victor Zhong, Caiming Xiong, and Richard Socher. 2017. Seq2SQL: Generating Structured Queries from Natural Language using Reinforcement Learning.

@article{zhongSeq2SQL2017,
  author    = {Victor Zhong and
               Caiming Xiong and
               Richard Socher},
  title     = {Seq2SQL: Generating Structured Queries from Natural Language using
               Reinforcement Learning},
  journal   = {CoRR},
  volume    = {abs/1709.00103},
  year      = {2017}
}

Notes

Regarding tokenization and Stanza --- when WikiSQL was written 3-years ago, it relied on Stanza, a CoreNLP python wrapper that has since been deprecated. If you'd still like to use the tokenizer, please use the docker image. We do not anticipate switching to the current Stanza as changes to the tokenizer would render the previous results not reproducible.

Leaderboard

If you submit papers on WikiSQL, please consider sending a pull request to merge your results onto the leaderboard. By submitting, you acknowledge that your results are obtained purely by training on the training split and tuned on the dev split (e.g. you only evaluted on the test set once). Moreover, you acknowledge that your models only use the table schema and question during inference. That is they do not use the table content. Update (May 12, 2019): We now have a separate leaderboard for weakly supervised models that do not use logical forms during training.

Weakly supervised without logical forms

ModelDev execution accuracyTest execution accuracy
TAPEX (Liu 2022)89.289.5
HardEM (Min 2019)84.483.9
LatentAlignment (Wang 2019)79.479.3
MeRL (Agarwal 2019)74.9 +/- 0.174.8 +/- 0.2
MAPO (Liang 2018)72.2 +/- 0.272.1 +/- 0.3
Rule-SQL (Guo 2019)61.1 +/- 0.261.0 +/- 0.3

Supervised via logical forms

ModelDev logical form <br /> accuracyDev <br /> execution <br /> accuracyTest <br /> logical form <br /> accuracyTest <br /> execution <br /> accuracyUses execution
SeaD<br />+Execution-Guided Decoding<br />(Xu 2021) <br /> (Ant Group, Ada & ZhiXiaoBao)87.692.987.593.0Inference
SDSQL<br />+Execution-Guided Decoding<br />(Hui 2020) <br /> (Alibaba Group)87.192.687.092.7Inference
IE-SQL<br />+Execution-Guided Decoding<br />(Ma 2020) <br /> (Ping An Life, AI Team)87.992.687.892.5Inference
HydraNet<br />+Execution-Guided Decoding<br />(Lyu 2020) <br />(Microsoft Dynamics 365 AI) <br/>(code)86.692.486.592.2Inference
BRIDGE^<br />+Execution-Guided Decoding<br />(Lin 2020)<br />(Salesforce Research)86.892.686.391.9Inference
X-SQL<br />+Execution-Guided Decoding<br />(He 2019)86.292.386.091.8Inference
SDSQL<br />(Hui 2020) <br /> (Alibaba Group)86.091.885.691.4
BRIDGE^<br />(Lin 2020)<br />(Salesforce Research)86.291.785.791.1
Text2SQLGen + EG (Mellah 2021) <br/>(Novelis.io Research)91.291.0Inference
SeqGenSQL+EG (Li 2020)90.890.5Inference
SeqGenSQL (Li 2020)90.690.3Inference
SeaD<br />(Xu 2021) <br /> (Ant Group, Ada & ZhiXiaoBao)84.990.284.790.1Inference
(Guo 2019) <br />+Execution-Guided Decoding <br /> with BERT-Base-Uncased^85.491.184.590.1Inference
SQLova<br />+Execution-Guided Decoding<br />(Hwang 2019)84.290.283.689.6Inference
IncSQL<br />+Execution-Guided Decoding<br />(Shi 2018)51.387.251.187.1Inference
HydraNet (Lyu 2020) <br/>(Microsoft Dynamics 365 AI) <br/>(code)83.689.183.889.2
(Guo 2019) <br /> with BERT-Base-Uncased^84.390.383.789.2
IE-SQL (Ma 2020) <br />(Ping An Life, AI Team)84.688.784.688.8
X-SQL<br />(He 2019)83.889.583.388.7
SQLova <br />(Hwang 2019)81.687.280.786.2
Execution-Guided Decoding<br />(Wang 2018)76.084.075.483.8Inference
IncSQL<br />(Shi 2018)49.984.049.983.7
Auxiliary Mapping Task <br />(Chang 2019)76.082.375.081.7
MQAN (unordered)<br />(McCann 2018)76.182.075.481.4
MQAN (ordered)<br />(McCann 2018)73.582.073.281.4
Coarse2Fine<br />(Dong 2018)72.579.071.778.5
TypeSQL<br />(Yu 2018)-74.5-73.5
PT-MAML<br />(Huang 2018)63.168.362.868.0
(Guo 2018)64.171.162.569.0
SQLNet<br />(Xu 2017)-69.8-68.0
Wang 2017^62.067.161.566.8
Seq2SQL<br />(Zhong 2017)49.560.848.359.4Training
Baseline<br />(Zhong 2017)23.337.023.435.9

^ indicates that table content is used directly by the model during training. <br /> * indicates that the order in where conditions is ignored.

Installation

Both the evaluation script as well as the dataset are stored within the repo. Only Python 3 is supported at the moment - I would very much welcome a pull request that ports the code to work with Python 2. The installation steps are as follows:

git clone https://github.com/salesforce/WikiSQL
cd WikiSQL
pip install -r requirements.txt
tar xvjf data.tar.bz2

This will unpack the data files into a directory called data.

Content and format

Inside the data folder you will find the files in jsonl and db format. The former can be read line by line, where each line is a serialized JSON object. The latter is a SQLite3 database.

Question, query and table ID

These files are contained in the *.jsonl files. A line looks like the following:

{
   "phase":1,
   "question":"who is the manufacturer for the order year 1998?",
   "sql":{
      "conds":[
         [
            0,
            0,
            "1998"
         ]
      ],
      "sel":1,
      "agg":0
   },
   "table_id":"1-10007452-3"
}

The fields represent the following:

Tables

These files are contained in the *.tables.jsonl files. A line looks like the following:

{
   "id":"1-1000181-1",
   "header":[
      "State/territory",
      "Text/background colour",
      "Format",
      "Current slogan",
      "Current series",
      "Notes"
   ],
   "types":[
      "text",
      "text",
      "text",
      "text",
      "text",
      "text"
   ],
   "rows":[
      [
         "Australian Capital Territory",
         "blue/white",
         "Yaa\u00b7nna",
         "ACT \u00b7 CELEBRATION OF A CENTURY 2013",
         "YIL\u00b700A",
         "Slogan screenprinted on plate"
      ],
      [
         "New South Wales",
         "black/yellow",
         "aa\u00b7nn\u00b7aa",
         "NEW SOUTH WALES",
         "BX\u00b799\u00b7HI",
         "No slogan on current series"
      ],
      [
         "New South Wales",
         "black/white",
         "aaa\u00b7nna",
         "NSW",
         "CPX\u00b712A",
         "Optional white slimline series"
      ],
      [
         "Northern Territory",
         "ochre/white",
         "Ca\u00b7nn\u00b7aa",
         "NT \u00b7 OUTBACK AUSTRALIA",
         "CB\u00b706\u00b7ZZ",
         "New series began in June 2011"
      ],
      [
         "Queensland",
         "maroon/white",
         "nnn\u00b7aaa",
         "QUEENSLAND \u00b7 SUNSHINE STATE",
         "999\u00b7TLG",
         "Slogan embossed on plate"
      ],
      [
         "South Australia",
         "black/white",
         "Snnn\u00b7aaa",
         "SOUTH AUSTRALIA",
         "S000\u00b7AZD",
         "No slogan on current series"
      ],
      [
         "Victoria",
         "blue/white",
         "aaa\u00b7nnn",
         "VICTORIA - THE PLACE TO BE",
         "ZZZ\u00b7562",
         "Current series will be exhausted this year"
      ]
   ]
}

The fields represent the following:

Tables are also contained in a corresponding *.db file. This is a SQL database with the same information. Note that due to the flexible format of HTML tables, the column names of tables in the database has been symbolized. For example, for a table with the columns ['foo', 'bar'], the columns in the database are actually col0 and col1.

Scripts

evaluate.py contains the evaluation script, whose options are:

usage: evaluate.py [-h] source_file db_file pred_file

positional arguments:
  source_file  source file for the prediction
  db_file      source database for the prediction
  pred_file    predictions by the model

optional arguments:
  -h, --help   show this help message and exit

The pred_file, which is supplied by the user, should contain lines of serialized JSON objects. Each JSON object should contain a query field which corresponds to the query predicted for a line in the input *.jsonl file and should be similar to the sql field of the input. In particular, it should contain:

An example predictions file can be found in test/example.pred.dev.jsonl. The lib directory contains dependencies of evaluate.py.

Integration Test

We supply a sample predictions file for the dev set in test/example.pred.dev.jsonl.bz2. You can unzip this file using bunzip2 test/example.pred.dev.jsonl.bz2 -k to look at what a real predictions file should look like. We distribute a docker file which installs the necessary dependencies of this library and runs the evaluation script on this file. The docker file also serves as an example of how to use the evaluation script.

To run the test, first build the image from the root directory:

docker build -t wikisqltest -f test/Dockerfile .

Next, run the image

docker run --rm --name wikisqltest wikisqltest

If everything works correctly, the output should be:

{
  "ex_accuracy": 0.5380596128725804,
  "lf_accuracy": 0.35375846099038116
}

Annotation

In addition to the raw data dump, we also release an optional annotation script that annotates WikiSQL using Stanford CoreNLP. The annotate.py script will annotate the query, question, and SQL table, as well as a sequence to sequence construction of the input and output for convenience of using Seq2Seq models. To use annotate.py, you must set up the CoreNLP python client using Stanford Stanza. One docker image of the CoreNLP server that this works with is here:

docker run --name corenlp -d -p 9000:9000 vzhong/corenlp-server

Note that the sequence output contain symbols to delineate the boundaries of fields. In lib/query.py you will also find accompanying functions to reconstruct a query given a sequence output in the annotated format.

FAQ

I will update this list with frequently asked questions.

How do you convert HTML table columns to SQL table columns?

Web tables are noisy and are not directly transferrable into a database. One problem is that SQL column names need to be symbolic whereas web table columns usually have unicode characters, whitespaces etc. To handle this problem, we convert table columns to symbols (e.g. Player Name to col1) just before executing the query. For the implementation details, please see evaluate.py.

Changelog