|
| 1 | +# Introduction |
| 2 | +This is PointSQL, the source codes of [Natural Language to Structured Query Generation via Meta-Learning](https://arxiv.org/abs/1803.02400) |
| 3 | +and [Pointing Out SQL Queries From Text](https://www.microsoft.com/en-us/research/publication/pointing-sql-queries-text) from Microsoft Research. |
| 4 | +We present the setup for the WikiSQL experiments. |
| 5 | + |
| 6 | + |
| 7 | +# Training a New Model |
| 8 | + |
| 9 | +## Data Pre-processing |
| 10 | + |
| 11 | +- Download a preprocessed dataset [link](https://1drv.ms/u/s!AryzSDJYB5TxnDWZtpb3ZjL3xBny) to `input/` |
| 12 | +- Untar the file `tar -xvjf input.tar.bz2` |
| 13 | + |
| 14 | +#### Reproduce Preprocess Steps |
| 15 | + |
| 16 | +1. Download data from [WikiSQL](https://github.com/salesforce/WikiSQL). |
| 17 | + |
| 18 | +``` |
| 19 | +$ cd wikisql_data |
| 20 | +$ wget https://github.com/salesforce/WikiSQL/raw/master/data.tar.bz2 |
| 21 | +$ tar -xvjf data.tar.bz2 |
| 22 | +``` |
| 23 | +2. Put the [lib directory](https://github.com/salesforce/WikiSQL/tree/master/lib) under `wikisql_data/scripts/` |
| 24 | +3. Run annotation using Stanza and preproces the dataset |
| 25 | +``` |
| 26 | +$ cd wikisql_data/scripts/ |
| 27 | +$ python annotate.py |
| 28 | +$ python prepare.py |
| 29 | +``` |
| 30 | + |
| 31 | +4. Put the train/dev/test data into ``input/data`` for model training/testing. |
| 32 | +5. Use relevance function to prepare relevance files and put them under ``input/nl2prog_input_support_rank`` |
| 33 | +``` |
| 34 | +python wikisql_data/scripts/relevance.py |
| 35 | +``` |
| 36 | +6. Download pretrained embeddings from [glove](https://nlp.stanford.edu/projects/glove/) and [character n-gram embeddings](http://www.logos.t.u-tokyo.ac.jp/~hassy/publications/arxiv2016jmt/) and put them under ``input/`` |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +## Training |
| 41 | +Meta + Sum loss training |
| 42 | +``` |
| 43 | +$ OUTDIR=output/meta_sum |
| 44 | +$ mkdir $OUTDIR |
| 45 | +$ python run.py --input-dir ./input \ |
| 46 | + --output-dir $OUTDIR \ |
| 47 | + --config config/nl2prog.meta_2_0.001.rank.config \ |
| 48 | + --meta_learning_rate 0.001 --gradient_clip_norm 5 \ |
| 49 | + --num_layers 3 --num_meta_example 2 \ |
| 50 | + --meta_learning --production |
| 51 | +``` |
| 52 | + |
| 53 | +## Evaluation |
| 54 | +- Due to the preprocessing error, we ignore some development (see ``input/data/wikisql_err_dev.dat``) and test (see ``input/data/wikisql_err_test.dat``) set examples, we treat them as incorrect directly. |
| 55 | +- Run evaluation as follows (replace ``model_zoo/meta_sum/table_nl_prog-40`` with ``$OUTDIR/table_nl_prog-??`` with the last checkpoint in the folder): |
| 56 | + |
| 57 | +- Development set |
| 58 | +``` |
| 59 | +$ mkdir -p ${OUTDIR}_dev |
| 60 | +$ python run.py --input-dir ./input --output-dir ${OUTDIR}_dev \ |
| 61 | + --config config/nl2prog.meta_2_0.001.rank.devconfig \ |
| 62 | + --meta_learning --test-model model_zoo/meta_sum/table_nl_prog-40 --production |
| 63 | +``` |
| 64 | +* Run execution for developement set as follows: |
| 65 | + ``` |
| 66 | + $ cp ${OUTDIR}_dev/test_top_1.log dev_top_1.log |
| 67 | + $ python2 execute_dev.py |
| 68 | + #Q2 (predition) result is wrong: 1254 |
| 69 | + #Q1 or Q2 fail to parse: 0 |
| 70 | + #Q1 (ground truth) exec to None: 20 |
| 71 | + #Q1 (ground truth) failed to execute: 0 |
| 72 | + Logical Form Accuracy: 0.631383269546 |
| 73 | + Execute Accuracy: 0.68277747403 |
| 74 | + ``` |
| 75 | +- Test set |
| 76 | +``` |
| 77 | +$ mkdir -p ${OUTDIR}_test |
| 78 | +$ python run.py --input-dir ./input --output-dir ${OUTDIR}_test \ |
| 79 | + --config config/nl2prog.meta_2_0.001.rank.testconfig \ |
| 80 | + --meta_learning --test-model model_zoo/meta_sum/table_nl_prog-40 --production |
| 81 | +``` |
| 82 | +* Run execution for test set as follows: |
| 83 | + ``` |
| 84 | + $ cp ${OUTDIR}_test/test_top_1.log . |
| 85 | + $ python2 execute.py |
| 86 | + #Q2 (predition) result is wrong: 2556 |
| 87 | + #Q1 or Q2 fail to parse: 0 |
| 88 | + #Q1 (ground truth) exec to None: 48 |
| 89 | + #Q1 (ground truth) failed to execute: 0 |
| 90 | + Logical Form Accuracy: 0.628073829775 |
| 91 | + Execute Accuracy: 0.680379563733 |
| 92 | + ``` |
| 93 | + |
| 94 | +- Baseline model on test set |
| 95 | + ``` |
| 96 | + $ OUTDIR=output/base_sum |
| 97 | + $ python run.py --input-dir ./input --output-dir ${OUTDIR}_test \ |
| 98 | + --config config/nl2prog.testconfig --production \ |
| 99 | + --test-model model_zoo/base_sum/table_nl_prog-79 --production |
| 100 | + ``` |
| 101 | + |
| 102 | +* Run execution for the baseline model on test set as follows: |
| 103 | + ``` |
| 104 | + $ cp ${OUTDIR}_test/test_top_1.log . |
| 105 | + $ python2 execute.py |
| 106 | + #Q2 (predition) result is wrong: 2636 |
| 107 | + #Q1 or Q2 fail to parse: 0 |
| 108 | + #Q1 (ground truth) exec to None: 48 |
| 109 | + #Q1 (ground truth) failed to execute: 0 |
| 110 | + Logical Form Accuracy: 0.614592374009 |
| 111 | + Execute Accuracy: 0.668055314471 |
| 112 | + ``` |
| 113 | + |
| 114 | + |
| 115 | +# Pre-trained Models |
| 116 | +- Download [pretrained model checkpoints](https://1drv.ms/u/s!AryzSDJYB5TxnDR5I4rYjLi4HUYz) to ``model_zoo/`` |
| 117 | +- Run ``tar -xvjf model_zoo.tar.bz2`` to extract pretrain models. |
| 118 | + |
| 119 | + + Meta + Sum loss: `model_zoo/meta_sum` |
| 120 | + + Base Sum loss: `model_zoo/base_sum` |
| 121 | + |
| 122 | + |
| 123 | +# Requirements |
| 124 | +- Tensorflow 1.4 |
| 125 | +- python 3.6 |
| 126 | +- [Stanza](https://github.com/stanfordnlp/stanza) |
| 127 | + |
| 128 | + |
| 129 | +# Citation |
| 130 | + |
| 131 | +If you use the code in your paper, then please cite it as: |
| 132 | + |
| 133 | +``` |
| 134 | +@inproceedings{pshuang2018PT-MAML, |
| 135 | + author = {Po{-}Sen Huang and |
| 136 | + Chenglong Wang and |
| 137 | + Rishabh Singh and |
| 138 | + Wen-tau Yih and |
| 139 | + Xiaodong He}, |
| 140 | + title = {Natural Language to Structured Query Generation via Meta-Learning}, |
| 141 | + booktitle = {NAACL}, |
| 142 | + year = {2018}, |
| 143 | +} |
| 144 | +``` |
| 145 | + |
| 146 | +and |
| 147 | + |
| 148 | + |
| 149 | +``` |
| 150 | +@techreport{chenglong, |
| 151 | + author = {Wang, Chenglong and Brockschmidt, Marc and Singh, Rishabh}, |
| 152 | + title = {Pointing Out {SQL} Queries From Text}, |
| 153 | + number = {MSR-TR-2017-45}, |
| 154 | + year = {2017}, |
| 155 | + month = {November}, |
| 156 | + url = {https://www.microsoft.com/en-us/research/publication/pointing-sql-queries-text/}, |
| 157 | +} |
| 158 | +``` |
| 159 | + |
| 160 | + |
| 161 | + |
| 162 | +# Contributing |
| 163 | + |
| 164 | +This project welcomes contributions and suggestions. Most contributions require you to agree to a |
| 165 | +Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us |
| 166 | +the rights to use your contribution. For details, visit https://cla.microsoft.com. |
| 167 | + |
| 168 | +When you submit a pull request, a CLA-bot will automatically determine whether you need to provide |
| 169 | +a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions |
| 170 | +provided by the bot. You will only need to do this once across all repos using our CLA. |
| 171 | + |
| 172 | +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). |
| 173 | +For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or |
| 174 | +contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. |
0 commit comments