IP Library › Granted Patent US 10,747,761
Granted Patent B2
US 10,747,761 · App. 15/885,613 · Granted Aug 18, 2020

Neural network based translation of natural language queries to database queries

Inventors: Victor Zhong (San Francisco, CA); Caiming Xiong (Palo Alto, CA); Richard Socher (Menlo Park, CA)
Assignee: salesforce.com, inc.
G06F16/24522G06N3/006G06N3/0454G06N3/08G06N7/005G06F16/13G06F16/24578
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 10,747,761
App. No.
15/885,613
Granted
Aug 18, 2020
Kind
B2
Abstract

A computing system uses neural networks to translate natural language queries to database queries. The computing system uses a plurality of machine learning based models, each machine learning model for generating a portion of the database query. The machine learning models use an input representation generated based on terms of the input natural language query, a set of columns of the database schema, and the vocabulary of a database query language, for example, structured query language SQL. The plurality of machine learning based models may include an aggregation classifier model for determining an aggregation operator in the database query, a result column predictor model for determining the result columns of the database query, and a condition clause predictor model for determining the condition clause of the database query. The condition clause predictor is based on reinforcement learning.

Claims (406)

1. A method carried out by a computer system comprising one or more computers, wherein the computer system performs the following steps:

receiving an input natural language query based on data stored using a database schema;

generating a sequence of tokens from a plurality of terms comprising:

terms of the input natural language query,

a set of columns of the database schema, and

vocabulary of a database query language;

generating one or more input representations, each input representation obtained by encoding the sequence of tokens;

accessing a plurality of machine learning based models, each machine learning based model configured to predict a portion of a database query corresponding to the input natural language query;

for each of the plurality of machine learning based models, executing the machine learning based model using an input representation to generate a portion of the database query;

combining the generated portions of the database query to obtain the database query; and

executing the database query to obtain a result set.

2. The method of claim 1 , wherein the input natural language query is received from a client device and the method further comprises a step of sending the result set to the client device.

3. The method of claim 1 , wherein the plurality of machine learning based models comprise an aggregation classifier model for determining an aggregation operator in the database query, wherein the aggregation classifier model comprises a multi-layer perceptron.

4. The method of claim 1 , wherein the plurality of machine learning based models comprise a result column predictor model for determining the result columns of the database query, wherein the result column predictor model comprises a multi-layer perceptron.

5. The method of claim 1 , wherein the plurality of machine learning based models comprise a condition clause predictor model for determining the condition clause of the database query, wherein the condition clause predictor model is based on reinforcement learning.

6. The method of claim 5 , further comprising:

receiving a result set based on a ground truth database query;

determining reward values based on a comparison of the result obtained from the generated query and the result obtained from the ground truth query; and

adjusting weights of the condition clause predictor model based on the reward values.

7. The method of claim 5 , further comprising:

determining column encodings corresponding to each token of the sequence;

determining a vector comprising scalar attention scores for each token of the input sequence;

normalizing the vector using a softmax function; and

determining the input representation as the sum of the column encodings weighted by the corresponding normalized score.

8. The method of claim 1 , further comprising:

training the plurality of machine learning based models using gradient descent to minimize an objective function representing a loss based on the result of each of the plurality of models.

9. The method of claim 1 , wherein generating the one or more input representations comprises computing an input representation κ agg by:

computing a scalar attention score, α in t =W inp h t enc for each tth token in sequence of tokens, wherein h t enc is a state of an encoder corresponding to a tth word in the input sequence,

normalizing the vector of scores α in =[α 1 inp , α 2 inp , . . . ] to produce a distribution over the tokens in the sequence of tokens,

obtaining the input representation κ agg as

κ

agg

=

∑

t

⁢

β

t

inp

⁢

h

t

enc

wherein β agg =softmax(α agg ), and

α agg =W agg tan h ( V agg κ agg +b agg )+ c agg

10. The method of claim 1 , further comprising:

using a long-short term memory (LSTM) with a pointer network that formulates a select clause of the SQL query with one or more column names, comprising:

given a list of column representations and a question representation, selecting the column that best matches the question, wherein the list of column representations is obtained by encoding each column name with a LSTM, wherein the representation of a particular column j, e j c is given by

h j,t c =LSTM(emb( x j,t c ), h j,t-1 c ) e j c =h j,T, c

11. The method of claim 1 , further comprising:

using reinforcement learning to formulate where conditions of the SQL query by executing the generated SQL query against the database to obtain a reward R(q({tilde over (y)}),q g ) defined as:

R

⁡

(

q

⁡

(

y

)

,

q

g

)

=

{

-

2

,

if

⁢

⁢

q

⁡

(

y

)

⁢

⁢

is

⁢

⁢

not

⁢

⁢

a

⁢

⁢

valid

⁢

⁢

S

⁢

⁢

Q

⁢

⁢

L

⁢

⁢

query

-

1

,

if

⁢

⁢

q

⁡

(

y

)

⁢

⁢

is

⁢

⁢

a

⁢

⁢

valid

⁢

⁢

⁢

S

⁢

⁢

Q

⁢

⁢

L

⁢

⁢

query

⁢

⁢

and

⁢

⁢

executes

to

⁢

⁢

an

⁢

⁢

⁢

incorrect

⁢

⁢

⁢

result

+

1

,

if

⁢

⁢

q

⁡

(

y

)

⁢

⁢

is

⁢

⁢

a

⁢

⁢

valid

⁢

⁢

⁢

S

⁢

⁢

Q

⁢

⁢

L

⁢

⁢

query

⁢

⁢

and

⁢

⁢

executes

to

⁢

⁢

the

⁢

⁢

correct

⁢

⁢

result

where q(y) denotes the query generated by the machine learning based model, and q g denotes the ground truth query corresponding to the input natural language query.

12. A method comprising:

processing a natural language request to generate parts of an SQL query, including:

using a long-short term memory (LSTM) with a pointer network that formulates a select clause of the SQL query with one or more column names; and

using an augmented pointer decoder trained by reinforcement learning to formulate where conditions of the SQL query.

13. The method of claim 12 , further comprising:

using a multilayer perceptron to determine an aggregation operation of the SQL query applicable to columns selected under specified conditions.

14. The method of claim 12 , wherein using a long-short term memory (LSTM) with a pointer network that formulates a select clause of the SQL query with one or more column names comprises:

given a list of column representations and a question representation, selecting the column that best matches the question.

15. The method of claim 14 , wherein the list of column representations is obtained by encoding each column name with a LSTM, wherein the representation of a particular column j, e j c is given by

h j,t c =LSTM(emb( x j,t c ), h j,t-1 c ) e j c =h j,T, c

16. The method of claim 14 , wherein generating the one or more input representations comprises computing an input representation κ agg by:

computing a scalar attention score, α in t =W inp h t enc , for each tth token in sequence of tokens, wherein h t enc is a state of an encoder corresponding to a tth word in the input sequence,

normalizing the vector of scores α in =[α 1 inp , α 2 inp , . . . ] to produce a distribution over

the tokens in the sequence of tokens, obtaining the input representation κ agg as

κ

agg

=

∑

t

⁢

β

t

inp

⁢

h

t

enc

wherein β agg =softmax(α agg ), and

α agg =W agg tan h ( V agg κ agg +b agg )+ c agg

17. The method of claim 14 , further comprising:

using reinforcement learning to formulate where conditions of the SQL query by executing the generated SQL query against the database to obtain a reward R(g({tilde over (y)}),q g ) defined as:

R

⁡

(

q

⁡

(

y

)

,

q

g

)

=

{

-

2

,

if

⁢

⁢

q

⁡

(

y

)

⁢

⁢

is

⁢

⁢

not

⁢

⁢

a

⁢

⁢

valid

⁢

⁢

S

⁢

⁢

Q

⁢

⁢

L

⁢

⁢

query

-

1

,

if

⁢

⁢

q

⁡

(

y

)

⁢

⁢

is

⁢

⁢

a

⁢

⁢

valid

⁢

⁢

⁢

S

⁢

⁢

Q

⁢

⁢

L

⁢

⁢

query

⁢

⁢

and

⁢

⁢

executes

to

⁢

⁢

an

⁢

⁢

⁢

incorrect

⁢

⁢

⁢

result

+

1

,

if

⁢

⁢

q

⁡

(

y

)

⁢

⁢

is

⁢

⁢

a

⁢

⁢

valid

⁢

⁢

⁢

S

⁢

⁢

Q

⁢

⁢

L

⁢

⁢

query

⁢

⁢

and

⁢

⁢

executes

to

⁢

⁢

the

⁢

⁢

correct

⁢

⁢

result

where q(y) denotes the query generated by the machine learning based model, and q g denotes the ground truth query corresponding to the input natural language query.

18. A non-transitory computer-readable storage medium comprising computer executable code that when executed by one or more computers causes the one or more computers to perform the steps comprising:

receiving an input natural language query based on data stored using a database schema;

generating a sequence of tokens from a plurality of terms comprising:

terms of the input natural language query,

a set of columns of the database schema, and

vocabulary of a database query language;

generating one or more input representations, each input representation obtained by encoding the sequence of tokens;

accessing a plurality of machine learning based models, each machine learning based model configured to predict a portion of a database query corresponding to the input natural language query;

for each of the plurality of machine learning based models, executing the machine learning based model using an input representation to generate a portion of the database query;

combining the generated portions of the database query to obtain the database query; and

executing the database query to obtain a result set.

19. A computer system for generating a recurrent neural network (RNN) architecture, the computer system comprising:

one or more computer processors; and

a non-transitory computer-readable storage medium comprising computer executable code that when executed by one or more computers causes the one or more computers to perform the steps comprising:

receiving an input natural language query based on data stored using a database schema;

generating a sequence of tokens from a plurality of terms comprising:

terms of the input natural language query,

a set of columns of the database schema, and

vocabulary of a database query language;

generating one or more input representations, each input representation obtained by encoding the sequence of tokens;

accessing a plurality of machine learning based models, each machine learning based model configured to predict a portion of a database query corresponding to the input natural language query;

for each of the plurality of machine learning based models, executing the machine learning based model using an input representation to generate a portion of the database query;

combining the generated portions of the database query to obtain the database query; and

executing the database query to obtain a result set.

Assignments (2)
CHANGE OF NAME Recorded Aug 4, 2026
From: SALESFORCE.COM, INC.
To: SALESFORCE, INC.
Reel/Frame 076118/0548 →
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded May 21, 2019
From: ZHONG, VICTOR; XIONG, CAIMING; SOCHER, RICHARD
To: SALESFORCE.COM, INC.
Reel/Frame 049248/0796 →
Continuity (2)
Provisional Application 62508367 · May 18, 2017
Related Publication 20180336198A1 · Nov 22, 2018
Cited By (12)
US 12,197,503 US 12,265,528 US 12,265,909 US 12,271,698 US 12,299,982 US 12,346,315 US 12,511,282 US 12,530,344 US 12,530,560 US 12,585,645 US 12,681,769 US 12,717,780