A method and related device for generating database query statements

By constructing a syntax tree-action two-part graph in the generative model and combining decoder decoding, the problem of low accuracy of database query statements in the prior art is solved, and a more accurate database query statement generation is achieved.

CN115114318BActive Publication Date: 2025-08-29TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210368035.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-08
Publication Date
2025-08-29
Estimated Expiration
2042-04-08

AI Technical Summary

Technical Problem

In the prior art, the method of generating database query statements based on natural language statements fails to fully consider other information other than the encoding information of natural language statements and database patterns, resulting in the generated action sequence being inaccurate enough, which reduces the accuracy of database query statements.

Method used

The encoder of the generation model encodes the natural language statements and database patterns to construct a syntax tree-action two-part graph of the generated actions, and uses a decoder based on the two-part graph to decode the encoded vector and the syntax tree-action two-part graph to generate an action sequence, combining the encoded vectors of the natural language statements and database patterns and the syntax tree structure information of the generated actions.

Benefits of technology

Improve the accuracy of the generated database query statements and generate more accurate action sequences.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115114318B_ABST
    Figure CN115114318B_ABST
Patent Text Reader

Abstract

The present application discloses a method and related device for generating database query statements, which are applied to artificial intelligence. The method comprises inputting a natural language statement to be processed and a database schema of a database to be queried into an encoder of a generative model, outputting a first encoding vector of the natural language statement to be processed and the database schema; after the first encoding vector is input into the generative model to generate t-1 actions, a first syntax tree-action bipartite graph of t-1 actions is constructed, where t is a positive integer and t≥2; inputting the first encoding vector and the first syntax tree-action bipartite graph into a bipartite graph-based decoder of the generative model, outputting the tth action, and finally generating a complete candidate action sequence; and converting the candidate action sequence into a database query statement to be processed corresponding to the natural language statement to be processed. In the process of generating the action sequence, the syntax tree structure information of the generated action is fully considered to generate a more accurate action sequence, thereby improving the accuracy of the generated database query statement.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing, and in particular to a method and related device for generating database query statements. Background Art

[0002] Currently, databases are widely used in various fields as the primary data storage tool. To implement database query functions using natural language statements, it is necessary to generate database query statements based on natural language statements. This allows users to query the database using natural language statements without having to master the relevant knowledge of database query statements.

[0003] In the related art, the method of generating database query statements based on natural language statements mainly adopts the encoder-decoder framework, that is, the natural language statements and database patterns are encoded by the encoder to obtain encoding vectors, and the encoding vectors are decoded by the decoder to generate action sequences and convert them into database query statements.

[0004] However, database query statements have a certain grammatical structure, but the above method only decodes the encoding vectors of natural language statements and database patterns. In the process of generating action sequences, it is unable to fully consider other information besides the encoding information of natural language statements and database patterns, resulting in the generated action sequence being inaccurate, thereby reducing the accuracy of the generated database query statements. Summary of the Invention

[0005] In order to solve the above technical problems, the present application provides a method and related devices for generating database query statements, which can generate more accurate action sequences, thereby improving the accuracy of the generated database query statements.

[0006] The embodiments of this application disclose the following technical solutions:

[0007] In one aspect, the present application provides a method for generating a database query statement, the method comprising:

[0008] Encoding the natural language sentence to be processed and the database schema of the database to be queried by generating an encoder of the model to obtain a first encoding vector of the natural language sentence to be processed and the database schema;

[0009] Constructing a first syntax tree-action bipartite graph of t-1 generated actions; the t-1 actions are generated after the first encoding vector is input into the generation model, where t is a positive integer and t≥2;

[0010] Decoding the first encoding vector and the first syntax tree-action bipartite graph using a bipartite graph-based decoder of the generative model to obtain the t-th action, until a complete candidate action sequence is generated;

[0011] The candidate action sequence is converted into a database query statement to be processed corresponding to the natural language statement to be processed.

[0012] On the other hand, the present application provides a device for generating a database query statement, the device comprising: an encoding unit, a construction unit, a decoding unit, and a conversion unit;

[0013] The encoding unit is configured to encode the natural language sentence to be processed and the database schema of the database to be queried by using an encoder of the generation model to obtain a first encoding vector of the natural language sentence to be processed and the database schema;

[0014] The construction unit is configured to construct a first syntax tree-action bipartite graph of t-1 generated actions; the t-1 actions are generated after the first encoding vector is input into the generation model, where t is a positive integer and t≥2;

[0015] The decoding unit is configured to decode the first encoding vector and the first syntax tree-action bipartite graph through a bipartite graph-based decoder of the generative model to obtain the t-th action, until a complete candidate action sequence is generated;

[0016] The conversion unit is configured to convert the candidate action sequence into a database query statement to be processed corresponding to the natural language statement to be processed.

[0017] In another aspect, the present application provides a device for generating a database query statement, the device comprising a processor and a memory:

[0018] The memory is used to store program code and transmit the program code to the processor;

[0019] The processor is configured to execute the method for generating a database query statement as described above according to the instructions in the program code.

[0020] On the other hand, an embodiment of the present application provides a computer-readable storage medium, which is used to store a computer program, and the computer program is used to execute the method for generating a database query statement described in the above aspect.

[0021] On the other hand, an embodiment of the present application provides a computer program product, which includes a computer program or instructions; when the computer program or instructions are executed by a processor, the method for generating a database query statement described in the above aspect is executed.

[0022] It can be seen from the above technical solution that, first, the natural language sentence to be processed and the database model of the database to be queried are input into the encoder of the generative model, and the first encoding vector of the natural language sentence to be processed and the database model is output; secondly, after the first encoding vector is input into the generative model to generate t-1 actions, the first syntax tree-action bipartite graph of t-1 actions is constructed, where t is a positive integer and t≥2; then, the first encoding vector and the first syntax tree-action bipartite graph are input into the bipartite graph-based decoder of the generative model, and the tth action is output until a complete candidate action sequence is generated; finally, the candidate action sequence is converted into the database query statement to be processed corresponding to the natural language sentence to be processed.

[0023] Based on this, after the encoder encodes the natural language sentence and the database schema of the database to obtain the encoding vector, and the encoding vector is input into the generation model to generate some actions, the syntax tree-action bipartite graph of the generated action is further constructed, and the syntax tree structure information of the generated action is introduced; on this basis, the decoder based on the bipartite graph decodes the encoding vector and the syntax tree-action bipartite graph, and in the process of generating the action sequence, both the encoding vector of the natural language sentence and the database schema and the syntax tree structure information of the generated action are considered to generate a more accurate action sequence, thereby improving the accuracy of the generated database query statement. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0025] Figure 1 A schematic diagram of an application scenario of a method for generating a database query statement provided in an embodiment of the present application;

[0026] Figure 2 A schematic diagram of a first syntax tree-action bipartite graph provided in an embodiment of the present application;

[0027] Figure 3 A flowchart of a method for generating a database query statement provided in an embodiment of the present application;

[0028] Figure 4A schematic diagram of a specific framework of a decoder based on a bipartite graph provided in an embodiment of the present application;

[0029] Figure 5 A schematic diagram of a candidate action sequence and a syntax tree of the candidate action sequence provided in an embodiment of the present application;

[0030] Figure 6 A flowchart of a training method for a generative model provided in an embodiment of the present application;

[0031] Figure 7 A flowchart of another method for generating a database query statement provided in an embodiment of the present application;

[0032] Figure 8 A flowchart of a method for training a ranking model provided in an embodiment of the present application;

[0033] Figure 9 A flowchart of a method for training a generation model and a ranking model provided in an embodiment of the present application;

[0034] Figure 10 A schematic diagram of a specific application of a method for generating a database query statement provided in an embodiment of the present application;

[0035] Figure 11 A schematic diagram of a device for generating a database query statement provided in an embodiment of the present application;

[0036] Figure 12 A schematic diagram of the structure of a server provided in an embodiment of the present application;

[0037] Figure 13 A schematic diagram of the structure of a terminal device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0038] The embodiments of the present application are described below with reference to the accompanying drawings.

[0039] Currently, when using natural language statements to query a database, it is necessary to generate database query statements based on the natural language statements; that is, an encoder-decoder framework is adopted, in which the encoder encodes the natural language statement and the database pattern to obtain an encoding vector, and the decoder decodes the encoding vector to generate an action sequence, which can be converted into a database query statement.

[0040] However, after research, it was found that database query statements have a certain grammatical structure, but the above method only decodes the encoding vectors of natural language statements and database patterns. In the process of generating action sequences, it is unable to fully consider other information besides the encoding information of natural language statements and database patterns, resulting in the generated action sequence being inaccurate, thereby reducing the accuracy of the generated database query statements.

[0041] In view of this, the present application proposes a method and related devices for generating database query statements. After the encoder encodes the natural language statement and the database schema of the database to obtain an encoding vector, the encoding vector is input into the generation model to generate some actions, and then the syntax tree-action bipartite graph of the generated action is further constructed, and the syntax tree structure information of the generated action is introduced; on this basis, the decoder based on the bipartite graph decodes the encoding vector and the syntax tree-action bipartite graph, and in the process of generating the action sequence, both the encoding vector of the natural language statement and the database schema and the syntax tree structure information of the generated action are considered to generate a more accurate action sequence, thereby improving the accuracy of the generated database query statement.

[0042] In order to facilitate understanding of the technical solution of the present application, the method for generating a database query statement provided in an embodiment of the present application is introduced below in combination with actual application scenarios.

[0043] See also Figure 1 , Figure 1 A schematic diagram of an application scenario of a method for generating a database query statement provided in an embodiment of the present application. Figure 1 The application scenario shown includes a terminal device 101 and a server 102, wherein the terminal device 101 serves as a device for inputting natural language statements, and the server 102 serves as a device for generating database query statements, and the server 102 pre-stores a generation model and a database schema.

[0044] The user of terminal device 101 inputs a natural language sentence to be processed through terminal device 101, and terminal device 101 obtains the natural language sentence to be processed and sends it to server 102. Server 302 encodes the natural language sentence to be processed and the database schema of the database to be queried using the encoder of the generative model, obtaining a first encoding vector of the natural language sentence to be processed and the database schema. For example, the database schema is S = {C, T}, where C represents a column set and T represents a table set. The user of terminal device 101 inputs the natural language sentence to be processed "How many teachers are there in category A" through terminal device 101, and terminal device 101 obtains the natural language sentence to be processed "How many teachers are there in category A" and sends it to server 102; server 302 uses the encoder of the generative model to encode the natural language sentence to be processed "How many teachers are there in category A" and the database schema S = {C, T} to obtain a first encoding vector EV1.

[0045] The server 102 constructs a first syntax tree-action bipartite graph of the generated t-1 actions; the t-1 actions are generated after the first encoding vector is input into the generative model, t is a positive integer, t≥2. For example, after the first encoding vector EV1 is input into the generative model, two actions are generated, namely "1: sql→sql_unit" and "2: sql_unit→(from, select)". The server 102 can construct a first syntax tree-action bipartite graph of the two generated actions, see Figure 2 The diagram shows a first syntax tree-action bipartite graph, wherein circular nodes represent syntax tree nodes and rectangular nodes represent action nodes.

[0046] The server 102 decodes the first encoding vector and the first syntax tree-action bipartite graph using the decoder based on the bipartite graph of the generative model to obtain the t-th action until a complete candidate action sequence is generated. The server 102 decodes the first encoding vector EV1 and the above-mentioned bipartite graph using the decoder based on the bipartite graph of the generative model. Figure 2 The first syntax tree-action bipartite graph shown in the figure shows that the third action is "from→tab_id", and so on until a complete sequence of candidate actions is generated.

[0047] The server 102 converts the candidate action sequence into a database query statement to be processed corresponding to the natural language statement to be processed. Based on this, the server 102 can convert the candidate action sequence into a database query statement to be processed corresponding to the natural language statement to be processed. Converted into the to-be-processed database query statement "select count(column:sort A)from table:teacher" corresponding to the to-be-processed natural language statement "How many teachers of category A are there?"

[0048] It can be seen that after the encoder encodes the natural language sentence and the database schema of the database to obtain the encoding vector, the encoding vector is input into the generation model to generate some actions, and then the syntax tree-action bipartite graph of the generated action is further constructed, and the syntax tree structure information of the generated action is introduced; on this basis, the decoder based on the bipartite graph decodes the encoding vector and the syntax tree-action bipartite graph, and in the process of generating the action sequence, both the encoding vector of the natural language sentence and the database schema and the syntax tree structure information of the generated action are considered to generate a more accurate action sequence, thereby improving the accuracy of the generated database query statement.

[0049] The method for generating database query statements provided in the embodiments of the present application is based on artificial intelligence. Artificial Intelligence (AI) is a theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results. In other words, artificial intelligence is a comprehensive technology in computer science that attempts to understand the essence of intelligence and generate a new type of intelligent machine that can respond in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines, so that machines have the functions of perception, reasoning and decision-making.

[0050] Artificial intelligence (AI) technology is a comprehensive discipline encompassing a wide range of fields, encompassing both hardware and software technologies. Foundational AI technologies generally include sensors, specialized AI chips, cloud computing, distributed storage, big data processing, operating / interaction systems, and mechatronics. AI software technologies primarily encompass computer vision, speech processing, natural language processing, as well as machine learning / deep learning, autonomous driving, and smart transportation.

[0051] In the embodiments of this application, the main artificial intelligence software technologies involved include the above-mentioned natural language processing technologies and machine learning / deep learning. For example, it may involve technologies such as text processing and semantic understanding in natural language processing (NLP), and it may also involve various artificial neural networks (ANN) in machine learning (ML).

[0052] The method for generating database query statements provided in this application can be applied to devices that have data processing capabilities and generate database query statements, such as servers and terminal devices. Among them, the server can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides cloud computing services, etc., but is not limited to these; terminal devices include but are not limited to mobile phones, tablets, computers, computers, smart cameras, smart voice interaction devices, smart home appliances, vehicle-mounted terminals, aircraft, etc., but are not limited to these. Terminal devices and servers can be directly or indirectly connected through wired or wireless communication, and this application does not impose any restrictions on this.

[0053] The device for generating database query statements may have the ability to implement natural language processing, which is an important direction in the fields of computer science and artificial intelligence. It studies various theories and methods that can enable effective communication between humans and computers using natural language. Natural language processing is a science that integrates linguistics, computer science, and mathematics. Therefore, research in this field will involve natural language, that is, the language people use in daily life, so it is closely related to the study of linguistics. Natural language processing technology generally includes text processing, semantic understanding, machine translation, robot question answering, knowledge graphs and other technologies. In an embodiment of the present application, when the first modal information and the second modal information include video text information, the device for generating database query statements can extract features from the video text information to obtain semantic features through text processing, semantic understanding and other technologies in natural language processing.

[0054] The device for generating database query statements may have machine learning capabilities. Machine learning is a multi-disciplinary interdisciplinary subject involving probability theory, statistics, approximation theory, convex analysis, algorithmic complexity theory and other disciplines. It specializes in studying how computers simulate or implement human learning behavior to acquire new knowledge or skills and reorganize existing knowledge structures to continuously improve their own performance. Machine learning is the core of artificial intelligence and the fundamental way to make computers intelligent. Its applications are spread across all areas of artificial intelligence. Machine learning and deep learning generally include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning, and learning by formulas. In the embodiments of the present application, the generation model, ranking model, etc. used in the method for generating database query statements mainly involve the application of artificial neural networks, and the method for generating database query statements is implemented by artificial neural networks.

[0055] The method for generating a database query statement provided in an embodiment of the present application may also involve a blockchain, wherein relevant model architectures, model parameters, and database schema data such as classification models and sorting models may be stored on the blockchain.

[0056] The method for generating database query statements provided in this application can be applied to various scenarios, including but not limited to cloud technology, artificial intelligence, smart transportation, assisted driving, etc.

[0057] The following describes in detail the method for generating a database query statement provided in an embodiment of the present application, using a server as a device for generating a database query statement.

[0058] See also Figure 3 , which is a flow chart of a method for generating a database query statement provided by an embodiment of the present application. Figure 3 As shown, the method for generating a database query statement includes the following steps:

[0059] S301: Encode the natural language sentence to be processed and the database schema of the database to be queried by generating an encoder of the model to obtain first encoding vectors of the natural language sentence to be processed and the database schema.

[0060] In an embodiment of the present application, in order to implement a database query function using a natural language statement, after obtaining a natural language statement to be processed, it is necessary to generate a database query statement to be processed based on the natural language statement to be processed. First, a generative model can be used to encode the natural language statement to be processed and the database schema of the database to be queried. The generative model includes an encoder, which inputs the natural language statement to be processed and the database schema into the encoder for encoding processing, and outputs an encoding vector of the natural language statement to be processed and the database schema as a first encoding vector.

[0061] The database schema is a structure described in a formal language supported by the database management system. For example, the database schema of a relational database defines tables, fields, relations, views, indexes, packages, procedures, functions, queues, triggers, types, sequences, materialized views, synonyms, database links, directories, Extensible Markup Language (XML) schemas, and other elements.

[0062] As an example, the natural language sentence to be processed is "How many teachers of category A are there?", the database to be queried is a relational database a, and its database schema is S = {C, T}; the encoder is used to encode the natural language sentence to be processed "How many teachers of category A are there?" and the database schema to obtain a first encoding vector EV1. The first encoding vector EV1 may include, for example, the encoding vector W = [w1, w2, ..., w n ]∈R n×k , the encoding vector of the table set in the database schema T = [t1, t2, ..., t |t| ]∈R |t|×k and the encoding vector C = [c1, c2, ..., c |c| ]∈R |c|×k ; where k represents the preset dimension, |t| is the number of tables in the table set, and |c| is the number of columns in the column set.

[0063] Among them, the generation model is obtained by pre-training the generator based on the sequence of actions to be trained converted from the natural language sentences to be trained, the database model and the database query sentences to be trained corresponding to the natural language sentences to be trained. The specific implementation method of the training method can be found in the embodiment of the training method of the generation model below, which will not be described in detail here.

[0064] S302: Construct a first syntax tree-action bipartite graph of the generated t-1 actions; the t-1 actions are generated after the first encoding vector is input into the generation model, t is a positive integer, t≥2.

[0065] In the related art, when an encoder-decoder framework is used to generate a database query statement to be processed based on a natural language statement to be processed, after the encoder encodes the natural language statement to be processed and the database pattern to obtain a first encoding vector, the decoder directly decodes the first encoding vector to generate an action sequence, which can be converted into a database query statement to be processed.

[0066] However, after research, it was found that database query statements have a certain grammatical structure, but the method in the above-mentioned related technology only decodes the first encoding vector of the natural language statement to be processed and the database model. In the process of generating the action sequence, it is unable to fully consider other information except the first encoding information of the natural language statement to be processed and the database model, resulting in the generated action sequence being inaccurate, thereby reducing the accuracy of the generated database query statement to be processed.

[0067] In an embodiment of the present application, considering that the actions generated in the process of generating an action sequence have corresponding syntax trees, the syntax tree is a representation of the syntax structure of the source code. It expresses the syntax structure of the programming language in a tree form, and each node on the tree represents a syntax structure in the source code; that is, the syntax tree of the generated action can represent part of the syntax structure of the corresponding database query language.

[0068] Based on this, after S301 obtains the first encoding vector of the natural language sentence and database model to be processed, if the first encoding vector is input into the generation model to generate t-1 actions, t is a positive integer, t≥2, on the basis of t-1 actions, a bipartite graph construction method is adopted to further construct a syntax tree-action bipartite graph of the generated t-1 actions, that is, a first syntax tree-action bipartite graph, so as to introduce the syntax tree structure information of the generated t-1 actions in this way.

[0069] A bipartite graph is a special model in graph theory. Its vertex set can be split into two disjoint subsets, and the two vertices attached to each edge in the graph belong to these two disjoint subsets, meaning that the vertices in the two subsets are not adjacent. Specifically, the node set of a syntax tree-action bipartite graph can be split into two disjoint sets of syntax tree nodes and action nodes, and the syntax tree nodes and action nodes attached to each edge in the graph belong to these disjoint sets of syntax tree nodes and action nodes, respectively. The syntax tree nodes in the syntax tree node set are not adjacent, and the action nodes in the action node set are not adjacent.

[0070] As an example, based on the above example, after the first encoding vector EV1 is input into the generation model, two actions are generated: "1: sql→sql_unit" and "2: sql_unit→(from, select)". The first syntax tree-action bipartite graph of the two generated actions is constructed. The first syntax tree-action bipartite graph can be found in the above Figure 2 .

[0071] In the syntax tree-action bipartite graph, G is defined as G = < V ST ,ε,V G >,V ST is the set of syntax tree nodes and ε edges, V G It is based on the set of action nodes. Each action node is used as an intermediate node between the head syntax tree node and the child syntax tree node of the action, such as Figure 2 As shown, the action node "1: sql→sql_unit" is the intermediate node between the head syntax tree node "sql" and the sub-syntax tree node "sql_unit" of the action, and the action node "2: sql_unit→(from, select)" is the intermediate node between the head syntax tree node "sql_unit" and the sub-syntax tree node "from" of the action, as well as the intermediate node between the head syntax tree node "sql_unit" and the sub-syntax tree node "select".

[0072] S303: Decode the first encoding vector and the first syntax tree-action bipartite graph using a bipartite graph-based decoder of the generative model to obtain the t-th action, until a complete candidate action sequence is generated.

[0073] In an embodiment of the present application, after constructing the first syntax tree-action bipartite graph of the generated t-1 actions in S302, the generation model, in the process of generating an action sequence, not only needs to implement decoding of the first encoding vector of the natural language sentence to be processed and the database schema, but also needs to implement decoding of the first syntax tree-action bipartite graph of the generated t-1 actions. The generation model then includes a decoder based on a bipartite graph, which inputs the first encoding vector and the first syntax tree-action bipartite graph into the decoder based on the bipartite graph for decoding, learns the syntax tree structure information of the generated t-1 actions, and fuses the first encoding vector of the natural language sentence to be processed and the database schema, outputs the t-th action, and so on until a complete action sequence is generated as a candidate action sequence.

[0074] This method considers both the first encoding vector of the natural language statement to be processed and the database schema in the process of generating an action sequence, and the syntax tree structure information of the generated t-1 actions, and can generate a more accurate candidate action sequence, thereby improving the accuracy of the generated database query statement to be processed.

[0075] In the specific implementation of S303, first, a bipartite graph extractor for learning the syntax tree structure information of the generated t-1 actions needs to be deployed in the bipartite graph-based decoder, and the first syntax tree-action bipartite graph of the generated t-1 actions is input into the bipartite graph extractor for extraction processing, and the first action vector of the action node in the first syntax tree-action bipartite graph is output. The first action vector fully learns the syntax tree structure information of the generated t-1 actions.

[0076] Secondly, a decoder based on a bipartite graph also needs to be deployed to input the first action vector of the action node in the first syntax tree-action bipartite graph, as well as the first encoding vector of the natural language sentence to be processed and the database pattern into the decoder for decoding processing; based on the syntax tree structure information of the generated t-1 actions learned by the first action vector, the first encoding vector of the natural language sentence to be processed and the database pattern is further integrated to predict the next action, that is, output the t-th action, and so on until a candidate action sequence is generated. Therefore, the present application provides a possible implementation method, in which a decoder based on a bipartite graph includes a bipartite graph extractor and a decoder; S303 may, for example, include the following S3031-S3032:

[0077] S3031: Extract the first syntax tree-action bipartite graph using a bipartite graph extractor to obtain a first action vector of an action node in the first syntax tree-action bipartite graph.

[0078] When S3031 is specifically implemented, the initialization vectors of each node in the first syntax tree-action bipartite graph can be first obtained, that is, the first initialization vector of the syntax tree node and the second initialization vector of the action node; then the first initialization vector of the syntax tree node is merged with the second initialization vector of the action node to obtain the first action vector of the action node in the first syntax tree-action bipartite graph. Therefore, the present application provides a possible implementation method, and S3031 may, for example, include the following S1-S2:

[0079] S1: Obtain a first initialization vector for a syntax tree node and a second initialization vector for an action node in a first syntax tree-action bipartite graph.

[0080] As an example, assume that the first syntax tree-action bipartite graph includes h syntax tree nodes and t-1 action nodes. For the syntax tree nodes, the trainable matrix Get the first initialization vector. For action nodes, you can find the trainable matrix Get the second initialization vector; then the first initialization vector of the syntax tree node and the second initialization vector of the action node are Among them, |V ST| is the number of types of syntax tree nodes in the syntax tree node set, |V G | is the number of action node types in the action node set. It should be noted that for some syntax tree nodes corresponding to tables or columns, the encoding vector of the table set or column set in the database schema can be searched to obtain the first initialization vector.

[0081] S2: Fuse the first initialization vector into the second initialization vector to obtain a first motion vector.

[0082] Among them, the bipartite graph extractor can, for example, include a graph attention network based on a multi-head attention mechanism. Then, through the graph attention network based on the multi-head attention mechanism, the first initialization vector of the syntax tree node can be fused to the second initialization vector of the action node to obtain the first action vector of the action node in the first syntax tree-action bipartite graph.

[0083] As an example, based on the above example, the first initialization vector is fused to the second initialization vector through the graph attention network based on the multi-head attention mechanism, and the first action vector of the action node in the first syntax tree-action bipartite graph is obtained as by For example, the aggregate function is:

[0084]

[0085]

[0086] in, is a trainable parameter, || represents the cascade operation of the matrix, LRelu is the abbreviation of the activation function LeakyRelu. K1 represents the number of heads in the multi-head attention mechanism, L ij = 1 means there is an edge between the i-th node and the j-th node. Then, an attention mechanism is used to calculate the importance of each head:

[0087]

[0088] Among them, W a is a trainable parameter, and finally we get the following:

[0089]

[0090] S3032: Decode the first coding vector and the first action vector through a decoder to obtain the t-th action, until a candidate action sequence is generated.

[0091] In the specific implementation of S3032, the decoder is composed of a stack of multiple decoding modules and fully connected layers. Each decoding module includes two decoding layers, and the first encoding vector is fused in the second decoding layer. The difference between the multiple decoding modules is that the input of the first decoding module is the first action vector of the action node in the first syntax tree-action bipartite graph and the position vector corresponding to the first action vector, while the input of other decoding modules is the output of the previous decoding module, and the input of the fully connected layer is the output of the last decoding module; the first decoding module, the second decoding module and the fully connected layer can be deployed in the decoder, the first decoding module deploys the first decoding layer and the second decoding layer, and the second decoding module deploys the third decoding layer and the fourth decoding layer.

[0092] Based on the above description, first, the first action vector of the action node in the first syntax tree-action bipartite graph and the position vector corresponding to the first action vector are input into the first decoding layer for decoding processing, and the second action vector of the action node in the first syntax tree-action bipartite graph is output; secondly, the second action vector and the first encoding vector of the natural language sentence to be processed and the database pattern are input into the second decoding layer for decoding processing, and the third action vector of the action node in the first syntax tree-action bipartite graph is output; then, the third action vector is input into the third decoding layer for decoding processing, and the fourth action vector of the action node in the first syntax tree-action bipartite graph is output; then, the fourth action vector and the first encoding vector of the natural language sentence to be processed and the database pattern are input into the fourth decoding layer for decoding processing, and the final decoding vector is output as the first decoding vector; finally, the first decoding vector is input into the fully connected layer for prediction processing, and the tth action is output, until a candidate action sequence is generated.

[0093] That is, the present application provides a possible implementation, where the decoder includes a first decoding module, a second decoding module, and a fully connected layer, the first decoding module includes a first decoding layer and a second decoding layer, and the second decoding module includes a third decoding layer and a fourth decoding layer; S3032 may, for example, include the following S3-S7:

[0094] S3: Decode the first motion vector and the position vector corresponding to the first motion vector through the first decoding layer to obtain a second motion vector.

[0095] Among them, the present application provides a possible implementation method, in which the first decoding layer includes a first action attention layer based on a multi-head attention mechanism.

[0096] As an example, when the first decoding layer is the first action attention layer based on the multi-head attention mechanism, the multi-head attention mechanism is used, and the first action vector of the action node in the first syntax tree-action bipartite graph is On the basis of this, the position vector corresponding to the first action vector is introduced to learn the position information of the generated t-1 actions. The position vector The calculation formula is as follows:

[0097] P i [2j] = sin(i / 10000 2j / k )

[0098] P i [2j+1]=cos(i / 10000 2j / k )

[0099] Where i is the i-th rule and j is the j-th dimension of the vector. Given an input Through the decoding process of the first action attention layer based on the multi-head attention mechanism, an output is obtained

[0100]

[0101] Among them, K2 refers to the number of heads in the multi-head attention mechanism, is a trainable parameter, The calculation formula is as follows:

[0102]

[0103] Among them, d k =d / K2 dimension of the directivity, where Q g , K g 、V g The calculation formula is as follows:

[0104] [Q g ,K g ,V g ]=X m [W Qg ,W Kg ,W Vg ]

[0105] S4: Decode the first coding vector and the second motion vector through a second decoding layer to obtain a third motion vector.

[0106] Among them, the present application provides a possible implementation method, in which the second decoding layer includes a first encoding attention layer based on a multi-head attention mechanism.

[0107] As an example, when the second decoding layer is the first encoding attention layer based on the multi-head attention mechanism, the multi-head attention mechanism is adopted. The specific implementation method of the decoding process of the first encoding attention layer based on the multi-head attention mechanism is similar to the specific implementation method of the decoding process of the first action attention layer based on the multi-head attention mechanism. g , K g 、Vg Need to change to Q e , K e 、V e Among them, Q e , K e 、V e The calculation method of K is: the first encoding vector EV1 = [W, T, C] of the natural language sentence to be processed and the database pattern is used to calculate K e 、V e , and the output Y of the first action attention layer based on the multi-head attention mechanism m =[y1,…,y L ] is used to calculate Q e ;Right now,

[0108] S5: Decode the third motion vector through the third decoding layer to obtain a fourth motion vector.

[0109] S6: Decode the first coding vector and the fourth motion vector through the fourth decoding layer to obtain a first decoding vector.

[0110] Similarly, the present application provides a possible implementation method, in which the third decoding layer includes a second action attention layer based on a multi-head attention mechanism, and the fourth decoding layer includes a second encoding attention layer based on a multi-head attention mechanism.

[0111] As an example, actions can be divided into three categories: selection rule action, selection table action and selection column action. If the first decoding vector is Corresponding to the selection rule action, selection table action and selection column action, we get and

[0112] S7: Predict the first decoded vector through the fully connected layer to obtain the t-th action until a candidate action sequence is generated.

[0113] In addition, based on the above example, for the selection rule action, its predicted probability P r The calculation formula is as follows:

[0114] P r =softmax(tanh(W r H r ))

[0115] Among them, W r is the parameter of the fully connected layer, which is used to transform H r Mapped to rule space.

[0116] For the selection table action, calculate H tThe similarity between each table T, and the similarity matrix Then we get its predicted probability P r The calculation formula is as follows:

[0117] P t =softmax(M t )

[0118] For the select column action, calculate H c The similarity between each column C, and the similarity matrix Then we get its predicted probability P c The calculation formula is as follows:

[0119] P c =softmax(M c )

[0120] In addition, in an embodiment of the present application, after obtaining the t-th action, the first syntax tree-action bipartite graph of the generated t-1 actions is expanded using the t-th action, and so on until a candidate action sequence is generated.

[0121] As an example, in combination with the specific implementation of S1-S7 above, see Figure 4 The schematic diagram of a specific framework of a decoder based on a bipartite graph is shown, and the decoder based on the bipartite graph is used to decode the first encoding vector EV1 and the above Figure 2 The first syntax tree-action bipartite graph shown in the figure shows that the third action is "from→tab_id", and so on until a complete candidate action sequence a is generated; see Figure 5 The diagram shows a candidate action sequence and a syntax tree of the candidate action sequence, wherein the candidate action sequence is a=1, 2, 3, select table, 6, 7, 8, select column.

[0122] S304: Convert the candidate action sequence into a database query statement to be processed corresponding to the natural language statement to be processed.

[0123] In the embodiment of the present application, after the candidate action sequence is generated in S303, one candidate action sequence can be uniquely converted into a database query statement as the database query statement to be processed corresponding to the natural language statement to be processed.

[0124] As an example, based on the above example, combined with Figure 5 The candidate action sequence and the syntax tree of the candidate action sequence are shown, and the candidate action sequence It can be converted into the to-be-processed database query statement "select count(column:sort A)from table:teacher" corresponding to the to-be-processed natural language statement "How many teachers of category A are there?"

[0125] In addition, in an embodiment of the present application, the database query statement may be, for example, a structured query language (SQL) statement, which is a programming language statement for database queries and is used to store data and query, update, and manage database systems; the syntax tree may be, for example, an abstract syntax tree (AST), which is an abstract representation of the syntax structure of the source code. It represents the syntax structure of the programming language in a tree-like form, and each node on the tree represents a structure in the source code.

[0126] The method for generating a database query statement provided in the above embodiment first inputs the natural language statement to be processed and the database schema of the database to be queried into the encoder of the generative model, and outputs the first encoding vector of the natural language statement to be processed and the database schema; secondly, after the first encoding vector is input into the generative model to generate t-1 actions, a first syntax tree-action bipartite graph of t-1 actions is constructed, where t is a positive integer and t≥2; then, the first encoding vector and the first syntax tree-action bipartite graph are input into the bipartite graph-based decoder of the generative model, and the tth action is output until a complete candidate action sequence is generated; finally, the candidate action sequence is converted into the database query statement to be processed corresponding to the natural language statement to be processed.

[0127] Based on this, after the encoder encodes the natural language sentence and the database schema of the database to obtain the encoding vector, and the encoding vector is input into the generation model to generate some actions, the syntax tree-action bipartite graph of the generated action is further constructed, and the syntax tree structure information of the generated action is introduced; on this basis, the decoder based on the bipartite graph decodes the encoding vector and the syntax tree-action bipartite graph, and in the process of generating the action sequence, both the encoding vector of the natural language sentence and the database schema and the syntax tree structure information of the generated action are considered to generate a more accurate action sequence, thereby improving the accuracy of the generated database query statement.

[0128] With respect to the generation model in the method for generating a database query statement provided in the above embodiment, the training method of the generation model is introduced below in conjunction with the accompanying drawings.

[0129] See also Figure 6 , Figure 6 A flow chart of a training method for generating a model provided in an embodiment of the present application. Figure 6 As shown, the training method of the generative model includes the following steps:

[0130] S601: Based on the database schema, construct a natural language sentence to be trained and a database query sentence to be trained corresponding to the natural language sentence to be trained.

[0131] In an embodiment of the present application, it is first necessary to construct a training sample for training the generator. In specific practice, it is necessary to first construct a natural language statement that can query the database to be queried corresponding to the database model according to the database model in the above embodiment, as the natural language statement to be trained; then construct a database query statement corresponding to the natural language statement to be trained, as the database query statement to be trained.

[0132] S602: Convert the database query statement to be trained into an action sequence to be trained.

[0133] In an embodiment of the present application, since the generator outputs an action sequence, it is also necessary to convert the database query statement to be trained into an action sequence as the action sequence to be trained. The action sequence to be trained is the output target of the generator when training the natural language statement to be trained and the database model.

[0134] S603: Train a generator according to the natural language sentences to be trained, the database schema, and the action sequences to be trained to obtain a generation model; the generator includes an encoder and a decoder based on a bipartite graph.

[0135] In an embodiment of the present application, the generator also includes an encoder and a decoder based on a bipartite graph. The natural language sentences and database patterns to be trained are taken as input, and the action sequences to be trained are taken as output. The generator is trained, and the trained generator can be used as a generation model.

[0136] When S603 is specifically implemented, the training process is actually: first, the natural language sentence to be trained and the database pattern are input into the encoder for encoding processing, and the encoding vector of the natural language sentence to be trained and the database pattern is output as the second encoding vector.

[0137] Secondly, if the second encoding vector input generator generates t-1 predicted actions, t is a positive integer, t≥2, based on the t-1 predicted actions, the bipartite graph construction method is used to further construct the syntax tree-action bipartite graph of the generated t-1 predicted actions, that is, the second syntax tree-action bipartite graph.

[0138] Then, the second encoding vector and the second syntax tree-action bipartite graph are input into the bipartite graph-based decoder for decoding processing, the syntax tree structure information of the generated t-1 predicted actions is learned, and the second encoding vector of the natural language sentence to be trained and the database pattern is integrated, and the tth predicted action is output. This process is repeated until a complete action sequence is generated as the predicted action sequence.

[0139] Finally, determine whether the predicted action sequence matches the training action sequence. If not, it means that the predicted action sequence output by the generator based on the natural language sentence to be trained and the database pattern does not meet the output target of the training action sequence, and the model parameters of the generator need to be adjusted. Based on this, the adjusted generator can be used as the generation model. Therefore, this application provides a possible implementation method, S603, for example, may include the following S6031-S6034:

[0140] S6031: Encode the natural language sentence to be trained and the database model through an encoder to obtain a second encoding vector of the natural language sentence to be trained and the database model.

[0141] S6032: Construct a second syntax tree-action bipartite graph of the generated t-1 predicted actions; the t-1 predicted actions are generated after the second encoding vector is input into the generator.

[0142] S6033: Decode the second encoding vector and the second syntax tree-action bipartite graph through a decoder based on the bipartite graph to obtain the t-th predicted action, until a complete predicted action sequence is obtained.

[0143] S6034: If the predicted action sequence does not match the action sequence to be trained, adjust the model parameters of the generator and use the adjusted generator as the generation model.

[0144] The above-described generative model training method enables the model to construct a syntax tree-action bipartite graph for generated actions, incorporate the syntax tree structure information of the generated actions, and consider both the encoding vectors of natural language statements and database schemas, as well as the syntax tree structure information of the generated actions, during the generation of action sequences. Based on this, the trained generative model can be used to execute the method for generating database query statements in the above-described embodiment, effectively and fully considering the syntax tree structure information of the generated actions, thereby improving the accuracy of the generated database query statements.

[0145] Regarding the method for generating database query statements provided in the above embodiment, the candidate action sequence generated by S303 is only for obtaining a more accurate candidate action sequence, and one candidate action sequence is uniquely converted into one database query statement; however, the candidate action sequence is an intermediate product for generating a database query statement, and there is a certain gap between it and the database query statement at the semantic level. Therefore, the database query statement to be processed corresponding to the natural language statement to be processed obtained by converting only one candidate action sequence is not accurate enough, which to a certain extent leads to a reduction in the accuracy of the generated database query statement.

[0146] Therefore, it is also possible to consider combining a beam search approach in S303 to generate multiple candidate action sequences and obtain a predicted probability for each candidate action sequence. Beam search is used to solve a class of problems: when predicting a sequence, only one element can be predicted at each prediction step, and the predicted probability of the entire sequence is expected to be the joint conditional probability of all elements. If each prediction step predicts the element with the highest current probability, the resulting sequence may not be the one with the highest predicted probability; that is, beam search predicts multiple elements at each prediction step to obtain multiple sequences.

[0147] On this basis, multiple candidate action sequences can be converted into multiple candidate database query statements. Furthermore, the natural language statement to be processed and each candidate database query statement are taken as a pair, and input into a ranking model used to predict the score of the candidate database query statement for sorting processing, and the score of each candidate database query statement is output; so that the predicted probability of the candidate action sequence corresponding to each candidate database query statement and the score of each candidate database query statement can be comprehensively considered, and the optimal database query statement can be determined from multiple candidate database query statements as the database query statement to be processed corresponding to the natural language statement to be processed.

[0148] See also Figure 7 , which is a flow chart of another method for generating a database query statement provided by an embodiment of the present application. Figure 7 As shown, the method for generating a database query statement includes the following steps:

[0149] S701: Encode the natural language sentence to be processed and the database schema of the database to be queried by generating an encoder of the model to obtain first encoding vectors of the natural language sentence to be processed and the database schema.

[0150] S702: Construct a first syntax tree-action bipartite graph of the generated t-1 actions; the t-1 actions are generated after the first encoding vector is input into the generation model, t is a positive integer, t≥2.

[0151] S703: Decode the first encoding vector and the first syntax tree-action bipartite graph through a bipartite graph-based decoder of the generative model to obtain the t-th action, until a complete plurality of candidate action sequences and a plurality of predicted probabilities of the plurality of candidate action sequences are generated.

[0152] In the embodiment of the present application, the specific implementation method of S701-S703 is similar to the specific implementation method of S301-S303 in the above-mentioned method embodiment of generating database query statements. The specific implementation method of S701-S703 refers to the specific implementation method of S301-S303 and will not be repeated here.

[0153] As an example, the candidate action sequence The predicted probability is based on the candidate action sequence The predicted probability of each action in is obtained, and the calculation formula is as follows:

[0154]

[0155] Among them, P(a i |Q,a1,…,a i-1 ) represents the predicted probability of the i-th action in the candidate action sequence.

[0156] S704: Convert the multiple candidate action sequences into multiple candidate database query statements.

[0157] S705: Sorting the natural language statement to be processed and each candidate database query statement using the ranking model to obtain a score for each candidate database query statement.

[0158] Among them, the sorting model is obtained by pre-training the sorter based on the natural language sentences to be trained, the database query sentences to be trained and the first score, as well as the natural language sentences to be processed, the erroneous database query sentences and the second score. The first score is greater than the second score. The specific implementation method of the training method refers to the embodiment of the training method of the sorting model below, which will not be described in detail here.

[0159] S706: Determine a database query statement to be processed from the plurality of candidate database query statements based on the predicted probability of the candidate action sequence corresponding to each candidate database query statement and the score of each candidate database query statement.

[0160] In the specific implementation of S706, first, consider the predicted probability of the candidate action sequence corresponding to each candidate database query statement, and sort multiple candidate database query statements from high to low. Then, consider the score of each candidate database query statement, traverse the sorted multiple candidate database query statements, and compare the score of each candidate database query statement with the score of the optimal database query statement. If the difference is greater than a certain difference, replace the optimal database query statement with the candidate database query statement. After the traversal is completed, the optimal database query statement can be used as the database query statement to be processed corresponding to the natural language statement to be processed; it should be noted that the initial value of the score of the optimal database query statement is a preset value. Therefore, the present application provides a possible implementation method, and S706 may include the following S7061-S7063:

[0161] S7061: Arrange the plurality of candidate database query statements in descending order according to the predicted probability of the candidate action sequence corresponding to each candidate database query statement.

[0162] S7062: Traverse multiple candidate database query statements arranged in descending order. If the difference between the score of the traversed candidate database query statement and the score of the optimal database query statement is greater than or equal to a preset difference, replace the optimal database query statement with the traversed candidate database query statement; the initial value of the score of the optimal database query statement is a preset value.

[0163] The initial value of the score of the optimal database query statement is a preset value, for example, 0.

[0164] S7063: After the traversal is completed, the optimal database query statement is determined as the database query statement to be processed.

[0165] The method for generating a database query statement provided in the above embodiment, based on generating multiple candidate action sequences, converts the multiple candidate action sequences into multiple candidate database query statements, comprehensively considers the predicted probability of the candidate action sequence corresponding to each candidate database query statement, and the score of each candidate database query statement, and determines the optimal database query statement from the multiple candidate database query statements as the database query statement to be processed corresponding to the natural language statement to be processed, so that the accuracy of the database query statement to be processed is higher.

[0166] With respect to the ranking model in the method for generating a database query statement provided in the above embodiment, a training method for the ranking model is introduced below in conjunction with the accompanying drawings.

[0167] See also Figure 8 , Figure 8 A flow chart of a training method for a sorting model provided in an embodiment of the present application. Figure 8 As shown, the method for obtaining the generative model includes the following steps:

[0168] S801: Obtain a natural language sentence to be trained, a database query sentence to be trained, and a first score.

[0169] In an embodiment of the present application, it is first necessary to construct training samples for training a sorter. The purpose of the sorter is to target an input natural language statement-database query statement pair. When the database query statement correctly corresponds to the natural language statement, the score of the database query statement is higher. When the database query statement incorrectly corresponds to the natural language statement, the score of the database query statement is lower. The training samples are then divided into positive samples and negative samples.

[0170] In specific practice, constructing a positive sample means taking the natural language sentence to be trained in S601 and the database query sentence to be trained corresponding to the natural language sentence to be trained as a pair, and setting a higher first score. The first score is the output target of the sorter for training the natural language sentence to be trained and the natural language sentence to be trained.

[0171] S802: Obtain a natural language sentence to be trained, an erroneous database query sentence, and a second score; the erroneous action sequence corresponding to the erroneous database query sentence is an action sequence generated by the natural language sentence input generator to be trained and does not match the action sequence to be trained, and the first score is greater than the second score.

[0172] In the embodiment of the present application, in addition to constructing positive samples, negative samples are also constructed. The premise is that the action sequence generated by the input generator of the natural language sentence to be trained, which does not match the action sequence to be trained, is used as the incorrect action sequence, and the database query statement converted from the incorrect action sequence is used as the incorrect database query statement. Based on this, the natural language sentence to be trained and the incorrect database query statement are treated as a pair, and a lower second score is set. The second score is the output target of the sorter for training the natural language sentence to be trained and the incorrect natural language sentence.

[0173] S803: Train a ranker based on the natural language sentence to be trained, the database query sentence to be trained and the first score, and the natural language sentence to be processed, the erroneous database query sentence and the second score to obtain a ranking model.

[0174] In an embodiment of the present application, the natural language sentences to be trained and the database query sentences to be trained are used as input, and the first score is used as output; and the natural language sentences to be processed and the erroneous database query sentences are used as input, and the second score is used as output, and the sorter is trained. The trained sorter can be used as a sorting model.

[0175] When S803 is specifically implemented, the training process is actually: first, the natural language sentence to be processed and the database query sentence to be trained, as well as the natural language sentence to be processed and the erroneous database query sentence are input into the sorter for sorting, and the prediction score of the database query sentence to be trained is output as the first prediction score, and the prediction score of the erroneous database query sentence is output as the second prediction score. Then, it is determined whether the first prediction score matches the first score, and whether the second prediction score matches the second score. If any of the judgment results is not matched, it means that the output target of the first prediction score of the database query sentence to be trained is higher and the second prediction score of the erroneous database query sentence is lower is not met, then the model parameters of the sorter need to be adjusted; based on this, the adjusted sorter can be used as a sorting model, and the loss function used in the adjustment process is the cross entropy loss function. Therefore, the present application provides a possible implementation method, and S803 may, for example, include the following S8031-S8032:

[0176] S8031: Sorting the natural language statement to be processed and the database query statement to be trained, as well as the natural language statement to be processed and the erroneous database query statement, by a sorter to obtain a first prediction score for the database query statement to be trained and a second prediction score for the erroneous database query statement.

[0177] S8032: If the first prediction score does not match the first score, or the second prediction score does not match the second score, adjust the model parameters of the sorter and use the adjusted sorter as the sorting model.

[0178] In addition, in order to avoid the introduction of a large amount of noise in the training process when the table names and column names in the large number of database query statements to be trained and the error database query statements are used as input, considering that each database query statement to be trained and the error database query statement is only rarely related to the table name and column name, the table names and column names in the large number of database query statements to be trained and the error database query statements are simplified, where the table name is replaced with "tab" and the column name is replaced with "col".

[0179] Through the aforementioned ranking model training method, the ranking model is able to assign a higher score to an input natural language statement-database query statement pair when the database query statement correctly corresponds to the natural language statement, and a lower score when the database query statement incorrectly corresponds to the natural language statement. Based on this, the trained ranking model can be used to execute the method for generating database query statements in the aforementioned embodiment. This can further combine the scores of candidate database query statements to determine a more accurate database query statement corresponding to the natural language statement to be processed, thereby further improving the accuracy of the generated database query statement.

[0180] See also Figure 9 , which is a flow chart of a training method for a generation model and a ranking model provided in an embodiment of the present application. Figure 9 As shown, the training method of the generation model and the sorting model includes the following steps:

[0181] S901: Based on the database schema, construct a natural language sentence to be trained and a database query sentence to be trained corresponding to the natural language sentence to be trained.

[0182] S902: Convert the database query statement to be trained into an action sequence to be trained.

[0183] S903: Train the generator according to the natural language sentences to be trained, the database pattern and the action sequence to be trained to obtain a generation model; the generator includes an encoder and a decoder based on a bipartite graph.

[0184] In the embodiment of the present application, the specific implementation method of S901-S903 is the same as the specific implementation method of S601-S603 in the above-mentioned method embodiment of generating a database query statement. The specific implementation method of S901-S903 refers to the specific implementation method of S601-S603 and will not be repeated here.

[0185] S904: Obtain a natural language sentence to be trained, a database query sentence to be trained, and a first score.

[0186] S905: Obtain the natural language sentence to be trained, the erroneous database query sentence, and the second score; the erroneous action sequence corresponding to the erroneous database query sentence is an action sequence generated by the natural language sentence input generator to be trained and does not match the action sequence to be trained, and the first score is greater than the second score.

[0187] S906: Train the sorter according to the natural language sentence to be trained, the database query sentence to be trained and the first score, and the natural language sentence to be processed, the erroneous database query sentence and the second score to obtain a sorting model.

[0188] In the embodiment of the present application, the specific implementation method of S904-S906 is the same as the specific implementation method of S801-S803 in the above-mentioned method embodiment of generating a database query statement. The specific implementation method of S904-S906 refers to the specific implementation method of S801-S803 and will not be repeated here.

[0189] The above generation and ranking models were trained on the training set of the publicly available relational database question-answering dataset, Spider. Since its test set is not publicly available, they were tested on the validation set. The exact set match metric was used to measure the correctness of the generated database query statements. In addition, the following models were selected as controls:

[0190] IRNet is a model that proposes database schema linking to identify tables and columns appearing in natural language sentences and proposes an intermediate representation to reduce the semantic distance between natural language sentences and database query statements;

[0191] Global-GNN is a model that proposes global reasoning on the grammatical structure of the output database query statement to determine the use of database constants;

[0192] RAT-SQL is a model that proposes to construct natural language statements and database schemas into a directed graph and use a relation-aware self-attention mechanism for representation learning.

[0193] LGESQL is a model that uses line graphs to enhance the meta-path information in learning directed graphs based on the above-mentioned RAT-SQL.

[0194] The test results are shown in Table 1 below:

[0195] Table 1 Test results

[0196] Model accuracy IRNet 53.2 Global-GNN 52.7 RAT-SQL 62.7 LGESQL 67.6 Generative Models 69.1 Generative Model-Ranking Model 69.8

[0197] See also Figure 10 , which is a specific application diagram of a method for generating a database query statement provided by an embodiment of the present application. A mobile phone user inputs a natural language statement to be processed, "How many teachers of category A are there?", and the mobile phone obtains the natural language statement to be processed, "How many teachers of category A are there?" and sends it to the server. The server uses the method for generating a database query statement provided by an embodiment of the present application to obtain a database query statement to be processed, "select count (column: sort A) from table: teacher," and sends it to the mobile phone so that the mobile phone displays the database query statement to be processed, "select count (column: sort A) from table: teacher." The server queries the database to be queried based on the database query statement to be processed, obtains the query result, and sends it to the mobile phone so that the mobile phone displays the query result.

[0198] To sum up, the method for generating database query statements provided in the embodiment of the present application can be applied to the form question and answer scenario in the dialogue system, and can also be applied to the data analysis scenario of the analysis system, etc.; in the above scenarios, it is necessary to convert natural language statements into database query statements.

[0199] In response to the method for generating a database query statement provided in the above embodiment, an embodiment of the present application also provides a device for generating a database query statement.

[0200] See also Figure 11 , Figure 11 Schematic diagram of a device for generating a database query statement provided in an embodiment of the present application. Figure 11 As shown, the device 1100 for generating a database query statement includes: an encoding unit 1101, a construction unit 1102, a decoding unit 1103 and a conversion unit 1104;

[0201] An encoding unit 1101 is configured to encode the natural language sentence to be processed and the database schema of the database to be queried using an encoder of the generation model to obtain a first encoding vector of the natural language sentence to be processed and the database schema;

[0202] A construction unit 1102 is configured to construct a first syntax tree-action bipartite graph of t-1 generated actions; the t-1 actions are generated after the first encoding vector is input into the generative model, where t is a positive integer and t≥2;

[0203] A decoding unit 1103 is configured to decode the first encoding vector and the first syntax tree-action bipartite graph using a bipartite graph-based decoder of the generative model to obtain the t-th action, until a complete candidate action sequence is generated;

[0204] The conversion unit 1104 is configured to convert the candidate action sequence into a database query statement to be processed corresponding to the natural language statement to be processed.

[0205] As a possible implementation, the decoding unit 1103 includes: an extraction subunit and a decoding subunit;

[0206] An extraction subunit, configured to extract the first syntax tree-action bipartite graph using a bipartite graph extractor to obtain a first action vector of an action node in the first syntax tree-action bipartite graph;

[0207] The decoding subunit is configured to decode the first coding vector and the first action vector through a decoder to obtain the t-th action until a candidate action sequence is generated.

[0208] As a possible implementation method, subunits are extracted, specifically for:

[0209] Obtain a first initialization vector for a syntax tree node and a second initialization vector for an action node in a first syntax tree-action bipartite graph;

[0210] The first initialization vector is fused with the second initialization vector to obtain a first motion vector.

[0211] As a possible implementation, the decoder includes a first decoding module, a second decoding module, and a fully connected layer, the first decoding module includes a first decoding layer and a second decoding layer, the second decoding module includes a third decoding layer and a fourth decoding layer; the decoding subunit is specifically configured to:

[0212] Decoding the first motion vector and the position vector corresponding to the first motion vector through a first decoding layer to obtain a second motion vector;

[0213] Decoding the first coding vector and the second motion vector through a second decoding layer to obtain a third motion vector;

[0214] Decoding the third motion vector through a third decoding layer to obtain a fourth motion vector;

[0215] Decoding the first encoding vector and the fourth motion vector through a fourth decoding layer to obtain a first decoding vector;

[0216] The first decoded vector is predicted through the fully connected layer to obtain the t-th action until a candidate action sequence is generated.

[0217] As a possible implementation, the bipartite graph extractor includes a graph attention network based on a multi-head attention mechanism; the first decoding layer includes a first action attention layer based on the multi-head attention mechanism, the second decoding layer includes a first encoding attention layer based on the multi-head attention mechanism, the third decoding layer includes a second action attention layer based on the multi-head attention mechanism, and the fourth decoding layer includes a second encoding attention layer based on the multi-head attention mechanism.

[0218] As a possible implementation, the apparatus further includes: a first training unit; the first training unit is configured to:

[0219] Based on the database schema, construct a natural language sentence to be trained and a database query statement to be trained corresponding to the natural language sentence to be trained;

[0220] Convert the query statement of the database to be trained into the action sequence to be trained;

[0221] A generator is trained according to natural language sentences to be trained, database patterns and action sequences to be trained to obtain a generation model; the generator includes an encoder and a decoder based on a bipartite graph.

[0222] As a possible implementation, the first training unit is specifically configured to:

[0223] Encoding the natural language sentence to be trained and the database pattern by an encoder to obtain a second encoding vector of the natural language sentence to be trained and the database pattern;

[0224] Construct the second syntax tree-action bipartite graph of the generated t-1 predicted actions; the t-1 predicted actions are generated after the second encoding vector is input into the generator;

[0225] The second encoding vector and the second syntax tree-action bipartite graph are decoded by a decoder based on a bipartite graph to obtain the t-th predicted action, until a complete predicted action sequence is obtained;

[0226] If the predicted action sequence does not match the action sequence to be trained, the model parameters of the generator are adjusted and the adjusted generator is used as the generation model.

[0227] As a possible implementation, the decoding unit 1103 is specifically configured to:

[0228] Decoding the first encoding vector and the first syntax tree-action bipartite graph using a bipartite graph-based decoder of the generative model to obtain the t-th action, until a complete plurality of candidate action sequences and a plurality of predicted probabilities of the plurality of candidate action sequences are generated;

[0229] The conversion unit 1104 is specifically configured to:

[0230] Converting multiple candidate action sequences into multiple candidate database query statements;

[0231] The natural language statement to be processed and each candidate database query statement are ranked by the ranking model to obtain a score for each candidate database query statement;

[0232] A database query statement to be processed is determined from multiple candidate database query statements according to the predicted probability of the candidate action sequence corresponding to each candidate database query statement and the score of each candidate database query statement.

[0233] As a possible implementation, the conversion unit 1104 is specifically configured to:

[0234] Arrange the plurality of candidate database query statements in descending order according to the predicted probability of the candidate action sequence corresponding to each candidate database query statement;

[0235] Traversing multiple candidate database query statements arranged in descending order, and if the difference between the score of the traversed candidate database query statement and the score of the optimal database query statement is greater than or equal to a preset difference, replacing the optimal database query statement with the traversed candidate database query statement; the initial value of the score of the optimal database query statement is a preset value;

[0236] After the traversal is completed, the optimal database query statement is determined as the database query statement to be processed.

[0237] As a possible implementation, the apparatus includes: a second training unit; the second training unit is configured to:

[0238] Obtaining a natural language sentence to be trained, a database query sentence to be trained, and a first score;

[0239] Obtaining a natural language sentence to be trained, an erroneous database query sentence, and a second score; the erroneous action sequence corresponding to the erroneous database query sentence is an action sequence generated by the natural language sentence input generator to be trained and does not match the action sequence to be trained, and the first score is greater than the second score;

[0240] A sorter is trained according to the natural language sentence to be trained, the database query sentence to be trained and the first score, and the natural language sentence to be processed, the erroneous database query sentence and the second score to obtain a sorting model.

[0241] As a possible implementation, the second training unit is specifically configured to:

[0242] Sorting the natural language statement to be processed and the database query statement to be trained, as well as the natural language statement to be processed and the erroneous database query statement, by a sorter, to obtain a first prediction score for the database query statement to be trained and a second prediction score for the erroneous database query statement;

[0243] If the first predicted score does not match the first score, or the second predicted score does not match the second score, the model parameters of the ranker are adjusted, and the adjusted ranker is used as the ranking model.

[0244] The device for generating a database query statement provided by the above embodiment first inputs the natural language statement to be processed and the database model into the encoder of the generation model, and outputs the first encoding vector of the natural language statement to be processed and the database model; secondly, after the first encoding vector is input into the generation model to generate t-1 actions, a first syntax tree-action bipartite graph of t-1 actions is constructed, where t is a positive integer and t≥2; then, the first encoding vector and the first syntax tree-action bipartite graph are input into the bipartite graph-based decoder of the generation model, and the tth action is output until a complete candidate action sequence is generated; finally, the candidate action sequence is converted into the database query statement to be processed corresponding to the natural language statement to be processed.

[0245] Based on this, after the encoder encodes the natural language sentence and the database schema of the database to obtain the encoding vector, and the encoding vector is input into the generation model to generate some actions, the syntax tree-action bipartite graph of the generated action is further constructed, and the syntax tree structure information of the generated action is introduced; on this basis, the decoder based on the bipartite graph decodes the encoding vector and the syntax tree-action bipartite graph, and in the process of generating the action sequence, both the encoding vector of the natural language sentence and the database schema and the syntax tree structure information of the generated action are considered to generate a more accurate action sequence, thereby improving the accuracy of the generated database query statement.

[0246] In response to the method for generating database query statements described above, an embodiment of the present application also provides a device for generating database query statements, so that the above-mentioned method for generating database query statements can be implemented and applied in practice. The computer device provided in the embodiment of the present application will be introduced from the perspective of hardware entity below.

[0247] See also Figure 12 , Figure 12This is a schematic diagram of a server structure provided by an embodiment of the present application. The server 1200 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPUs) 1222 (for example, one or more processors) and memories 1232, and one or more storage media 1230 (for example, one or more massive storage devices) for storing application programs 1242 or data 1244. Among them, the memories 1232 and the storage media 1230 may be temporary storage or permanent storage. The program stored in the storage medium 1230 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server. Furthermore, the central processing unit 1222 may be configured to communicate with the storage medium 1230 to execute a series of instruction operations in the storage medium 1230 on the server 1200.

[0248] The server 1200 may also include one or more power supplies 1226, one or more wired or wireless network interfaces 1250, one or more input and output interfaces 1258, and / or one or more operating systems 1241, such as Windows Server 200. TM , Mac OS X TM , Unix TM , Linux TM , FreeBSD TM etc.

[0249] The steps performed by the server in the above embodiment can be based on the Figure 12 The server structure shown.

[0250] The CPU 1222 is configured to execute the following steps:

[0251] Encoding the natural language sentence to be processed and the database schema of the database to be queried by generating an encoder of the model to obtain a first encoding vector of the natural language sentence to be processed and the database schema;

[0252] Construct the first syntax tree-action bipartite graph of the generated t-1 actions; t-1 actions are generated after the first encoding vector is input into the generation model, t is a positive integer, t ≥ 2;

[0253] Decoding the first encoding vector and the first syntax tree-action bipartite graph through the generative model's bipartite graph decoder to obtain the t-th action until a complete sequence of candidate actions is generated.

[0254] The candidate action sequences are converted into database query statements to be processed corresponding to the natural language statements to be processed.

[0255] Optionally, the CPU 1222 may also execute the method steps of any specific implementation of the method for generating a database query statement in the embodiments of the present application.

[0256] See also Figure 13 , Figure 13 This is a schematic diagram of the structure of a terminal device provided in an embodiment of the present application. For ease of explanation, only the parts related to the embodiment of the present application are shown. For specific technical details not disclosed, please refer to the method section of the embodiment of the present application. The terminal device can be any terminal device including a mobile phone, tablet computer, PDA, etc. Taking the terminal device as a mobile phone as an example:

[0257] Figure 13 The block diagram shows a partial structure of a mobile phone related to the terminal device provided in the embodiment of the present application. Figure 13 The mobile phone includes components such as a radio frequency (RF) circuit 1310, a memory 1320, an input unit 1330, a display unit 1340, a sensor 1350, an audio circuit 1360, a wireless fidelity (WiFi) module 1370, a processor 1380, and a power supply 1390. Those skilled in the art will understand that Figure 13 The mobile phone structure shown in the figure does not constitute a limitation to the mobile phone, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.

[0258] The following combination Figure 13 A detailed introduction to the various components of a mobile phone:

[0259] The RF circuit 1310 can be used to receive and send signals during information transmission or calls. In particular, after receiving downlink information from the base station, it is sent to the processor 1380 for processing. In addition, the designed uplink data is sent to the base station. Generally, the RF circuit 1310 includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier (LNA), a duplexer, etc. In addition, the RF circuit 1310 can also communicate with the network and other devices through wireless communication. The above-mentioned wireless communication can use any communication standard or protocol, including but not limited to Global System of Mobile Communication (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Long Term Evolution (LTE), email, Short Messaging Service (SMS), etc.

[0260] Memory 1320 can be used to store software programs and modules. Processor 1380 implements various functional applications and data processing of the mobile phone by running the software programs and modules stored in memory 1320. Memory 1320 may mainly include a program storage area and a data storage area. The program storage area may store an operating system and at least one application required for a function (such as a sound playback function, an image playback function, etc.); the data storage area may store data created based on the use of the mobile phone (such as audio data, a phone book, etc.). In addition, memory 1320 may include high-speed random access memory and non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.

[0261] The input unit 1330 can be used to receive input digital or character information, and to generate key signal input related to the user settings and function control of the mobile phone. Specifically, the input unit 1330 may include a touch panel 1331 and other input devices 1332. The touch panel 1331, also known as a touch screen, can collect user touch operations on or near it (such as operations performed by the user using a finger, stylus, or any other suitable object or accessory on or near the touch panel 1331) and drive the corresponding connection device according to a pre-set program. Optionally, the touch panel 1331 may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch direction and detects the signal generated by the touch operation, and transmits the signal to the touch controller; the touch controller receives the touch information from the touch detection device and converts it into touch point coordinates, which are then sent to the processor 1380. It can also receive commands sent by the processor 1380 and execute them. In addition, the touch panel 1331 can be implemented using various types such as resistive, capacitive, infrared, and surface acoustic wave. In addition to the touch panel 1331, the input unit 1330 may further include other input devices 1332. Specifically, the other input devices 1332 may include, but are not limited to, one or more of a physical keyboard, function keys (such as volume control keys, power keys, etc.), a trackball, a mouse, and a joystick.

[0262] The display unit 1340 can be used to display information input by the user or information provided to the user and various menus of the mobile phone. The display unit 1340 may include a display panel 1341. Optionally, the display panel 1341 may be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), etc. Further, the touch panel 1331 may cover the display panel 1341. When the touch panel 1331 detects a touch operation on or near it, it is transmitted to the processor 1380 to determine the type of touch event. Subsequently, the processor 1380 provides corresponding visual output on the display panel 1341 according to the type of touch event. Although in Figure 10 In the embodiment, the touch panel 1331 and the display panel 1341 are used as two independent components to realize the input and output functions of the mobile phone, but in some embodiments, the touch panel 1331 and the display panel 1341 can be integrated to realize the input and output functions of the mobile phone.

[0263] The mobile phone may also include at least one sensor 1350, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor, wherein the ambient light sensor may adjust the brightness of the display panel 1341 according to the brightness of the ambient light, and the proximity sensor may turn off the display panel 1341 and / or the backlight when the mobile phone is moved to the ear. As a type of motion sensor, the accelerometer sensor can detect the magnitude of acceleration in all directions (generally three axes), and can detect the magnitude and direction of gravity when stationary. It can be used for applications that identify the posture of the mobile phone (such as horizontal and vertical screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, tapping), etc.; as for other sensors that the mobile phone can also be configured with, such as gyroscopes, barometers, hygrometers, thermometers, infrared sensors, etc., they will not be described here.

[0264] Audio circuit 1360, speaker 1361, and microphone 1362 provide an audio interface between the user and the phone. Audio circuit 1360 converts received audio data into electrical signals and transmits them to speaker 1361, which then converts them into sound signals for output. Microphone 1362, on the other hand, converts collected sound signals into electrical signals, which are then received by audio circuit 1360 and converted into audio data. The audio data is then processed by processor 1380 and transmitted to, for example, another phone via RF circuit 1310, or stored in memory 1320 for further processing.

[0265] WiFi is a short-range wireless transmission technology. The mobile phone can help users send and receive emails, browse the web and access streaming media through the WiFi module 1370. It provides users with wireless broadband Internet access. Figure 13 A WiFi module 1370 is shown, but it is understandable that it is not an essential component of the mobile phone and can be omitted as needed without changing the essence of the invention.

[0266] Processor 1380 is the control center of the phone, connecting all parts of the phone using various interfaces and circuits. By running or executing software programs and / or modules stored in memory 1320 and accessing data stored in memory 1320, it executes various phone functions and processes data, thereby providing overall control of the phone. Optionally, processor 1380 may include one or more processing units; preferably, processor 1380 may integrate an application processor and a modem processor. The application processor primarily handles the operating system, user interface, and application programs, while the modem processor primarily handles wireless communications. It is understood that the modem processor may not be integrated into processor 1380.

[0267] The mobile phone also includes a power supply 1390 (such as a battery) for supplying power to various components. Preferably, the power supply can be logically connected to the processor 1380 through a power management system, thereby managing charging, discharging, and power consumption through the power management system.

[0268] Although not shown, the mobile phone may also include a camera, a Bluetooth module, etc., which will not be described in detail here.

[0269] In the embodiment of the present application, the memory 1320 included in the mobile phone can store program codes and transmit the program codes to the processor.

[0270] The processor 1380 included in the mobile phone can execute the method for generating a database query statement provided in the above embodiment according to the instructions in the program code.

[0271] An embodiment of the present application also provides a computer-readable storage medium for storing a computer program, which is used to execute the method for generating a database query statement provided in the above embodiment.

[0272] The present application also provides a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the method for generating a database query statement provided in various optional implementations of the above aspects.

[0273] A person skilled in the art will understand that all or part of the steps of implementing the above-mentioned method embodiment can be completed by hardware related to program instructions, and the above-mentioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above-mentioned method embodiment; and the above-mentioned storage medium can be at least one of the following media: read-only memory (ROM), random access memory (RAM), magnetic disk or optical disk, etc., various media that can store program codes.

[0274] It should be noted that the various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device and system embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments. The device and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of this embodiment. A person of ordinary skill in the art can understand and implement it without expending creative work.

[0275] The above is merely one specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.

Claims

1. A method for generating a database query statement, characterized in that: The method comprises: Encoding the natural language sentence to be processed and the database schema of the database to be queried by generating an encoder of the model to obtain a first encoding vector of the natural language sentence to be processed and the database schema; Constructing a first syntax tree-action bipartite graph of t-1 generated actions; the t-1 actions are generated after the first encoding vector is input into the generation model, where t is a positive integer and t≥2; Decoding the first encoding vector and the first syntax tree-action bipartite graph using a bipartite graph-based decoder of the generative model to obtain the t-th action, until a complete candidate action sequence is generated; generating the complete candidate action sequence includes generating multiple complete candidate action sequences and multiple predicted probabilities of the multiple candidate action sequences; Converting the candidate action sequence into a database query statement to be processed corresponding to the natural language statement to be processed specifically includes: converting the plurality of candidate action sequences into a plurality of candidate database query statements; Sorting the natural language statement to be processed and each of the candidate database query statements using a ranking model to obtain a score for each of the candidate database query statements; The database query statement to be processed is determined from a plurality of the candidate database query statements according to the predicted probability of the candidate action sequence corresponding to each of the candidate database query statements and the score of each of the candidate database query statements.

2. The method according to claim 1, characterized in that The bipartite graph-based decoder includes a bipartite graph extractor and a decoder; the bipartite graph-based decoder based on the generative model decodes the first encoding vector and the first syntax tree-action bipartite graph to obtain the t-th action until a complete candidate action sequence is generated, including: Extracting the first syntax tree-action bipartite graph using the bipartite graph extractor to obtain a first action vector of an action node in the first syntax tree-action bipartite graph; The first coding vector and the first action vector are decoded by the decoder to obtain the t-th action, until the candidate action sequence is generated.

3. The method according to claim 2, characterized in that The extracting and processing the first syntax tree-action bipartite graph by the bipartite graph extractor to obtain a first action vector of an action node in the first syntax tree-action bipartite graph includes: Obtain a first initialization vector for a syntax tree node and a second initialization vector for an action node in the first syntax tree-action bipartite graph; The first initialization vector is fused with the second initialization vector to obtain the first motion vector.

4. The method according to claim 2, characterized in that The decoder includes a first decoding module, a second decoding module, and a fully connected layer, the first decoding module includes a first decoding layer and a second decoding layer, and the second decoding module includes a third decoding layer and a fourth decoding layer; the decoder decodes the first encoding vector and the first action vector to obtain the t-th action until the candidate action sequence is generated, including: Decoding the first motion vector and the position vector corresponding to the first motion vector through the first decoding layer to obtain a second motion vector; Decoding the first coding vector and the second motion vector through the second decoding layer to obtain a third motion vector; Decoding the third motion vector through the third decoding layer to obtain a fourth motion vector; Decoding the first encoding vector and the fourth motion vector through the fourth decoding layer to obtain a first decoding vector; The first decoding vector is predicted by the fully connected layer to obtain the t-th action until the candidate action sequence is generated.

5. The method according to claim 4, characterized in that The bipartite graph extractor includes a graph attention network based on a multi-head attention mechanism; the first decoding layer includes a first action attention layer based on a multi-head attention mechanism, the second decoding layer includes a first encoding attention layer based on a multi-head attention mechanism, the third decoding layer includes a second action attention layer based on a multi-head attention mechanism, and the fourth decoding layer includes a second encoding attention layer based on a multi-head attention mechanism.

6. The method according to claim 1, characterized in that The training steps of the generative model include: Based on the database schema, constructing a natural language sentence to be trained and a database query statement to be trained corresponding to the natural language sentence to be trained; Converting the to-be-trained database query statement into a to-be-trained action sequence; A generator is trained according to the natural language sentence to be trained, the database model and the action sequence to be trained to obtain the generation model; the generator includes the encoder and the decoder based on the bipartite graph.

7. The method according to claim 6, characterized in that The step of training a generator according to the natural language sentence to be trained, the database schema, and the action sequence to be trained to obtain the generation model includes: Encoding the natural language sentence to be trained and the database schema by the encoder to obtain a second encoding vector of the natural language sentence to be trained and the database schema; Constructing a second syntax tree-action bipartite graph of the generated t-1 predicted actions; the t-1 predicted actions are generated after the second encoding vector is input into the generator; Decoding the second encoding vector and the second syntax tree-action bipartite graph using the bipartite graph-based decoder to obtain the t-th predicted action, until a complete predicted action sequence is obtained; If the predicted action sequence does not match the action sequence to be trained, the model parameters of the generator are adjusted, and the adjusted generator is used as the generation model.

8. The method according to claim 1, characterized in that Determining the database query statement to be processed from a plurality of candidate database query statements based on the predicted probability of the candidate action sequence corresponding to each candidate database query statement and the score of each candidate database query statement includes: Arrange the plurality of candidate database query statements in descending order according to the predicted probability of the candidate action sequence corresponding to each candidate database query statement; Traversing the plurality of candidate database query statements arranged in descending order, and if the difference between the score of the traversed candidate database query statement and the score of the optimal database query statement is greater than or equal to a preset difference, replacing the optimal database query statement with the traversed candidate database query statement; the initial value of the score of the optimal database query statement is a preset value; After the traversal is completed, the optimal database query statement is determined as the database query statement to be processed.

9. The method according to claim 6, characterized in that The training steps of the ranking model include: Obtaining the natural language sentence to be trained, the database query sentence to be trained, and a first score; Obtaining the natural language sentence to be trained, an erroneous database query sentence, and a second score; the erroneous action sequence corresponding to the erroneous database query sentence is an action sequence generated by the generator inputted with the natural language sentence to be trained and does not match the action sequence to be trained, and the first score is greater than the second score; A ranker is trained based on the natural language sentence to be trained, the database query sentence to be trained and the first score, and the natural language sentence to be processed, the erroneous database query sentence and the second score to obtain the ranking model.

10. The method according to claim 9, characterized in that The step of training a ranker based on the natural language sentence to be trained, the database query sentence to be trained, and the first score, and the natural language sentence to be processed, the erroneous database query sentence, and the second score to obtain the ranking model includes: Sorting the natural language statement to be processed and the database query statement to be trained, and the natural language statement to be processed and the erroneous database query statement, by a sorter, to obtain a first prediction score for the database query statement to be trained and a second prediction score for the erroneous database query statement; If the first prediction score does not match the first score, or the second prediction score does not match the second score, the model parameters of the ranker are adjusted, and the adjusted ranker is used as the ranking model.

11. A device for generating a database query statement, characterized in that: The device comprises: an encoding unit, a construction unit, a decoding unit and a conversion unit; The encoding unit is configured to encode the natural language sentence to be processed and the database schema of the database to be queried by using an encoder of the generation model to obtain a first encoding vector of the natural language sentence to be processed and the database schema; The construction unit is configured to construct a first syntax tree-action bipartite graph of t-1 generated actions; the t-1 actions are generated after the first encoding vector is input into the generation model, where t is a positive integer and t≥2; The decoding unit is configured to decode the first encoding vector and the first syntax tree-action bipartite graph using a bipartite graph-based decoder of the generative model to obtain the t-th action, until a complete candidate action sequence is generated; the step of generating a complete candidate action sequence includes generating multiple complete candidate action sequences and multiple predicted probabilities of the multiple candidate action sequences; The conversion unit is used to convert the candidate action sequence into a database query statement to be processed corresponding to the natural language statement to be processed, and is specifically used to: converting the plurality of candidate action sequences into a plurality of candidate database query statements; Sorting the natural language statement to be processed and each of the candidate database query statements using a ranking model to obtain a score for each of the candidate database query statements; The database query statement to be processed is determined from a plurality of the candidate database query statements according to the predicted probability of the candidate action sequence corresponding to each of the candidate database query statements and the score of each of the candidate database query statements.

12. The device according to claim 11, characterized in that The bipartite graph-based decoder includes a bipartite graph extractor and a decoder; the decoding unit includes: an extraction subunit, configured to extract the first syntax tree-action bipartite graph using the bipartite graph extractor to obtain a first action vector of an action node in the first syntax tree-action bipartite graph; A decoding subunit is configured to decode the first coding vector and the first action vector through the decoder to obtain the t-th action until the candidate action sequence is generated.

13. The device according to claim 12, characterized in that The extraction subunit is specifically used for: Obtain a first initialization vector for a syntax tree node and a second initialization vector for an action node in the first syntax tree-action bipartite graph; The first initialization vector is fused with the second initialization vector to obtain the first motion vector.

14. The device according to claim 12, characterized in that The decoder includes a first decoding module, a second decoding module and a fully connected layer, the first decoding module includes a first decoding layer and a second decoding layer, and the second decoding module includes a third decoding layer and a fourth decoding layer; the decoding subunit is specifically used to: Decoding the first motion vector and the position vector corresponding to the first motion vector through the first decoding layer to obtain a second motion vector; Decoding the first coding vector and the second motion vector through the second decoding layer to obtain a third motion vector; Decoding the third motion vector through the third decoding layer to obtain a fourth motion vector; Decoding the first encoding vector and the fourth motion vector through the fourth decoding layer to obtain a first decoding vector; The first decoding vector is predicted by the fully connected layer to obtain the t-th action until the candidate action sequence is generated.

15. The device according to claim 14, characterized in that The bipartite graph extractor includes a graph attention network based on a multi-head attention mechanism; the first decoding layer includes a first action attention layer based on a multi-head attention mechanism, the second decoding layer includes a first encoding attention layer based on a multi-head attention mechanism, the third decoding layer includes a second action attention layer based on a multi-head attention mechanism, and the fourth decoding layer includes a second encoding attention layer based on a multi-head attention mechanism.

16. The device according to claim 11, characterized in that Also includes: First training unit; The first training unit is configured to include: Based on the database schema, constructing a natural language sentence to be trained and a database query statement to be trained corresponding to the natural language sentence to be trained; Converting the to-be-trained database query statement into a to-be-trained action sequence; A generator is trained according to the natural language sentence to be trained, the database model and the action sequence to be trained to obtain the generation model; the generator includes the encoder and the decoder based on the bipartite graph.

17. The device according to claim 16, characterized in that The first training unit is specifically used to: Encoding the natural language sentence to be trained and the database schema by the encoder to obtain a second encoding vector of the natural language sentence to be trained and the database schema; Constructing a second syntax tree-action bipartite graph of the generated t-1 predicted actions; the t-1 predicted actions are generated after the second encoding vector is input into the generator; Decoding the second encoding vector and the second syntax tree-action bipartite graph using the bipartite graph-based decoder to obtain the t-th predicted action, until a complete predicted action sequence is obtained; If the predicted action sequence does not match the action sequence to be trained, the model parameters of the generator are adjusted, and the adjusted generator is used as the generation model.

18. The device according to claim 11, characterized in that The conversion unit is specifically used for: Arrange the plurality of candidate database query statements in descending order according to the predicted probability of the candidate action sequence corresponding to each candidate database query statement; Traversing the plurality of candidate database query statements arranged in descending order, and if the difference between the score of the traversed candidate database query statement and the score of the optimal database query statement is greater than or equal to a preset difference, replacing the optimal database query statement with the traversed candidate database query statement; the initial value of the score of the optimal database query statement is a preset value; After the traversal is completed, the optimal database query statement is determined as the database query statement to be processed.

19. The device according to claim 16, characterized in that Also includes: Second training unit; The second training unit is used to: Obtaining the natural language sentence to be trained, the database query sentence to be trained, and a first score; Obtain the natural language sentence to be trained, the error database query sentence and the second score; The erroneous action sequence corresponding to the erroneous database query statement is an action sequence generated by the generator input with the natural language statement to be trained and does not match the action sequence to be trained, and the first score is greater than the second score; A ranker is trained based on the natural language sentence to be trained, the database query sentence to be trained and the first score, and the natural language sentence to be processed, the erroneous database query sentence and the second score to obtain the ranking model.

20. The device according to claim 19, characterized in that The second training unit is specifically used to: Sorting the natural language statement to be processed and the database query statement to be trained, and the natural language statement to be processed and the erroneous database query statement, by a sorter, to obtain a first prediction score for the database query statement to be trained and a second prediction score for the erroneous database query statement; If the first prediction score does not match the first score, or the second prediction score does not match the second score, the model parameters of the ranker are adjusted, and the adjusted ranker is used as the ranking model.

21. A computer device, characterized in that: The device includes a processor and a memory: The memory is used to store program code and transmit the program code to the processor; The processor is configured to execute the method for generating a database query statement according to any one of claims 1 to 10 according to the instructions in the program code.

22. A computer-readable storage medium, characterized in that The computer-readable storage medium is used to store a computer program, and the computer program is used to execute the method for generating a database query statement according to any one of claims 1 to 10.

23. A computer program product, characterized in that The method comprises a computer program or an instruction; when the computer program or the instruction is executed by a processor, the method for generating a database query statement according to any one of claims 1 to 10 is executed.

Citation Information

Patent Citations

  • Multi-round natural language to SQL method based on intermediate syntax tree

    CN112069199A