WO2022141880A1 - Sql语句生成方法、装置、服务器及计算机可读存储介质 - Google Patents

Sql语句生成方法、装置、服务器及计算机可读存储介质 Download PDF

Info

Publication number
WO2022141880A1
WO2022141880A1 PCT/CN2021/084304 CN2021084304W WO2022141880A1 WO 2022141880 A1 WO2022141880 A1 WO 2022141880A1 CN 2021084304 W CN2021084304 W CN 2021084304W WO 2022141880 A1 WO2022141880 A1 WO 2022141880A1
Authority
WO
WIPO (PCT)
Prior art keywords
target
field
function
label
classification model
Prior art date
Application number
PCT/CN2021/084304
Other languages
English (en)
French (fr)
Inventor
梁子敬
贺春艳
翁志
Original Assignee
平安科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2022141880A1 publication Critical patent/WO2022141880A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24553Query execution of query operations
    • G06F16/24558Binary matching operations
    • G06F16/2456Join operations
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/24Classification techniques
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/279Recognition of textual entities
    • G06F40/284Lexical analysis, e.g. tokenisation or collocates
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/30Semantic analysis
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/044Recurrent networks, e.g. Hopfield networks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/045Combinations of networks

Definitions

  • the present application relates to semantic analysis of databases in the field of big data, and in particular, to a method, apparatus, server and computer-readable storage medium for generating SQL statements.
  • the task input by the user is mainly converted into an executable SQL statement by using a natural language to SQL statement (Natural Language to SQL, NL2SQL) task, and then the computer executes the SQL statement to obtain the answer to the question. , and output the answer to the user.
  • SQL statement Natural Language to SQL, NL2SQL
  • the NL2SQL task is mainly realized through the semantic recognition model and multi-classification task, but the executable SQL statement corresponding to the problem cannot be accurately determined only through the semantic recognition model and the multi-classification task. Therefore, how to improve the generation accuracy of executable SQL statements is an urgent problem to be solved at present.
  • a method, apparatus, server and computer-readable storage medium for generating an SQL statement are provided.
  • a SQL statement generation method applied to a server, the server stores a SQL statement generation model, and the SQL statement generation model comprises a pre-trained Bert model, a pre-trained LSTM model or a GRU model, a pre-trained first A classification model group and a second classification model group, the method includes:
  • N target sentence fragments are generated, and each target sentence fragment includes the target problem, at least one of the fields, and at least one sequence of field labels;
  • each classification model in the first classification model group determine the number of fields of each preset SQL function and the first classification label of the connector
  • An executable SQL statement is generated according to the target query field of each preset SQL function, the first classification label of the connector, and the second classification label of the aggregation function.
  • a SQL statement generation device applied to a server, the server stores a SQL statement generation model, and the SQL statement generation model includes a pre-trained Bert model, a pre-trained LSTM model or a GRU model, a pre-trained first A classification model group and a second classification model group, and the SQL statement generating device includes:
  • an acquisition module used for acquiring the target question to be answered, and acquiring the data report corresponding to the target question
  • a statement fragment generation module configured to generate N target sentence fragments according to the target question and each field in the data report, each of the target sentence fragments including the target question, at least one of the fields and at least one sequence of field labels;
  • a control module for inputting the N target sentence fragments into the Bert model, to obtain a semantic vector and an encoding vector of each of the target sentence fragments;
  • the control module is used to input the semantic vector of each of the target sentence fragments into the LSTM model or the GRU model to obtain the target semantic vector;
  • a vector generation module for generating a target encoding vector corresponding to each field label in the field label sequence according to the encoding vector of each of the target sentence fragments;
  • a determination module for determining the number of fields of each preset SQL function and the first classification label of the connector according to the target semantic vector and each classification model in the first classification model group;
  • the determination module is also used to determine the probability that each field in the data report hits each preset SQL function and the second category label of the aggregation function;
  • the determining module is further configured to determine the target query field of each preset SQL function according to the probability that each field hits each preset SQL function and the number of fields of each preset SQL function;
  • the SQL statement generation module is configured to generate an executable SQL statement according to the target query field of each preset SQL function, the first classification label of the connector and the second classification label of the aggregation function.
  • a server includes a processor, a memory, and a computer program stored on the memory and executable by the processor, wherein when the computer program is executed by the processor, a method for generating an SQL statement is implemented , the above method includes:
  • N target sentence fragments are generated, and each target sentence fragment includes the target problem, at least one of the fields, and at least one sequence of field labels;
  • each classification model in the first classification model group determine the number of fields of each preset SQL function and the first classification label of the connector
  • An executable SQL statement is generated according to the target query field of each preset SQL function, the first classification label of the connector, and the second classification label of the aggregation function.
  • a computer-readable storage medium storing a computer program on the computer-readable storage medium, wherein when the computer program is executed by a processor, the steps of any one of the above-mentioned SQL statement generation methods are implemented.
  • the present application can greatly improve the generation accuracy of the SQL statement.
  • FIG. 1 is a schematic flowchart of a method for generating an SQL statement provided by an embodiment of the present application
  • FIG. 2 is a schematic diagram of a scene in which a target sentence fragment is generated in an embodiment of the present application
  • Fig. 3 is a structural representation of the SQL statement generation model in the embodiment of the present application.
  • FIG. 4 is a schematic block diagram of an apparatus for generating a SQL statement provided by an embodiment of the present application.
  • Fig. 5 is the schematic block diagram of the submodule of the SQL statement generation device in Fig. 4;
  • FIG. 6 is a schematic structural block diagram of a server provided by an embodiment of the present application.
  • the natural language to SQL statement Natural Language to SQL, NL2SQL
  • NL2SQL Natural Language to SQL
  • the NL2SQL task is mainly realized through semantic recognition model and multi-classification task, but only through semantic recognition model and multi-classification task can not accurately determine the executable SQL statement corresponding to the problem. Therefore, how to improve the generation accuracy of executable SQL statements is an urgent problem to be solved at present.
  • embodiments of the present application provide a method, apparatus, server, and computer-readable storage medium for generating an SQL statement.
  • the encoding vector and input the semantic vector of each target sentence fragment into the LSTM model or GRU model to obtain the target semantic vector, and at the same time, according to the encoding vector of each target sentence fragment, generate the target code corresponding to each field label in the field label sequence vector, and then according to the target semantic vector and each classification model in the first classification model group, determine the number of fields of each preset SQL function and the first classification label of the connector, and encode the vector according to each target and the first classification label of the first classification model.
  • each classification model in the two-class model group determine the probability that each field in the data report hits each preset SQL function and the second classification label of the aggregate function, and finally determine the probability of hitting each preset SQL function according to each field and The number of fields of each preset SQL function, determine the target query field of each preset SQL function, and according to the target query field of each preset SQL function, the first category label of the connector and the second category of the aggregation function tags, and generate executable SQL statements, which can greatly improve the generation accuracy of SQL statements.
  • FIG. 1 is a schematic flowchart of a method for generating an SQL statement provided by an embodiment of the present application.
  • the SQL statement generation method includes steps S101 to S109.
  • Step S101 Acquire a target question to be answered, and acquire a data report corresponding to the target question.
  • the server stores multiple data reports, different questions can involve different data reports, one question can also involve only one data report, one question can also involve multiple different data reports, and each data report includes multiple fields , the field may be a column field in the data report, or may be a row field in the data report, which is not specifically limited in this embodiment of the present application.
  • the server obtains a data query request sent by the terminal device, wherein the data query request includes a target question input by the user through the terminal device; the data query request is parsed to obtain the target question in the data query request ; Split the target question into multiple keywords, match each keyword in the multiple keywords with each field in each data report, and determine the data report with at least one keyword in each field. Data report corresponding to the target problem.
  • the target question is "As of November 10, 2020, the rate of return and total return of self-selected fund products”
  • split the target question “As of November 10, 2020, the rate of return and total return of self-selected fund products”
  • these keywords to find the data report corresponding to the target problem.
  • Step S102 Generate N target sentence fragments according to the target question and each field in the data report.
  • a field sequence corresponding to the data report obtains a field sequence corresponding to the data report, and insert a field label sequence at the head position of each field in the field sequence to obtain a target field sequence; split the target field sequence into N field subsequences , so that the sum of the number of first characters corresponding to each field subsequence and the number of second characters of the target question is less than or equal to the preset number of characters; splicing the target question and each field subsequence to obtain N initial sentence fragments, and character-fill the N initial sentence fragments to obtain N target sentence fragments.
  • the number of characters in each target sentence fragment is equal to the preset number of characters, and the preset number of characters can be set based on the actual situation, which is not specifically limited in this embodiment of the present application, for example, the preset number of characters is 256 or 128.
  • each target sentence fragment includes a target question, at least one field and at least one field label sequence, the number of field label sequences in the target sentence fragment matches the number of fields in the target sentence fragment, and the field label sequence includes Multiple different field labels.
  • the field label is used to describe whether the field in the target statement fragment is the target query field of the preset SQL function.
  • the preset SQL function includes the select function, the where function, and the Groupby function.
  • the field label The sequence includes a first field label, a second field label, and a third field label. The first field label is used to describe whether the field in the target sentence fragment is the target query field of the select function, and the second field label is used to describe the target sentence fragment. Whether the field is the target query field of the where function, and the third field label is used to describe whether the field in the target statement fragment is the target query field of the Groupby function.
  • the field sequence 10 corresponding to the data report includes M fields. Inserting the field label sequence [label, label2, label3] at the head position of each field in the field sequence 10 can obtain the target field sequence 20, label It is used to describe whether the field is the target query field of the select function, label2 is used to describe whether the field is the target query field of the where function, and label3 is used to describe whether the field is the target query field of the Groupby function. Then, the target field sequence 20 is divided into N field subsequences, and the N field subsequences constitute a field subsequence group 30. The target problem is spliced with each field subsequence in the field subsequence group 30, and N can be obtained. The N initial sentence fragments constitute the initial sentence fragment group 40, and finally the N initial sentence fragments are filled with characters to obtain N target sentence fragments.
  • Step S103 Input the N target sentence fragments into the Bert model to obtain a semantic vector and an encoding vector of each target sentence fragment.
  • the server stores a SQL statement generation model
  • the SQL statement generation model includes a pre-trained Bert model, a pre-trained LSTM model or a GRU model, a pre-trained first classification model group and a second classification model group, as shown in the figure
  • the Bert model is connected with the LSTM model or the GRU model
  • the LSTM model or the GRU model is connected with the first classification model group 11
  • the Bert model is also connected with the second classification model group 12
  • the first classification model group 11 includes the first classification model group 11.
  • the first classification model is used to determine the number of the first fields of the select function
  • the second classification model is used to determine the number of the second fields of the where function
  • the The three classification model is used to determine the number of third fields of the Groupby function
  • the fourth classification model is used to determine the first classification label of the connector
  • the second classification model group 12 includes the fifth classification model, the sixth classification model, and the seventh classification model and the eighth classification model
  • the fifth classification model is used to determine the probability that each field in the data report hits the select function
  • the sixth classification model is used to determine the probability that each field in the data report hits the where function
  • the seventh classification model uses In order to determine the probability that each field in the data report hits the Groupby function
  • the eighth classification model is used to determine the second classification label of the aggregation function.
  • the SQL statement generation model can be obtained, or, by training the Bert model, the GRU model, the first classification model group and the second classification model group
  • the model group is iteratively trained together, and the SQL statement generation model can be obtained.
  • the specific training process may be: obtaining a sample data set, and performing iterative training on the Bert model, LSTM model, the first classification model group and the second classification model group according to the sample data in the sample data set, until the Bert model, the LSTM model, the first classification model group. Both the first classification model group and the second classification model converge, and the SQL statement generation model is obtained.
  • the position of each character in each target sentence fragment in the preset dictionary is determined; according to the position of each character in each target sentence fragment in the preset dictionary, Each character is encoded to obtain the character vector sequence of each target sentence fragment; the character vector sequence of each target sentence fragment is input into the Bert model, and the semantic vector and encoding vector of each target sentence fragment are obtained.
  • the semantic vector is used to describe the semantic information that the target sentence fragment wants to express, and the preset dictionary can be set based on the actual situation, which is not specifically limited in the example of this application.
  • the mapping relationship with the character vector the character vector corresponding to the character can be obtained, and then the character vector sequence of the target sentence fragment is composed based on the character vector of each character.
  • Step S104 Input the semantic vector of each target sentence segment into the LSTM model or the GRU model to obtain a target semantic vector.
  • the semantic vector of each target sentence fragment is spliced to obtain a semantic vector sequence, and the semantic vector sequence is input into the LSTM model or GRU model to obtain the target semantic vector.
  • Step S105 Generate a target encoding vector corresponding to each field label in the field label sequence according to the encoding vector of each target sentence fragment.
  • the coding sub-vectors corresponding to each field label in the coding vector of each target sentence fragment are obtained; the coding sub-vectors corresponding to the same field labels are spliced to obtain the target coding vector corresponding to each field label.
  • the field label sequence is [label, label2, label3].
  • the code vector corresponding to the field label label of each field and the code corresponding to the field label label2 are obtained from the coding vector of the target sentence fragment.
  • the encoding sub-vectors corresponding to the field label label3 splicing all the encoding sub-vectors corresponding to the field label label to obtain the target encoding vector corresponding to the field label label, and splicing all the encoding sub-vectors corresponding to the field label label2 to obtain the field label
  • all coding sub-vectors corresponding to the field label label3 are spliced to obtain the target coding vector corresponding to the field label label3.
  • Step S106 according to the target semantic vector and each classification model in the first classification model group, determine the number of fields of each preset SQL function and the first classification label of the connector.
  • the preset SQL function includes a select function, a where function and a Groupby function
  • the first classification model group includes a first classification model, a second classification model, a third classification model and a fourth classification model
  • the first classification model is used to determine the select
  • the number of the first field of the function, the second classification model is used to determine the number of the second field of the where function, the third classification model is used to determine the number of the third field of the Groupby function, and the fourth classification model is used to determine the number of connectors.
  • the first category label is used to determine the select function, a where function and a Groupby function
  • the first classification model group includes a first classification model, a second classification model, a third classification model and a fourth classification model
  • the first classification model is used to determine the select
  • the target semantic vector is input into the first classification model to obtain the first field number of the select function; the target semantic vector is input into the second classification model to obtain the second field number of the where function; Input the third classification model to obtain the third field number of the Groupby function; input the target semantic vector into the fourth classification model to obtain the first classification label of the connector.
  • the first classification model, the second classification model, and the third classification model may be five-classification models, so the number of fields output by the first classification model, the second classification model, and the third classification model may be 0, 1, 2, 3 and 4, the fourth classification model is a three-classification model, therefore, the first classification label output by the fourth classification model includes the first connector label, the second connector label and the third connector label, and the fourth classification model outputs the first label.
  • a connector label indicates that the "and" connector is selected
  • the fourth classification model outputs the second connector label, it indicates that the "or" connector is selected
  • the fourth classification model outputs the third connector label, indicating that the connection is not selected. symbol.
  • the first classification model includes a first fully connected layer and a first Softmax model
  • the second classification model includes a second fully connected layer and a second Softmax model
  • the third classification model includes a third fully connected layer and a third Softmax model
  • the fourth classification model includes the fourth fully connected layer and the fourth Softmax model.
  • the target semantic vector is input into the first fully connected layer for processing, and the processed target semantic vector is input into the first Softmax model for processing to obtain The number of the first fields of the select function; input the target semantic vector into the second fully connected layer for processing, and input the processed target semantic vector into the second Softmax model for processing to obtain the second field number of the where function;
  • the semantic vector is input into the third fully connected layer for processing, and the processed target semantic vector is input into the third Softmax model for processing to obtain the third field number of the Groupby function;
  • the target semantic vector is input into the fourth fully connected layer for processing,
  • the processed target semantic vector is input into the fourth Softmax model for processing, and the first classification label of the connector is obtained.
  • the characterization formula of the third classification model can determine the number of third fields of the Groupby function, and the first classification label of the connector can be determined through the characterization formula of the fourth classification model, where and are the model parameters of the first fully connected layer, and are the model parameters of the second fully connected layer, and are the model parameters of the third fully connected layer, and are the model parameters of the fourth fully connected layer.
  • the first Softmax model, the second Softmax model and the third Softmax model are all five-category Softmax models.
  • the field number classification of the five-category Softmax model includes the number of fields being 0, the number of fields being 1, and the number of fields being 1. The number is 2, the number of fields is 3, and the number of fields is 4.
  • the fourth Softmax model is a three-category Softmax model.
  • the first category label of the connector output by the three-category Softmax model includes the first connector. label, the second connector label and the third connector label, if the fourth classification model outputs the first connector label, it means that the "and" connector is selected, and the fourth classification model outputs the second connector label, which means that the "or” is selected. "connector, the fourth classification model outputs the third connector label, which means that the connector is not selected.
  • Step S107 according to each described target coding vector and each classification model in the described second classification model group, determine that each field in the data report hits the probability of each preset SQL function and the second of the aggregation function. Category labels.
  • the second classification model group includes the fifth classification model, the sixth classification model, the seventh classification model and the eighth classification model
  • the field label sequence includes the first field label, the second field label and the third field label
  • the fifth classification The model is used to determine the probability that each field in the data report hits the select function
  • the sixth classification model is used to determine the probability that each field in the data report hits the where function
  • the seventh classification model is used to determine that each field in the data report hits Groupby The probability of the function
  • the eighth classification model is used to determine the second classification label of the aggregate function.
  • the target coding vector corresponding to the first field label is input into the fifth classification model to obtain the first probability that each field in the data report hits the select function; the target coding vector corresponding to the second field label is input into the described
  • the sixth classification model obtains the second probability that each field in the data report hits the where function; the target encoding vector corresponding to the first field label and the target encoding vector corresponding to the third field label are spliced to obtain the splicing code vector; splicing
  • the coding vector is input into the seventh classification model to obtain the third probability that each field in the data report hits the Groupby function; the target coding vector corresponding to the first field label is input into the eighth classification model to obtain the second classification label of the aggregation function.
  • the aggregation function includes a Min function, a Max function, an Avg function, a count function, and a Sum function.
  • the fifth classification model includes the fifth fully connected layer and the fifth Softmax model
  • the sixth classification model includes the sixth fully connected layer and the sixth Softmax model
  • the seventh classification model includes the seventh fully connected layer and the seventh Softmax model
  • the eighth classification model includes the eighth fully connected layer and the eighth Softmax model.
  • the target encoding vector corresponding to the first field label is input into the fifth fully connected layer for processing, and the processed target encoding vector is input into the fifth Softmax model, obtain the first probability that each field in the data report hits the select function; input the target coding vector corresponding to the second field label into the sixth fully connected layer for processing, and input the processed target coding vector into the sixth Softmax model , obtain the second probability that each field in the data report hits the where function; input the splicing coding vector into the seventh fully connected layer for processing, input the processed splicing coding vector into the seventh Softmax model, and obtain each field in the data report Hit the third probability of the Groupby function; input the target encoding vector corresponding to the first field label into the eighth fully connected layer, and input the processed target encoding vector into the eighth Softmax model to obtain the second classification label of the aggregation function.
  • the target encoding vector corresponding to the first field label is
  • the target encoding vector corresponding to the second field label is
  • the target encoding vector corresponding to the third field label is The first probability that each field in the report hits the select function
  • the first probability that each field in the data report hits the where function can be determined through the characterization formula of the sixth classification model
  • the fifth Softmax model, the sixth Softmax model, the seventh Softmax model, and the eighth Softmax model are all multi-class Softmax models.
  • the eighth Softmax model is a six-class Softmax model
  • the output of the eighth classification model is The second classification label includes the first label, the second label, the third label, the fourth label, the fifth label and the sixth label
  • the second classification label output by the eighth classification model is the first label, which means the selected aggregation function is "Min function”
  • the second classification label output by the eighth classification model is the second label, it means that the selected aggregation function is "Max function”
  • the second classification label output by the eighth classification model is the third label, it means that The selected aggregation function is "Avg function”
  • the second classification label output by the eighth classification model is the fourth label, it means that the selected aggregation function is "count function”
  • the second classification label output by the eighth classification model is the fifth label, it indicates that the selected aggregation function is "Sum function”
  • Step S108 Determine the target query field of each preset SQL function according to the probability that each field hits each preset SQL function and the number of fields of each preset SQL function.
  • the target query field of the select function is determined from each field, that is, according to each field in the data report hitting the select.
  • the order of the first probability of the function sort each field, get the first field queue, start from the first field of the first field queue, and select the target query field of the select function from the first field queue in turn, until the selection
  • the number of target query fields reaches the first field number. For example, if the number of the first fields is 2, the first 2 fields are selected from the first field queue as the target query fields of the select function.
  • each field in the data report hits the where function and the number of second fields of the where function
  • determine the target query field of the where function from each field that is, hit the where function according to each field in the data report.
  • the order of the size of the second probability sort each field, get the second field queue, start from the first field of the second field queue, select the target query field of the where function from the second field queue in turn, until the selected
  • the number of target query fields reaches the number of second fields. For example, if the number of the second field is 1, the first field is selected from the second field queue as the target query field of the where function.
  • the target query field of the Groupby function is determined from each field, that is, the Groupby function is hit according to each field in the data report.
  • the order of the size of the third probability sort each field to get the third field queue, starting from the first field of the third field queue, select the target query field of the Groupby function from the third field queue in turn, until the selected The number of target query fields reaches the number of third fields. For example, if the number of the third field is 1, the first field from the third field queue is selected as the target query field of the Groupby function.
  • Step S109 Generate an executable SQL statement according to the target query field of each preset SQL function, the first category label of the connector, and the second category label of the aggregate function.
  • the target connector in the SQL statement to be generated is determined; according to the second classification label, the target aggregation function in the SQL statement to be generated is determined; according to the target query of each preset SQL function Fields, target connectors, and target aggregate functions to generate executable SQL statements.
  • the target connector includes and and/or or, and the target aggregation function includes the Min function, the Max function, the Avg function, the count function and/or the Sum function.
  • the SQL statement may have a concatenator and/or aggregate function, or may not have an aggregate function and/or concatenator, and the SQL statement may include only the select function, or only the select function and the where function, or Only the select function and the Groupby function are included, and the select function, the where function and the Groupby function can also be included. This embodiment of the present application does not specifically limit this.
  • the SQL statement generation method by obtaining the data report corresponding to the target question, and according to the target question and each field in the data report, generating N target sentence fragments, and then inputting the N target sentence fragments into the Bert model, Obtain the semantic vector and encoding vector of each target sentence fragment, and input the semantic vector of each target sentence fragment into the LSTM model or GRU model to obtain the target semantic vector, and generate the field label sequence according to the encoding vector of each target sentence fragment.
  • the target encoding vector corresponding to each field label in and according to each target coding vector and each classification model in the second classification model group, determine the probability that each field in the data report hits each preset SQL function and the second classification label of the aggregation function, and finally, according to each field
  • the probability of hitting each preset SQL function and the number of fields of each preset SQL function are determined, and the target query field of each preset SQL function is determined, and the target query field of each preset SQL function and the first number of the connector are determined.
  • the first classification label and the second classification label of the aggregation function generate executable SQL statements, which can greatly improve the generation accuracy of SQL statements.
  • FIG. 4 is a schematic block diagram of an apparatus for generating a SQL statement provided by an embodiment of the present application.
  • the SQL statement generation device is applied to a server, the server stores a SQL statement generation model, and the SQL statement generation model includes a pre-trained Bert model, a pre-trained LSTM model or a GRU model, and a pre-trained first classification A model group and a second classification model group.
  • the SQL statement generation device 200 includes: an acquisition module 210, a statement segment generation module 220, a control module 230, a vector generation module 240, a determination module 250 and an SQL statement generation module 260, wherein:
  • the obtaining module 210 is used to obtain the target question to be answered, and obtain the data report corresponding to the target question;
  • the sentence fragment generation module 220 is configured to generate N target sentence fragments according to the target question and each field in the data report, and each target sentence fragment includes the target problem, at least one described fields and at least one sequence of field labels;
  • the control module 230 is configured to input the N target sentence fragments into the Bert model to obtain a semantic vector and an encoding vector of each of the target sentence fragments;
  • the control module 230 is used to input the semantic vector of each of the target sentence fragments into the LSTM model or the GRU model to obtain the target semantic vector;
  • the vector generation module 240 is configured to generate a target encoding vector corresponding to each field label in the field label sequence according to the encoding vector of each of the target sentence fragments;
  • the determining module 250 is configured to determine the number of fields of each preset SQL function and the first classification label of the connector according to the target semantic vector and each classification model in the first classification model group;
  • the determining module 250 is further configured to determine the probability that each field in the data report hits each preset SQL function according to each of the target coding vectors and each classification model in the second classification model group and the second categorical label of the aggregate function;
  • the determining module 250 is further configured to determine the target query field of each preset SQL function according to the probability that each field hits each preset SQL function and the number of fields of each preset SQL function;
  • the SQL statement generation module 260 is configured to generate an executable SQL statement according to the target query field of each preset SQL function, the first classification label of the connector and the second classification label of the aggregate function.
  • the field label sequence includes a plurality of different field labels, and the field labels are used to describe whether a field in the target sentence fragment is a target query field of a preset SQL function.
  • the number of characters of the target sentence fragment is equal to the preset number of characters.
  • the vector generating module 240 includes:
  • the splicing sub-module 242 is used for splicing the coding sub-vectors corresponding to the same described field labels to obtain the corresponding target coding vectors of each described field labels.
  • the preset SQL function includes a select function, a where function, and a Groupby function
  • the first classification model group includes a first classification model, a second classification model, a third classification model, and a fourth classification model
  • the determining module 250 is also used for:
  • the target semantic vector is input into the second classification model to obtain the second field number of the where function;
  • the target semantic vector is input into the third classification model to obtain the third field number of the Groupby function;
  • the second classification model group includes a fifth classification model, a sixth classification model, a seventh classification model and an eighth classification model
  • the field label sequence includes a first field label, a second field label and The third field label, the determining module 250 is also used for:
  • the target coding vector corresponding to the first field label is input into the fifth classification model to obtain the first probability that each field in the data report hits the select function;
  • the target coding vector corresponding to the second field label is input into the sixth classification model to obtain the second probability that each field in the data report hits the where function;
  • Described splicing coding vector is input described 7th classification model, obtains the 3rd probability that each field in described data report hits described where function;
  • the target encoding vector corresponding to the first field label is input into the eighth classification model to obtain the second classification label of the aggregation function.
  • the SQL statement generation module 260 is further configured to:
  • An executable SQL statement is generated according to the target query field of each preset SQL function, the target connector and the target aggregate function.
  • the apparatuses provided by the above embodiments may be implemented in the form of a computer program, and the computer program may be executed on the server as shown in FIG. 6 .
  • FIG. 6 is a schematic structural block diagram of a server provided by an embodiment of the present application.
  • the server includes a processor, a memory, and a network interface connected through a system bus, wherein the memory may include a storage medium and an internal memory, and the memory is used to store an SQL statement generation model, and the SQL statement generation model It includes a pre-trained Bert model, a pre-trained LSTM model or a GRU model, a pre-trained first classification model group and a second classification model group.
  • the storage medium may store an operating system and a computer program.
  • the computer program includes program instructions, which, when executed, can cause the processor to execute any SQL statement generation method.
  • the processor is used to provide computing and control capabilities to support the operation of the entire server.
  • the internal memory provides an environment for running the computer program in the storage medium.
  • the processor can execute any SQL statement generation method.
  • the network interface is used for network communication, such as sending assigned tasks.
  • the network interface is used for network communication, such as sending assigned tasks.
  • FIG. 6 is only a block diagram of a partial structure related to the solution of the present application, and does not constitute a limitation on the server to which the solution of the present application is applied. More or fewer components are shown in the figures, either in combination or with different arrangements of components.
  • the processor may be a central processing unit (Central Processing Unit, CPU), and the processor may also be other general-purpose processors, digital signal processors (Digital Signal Processors, DSP), application specific integrated circuits (Application Specific Integrated circuits) Circuit, ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
  • the general-purpose processor can be a microprocessor or the processor can also be any conventional processor or the like.
  • the processor is used for running the computer program stored in the memory to realize the following steps:
  • N target sentence fragments are generated, and each target sentence fragment includes the target problem, at least one of the fields, and at least one sequence of field labels;
  • each classification model in the first classification model group determine the number of fields of each preset SQL function and the first classification label of the connector
  • An executable SQL statement is generated according to the target query field of each preset SQL function, the first classification label of the connector, and the second classification label of the aggregation function.
  • the field label sequence includes a plurality of different field labels, and the field labels are used to describe whether a field in the target sentence fragment is a target query field of a preset SQL function.
  • the number of characters of the target sentence fragment is equal to the preset number of characters.
  • the processor when the processor generates a target encoding vector corresponding to each field label in the field label sequence according to the encoding vector of each target sentence fragment, the processor is configured to:
  • the coding sub-vectors corresponding to the same field labels are spliced to obtain a target coding vector corresponding to each of the field labels.
  • the preset SQL function includes a select function, a where function, and a Groupby function
  • the first classification model group includes a first classification model, a second classification model, a third classification model, and a fourth classification model
  • the processor is used for determining the number of fields of each preset SQL function and the first classification label of the connector according to the target semantic vector and each classification model in the first classification model group. accomplish:
  • the target semantic vector is input into the second classification model to obtain the second field number of the where function;
  • the target semantic vector is input into the third classification model to obtain the third field number of the Groupby function;
  • the second classification model group includes a fifth classification model, a sixth classification model, a seventh classification model and an eighth classification model
  • the field label sequence includes a first field label, a second field label and The third field label
  • the processor determines that each field in the data report hits each preset SQL function according to each target encoding vector and each classification model in the second classification model group
  • the probabilities and aggregation functions of the second categorical label are used to implement:
  • the target coding vector corresponding to the first field label is input into the fifth classification model to obtain the first probability that each field in the data report hits the select function;
  • the target coding vector corresponding to the second field label is input into the sixth classification model to obtain the second probability that each field in the data report hits the where function;
  • Described splicing coding vector is input described 7th classification model, obtains the 3rd probability that each field in described data report hits described where function;
  • the target encoding vector corresponding to the first field label is input into the eighth classification model to obtain the second classification label of the aggregation function.
  • the processor generates an executable SQL statement according to the target query field of each preset SQL function, the first classification label of the connector, and the second classification label of the aggregate function. , used to achieve:
  • An executable SQL statement is generated according to the target query field of each preset SQL function, the target connector and the target aggregate function.
  • the present application can be implemented by means of software plus a necessary general hardware platform. Based on this understanding, the technical solutions of the present application can be embodied in the form of software products in essence or the parts that make contributions to the prior art, and the computer software products can be stored in storage media, such as ROM/RAM, magnetic disks , optical disc, etc., including several instructions for causing a server (which may be a personal computer, a server, or a network server, etc.) to execute the methods described in various embodiments or some parts of the embodiments of the present application.
  • a server which may be a personal computer, a server, or a network server, etc.
  • Embodiments of the present application further provide a computer-readable storage medium, where a computer program is stored on the computer-readable storage medium, the computer program includes program instructions, and the method implemented when the program instructions are executed can be referred to herein.
  • Various embodiments of SQL statement generation methods are applied.
  • the computer-readable storage medium may be volatile or non-volatile.
  • the computer-readable storage medium may be an internal storage unit of the server described in the foregoing embodiments, such as a hard disk or a memory of the server.
  • the computer-readable storage medium may also be an external storage device of the server, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card equipped on the server , Flash Card (Flash Card) and so on.
  • the computer-readable storage medium may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required by at least one function, and the like; The data created by the use of the node, etc.
  • the blockchain referred to in this application is a new application mode of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm.
  • Blockchain essentially a decentralized database, is a series of data blocks associated with cryptographic methods. Each data block contains a batch of network transaction information to verify its Validity of information (anti-counterfeiting) and generation of the next block.
  • the blockchain can include the underlying platform of the blockchain, the platform product service layer, and the application service layer.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Artificial Intelligence (AREA)
  • General Health & Medical Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Evolutionary Computation (AREA)
  • Mathematical Physics (AREA)
  • Molecular Biology (AREA)
  • Biomedical Technology (AREA)
  • Biophysics (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Databases & Information Systems (AREA)
  • Computing Systems (AREA)
  • Software Systems (AREA)
  • Bioinformatics & Cheminformatics (AREA)
  • Bioinformatics & Computational Biology (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Evolutionary Biology (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

一种SQL语句生成方法、装置、服务器及计算机可读存储介质,该方法包括:获取目标问题对应的数据报表;根据目标问题和数据报表生成N个目标语句片段;将N个目标语句片段输入Bert模型,得到每个目标语句片段的语义向量和编码向量;根据每个编码向量生成每个字段标签对应的目标编码向量;根据目标语义向量和第一分类模型组确定预设SQL函数的字段个数和第一分类标签;根据每个目标编码向量和第二分类模型组确定各字段命中预设SQL函数的概率和第二分类标签;确定预设SQL函数的目标查询字段;生成可执行的SQL语句。该方法提高了SQL语句的生成准确性。该方法还涉及区块链领域,上述计算机可读存储介质可存储根据区块链节点的使用所创建的数据。

Description

SQL语句生成方法、装置、服务器及计算机可读存储介质
本申请要求于2020年12月31日提交的、申请号为202011642208.5、发明名称为“SQL语句生成方法、装置、服务器及计算机可读存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及大数据领域中数据库的语义分析,尤其涉及一种SQL语句生成方法、装置、服务器及计算机可读存储介质。
背景技术
随着网络和互联网技术的快速发展,越来越多的企业都开始使用机器人客服为用户提供服务,主要是用户输入问题,由机器人客户对用户输入的问题进行回答。发明人意识到,目前主要是使用自然语言转SQL语句(Natural Language to SQL,NL2SQL)任务将用户输入的问题转换为可执行的SQL语句,然后由计算机执行该SQL语句,以获得该问题的答案,并向用户输出该答案。
技术问题
NL2SQL任务主要是通过语义识别模型和多分类任务实现的,但仅通过语义识别模型和多分类任务无法准确地确定问题所对应的可执行的SQL语句。因此,如何提高可执行的SQL语句的生成准确性是目前亟待解决的问题。针对现有技术中存在的上述问题,现提供一种SQL语句生成方法、装置、服务器及计算机可读存储介质。
技术解决方案
具体技术方案如下:
一种SQL语句生成方法,应用于服务器,所述服务器存储有SQL语句生成模型,所述SQL语句生成模型包括预先训练好的Bert模型、预先训练好的LSTM模型或GRU模型、预先训练好的第一分类模型组和第二分类模型组,所述方法包括:
获取待回答的目标问题,并获取所述目标问题对应的数据报表;
根据所述目标问题和所述数据报表中的每个字段,生成N个目标语句片段,每个所述目标语句片段均包括所述目标问题、至少一个所述字段和至少一个字段标签序列;
将所述N个目标语句片段输入所述Bert模型,得到每个所述目标语句片段的语义向量和编码向量;
将每个所述目标语句片段的语义向量输入所述LSTM模型或GRU模型,得到目标语义向量;
根据每个所述目标语句片段的编码向量,生成所述字段标签序列中的每个字段标签对应的目标编码向量;
根据所述目标语义向量和所述第一分类模型组中的每个分类模型,确定每个预设SQL函数的字段个数和连接符的第一分类标签;
根据每个所述目标编码向量和所述第二分类模型组中的每个分类模型,确定所述数据报表中的各字段命中每个预设SQL函数的概率和聚合函数的第二分类标签;
根据所述各字段命中每个预设SQL函数的概率和每个预设SQL函数的字段个数,确定每个预设SQL函数的目标查询字段;
根据每个预设SQL函数的目标查询字段、所述连接符的第一分类标签和所述聚合函数的第二分类标签,生成可执行的SQL语句。
一种SQL语句生成装置,应用于服务器,所述服务器存储有SQL语句生成模型,所述SQL语句生成模型包括预先训练好的Bert模型、预先训练好的LSTM模型或GRU模型、预先训练好的第一分类模型组和第二分类模型组,所述SQL语句生成装置包括:
获取模块,用于获取待回答的目标问题,并获取所述目标问题对应的数据报表;
语句片段生成模块,用于根据所述目标问题和所述数据报表中的每个字段,生成N个目标语句片段,每个所述目标语句片段均包括所述目标问题、至少一个所述字段和至少一个字段标签序列;
控制模块,用于将所述N个目标语句片段输入所述Bert模型,得到每个所述目标语句片段的语义向量和编码向量;
所述控制模块,用于将每个所述目标语句片段的语义向量输入所述LSTM模型或GRU模型,得到目标语义向量;
向量生成模块,用于根据每个所述目标语句片段的编码向量,生成所述字段标签序列中的每个字段标签对应的目标编码向量;
确定模块,用于根据所述目标语义向量和所述第一分类模型组中的每个分类模型,确定每个预设SQL函数的字段个数和连接符的第一分类标签;
所述确定模块,还用于根据每个所述目标编码向量和所述第二分类模型组中的每个分类模型,确定所述数据报表中的各字段命中每个预设SQL函数的概率和聚合函数的第二分类标签;
所述确定模块,还用于根据所述各字段命中每个预设SQL函数的概率和每个预设SQL函数的字段个数,确定每个预设SQL函数的目标查询字段;
SQL语句生成模块,用于根据每个预设SQL函数的目标查询字段、所述连接符的第一分类标签和所述聚合函数的第二分类标签,生成可执行的SQL语句。
一种服务器,所述服务器包括处理器、存储器、以及存储在所述存储器上并可被所述处理器执行的计算机程序,其中所述计算机程序被所述处理器执行时,实现SQL语句生成方法,上述方法包括:
获取待回答的目标问题,并获取所述目标问题对应的数据报表;
根据所述目标问题和所述数据报表中的每个字段,生成N个目标语句片段,每个所述目标语句片段均包括所述目标问题、至少一个所述字段和至少一个字段标签序列;
将所述N个目标语句片段输入所述Bert模型,得到每个所述目标语句片段的语义向量和编码向量;
将每个所述目标语句片段的语义向量输入所述LSTM模型或GRU模型,得到目标语义向量;
根据每个所述目标语句片段的编码向量,生成所述字段标签序列中的每个字段标签对应的目标编码向量;
根据所述目标语义向量和所述第一分类模型组中的每个分类模型,确定每个预设SQL函数的字段个数和连接符的第一分类标签;
根据每个所述目标编码向量和所述第二分类模型组中的每个分类模型,确定所述数据报表中的各字段命中每个预设SQL函数的概率和聚合函数的第二分类标签;
根据所述各字段命中每个预设SQL函数的概率和每个预设SQL函数的字段个数,确定每个预设SQL函数的目标查询字段;
根据每个预设SQL函数的目标查询字段、所述连接符的第一分类标签和所述聚合函数的第二分类标签,生成可执行的SQL语句。
一种计算机可读存储介质,所述计算机可读存储介质上存储有计算机程序,其中所述计算机程序被处理器执行时,实现上述任一项所述的SQL语句生成方法的步骤。
有益效果
本申请能够极大的提高SQL语句的生成准确性。
附图说明
为了更清楚地说明本申请实施例技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1是本申请实施例提供的一种SQL语句生成方法的流程示意图;
图2是本申请实施例中生成目标语句片段的一场景示意图;
图3是本申请实施例中SQL语句生成模型的一结构示意图;
图4是本申请实施例提供的一种SQL语句生成装置的示意性框图;
图5是图4中的SQL语句生成装置的子模块的示意性框图;
图6是本申请实施例提供的一种服务器的结构示意性框图。
具体实施方式
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
附图中所示的流程图仅是示例说明,不是必须包括所有的内容和操作/步骤,也不是必须按所描述的顺序执行。例如,有的操作/步骤还可以分解、组合或部分合并,因此实际执行的顺序有可能根据实际情况改变。
随着网络和互联网技术的快速发展,越来越多的企业都开始使用机器人客服为用户提供服务,主要是用户输入问题,由机器人客户对用户输入的问题进行回答。目前,主要是 使用自然语言转SQL语句(Natural Language to SQL,NL2SQL)任务将用户输入的问题转换为可执行的SQL语句,然后由计算机执行该SQL语句,以获得该问题的答案,并向用户输出该答案。然而,NL2SQL任务主要是通过语义识别模型和多分类任务实现的,但仅通过语义识别模型和多分类任务无法准确地确定问题所对应的可执行的SQL语句。因此,如何提高可执行的SQL语句的生成准确性是目前亟待解决的问题。
为解决上述问题,本申请实施例提供一种SQL语句生成方法、装置、服务器及计算机可读存储介质。通过获取目标问题对应的数据报表,并根据目标问题和数据报表中的每个字段,生成N个目标语句片段,然后将N个目标语句片段输入Bert模型,得到每个目标语句片段的语义向量和编码向量,并将每个目标语句片段的语义向量输入LSTM模型或GRU模型,得到目标语义向量,同时根据每个目标语句片段的编码向量,生成字段标签序列中的每个字段标签对应的目标编码向量,再然后根据目标语义向量和第一分类模型组中的每个分类模型,确定每个预设SQL函数的字段个数和连接符的第一分类标签,并根据每个目标编码向量和第二分类模型组中的每个分类模型,确定数据报表中的各字段命中每个预设SQL函数的概率和聚合函数的第二分类标签,最后根据各字段命中每个预设SQL函数的概率和每个预设SQL函数的字段个数,确定每个预设SQL函数的目标查询字段,并根据每个预设SQL函数的目标查询字段、连接符的第一分类标签和聚合函数的第二分类标签,生成可执行的SQL语句,能够极大的提高SQL语句的生成准确性。
下面结合附图,对本申请的一些实施方式作详细说明。在不冲突的情况下,下述的实施例及实施例中的特征可以相互组合。
请参阅图1,图1是本申请实施例提供的一种SQL语句生成方法的流程示意图。
如图1所示,该SQL语句生成方法包括步骤S101至步骤S109。
步骤S101、获取待回答的目标问题,并获取所述目标问题对应的数据报表。
其中,服务器存储有多个数据报表,不同的问题可以涉及不同的数据报表,一个问题也可以仅涉及一个数据报表,一个问题也可以涉及多个不同的数据报表,每个数据报表包括多个字段,该字段可以是数据报表中的列字段,也可以是数据报表中的行字段,本申请实施例对此不做具体限定。
在一实施例中,服务器获取终端设备发送的数据查询请求,其中,所述数据查询请求包括用户通过终端设备输入的目标问题;对该数据查询请求进行解析,得到该数据查询请求中的目标问题;将该目标问题拆分为多个关键词,并将多个关键词中的每个关键词与每个数据报表中的各字段进行匹配,将各字段中存在至少一个关键词的数据报表确定为目标问题对应的数据报表。
例如,目标问题为“截至2020年11月10日,自选基金产品的收益率和总收益”,则将目标问题“截至2020年11月10日,自选基金产品的收益率和总收益”拆分,可以得到的关键词“自选基金产品”、“收益率”和“总收益”,然后通过这些关键词查找目标问题对应的数据报表。
步骤S102、根据所述目标问题和所述数据报表中的每个字段,生成N个目标语句片段。
示例性的,获取该数据报表对应的字段序列,并在该字段序列中的每个字段的头部位置***字段标签序列,得到目标字段序列;将该目标字段序列拆分为N个字段子序列,使得每个字段子序列各自对应的第一字符个数与目标问题的第二字符个数之和小于或等于预设字符个数;将该目标问题与每个字段子序列进行拼接,得到N个初始语句片段,并对N个初始语句片段进行字符填充,得到N个目标语句片段。其中,每个目标语句片段的字符个数等于预设字符个数,预设字符个数可基于实际情况进行设置,本申请实施例对此不做具体限定,例如,预设字符个数为256或128。
其中,每个目标语句片段均包括目标问题、至少一个字段和至少一个字段标签序列,目标语句片段中的字段标签序列的个数与目标语句片段中的字段的个数匹配,该字段标签序列包括多个不同的字段标签,该字段标签用于描述目标语句片段中的字段是否为预设SQL函数的目标查询字段,可选的,预设SQL函数包括select函数、where函数和Groupby函数,字段标签序列包括第一字段标签、第二字段标签和第三字段标签,第一字段标签用于描述目标语句片段中的字段是否为select函数的目标查询字段,第二字段标签用于描述目标语句片段中的字段是否为where函数的目标查询字段,第三字段标签用于描述目标语句片段中的字段是否为Groupby函数的目标查询字段。
如图2所示,数据报表对应的字段序列10包括M个字段,在字段序列10中的每个字段的头部位置***字段标签序列[label,label2,label3]可以得到目标字段序列20,label用于描述字段是否为select函数的目标查询字段,label2用于描述字段是否为where函数的目标查询字段,label3用于描述字段是否为Groupby函数的目标查询字段。然后将目标字段序列20拆分为N个字段子序列,N个字段子序列构成字段子序列组30,将该目标问题与字段子序列组30中的每个字段子序列进行拼接,可以得到N个初始语句片段,N个初始语句片段构成初始语句片段组40,最后对N个初始语句片段进行字符填充,得到N个目标语句片段。
步骤S103、将所述N个目标语句片段输入所述Bert模型,得到每个所述目标语句片段的语义向量和编码向量。
其中,服务器存储有SQL语句生成模型,SQL语句生成模型包括预先训练好的Bert模型、预先训练好的LSTM模型或GRU模型、预先训练好的第一分类模型组和第二分类模型组,如图3所示,Bert模型与LSTM模型或GRU模型连接,LSTM模型或GRU模型与第一分类模型组11连接,Bert模型还与第二分类模型组12连接,第一分类模型组11包括第一分类模型、第二分类模型、第三分类模型和第四分类模型,第一分类模型用于确定select函数的第一字段个数,第二分类模型用于确定where函数的第二字段个数,第三分类模型用于确定Groupby函数的第三字段个数,第四分类模型用于确定连接符的第一分类标签,第二分类模型组12包括第五分类模型、第六分类模型、第七分类模型和第八分类模型,第五分类模型用于确定数据报表中的各字段命中select函数的概率,第六分类模型用于确定数据报表中的各字段命中where函数的概率,第七分类模型用于确定数据报表中的各字段命中Groupby函数的概率,第八分类模型用于确定聚合函数的第二分类标签。
通过对Bert模型、LSTM模型、第一分类模型组和第二分类模型组一起进行迭代训练,可以得到SQL语句生成模型,或者,通过对Bert模型、GRU模型、第一分类模型组和第二分类模型组一起进行迭代训练,可以得到SQL语句生成模型。其具体训练过程可以为:获取样本数据集,并根据样本数据集中的样本数据对Bert模型、LSTM模型、第一分类模型组和第二分类模型组进行迭代训练,直到Bert模型、LSTM模型、第一分类模型组和第二分类模型均收敛,得到SQL语句生成模型。
在一实施例中,确定每个目标语句片段中的各字符在预设词典中的位置;根据每个目标语句片段中的各字符在预设词典中的位置,对每个目标语句片段中的各字符进行编码,得到每个目标语句片段的字符向量序列;将每个目标语句片段的字符向量序列输入Bert模型,得到每个目标语句片段的语义向量和编码向量。其中,该语义向量用于描述目标语句片段所想要表达的语义信息,预设词典可基于实际情况进行设置,本申请实例对此不做具体限定,通过字符在预设词典中的位置以及位置与字符向量之间的映射关系,可以得到字符对应的字符向量,然后再基于各字符的字符向量组成目标语句片段的字符向量序列。
步骤S104、将每个所述目标语句片段的语义向量输入所述LSTM模型或GRU模型,得到目标语义向量。
将每个目标语句片段的语义向量进行拼接,得到语义向量序列,并将该语义向量序列输入LSTM模型或GRU模型,得到目标语义向量。
步骤S105、根据每个所述目标语句片段的编码向量,生成所述字段标签序列中的每个字段标签对应的目标编码向量。
示例性的,获取每个目标语句片段的编码向量中的各字段标签对应的编码子向量;将相同字段标签对应的编码子向量进行拼接,得到每个字段标签对应的目标编码向量。例如,字段标签序列为[label,label2,label3],对于每个目标语句片段,从该目标语句片段的编码向量获取每个字段的字段标签label对应的编码子向量、字段标签label2对应的编码子向量、字段标签label3对应的编码子向量,将字段标签label对应的全部编码子向量进行拼接,得到字段标签label对应的目标编码向量,将字段标签labe2对应的全部编码子向量进行拼接,得到字段标签labe2对应的目标编码向量,将字段标签labe3对应的全部编码子向量进行拼接,得到字段标签labe3对应的目标编码向量。
步骤S106、根据所述目标语义向量和所述第一分类模型组中的每个分类模型,确定每个预设SQL函数的字段个数和连接符的第一分类标签。
其中,预设SQL函数包括select函数、where函数和Groupby函数,第一分类模型组包括第一分类模型、第二分类模型、第三分类模型和第四分类模型,第一分类模型用于确定select函数的第一字段个数,第二分类模型用于确定where函数的第二字段个数,第三分类模型用于确定Groupby函数的第三字段个数,第四分类模型用于确定连接符的第一分类标签。
在一实施例中,将目标语义向量输入第一分类模型,得到select函数的第一字段个数;将目标语义向量输入第二分类模型,得到where函数的第二字段个数;将目标语义向量输 入第三分类模型,得到Groupby函数的第三字段个数;将目标语义向量输入第四分类模型,得到连接符的第一分类标签。其中,第一分类模型、第二分类模型、第三分类模型可以为五分类模型,因此第一分类模型、第二分类模型、第三分类模型输出的字段个数可以为0、1、2、3和4,第四分类模型为三分类模型,因此,第四分类模型输出的第一分类标签包括第一连接符标签、第二连接符标签和第三连接符标签,第四分类模型输出第一连接符标签,则表示选择“and”连接符,第四分类模型输出第二连接符标签,则表示选择“or”连接符,第四分类模型输出第三连接符标签,则表示不选择连接符。
示例性的,第一分类模型包括第一全连接层和第一Softmax模型,第二分类模型包括第二全连接层和第二Softmax模型,第三分类模型包括第三全连接层和第三Softmax模型,第四分类模型包括第四全连接层和第四Softmax模型,因此,将目标语义向量输入第一全连接层进行处理,将经过处理后的目标语义向量输入第一Softmax模型进行处理,得到select函数的第一字段个数;将目标语义向量输入第二全连接层进行处理,将经过处理后的目标语义向量输入第二Softmax模型进行处理,得到where函数的第二字段个数;将目标语义向量输入第三全连接层进行处理,将经过处理后的目标语义向量输入第三Softmax模型进行处理,得到Groupby函数的第三字段个数;将目标语义向量输入第四全连接层进行处理,将经过处理后的目标语义向量输入第四Softmax模型进行处理,得到连接符的第一分类标签。
示例性的,设目标语义向量为,则通过第一分类模型的表征公式可以确定select函数的第一字段个数,通过第二分类模型的表征公式可以确定where函数的第二字段个数,通过第三分类模型的表征公式可以确定Groupby函数的第三字段个数,通过第四分类模型的表征公式可以确定连接符的第一分类标签,其中,和是第一全连接层的模型参数,和是第二全连接层的模型参数,和是第三全连接层的模型参数,和是第四全连接层的模型参数。
其中,第一Softmax模型、第二Softmax模型和第三Softmax模型均为五分类的Softmax模型,这个五分类的Softmax模型的字段个数分类包括字段个数为0、字段个数为1、字段个数为2、字段个数为3和字段个数为4这五个,第四Softmax模型为三分类的Softmax模型,这个三分类的Softmax模型输出的连接符的第一分类标签包括第一连接符标签、第二连接符标签和第三连接符标签,第四分类模型输出第一连接符标签,则表示选择“and”连接符,第四分类模型输出第二连接符标签,则表示选择“or”连接符,第四分类模型输出第三连接符标签,则表示不选择连接符。
步骤S107、根据每个所述目标编码向量和所述第二分类模型组中的每个分类模型,确定所述数据报表中的各字段命中每个预设SQL函数的概率和聚合函数的第二分类标签。
其中,第二分类模型组包括第五分类模型、第六分类模型、第七分类模型和第八分类模型,字段标签序列包括第一字段标签、第二字段标签和第三字段标签,第五分类模型用于确定数据报表中的各字段命中select函数的概率,第六分类模型用于确定数据报表中的各字段命中where函数的概率,第七分类模型用于确定数据报表中的各字段命中Groupby 函数的概率,第八分类模型用于确定聚合函数的第二分类标签。
在一实施例中,将第一字段标签对应的目标编码向量输入第五分类模型,得到数据报表中的各字段命中select函数的第一概率;将第二字段标签对应的目标编码向量输入所述第六分类模型,得到数据报表中的各字段命中where函数的第二概率;对第一字段标签对应的目标编码向量和第三字段标签对应的目标编码向量进行拼接,得到拼接编码向量;将拼接编码向量输入第七分类模型,得到数据报表中的各字段命中Groupby函数的第三概率;将第一字段标签对应的目标编码向量输入第八分类模型,得到聚合函数的第二分类标签。其中,聚合函数包括Min函数、Max函数、Avg函数、count函数、Sum函数。
示例性的,第五分类模型包括第五全连接层和第五Softmax模型,第六分类模型包括第六全连接层和第六Softmax模型,第七分类模型包括第七全连接层和第七Softmax模型,第八分类模型包括第八全连接层和第八Softmax模型,因此,将第一字段标签对应的目标编码向量输入第五全连接层进行处理,将经过处理后的目标编码向量输入第五Softmax模型,得到数据报表中的各字段命中select函数的第一概率;将第二字段标签对应的目标编码向量输入第六全连接层进行处理,将经过处理后的目标编码向量输入第六Softmax模型,得到数据报表中的各字段命中where函数的第二概率;将拼接编码向量输入第七全连接层进行处理,将经过处理后的拼接编码向量输入第七Softmax模型,得到数据报表中的各字段命中Groupby函数的第三概率;将第一字段标签对应的目标编码向量输入第八全连接层,将经过处理后的目标编码向量输入第八Softmax模型,得到聚合函数的第二分类标签。
示例性的,设第一字段标签对应的目标编码向量为,第二字段标签对应的目标编码向量为,第三字段标签对应的目标编码向量为,则通过第五分类模型的表征公式可以确定数据报表中的各字段命中select函数的第一概率,通过第六分类模型的表征公式可以确定数据报表中的各字段命中where函数的第一概率,通过第七分类模型的表征公式可以确定数据报表中的各字段命中Groupby函数的第三概率,通过第八分类模型的表征公式,其中,和是第五全连接层的模型参数,和是第六全连接层的模型参数,和是第七全连接层的模型参数,和是第八全连接层的模型参数。
示例性的,第五Softmax模型、第六Softmax模型、第七Softmax模型和第八Softmax模型均为多分类的Softmax模型,例如,第八Softmax模型为六分类的Softmax模型,第八分类模型输出的第二分类标签包括第一标签、第二标签、第三标签、第四标签、第五标签和第六标签,第八分类模型输出的第二分类标签为第一标签,则表示选择的聚合函数为“Min函数”,第八分类模型输出的第二分类标签为第二标签,则表示选择的聚合函数为“Max函数”,第八分类模型输出的第二分类标签为第三标签,则表示选择的聚合函数为“Avg函数”,第八分类模型输出的第二分类标签为第四标签,则表示选择的聚合函数为“count函数”,第八分类模型输出的第二分类标签为第五标签,则表示选择的聚合函数为“Sum函数”,第八分类模型输出的第二分类标签为第六标签,则表示不选择聚合函数。
步骤S108、根据所述各字段命中每个预设SQL函数的概率和每个预设SQL函数的字段个数,确定每个预设SQL函数的目标查询字段。
示例性的,根据数据报表中的各字段命中select函数的第一概率和select函数的第一字段个数,从各字段中确定select函数的目标查询字段,即根据数据报表中的各字段命中select函数的第一概率的大小顺序,对各字段进行排序,得到第一字段队列,从该第一字段队列的首个字段开始,依次从第一字段队列中选择select函数的目标查询字段,直到选择的目标查询字段的个数达到第一字段个数。例如,第一字段个数为2个,则从第一字段队列中选择靠前的2个字段作为select函数的目标查询字段。
类似的,根据数据报表中的各字段命中where函数的第二概率和where函数的第二字段个数,从各字段中确定where函数的目标查询字段,即根据数据报表中的各字段命中where函数的第二概率的大小顺序,对各字段进行排序,得到第二字段队列,从该第二字段队列的首个字段开始,依次从第二字段队列中选择where函数的目标查询字段,直到选择的目标查询字段的个数达到第二字段个数。例如,第二字段个数为1个,则从第二字段队列中选择第一个字段作为where函数的目标查询字段。
类似的,根据数据报表中的各字段命中Groupby函数的第三概率和Groupby函数的第三字段个数,从各字段中确定Groupby函数的目标查询字段,即根据数据报表中的各字段命中Groupby函数的第三概率的大小顺序,对各字段进行排序,得到第三字段队列,从该第三字段队列的首个字段开始,依次从第三字段队列中选择Groupby函数的目标查询字段,直到选择的目标查询字段的个数达到第三字段个数。例如,第三字段个数为1个,则从第三字段队列中选择第一个字段作为Groupby函数的目标查询字段。
步骤S109、根据每个预设SQL函数的目标查询字段、所述连接符的第一分类标签和所述聚合函数的第二分类标签,生成可执行的SQL语句。
示例性的,根据第一分类标签,确定待生成的SQL语句中的目标连接符;根据第二分类标签,确定待生成的SQL语句中的目标聚合函数;根据每个预设SQL函数的目标查询字段、目标连接符和目标聚合函数,生成可执行的SQL语句。其中,目标连接符包括and和/或or,目标聚合函数包括Min函数、Max函数、Avg函数、count函数和/或Sum函数。
可以理解的是,SQL语句中可以有连接符和/或聚合函数,也可以没有聚合函数和/或连接符,SQL语句中可以仅包括select函数,也可以仅包括select函数和where函数,也可以仅包括select函数和Groupby函数,还可以包括select函数、where函数和Groupby函数。本申请实施例对此不做具体限定。
上述实施例提供的SQL语句生成方法,通过获取目标问题对应的数据报表,并根据目标问题和数据报表中的每个字段,生成N个目标语句片段,然后将N个目标语句片段输入Bert模型,得到每个目标语句片段的语义向量和编码向量,并将每个目标语句片段的语义向量输入LSTM模型或GRU模型,得到目标语义向量,同时根据每个目标语句片段的编码向量,生成字段标签序列中的每个字段标签对应的目标编码向量,再然后根据目标语义向量和第一分类模型组中的每个分类模型,确定每个预设SQL函数的字段个数和连接符的第一分类标签,并根据每个目标编码向量和第二分类模型组中的每个分类模型,确定数据报表中的各字段命中每个预设SQL函数的概率和聚合函数的第二分类标签,最后根据各字 段命中每个预设SQL函数的概率和每个预设SQL函数的字段个数,确定每个预设SQL函数的目标查询字段,并根据每个预设SQL函数的目标查询字段、连接符的第一分类标签和聚合函数的第二分类标签,生成可执行的SQL语句,能够极大的提高SQL语句的生成准确性。
请参阅图4,图4是本申请实施例提供的一种SQL语句生成装置的示意性框图。
该SQL语句生成装置应用于服务器,所述服务器存储有SQL语句生成模型,所述SQL语句生成模型包括预先训练好的Bert模型、预先训练好的LSTM模型或GRU模型、预先训练好的第一分类模型组和第二分类模型组。
如图4所示,该SQL语句生成装置200包括:获取模块210、语句片段生成模块220、控制模块230、向量生成模块240、确定模块250和SQL语句生成模块260,其中:
所述获取模块210,用于获取待回答的目标问题,并获取所述目标问题对应的数据报表;
所述语句片段生成模块220,用于根据所述目标问题和所述数据报表中的每个字段,生成N个目标语句片段,每个所述目标语句片段均包括所述目标问题、至少一个所述字段和至少一个字段标签序列;
所述控制模块230,用于将所述N个目标语句片段输入所述Bert模型,得到每个所述目标语句片段的语义向量和编码向量;
所述控制模块230,用于将每个所述目标语句片段的语义向量输入所述LSTM模型或GRU模型,得到目标语义向量;
所述向量生成模块240,用于根据每个所述目标语句片段的编码向量,生成所述字段标签序列中的每个字段标签对应的目标编码向量;
所述确定模块250,用于根据所述目标语义向量和所述第一分类模型组中的每个分类模型,确定每个预设SQL函数的字段个数和连接符的第一分类标签;
所述确定模块250,还用于根据每个所述目标编码向量和所述第二分类模型组中的每个分类模型,确定所述数据报表中的各字段命中每个预设SQL函数的概率和聚合函数的第二分类标签;
所述确定模块250,还用于根据所述各字段命中每个预设SQL函数的概率和每个预设SQL函数的字段个数,确定每个预设SQL函数的目标查询字段;
所述SQL语句生成模块260,用于根据每个预设SQL函数的目标查询字段、所述连接符的第一分类标签和所述聚合函数的第二分类标签,生成可执行的SQL语句。
在一实施例中,所述字段标签序列包括多个不同的字段标签,所述字段标签用于描述所述目标语句片段中的字段是否为预设SQL函数的目标查询字段。
在一实施例中,所述目标语句片段的字符个数等于预设字符个数。
在一实施例中,如图5所示,所述向量生成模块240包括:
获取子模块241,用于获取每个所述目标语句片段的编码向量中的各所述字段标签对应的编码子向量;
拼接子模块242,用于将相同所述字段标签对应的编码子向量进行拼接,得到每个所述 字段标签对应的目标编码向量。
在一个实施例中,所述预设SQL函数包括select函数、where函数和Groupby函数,所述第一分类模型组包括第一分类模型、第二分类模型、第三分类模型和第四分类模型,所述确定模块250还用于:
将所述目标语义向量输入所述第一分类模型,得到所述select函数的第一字段个数;
将所述目标语义向量输入所述第二分类模型,得到所述where函数的第二字段个数;
将所述目标语义向量输入所述第三分类模型,得到所述Groupby函数的第三字段个数;
将所述目标语义向量输入所述第四分类模型,得到所述连接符的第一分类标签。
在一实施例中,所述第二分类模型组包括第五分类模型、第六分类模型、第七分类模型和第八分类模型,所述字段标签序列包括第一字段标签、第二字段标签和第三字段标签,所述确定模块250还用于:
将所述第一字段标签对应的目标编码向量输入所述第五分类模型,得到所述数据报表中的各字段命中所述select函数的第一概率;
将所述第二字段标签对应的所述目标编码向量输入所述第六分类模型,得到所述数据报表中的各字段命中所述where函数的第二概率;
对所述第一字段标签对应的所述目标编码向量和所述第三字段标签对应的所述目标编码向量进行拼接,得到拼接编码向量;
将所述拼接编码向量输入所述第七分类模型,得到所述数据报表中的各字段命中所述where函数的第三概率;
将所述第一字段标签对应的目标编码向量输入所述第八分类模型,得到聚合函数的第二分类标签。
在一实施例中,所述SQL语句生成模块260还用于:
根据所述第一分类标签,确定待生成的SQL语句中的目标连接符;
根据所述第二分类标签,确定待生成的SQL语句中的目标聚合函数;
根据每个预设SQL函数的目标查询字段、所述目标连接符和所述目标聚合函数,生成可执行的SQL语句。
需要说明的是,所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,上述描述的装置和各模块及单元的具体工作过程,可以参考前述SQL语句生成方法实施例中的对应过程,在此不再赘述。
上述实施例提供的装置可以实现为一种计算机程序的形式,该计算机程序可以在如图6所示的服务器上运行。
请参阅图6,图6是本申请实施例提供的一种服务器的结构示意性框图。
如图6所示,该服务器包括通过***总线连接的处理器、存储器和网络接口,其中,存储器可以包括存储介质和内存储器,所述存储器用于存储SQL语句生成模型,所述SQL语句生成模型包括预先训练好的Bert模型、预先训练好的LSTM模型或GRU模型、预先训练好的第一分类模型组和第二分类模型组。
存储介质可存储操作***和计算机程序。该计算机程序包括程序指令,该程序指令被执行时,可使得处理器执行任意一种SQL语句生成方法。
处理器用于提供计算和控制能力,支撑整个服务器的运行。
内存储器为存储介质中的计算机程序的运行提供环境,该计算机程序被处理器执行时,可使得处理器执行任意一种SQL语句生成方法。
该网络接口用于进行网络通信,如发送分配的任务等。本领域技术人员可以理解,图6中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的服务器的限定,具体的服务器可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。
应当理解的是,处理器可以是中央处理单元(Central Processing Unit,CPU),该处理器还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现场可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。其中,通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。
其中,在一实施例中,所述处理器用于运行存储在存储器中的计算机程序,以实现如下步骤:
获取待回答的目标问题,并获取所述目标问题对应的数据报表;
根据所述目标问题和所述数据报表中的每个字段,生成N个目标语句片段,每个所述目标语句片段均包括所述目标问题、至少一个所述字段和至少一个字段标签序列;
将所述N个目标语句片段输入所述Bert模型,得到每个所述目标语句片段的语义向量和编码向量;
将每个所述目标语句片段的语义向量输入所述LSTM模型或GRU模型,得到目标语义向量;
根据每个所述目标语句片段的编码向量,生成所述字段标签序列中的每个字段标签对应的目标编码向量;
根据所述目标语义向量和所述第一分类模型组中的每个分类模型,确定每个预设SQL函数的字段个数和连接符的第一分类标签;
根据每个所述目标编码向量和所述第二分类模型组中的每个分类模型,确定所述数据报表中的各字段命中每个预设SQL函数的概率和聚合函数的第二分类标签;
根据所述各字段命中每个预设SQL函数的概率和每个预设SQL函数的字段个数,确定每个预设SQL函数的目标查询字段;
根据每个预设SQL函数的目标查询字段、所述连接符的第一分类标签和所述聚合函数的第二分类标签,生成可执行的SQL语句。
在一实施例中,所述字段标签序列包括多个不同的字段标签,所述字段标签用于描述所述目标语句片段中的字段是否为预设SQL函数的目标查询字段。
在一实施例中,所述目标语句片段的字符个数等于预设字符个数。
在一实施例中,所述处理器在实现根据每个所述目标语句片段的编码向量,生成所述字段标签序列中的每个字段标签对应的目标编码向量时,用于实现:
获取每个所述目标语句片段的编码向量中的各所述字段标签对应的编码子向量;
将相同所述字段标签对应的编码子向量进行拼接,得到每个所述字段标签对应的目标编码向量。
在一实施例中,所述预设SQL函数包括select函数、where函数和Groupby函数,所述第一分类模型组包括第一分类模型、第二分类模型、第三分类模型和第四分类模型,所述处理器在实现根据所述目标语义向量和所述第一分类模型组中的每个分类模型,确定每个预设SQL函数的字段个数和连接符的第一分类标签时,用于实现:
将所述目标语义向量输入所述第一分类模型,得到所述select函数的第一字段个数;
将所述目标语义向量输入所述第二分类模型,得到所述where函数的第二字段个数;
将所述目标语义向量输入所述第三分类模型,得到所述Groupby函数的第三字段个数;
将所述目标语义向量输入所述第四分类模型,得到所述连接符的第一分类标签。
在一实施例中,所述第二分类模型组包括第五分类模型、第六分类模型、第七分类模型和第八分类模型,所述字段标签序列包括第一字段标签、第二字段标签和第三字段标签,所述处理器在实现根据每个所述目标编码向量和所述第二分类模型组中的每个分类模型,确定所述数据报表中的各字段命中每个预设SQL函数的概率和聚合函数的第二分类标签时,用于实现:
将所述第一字段标签对应的目标编码向量输入所述第五分类模型,得到所述数据报表中的各字段命中所述select函数的第一概率;
将所述第二字段标签对应的所述目标编码向量输入所述第六分类模型,得到所述数据报表中的各字段命中所述where函数的第二概率;
对所述第一字段标签对应的所述目标编码向量和所述第三字段标签对应的所述目标编码向量进行拼接,得到拼接编码向量;
将所述拼接编码向量输入所述第七分类模型,得到所述数据报表中的各字段命中所述where函数的第三概率;
将所述第一字段标签对应的目标编码向量输入所述第八分类模型,得到聚合函数的第二分类标签。
在一实施例中,所述处理器在实现根据每个预设SQL函数的目标查询字段、所述连接符的第一分类标签和所述聚合函数的第二分类标签,生成可执行的SQL语句时,用于实现:
根据所述第一分类标签,确定待生成的SQL语句中的目标连接符;
根据所述第二分类标签,确定待生成的SQL语句中的目标聚合函数;
根据每个预设SQL函数的目标查询字段、所述目标连接符和所述目标聚合函数,生成可执行的SQL语句。
需要说明的是,所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,上述描述的服务器的具体工作过程,可以参考前述SQL语句生成方法实施例中的对应过程, 在此不再赘述。
通过以上的实施方式的描述可知,本领域的技术人员可以清楚地了解到本申请可借助软件加必需的通用硬件平台的方式来实现。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台服务器(可以是个人计算机,服务器,或者网络服务器等)执行本申请各个实施例或者实施例的某些部分所述的方法。
本申请实施例还提供一种计算机可读存储介质,所述计算机可读存储介质上存储有计算机程序,所述计算机程序中包括程序指令,所述程序指令被执行时所实现的方法可参阅本申请SQL语句生成方法的各个实施例。
其中,所述计算机可读存储介质可以是易失性的,也可以是非易失性的。所述计算机可读存储介质可以是前述实施例所述的服务器的内部存储单元,例如所述服务器的硬盘或内存。所述计算机可读存储介质也可以是所述服务器的外部存储设备,例如所述服务器上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。
进一步地,所述计算机可读存储介质可主要包括存储程序区和存储数据区,其中,存储程序区可存储操作***、至少一个功能所需的应用程序等;存储数据区可存储根据区块链节点的使用所创建的数据等。
本申请所指区块链是分布式数据存储、点对点传输、共识机制、加密算法等计算机技术的新型应用模式。区块链(Blockchain),本质上是一个去中心化的数据库,是一串使用密码学方法相关联产生的数据块,每一个数据块中包含了一批次网络交易的信息,用于验证其信息的有效性(防伪)和生成下一个区块。区块链可以包括区块链底层平台、平台产品服务层以及应用服务层等。
应当理解,在此本申请说明书中所使用的术语仅仅是出于描述特定实施例的目的而并不意在限制本申请。如在本申请说明书和所附权利要求书中所使用的那样,除非上下文清楚地指明其它情况,否则单数形式的“一”、“一个”及“该”意在包括复数形式。
还应当理解,在本申请说明书和所附权利要求书中使用的术语“和/或”是指相关联列出的项中的一个或多个的任何组合以及所有可能组合,并且包括这些组合。需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者***不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者***所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、方法、物品或者***中还存在另外的相同要素。
上述本申请实施例序号仅仅为了描述,不代表实施例的优劣。以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到各种等效的修改或替换,这些修改或替换都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以权利要求的保护范围为准。

Claims (20)

  1. 一种SQL语句生成方法,其中,应用于服务器,所述服务器存储有SQL语句生成模型,所述SQL语句生成模型包括预先训练好的Bert模型、预先训练好的LSTM模型或GRU模型、预先训练好的第一分类模型组和第二分类模型组,所述方法包括:
    获取待回答的目标问题,并获取所述目标问题对应的数据报表;
    根据所述目标问题和所述数据报表中的每个字段,生成N个目标语句片段,每个所述目标语句片段均包括所述目标问题、至少一个所述字段和至少一个字段标签序列;
    将所述N个目标语句片段输入所述Bert模型,得到每个所述目标语句片段的语义向量和编码向量;
    将每个所述目标语句片段的语义向量输入所述LSTM模型或GRU模型,得到目标语义向量;
    根据每个所述目标语句片段的编码向量,生成所述字段标签序列中的每个字段标签对应的目标编码向量;
    根据所述目标语义向量和所述第一分类模型组中的每个分类模型,确定每个预设SQL函数的字段个数和连接符的第一分类标签;
    根据每个所述目标编码向量和所述第二分类模型组中的每个分类模型,确定所述数据报表中的各字段命中每个预设SQL函数的概率和聚合函数的第二分类标签;
    根据所述各字段命中每个预设SQL函数的概率和每个预设SQL函数的字段个数,确定每个预设SQL函数的目标查询字段;
    根据每个预设SQL函数的目标查询字段、所述连接符的第一分类标签和所述聚合函数的第二分类标签,生成可执行的SQL语句。
  2. 根据权利要求1所述的SQL语句生成方法,其中,所述字段标签序列包括多个不同的字段标签,所述字段标签用于描述所述目标语句片段中的字段是否为预设SQL函数的目标查询字段。
  3. 根据权利要求1所述的SQL语句生成方法,其中,所述目标语句片段的字符个数等于预设字符个数。
  4. 根据权利要求1所述的SQL语句生成方法,其中,所述根据每个所述目标语句片段的编码向量,生成所述字段标签序列中的每个字段标签对应的目标编码向量,包括:
    获取每个所述目标语句片段的编码向量中的各所述字段标签对应的编码子向量;
    将相同所述字段标签对应的编码子向量进行拼接,得到每个所述字段标签对应的目标编码向量。
  5. 根据权利要求1-4中任一项所述的SQL语句生成方法,其中,所述预设SQL函数包括select函数、where函数和Groupby函数,所述第一分类模型组包括第一分类模型、第二分类模型、第三分类模型和第四分类模型,所述根据所述目标语义向量和所述第一分类模型组中的每个分类模型,确定每个预设SQL函数的字段个数和连接符的第一分类标签, 包括:
    将所述目标语义向量输入所述第一分类模型,得到所述select函数的第一字段个数;
    将所述目标语义向量输入所述第二分类模型,得到所述where函数的第二字段个数;
    将所述目标语义向量输入所述第三分类模型,得到所述Groupby函数的第三字段个数;
    将所述目标语义向量输入所述第四分类模型,得到所述连接符的第一分类标签。
  6. 根据权利要求5所述的SQL语句生成方法,其中,所述第二分类模型组包括第五分类模型、第六分类模型、第七分类模型和第八分类模型,所述字段标签序列包括第一字段标签、第二字段标签和第三字段标签,所述根据每个所述目标编码向量和所述第二分类模型组中的每个分类模型,确定所述数据报表中的各字段命中每个预设SQL函数的概率和聚合函数的第二分类标签,包括:
    将所述第一字段标签对应的目标编码向量输入所述第五分类模型,得到所述数据报表中的各字段命中所述select函数的第一概率;
    将所述第二字段标签对应的所述目标编码向量输入所述第六分类模型,得到所述数据报表中的各字段命中所述where函数的第二概率;
    对所述第一字段标签对应的所述目标编码向量和所述第三字段标签对应的所述目标编码向量进行拼接,得到拼接编码向量;
    将所述拼接编码向量输入所述第七分类模型,得到所述数据报表中的各字段命中所述where函数的第三概率;
    将所述第一字段标签对应的目标编码向量输入所述第八分类模型,得到聚合函数的第二分类标签。
  7. 根据权利要求1-4中任一项所述的SQL语句生成方法,其中,所述根据每个预设SQL函数的目标查询字段、所述连接符的第一分类标签和所述聚合函数的第二分类标签,生成可执行的SQL语句,包括:
    根据所述第一分类标签,确定待生成的SQL语句中的目标连接符;
    根据所述第二分类标签,确定待生成的SQL语句中的目标聚合函数;
    根据每个预设SQL函数的目标查询字段、所述目标连接符和所述目标聚合函数,生成可执行的SQL语句。
  8. 一种SQL语句生成装置,其中,应用于服务器,所述服务器存储有SQL语句生成模型,所述SQL语句生成模型包括预先训练好的Bert模型、预先训练好的LSTM模型或GRU模型、预先训练好的第一分类模型组和第二分类模型组,所述SQL语句生成装置包括:
    获取模块,用于获取待回答的目标问题,并获取所述目标问题对应的数据报表;
    语句片段生成模块,用于根据所述目标问题和所述数据报表中的每个字段,生成N个目标语句片段,每个所述目标语句片段均包括所述目标问题、至少一个所述字段和至少一个字段标签序列;
    控制模块,用于将所述N个目标语句片段输入所述Bert模型,得到每个所述目标语句 片段的语义向量和编码向量;
    所述控制模块,用于将每个所述目标语句片段的语义向量输入所述LSTM模型或GRU模型,得到目标语义向量;
    向量生成模块,用于根据每个所述目标语句片段的编码向量,生成所述字段标签序列中的每个字段标签对应的目标编码向量;
    确定模块,用于根据所述目标语义向量和所述第一分类模型组中的每个分类模型,确定每个预设SQL函数的字段个数和连接符的第一分类标签;
    所述确定模块,还用于根据每个所述目标编码向量和所述第二分类模型组中的每个分类模型,确定所述数据报表中的各字段命中每个预设SQL函数的概率和聚合函数的第二分类标签;
    所述确定模块,还用于根据所述各字段命中每个预设SQL函数的概率和每个预设SQL函数的字段个数,确定每个预设SQL函数的目标查询字段;
    SQL语句生成模块,用于根据每个预设SQL函数的目标查询字段、所述连接符的第一分类标签和所述聚合函数的第二分类标签,生成可执行的SQL语句。
  9. 根据权利要求8所述的SQL语句生成装置,其中,所述字段标签序列包括多个不同的字段标签,所述字段标签用于描述所述目标语句片段中的字段是否为预设SQL函数的目标查询字段。
  10. 根据权利要求8所述的SQL语句生成装置,其中,所述目标语句片段的字符个数等于预设字符个数。
  11. 根据权利要求8所述的SQL语句生成装置,其中,所述向量生成模块包括:
    获取子模块,用于获取每个所述目标语句片段的编码向量中的各所述字段标签对应的编码子向量;
    拼接子模块,用于将相同所述字段标签对应的编码子向量进行拼接,得到每个所述字段标签对应的目标编码向量。
  12. 根据权利要求8-11中任一项所述的SQL语句生成装置,其中,所述预设SQL函数包括select函数、where函数和Groupby函数,所述第一分类模型组包括第一分类模型、第二分类模型、第三分类模型和第四分类模型,所述确定模块还用于:
    将所述目标语义向量输入所述第一分类模型,得到所述select函数的第一字段个数;
    将所述目标语义向量输入所述第二分类模型,得到所述where函数的第二字段个数;
    将所述目标语义向量输入所述第三分类模型,得到所述Groupby函数的第三字段个数;
    将所述目标语义向量输入所述第四分类模型,得到所述连接符的第一分类标签。
  13. 一种服务器,其中,所述服务器包括处理器、存储器、以及存储在所述存储器上并可被所述处理器执行的计算机程序,其中所述计算机程序被所述处理器执行时,实现SQL语句生成方法,所述方法包括:
    获取待回答的目标问题,并获取所述目标问题对应的数据报表;
    根据所述目标问题和所述数据报表中的每个字段,生成N个目标语句片段,每个所述 目标语句片段均包括所述目标问题、至少一个所述字段和至少一个字段标签序列;
    将所述N个目标语句片段输入所述Bert模型,得到每个所述目标语句片段的语义向量和编码向量;
    将每个所述目标语句片段的语义向量输入所述LSTM模型或GRU模型,得到目标语义向量;
    根据每个所述目标语句片段的编码向量,生成所述字段标签序列中的每个字段标签对应的目标编码向量;
    根据所述目标语义向量和所述第一分类模型组中的每个分类模型,确定每个预设SQL函数的字段个数和连接符的第一分类标签;
    根据每个所述目标编码向量和所述第二分类模型组中的每个分类模型,确定所述数据报表中的各字段命中每个预设SQL函数的概率和聚合函数的第二分类标签;
    根据所述各字段命中每个预设SQL函数的概率和每个预设SQL函数的字段个数,确定每个预设SQL函数的目标查询字段;
    根据每个预设SQL函数的目标查询字段、所述连接符的第一分类标签和所述聚合函数的第二分类标签,生成可执行的SQL语句。
  14. 根据权利要求13所述的服务器,其中,所述字段标签序列包括多个不同的字段标签,所述字段标签用于描述所述目标语句片段中的字段是否为预设SQL函数的目标查询字段。
  15. 根据权利要求13所述的服务器,其中,所述目标语句片段的字符个数等于预设字符个数。
  16. 根据权利要求13所述的服务器,其中,所述根据每个所述目标语句片段的编码向量,生成所述字段标签序列中的每个字段标签对应的目标编码向量,包括:
    获取每个所述目标语句片段的编码向量中的各所述字段标签对应的编码子向量;
    将相同所述字段标签对应的编码子向量进行拼接,得到每个所述字段标签对应的目标编码向量。
  17. 根据权利要求13-16中任一项所述的服务器,其中,所述预设SQL函数包括select函数、where函数和Groupby函数,所述第一分类模型组包括第一分类模型、第二分类模型、第三分类模型和第四分类模型,所述根据所述目标语义向量和所述第一分类模型组中的每个分类模型,确定每个预设SQL函数的字段个数和连接符的第一分类标签,包括:
    将所述目标语义向量输入所述第一分类模型,得到所述select函数的第一字段个数;
    将所述目标语义向量输入所述第二分类模型,得到所述where函数的第二字段个数;
    将所述目标语义向量输入所述第三分类模型,得到所述Groupby函数的第三字段个数;
    将所述目标语义向量输入所述第四分类模型,得到所述连接符的第一分类标签。
  18. 根据权利要求17所述的服务器,其中,所述第二分类模型组包括第五分类模型、第六分类模型、第七分类模型和第八分类模型,所述字段标签序列包括第一字段标签、第二字段标签和第三字段标签,所述根据每个所述目标编码向量和所述第二分类模型组中的 每个分类模型,确定所述数据报表中的各字段命中每个预设SQL函数的概率和聚合函数的第二分类标签,包括:
    将所述第一字段标签对应的目标编码向量输入所述第五分类模型,得到所述数据报表中的各字段命中所述select函数的第一概率;
    将所述第二字段标签对应的所述目标编码向量输入所述第六分类模型,得到所述数据报表中的各字段命中所述where函数的第二概率;
    对所述第一字段标签对应的所述目标编码向量和所述第三字段标签对应的所述目标编码向量进行拼接,得到拼接编码向量;
    将所述拼接编码向量输入所述第七分类模型,得到所述数据报表中的各字段命中所述where函数的第三概率;
    将所述第一字段标签对应的目标编码向量输入所述第八分类模型,得到聚合函数的第二分类标签。
  19. 根据权利要求13-16中任一项所述的服务器,其中,所述根据每个预设SQL函数的目标查询字段、所述连接符的第一分类标签和所述聚合函数的第二分类标签,生成可执行的SQL语句,包括:
    根据所述第一分类标签,确定待生成的SQL语句中的目标连接符;
    根据所述第二分类标签,确定待生成的SQL语句中的目标聚合函数;
    根据每个预设SQL函数的目标查询字段、所述目标连接符和所述目标聚合函数,生成可执行的SQL语句。
  20. 一种计算机可读存储介质,其中,所述计算机可读存储介质上存储有计算机程序,其中所述计算机程序被处理器执行时,实现如权利要求1至7中任一项所述的SQL语句生成方法的步骤。
PCT/CN2021/084304 2020-12-31 2021-03-31 Sql语句生成方法、装置、服务器及计算机可读存储介质 WO2022141880A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202011642208.5A CN112732741B (zh) 2020-12-31 2020-12-31 Sql语句生成方法、装置、服务器及计算机可读存储介质
CN202011642208.5 2020-12-31

Publications (1)

Publication Number Publication Date
WO2022141880A1 true WO2022141880A1 (zh) 2022-07-07

Family

ID=75609165

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/084304 WO2022141880A1 (zh) 2020-12-31 2021-03-31 Sql语句生成方法、装置、服务器及计算机可读存储介质

Country Status (2)

Country Link
CN (1) CN112732741B (zh)
WO (1) WO2022141880A1 (zh)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115408506A (zh) * 2022-09-15 2022-11-29 云南大学 联合语义解析和语义成分匹配的nl2sql的方法
CN116629227A (zh) * 2023-07-24 2023-08-22 海信集团控股股份有限公司 一种将文本转换为sql语句的方法及设备
CN116880438A (zh) * 2023-04-03 2023-10-13 材谷金带(佛山)金属复合材料有限公司 退火设备控制***的故障检测方法及***

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113282724B (zh) * 2021-05-21 2024-05-28 北京京东振世信息技术有限公司 一种智能客服的交互方法和装置

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160275148A1 (en) * 2015-03-20 2016-09-22 Huawei Technologies Co., Ltd. Database query method and device
CN109408526A (zh) * 2018-10-12 2019-03-01 平安科技(深圳)有限公司 Sql语句生成方法、装置、计算机设备及存储介质
CN110888897A (zh) * 2019-11-12 2020-03-17 杭州世平信息科技有限公司 一种根据自然语言生成sql语句的方法及装置
CN111414380A (zh) * 2020-03-20 2020-07-14 华泰证券股份有限公司 一种中文数据库sql语句生成方法、设备及存储介质
CN111581229A (zh) * 2020-03-25 2020-08-25 平安科技(深圳)有限公司 Sql语句的生成方法、装置、计算机设备及存储介质

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111177174A (zh) * 2018-11-09 2020-05-19 百度在线网络技术(北京)有限公司 Sql语句的生成方法、装置、设备和计算机可读存储介质

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160275148A1 (en) * 2015-03-20 2016-09-22 Huawei Technologies Co., Ltd. Database query method and device
CN109408526A (zh) * 2018-10-12 2019-03-01 平安科技(深圳)有限公司 Sql语句生成方法、装置、计算机设备及存储介质
CN110888897A (zh) * 2019-11-12 2020-03-17 杭州世平信息科技有限公司 一种根据自然语言生成sql语句的方法及装置
CN111414380A (zh) * 2020-03-20 2020-07-14 华泰证券股份有限公司 一种中文数据库sql语句生成方法、设备及存储介质
CN111581229A (zh) * 2020-03-25 2020-08-25 平安科技(深圳)有限公司 Sql语句的生成方法、装置、计算机设备及存储介质

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115408506A (zh) * 2022-09-15 2022-11-29 云南大学 联合语义解析和语义成分匹配的nl2sql的方法
CN115408506B (zh) * 2022-09-15 2023-09-12 云南大学 联合语义解析和语义成分匹配的nl2sql的方法
CN116880438A (zh) * 2023-04-03 2023-10-13 材谷金带(佛山)金属复合材料有限公司 退火设备控制***的故障检测方法及***
CN116880438B (zh) * 2023-04-03 2024-04-26 材谷金带(佛山)金属复合材料有限公司 退火设备控制***的故障检测方法及***
CN116629227A (zh) * 2023-07-24 2023-08-22 海信集团控股股份有限公司 一种将文本转换为sql语句的方法及设备
CN116629227B (zh) * 2023-07-24 2023-10-24 海信集团控股股份有限公司 一种将文本转换为sql语句的方法及设备

Also Published As

Publication number Publication date
CN112732741B (zh) 2024-06-07
CN112732741A (zh) 2021-04-30

Similar Documents

Publication Publication Date Title
WO2022141880A1 (zh) Sql语句生成方法、装置、服务器及计算机可读存储介质
US10795939B2 (en) Query method and apparatus
WO2022088672A1 (zh) 基于bert的机器阅读理解方法、装置、设备及存储介质
US9846841B1 (en) Predicting object identity using an ensemble of predictors
WO2022142121A1 (zh) 摘要语句提取方法、装置、服务器及计算机可读存储介质
CN111026858B (zh) 基于项目推荐模型的项目信息处理方法及装置
US11244328B2 (en) Discovery of new business openings using web content analysis
US11423314B2 (en) Method and system for facilitating user support using multimodal information
AU2020372605B2 (en) Mapping natural language utterances to operations over a knowledge graph
WO2022088671A1 (zh) 自动问答方法、装置、设备及存储介质
CN112580357A (zh) 自然语言查询的语义解析
WO2023029513A1 (zh) 基于人工智能的搜索意图识别方法、装置、设备及介质
WO2022105493A1 (zh) 基于语义识别的数据查询方法、装置、设备及存储介质
WO2019217150A1 (en) Search system for providing free-text problem-solution searching
CN112925898B (zh) 基于人工智能的问答方法、装置、服务器及存储介质
GB2604736A (en) System and method for classification of unstructured text data
US11688393B2 (en) Machine learning to propose actions in response to natural language questions
CN114175007A (zh) 用于数据匹配的主动学习
CN108959327B (zh) 一种业务处理方法、装置及计算机可读存储介质
CN114742062A (zh) 文本关键词提取处理方法及***
US11244015B1 (en) Projecting queries into a content item embedding space
CN102682073B (zh) 用于搜索引擎检索的原子(atom)的选择
US20230111562A1 (en) Dense retrieval of document templates
AU2022204665B2 (en) Automated search and presentation computing system
US20230099368A1 (en) Conversational user interfaces based on knowledge graphs

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21912650

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21912650

Country of ref document: EP

Kind code of ref document: A1