Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

inferring sql queries from plain-text questions about tables

NotificationsYou must be signed in to change notification settings

paulfitz/mlsql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Infer SQL queries from plain-text questions and table headers.

Requirements:

I take pretrained models published along with academic papers, and do whatever it takesto make them testable on fresh data (academic work often omits that, with code tiedto a particular benchmark dataset). I spend days tracking down and patching obscuredata preprocessing steps so you don't have to.

ValueNet example

So far I've packaged three models:

  • SQLova. Works on single tables.
  • ValueNet. Works on multiple tables, andmakes an effort to predict parameters.
  • IRNet. Works on multiple tables, but doesn'tpredict parameters.

In each case, I've mangled the original network somewhat, so if they interest you do follow upwith the original sources.

SQLova

This wraps up a published pretrained model for SQLova (https://github.com/naver/sqlova/).

Fetch and start SQLova running as an api server on port 5050:

docker run --name sqlova -d -p 5050:5050 paulfitz/sqlova

Be patient, the image is about 4.2GB. Once it is running, it'll take a few secondsto load models and then you can start asking questions about CSV tables. For example:

curl -F "csv=@bridges.csv" -F "q=how long is throgs neck" localhost:5050# {"answer":[1800],"params":["throgs neck"],"sql":"SELECT (length) FROM bridges WHERE bridge = ?"}

This is using the samplebridges.csv included in this repo.

bridgedesignerlength
BrooklynJ. A. Roebling1595
ManhattanG. Lindenthal1470
WilliamsburgL. L. Buck1600
QueensboroughPalmer & Hornbostel1182
TriboroughO. H. Ammann1380,383
Bronx WhitestoneO. H. Ammann2300
Throgs NeckO. H. Ammann1800
George WashingtonO. H. Ammann3500

Here are some examples of the answers and sql inferred for plain-text questions aboutthis table:

questionanswersql
how long is throgs neck1800SELECT (length) FROM bridges WHERE bridge = ? ['throgs neck']
who designed the george washingtonO. H. AmmannSELECT (designer) FROM bridges WHERE bridge = ? ['george washington']
how many bridges are there8SELECT count(bridge) FROM bridges
how many bridges are designed by O. H. Ammann4SELECT count(bridge) FROM bridges WHERE designer = ? ['O. H. Ammann']
which bridge are longer than 2000Bronx Whitestone, George WashingtonSELECT (bridge) FROM bridges WHERE length > ? ['2000']
how many bridges are longer than 20002SELECT count(bridge) FROM bridges WHERE length > ? ['2000']
what is the shortest length1182SELECT min(length) FROM bridges

With theplayers.csv sample from WikiSQL:

PlayerNo.NationalityPositionYears in TorontoSchool/Club Team
Antonio Lang21United StatesGuard-Forward1999-2000Duke
Voshon Lenard2United StatesGuard2002-03Minnesota
Martin Lewis32, 44United StatesGuard-Forward1996-97Butler CC (KS)
Brad Lohaus33United StatesForward-Center1996Iowa
Art Long42United StatesForward-Center2002-03Cincinnati
John Long25United StatesGuard1996-97Detroit
Kyle Lowry3United StatesGuard2012-presentVillanova
questionanswersql
What number did the person playing for Duke wear?21SELECT (No.) FROM players WHERE School/Club Team = ? ['duke']
Who is the player that wears number 42?Art LongSELECT (Player) FROM players WHERE No. = ? ['42']
What year did Brad Lohaus play?1996SELECT (Years in Toronto) FROM players WHERE Player = ? ['brad lohaus']
What country is Voshon Lenard from?United StatesSELECT (Nationality) FROM players WHERE Player = ? ['voshon lenard']

Some questions aboutiris.csv:

questionanswersql
what is the average petal width for virginica2.026SELECT avg(Petal.Width) FROM iris WHERE Species = ? ['virginica']
what is the longest sepal for versicolor7.0SELECT max(Sepal.Length) FROM iris WHERE Species = ? ['versicolor']
how many setosa rows are there50SELECT count(col0) FROM iris WHERE Species = ? ['setosa']

There are plenty of types of questions this model cannot answer (and that aren't coveredin the dataset it is trained on, or in the sql it is permitted to generate).

ValueNet

This wraps up a published pretrained model for ValueNet (https://github.com/brunnurs/valuenet).

Fetch and start ValueNet running as an api server on port 5050:

docker run --name valuenet -d -p 5050:5050 paulfitz/valuenet

You can then ask questions of individual csv files as before, or several csv files(just repeat-F "csv=@fileN.csv") or a simple sqlite db with tables related by foreign keys.In this last case, the model can answer using joins.

curl -F "sqlite=@companies.sqlite" -F "q=who is the CEO of Omni Cooperative" localhost:5050# {"answer":[["Dracula"]], "sql":"SELECT T1.name FROM people AS T1 JOIN organizations AS T2 \#   ON T1.id = T2.ceo_id WHERE T2.company = 'Omni Cooperative'"}curl -F "csv=@bridges.csv" -F "q=how many designers are there?" localhost:5050# {"answer":[[5]],"sql":"SELECT DISTINCT count(DISTINCT T1.designer) FROM bridges AS T1"}curl -F "csv=@bridges.csv" -F "csv=@airports.csv" -F "q=how many designers are there?" localhost:5050# same answercurl -F "csv=@bridges.csv" -F "csv=@airports.csv" -F "q=what is the name of the airport with the highest latitude?" localhost:5050# {"answer":[["Disraeli Inlet Water Aerodrome"]],#  "sql":"SELECT T1.name FROM airports AS T1 ORDER BY T1.latitude_deg DESC LIMIT 1"}

I've includes material to convert user tables into the form needed to query them. Don'tjudge the network by its quality here, go do a deep dive with the original - I've deviatedfrom the original in important respects, including how named entity recognition is done.

I've written upsome experiments with ValueNet.

IRNet

This wraps up a published pretrained model for IRNet (https://github.com/microsoft/IRNet).Upstream released a better model after I packaged this, so don't judge the model by playingwith it here.

Fetch and start IRNet running as an api server on port 5050:

docker run --name irnet -d -p 5050:5050 -v $PWD/cache:/cache paulfitz/irnet

Be super patient! Especially on the first run, when a few large models need tobe downloaded and unpacked.

You can then ask questions of individual csv files as before, or several csv files(just repeat-F "csv=@fileN.csv") or a simple sqlite db with tables related by foreign keys.In this last case, the model can answer using joins.

curl -F "sqlite=@companies.sqlite" -F "q=what city is The Firm headquartered in?" localhost:5050# Answer: SELECT T1.city FROM locations AS T1 JOIN organizations AS T2 WHERE T2.company = 1curl -F "sqlite=@companies.sqlite" -F "q=who is the CEO of Omni Cooperative" localhost:5050# Answer: SELECT T1.name FROM people AS T1 JOIN organizations AS T2 WHERE T2.company = 1curl -F "sqlite=@companies.sqlite" -F "q=what company has Dracula as CEO" localhost:5050# Answer: SELECT T1.company FROM organizations AS T1 JOIN people AS T2 WHERE T2.name = 1

(Note there's no value prediction, so e.g. the where clauses are= 1 rather than somethingmore useful).

Postman users

Curl can be replaced by Postman for those who like that. Here's a working set-up:Postman version

Other models

I hope to track research in the area and substitute in models as they become available:

Live demoes

  • Photon by the SalesForce group is a good live demo oftext-to-SQL.

About

inferring sql queries from plain-text questions about tables

Topics

Resources

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp