Giter Club home page Giter Club logo

nl2sql's Introduction

Natural Language Database Queries

This repository explores translation of natural language questions to SQL code to get data from relational databases. The base model and algorithm was inspired and based upon the Coarse2Fine repo.

This repo provides:

  • inference files for running the Coarse2Fine model with new input questions over tables from WikiSQL,
  • a sample Flask app that uses the inference files to serve the model, and
  • a simplified implementation of execution guidance when decoding the SQL code to improve the accuracy of the model.

Here are some slides for the presentation of this repo, and the Flask app page serving the model (www.nlp2sql.com):

Alt text

You need:

Install dependencies

pip install -r requirements.txt

Download pretrained model

Download pretrained model from here and unzip it in the folder pretrained in the root folder.

Train model

Use these for training (preprocess.py will save the data files in pt format):

cd src/
python preprocess.py
python train.py

Infer model

You can modify the config/model_config.json file and run run_model.py for infering the model with new input questions:

Example:

python run_model.py -config_path "config/model_config.json" -question "what was the result of the game with New York Jets?"

Result:

SQL code: SELECT  `Result` FROM table WHERE `Opponent` = New York Jets
Execution result: w 20-13

Use execution guidance for evaluating the model over test set

Evaluate the model over all questions from tables of the test set in WikiSQL:

cd src/
python evaluate.py -model_path ../pretrained/pretrain.pt -beam_search

nl2sql's People

Contributors

prezaei85 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

nl2sql's Issues

TypeError: string indices must be integers in preprocess.py

Preparing training ...
Building Training...
Traceback (most recent call last):
  File "preprocess.py", line 71, in <module>
    main()
  File "preprocess.py", line 49, in main
    train = table.IO.TableDataset(opt.train_anno, fields, opt, True)
  File "/home/shahqaan_qasim/imran/nl2sql/src/table/IO.py", line 106, in __init__
    js_list = read_anno_json(anno)
  File "/home/shahqaan_qasim/imran/nl2sql/src/table/IO.py", line 82, in read_anno_json
    cond_list = list(enumerate(js['query']['conds']))
TypeError: string indices must be integers

After following the issue #7 , I copied train.jsonl from data to annotated. And now it gives me the above error.

train.jsonl missing

When running preprocess.py under ./src,
it requires a train.jsonl under annotations which seems to be missing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.