4
$\begingroup$

I have been reading about NLP but got confused and not able to figure out - if it is feasible for NLP to convert questions in natural language to transform into SQL queries (so that it can execute on concerned database and fetch the output).

Ex. If the user raises a question to the AI engine (application) -

How many new customers have registered on my website this month?

The AI should parse this using NLP techniques and convert it into SQL and execute on database table say "User_management" -

select count(1) from User_management
where joining_month = 'Oct' and joining_year = 2019

Please share your thoughts and advice.

Update 1) Got this SO link and this NLTK chapter as starting point

$\endgroup$

3 Answers 3

1
$\begingroup$

Yes it is possible. You can train end to end an RNN over the training data. It means input the user query as an input and set the output for the sql query. Definitely the most challenging part is preparing the training set as RNN needs a lot of data to be learned.

Also, for the training set, it might you can use a GAN‌ to generate more queries for the users' query dataset that you have. Notice that, as you want the query generator for the specific schema of the database, you need your own training data and it could not be generalized over all kinda schemas.

$\endgroup$
3
  • $\begingroup$ Thanks. I see where you are coming from. I'll study tinker about it. Do you have any blog reference or post about it? Will be easier if I have a reference. $\endgroup$
    – ranit.b
    Commented Oct 15, 2019 at 11:02
  • $\begingroup$ (+1) I agree that it's possible to try, but I doubt it would perform very well in general. Also the system would have to deal with the case of questions which cannot be converted. $\endgroup$
    – Erwan
    Commented Oct 15, 2019 at 12:35
  • $\begingroup$ check out this answer: datascience.stackexchange.com/questions/31617/… $\endgroup$ Commented May 5, 2020 at 13:42
0
$\begingroup$

Some time has passed since this question was posed, and AI has advanced. There are companies that offer this service now, e.g. AI2sql.

The algorithm behind is not RNN anymore, but transformers like GPT-3.

$\endgroup$
0
$\begingroup$

Check out http://beta.metatable.ai/ - it is a free beta version. They have text 2 SQL and you can execute it right there on an SQL database.

$\endgroup$
1
  • $\begingroup$ While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review $\endgroup$
    – Ethan
    Commented Apr 2, 2023 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.