CN112732741B - SQL sentence generation method, device, server and computer readable storage medium - Google Patents

SQL sentence generation method, device, server and computer readable storage medium Download PDF

Info

Publication number
CN112732741B
CN112732741B CN202011642208.5A CN202011642208A CN112732741B CN 112732741 B CN112732741 B CN 112732741B CN 202011642208 A CN202011642208 A CN 202011642208A CN 112732741 B CN112732741 B CN 112732741B
Authority
CN
China
Prior art keywords
target
field
function
sql
classification model
Prior art date
Legal status (The legal status 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 status listed.)
Active
Application number
CN202011642208.5A
Other languages
Chinese (zh)
Other versions
CN112732741A (en
Inventor
梁子敬
贺春艳
翁志
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Technology Shenzhen Co Ltd
Original Assignee
Ping An Technology Shenzhen Co Ltd
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 Ping An Technology Shenzhen Co Ltd filed Critical Ping An Technology Shenzhen Co Ltd
Priority to CN202011642208.5A priority Critical patent/CN112732741B/en
Priority to PCT/CN2021/084304 priority patent/WO2022141880A1/en
Publication of CN112732741A publication Critical patent/CN112732741A/en
Application granted granted Critical
Publication of CN112732741B publication Critical patent/CN112732741B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

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

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

The application provides an SQL sentence generation method, a device, a server and a computer readable storage medium, wherein the method comprises the following steps: acquiring a data report corresponding to a target problem; generating N target statement fragments according to the target problems and the data report; inputting N target sentence fragments into a Bert model to obtain semantic vectors and coding vectors of each target sentence fragment; generating a target coding vector corresponding to each field label according to each coding vector; determining the number of fields of a preset SQL function and a first classification label according to the target semantic vector and the first classification model group; determining the probability of each field hitting a preset SQL function and a second classification label according to each target coding vector and the second classification model group; determining a target query field of a preset SQL function; executable SQL statements are generated. The method improves the generation accuracy of SQL sentences. The present application also relates to the field of blockchain, and the computer readable storage medium described above may store data created from the use of blockchain nodes.

Description

SQL sentence generation method, device, server and computer readable storage medium
Technical Field
The present application relates to the field of semantic analysis technologies, and in particular, to a method and apparatus for generating an SQL statement, a server, and a computer readable storage medium.
Background
With the rapid development of network and internet technologies, more and more enterprises begin to use robot customer service to provide services for users, mainly user input questions, and robot clients answer the questions input by the users. Currently, a natural language to SQL statement (Natural Language to SQL, NL2 SQL) task is mainly used to convert a question input by a user into an executable SQL statement, and then the SQL statement is executed by a computer to obtain an answer to the question, and the answer is output to the user. However, NL2SQL tasks are mainly implemented through semantic recognition models and multi-classification tasks, but executable SQL statements corresponding to problems cannot be accurately determined only through the semantic recognition models and the multi-classification tasks. Therefore, how to improve the generation accuracy of executable SQL sentences is a problem to be solved at present.
Disclosure of Invention
The embodiment of the application provides a method, a device, a server and a computer-readable storage medium for generating SQL sentences, aiming at improving the generation accuracy of executable SQL sentences.
In a first aspect, an embodiment of the present application provides an SQL statement generation method, applied to a server, where the server stores an SQL statement generation model, where the SQL statement generation model includes a pretrained Bert model, a pretrained LSTM model or a GRU model, a pretrained first classification model group, and a second classification model group, and the method includes:
Acquiring a target question to be answered, and acquiring a data report corresponding to the target question;
generating N target statement fragments according to the target questions and each field in the data report, wherein each target statement fragment comprises the target questions, at least one field and at least one field tag sequence;
Inputting the N target sentence fragments into the Bert model to obtain semantic vectors and coding vectors of each target sentence fragment;
Inputting the semantic vector of each target sentence fragment into the LSTM model or the GRU model to obtain a target semantic vector;
Generating a target coding vector corresponding to each field tag in the field tag sequence according to the coding vector of each target statement fragment;
Determining the number of fields of each preset SQL function and a first classification label of a connector according to the target semantic vector and each classification model in the first classification model group;
determining the probability of each field in the data report hitting each preset SQL function and the second classification label of the aggregation function according to each target coding vector and each classification model in the second classification model group;
Determining a target query field of each preset SQL function according to the probability of hit of each preset SQL function in each field and the number of fields of each preset SQL function;
and generating executable SQL sentences 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.
In a second aspect, an embodiment of the present application further provides an SQL statement generation apparatus, applied to a server, where the server stores an SQL statement generation model, where the SQL statement generation model includes a pretrained Bert model, a pretrained LSTM model or a GRU model, a pretrained first classification model group, and a second classification model group, and the SQL statement generation apparatus includes:
the acquisition module is used for acquiring target questions to be answered and acquiring data reports corresponding to the target questions;
the statement fragment generation module is used for generating N target statement fragments according to the target questions and each field in the data report, wherein each target statement fragment comprises the target questions, at least one field and at least one field tag sequence;
The control module is used for inputting the N target sentence fragments into the Bert model to obtain a semantic vector and a coding vector of each target sentence fragment;
The control module is used for inputting the semantic vector of each target statement fragment into the LSTM model or the GRU model to obtain a target semantic vector;
The vector generation module is used for generating a target coding vector corresponding to each field tag in the field tag sequence according to the coding vector of each target statement fragment;
the determining module 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;
The determining module is further configured to determine, according to each target encoding vector and each classification model in the second classification model group, a probability that each field in the data report hits each preset SQL function and a second classification label of an aggregation function;
the determining module is further configured to determine a 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;
And the SQL sentence generating module is used for generating executable SQL sentences 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.
In a third aspect, an embodiment of the present application further provides a server, where the server includes a processor, a memory, and a computer program stored on the memory and executable by the processor, where the computer program, when executed by the processor, implements the steps of the SQL statement generation method described above.
In a fourth aspect, embodiments of the present application also provide a computer readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the SQL statement generation method described above.
The embodiment of the application provides an SQL sentence generating method, device, server and computer readable storage medium, which are characterized in that N target sentence fragments are generated by acquiring a data report corresponding to a target problem and according to each field in the target problem and the data report, then the N target sentence fragments are input into a Bert model to obtain semantic vectors and coding vectors of each target sentence fragment, the semantic vectors of each target sentence fragment are input into an LSTM model or a GRU model to obtain target semantic vectors, meanwhile, according to the coding vectors of each target sentence fragment, target coding vectors corresponding to each field label in a field label sequence are generated, then according to the target semantic vectors and each classification model in a first classification model group, the number of fields of each preset SQL function and the first classification label of a connector are determined, according to each target coding vector and each classification model in a second classification model group, the probability of each preset SQL function and the second classification label of an aggregation function are determined, finally according to the probability of each field hit each preset SQL function and the probability of each preset SQL function and the second classification label of each preset SQL function, the SQL function can be accurately executed, and the query can be accurately and the query can be generated according to the first classification labels of the preset fields and the SQL labels.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for the description of the embodiments will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present application, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flow chart of an SQL statement generation method according to an embodiment of the application;
FIG. 2 is a schematic diagram of a scenario for generating a target sentence fragment according to an embodiment of the present application;
FIG. 3 is a schematic diagram of a SQL statement generation model according to an embodiment of the application;
FIG. 4 is a schematic block diagram of an SQL statement generating device according to an embodiment of the application;
FIG. 5 is a schematic block diagram of a sub-module of the SQL statement generation device in FIG. 4;
Fig. 6 is a schematic block diagram of a server according to an embodiment of the present application.
The achievement of the objects, functional features and advantages of the present application will be further described with reference to the accompanying drawings, in conjunction with the embodiments.
Detailed Description
The following description of the embodiments of the present application will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are some, but not all embodiments of the application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
The flow diagrams depicted in the figures are merely illustrative and not necessarily all of the elements and operations/steps are included or performed in the order described. For example, some operations/steps may be further divided, combined, or partially combined, so that the order of actual execution may be changed according to actual situations.
With the rapid development of network and internet technologies, more and more enterprises begin to use robot customer service to provide services for users, mainly user input questions, and robot clients answer the questions input by the users. Currently, a natural language to SQL statement (Natural Language to SQL, NL2 SQL) task is mainly used to convert a question input by a user into an executable SQL statement, and then the SQL statement is executed by a computer to obtain an answer to the question, and the answer is output to the user. However, NL2SQL tasks are mainly implemented through semantic recognition models and multi-classification tasks, but executable SQL statements corresponding to problems cannot be accurately determined only through the semantic recognition models and the multi-classification tasks. Therefore, how to improve the generation accuracy of executable SQL sentences is a problem to be solved at present.
In order to solve the above problems, embodiments of the present application provide a method, an apparatus, a server, and a computer readable storage medium for generating an SQL statement. The method comprises the steps of obtaining a data report corresponding to a target problem, generating N target statement fragments according to the target problem and each field in the data report, inputting the N target statement fragments into a Bert model to obtain semantic vectors and encoding vectors of each target statement fragment, inputting the semantic vectors of each target statement fragment into an LSTM model or a GRU model to obtain target semantic vectors, simultaneously generating target encoding vectors corresponding to each field tag in a field tag sequence according to the encoding vectors of each target statement fragment, then determining the number of fields of each preset SQL function and a first classification tag of a connector according to the target semantic vectors and each classification model in a first classification model group, determining the probability of each field in the data report hitting each preset SQL function and a second classification tag of an aggregation function according to the probability of each field hitting each preset SQL function and the field of each preset SQL function, determining the target query field of each preset SQL function according to the target semantic vectors of each preset SQL function, determining the number of the target query field of each preset SQL function according to each classification model of each preset SQL function, and executing the first classification tag of each preset SQL function according to each classification model in the target statement group, and generating the first classification tag of the SQL function, and improving the accuracy.
Some embodiments of the present application are described in detail below with reference to the accompanying drawings. The following embodiments and features of the embodiments may be combined with each other without conflict.
Referring to fig. 1, fig. 1 is a flowchart illustrating a method for generating an SQL statement according to an embodiment of the application.
As shown in fig. 1, the SQL statement generation method includes steps S101 to S109.
Step S101, obtaining a target question to be answered, and obtaining a data report corresponding to the target question.
The server stores a plurality of data reports, different problems can relate to different data reports, one problem can relate to only one data report, one problem can relate to a plurality of different data reports, each data report table comprises a plurality of fields, the fields can be column fields in the data report or row fields in the data report, and the embodiment of the application is not limited in particular.
In an embodiment, a server obtains a data query request sent by a terminal device, wherein the data query request comprises a target problem input by a user through the terminal device; analyzing the data query request to obtain a target problem in the data query request; splitting the target problem into a plurality of keywords, matching each keyword in the plurality of keywords with each field in each data report, and determining the data report with at least one keyword in each field as the data report corresponding to the target problem.
For example, the target problem is "by 11 months of 2020, 10 days of 11 months of 11, the yield and total yield of the self-selected fund product" and then the target problem is split into "by 11 months of 2020, 10 days of 11 months of 11, the yield and total yield of the self-selected fund product" and the keywords "self-selected fund product", "yield" and "total yield" can be obtained, and then the data report corresponding to the target problem is searched through the keywords.
And S102, generating N target statement fragments according to the target questions and each field in the data report.
Exemplary, a field sequence corresponding to the data report is obtained, and a field tag sequence is inserted into the head position of each field in the field sequence to obtain a target field sequence; splitting the target field sequence into N field subsequences, so that the sum of the number of the first characters corresponding to each field subsequence and the number of the second characters of the target problem is smaller than or equal to the number of preset characters; and splicing the target problem with each field subsequence to obtain N initial sentence fragments, and performing character filling on the N initial sentence fragments to obtain N target sentence fragments. Wherein N is a positive integer, the number of characters in each target sentence fragment is equal to the number of preset characters, and the number of preset characters can be set based on practical situations, and the embodiment of the application is not limited in particular, for example, the number of preset characters is 256 or 128.
Each target statement fragment comprises a target question, at least one field and at least one field tag sequence, the number of the field tag sequences in the target statement fragments is matched with the number of the fields in the target statement fragments, the field tag sequences comprise a plurality of different field tags, the field tags are used for describing whether the fields in the target statement fragments are target query fields of a preset SQL function, the preset SQL function comprises a select function, a where function and a Groupby function, the field tag sequences comprise a first field tag, a second field tag and a third field tag, the first field tag is used for describing whether the fields in the target statement fragments are target query fields of the select function, the second field tag is used for describing whether the fields in the target statement fragments are target query fields of the where function, and the third field tag is used for describing whether the fields in the target statement fragments are target query fields of the Groupby function.
As shown in fig. 2, the field sequence 10 corresponding to the data report includes M fields, and a field tag sequence [ label, label2, label3] is inserted at the head position of each field in the field sequence 10 to obtain a target field sequence 20, where label is used to describe whether the field is a target query field of a select function, label2 is used to describe whether the field is a target query field of a sphere function, and label3 is used to describe whether the field is a target query field of a Groupby function. Then the target field sequence 20 is split into N field sub-sequences, the N field sub-sequences form a field sub-sequence group 30, the target question is spliced with each field sub-sequence in the field sub-sequence group 30 to obtain N initial sentence fragments, the N initial sentence fragments form an initial sentence fragment group 40, and finally the N initial sentence fragments are character-filled to obtain N target sentence fragments.
And step S103, inputting the N target sentence fragments into the Bert model to obtain the semantic vector and the coding vector of each target sentence fragment.
The server stores an SQL statement generating model, the SQL statement generating model comprises a pre-trained Bert model, a pre-trained LSTM model or GRU model, a pre-trained first classification model set and a pre-trained second classification model set, as shown in fig. 3, 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 set 11, the Bert model is further connected with the second classification model set 12, the first classification model set 11 comprises a first classification model, a second classification model, a third classification model and a fourth classification model, the first classification model is used for determining the first field number of a select function, the second classification model is used for determining the second field number of a where function is used for determining the third field number of a Groupby function, the fourth classification model is used for determining the first classification label of a connector, the second classification model set 12 comprises a fifth classification model, a sixth classification model, a seventh classification model and an eighth classification model, the fifth classification model is used for determining the probability of each of a select function in a data report, and the probability of each of a select function in a report model is used for determining the probability of each field of a candidate function in a report, and the probability of each classification model is used for determining the probability of each of a candidate function in a classification function is used for determining the probability of a field of a probability of a candidate function.
The SQL sentence generating model can be obtained by performing iterative training on the Bert model, the LSTM model, the first classification model group and the second classification model group together, or by performing iterative training on the Bert model, the GRU model, the first classification model group and the second classification model group together. The specific training process can be as follows: and acquiring a sample data set, and carrying out iterative training on the Bert model, the LSTM model, the first classification model group and the second classification model group according to sample data in the sample data set until the Bert model, the LSTM model, the first classification model group and the second classification model are converged to obtain an SQL sentence generation model.
In one embodiment, determining the position of each character in each target sentence fragment in a preset dictionary; coding the characters in each target sentence fragment according to the positions of the characters in each target sentence fragment in a preset dictionary to obtain a character vector sequence of each target sentence fragment; and inputting the character vector sequence of each target sentence fragment into a Bert model to obtain the semantic vector and the coding vector of each target sentence fragment. The preset dictionary is not particularly limited in this aspect, and a character vector corresponding to a character can be obtained through the position of the character in the preset dictionary and the mapping relationship between the position and the character vector, and then a character vector sequence of the target sentence fragment is formed based on the character vector of each character.
And step S104, inputting the semantic vector of each target statement fragment into the LSTM model or the GRU model to obtain a target semantic vector.
And splicing the semantic vectors of each target sentence fragment to obtain a semantic vector sequence, and inputting the semantic vector sequence into an LSTM model or a GRU model to obtain a target semantic vector.
Step 105, generating a target coding vector corresponding to each field tag in the field tag sequence according to the coding vector of each target statement fragment.
Illustratively, obtaining a coding sub-vector corresponding to each field tag in the coding vector of each target sentence fragment; and splicing the code sub-vectors corresponding to the same field labels to obtain the target code vector corresponding to each field label. For example, the field tag sequence is [ label, label2, label3], for each target sentence fragment, the coding sub-vector corresponding to the field tag label of each field, the coding sub-vector corresponding to the field tag label2, and the coding sub-vector corresponding to the field tag label3 are obtained from the coding vector of the target sentence fragment, all the coding sub-vectors corresponding to the field tag label are spliced to obtain the target coding vector corresponding to the field tag label, all the coding sub-vectors corresponding to the field tag labe are spliced to obtain the target coding vector corresponding to the field tag labe, and all the coding sub-vectors corresponding to the field tag labe are spliced to obtain the target coding vector corresponding to the field tag labe 3.
And S106, 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 preset SQL function comprises a select function, a where function and Groupby functions, the first classification model group comprises a first classification model, a second classification model, a third classification model and a fourth classification model, the first classification model is used for determining the first field number of the select function, the second classification model is used for determining the second field number of the where function, the third classification model is used for determining the third field number of the Groupby functions, and the fourth classification model is used for determining the first classification label of the connector.
In one embodiment, the target semantic vector is input into a first classification model to obtain a first field number of the select function; inputting the target semantic vector into a second classification model to obtain the number of second fields of the where function; inputting the target semantic vector into a third classification model to obtain the third field number of Groupby functions; and inputting the target semantic vector into a 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 can be five classification models, so that the number of fields output by the first classification model, the second classification model and the third classification model can be 0, 1, 2, 3 and 4, the fourth classification model is three classification models, and therefore, the first classification label output by the fourth classification model comprises a first connector label, a second connector label and a third connector label, the fourth classification model outputs the first connector label and indicates that an 'and' connector is selected, the fourth classification model outputs the second connector label and indicates that an 'or' connector is selected, and the fourth classification model outputs the third connector label and indicates that no connector is selected.
The first classification model comprises a first full connection layer and a first Softmax model, the second classification model comprises a second full connection layer and a second Softmax model, the third classification model comprises a third full connection layer and a third Softmax model, and the fourth classification model comprises a fourth full connection layer and a fourth Softmax model, so that the target semantic vector is input into the first full connection layer for processing, the processed target semantic vector is input into the first Softmax model for processing, and the first field number of the select function is obtained; inputting the target semantic vector into a second full-connection layer for processing, and inputting the processed target semantic vector into a second Softmax model for processing to obtain the second field number of the sphere function; inputting the target semantic vector into a third full connection layer for processing, and inputting the processed target semantic vector into a third Softmax model for processing to obtain the third field number of Groupby functions; and inputting the target semantic vector into a fourth full connection layer for processing, and inputting the processed target semantic vector into a fourth Softmax model for processing to obtain the first classification label of the connector.
For example, assuming the target semantic vector is hidden sql, the first field number of the select function may be determined by the characterization formula softmax (w s*hiddensql+bs) of the first classification model, the second field number of the where function may be determined by the characterization formula softmax (w w*hiddensql+bw) of the second classification model, the third field number of the Groupby function may be determined by the characterization formula softmax (w g*hiddensql+bg) of the third classification model, the first classification tag of the connector may be determined by the characterization formula softmax (w c*hiddensql+bc) of the fourth classification model, where w s and b s are model parameters of the first fully connected layer, w w and b w are model parameters of the second fully connected layer, w g and b g are model parameters of the third fully connected layer, and w c and b c are model parameters of the fourth fully connected layer.
The first, second and third Softmax models are five-class Softmax models, the number of fields of the five-class Softmax model is five, the number of fields is 0, 1, 2, 3 and 4, the first class label of the connector output by the three-class Softmax model comprises a first connector label, a second connector label and a third connector label, the fourth class model outputs the first connector label and then indicates that an 'and' connector is selected, the fourth class model outputs the second connector label and then indicates that an 'or' connector is selected, and the fourth class model outputs the third connector label and then indicates that a connector is not selected.
And step S107, determining the probability of each field in the data report hitting each preset SQL function and the second classification label of the aggregation function according to each target coding vector and each classification model in the second classification model group.
The second classification model group comprises a fifth classification model, a sixth classification model, a seventh classification model and an eighth classification model, the field tag sequence comprises a first field tag, a second field tag and a third field tag, the fifth classification model is used for determining the probability of each field in the data report to hit a select function, the sixth classification model is used for determining the probability of each field in the data report to hit a sphere function, the seventh classification model is used for determining the probability of each field in the data report to hit a Groupby function, and the eighth classification model is used for determining the second classification tag of the aggregation function.
In one embodiment, inputting a target coding vector corresponding to the first field label into a fifth classification model to obtain a first probability of each field in the data report to hit a select function; inputting the target coding vector corresponding to the second field label into the sixth classification model to obtain a second probability of each field hit in the data report; splicing the target coding vector corresponding to the first field label and the target coding vector corresponding to the third field label to obtain a spliced coding vector; inputting the spliced encoding vector into a seventh classification model to obtain a third probability of each field hit Groupby function in the data report; and inputting the target coding vector corresponding to the first field label into an eighth classification model to obtain a second classification label of the aggregation function. The aggregation functions comprise Min functions, max functions, avg functions, count functions and Sum functions.
The fifth classification model includes a fifth full-connection layer and a fifth Softmax model, the sixth classification model includes a sixth full-connection layer and a sixth Softmax model, the seventh classification model includes a seventh full-connection layer and a seventh Softmax model, and the eighth classification model includes an eighth full-connection layer and an eighth Softmax model, so that the target coding vector corresponding to the first field label is input into the fifth full-connection layer for processing, the processed target coding vector is input into the fifth Softmax model, and the first probability of each field hit selection function in the data report is obtained; inputting the target coding vector corresponding to the second field label into a sixth full-connection layer for processing, and inputting the processed target coding vector into a sixth Softmax model to obtain a second probability of each field hit in the data report; inputting the spliced encoding vector into a seventh full connection layer for processing, and inputting the processed spliced encoding vector into a seventh Softmax model to obtain a third probability of each field hit Groupby function in the data report; and inputting the target coding vector corresponding to the first field label into an eighth full-connection layer, and inputting the processed target coding vector into an eighth Softmax model to obtain a second classification label of the aggregation function.
For example, assuming that the target encoding vector corresponding to the first field tag is hidden sc, the target encoding vector corresponding to the second field tag is hidden wc, the target encoding vector corresponding to the third field tag is hidden gc, the first probability of each field hit selecting function in the data report may be determined by the characterization formula softmax (w sc*hiddensc+bsc) of the fifth classification model, the first probability of each field hit hitting function in the data report may be determined by the characterization formula softmax (w wc*hiddenwc+bwc) of the sixth classification model, the third probability of each field hit Groupby function in the data report may be determined by the characterization formula softmax (w gc*cat(hiddensc,hiddengc)+bgc) of the seventh classification model, the characterization formula softmax (w ac*hiddensc+bac) of the eighth classification model, wherein w sc and b sc are model parameters of the fifth fully connected layer, w wc and b wc are model parameters of the sixth fully connected layer, w gc and b gc are model parameters of the seventh fully connected layer, and w ac is a fully connected layer.
The fifth Softmax model, the sixth Softmax model, the seventh Softmax model and the eighth Softmax model are all multi-class Softmax models, for example, the eighth Softmax model is a six-class Softmax model, the second class label output by the eighth class model comprises a first label, a second label, a third label, a fourth label, a fifth label and a sixth label, the second class label output by the eighth class model is the first label, the selected aggregation function is represented as a "Min function", the second class label output by the eighth class model is the second label, the selected aggregation function is represented as a "Max function", the second class label output by the eighth class model is the third label, the selected aggregation function is represented as an "Avg function", the second class label output by the eighth class model is the fourth label, the selected aggregation function is represented as a "count function", the second class label output by the eighth class model is represented as a fifth label, the selected aggregation function is represented as a "Sum function", and the eighth class label is not represented as a "Sum function".
Step S108, determining the target query field of each preset SQL function according to the probability of each field hitting each preset SQL function and the number of the fields of each preset SQL function.
Illustratively, according to the first probability that each field in the data report hits the select function and the first field number of the select function, determining the target query field of the select function from each field, that is, according to the order of magnitude of the first probability that each field in the data report hits the select function, ordering each field to obtain a first field queue, and sequentially selecting the target query field of the select function from the first field queue from the first field of the first field queue until the number of the selected target query fields reaches the first field number. For example, the first field number is 2, and the first 2 fields are selected from the first field queue as the target query fields of the select function.
Similarly, according to the second probability of each field hit of the sphere function and the second field number of the sphere function in the data report, determining the target query field of the sphere function from the fields, namely, according to the size sequence of the second probability of each field hit of the sphere function in the data report, sequencing the fields to obtain a second field queue, and sequentially selecting the target query field of the sphere function from the second field queue from the first field of the second field queue until the number of the selected target query fields reaches the second field number. For example, if the number of the second fields is 1, the first field is selected from the second field queue as the target query field of the where function.
Similarly, according to the third probability of each field hit Groupby in the data report and the third field number of the Groupby function, determining the target query field of the Groupby function from each field, namely, according to the order of magnitude of the third probability of each field hit Groupby in the data report, ordering each field to obtain a third field queue, starting from the first field of the third field queue, sequentially selecting the target query field of the Groupby function from the third field queue until the number of the selected target query fields reaches the third field number. For example, if the number of the third fields is 1, the first field is selected from the third field queue as the target query field of Groupby functions.
Step S109, 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, an executable SQL sentence is generated.
Illustratively, determining a target connector in the SQL sentence to be generated according to the first classification tag; determining a target aggregation function in the SQL sentence to be generated according to the second classification label; and generating executable SQL sentences according to the target query field, the target connector and the target aggregation function of each preset SQL function. Wherein the target connector comprises and/or, and the target aggregation function comprises Min function, max function, avg function, count function and/or Sum function.
It is understood that there may or may not be an aggregation function and/or a connector in the SQL statement, and that the SQL statement may include only select functions, only select functions and where functions, only select functions and Groupby functions, and only select functions, where functions and Groupby functions. The embodiment of the present application is not particularly limited thereto.
According to the SQL sentence generation method provided by the embodiment, N target sentence fragments are generated according to the target problems and each field in the data report, then the N target sentence fragments are input into the Bert model to obtain semantic vectors and coding vectors of each target sentence fragment, the semantic vectors of each target sentence fragment are input into the LSTM model or the GRU model to obtain target semantic vectors, meanwhile, according to the coding vectors of each target sentence fragment, the target coding vectors corresponding to each field label in the field label sequence are generated, then according to the target semantic vectors and each classification model in the first classification model group, the field number of each preset SQL function and the first classification label of a connector are determined, according to each target coding vector and each classification model in the second classification model group, the probability of each preset SQL function in the data report and the second classification label of the aggregation function are determined, finally, according to the probability of each preset SQL function and the field number of each preset SQL function, the target sentence is determined, and the second classification label of each preset SQL function is executed, and the query can be accurately classified according to the aggregate field labels, and the query can be accurately generated.
Referring to fig. 4, fig. 4 is a schematic block diagram of an SQL statement generation device according to an embodiment of the application.
The SQL sentence generating device is applied to a server, wherein the server stores an SQL sentence generating model, and the SQL sentence generating model comprises a pretrained Bert model, a pretrained LSTM model or GRU model, a pretrained first classification model group and a pretrained second classification model group.
As shown in fig. 4, the SQL statement generation apparatus 200 includes: an acquisition module 210, a statement fragment 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 acquiring module 210 is configured to acquire a target question to be answered, and acquire a data report corresponding to the target question;
The statement fragment generation module 220 is configured to generate N target statement fragments according to the target question and each field in the data report, where each target statement fragment includes the target question, at least one field, and at least one field tag sequence;
the control module 230 is configured to input the N target sentence fragments into the Bert model, to obtain a semantic vector and a coding vector of each target sentence fragment;
The control module 230 is configured to input a semantic vector of each of the target sentence fragments into the LSTM model or the GRU model to obtain a target semantic vector;
The vector generation module 240 is configured to generate a target encoding vector corresponding to each field tag in the field tag sequence according to the encoding vector of each target sentence fragment;
the determining module 250 is configured to determine, according to the target semantic vector and each classification model in the first classification model set, a first classification label of a connector and a number of fields of each preset SQL function;
The determining module 250 is further configured to determine, according to each target encoding vector and each classification model in the second classification model set, a probability that each field in the data report hits each preset SQL function and a second classification label of an aggregation function;
The determining module 250 is further configured to determine a 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 class label of the connector, and the second class label of the aggregation function.
In an embodiment, the field tag sequence includes a plurality of different field tags, where the field tags are used to describe whether a field in the target statement fragment is a target query field of a preset SQL function.
In one embodiment, the number of characters of the target sentence fragment is equal to a preset number of characters.
In one embodiment, as shown in fig. 5, the vector generation module 240 includes:
an obtaining sub-module 241, configured to obtain a coding sub-vector corresponding to each field tag in the coding vector of each target sentence fragment;
and the splicing sub-module 242 is configured to splice the encoded sub-vectors corresponding to the same field tag to obtain a target encoded vector corresponding to each field tag.
In one embodiment, 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, and the determination module 250 is further configured to:
inputting the target semantic vector into the first classification model to obtain the first field number of the select function;
Inputting the target semantic vector into the second classification model to obtain the second field number of the where function;
inputting the target semantic vector into the third classification model to obtain the third field number of the Groupby functions;
and inputting the target semantic vector into the fourth classification model to obtain a first classification label of the connector.
In an embodiment, 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 tag sequence includes a first field tag, a second field tag, and a third field tag, and the determining module 250 is further configured to:
Inputting the target coding vector corresponding to the first field label into the fifth classification model to obtain a first probability of each field in the data report to hit the select function;
inputting the target coding vector corresponding to the second field label into the sixth classification model to obtain a second probability of each field in the data report to hit the sphere function;
Splicing the target coding vector corresponding to the first field tag and the target coding vector corresponding to the third field tag to obtain a spliced coding vector;
inputting the spliced encoding vector into the seventh classification model to obtain a third probability of each field in the data report hitting the sphere function;
And inputting the target coding vector corresponding to the first field label into the eighth classification model to obtain a second classification label of the aggregation function.
In one embodiment, the SQL statement generation module 260 is further configured to:
determining a target connector in the SQL sentence to be generated according to the first classification label;
Determining a target aggregation function in the SQL sentence to be generated according to the second classification label;
And generating executable SQL sentences according to the target query field, the target connector and the target aggregation function of each preset SQL function.
It should be noted that, for convenience and brevity of description, specific working processes of the above-described apparatus and modules and units may refer to corresponding processes in the foregoing SQL statement generation method embodiment, and are not described herein again.
The apparatus provided by the above embodiments may be implemented in the form of a computer program which may be run on a server as shown in fig. 6.
Referring to fig. 6, fig. 6 is a schematic block diagram of a server according to an embodiment of the present application.
As shown in fig. 6, the server includes a processor, a memory, and a network interface connected through a system bus, where the memory may include a storage medium and an internal memory, and the memory is configured to store an SQL statement generation model, where the SQL statement generation model includes a pretrained Bert model, a pretrained LSTM model or a GRU model, a pretrained 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 comprises program instructions that, when executed, cause the processor to perform any one of the SQL statement generation methods.
The processor is used to provide computing and control capabilities, supporting the operation of the entire server.
The internal memory provides an environment for the execution of a computer program in a storage medium that, when executed by a processor, causes the processor to perform any one of the SQL statement generation methods.
The network interface is used for network communication such as transmitting assigned tasks and the like. It will be appreciated by those skilled in the art that the structure shown in fig. 6 is merely a block diagram of a portion of the structure associated with the present inventive arrangements and is not limiting of the server to which the present inventive arrangements are applied, and that a particular server may include more or fewer components than shown, or may combine some of the components, or have a different arrangement of components.
It should be appreciated that the Processor may be a central processing unit (Central Processing Unit, CPU), it may also be other general purpose processors, digital signal processors (DIGITAL SIGNAL Processor, DSP), application SPECIFIC INTEGRATED Circuit (ASIC), field-Programmable gate array (Field-Programmable GATE ARRAY, FPGA) or other Programmable logic device, discrete gate or transistor logic device, discrete hardware components, or the like. Wherein the general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
Wherein, in an embodiment, the processor is configured to execute a computer program stored in the memory to implement the steps of:
Acquiring a target question to be answered, and acquiring a data report corresponding to the target question;
generating N target statement fragments according to the target questions and each field in the data report, wherein each target statement fragment comprises the target questions, at least one field and at least one field tag sequence;
Inputting the N target sentence fragments into the Bert model to obtain semantic vectors and coding vectors of each target sentence fragment;
Inputting the semantic vector of each target sentence fragment into the LSTM model or the GRU model to obtain a target semantic vector;
Generating a target coding vector corresponding to each field tag in the field tag sequence according to the coding vector of each target statement fragment;
Determining the number of fields of each preset SQL function and a first classification label of a connector according to the target semantic vector and each classification model in the first classification model group;
determining the probability of each field in the data report hitting each preset SQL function and the second classification label of the aggregation function according to each target coding vector and each classification model in the second classification model group;
Determining a target query field of each preset SQL function according to the probability of hit of each preset SQL function in each field and the number of fields of each preset SQL function;
and generating executable SQL sentences 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.
In an embodiment, the field tag sequence includes a plurality of different field tags, where the field tags are used to describe whether a field in the target statement fragment is a target query field of a preset SQL function.
In one embodiment, the number of characters of the target sentence fragment is equal to a preset number of characters.
In an embodiment, when implementing the generation of the target encoding vector corresponding to each field tag in the field tag sequence according to the encoding vector of each target statement fragment, the processor is configured to implement:
Acquiring coding sub-vectors corresponding to the field labels in the coding vectors of each target statement fragment;
And splicing the code sub-vectors corresponding to the same field labels to obtain the target code vector corresponding to each field label.
In an embodiment, the preset SQL functions include a select function, a where function, and a Groupby function, and the first classification model group includes a first classification model, a second classification model, a third classification model, and a fourth classification model, and the processor, when implementing determining, according to the target semantic vector and each classification model in the first classification model group, a first classification label for each field number and a connector of the preset SQL functions, is configured to implement:
inputting the target semantic vector into the first classification model to obtain the first field number of the select function;
Inputting the target semantic vector into the second classification model to obtain the second field number of the where function;
inputting the target semantic vector into the third classification model to obtain the third field number of the Groupby functions;
and inputting the target semantic vector into the fourth classification model to obtain a first classification label of the connector.
In an embodiment, the second classification model group includes a fifth classification model, a sixth classification model, a seventh classification model, and an eighth classification model, the sequence of field tags includes a first field tag, a second field tag, and a third field tag, and the processor is configured to, when implementing determining, according to each of the target coding vector and each classification model in the second classification model group, a probability that each field in the data report hits each preset SQL function and a second classification tag of an aggregate function, implement:
Inputting the target coding vector corresponding to the first field label into the fifth classification model to obtain a first probability of each field in the data report to hit the select function;
inputting the target coding vector corresponding to the second field label into the sixth classification model to obtain a second probability of each field in the data report to hit the sphere function;
Splicing the target coding vector corresponding to the first field tag and the target coding vector corresponding to the third field tag to obtain a spliced coding vector;
inputting the spliced encoding vector into the seventh classification model to obtain a third probability of each field in the data report hitting the sphere function;
And inputting the target coding vector corresponding to the first field label into the eighth classification model to obtain a second classification label of the aggregation function.
In an embodiment, the processor is configured to, when implementing generating the executable SQL statement according to the target query field of each preset SQL function, the first class label of the connector, and the second class label of the aggregation function, implement:
determining a target connector in the SQL sentence to be generated according to the first classification label;
Determining a target aggregation function in the SQL sentence to be generated according to the second classification label;
And generating executable SQL sentences according to the target query field, the target connector and the target aggregation function of each preset SQL function.
It should be noted that, for convenience and brevity of description, a specific working process of the server described above may refer to a corresponding process in the foregoing SQL statement generation method embodiment, which is not described herein again.
From the above description of embodiments, it will be apparent to those skilled in the art that the present application may be implemented in software plus a necessary general hardware platform. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art in the form of a software product, which may be stored in a storage medium, such as a ROM/RAM, a magnetic disk, an optical disk, etc., including several instructions for causing a server (which may be a personal computer, a server, or a network server, etc.) to perform the method described in the embodiments or some parts of the embodiments of the present application.
Embodiments of the present application further provide a computer readable storage medium, where a computer program is stored, where the computer program includes program instructions, and a method implemented when the program instructions are executed may refer to various embodiments of the SQL statement generation method of the present application.
Wherein the computer readable storage medium may be volatile or nonvolatile. The computer readable storage medium may be an internal storage unit of the server according to the foregoing embodiment, for example, 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 (SD) card, a flash memory card (FLASH CARD), or the like, which are provided on the server.
Further, 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 for at least one function, and the like; the storage data area may store data created from the use of blockchain nodes, and the like.
The blockchain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, encryption algorithm and the like. The blockchain (Blockchain), essentially a de-centralized database, is a string of data blocks that are generated in association using cryptographic methods, each of which contains information from a batch of network transactions for verifying the validity (anti-counterfeit) of its information and generating the next block. The blockchain may include a blockchain underlying platform, a platform product services layer, an application services layer, and the like.
It is to be understood that the terminology used in the description of the application herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in this specification and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should also be understood that the term "and/or" as used in the present specification and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes such combinations. It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The foregoing embodiment numbers of the present application are merely for the purpose of description, and do not represent the advantages or disadvantages of the embodiments. While the application has been described with reference to certain preferred embodiments, it will be understood by those skilled in the art that various changes and substitutions of equivalents may be made and equivalents will be apparent to those skilled in the art without departing from the scope of the application. Therefore, the protection scope of the application is subject to the protection scope of the claims.

Claims (10)

1. The SQL sentence generation method is characterized by being applied to a server, wherein the server stores an SQL sentence generation model, the SQL sentence generation model comprises a pretrained Bert model, a pretrained LSTM model or GRU model, a pretrained first classification model group and a pretrained second classification model group, and the method comprises the following steps:
Acquiring a target question to be answered, and acquiring a data report corresponding to the target question;
Generating N target sentence fragments according to the target question and each field in the data report, wherein each target sentence fragment comprises the target question, at least one field and at least one field tag sequence, and generating N target sentence fragments according to the target question and each field in the data report comprises: acquiring a field sequence corresponding to the data report, and inserting a field tag sequence into the head position of each field in the field sequence to obtain a target field sequence; splitting the target field sequence into N field subsequences, so that the sum of the number of the first characters corresponding to each field subsequence and the number of the second characters of the target problem is smaller than or equal to the preset number of characters; splicing the target problem with each field subsequence to obtain N initial sentence fragments, and character filling the N initial sentence fragments to obtain N target sentence fragments, wherein N is a positive integer;
Inputting the N target sentence fragments into the Bert model to obtain semantic vectors and coding vectors of each target sentence fragment;
Inputting the semantic vector of each target sentence fragment into the LSTM model or the GRU model to obtain a target semantic vector;
Generating a target coding vector corresponding to each field tag in the field tag sequence according to the coding vector of each target statement fragment;
Determining the number of fields of each preset SQL function and a first classification label of a connector according to the target semantic vector and each classification model in the first classification model group;
determining the probability of each field in the data report hitting each preset SQL function and the second classification label of the aggregation function according to each target coding vector and each classification model in the second classification model group;
Determining a target query field of each preset SQL function according to the probability of hit of each preset SQL function in each field and the number of fields of each preset SQL function;
and generating executable SQL sentences 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.
2. The SQL statement generation method of claim 1, wherein the sequence of field tags comprises a plurality of different field tags describing whether a field in the target statement fragment is a target query field of a preset SQL function.
3. The SQL statement generation method according to claim 1, wherein the number of characters of the target statement fragment is equal to a preset number of characters.
4. The method of claim 1, wherein generating the target encoding vector corresponding to each field tag in the sequence of field tags according to the encoding vector of each target statement fragment comprises:
Acquiring coding sub-vectors corresponding to the field labels in the coding vectors of each target statement fragment;
And splicing the code sub-vectors corresponding to the same field labels to obtain the target code vector corresponding to each field label.
5. The SQL statement generation method according to any one of claims 1-4, wherein 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, and the determining a first classification label for a field number and a connector of each preset SQL function according to the target semantic vector and each classification model in the first classification model group includes:
inputting the target semantic vector into the first classification model to obtain the first field number of the select function;
Inputting the target semantic vector into the second classification model to obtain the second field number of the where function;
inputting the target semantic vector into the third classification model to obtain the third field number of the Groupby functions;
and inputting the target semantic vector into the fourth classification model to obtain a first classification label of the connector.
6. The SQL statement generation method of claim 5, wherein the second classification model group comprises a fifth classification model, a sixth classification model, a seventh classification model, and an eighth classification model, the sequence of field tags comprises a first field tag, a second field tag, and a third field tag, and determining the probability of each field in the data report hitting each preset SQL function and the second classification tag of the aggregate function based on each target encoding vector and each classification model in the second classification model group comprises:
Inputting the target coding vector corresponding to the first field label into the fifth classification model to obtain a first probability of each field in the data report to hit the select function;
inputting the target coding vector corresponding to the second field label into the sixth classification model to obtain a second probability of each field in the data report to hit the sphere function;
Splicing the target coding vector corresponding to the first field tag and the target coding vector corresponding to the third field tag to obtain a spliced coding vector;
inputting the spliced encoding vector into the seventh classification model to obtain a third probability of each field in the data report hitting the Groupby functions;
And inputting the target coding vector corresponding to the first field label into the eighth classification model to obtain a second classification label of the aggregation function.
7. The method according to any one of claims 1 to 4, wherein the generating an executable SQL statement according to the target query field of each preset SQL function, the first class label of the connector, and the second class label of the aggregation function comprises:
determining a target connector in the SQL sentence to be generated according to the first classification label;
Determining a target aggregation function in the SQL sentence to be generated according to the second classification label;
And generating executable SQL sentences according to the target query field, the target connector and the target aggregation function of each preset SQL function.
8. An SQL statement generation device, which is applied to a server, wherein the server stores an SQL statement generation model, the SQL statement generation model includes a pretrained Bert model, a pretrained LSTM model or a GRU model, a pretrained first classification model group, and a second classification model group, and the SQL statement generation device includes:
the acquisition module is used for acquiring target questions to be answered and acquiring data reports corresponding to the target questions;
The statement fragment generation module is configured to generate N target statement fragments according to the target question and each field in the data report, where each target statement fragment includes the target question, at least one field, and at least one field tag sequence, and generating N target statement fragments according to the target question and each field in the data report includes: acquiring a field sequence corresponding to the data report, and inserting a field tag sequence into the head position of each field in the field sequence to obtain a target field sequence; splitting the target field sequence into N field subsequences, so that the sum of the number of the first characters corresponding to each field subsequence and the number of the second characters of the target problem is smaller than or equal to the preset number of characters; splicing the target problem with each field subsequence to obtain N initial sentence fragments, and character filling the N initial sentence fragments to obtain N target sentence fragments, wherein N is a positive integer;
The control module is used for inputting the N target sentence fragments into the Bert model to obtain a semantic vector and a coding vector of each target sentence fragment;
The control module is used for inputting the semantic vector of each target statement fragment into the LSTM model or the GRU model to obtain a target semantic vector;
The vector generation module is used for generating a target coding vector corresponding to each field tag in the field tag sequence according to the coding vector of each target statement fragment;
the determining module 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;
The determining module is further configured to determine, according to each target encoding vector and each classification model in the second classification model group, a probability that each field in the data report hits each preset SQL function and a second classification label of an aggregation function;
the determining module is further configured to determine a 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;
And the SQL sentence generating module is used for generating executable SQL sentences 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.
9. A server comprising a processor, a memory, and a computer program stored on the memory and executable by the processor, wherein the computer program when executed by the processor implements the steps of the SQL statement generation method of any one of claims 1 to 7.
10. A computer readable storage medium, characterized in that the computer readable storage medium has stored thereon a computer program, wherein the computer program, when executed by a processor, implements the steps of the SQL statement generation method of any one of claims 1 to 7.
CN202011642208.5A 2020-12-31 2020-12-31 SQL sentence generation method, device, server and computer readable storage medium Active CN112732741B (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202011642208.5A CN112732741B (en) 2020-12-31 2020-12-31 SQL sentence generation method, device, server and computer readable storage medium
PCT/CN2021/084304 WO2022141880A1 (en) 2020-12-31 2021-03-31 Sql statement generation method, apparatus, server, and computer-readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011642208.5A CN112732741B (en) 2020-12-31 2020-12-31 SQL sentence generation method, device, server and computer readable storage medium

Publications (2)

Publication Number Publication Date
CN112732741A CN112732741A (en) 2021-04-30
CN112732741B true CN112732741B (en) 2024-06-07

Family

ID=75609165

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011642208.5A Active CN112732741B (en) 2020-12-31 2020-12-31 SQL sentence generation method, device, server and computer readable storage medium

Country Status (2)

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

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113282724B (en) * 2021-05-21 2024-05-28 北京京东振世信息技术有限公司 Interaction method and device for intelligent customer service
CN115408506B (en) * 2022-09-15 2023-09-12 云南大学 NL2SQL method combining semantic analysis and semantic component matching
CN116880438B (en) * 2023-04-03 2024-04-26 材谷金带(佛山)金属复合材料有限公司 Fault detection method and system for annealing equipment control system
CN116629227B (en) * 2023-07-24 2023-10-24 海信集团控股股份有限公司 Method and equipment for converting text into SQL (structured query language) sentence

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109408526A (en) * 2018-10-12 2019-03-01 平安科技(深圳)有限公司 SQL statement generation method, device, computer equipment and storage medium
CN111177174A (en) * 2018-11-09 2020-05-19 百度在线网络技术(北京)有限公司 SQL statement generation method, device, equipment and computer readable storage medium
CN111414380A (en) * 2020-03-20 2020-07-14 华泰证券股份有限公司 Chinese database SQ L statement generation method, equipment and storage medium
CN111581229A (en) * 2020-03-25 2020-08-25 平安科技(深圳)有限公司 SQL statement generation method and device, computer equipment and storage medium

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106033466A (en) * 2015-03-20 2016-10-19 华为技术有限公司 Database query method and device
CN110888897B (en) * 2019-11-12 2020-07-14 杭州世平信息科技有限公司 Method and device for generating SQ L statement according to natural language

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109408526A (en) * 2018-10-12 2019-03-01 平安科技(深圳)有限公司 SQL statement generation method, device, computer equipment and storage medium
CN111177174A (en) * 2018-11-09 2020-05-19 百度在线网络技术(北京)有限公司 SQL statement generation method, device, equipment and computer readable storage medium
CN111414380A (en) * 2020-03-20 2020-07-14 华泰证券股份有限公司 Chinese database SQ L statement generation method, equipment and storage medium
CN111581229A (en) * 2020-03-25 2020-08-25 平安科技(深圳)有限公司 SQL statement generation method and device, computer equipment and storage medium

Also Published As

Publication number Publication date
WO2022141880A1 (en) 2022-07-07
CN112732741A (en) 2021-04-30

Similar Documents

Publication Publication Date Title
CN112732741B (en) SQL sentence generation method, device, server and computer readable storage medium
US11151177B2 (en) Search method and apparatus based on artificial intelligence
CN107273503B (en) Method and device for generating parallel text in same language
CN110334179B (en) Question-answer processing method, device, computer equipment and storage medium
CN112035599B (en) Query method and device based on vertical search, computer equipment and storage medium
CN113707300B (en) Search intention recognition method, device, equipment and medium based on artificial intelligence
CN109766418B (en) Method and apparatus for outputting information
WO2022174496A1 (en) Data annotation method and apparatus based on generative model, and device and storage medium
CN107291775B (en) Method and device for generating repairing linguistic data of error sample
CN111274822A (en) Semantic matching method, device, equipment and storage medium
CN110990533A (en) Method and device for determining standard text corresponding to query text
CN113821622B (en) Answer retrieval method and device based on artificial intelligence, electronic equipment and medium
CN112925898B (en) Question-answering method and device based on artificial intelligence, server and storage medium
CN116415564B (en) Functional point amplification method and system based on knowledge graph
CN115470338A (en) Multi-scene intelligent question and answer method and system based on multi-way recall
WO2021042529A1 (en) Article abstract automatic generation method, device, and computer-readable storage medium
CN112949320B (en) Sequence labeling method, device, equipment and medium based on conditional random field
CN107679055B (en) Information retrieval method, server and readable storage medium
CN112597299A (en) Text entity classification method and device, terminal equipment and storage medium
CN116451688A (en) Chinese word segmentation method, device, server and storage medium
CN114742062B (en) Text keyword extraction processing method and system
CN113064984B (en) Intention recognition method, device, electronic equipment and readable storage medium
CN113076089B (en) API (application program interface) completion method based on object type
CN111523312A (en) Paraphrase disambiguation-based query display method and device and computing equipment
CN113723058B (en) Text abstract and keyword extraction method, device, equipment and medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
REG Reference to a national code

Ref country code: HK

Ref legal event code: DE

Ref document number: 40041543

Country of ref document: HK

SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant