A method and device for generating SQL statements from natural language statements

Through the language processing model and language conversion model based on data augmentation, the problem of complex natural language conversion into SQL statements is solved, and database interactions are realized without understanding SQL syntax rules are realized, and the processing capability and accuracy of complex queries are improved. Enhanced model adaptability.

CN118484465BActive Publication Date: 2024-12-03JIANGSU ELECTRIC POWER CO PURCHASING & DISTRIBUTION CENT
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410452634.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-04-16
Publication Date
2024-12-03
Estimated Expiration
2044-04-16

AI Technical Summary

Technical Problem

The prior art is difficult to effectively handle the conversion of complex natural languages ​​to SQL statements, which leads to the overly complex model and difficult to adapt to diverse database patterns and natural language expressions, limiting the database interaction capabilities of non-technical users.

Method used

Using a language processing model based on data augmentation, it generates training data through data syntax analysis, information removal and data sampling, combines task training modules and language conversion models, decomposes natural language statements and generates SQL statements, and uses feedforward neural networks and relationship perception networks. Encoding and decoding with long and short-term memory networks to generate the final SQL statement.

Benefits of technology

It lowers the threshold for user usage, prevents non-technical users from understanding SQL syntax rules, improves the processing ability and query accuracy of complex queries, enhances the generalization ability of the model, and realizes the intelligent interaction between natural language and database.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118484465B_ABST
    Figure CN118484465B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for generating SQL statements from natural language statements. The method comprises establishing a language processing model based on data enhancement, wherein the language processing model comprises a data enhancement module and a task training module; obtaining first training data and inputting the data into the data enhancement module for data syntax analysis, information removal and data sampling to obtain second training data; merging the first training data and the second training data to generate training data and sending the training data to the task training module for training until the language processing model converges; establishing a language conversion model and embedding the language processing model into the language conversion model; the language conversion model receives the natural language statement to be converted, and decomposes the natural language statement to be converted through the language conversion model to obtain a simple statement; encoding and decoding are performed based on the simple statement to generate SQL statements. The present invention can realize the effective processing of complex natural language statements and improve the processing capability of complex database queries.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method and device for generating SQL statements from natural language statements. Background Art

[0002] In computer network applications, a large amount of data is stored in the database. To obtain and analyze the data in the database, structured query statements, such as SQL statements, are required. This requires users to understand the grammatical rules of query statements, which limits the use of non-technical users. NL2SQL (Natural Language to Structured Query Language) is a technology that converts natural language statements input by users into corresponding executable SQL statements. This technology can break the barrier between computer language and human natural language, automatically convert natural language into structured SQL query statements, and enable users to interact with the database in natural language without expert knowledge.

[0003] Patent document CN110888897A provides a method and device for generating SQL statements based on natural language, the method comprising: 1) converting natural language N into sentence vector Ns by sentence vector generation method; 2) converting table descriptions of all tables in the database to be checked into description vector Ti of each table by using sentence vector generation method; 3) calculating the correlation between description vector Ti of each table and natural language sentence vector Ns; 4) selecting the top n tables with the largest correlation as candidate tables; 5) converting natural language N into corresponding SQL template by using semantic analysis algorithm, traversing the selected candidate tables, inserting each candidate table into SQL template, and obtaining SQL statement list; 6) calculating the confidence of SQL statement list, and selecting SQL statement as matching statement according to the confidence. However, this method is only applicable to simple natural language conversion. For complex natural language, it is difficult to express it with a single SQL template, and it will cause the model to be too complicated. Summary of the invention

[0004] The present invention provides a method and device for generating SQL statements from natural language statements, which can make it unnecessary for non-technical users to understand SQL grammar rules, thus lowering the threshold for users to use the system and improving the processing capability and query accuracy of complex queries.

[0005] In a first aspect, the present invention provides a method for generating SQL statements from natural language statements, comprising:

[0006] Establishing a language processing model based on data enhancement, wherein the language processing model includes a data enhancement module and a task training module;

[0007] Acquire first training data, input the first training data into the data enhancement module for data syntax analysis, information removal, and data sampling, and obtain second training data;

[0008] Merging the first training data and the second training data to generate training data and sending the training data to the task training module for training until the language processing model converges;

[0009] Establishing a language conversion model, and embedding the language processing model into the language conversion model;

[0010] The language conversion model receives a natural language sentence to be converted, and decomposes the natural language sentence to be converted through the language conversion model to obtain a simple sentence;

[0011] Encoding and decoding are performed based on the simple statement to generate an SQL statement.

[0012] Furthermore, the first training data includes multiple groups of sample data, and the sample data includes natural language statements, corresponding SQL statements, and associated table models.

[0013] Furthermore, the first training data is input into the data enhancement module for data syntax analysis, information removal and data sampling to obtain second training data, including:

[0014] Performing grammatical analysis on the SQL statements in the first training data to determine grammatical rules in the SQL statements;

[0015] Determine each component of the SQL statement according to the grammatical rules;

[0016] For each SQL statement, information is removed according to its components, and multiple sub-productions are generated accordingly;

[0017] Analyze the subproduction formula to obtain the corresponding SQL template classification result;

[0018] Select a preset number of SQL templates with the largest number of occurrences, and obtain their corresponding multiple different natural language statements;

[0019] The SQL template, the corresponding natural language statement and the table pattern are randomly sampled and synthesized to generate the second training data.

[0020] Furthermore, the SQL statement describes the grammatical rules through production formulas; the components of the SQL statement include non-terminal symbols and expressions, and the expression is a sequence of non-terminal symbols and terminal symbols;

[0021] For each SQL statement, information is removed according to its components, and multiple sub-productions are generated accordingly, including:

[0022] In one operation, a non-terminal symbol in the expression of the SQL statement is removed to obtain a subproduction formula;

[0023] Non-terminal symbols in the expression of the SQL statement are removed in sequence to obtain multiple sub-productions.

[0024] Furthermore, the task training module is trained according to the training data, including:

[0025] Establishing a first intermediate state statement between the natural language statement and the SQL statement;

[0026] Iterate and perform the following operations until the training stop condition is met:

[0027] Randomly masking the grammatical sequence of the first intermediate state sentence based on a masking mechanism;

[0028] Predicting and filling the randomly masked part in the first intermediate state statement according to the corresponding natural language statement in the training data and the SQL statement;

[0029] Calculate the loss function value based on the prediction result, and obtain the gradient value generated by gradient descent during the calculation process;

[0030] The parameters of the language processing model are updated according to the gradient value.

[0031] Furthermore, the language conversion model decomposes the natural language sentence to be converted to obtain simple sentences, including:

[0032] The language conversion model uses an embedded language processing model to encode the natural language sentence to be converted into a vector representation and inputs it into a pre-set feedforward neural network to predict whether the natural language sentence to be converted contains multiple layers of complex semantics;

[0033] If the natural language sentence to be converted contains multiple layers of complex semantics, a semantic tree is established according to the natural language sentence to be converted;

[0034] Perform a depth-first traversal on the semantic tree to obtain simple sentences.

[0035] Furthermore, encoding and decoding are performed based on the simple statement to generate an SQL statement, including:

[0036] Parsing the simple statement and converting it into a statement graph representation;

[0037] Analyze the relationship between database tables and columns to obtain a graphical representation of the database schema;

[0038] Associating and matching the statement graph representation with the graph representation of the database schema to obtain an association graph;

[0039] Encoding the association graph using the language conversion model and a pre-established relationship-aware network to obtain a vector representation;

[0040] Decoding the vector representation using a long short-term memory network to generate a second intermediate state statement between the simple statement and the database pattern;

[0041] Infer and concatenate SQL statements based on the second intermediate state statement to generate a final SQL statement.

[0042] Furthermore, the association graph is encoded using the language conversion model and a pre-established relationship perception network to obtain a vector representation, including:

[0043] constructing an input vector according to the association graph;

[0044] Encoding the input vector using the language conversion model to obtain an initial vector representation;

[0045] Position embedding for each word in a simple sentence;

[0046] The initial vector representation and position embedding are further embedded using the relationship-aware network to obtain the vector representation.

[0047] In a second aspect, the present invention provides a device for generating SQL statements from natural language statements, comprising:

[0048] A first model building module, used to build a language processing model based on data enhancement, wherein the language processing model includes a data enhancement module and a task training module;

[0049] A data processing module, used for acquiring first training data, inputting the first training data into the data enhancement module for data syntax analysis, information removal and data sampling, and obtaining second training data;

[0050] A training module, used for merging the first training data and the second training data to generate training data and sending the training data to the task training module for training until the language processing model converges;

[0051] A second model building module, used for building a language conversion model and embedding the language processing model into the language conversion model;

[0052] A decomposition module, used for receiving a natural language sentence to be converted through the language conversion model, and decomposing the natural language sentence to be converted through the language conversion model to obtain a simple sentence;

[0053] The statement generation module performs encoding and decoding based on the simple statement to generate an SQL statement.

[0054] Furthermore, the data processing module includes:

[0055] Performing grammatical analysis on the SQL statements in the first training data to determine grammatical rules in the SQL statements;

[0056] Determine each component of the SQL statement according to the grammatical rules;

[0057] For each SQL statement, information is removed according to its components, and multiple sub-productions are generated accordingly;

[0058] Analyze the subproduction formula to obtain the corresponding SQL template classification result;

[0059] Select a preset number of SQL templates with the largest number of occurrences, and obtain their corresponding multiple different natural language statements;

[0060] The SQL template, the corresponding natural language statement and the table pattern are randomly sampled and synthesized to generate the second training data.

[0061] Furthermore, the data processing module also includes:

[0062] In one operation, a non-terminal symbol in the expression of the SQL statement is removed to obtain a subproduction formula;

[0063] Non-terminal symbols in the expression of the SQL statement are removed in sequence to obtain multiple sub-productions.

[0064] Furthermore, the training module also includes:

[0065] Establishing a first intermediate state statement between the natural language statement and the SQL statement;

[0066] Iterate and perform the following operations until the training stop condition is met:

[0067] Randomly masking the grammatical sequence of the first intermediate state sentence based on a masking mechanism;

[0068] Predicting and filling the randomly masked part in the first intermediate state statement according to the corresponding natural language statement in the training data and the SQL statement;

[0069] Calculate the loss function value based on the prediction result, and obtain the gradient value generated by gradient descent during the calculation process;

[0070] The parameters of the language processing model are updated according to the gradient value.

[0071] Furthermore, the decomposition module also includes:

[0072] The language conversion model uses an embedded language processing model to encode the natural language sentence to be converted into a vector representation and inputs it into a pre-set feedforward neural network to predict whether the natural language sentence to be converted contains multiple layers of complex semantics;

[0073] If the natural language sentence to be converted contains multiple layers of complex semantics, a semantic tree is established according to the natural language sentence to be converted;

[0074] Perform a depth-first traversal on the semantic tree to obtain simple sentences.

[0075] Furthermore, the statement generation module includes:

[0076] Parsing the simple statement and converting it into a statement graph representation;

[0077] Analyze the relationship between database tables and columns to obtain a graphical representation of the database schema;

[0078] Associating and matching the statement graph representation with the graph representation of the database schema to obtain an association graph;

[0079] Encoding the association graph using the language conversion model and a pre-established relationship-aware network to obtain a vector representation;

[0080] Decoding the vector representation using a long short-term memory network to generate a second intermediate state statement between the simple statement and the database pattern;

[0081] Infer and concatenate SQL statements based on the second intermediate state statement to generate a final SQL statement.

[0082] Furthermore, the statement generation module also includes:

[0083] constructing an input vector according to the association graph;

[0084] Encoding the input vector using the language conversion model to obtain an initial vector representation;

[0085] Position embedding for each word in a simple sentence;

[0086] The initial vector representation and position embedding are further embedded using the relationship-aware network to obtain the vector representation.

[0087] In a third aspect, the present invention further provides a computer storage medium, wherein the computer storage medium stores computer instructions, and when the computer instructions are called, they are used to execute the above method.

[0088] The present invention provides a method and device for generating SQL statements from natural language statements, which at least have the following beneficial effects:

[0089] (1) It allows non-technical users to interact with the database using natural language without having to understand SQL syntax rules, thereby lowering the user's usage threshold. By establishing a language processing model based on data enhancement, it can effectively process complex natural language statements. Through data enhancement and task training modules, the processing ability of complex queries can be improved. By decomposing natural language into simple statements through a language conversion model, query accuracy can be improved. Through the data enhancement module, the generalization ability of the model can be enhanced. The automated conversion from natural language to SQL statements reduces the need for manual writing and debugging of SQL statements, making it automated and intelligent.

[0090] (2) Through the first intermediate state statement and the second intermediate state statement, a more direct and simplified path can be provided to convert natural language queries into executable SQL statements, thereby more efficiently processing complex queries and reducing errors that may occur during the conversion process. BRIEF DESCRIPTION OF THE DRAWINGS

[0091] Figure 1 A flowchart of a method for generating SQL statements from natural language statements provided by the present invention;

[0092] Figure 2 A flowchart of obtaining second training data according to an embodiment of the present invention;

[0093] Figure 3 A flowchart of obtaining a simple statement according to an embodiment of the present invention;

[0094] Figure 4 A flowchart of generating SQL statements according to an embodiment of the present invention;

[0095] Figure 5 A flowchart of obtaining a vector representation according to an embodiment of the present invention;

[0096] Figure 6 A schematic diagram of a device for generating SQL statements from natural language statements provided by the present invention. DETAILED DESCRIPTION

[0097] In order to better understand the above technical solution, the above technical solution will be described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0098] like Figure 1 As shown, this embodiment provides a method for generating SQL statements from natural language statements, including:

[0099] Establishing a language processing model based on data enhancement, wherein the language processing model includes a data enhancement module and a task training module;

[0100] Acquire first training data, input the first training data into the data enhancement module for data syntax analysis, information removal, and data sampling, and obtain second training data;

[0101] Merging the first training data and the second training data to generate training data and sending the training data to the task training module for training until the language processing model converges;

[0102] Establishing a language conversion model, and embedding the language processing model into the language conversion model;

[0103] The language conversion model receives a natural language sentence to be converted, and decomposes the natural language sentence to be converted through the language conversion model to obtain a simple sentence;

[0104] Encoding and decoding are performed based on the simple statement to generate an SQL statement.

[0105] The method provided by the above embodiment can enable non-technical users to interact with the database using natural language without understanding the SQL syntax rules, thereby lowering the user's usage threshold. By establishing a language processing model based on data enhancement, complex natural language statements can be effectively processed. Through data enhancement and task training modules, the model can learn a richer mapping relationship between natural language and database models, thereby improving the processing ability of complex queries. By decomposing natural language into simple statements through a language conversion model, and encoding and decoding based on these simple statements to generate SQL statements, the query accuracy can be improved. Through the data enhancement module, the model can be trained on diverse data, which helps to improve the model's adaptability to different database models and natural language expressions, thereby enhancing the generalization ability of the model. The automated conversion from natural language to SQL statements reduces the need for manual writing and debugging of SQL statements, making it automated and intelligent.

[0106] The language processing model can be a pre-trained language model, which is a machine learning model trained with a large amount of text data to understand and generate human language. This model captures the grammar, vocabulary and context of the language by learning a large-scale text library, so that it can encode and decode the language without specific task guidance.

[0107] The first training data includes multiple groups of sample data, and the sample data includes natural language statements, corresponding SQL statements, and associated table models. Natural language statements are language forms used in daily communication, usually free-form text, which can express rich information and requests. In NL2SQL, natural language statements are inquiries or commands raised by users, aiming to retrieve or operate data from a database. For example, a user raises a question: "Which cities have an average salary higher than the average?" The user's natural language statement needs to be converted into a corresponding SQL statement to execute the query on the database. SQL (Structured Query Language) statements are a programming language for managing and operating relational databases. It is a structured query language used to perform various database operations, such as data query, update, insert, and delete. SQL statements follow strict grammatical rules and need to specify correct keywords, table names, column names, conditions, etc. For example, for the natural language statement corresponding to the above user's query, the corresponding SQL statement can be: "SELECTcity FROMsalaries WHERE avg_salary>(SELECTAVG(salary)FROMsalaries)". The table schema is the structure of the table in the database, including the column names, data types, keys (such as primary keys, foreign keys), and relationships between tables (such as one-to-one, one-to-many, or many-to-many relationships). The table schema is part of the database and defines how to organize and store data in the database. In the NL2SQL system, the table schema is crucial for understanding the entities and attributes in natural language statements, and provides the contextual information required to map natural language to specific database fields.

[0108] Furthermore, if Figure 2 As shown, inputting the first training data into the data enhancement module for data syntax analysis, information removal, and data sampling to obtain the second training data may include:

[0109] Performing grammatical analysis on the SQL statements in the first training data to determine grammatical rules in the SQL statements;

[0110] Determine each component of the SQL statement according to the grammatical rules;

[0111] For each SQL statement, information is removed according to its components, and multiple sub-productions are generated accordingly;

[0112] Analyze the subproduction formula to obtain the corresponding SQL template classification result;

[0113] Select a preset number of SQL templates with the largest number of occurrences, and obtain their corresponding multiple different natural language statements;

[0114] The SQL template, the corresponding natural language statement and the table pattern are randomly sampled and synthesized to generate the second training data.

[0115] The syntax analysis performed to determine the syntax rules in the SQL statement may include the following:

[0116] Identify keywords and operators: When performing syntax analysis, you need to identify keywords (such as SELECT, FROM, WHERE, GROUP BY, etc.) and operators (such as =, <, >, AND, OR, etc.) in SQL statements. Keywords and operators are the basic elements that constitute the structure of SQL statements.

[0117] Parsing expression structure: Analyze expressions in SQL statements, such as column names, function calls, conditional expressions, and their hierarchical relationships. For example, identify the relationship between column names and comparison operators, or the structure of function names and their parameters.

[0118] Determine the clause structure: SQL statements can contain multiple clauses, such as SELECT clause, FROM clause, WHERE clause, etc. Syntax analysis needs to determine the start and end position of each clause, as well as their order and nesting relationship in the statement;

[0119] Identify aggregate functions: Aggregate functions such as COUNT, SUM, AVG, MAX, MIN, etc. are used in SQL statements to perform calculations on a set of values; syntax analysis requires identifying the use of these functions and understanding their role in queries;

[0120] Processing join queries: For SQL statements containing JOIN operations, syntax analysis needs to identify the join type (such as INNER JOIN, LEFT JOIN, RIGHT JOIN, etc.), as well as the join conditions and the tables involved;

[0121] Identify data types and constraints: In SQL statements, data types (such as INT, VARCHAR, DATE, etc.) and constraints (such as PRIMARYKEY, FOREIGNKEY, NOT NULL, etc.) may be specified; syntax analysis needs to identify this information in order to correctly understand and process the data;

[0122] Handling nested queries: For SQL statements containing subqueries, syntax analysis needs to identify the scope of the subquery and understand its relationship to the outer query;

[0123] Identify comments and spaces: Comments and spaces in SQL statements have no effect on the execution of the statement, but are important for reading and understanding SQL statements; syntax analysis requires correct processing of comments and spaces to ensure that they do not interfere with the recognition of syntax rules;

[0124] Through the above syntax analysis steps, the data enhancement module can deeply understand the structure and meaning of SQL statements, thereby effectively enhancing and transforming the data while keeping the semantics unchanged, providing richer and more diverse training data for subsequent training modules. These enhanced data help improve the generalization ability and accuracy of the NL2SQL model.

[0125] When determining each component in the SQL statement, each component in the SQL statement may include:

[0126] 1. SELECT clause: used to specify the columns to be returned from the query results, for example: SELECT customers.name, orders.total_amount; customers.name: specifies to select the name column from the customers table; orders.total_amount: specifies to select the total_amount column from the orders table.

[0127] 2. FROM clause: specifies the tables involved in the query.

[0128] 3. JOIN clause: used to connect multiple tables and specify the connection conditions.

[0129] 4. WHERE clause: used to specify filtering conditions and only return records that meet specific conditions.

[0130] 5. GROUP BY clause: used to group the result set according to one or more columns.

[0131] 6. HAVING clause: used to filter the grouped results and only include groups that meet the specified conditions.

[0132] 7. ORDER BY clause: used to specify the sorting method of returned results.

[0133] The SQL statements in this embodiment describe the grammatical rules through productions; the components of the SQL statements include non-terminal symbols and expressions, and the expressions are sequences of non-terminal symbols and terminal symbols. For each SQL statement, information is removed according to the components, and multiple sub-productions are generated accordingly, including:

[0134] In one operation, a non-terminal symbol in the expression of the SQL statement is removed to obtain a subproduction formula;

[0135] Non-terminal symbols in the expression of the SQL statement are removed in sequence to obtain multiple sub-productions.

[0136] The expression of an SQL statement is the part of an SQL statement used to specify an operation. Non-terminal symbols are symbols used to define grammatical rules in a context-free grammar, representing a grammatical structure that can be further decomposed. In this embodiment, multiple sub-productions can be obtained by gradually removing non-terminal symbols. The obtained sub-productions are simplified or transformed forms of the original expression. Exemplarily, a simplified context-free grammar can be defined to describe the structure of an SQL statement expression. The grammar rules are:

[0137] SelectStatement→SELECT Columns FROM Table WHERECondition

[0138] Columns→Column|Columns,Column

[0139] Column→*|ColumnName

[0140] Table→TableName

[0141] Condition→Column OperatorValue|ConditionAND Condition

[0142] Operator→=|<|>|!=

[0143] According to the above grammar rules, the expression of SQL statement can be expressed as:

[0144] SelectStatement

[0145] Gradually remove the non-terminal symbols of SelectStatement to obtain subproductions, and we get:

[0146] SELECT Columns FROM Table WHERE Condition

[0147] Removing the Columns nonterminal, we get two possible subproductions:

[0148] SELECT Column FROM Table WHERE Condition

[0149] SELECT Columns,Column FROM Table WHERE Condition

[0150] For the first subproduction, you can continue to remove the Column nonterminal, remove the Table nonterminal, or remove the Condition nonterminal; when removing the Column nonterminal, you can get two possible subproductions again:

[0151] SELECT*FROM Table WHERE Condition

[0152] SELECT ColumnName FROM Table WHERE Condition

[0153] When the Table non-terminal symbol is removed, the following subproduction is obtained:

[0154] SELECT Columns FROM TableName WHERE Condition

[0155] Among them, TableName is the specific table name, such as customers;

[0156] When the Condition non-terminal symbol is removed, the following subproduction formula can be obtained:

[0157] SELECT Columns FROM Table

[0158] It represents a query with no filter conditions.

[0159] By removing non-terminal symbols, multiple possible SQL statement variants can be generated. Each subproduction represents a valid alternative to the original expression, which can be used for data augmentation or other operations in NL2SQL tasks.

[0160] Furthermore, the task training module is trained according to the training data, which may include:

[0161] Establishing a first intermediate state statement between the natural language statement and the SQL statement;

[0162] Iterate and perform the following operations until the training stop condition is met:

[0163] Randomly masking the grammatical sequence of the first intermediate state sentence based on a masking mechanism;

[0164] Predicting and filling the randomly masked part in the first intermediate state statement according to the corresponding natural language statement in the training data and the SQL statement;

[0165] Calculate the loss function value based on the prediction result, and obtain the gradient value generated by gradient descent during the calculation process;

[0166] The parameters of the language processing model are updated according to the gradient value.

[0167] Among them, the intermediate state statements (the first intermediate state statement and the second intermediate state statement) are intermediate representations, which are structured forms designed to simplify the conversion process from natural language to SQL statements. The intermediate state statements capture the key information in the natural language statements and organize them into a structure that is closer to SQL statements, but simpler and easier to process than complete SQL statements. There are several ways to represent intermediate state statements:

[0168] 1. Template-based intermediate representation:

[0169] A natural language statement could be: Find the names and positions of all employees working in Beijing;

[0170] The corresponding intermediate state statement (based on the template) is: SELECT name, position FROM employees WHERE city = 'Beijing';

[0171] The intermediate state statement follows a predefined template, in which the SELECT clause specifies the columns to be selected (name and position), the FROM clause specifies the table (employees), and the WHERE clause specifies the filtering condition (city='Beijing').

[0172] 2. Intermediate representation based on syntax tree:

[0173] A natural language sentence could be: Find products with sales exceeding the average.

[0174] The corresponding intermediate state statement (based on the syntax tree) is: SELECT product_id,sales FROMsales_data GROUP BY product_id HAVING sales>(SELECTAVG(sales)FROM sales_data);

[0175] The intermediate statement uses the SQL GROUP BY and HAVING clauses to calculate the average sales and filter out products with sales exceeding the average. This representation is closer to the final SQL statement, but omits some details, such as the specific table name and column name, which can be determined in subsequent processing.

[0176] 3. Intermediate representation based on logical form:

[0177] A natural language sentence could be: List the average salary for each department.

[0178] The corresponding intermediate state statement (based on logical form) is: department average salary filter (department_id, employees)

[0179] The intermediate state statement uses a logical form to express the query. The department average salary describes the aggregate value to be calculated, and filter(department_id,employees) indicates that the department_id in the employees table needs to be filtered. This logical form does not directly correspond to SQL syntax, but provides a clear query semantics that can be further converted into SQL statements.

[0180] The purpose of establishing the intermediate state statement of the present invention is to provide a more direct and simplified path to convert natural language queries into executable SQL statements. In this way, the NL2SQL system can process complex queries more effectively and reduce errors that may occur during the conversion process.

[0181] The embodiment of the present invention predicts and fills the randomly masked part in the first intermediate state statement, which may include the following aspects: 1. Keywords and operators: Keywords and operators in SQL statements, such as SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, etc., and the logical relationship between them. For example, the HAVING clause in the intermediate state statement is masked, and the model needs to predict and fill this part to ensure the correctness of the query. 2. Column name and table name: The model needs to predict the column name and table name referenced in the SQL statement. It usually involves extracting relevant information from the natural language statement and converting it into an identifier in the corresponding database schema. 3. Conditional expression: In the WHERE clause, the model needs to predict the conditional expression, including column name, comparison operator (such as =, <, >, ! =, etc.) and conditional value. For example, if the natural language statement mentions "age is greater than 30", the model needs to predict the corresponding conditional expression as age>30. 4. Aggregate function: For queries containing aggregate functions, such as SUM, AVG, COUNT, MAX, MIN, etc., the model needs to predict these functions and the column names to which they are applied. 5. Grouping and sorting: If the query contains GROUP BY and ORDER BY clauses, the model needs to predict the grouping column names and the sorting rules (ascending or descending).

[0182] Among them, the process of predicting filling can be achieved through the following different technologies: 1. Rule-based methods: use predefined rules and patterns to guide the prediction process. 2. Statistical methods: use machine learning models, such as random forests or gradient boosting machines, to make predictions based on patterns in the training data. 3. Deep learning-based methods: use neural networks, such as recurrent neural networks (RNNs) or Transformer models, to learn complex mapping relationships and make end-to-end predictions.

[0183] In the NL2SQL task, the loss function is used to measure the difference between the model's prediction results and the actual SQL statement. By minimizing the loss function, the model can adjust its parameters to improve the accuracy of the prediction. Loss functions can include cross-entropy loss and sequence-to-sequence loss, which can be used for classification problems and sequence generation problems. In the NL2SQL task, the specific forms of the loss function and gradient need to be adjusted according to the characteristics of the task and the model used. For example, if the task is to convert a natural language statement into an intermediate representation of a SQL statement, the loss function needs to take into account the semantic information in the natural language statement and the structural information of the SQL statement. In addition, if a specific intermediate representation (such as an abstract syntax tree or logical form) is used, the loss function and gradient calculation also need to be adjusted accordingly to ensure that the characteristics of the intermediate representation are reflected.

[0184] Further, such as Figure 3 As shown, the language conversion model decomposes the natural language sentence to be converted to obtain simple sentences, including:

[0185] The language conversion model uses an embedded language processing model to encode the natural language sentence to be converted into a vector representation and inputs it into a pre-set feedforward neural network to predict whether the natural language sentence to be converted contains multiple layers of complex semantics;

[0186] If the natural language sentence to be converted contains multiple layers of complex semantics, a semantic tree is established according to the natural language sentence to be converted;

[0187] Perform a depth-first traversal on the semantic tree to obtain simple sentences.

[0188] Among them, encoding the natural language sentence to be converted into a vector representation is the process of converting natural language into a numerical form that can be processed by the machine learning model. This process involves the following steps:

[0189] Word segmentation and embedding: First, natural language sentences are segmented into individual words or subwords (Tokens); then, each word or subword is mapped to an embedding vector in a high-dimensional space; these embedding vectors are obtained by pre-training on a large amount of text data and can capture the semantic information of words;

[0190] Context encoding: Since the embedding of a single word may not be sufficient to express complex semantic relationships, context encoders (such as recurrent neural networks (RNNs), long short-term memory networks (LSTMs), or gated recurrent units (GRUs)) are used to process serialized natural languages; these encoders are able to take into account the order and dependencies between words and generate a vector representation that contains contextual information;

[0191] Attention Mechanism: In some more advanced models, such as Transformer or BERT, an attention mechanism is used to dynamically focus on different parts of the input sequence; this allows the model to focus on the most relevant parts of the input sequence when generating each output.

[0192] The process of making predictions through a pre-set feedforward neural network may include:

[0193] Preparation of input vectors: The encoded natural language sentence vectors are used as input to the feedforward neural network; these vectors already contain the semantic and structural information of the natural language;

[0194] Cascade processing: Feedforward neural networks consist of multiple layers, each containing multiple neurons; the input vector is passed layer by layer, and each layer applies an activation function (such as ReLU or Sigmoid) and weight transformation to learn more abstract feature representations;

[0195] Output and prediction: The last layer of the network usually outputs a probability distribution, indicating the possibility that the natural language sentence to be converted contains multiple layers of complex semantics; this output can be converted to probability through the softmax function and compared with the true label through the loss function;

[0196] Loss calculation and backpropagation: Calculate the loss between the predicted results and the actual labels (for example, using binary cross entropy loss); then calculate the gradients through the backpropagation algorithm and update the weights of the network based on these gradients.

[0197] When a semantic tree is established according to the natural language sentence to be converted, it may include:

[0198] Identify main concepts and logical structures: Analyze natural language sentences to identify main concepts (such as entities, attributes, events, etc.) and the logical relationships between them (such as parallelism, selection, cause and effect, etc.).

[0199] Construct the root node of the tree: Determine the core semantics of the sentence as the root node of the semantic tree, which is the theme or main action of the entire sentence.

[0200] Recursively build subnodes: For each main concept, recursively build subnodes according to its role in the sentence and its relationship with other concepts; subnodes can be further expanded into deeper subtrees to represent more complex semantic structures.

[0201] Representing parallel and selection relationships: For parallel relationships in a sentence (such as elements connected by "and" and "or"), they are represented by sibling nodes at the same level in the semantic tree; for selection relationships (such as the "either...or..." structure), they are represented by conditional branches in the semantic tree.

[0202] Handling nested and modified structures: For nested statements or subqueries, build internal subtrees to represent the nested logic; for modifying phrases or clauses (such as attributives, adverbials, etc.), link them to the appropriate positions in the main tree by connecting the modifying nodes and the modified nodes.

[0203] Labeling semantic roles: Assign semantic role labels to each node in the semantic tree, such as "subject", "predicate", "object", "condition", etc., to clarify the function of each node in the sentence.

[0204] Optimize and simplify the semantic tree: Optimize and simplify the semantic tree as needed, remove redundant nodes, merge branches that can be merged, and ensure that the tree structure is clear and easy to handle.

[0205] The depth-first traversal of the semantic tree can include the following steps:

[0206] 1) Select the starting node: start traversing from the root node of the semantic tree.

[0207] 2) Access the current node: Access the current node and perform corresponding operations based on the type and content of the node. For example, if the node represents an entity, the name of the entity may be recorded.

[0208] 3) Recursively traverse child nodes: recursively traverse all child nodes of the current node. Specifically, visit the leftmost child node first, then the next child node, and so on, until all child nodes have been visited. During the recursive process, each child node will be regarded as a new "current node" and steps 2) and 3) will be repeated.

[0209] 4) Backtracking: After all child nodes of the current node have been visited, backtrack to its parent node. If the parent node has other unvisited child nodes, continue to traverse from the unvisited child nodes. If all child nodes of the parent node have been visited, continue to backtrack to the parent node at a higher level until there are no other nodes to visit.

[0210] 5) Processing leaf nodes: When a leaf node is reached, since there are no child nodes to continue accessing, the information of the leaf node is recorded and then traced back to the parent node.

[0211] 6) Traversal completed: Repeat the above steps 1) to 5) until all nodes have been visited, at which point the depth-first traversal of the semantic tree is completed.

[0212] Furthermore, if Figure 4 As shown, encoding and decoding are performed based on the simple statement to generate an SQL statement, including:

[0213] Parsing the simple statement and converting it into a statement graph representation;

[0214] Analyze the relationship between database tables and columns to obtain a graphical representation of the database schema;

[0215] Associating and matching the statement graph representation with the graph representation of the database schema to obtain an association graph;

[0216] Encoding the association graph using the language conversion model and a pre-established relationship-aware network to obtain a vector representation;

[0217] Decoding the vector representation using a long short-term memory network to generate a second intermediate state statement between the simple statement and the database pattern;

[0218] Infer and concatenate SQL statements based on the second intermediate state statement to generate a final SQL statement.

[0219] The parsing of the simple statement and converting it into a statement graph representation may include the following steps:

[0220] 1. Parsing: Perform syntactic analysis on simple sentences to identify the various components in the sentence, such as subject, predicate, object, attributive, adverbial, etc. Through syntactic analysis, a dependency tree can be constructed, in which each node represents a word or phrase, and the edge represents the dependency relationship between words.

[0221] 2. Build a statement graph: Based on the dependency tree, further build a statement graph to map the entities, attributes, and relationships in the statement to nodes in the graph. Entities usually correspond to tables or column names in the database, attributes correspond to specific values ​​or conditions of columns, and relationships represent connections between entities or logical operations in statements.

[0222] 3. Node and edge labeling: Nodes need to be correctly labeled to reflect their roles in SQL statements. For example, table names, column names, operators, functions, values, etc. will be given specific labels. Edges represent the relationship between nodes, such as JOIN, ON, WHERE, SELECT, etc. The types of these edges need to be labeled according to the semantics of the statement.

[0223] 4. Handling complex structures: Statements containing complex structures, such as nested queries, subqueries, aggregate functions, etc., require special processing to ensure the accuracy of the graph. These complex structures may require additional nodes and edges to represent to ensure that the statement graph can fully capture the semantics of the statement.

[0224] 5. Graph optimization: After constructing the statement graph, you can optimize the statement graph, remove unnecessary nodes or edges, merge nodes that can be merged, to simplify the graph and reduce ambiguity. The optimization process helps improve the efficiency of subsequent processing steps, such as encoding and decoding processes.

[0225] A graph representation of a database schema may include nodes, edges, node attributes, hierarchical structures, and the layout of the graph; specifically, in a graph of a database schema, each node represents an entity in the database, which can be a table or a column in a table. A table is represented by a rectangle, while a column is represented by an ellipse or other shape inside a rectangle and placed inside the rectangle of the corresponding table. Edges are used to represent relationships between nodes; in a database schema, they are foreign key relationships between tables, or data dependencies between columns. If there is a foreign key relationship between two tables, there will be an edge between the nodes of the two tables, and the label of the edge indicates the type of relationship, such as "1:N" (one-to-many), "N:M" (many-to-many), or "1:1" (one-to-one). If there is a data dependency between columns, such as the value of a column depends on the value of another column, the nodes of the two columns are also connected by an edge. Node attributes provide additional information, such as table name, column name, data type, whether it is a primary key, etc. These attributes can be displayed as labels for nodes, or viewed interactively by hovering, clicking, etc. In some cases, a database schema graph may show a hierarchy between tables, where the relationship between parent and child tables is represented by a hierarchy of edges. This hierarchical structure helps understand how data is organized and the query path. The layout of the database schema diagram clearly shows the relationship between tables and columns, avoiding crossing and overlapping edges. The layout of the diagram will group related tables and columns together to make it easier to identify and understand the relationship between them.

[0226] Furthermore, if Figure 5 As shown, the association graph is encoded using the language conversion model and the pre-established relationship perception network to obtain a vector representation, including:

[0227] constructing an input vector according to the association graph;

[0228] Encoding the input vector using the language conversion model to obtain an initial vector representation;

[0229] Position embedding for each word in a simple sentence;

[0230] The initial vector representation and position embedding are further embedded using the relationship-aware network to obtain the vector representation.

[0231] The step of encoding the input vector using the language conversion model to obtain an initial vector representation may include the following steps:

[0232] Convert the input natural language text into a vector representation. This is achieved through an embedding layer and a recurrent neural network (such as LSTM or GRU). In the embedding layer, each word or subword is converted into a fixed-length vector that captures the semantic information of the word. These word vectors are fed into a recurrent neural network that can process sequence data and capture long-distance dependencies. The final output of the network is a vector representation that contains the entire input sequence information, that is, the initial vector representation.

[0233] The relation-aware network can be used to enhance the initial vector representation so that it better reflects the semantic relationship in the natural language sentence and the structural information of the database schema. The initial vector representation and position embedding are further embedded using the relation-aware network to obtain the vector representation, including the following steps:

[0234] 1. Initial vector representation: The initial vector representation is obtained through a language model (such as BERT or GPT) and contains the contextual information of each word in the natural language sentence.

[0235] 2. Position embedding: Position embedding is an additional vector information that captures the position information of elements in sequence data. In the Transformer architecture, position embedding is added to word embedding to provide the model with an understanding of the order of words in the sequence.

[0236] 3. Relation-aware embedding: Relation-aware networks recognize and encode entity relationships in input vectors by introducing additional attention mechanisms. For example, it can learn which words are table names in the database, which words are column names, and the associations between them. For database schemas, relationship-aware networks can handle foreign key relationships between tables and column relationships within tables.

[0237] 4. Further embedding process: In the relation-aware network, the initial vector representation and position embedding are first fed into one or more attention layers. These layers determine the importance of different parts of the sequence by calculating attention scores. The attention scores are dynamically calculated based on the relationship between entities and their role in the query. For example, if a column name is associated with a specific condition, the attention mechanism will give this column name a higher weight. In this way, the network is able to generate an enhanced vector representation that contains not only the original semantic information, but also the semantic information of the relationship between entities.

[0238] The enhanced vector representation obtained in this embodiment is richer and can provide more accurate context information for subsequent SQL statement generation. This enhanced vector representation can be used to guide the generation of more accurate SELECT clauses, FROM clauses, WHERE clauses and other parts of SQL statements. The application of relationship-aware networks enables the NL2SQL system to more deeply understand the complex relationship between natural language queries and database models, thereby generating more accurate SQL statements that are more in line with user intent. It is particularly effective when processing queries containing multiple entities and complex logic.

[0239] The vector representation is decoded using LSTM (Long Short-Term Memory Network) to generate a second intermediate state statement between the simple statement and the database schema, which includes the following steps:

[0240] Decoding phase: The LSTM network uses its hidden state to generate the second intermediate state statement. The goal of this phase is to convert the encoded semantic information into the structure of an executable SQL statement. The output of the LSTM network passes through a fully connected layer (or linear layer) to generate each component of the intermediate state statement, such as the SELECT clause, FROM clause, WHERE clause, etc.

[0241] Attention mechanism: To improve the accuracy of decoding, an attention mechanism can be integrated into the LSTM network. The attention mechanism allows the model to focus on the most relevant part of the input sequence when generating each word. In this way, the model can better understand the correspondence between natural language sentences and database patterns and generate accurate intermediate state sentences.

[0242] Generate statements: The LSTM network generates the components of the second intermediate state statement one by one, and the output of each step is used as the input of the next step until a complete statement is generated. The generated second intermediate state statement should be able to reflect the intention of the natural language statement and match the database schema, laying the foundation for the final generation of executable SQL statements.

[0243] The LSTM network can decode the vector representation of the natural language sentence into a second intermediate state sentence that matches the database schema. This second intermediate state sentence is a structured representation that converts the semantic information of the natural language into a form closer to the SQL sentence, thus facilitating the subsequent SQL generation step.

[0244] Inferring and splicing the SQL statement according to the second intermediate state statement to generate the final SQL statement includes the following steps:

[0245] 1. Parse the second intermediate state statement: Analyze the structure of the second intermediate state statement and identify the key components required for the query, such as the column name of the SELECT clause, the table name of the FROM clause, the conditions of the WHERE clause, etc. For statements containing aggregate functions or grouping, you also need to identify these components and determine their location in the final SQL statement.

[0246] 2. Build the framework of the SQL statement: Based on the information in the second intermediate state statement, build the basic framework of the SQL statement, including clauses such as SELECT, FROM, and WHERE. For queries that require aggregation and grouping, you also need to build GROUP BY and HAVING clauses.

[0247] 3. Refine each part of the SQL statement: Fill in each part of the SQL statement according to the detailed information in the intermediate state statement. For example, fill in the specific column name in the SELECT clause and the table name in the FROM clause. For the WHERE clause, it is necessary to generate specific filtering logic based on the conditional expression.

[0248] 4. Handling complex SQL components: For queries containing complex components, such as subqueries, joins, and nested queries, these components need to be handled specially and ensured to be correctly spliced ​​into SQL statements. It may also involve converting the logic in the intermediate state statements to comply with the requirements of SQL syntax.

[0249] 5. Optimize SQL statements: During the concatenation process, you may need to optimize the generated SQL statements to improve query efficiency and accuracy, including simplifying subqueries, optimizing join operations, and adjusting conditional expressions. The optimization steps can be adjusted according to the specific characteristics of the database and the performance requirements of the query.

[0250] 6. Generate the final SQL statement: After the above steps are processed, a complete and syntactically correct SQL statement is finally generated. This SQL statement can be directly executed in the database management system to retrieve and manipulate data.

[0251] The present invention converts the user's natural language query into a structured SQL statement, so that the user can interact with the database without having a deep understanding of SQL syntax.

[0252] like Figure 6 As shown, this embodiment provides a device for generating SQL statements from natural language statements, including:

[0253] A first model building module, used to build a language processing model based on data enhancement, wherein the language processing model includes a data enhancement module and a task training module;

[0254] A data processing module, used for acquiring first training data, inputting the first training data into the data enhancement module for data syntax analysis, information removal and data sampling, and obtaining second training data;

[0255] A training module, used for merging the first training data and the second training data to generate training data and sending the training data to the task training module for training until the language processing model converges;

[0256] A second model building module, used for building a language conversion model and embedding the language processing model into the language conversion model;

[0257] A decomposition module, used for receiving a natural language sentence to be converted through the language conversion model, and decomposing the natural language sentence to be converted through the language conversion model to obtain a simple sentence;

[0258] The statement generation module performs encoding and decoding based on the simple statement to generate an SQL statement.

[0259] The present invention establishes a language processing model based on data enhancement, performs grammatical analysis, information removal and data sampling on first training data to obtain second training data, merges the first training data and the second training data to generate training data and sends it to a task training module for training, decomposes natural language sentences through the language conversion model to obtain simple sentences, encodes and decodes the simple sentences to generate SQL sentences, which involves algorithms such as feedforward neural networks, relationship-aware networks, and long short-term memory networks, and can effectively process complex natural language sentences and improve the processing capabilities of complex database queries.

[0260] Furthermore, the data processing module includes:

[0261] Performing grammatical analysis on the SQL statements in the first training data to determine grammatical rules in the SQL statements;

[0262] Determine each component of the SQL statement according to the grammatical rules;

[0263] For each SQL statement, information is removed according to its components, and multiple sub-productions are generated accordingly;

[0264] Analyze the subproduction formula to obtain the corresponding SQL template classification result;

[0265] Select a preset number of SQL templates with the largest number of occurrences, and obtain their corresponding multiple different natural language statements;

[0266] The SQL template, the corresponding natural language statement and the table pattern are randomly sampled and synthesized to generate the second training data.

[0267] Furthermore, the data processing module also includes:

[0268] In one operation, a non-terminal symbol in the expression of the SQL statement is removed to obtain a subproduction formula;

[0269] Non-terminal symbols in the expression of the SQL statement are removed in sequence to obtain multiple sub-productions.

[0270] Furthermore, the training module also includes:

[0271] Establishing a first intermediate state statement between the natural language statement and the SQL statement;

[0272] Iterate and perform the following operations until the training stop condition is met:

[0273] Randomly masking the grammatical sequence of the first intermediate state sentence based on a masking mechanism;

[0274] Predicting and filling the randomly masked part in the first intermediate state statement according to the corresponding natural language statement in the training data and the SQL statement;

[0275] Calculate the loss function value based on the prediction result, and obtain the gradient value generated by gradient descent during the calculation process;

[0276] The parameters of the language processing model are updated according to the gradient value.

[0277] Furthermore, the decomposition module also includes:

[0278] The language conversion model uses an embedded language processing model to encode the natural language sentence to be converted into a vector representation and inputs it into a pre-set feedforward neural network to predict whether the natural language sentence to be converted contains multiple layers of complex semantics;

[0279] If the natural language sentence to be converted contains multiple layers of complex semantics, a semantic tree is established according to the natural language sentence to be converted;

[0280] Perform a depth-first traversal on the semantic tree to obtain simple sentences.

[0281] Furthermore, the statement generation module includes:

[0282] Parsing the simple statement and converting it into a statement graph representation;

[0283] Analyze the relationship between database tables and columns to obtain a graphical representation of the database schema;

[0284] Associating and matching the statement graph representation with the graph representation of the database schema to obtain an association graph;

[0285] Encoding the association graph using the language conversion model and a pre-established relationship-aware network to obtain a vector representation;

[0286] Decoding the vector representation using a long short-term memory network to generate a second intermediate state statement between the simple statement and the database pattern;

[0287] Infer and concatenate SQL statements based on the second intermediate state statement to generate a final SQL statement.

[0288] Furthermore, the statement generation module also includes:

[0289] constructing an input vector according to the association graph;

[0290] Encoding the input vector using the language conversion model to obtain an initial vector representation;

[0291] Position embedding for each word in a simple sentence;

[0292] The initial vector representation and position embedding are further embedded using the relationship-aware network to obtain the vector representation.

[0293] This embodiment further provides a computer storage medium, wherein the computer storage medium stores computer instructions, and when the computer instructions are called, they are used to execute the above method.

[0294] Although preferred embodiments of the present invention have been described, additional changes and modifications may be made to these embodiments by those skilled in the art once the basic inventive concepts are known. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention. Obviously, those skilled in the art may make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. A method for generating SQL statements from natural language statements, characterized in that: include: Establishing a language processing model based on data enhancement, wherein the language processing model includes a data enhancement module and a task training module; Acquire first training data, input the first training data into the data enhancement module for data syntax analysis, information removal, and data sampling, and obtain second training data; Merging the first training data and the second training data to generate training data and sending the training data to the task training module for training until the language processing model converges; Establishing a language conversion model, and embedding the language processing model into the language conversion model; The language conversion model receives a natural language sentence to be converted, and decomposes the natural language sentence to be converted through the language conversion model to obtain a simple sentence; Encoding and decoding are performed based on the simple statement to generate an SQL statement; The first training data includes multiple groups of sample data, and the sample data includes natural language statements, corresponding SQL statements, and associated table models; The task training module performs training according to the training data, including: Establishing a first intermediate state statement between the natural language statement and the SQL statement; Iterate and perform the following operations until the training stop condition is met: Randomly masking the grammatical sequence of the first intermediate state sentence based on a masking mechanism; Predicting and filling the randomly masked part in the first intermediate state statement according to the corresponding natural language statement in the training data and the SQL statement; Calculate the loss function value based on the prediction result, and obtain the gradient value generated by gradient descent during the calculation process; Updating parameters of the language processing model according to the gradient value; The language conversion model decomposes the natural language sentence to be converted to obtain simple sentences, including: The language conversion model uses an embedded language processing model to encode the natural language sentence to be converted into a vector representation and inputs it into a pre-set feedforward neural network to predict whether the natural language sentence to be converted contains multiple layers of complex semantics; If the natural language sentence to be converted contains multiple layers of complex semantics, a semantic tree is established according to the natural language sentence to be converted; Perform a depth-first traversal on the semantic tree to obtain simple sentences.

2. The method according to claim 1, characterized in that Inputting the first training data into the data enhancement module for data syntax analysis, information removal, and data sampling to obtain second training data, including: Performing grammatical analysis on the SQL statements in the first training data to determine grammatical rules in the SQL statements; Determine each component of the SQL statement according to the grammatical rules; For each SQL statement, information is removed according to its components, and multiple sub-productions are generated accordingly; Analyze the subproduction formula to obtain the corresponding SQL template classification result; Select a preset number of SQL templates with the largest number of occurrences, and obtain their corresponding multiple different natural language statements; The SQL template, the corresponding natural language statement and the table pattern are randomly sampled and synthesized to generate the second training data.

3. The method according to claim 2, characterized in that The SQL statement describes the grammatical rules through production formulas; the components of the SQL statement include non-terminal symbols and expressions, and the expression is a sequence of non-terminal symbols and terminal symbols; For each SQL statement, information is removed according to its components, and multiple sub-productions are generated accordingly, including: In one operation, a non-terminal symbol in the expression of the SQL statement is removed to obtain a subproduction formula; Non-terminal symbols in the expression of the SQL statement are removed in sequence to obtain multiple sub-productions.

4. The method according to claim 1, characterized in that: Encoding and decoding are performed based on the simple statement to generate an SQL statement, including: Parsing the simple statement and converting it into a statement graph representation; Analyze the relationship between database tables and columns to obtain a graphical representation of the database schema; Associating and matching the statement graph representation with the graph representation of the database schema to obtain an association graph; Encoding the association graph using the language conversion model and a pre-established relationship-aware network to obtain a vector representation; Decoding the vector representation using a long short-term memory network to generate a second intermediate state statement between the simple statement and the database pattern; Infer and concatenate SQL statements based on the second intermediate state statement to generate a final SQL statement.

5. The method according to claim 4, characterized in that Encoding the association graph using the language conversion model and a pre-established relationship-aware network to obtain a vector representation includes: constructing an input vector according to the association graph; Encoding the input vector using the language conversion model to obtain an initial vector representation; Position embedding for each word in a simple sentence; The initial vector representation and position embedding are further embedded using the relationship-aware network to obtain the vector representation.

6. A device for generating SQL statements from natural language statements, characterized in that: include: A first model building module, used to build a language processing model based on data enhancement, wherein the language processing model includes a data enhancement module and a task training module; A data processing module, used for acquiring first training data, inputting the first training data into the data enhancement module for data syntax analysis, information removal and data sampling, and obtaining second training data; A training module, used for merging the first training data and the second training data to generate training data and sending the training data to the task training module for training until the language processing model converges; A second model building module, used for building a language conversion model and embedding the language processing model into the language conversion model; A decomposition module, used for receiving a natural language sentence to be converted through the language conversion model, and decomposing the natural language sentence to be converted through the language conversion model to obtain a simple sentence; A statement generation module, encoding and decoding the simple statement to generate an SQL statement; The first training data includes multiple groups of sample data, and the sample data includes natural language statements, corresponding SQL statements, and associated table models; The task training module performs training according to the training data, including: Establishing a first intermediate state statement between the natural language statement and the SQL statement; Iterate and perform the following operations until the training stop condition is met: Randomly masking the grammatical sequence of the first intermediate state sentence based on a masking mechanism; Predicting and filling the randomly masked part in the first intermediate state statement according to the corresponding natural language statement in the training data and the SQL statement; Calculate the loss function value based on the prediction result, and obtain the gradient value generated by gradient descent during the calculation process; Updating parameters of the language processing model according to the gradient value; The language conversion model decomposes the natural language sentence to be converted to obtain simple sentences, including: The language conversion model uses an embedded language processing model to encode the natural language sentence to be converted into a vector representation and inputs it into a pre-set feedforward neural network to predict whether the natural language sentence to be converted contains multiple layers of complex semantics; If the natural language sentence to be converted contains multiple layers of complex semantics, a semantic tree is established according to the natural language sentence to be converted; Perform a depth-first traversal on the semantic tree to obtain simple sentences.

7. A computer storage medium, characterized in that: The computer storage medium stores computer instructions, and when the computer instructions are called, they are used to execute the method according to any one of claims 1 to 5.