A graph-based translation method from natural language questions to SQL

By adopting a deep learning model based on graph computing in the NL2SQL model, graph representation vectors are obtained and joint encoding are performed, the problem that existing models fail to effectively utilize knowledge graph structure information is solved, and the performance and expression ability of the model are improved.

CN115062052BActive Publication Date: 2025-02-07UNIV OF ELECTRONICS SCI & TECH OF CHINA
View PDF 1 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

The existing NL2SQL model fails to effectively integrate the graph structure information when using the knowledge graph, resulting in a decrease in expression ability and affecting the model performance.

Method used

A deep learning model based on graph calculation is used to obtain graph characterization vectors and add them to the coding process of the NL2SQL model to form joint encoding to enhance the feature expression ability of the intermediate vector.

Benefits of technology

Through joint encoding, the performance of the NL2SQL model is improved, so that it can better generate SQL query statements and make full use of the data semantic information of the knowledge graph.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115062052B_ABST
    Figure CN115062052B_ABST
Patent Text Reader

Abstract

The present invention discloses a graph-based translation method from natural language questions to SQL, including: based on the metadata knowledge graph of the SQL database, using a deep learning model 1 to obtain the representation of the tables and columns of the database; using a deep learning model 2 to encode the tables and columns of the database to obtain its representation containing graph structure information; using a deep learning model 3 to obtain the representation of the natural language question; using a deep learning model 4 to jointly encode the representation of the natural language question, the representation of the table and the column to obtain an intermediate semantic vector; decoding the intermediate semantic vector using a deep learning model 5 to generate an SQL statement. The present invention obtains a graph representation of database tables and columns based on the metadata knowledge graph of the database, and encodes them together with the representation of the natural language question, and decodes them by combining a deep learning model with a probability model, which can make full use of the rich data semantic information of the knowledge graph and better generate SQL query statements.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of natural language processing, and in particular to a graph-based translation method from natural language questions to SQL. Background Art

[0002] In recent years, natural language processing technology based on deep learning has made a lot of progress, and the achievements of machine translation technology have become more and more abundant. Based on machine translation technology, by translating natural language into SQL query statements, this task is often called Text-to-SQL or NL2SQL (Natural Language to SQL). Usually, the machine learning model designed for this task adopts the "encoder-decoder" framework. The encoder-decoder model is currently widely used in the field of deep learning, especially in the field of machine translation. Its core idea is: encode the source data through the encoder to obtain an intermediate vector containing the features of the complete input data; then decode the intermediate vector through the decoder to generate the target result. In natural language processing tasks, for input data in the form of text sequences, recurrent neural networks (Recurrent Neural Networks) or Transformer models are often used as encoders and decoders. The Transformer model is based on the attention mechanism and can be calculated in parallel. Compared with the recurrent neural network, which cannot be calculated in parallel, the model training speed is greatly improved.

[0003] Knowledge Graph, known as knowledge domain visualization or knowledge domain mapping map in the library and information industry, is a series of various graphics that show the development process and structural relationship of knowledge. It uses visualization technology to describe knowledge resources and their carriers, and to mine, analyze, construct, draw and display knowledge and their mutual connections. Specifically, knowledge graph is a modern theory that combines the theories and methods of applied mathematics, graphics, information visualization technology, information science and other disciplines with methods such as metrology citation analysis and co-occurrence analysis, and uses visualized graphs to vividly display the core structure, development history, frontier fields and overall knowledge architecture of the discipline to achieve the purpose of multidisciplinary integration. It has the following main features: 1. The more times users search and the wider the scope, the more information and content the search engine can obtain. 2. Give new meaning to strings, not just simple strings. 3. Integrate all disciplines to facilitate the coherence of user searches. 4. Find more accurate information for users, make more comprehensive summaries and provide more in-depth and relevant information. 5. Systematically display the knowledge system related to keywords to users. 6. Draw useful information from the entire Internet so that users can obtain more relevant public resources. The knowledge graph is essentially a knowledge base called a semantic network, that is, a knowledge base with a directed graph structure. In simple terms: a knowledge graph is a data structure composed of entities, relationships, and attributes, generally consisting of entities, relationships, and triples describing the corresponding relationships between entities and relationships.

[0004] Knowledge graphs systematically extract and organize knowledge, laying a solid foundation for efficient knowledge management. They have been widely used. Typical large-scale knowledge graphs include YAGO, DBpedia, Freebase, etc. At the same time, scholars in various fields also support research in their fields by establishing small-scale knowledge graphs in specific fields.

[0005] In recent years, many studies on NL2SQL tasks have adopted knowledge graph technology, but most of them are limited to using knowledge graphs for querying, such as querying the alignment relationship between keywords in natural language questions and database patterns. The structural information contained in the graph itself is not utilized, and the representation vector of the graph is not added to the encoding process. Knowledge graphs contain rich potential knowledge. Only querying the knowledge graph cannot effectively obtain this potential knowledge, nor can the knowledge in the graph be effectively integrated into the intermediate vector output by the encoder. The intermediate vector lacks the characteristics of the graph, resulting in a decrease in expression ability, which affects the performance of the NL2SQL model. Summary of the invention

[0006] The purpose of the present invention is to overcome the shortcomings of the prior art. A deep learning model based on graph computing is used to obtain an effective graph representation vector, which is added to the encoding process of the NL2SQL model to form a joint encoding, thereby enhancing the feature expression ability of the intermediate vector of the encoder-decoder model, thereby improving the performance of the NL2SQL model, thereby providing a graph-based translation method from natural language questions to SQL.

[0007] The objective of the present invention is achieved through the following technical solutions:

[0008] A graph-based translation method from natural language questions to SQL includes the following steps:

[0009] Step 1: Based on the metadata knowledge graph of the SQL database, use the deep learning model 1 to obtain the representation of the database tables and columns;

[0010] Step 2: Use the deep learning model 2 to encode the tables and columns of the database obtained in step 1 to obtain a representation containing graph structure information;

[0011] Step 3: Use deep learning model 3 to obtain the representation of natural language questions;

[0012] Step 4: Use the deep learning model 4 to jointly encode the representation of the natural language question, the representation of the table and the column to obtain an intermediate semantic vector;

[0013] Step 5: Decode the intermediate semantic vector using the deep learning model 5 to generate an SQL statement.

[0014] Furthermore, the step 1 comprises the following steps:

[0015] Step 101: Divide the triples in the metadata knowledge graph of the SQL database into a training set and a test set in a ratio of 9:1;

[0016] Step 102: Use the training set data to train a knowledge graph embedding model;

[0017] Step 103: Use the test set data to evaluate the model. If the model performance is not satisfactory, jump to step 102 and continue training. If the model performance is satisfactory, obtain the representation of the database tables and columns.

[0018] Furthermore, the step 2 comprises the following steps:

[0019] Step 201: construct a graph representation matrix and a graph adjacency matrix of the metadata knowledge graph of the SQL database, wherein the graph representation matrix stores the table and column representation of the database obtained in step 1, and the graph adjacency matrix describes the graph structure of the graph;

[0020] Step 202: Input the graph representation matrix and the graph adjacency matrix into a graph convolutional network, and train the graph convolutional network by classifying nodes into two types, table and column, as a training target;

[0021] Step 203: Obtain a representation of the tables and columns of the database including graph structure information.

[0022] Furthermore, the step 3 comprises the following steps:

[0023] Step 301: Perform word segmentation processing on natural language questions and load pre-training corpus;

[0024] Step 302: Encode the natural language question using the BiLSTM model to obtain a representation of the natural language question.

[0025] Furthermore, step 4 comprises the following steps:

[0026] Step 401: concatenate the representation of the natural language question and the representation of the table and the column to form a joint input;

[0027] Step 402: Encode the joint input using a relation-aware Transformer model to obtain an intermediate semantic vector.

[0028] Furthermore, the step 5 comprises the following steps:

[0029] Step 501: Decode the intermediate semantic vector obtained in step 4 using a gated recurrent unit model, output a decoding sequence, and generate SQL statements by using a pre-generation framework and filling in the blanks;

[0030] Step 502: according to the decoded sequence output by the decoder, recursively apply the corresponding grammar generation rules or fill in the table name and column name to generate a complete SQL;

[0031] Step 503: Use cross entropy as the loss function to calculate the loss of the decoder, update the parameters of the decoder and the Transformer model encoder, and continue training until the model performance is qualified.

[0032] Furthermore, the decoding sequence is a depth-first traversal sequence of the abstract syntax tree of the SQL statement, which is composed of three types of nodes: applying the syntax generation rules of SQL, selecting a table name to fill in, and selecting a column name to fill in; wherein the probability of applying a certain syntax generation rule is calculated using a multi-layer perceptron model, and the probability of selecting a certain table name or column name to fill in is calculated by the posterior joint probability.

[0033] Beneficial effects of the present invention: The present invention obtains a graph representation of database tables and columns based on the metadata knowledge graph of the database, and encodes them together with the representation of natural language questions. It is decoded by combining a deep learning model with a probabilistic model, and can make full use of the rich data semantic information of the knowledge graph to better generate SQL query statements corresponding to natural language questions about the SQL database. An effective graph representation vector can be obtained by using a deep learning model based on graph computing. The vector is added to the encoding process of the NL2SQL model to form a joint encoding, thereby enhancing the feature expression capability of the intermediate vector of the encoder-decoder model, thereby improving the performance of the NL2SQL model. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying creative work.

[0035] Figure 1 It is a flow chart of the method of the present invention.

[0036] Figure 2 It is a schematic diagram of an encoder that uses a graph convolutional network to obtain a graph representation of tables and columns of a database.

[0037] Figure 3 Schematic diagram of encoding joint input based on the relation-aware Transformer model.

[0038] Figure 4 This is a schematic diagram of using the gated recurrent unit model to decode and generate SQL statements. DETAILED DESCRIPTION

[0039] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not intended to limit the present invention.

[0040] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0041] It should be noted that all directional indications (such as up, down, left, right, front, back, etc.) in the embodiments of the present invention are only used to explain the relative position relationship, movement status, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication will also change accordingly.

[0042] In addition, the technical solutions between the various embodiments can be combined with each other, but it must be based on the fact that ordinary technicians in the field can implement it. When the combination of technical solutions is contradictory or cannot be implemented, it should be considered that such combination of technical solutions does not exist and is not within the scope of protection required by the present invention.

[0043] In this embodiment, if Figure 1 As shown, a graph-based translation method from natural language questions to SQL includes the following steps:

[0044] Step 1: Based on the metadata knowledge graph of the SQL database, use the deep learning model 1 to obtain the representation of the database tables and columns;

[0045] Step 2: Use the deep learning model 2 to encode the tables and columns of the database obtained in step 1 to obtain a representation containing graph structure information;

[0046] Step 3: Use deep learning model 3 to obtain the representation of natural language questions;

[0047] Step 4: Use the deep learning model 4 to jointly encode the representation of the natural language question, the representation of the table and the column obtained in the above step to obtain an intermediate semantic vector;

[0048] Step 5: Decode the intermediate semantic vector using the deep learning model 5 to generate an SQL statement.

[0049] In this embodiment, step 1 includes the following steps:

[0050] Step 101: Divide the triples in the metadata knowledge graph of the SQL database into a training set and a test set in a ratio of 9:1;

[0051] Step 102: Use the training set data to train a knowledge graph embedding model;

[0052] Step 103: Use the test set data to evaluate the model. If the model performance is not satisfactory, jump to step 102 and continue training. If the model performance is satisfactory, obtain the representation of the database tables and columns, such as Figure 2 The left half of the diagram is shown.

[0053] Knowledge graph embedding is one of the important methods to solve the problem of knowledge graph completion. It embeds entities and relations in the knowledge graph into a continuous vector space, thereby facilitating calculations while retaining the structural information in the knowledge graph. Knowledge graph embedding models can be roughly divided into three categories: distance-based models, bilinear models, and neural network models. Here, this solution uses a neural network model.

[0054] In this embodiment, step 2 includes the following steps:

[0055] Step 201: Construct a graph representation matrix and a graph adjacency matrix of the metadata knowledge graph of the SQL database. The graph representation matrix stores the table and column representation of the database obtained in step 1, and the graph adjacency matrix describes the graph structure of the graph;

[0056] Step 202: Input the graph representation matrix and the graph adjacency matrix into a graph convolutional network, and train the graph convolutional network by classifying nodes into two types, table and column, as a training target;

[0057] Step 203: Obtain a representation of the database tables and columns containing graph structure information, such as Figure 2 The right half of .

[0058] In this embodiment, step 3 includes the following steps:

[0059] Step 301: performing word segmentation processing on natural language questions and loading pre-training corpus;

[0060] Step 302: Use the BiLSTM model to encode the natural language question and obtain its representation, such as Figure 3 Shown in the lower left portion.

[0061] Wherein, the step 4 comprises the following steps:

[0062] Step 401: concatenate the representation of the natural language question, the representation of the table and the column to form a joint input;

[0063] Step 402: Encode the joint input using a relation-aware Transformer model to obtain an intermediate semantic vector, such as Figure 3 As shown, it is a schematic diagram of encoding joint input based on the relation-aware Transformer model.

[0064] In this embodiment, step 5 includes the following steps:

[0065] Step 501: The intermediate semantic vector obtained in step 4 is decoded using the gated recurrent unit model (Gated Recurrent Units), and a sequence is outputted, in which a SQL statement is generated by first generating a framework and then filling in the blanks. The decoding sequence is a depth-first traversal sequence of the abstract syntax tree of the SQL statement, which consists of three types of nodes: applying the syntax generation rules of SQL, selecting a table name to fill in, and selecting a column name to fill in. The probability of applying a syntax generation rule is calculated using a multi-layer perceptron model, and the probability of selecting a table name or column name to fill in is calculated using the posterior joint probability;

[0066] Step 502: According to the output sequence of the decoder, recursively apply the corresponding grammar generation rules or fill in the table name and column name to generate a complete SQL, such as Figure 4 , which is a schematic diagram of using a gated recurrent unit model to decode and generate SQL statements;

[0067] Step 503: Use cross entropy as the loss function to calculate the loss of the decoder, update the parameters of the decoder and the Transformer encoder in step 4, and continue training until the model performance is qualified.

[0068] The present invention uses a deep learning model based on graph computing to obtain effective graph representation vectors, adds the vectors to the encoding process of the NL2SQL model to form a joint encoding, and enhances the feature expression ability of the intermediate vectors of the encoder-decoder model, thereby improving the performance of the NL2SQL model. The present invention obtains a graph representation of database tables and columns based on the metadata knowledge graph of the database, and encodes them together with the representation of natural language questions. The deep learning model and the probability model are combined for decoding, which can make full use of the rich data semantic information of the knowledge graph and better generate SQL query statements corresponding to natural language questions about the SQL database.

[0069] In the embodiments of the present application, it should be noted that the above-mentioned method embodiments of the embodiments of the present application can be applied to a processor or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above-mentioned method embodiment can be completed by an integrated logic circuit of hardware in the processor or an instruction in the form of software. The above-mentioned processor may be a general-purpose processor, a digital signal processor (digital signal processor, DSP), an application specific integrated circuit (application specific integrated circuit, ASIC), a field programmable gate array (Field programmable gate array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The various methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application can be directly embodied as a hardware decoding processor to be executed, or a combination of hardware and software modules in the decoding processor to be executed. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory, and the processor reads the information in the memory and completes the steps of the above method in combination with its hardware.

[0070] It should be noted that, for the above-mentioned various method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that this application is not limited by the order of the actions described, because according to this application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and units involved are not necessarily required by this application.

[0071] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0072] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a ROM, a RAM, etc.

[0073] The above disclosure is only the preferred embodiment of the present invention, which certainly cannot be used to limit the scope of the present invention. Therefore, equivalent changes made according to the claims of the present invention are still within the scope of the present invention.

Claims

1. A graph-based translation method from natural language questions to SQL, characterized in that: The following steps are involved: Step 1: Based on the metadata knowledge graph of the SQL database, use the deep learning model 1 to obtain the representation of the database tables and columns; Step 2: Use the deep learning model 2 to encode the tables and columns of the database obtained in step 1 to obtain a representation containing graph structure information; Step 3: Use deep learning model 3 to obtain the representation of natural language questions; Step 4: Use the deep learning model 4 to jointly encode the representation of the natural language question, the representation of the table and the column to obtain an intermediate semantic vector; Step 5: Decode the intermediate semantic vector using the deep learning model 5 to generate SQL statements; The step 1 comprises the following steps: Step 101: Divide the triples in the metadata knowledge graph of the SQL database into a training set and a test set in a ratio of 9:1; Step 102: Use the training set data to train a knowledge graph embedding model; Step 103: Use the test set data to evaluate the model. If the model performance is not satisfactory, jump to step 102 and continue training. If the model performance is satisfactory, obtain the representation of the database tables and columns. The step 2 comprises the following steps: Step 201: construct a graph representation matrix and a graph adjacency matrix of the metadata knowledge graph of the SQL database, wherein the graph representation matrix stores the table and column representation of the database obtained in step 1, and the graph adjacency matrix describes the graph structure of the graph; Step 202: Input the graph representation matrix and the graph adjacency matrix into a graph convolutional network, and train the graph convolutional network by classifying nodes into two types, namely, table and column, as a training target; Step 203: Obtain a representation of the tables and columns of the database including graph structure information; The step 3 comprises the following steps: Step 301: Perform word segmentation processing on natural language questions and load pre-training corpus; Step 302: Encode the natural language question using the BiLSTM model to obtain a representation of the natural language question; The step 4 comprises the following steps: Step 401: concatenate the representation of the natural language question and the representation of the table and column to form a joint input; Step 402: Encode the joint input using a relation-aware Transformer model to obtain an intermediate semantic vector; The step 5 comprises the following steps: Step 501: Decode the intermediate semantic vector obtained in step 4 using a gated recurrent unit model, output a decoding sequence, and generate SQL statements by using a pre-generation framework and then filling in the blanks; Step 502: according to the decoded sequence output by the decoder, recursively apply the corresponding grammar generation rules or fill in the table name and column name to generate a complete SQL; Step 503: Use cross entropy as the loss function to calculate the loss of the decoder, update the parameters of the decoder and the Transformer model encoder, and continue training until the model performance is qualified.

2. The graph-based translation method from natural language questions to SQL according to claim 1, characterized in that: The decoding sequence is a depth-first traversal sequence of the abstract syntax tree of the SQL statement, which consists of three types of nodes: applying the syntax generation rule of SQL, selecting a table name to fill in, and selecting a column name to fill in; wherein the probability of applying a certain syntax generation rule is calculated using a multi-layer perceptron model, and the probability of selecting a certain table name or column name to fill in is calculated by the posterior joint probability.

Citation Information

Patent Citations

  • Method of predicting columns and tables used when translating SQL queries from natural language on basis of neural network

    WO2021132760A1