A method for updating an SQL database translated by machine learning artificial intelligence

Through machine learning artificial intelligence methods, SQL statements are generated using the LSTM network and graph attention mechanism, and converted into natural language through translation models, solving the problem of natural language to SQL statement translation and achieving the improvement of database security management.

CN115114313BActive Publication Date: 2025-05-30黄竑僖
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210911352.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-30
Publication Date
2025-05-30
Estimated Expiration
2042-07-30

AI Technical Summary

Technical Problem

The prior art is difficult to effectively understand and translate natural language into SQL statements, resulting in difficulties in database maintenance and security management.

Method used

Using machine learning artificial intelligence methods, the input information is encoded through a single-layer LSTM network and a double-layer LSTM network, SQL statements are generated in combination with the graph attention mechanism, and the abstract syntax tree is converted into natural language through the training of the translation model including generators and discriminators.

Benefits of technology

It realizes the rapid extraction of key elements in SQL statements, translates SQL to natural language, helps users identify potential risks, and improves database security management capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115114313B_ABST
    Figure CN115114313B_ABST
Patent Text Reader

Abstract

The present invention discloses an update method for a machine learning artificial intelligence translation SQL database. By receiving input information and using a single-layer LSTM network to encode the current sentence of the input information and a double-layer LSTM network to encode the conversation history before the current sentence, an attention mechanism is adopted to obtain a fused SQL statement generated by the current sentence vector and the context sentence vector above. The SQL statement is input into the translation model for training. The generator parameters are set, and the discriminator is trained using the samples generated by the generator and the real samples. The discriminator parameters are set, and the discriminant result is used as a reward to guide the training of the generator until the translation model converges to obtain an abstract syntax tree. The abstract syntax tree is converted into natural language with a preset grammar habit through a tree parser. SQL translation can convert SQL into natural language, enabling users or administrators to quickly discover potential risks in SQL statements and avoid database security problems.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of databases, and particularly relates to an update method for a machine learning artificial intelligence translation SQL database. Background Art

[0002] In recent years, with the continuous accumulation of big data in the Internet era, the improvement of computer computing power, and the proposal of relevant algorithms, artificial intelligence has re-entered the path of vigorous development. As an important branch of computer science, it has increasingly become an indispensable part of today's high-tech industries and gradually penetrated into various industries to play an important role. SQL, also known as Structured Query Language, can manage data stored in a relational database management system. SQL can benefit different types of users, including application developers, database administrators, managers, and end-users. The role of SQL is to provide an interface for operating a relational database, and all SQL statements are equivalent to instructions for operating the database.

[0003] Natural language processing is one of the core fields of artificial intelligence, enabling a computer to understand and use human language to achieve direct communication between natural language and the computer. The process of translating natural language into SQL statements is to convert natural language into a meaning representation that the machine can understand. In various natural language processing tasks, the machine needs to have a full understanding of human language. However, human language is usually complex. In many cases, it not only expresses the literal meaning but also has many connections with the outside world. Sometimes, many words are even omitted according to the context. This complex feature makes the process of the machine understanding human language extremely difficult. Moreover, due to the complex syntax structure of the SQL language, it is easy to increase the difficulty of the later maintenance of the database. And the maintenance personnel and supervisors of the database are often not professional database programmers, making it difficult to understand the functions of complex SQL statements, resulting in database security risks. Summary of the Invention

[0004] In view of this, the present invention provides an update method for a machine learning artificial intelligence translation SQL database that helps users quickly extract keywords, translate SQL into natural language, and can timely detect risks existing in SQL statements, to solve the above-mentioned existing technical problems, and specifically adopts the following technical solutions to achieve.

[0005] The present invention provides an update method for a machine learning artificial intelligence translation SQL database, including the following steps:

[0006] Receive the input information and perform encoding on the current sentence of the input information using a single-layer LSTM network and encoding on the dialogue history before the current sentence using a two-layer LSTM network. Among them, the single-layer LSTM network encodes all sentences in the above text at the word level, and the encoded output result is used as the input of the two-layer LSTM network. The two-layer LSTM network encodes the dialogue segment above the current sentence at the sentence level;

[0007] Adopt a graph attention mechanism with unidirectional information flow to fuse the obtained current sentence vector and the above-context sentence vector, decode the vector, and generate an SQL statement from the current sentence according to the above-context;

[0008] Input the SQL statement into the translation model for training. The translation model includes a generator and a discriminator. Set the generator parameters and use the samples generated by the generator and the real samples to train the discriminator, and update the discriminator parameters;

[0009] Set the discriminator parameters and use the discrimination result of the discriminator as a reward to guide the training of the generator, and update the generator parameters until the translation model converges to obtain an abstract syntax tree, and convert the abstract syntax tree into natural language with a preset grammar habit through a tree parser.

[0010] As a further improvement of the above technical solution, setting the discriminator parameters and using the discrimination result of the discriminator as a reward to guide the training of the generator includes:

[0011] Use the training word vector table to represent natural language questions and associated data tables, and adopt q = [q 1 , q 2 , q 3 ... q n to represent the input of the natural language question part;

[0012] Set that the data tables associated with the question use "||" to connect different data table units. The data table units include SQL keywords, column names in the table, and specific values, which are represented as where represents the unit in the kth data table;

[0013] Encode the data table input and the natural language question input respectively and input the encoded output into a two-layer LSTM network. In the first-layer bidirectional LSTM network, calculations are performed separately on the data table side and the natural language question side, and its expression is Input the output of the first-layer bidirectional LSTM network into the second-layer bidirectional LSTM network continuously, and its expression is For the question side, splice the encodings in two directions to obtain the encoding representation of the final question, that is For the data table side, and are spliced to obtain as the k-th data table unit representation.

[0014] As a further improvement of the above technical solution, an attention mechanism is used to obtain the natural language question encoding most relevant to each unit in the data table. For the data table unit regarding the natural language question encoding the attention score a k,i is expressed as where e* is a fully connected neural network of one layer, and then through obtain a new data table unit representation to replace the previous

[0015] The LSTM network decoder using attention selects the unit to be copied from the input sequence at each time step t. The probability of selecting the i-th unit u in the input sequence at the t-th time step is given by the expression i where S represents the decoder hidden state at the t-th time step, t represents the encoded hidden state of the data table unit u i and W a a represents the model parameters to be trained.

[0016] As a further improvement of the above technical solution, the construction process of the network model of the attention mechanism includes:

[0017] Construct a graph G according to the sorting result of the original sentences. The preset vertex set V is a set of n sentences, and the set of edges E is the relationship between sentences. The relationship between sentences is modeled by calculating the sentence similarity, and is used to represent the adjacency matrix. The importance score of the sentence is calculated by recursively using the global information on the graph, and its expression is f(t + 1) = λWD -1 f(t) + (1 - λ)y,, where represents the rank scores of n sentences, f(t) represents the rank scores after the t-th iteration, D represents a diagonal matrix, and the value of the (i, i) element is equal to the sum of the i-th column of the adjacency matrix W;

[0018] If h i is used as the vector of the sentence s i and where M is the parameter matrix to be learned, λ represents a damping factor, and all elements are equal to 1 / n, so the value of f can be expressed as f = (1 - λ)(i - λWD -1) -1 y, sentence s i The importance score of i is determined by its relationships with all other sentences.

[0019] As a further improvement of the above technical solution, set the generator parameters and use the samples generated by the generator and the real samples to train the discriminator, and update the discriminator parameters, including:

[0020] Use the trained word vectors to convert the SQL query statement input to the discriminator into a semantic representation x in the form of a continuous vector 1 ,...x T , splice T words together to get ε 1: , and its expression is where is the k-dimensional word vector representation, represents the splicing operation, represents a matrix of dimension T×k, and then use the convolutional kernel to perform a convolution operation on words with a window size of l to obtain a new feature map, and its expression is where represents the convolution operation, which is equal to the sum after multiplying each part separately, b is the bias term, P represents the non-linear function, and different numbers of convolutional kernels with different window sizes are used to extract different features.

[0021] As a further improvement of the above technical solution, convert the abstract syntax tree into natural language in a preset grammar habit through a tree parser, including:

[0022] Translate the method names, field names, and table names in the translation result into Chinese according to the database modeling table and database method table corresponding to the grammar abstract tree. When translating, determine the type of the content to be translated and search for the corresponding data table to complete the translation of the remaining English part into Chinese.

[0023] As a further improvement of the above technical solution, the word order needs to be adjusted during the translation process. The adjustment of the word order is implemented using a stack. Put the sentence whose word order needs to be adjusted into the stack and take it out from the stack when returning. Use a tree parser to complete the translation process.

[0024] As a further improvement of the above technical solution, the abstract syntax tree represents the input in the form of a tree and is parsed by the parser in the form of a tree to convey syntactic information, and the syntactic information includes keywords, fields, tables, and method names.

[0025] As a further improvement of the above technical solution, parse the SQL statement query generated by the model by the tree parser, and the process of parsing the SQL query includes:

[0026] Obtain the generated SQL query statement, divide the SQL keywords and data table units into several groups and mark each group, and combine them into new units according to preset rules to obtain the data table structure, where the data table structure includes table-column relationships and column-unit relationships. The table-column relationship is used to identify whether a column belongs to a table, and the column-unit relationship indicates whether it belongs to a column. The subquery is executed only when the table-column relationship and the column-unit relationship are satisfied.

[0027] As a further improvement of the above technical solution, set the string type of the data table structure. The string type includes two types: number and text. If the type of the digital content in the data table and the SQL keywords connecting the numbers is number, otherwise it is marked as text type. The subquery statement is executed only when the string types of all its SQL keywords and data table units match.

[0028] The present invention provides an update method for a machine learning artificial intelligence translation SQL database. By receiving input information and encoding the current sentence of the input information through a single-layer LSTM network and encoding the conversation history before the current sentence through a double-layer LSTM network, a graph attention mechanism with unidirectional information flow is used to fuse the obtained current sentence vector and the context sentence vector above, decode the vector, and generate an SQL statement from the current statement according to the context above. The SQL statement is input into the translation model for training. The translation model includes a generator and a discriminator. Set the generator parameters and use the samples generated by the generator and the real samples to train the discriminator, update the discriminator parameters, set the discriminator parameters and use the discrimination result of the discriminator as a reward to guide the training of the generator, and update the generator parameters until the translation model converges to obtain an abstract syntax tree. The abstract syntax tree is converted into natural language with a preset grammar habit through a tree parser, and the conversation state at the current moment is added to the LSTM network as external knowledge, realizing the preservation and memory of important semantic clue information in the context above, so as to accurately generate SQL statements. It helps users quickly extract key elements such as tables, query conditions, and fields. SQL translation can convert SQL into natural language, enabling users or administrators to quickly discover potential risks in SQL statements and avoid database security problems. Brief Description of the Drawings

[0029] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following will briefly introduce the drawings required to be used in the embodiments. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as limiting the scope. For those of ordinary skill in the art, other related drawings can be obtained based on these drawings without creative efforts.

[0030] Figure 1Flowchart of the update method for the machine learning artificial intelligence translation SQL database provided by the present invention;

[0031] Figure 2 Structural block diagram of the translation model provided by the present invention. Detailed implementation manners

[0032] The embodiments of the present invention will be described in detail below. The examples of the embodiments are shown in the drawings, where the same or similar reference numerals represent the same or similar elements or elements with the same or similar functions from beginning to end. The embodiments described below with reference to the drawings are exemplary and are only used to explain the present invention and should not be construed as a limitation to the present invention.

[0033] Refer to Figure 1 , the present invention provides an update method for a machine learning artificial intelligence translation SQL database, including the following steps:

[0034] S1: Receive input information and perform encoding on the current sentence of the input information by a single-layer LSTM network and encoding on the conversation history before the current sentence by a double-layer LSTM network. Among them, the single-layer LSTM network encodes all the sentences in the above text at the word level, and the output result obtained by encoding is used as the input of the double-layer LSTM network. The double-layer LSTM network encodes the conversation segment above the current sentence at the sentence level;

[0035] S2: Use the graph attention mechanism of unidirectional information flow to fuse the obtained current sentence vector and the above-context sentence vector, decode the vector, and generate an SQL statement from the current statement according to the above context;

[0036] S3: Input the SQL statement into the translation model for training. The translation model includes a generator and a discriminator. Set the generator parameters and use the samples generated by the generator and the real samples to train the discriminator, and update the discriminator parameters;

[0037] S4: Set the discriminator parameters and use the discrimination result of the discriminator as a reward to guide the training of the generator, and update the generator parameters until the translation model converges to obtain an abstract syntax tree, and convert the abstract syntax tree into a natural language with a preset grammar habit through a tree parser.

[0038] In this embodiment, the translation process needs to adjust the word order, and the adjustment of the word order is implemented using a stack. The sentence that needs to adjust the word order is put into the stack and taken out from the stack when returning, and a tree parser is used to complete the translation process. The method name, field name and table name in the translation result are translated into Chinese according to the database modeling table and database method table corresponding to the syntax abstract tree. During the translation, the type of the translated content is determined, and the corresponding data table is searched to complete the translation of the remaining English part into Chinese. The abstract syntax tree represents the input in the form of a tree, and is parsed by the parser in the form of a tree to convey syntactic information, which includes keywords, fields, tables and method names. Simple SQL query statements can be translated by word replacement, but slightly more complex SQL statements cannot be translated by the Nth replacement method. Even people familiar with SQL find it difficult to understand. However, by converting SQL statements into an abstract syntax tree with a structured hierarchy, it is easy to read and understand. Each keyword in the general structure of SQL query corresponds to an execution process of SQL. The general keywords are SELECT, FROM, WHERE, GROUP BY, HAVING, and ORDER BY. In multiple rounds of dialogue, each natural language sentence spoken by the user is parsed to generate the corresponding SQL statement, namely the SQL statement generation problem. Generating SQL statements from natural language sentences is a mapping process, which can be seen as a mapping from a natural language set to a structured language set. The input of the mapping is a natural language sentence. Each natural language sentence comes from a natural language set. Each word in ω i All belong to a known dictionary D N , the output of the mapping is a sequence of text Each sequence text output comes from a structured language set, and each word in the sequence text comes from a known dictionary D s Multi-round dialogue is different from single-round dialogue. It is no longer a question-and-answer format. Instead, it is necessary to model the historical information of the previous round of dialogue to solve possible reference disambiguation problems, making the generated SQL statements more accurate and more in line with the user's true intentions.

[0039] It should be noted that the first layer is a single-layer LSTM network, and the second layer is a double-layer LSTM network. The long short-term memory neural network, or LSTM, is a recurrent neural network with a load. The LSTM network uses a cell state c t To adjust the entire structure, so that the memory capacity of the entire network is enhanced, from the cell state c t-1 To cell state c tIt will undergo some linear operations and no non - linear operations. The memory storage unit of the LSTM network consists of an input gate, an output gate, a forget gate, and a self - recurrent connection node. The LSTM network maps the input sequence to a vector of a fixed dimension, and then uses another LSTM to decode the target sequence from the vector. The LSTM can solve the sequence learning problem of general sequences. The specific process is as follows: According to the LSTM, the input sequence is read once at each moment to obtain a vector representation of the sentence with a fixed dimension. Another LSTM network is used to extract and parse the output sequence from this vector. The second LSTM is a recursive neural network language model conditional on the input sequence. Since the LSTM network has the ability to learn data with long - distance temporal correlations, it can overcome the problem of the distance time difference between the input sequence and the output sequence.

[0040] It should be understood that when constructing an abstract syntax tree for the SQL language, the main body of the query in SQL needs to be considered and the unnecessary parts are ignored. The most important ones are tables, fields, views, and operations on tables, fields, and views. The query statement is a complex statement in SQL statements and can be in a nested and recursive manner with a very flexible syntax structure. The next task of SQL translation is to generate the translation result according to the abstract syntax tree. The nodes on the tree are converted into natural language according to their meanings through a tree parser. Since SQL is an English - based query language with different language habits from Chinese, the word order needs to be adjusted during the translation process to make the sentence smoother and more fluent for normal reading. Information such as query conditions is parsed into an abstract syntax tree, and it is necessary to check for risks in the language and identify risks such as incorrect conditions and SQL injection. Encoding the dialogue history requires taking additional measures to strengthen the memory of important information in the dialogue history. An LSTM network with enhanced memory is used to save the dialogue state at the current moment as external knowledge, and the constraint information corresponding to the SQL statement is stored in this dialogue state, thereby improving the accuracy of the SQL statement.

[0041] Optionally, set the discriminator parameters and use the discriminator's discrimination result as a reward to guide the training of the generator, including:

[0042] Use the training word vector table to represent natural language questions and associated data tables. Let q = [q 1 ,q 2 ,q 3 ...q n represent the input of the natural language question part;

[0043] Set the data tables associated with the question to connect different data table units using "||". The data table units include SQL keywords, column names in the table, and specific values, which are represented as where represents the unit in the k - th data table;

[0044] Encode the data table input and the natural language question input respectively, and input the encoded output into a two-layer LSTM network. In the first-layer bidirectional LSTM network, calculations are performed separately on the data table side and the natural language question side, and its white expression is The output of the first-layer bidirectional LSTM network Continue to input into the second-layer bidirectional LSTM network, and its expression is For the question side, concatenate the encodings in two directions to obtain the encoding representation of the final question, that is For the data table side and Concatenate to get As the representation of the k-th data table unit representation.

[0045] In this embodiment, the attention mechanism is used to obtain the natural language question encoding most relevant to each unit in the data table. The data table unit Regarding the natural language question encoding The attention score a k,i , and its expression is where e* is a one-layer fully connected neural network, and After that, through Get a new data table unit representation to replace the previous The LSTM network decoder using attention selects the unit to be copied from the input sequence at each time step t. The probability of selecting the i-th unit u i in the input sequence at the t-th time step is given by the expression where S t represents the decoder hidden state at the t-th time step, represents the encoded hidden state of the data table unit u i , and W a represents the model parameters to be trained.

[0046] Refer to Figure 2, It should be noted that the generator is used to translate natural language questions into SQL query statements, and the syntax parser is used to evaluate and guide the training of the generator. The specific process is as follows: The generator takes natural language questions and data tables to be queried as inputs, generates SQL statements, and then the SQL syntax parser parses the output of the generator and gives the generator rewards to guide the training of the generator. The generator includes a representation layer, an encoding layer, an interaction layer, and a decoding layer. The translation model includes a generator, a discriminator, and a syntax parser. The characteristics of SQL statements are as follows: An SQL query consists of multiple subqueries, each subquery is guided by an SQL keyword or consists of other subqueries. An SQL query can be executed using a data table. Based on the fact that each subquery is executable and conforms to the structure and semantic constraints of the data table. The SQL query generated by the model is parsed by this syntax parser, which not only interprets the SQL syntax but also interprets the structure and semantic constraints of the corresponding data table. At the beginning of training, the generator model on the training set is pre-trained using maximum likelihood estimation. After pre-training, the generator model and the discriminator model are alternately trained. When the generator is updated and trained through g steps, it is necessary to fix the parameters of the generator and re-train the discriminator to maintain good synchronization with the generator. When training the discriminator, the positive samples come from the given data set, and the negative samples come from the generator. To maintain balance, the model is set to generate the same number of negative samples as positive samples every d steps. To reduce the variability of the estimation, the model uses different negative sample sets and positive sample sets for training.

[0047] Optionally, the construction process of the network model of the attention mechanism includes:

[0048] Construct a graph G according to the sorting result of the original sentences. The preset vertex set V is a set of n sentences, and the set of edges E is the relationship between sentences. The relationship between sentences is modeled through sentence similarity calculation, and is used to represent the adjacency matrix. The importance score of a sentence is calculated by recursively using the global information on the graph, and its expression is f(t + 1) = λWD -1 f(t) + (1 - λ)y,, where represents the rank scores of n sentences, f(t) represents the rank scores after the t-th iteration, D represents a diagonal matrix, and the value of the (i, i) element is equal to the sum of the i-th column of the adjacency matrix W;

[0049] If h i is used as the vector of sentence s i , and where M is a parameter matrix to be learned, λ represents a damping factor, and all elements are equal to 1 / n. Thus, the value of f can be expressed as f = (1 - λ)(i - λWD -1) -1 y, sentence s i The importance score of i is determined by the relationship between h and all other sentences.

[0050] In this embodiment, the attention mechanism is the selective attention mechanism of human vision. When a human is looking at a picture, they usually do not carefully examine every detail of the painting from beginning to end in sequence, but quickly scan the whole picture to find the local area that needs to be carefully observed, that is, to find the location of the attention focus. People will pay focused attention to such a local area, concentrate their attention within this area to obtain more detailed information, and do not need to pay too much attention to other areas. The selective attention mechanism of vision allows people to quickly learn valuable information in a short time according to limited attention resources. This method can greatly improve the efficiency and accuracy of visual information processing. In the field of natural language processing, the attention mechanism can be described as a mapping from a query statement to a set of key-value pairs.

[0051] Optionally, set the generator parameters and use the samples generated by the generator and the real samples to train the discriminator, and update the discriminator parameters, including:

[0052] Use the trained word vectors to convert the SQL query statement input to the discriminator into a semantic representation x in the form of a continuous vector 1 ,...x T , splice T words together to get ε 1:T , and its expression is where is the k-dimensional word vector representation, represents the splicing operation, represents a matrix of T×k dimensions, and then use the convolution kernel to perform a convolution operation on words with a window size of l to obtain a new feature map, and its expression is where represents the convolution operation, which is equal to the sum after multiplying each part separately. b is the bias term, and P represents the non-linear function. Different numbers of convolution kernels with different window sizes are used to extract different features.

[0053] In this embodiment, the SQL statements generated by the model are parsed by a tree parser. The process of parsing the SQL query includes: obtaining the generated SQL query statement, dividing the SQL keywords and data table units into several groups and marking each group, and combining them into new units according to preset rules to obtain a data table structure. The data table structure includes a table-column relationship and a column-unit relationship. The table-column relationship is used to identify whether a column belongs to a table, and the column-unit relationship indicates whether it belongs to a column. The subquery is executed only when the table-column relationship and the column-unit relationship are satisfied. Set the string type of the data table structure. The string type includes two types: number and text. If the numeric content in the data table and the type of the SQL keyword connecting the numbers are of type number, otherwise it is marked as type text. The subquery statement is executed only when the string types of all its SQL keywords and data table units match.

[0054] It should be noted that when the SQL statements generated by the model pass through the syntax parser, a score reward is given based on the set checkpoints. Suppose the output of the generator is "SELECT MAX gold WHERE silver>3 and bronze<6". First, generalize this SQL statement, and then push it onto the stack in the order of the words. Combine adjacent elements that can be combined. For example, MAX and gold can be combined into $A_S, that is, when combining, judge how much reward can be obtained here. $A_S and SELECT can be further combined into $Sel_S, and so on. When no further combination is possible, pop the top element of the stack until the stack is empty. Use the syntax parser and the corresponding reward mechanism to evaluate the SQL query statements generated by the generator at multiple granularity levels, and use the reward score as the reinforcement target to improve the syntax and execution of the generated SQL query statements, generating the sample y i The expression for the expected reward score of

[0055] is: i where N represents the number of sampled SQL query statements generated, p(y i ) is the probability that y is generated by the model, i represents the weight of the i-th sample, r(y g , y i ) is the reward function, y g is the SQL query statement generated by the generator, y i represents the correct answer. The reward score of y g is calculated through r(y i ), r b represents the baseline reward. Its role is to encourage the model to generate SQL query statements with rewards greater than r b , and not to encourage the model to generate SQL query statements with reward scores less than r bThe SQL query statement.

[0056] It should be understood that SQL analysis technology is the core of database security. It can help users quickly extract fields, tables, views, and operations on them from SQL statements, thereby quickly identifying the risks of SQL statements and translating the SQL statements into natural language to make them easier to understand, which helps to achieve security management.

[0057] In all the examples shown and described here, any specific value should be construed as merely exemplary, not as a limitation. Therefore, other examples of the exemplary embodiments may have different values.

[0058] It should be noted that like reference numerals and letters indicate like items in the following figures. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.

[0059] The above-described embodiments merely represent several implementation manners of the present invention. The description thereof is relatively specific and detailed, but it should not be construed as a limitation on the scope of the present invention. It should be pointed out that for those of ordinary skill in the art, without departing from the concept of the present invention, several modifications and improvements can still be made, and these all belong to the protection scope of the present invention.

Claims

1. A method for updating a machine learning artificial intelligence translation SQL database, characterized in that, it includes the following steps: Receiving input information and performing encoding on the current sentence of the input information by a single-layer LSTM network and encoding on the conversation history before the current sentence by a double-layer LSTM network. Among them, the single-layer LSTM network encodes all sentences in the above text at the word level, and the output result obtained by encoding is used as the input of the double-layer LSTM network. The double-layer LSTM network encodes the entire above text conversation segment at the sentence level; Using a graph attention mechanism with unidirectional information flow to fuse the obtained current sentence vector and the above context sentence vector, decoding the vector, and generating an SQL statement from the current statement according to the above context; Inputting the SQL statement into a translation model for training. The translation model includes a generator and a discriminator. Set the generator parameters and use the samples generated by the generator and the real samples to train the discriminator, and update the discriminator parameters; Set the discriminator parameters and use the discrimination result of the discriminator as a reward to guide the training of the generator, and update the generator parameters until the translation model converges to obtain an abstract syntax tree, and convert the abstract syntax tree into natural language with a preset grammar habit through a tree parser; Setting the discriminator parameters and using the discrimination result of the discriminator as a reward to guide the training of the generator, including: Represent a natural language question and an associated data table using a trained word vector table, and use q = [q 1 , q 2 , q 3 ... q n to represent the input of the natural language question part; The data tables associated with the setting problem use "||" to connect different data table units. The data table units include SQL keywords, column names in the table, and specific values, which are represented as where represents the unit in the k-th data table; Encode the data table input and the natural language question input separately and input the encoded outputs into a two-layer LSTM network. In the bidirectional LSTM network of the first layer, calculations are performed separately on the data table side and the natural language question side, and its expression is Input the output of the first-layer bidirectional LSTM network Continue to input it into the second-layer bidirectional LSTM network, and its expression is For the question side, concatenate the encodings in two directions to obtain the encoding representation of the final question, that is For the data table side and Concatenate to get As the representation of the k-th data table unit ; Setting the generator parameters and using the samples generated by the generator and the real samples to train the discriminator, and updating the discriminator parameters, including: Convert the SQL query statement input to the discriminator into a semantic representation x in the form of a continuous vector using the trained word vectors 1 ,...x T , splice T words together to obtain ε 1:T , and its expression is where is the k-dimensional word vector representation, represents the splicing operation, represents a matrix of dimension T×k, and then use the convolutional kernel perform a convolution operation on the words with a window size of l to obtain a new feature map, and its expression is where represents the convolution operation, which is equal to the sum after multiplying each part separately, b is the bias term, and P represents the non-linear function. Different numbers of convolutional kernels with different window sizes are used to extract different features.

2. The method for updating a machine learning artificial intelligence translation SQL database according to claim 1, characterized in that, it further includes: Obtain the natural language question encoding most relevant to each cell in the data table using the attention mechanism, where the data table cell Regarding the natural language question encoding The attention score a k,i , and its expression is where e(*) is a fully connected neural network layer, and After that, through Obtain a new data table cell representation to replace the previous The LSTM network decoder using attention selects the cell to be copied from the input sequence at each time step t, and the probability of selecting the i-th cell u in the input sequence at the t-th time step is given by the expression i where S t represents the decoder hidden state at the t-th time step, represents the data table cell u i through the encoded hidden state, and W a represents the model parameters to be trained.

3. The method for updating a machine learning artificial intelligence translation SQL database according to claim 2, characterized in that, The construction process of the network model of the attention mechanism includes: Construct a graph G according to the sorting result of the original sentences. Assume that the preset vertex set V is a set of n sentences, and the edge set E is the relationship between sentences. Model the relationship between sentences through sentence similarity calculation, and use to represent the adjacency matrix. Calculate the importance score of sentences by recursively using the global information on the graph. Its expression is f(t + 1) = λWD -1 f(t) + (1 - λ)y, where represents the rank scores of n sentences, f(t) represents the rank scores after the t-th iteration, D represents a diagonal matrix, and the value of the (i, i) element is equal to the sum of the i-th column of the adjacency matrix W; If h is adopted i as the vector of sentence s i and where M is the parameter matrix to be learned and λ represents a damping factor and all elements are equal to 1 / n, so the value of f can be expressed as f = (1 - λ)(i - λWD -1 ) - 1 y, the importance score of sentence s i is determined by the relationship between h i and all other sentences 4. The method for updating a machine learning artificial intelligence translation SQL database according to claim 1, converting the abstract syntax tree into natural language with a preset grammar habit through a tree parser, including: Translating the method names, field names, and table names in the translation result into Chinese according to the database modeling table and database method table corresponding to the grammar abstract tree. During translation, determine the type of the content to be translated, and look up the corresponding data table to translate the remaining English part into Chinese.

5. The method for updating a machine learning artificial intelligence translation SQL database according to claim 4, the translation process requires adjusting the word order, and the adjustment of the word order is implemented using a stack. Put the sentence whose word order needs to be adjusted into the stack, and take it out of the stack when returning. The translation process is completed using a tree parser.

6. The method for updating a machine learning artificial intelligence translation SQL database according to claim 1, the abstract syntax tree represents the input in the form of a tree and is parsed by a parser in the form of a tree to convey syntactic information. The syntactic information includes keywords, fields, tables, and method names.

7. The method for updating a machine learning artificial intelligence translation SQL database according to claim 1, querying the SQL statement generated by the model by a tree parser, and the process of parsing the SQL query includes: Obtain the generated SQL query statement, divide the SQL keywords and data table units into several groups and mark each group, and combine them into new units according to preset rules to obtain the data table structure, where the data table structure includes table-column relationships and column-unit relationships. The table-column relationship is used to identify whether a column belongs to a table, and the column-unit relationship indicates whether it belongs to a column. The subquery is executed only when the table-column relationship and the column-unit relationship are satisfied.

8. The method for updating a SQL database by machine learning artificial intelligence translation according to claim 1, further comprises: Set the string type of the data table structure. The string type includes two types: number and text. If the type of the numeric content in the data table and the SQL keywords connecting the numbers is number, otherwise it is marked as text type. The subquery statement is executed only when the string types of all its SQL keywords and data table units match.

Citation Information

Patent Citations

  • Method for generating structured query statement based on natural language

    CN111813802A

  • Method and system for converting graph of SQL to text into natural language statement

    CN112487020A