Statement generation method and device, equipment and medium

By filtering candidate data tables to reduce resource consumption of large models, SQL statements are directly generated, which solves the problem of low SQL statement generation efficiency in the field of question and answers of large models, and achieves more efficient SQL statement generation.

CN119149560APending Publication Date: 2024-12-17MASHANG CONSUMER FINANCE CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202410924342.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-09
Publication Date
2024-12-17

AI Technical Summary

Technical Problem

In the field of question and answer, due to resource limitations, SQL statement generation is inefficient and takes a long time, and cannot effectively meet the needs of large-scale data processing.

Method used

By determining the similarity between the target vector of the problem text and the table vector of the target data table, pre-filtering the candidate data table, reducing the resource consumption of the big model when generating SQL statements, and directly generating structured query statements based on the candidate data table.

Benefits of technology

It improves the efficiency of SQL statement generation, reduces the resource loss of large models, and improves the accuracy and efficiency of the generation process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119149560A_ABST
    Figure CN119149560A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a statement generation method and device, equipment and a medium. The SQL statement generation method comprises the steps that a target vector of a question text is determined; determining the similarity between the table vector of the target data table and the target vector; if the similarity meets a preset condition, taking the target data table as a candidate data table; and when the process of generating the query statement for the problem text is entered, the structured query statement of the problem text is generated according to the candidate data table, so that the resource loss of a large model is reduced, and the SQL statement generation efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of natural language processing, and in particular to a sentence generation method, apparatus, device and medium. Background Art

[0002] With the continuous development of big models, big models are widely used in the field of question answering. The big model receives the question text, determines the structured query language (SQL) statement corresponding to the question text, and then determines the corresponding answer text according to the structured query statement. However, since the question answering field involves a large amount of data and the computing resources of the big model are limited, this results in the large model occupying a large amount of resources and taking a long time when applied, which in turn affects the efficiency of SQL statement generation. Summary of the invention

[0003] The present application provides a statement generation method, apparatus, device and medium, which reduces resource loss of large models and improves the efficiency of SQL statement generation.

[0004] In a first aspect, an embodiment of the present application provides a sentence generation method, the method comprising:

[0005] Determine the target vector of the question text;

[0006] Determining the similarity between the table vector of the target data table and the target vector;

[0007] If the similarity meets the preset condition, the target data table is used as a candidate data table;

[0008] When entering the process of generating a query statement for the question text, a structured query statement for the question text is generated according to the candidate data table.

[0009] In a second aspect, an embodiment of the present application provides a sentence generation device, the device comprising:

[0010] A processing module, used to determine a target vector of the question text; determine the similarity between a table vector of a target data table and the target vector; if the similarity meets a preset condition, use the target data table as a candidate data table;

[0011] A generating module is used to generate a structured query statement for the question text according to the candidate data table when entering the process of generating a query statement for the question text.

[0012] In a third aspect, an embodiment of the present application provides an electronic device, which includes at least a processor and a memory, and the processor is used to implement the steps of any of the above-mentioned sentence generation methods when executing a computer program stored in the memory.

[0013] In a fourth aspect, an embodiment of the present application provides a computer storage medium storing a computer program executable by an electronic device, wherein when the program runs on the electronic device, the electronic device executes the steps of any one of the above-mentioned sentence generation methods.

[0014] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes: a computer program code, which, when executed on the electronic device, enables the electronic device to execute the steps of any one of the above-mentioned sentence generation methods.

[0015] In an embodiment of the present application, before entering the process of generating a query statement for the question text, the target vector of the question text is first determined; the similarity between the table vector of the target data table and the target vector is determined; if the similarity meets the preset conditions, the target data table is used as a candidate data table; when entering the process of generating a query statement for the question text, a structured query statement of the question text is generated according to the candidate data table. In an embodiment of the present application, the electronic device first determines whether the target data table can be used as a candidate data table in the process of generating a query statement for the question text based on the table vector corresponding to the target data table and the target vector corresponding to the question text. If the target data table can be used as a candidate data table, when it is necessary to generate a structured query statement for the question text, the structured query statement of the question text is directly generated according to the candidate data table, without the need to determine whether the target data table can be used as a candidate data table when generating a structured statement. In short, the process of determining the candidate data table and the process of generating a structured statement based on the candidate data table are separate and independently executed, which reduces the resource loss of the process of generating a structured statement and improves the efficiency of SQL statement generation. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the technical solution of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. 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 paying any creative work.

[0017] Figure 1 A schematic diagram of a sentence generation process provided in an embodiment of the present application;

[0018] Figure 2 A schematic diagram of the SQL statement generation process provided in the embodiment of the present application;

[0019] Figure 3 A schematic diagram of the structure of a sentence generation device provided in an embodiment of the present application;

[0020] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0021] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application.

[0022] It should be noted that the brief description of terms in this application is only for the convenience of understanding the embodiments described below, and is not intended to limit the embodiments of this application. Unless otherwise specified, these terms should be understood according to their common and usual meanings.

[0023] The terms "first", "second", "third", etc. in the specification and claims of this application and the above drawings are used to distinguish similar or similar objects or entities, and do not necessarily mean to limit a specific order or sequence, unless otherwise noted. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances.

[0024] The terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover but not exclude inclusion, for example, a product or device comprising a list of components is not necessarily limited to all the components expressly listed but may include other components not expressly listed or inherent to such product or device.

[0025] The term "module" refers to any known or later developed hardware, software, firmware, artificial intelligence, fuzzy logic, or combination of hardware and / or software code that is capable of performing the functions associated with that element.

[0026] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.

[0027] For the convenience of explanation, the above description has been made in conjunction with specific embodiments. However, the above exemplary discussion is not intended to be exhaustive or limit the embodiments to the specific forms disclosed above. Based on the above teachings, various modifications and variations can be obtained. The selection and description of the above embodiments are to better explain the principles and practical applications, so that those skilled in the art can better use the embodiments and various different variations of the embodiments suitable for specific use considerations.

[0028] In order to better understand the embodiments of the present application, the application scenarios applicable to the embodiments of the present application are described below. Statement generation is an important basic tool in application fields such as information extraction, question-answering systems, syntactic analysis, and machine translation, and plays an important role in the process of natural language processing technology becoming practical. Statement generation is to convert text into SQL statements that can be recognized by machines, so that the data required for search can be generated based on the SQL statements.

[0029] In the first related technology, the corresponding data table and field name are obtained by obtaining the data table name input by the user; then the corresponding SQL code is generated according to the SQL operation statement selected by the user. However, this method can only be directly matched when the user is very familiar with the data table. If the user is not familiar with the content of the data table, he can only find the required table through the vague table description. At this time, the solution cannot provide a candidate table for operation in the first step. Because the user is not clear about the structure of the entire data table and the content of the data table.

[0030] In the second related technology, the knowledge base is initially constructed by constructing data entries corresponding to query questions, SQL query statements, and table structures. Then, the model is encoded with a noisy data set and a noise-free subtask, and is used to generate the corresponding SQL after training. However, the construction of the training set of this method is too time-consuming and labor-intensive, which will consume too much cost in the data preparation stage. In addition, although noise interference training is used, the Bidirectional Encoder Representation from Transformers (BERT) model itself is not a similarity embedding model, and its ability to extract information is limited when the table and description are too long. Secondly, each time the matching score is calculated by BERT, it takes too much time when the candidate set is large.

[0031] In the third related technology, a semantic matching network based on a pre-trained language model is constructed by using a cross encoder (CrossEncoder). CrossEncoder will concatenate two sentences, input them into the pre-trained language model, use the attention of the transformer for deeper semantic interaction, and then connect to a classification layer to output the probability of similarity for generating corresponding SQL. There are three main defects: First, CrossEncoder needs to be trained, and the construction of the training set is too time-consuming and laborious; second, the CrossEncoder's scoring tends to be distributed in two extremes, and the distinction between tables with higher similarity is small; third, the structural information of the table is not fully utilized.

[0032] In view of this, in order to improve the accuracy, portability, versatility and scalability of statement generation and to enhance the efficiency of generating SQL statements, the embodiments of the present application provide a statement generation method, apparatus, device and medium.

[0033] In an embodiment of the present application, the electronic device determines a target vector of a question text; determines the similarity between a table vector of a target data table and a target vector; if the similarity satisfies a preset condition, the target data table is used as a candidate data table; and when entering the process of generating a query statement for the question text, a structured query statement for the question text is generated based on the candidate data table.

[0034] The sentence generation method according to the embodiment of the present application can be executed by an electronic device such as a terminal device or a server, and the terminal device can be a vehicle-mounted device, a user equipment (UE), a mobile device, a user equipment, a terminal, a cellular phone, a cordless phone, a personal digital assistant (PDA), a handheld device, a computing device, a wearable device, etc. The method can be implemented by a processor calling a computer-readable program instruction stored in a memory. The server can be an independent physical server, a server cluster consisting of multiple servers, or a cloud server capable of cloud computing.

[0035] The statement generation method of the embodiment of the present application can be applied to any scenario where SQL statements need to be generated, and the method can be applied to products in these scenarios.

[0036] Figure 1 A schematic diagram of a statement generation process provided in an embodiment of the present application, the process includes:

[0037] S101: Determine the target vector corresponding to the question text.

[0038] A sentence generation method provided in an embodiment of the present application is applied to an electronic device, which may be a server, a PC, etc.

[0039] In the embodiment of the present application, the electronic device obtains the question text input by the user. The manner in which the electronic device obtains the question text input by the user is not limited in the embodiment of the present application. For example, the electronic device can obtain the question text through the front-end page. Optionally, the user can directly input the text question to the electronic device through a module such as a keyboard; or input voice information to the electronic device through a module such as a microphone, and after the electronic device receives the voice information, the voice information is converted into the question text; or the question text can be sent to the electronic device through other electronic devices.

[0040] In the embodiment of the present application, after the electronic device obtains the question text input by the user, the electronic device determines the target vector corresponding to the question text.

[0041] In a possible implementation, a knowledge base is stored in the electronic device, and the knowledge base stores word vectors corresponding to each character. The electronic device determines the target word vector corresponding to each character contained in the question text based on the knowledge base, and constructs the target vector corresponding to the question text based on the position of the character corresponding to each target word vector in the question text. For example, the question text is ABCDE, and the electronic device determines the target word vector a corresponding to the character A, determines the target word vector b corresponding to the character B, determines the target word vector c corresponding to the character C, determines the target word vector d corresponding to the character D, and determines the target word vector e corresponding to the character E by accessing the knowledge base. Based on this, the electronic device determines that the target vector corresponding to the question text is abcde.

[0042] In another possible implementation, the electronic device may determine the target vector corresponding to the question text through a feature extraction model. Specifically, the electronic device inputs the question text into the feature extraction model, and the feature extraction model processes the question text, and determines and outputs the target vector corresponding to the question text based on the semantic information of the question text. In the embodiment of the present application, the feature extraction model may be a Moka Massive Mixed Embedding (M3E) model, or other models.

[0043] S102: Determine the similarity between the table vector of the target data table and the target vector; if the similarity meets a preset condition, use the target data table as a candidate data table.

[0044] Since the question-answering field contains a large number of data tables and the computing resources of the large model are limited, if each data table and the question text are input into the large model together, and the large model selects the candidate data table used to generate the SQL statement corresponding to the question text from each data table, a large amount of computing resources of the large model will be used to determine the candidate data table, which will result in a long time and low efficiency in generating SQL statements.

[0045] In view of this, in order to improve the efficiency of SQL statement generation, in an embodiment of the present application, the electronic device can first determine the candidate data table used when generating the SQL statement corresponding to the question text, so that the large model does not need to determine the target data table, but directly generates the SQL statement corresponding to the question text based on the candidate data table, thereby reducing the time consumption of SQL statement generation and improving the accuracy of SQL statement generation.

[0046] Specifically, in the embodiment of the present application, the electronic device stores a table vector corresponding to the target data table, and the electronic device can determine the similarity between the question text and the target data table based on the table vector corresponding to the target data table and the target vector corresponding to the question text, and then determine whether the target data table is a candidate data table used when generating the SQL statement corresponding to the question text based on the similarity and the stored preset conditions. The table vector corresponding to the target data table is used to reflect the information of the data contained in the data table.

[0047] Among them, when the electronic device determines the similarity between the table vector corresponding to the target data table and the target vector corresponding to the question text, the electronic device can use the cosine similarity algorithm for calculation; the electronic device can also use other similarity algorithms for calculation, such as the Euclidean distance similarity algorithm, etc., which are not limited here.

[0048] Furthermore, in the embodiment of the present application, the number of target data tables may be one or more, which is not limited here. The preset condition stored in the electronic device is used to screen the similarity between the table vector of the target data table and the target vector, and the preset condition may be a similarity threshold, a similarity value range, etc.

[0049] S103: When entering the process of generating a query statement for the question text, a structured query statement for the question text is generated according to the candidate data table.

[0050] In the embodiment of the present application, after the electronic device uses the target data table as a candidate data table, the electronic device enters the process of generating SQL statements for the question text, and generates an SQL statement corresponding to the question text based on the candidate data table.

[0051] In one possible implementation, the electronic device may input the candidate data table and the question text into the large model, so that the large model outputs the SQL statement corresponding to the question text. In another possible implementation, the electronic device may also be configured with a program for generating SQL statements, and the electronic device generates the SQL statement corresponding to the question text through the program and the candidate data table.

[0052] In an embodiment of the present application, the electronic device first determines, based on a table vector corresponding to the target data table and a target vector corresponding to the question text, that the target data table represents a candidate data table used in the process of generating a query statement for the question text. If the target data table is used as a candidate data table, a structured query statement for the question text is generated based on the candidate data table, thereby reducing resource loss and improving the efficiency of SQL statement generation.

[0053] In order to reduce the resource consumption of the large model and improve the efficiency of SQL statement generation, based on the above embodiment, in the embodiment of the present application, the target data table is at least one of the multiple data tables; the similarity satisfies the preset conditions, including:

[0054] The similarity is greater than or equal to a similarity threshold; or,

[0055] The similarity is higher than the similarity of a non-target data table, where the similarity of the non-target data table refers to the similarity between a table vector of the non-target data table among the multiple data tables and the target vector.

[0056] Since the question-answering field includes a large number of data tables, in order to make the candidate data table of the SQL statement finally determined for generating the question text more accurate, in an embodiment of the present application, the target data table determined by the electronic device is at least one of the multiple data tables.

[0057] Furthermore, in an embodiment of the present application, the preset condition stored in the electronic device is used to screen the similarity between the table vector of the target data table and the target vector. The preset condition may be a specific similarity threshold or other restriction conditions, such as the similarity between the table vector of the target data table and the target vector is the highest similarity.

[0058] Specifically, in an embodiment of the present application, if the electronic device determines that the similarity between the table vector of the target data table and the target vector of the question text is greater than or equal to the similarity threshold, the electronic device determines that the similarity meets the preset condition. Alternatively, if the electronic device determines that the similarity between the table vector of the target data table and the target vector of the question text is higher than the similarity of the non-target data table, the electronic device determines that the similarity meets the preset condition. The similarity of the non-target data table refers to the similarity between the table vector of the non-target data table in the multiple data tables and the target vector.

[0059] Among them, the similarity of the non-target data table in the embodiment of the present application refers to the similarity between the table vector of the non-target data table in multiple data tables and the target vector.

[0060] In order to reduce the resource consumption of the large model and improve the efficiency of SQL statement generation, based on the above embodiments, in the embodiment of the present application, the process of determining the table vector of the target data table includes:

[0061] Determine graph data including the target data table;

[0062] A table vector of the target data table is determined according to the graph data.

[0063] In an embodiment of the present application, the electronic device may construct graph data including a data table, and determine a table vector of a target data table based on the graph data.

[0064] In order to reduce the resource loss of large models and improve the efficiency of SQL statement generation, on the basis of the above embodiments, in the embodiment of the present application, the graph data includes a data table node corresponding to the data table and a sample question node corresponding to the sample question, the data table node includes a target data table node corresponding to the target data table, the data table nodes and the sample question nodes having a corresponding relationship are connected to each other, a data table corresponding to a data table node is used to generate a sample structured query statement of the sample question of the corresponding sample question node, and the table vector of the target data table is determined according to the graph data, including:

[0065] Determine a target sample problem node connected to a target data table node in the graph data, determine a vector of the target sample problem corresponding to the target sample problem node, and determine the vector as an input vector of the target data table node;

[0066] For each non-target data table node in the graph data, determining an output vector of the non-target data table node according to whether the non-target data table node is connected to other data table nodes in the graph data except the non-target data table node;

[0067] Determine the loss value of the data table corresponding to the non-target data table node and the data table corresponding to the target data table node according to a preset activation function, the input vector of the target data table node and the output vector of the non-target data table;

[0068] The initial table vector of the target data table is optimized based on the loss value of each non-target data table node and the target data table node to determine the table vector of the target data table.

[0069] In an embodiment of the present application, the electronic device can determine the table vector corresponding to the target data table by constructing graph data of the data table.

[0070] Specifically, when the electronic device constructs graph data, the graph data includes two types of nodes, namely data table nodes and sample problem nodes, wherein the number of data table nodes is consistent with the number of data tables, and each data table node corresponds to a data table; the number of sample problem nodes is consistent with the number of sample problems, and each sample problem node corresponds to a sample problem, and each data table node corresponds to a different data table, and each sample problem node corresponds to a different sample problem.

[0071] The electronic device also stores the correspondence between each sample question and the data table of the SQL statement used to generate the sample question. Based on this, when the electronic device constructs the graph data, the data table nodes corresponding to the data table with the correspondence are connected to the sample question nodes corresponding to the sample question.

[0072] Furthermore, the electronic device also stores the fields contained in each data table. When the electronic device constructs graph data, the data table nodes corresponding to the data tables having the same fields are connected to each other.

[0073] For example, if data table A contains a name field and data table B also contains a name field, then in the graph data, data table node A corresponding to data table A and data table node B corresponding to data table B are connected to each other.

[0074] For example, if the data table corresponding to sample question text A and used to generate the sample question text is data table B, then in the graph data, the sample question node A corresponding to the sample question text and the data table node B corresponding to data table B are interconnected.

[0075] In an embodiment of the present application, after constructing the graph data, the electronic device determines the vector of each sample question text as the vector of the corresponding sample question node, initializes the table vector of each data table, and determines the initialized table vector of each data table as the vector of the corresponding data table node. The electronic device continuously optimizes the vector corresponding to the data table node according to the vector of the sample question node of the graph data and the connection relationship of the nodes in the graph structure, and the electronic device determines the vector corresponding to each data table node finally optimized as the table vector of the corresponding data table.

[0076] In an embodiment of the present application, when the electronic device determines the table vector of the target data table based on the graph data, it determines the input vector of the target data table node corresponding to the target data table and the output vector of each non-target data table node in the graph data. Among them, the input vector of the target data table node is determined based on the vector of the sample question text corresponding to the sample question node connected to the target data table node; the output vector of each non-target data table node is determined based on other data table nodes connected to each non-target data table node. In addition, the input vector is used to reflect the application information of the target data table node, and the output vector is used to reflect the association information of each data table node with other data table nodes.

[0077] Among them, the non-target data table nodes are other data table nodes in the graph structure except the target data points corresponding to the target data table.

[0078] Specifically, the electronic device determines a target sample problem node connected to a target data table node in the graph data, determines a vector of the target sample problem corresponding to the target sample problem node, and determines the vector as an input vector of the target data table node.

[0079] In one possible implementation, if the electronic device determines that a target data table node is connected to multiple sample question nodes, the electronic device can determine the vectors of the sample question text corresponding to each sample question node as the input vectors corresponding to the target data table node; the electronic device can also process the vectors of the sample question text corresponding to each sample question node to obtain a total vector, and then determine the total vector as the input vector corresponding to the target data table node.

[0080] Among them, in the embodiment of the present application, the electronic device processes the vector of the sample question text corresponding to each sample question node, and when obtaining the total vector, it can adopt averaging, direct splicing and other methods that can be used for vector processing, which are not limited here.

[0081] For each non-target data table node in the graph data, the electronic device determines an output vector of the non-target data table node according to whether the non-target data table node is connected to other data table nodes in the graph data except the non-target data table node.

[0082] The electronic device determines the loss values ​​of the data table corresponding to the non-target data table node and the data table corresponding to the target data table node based on a preset activation function, the input vector of the target data table node and the output vector of the non-target data table; optimizes the initial table vector of the target data table based on the loss value of each non-target data table node and the target data table node, and determines the table vector of the target data table.

[0083] In order to reduce the resource loss of the large model and improve the efficiency of SQL statement generation, on the basis of the above embodiments, in the embodiment of the present application, the loss value of the data table corresponding to the non-target data table node and the data table corresponding to the target data table node is determined according to the preset activation function, the input vector of the target data table node and the output vector of the non-target data table, including:

[0084] Determine an activation value according to a preset activation function, an input vector of the target data table node, and an output vector of the non-target data table;

[0085] The loss values ​​of the data table corresponding to the non-target data table node and the data table corresponding to the target data table node are determined according to whether the non-target data table node and the target data table node are connected to each other and the activation value.

[0086] In an embodiment of the present application, when the electronic device determines the loss value of the data table corresponding to the non-target data table node and the data table corresponding to the target data table node, the electronic device determines the activation value, and determines the loss value of the data table corresponding to the non-target data table node and the data table corresponding to the target data table node based on whether the non-target data table node and the target data table node are connected to each other and the activation value.

[0087] In order to reduce the resource loss of the large model and improve the efficiency of SQL statement generation, based on the above embodiments, in the embodiment of the present application, the output vector of the non-target data table node is determined according to whether the non-target data table node in the graph data is connected to other non-target data table nodes, including:

[0088] Construct a blank vector, where one element in the blank vector corresponds to one data table node;

[0089] Determine a connection data table node in the graph data that is interconnected with the non-target data table node;

[0090] The value of the element corresponding to the connection data table node in the blank vector is set to a first preset value, and the values ​​of other fields are set to a second preset value, to obtain an output vector of the non-target data table node.

[0091] In the embodiment of the present application, the output vector corresponding to each non-target data table node in the graph data reflects the connection relationship between the non-target data table node and other data table nodes in the graph data, wherein each field of the output vector corresponds to a data table node.

[0092] Specifically, in an embodiment of the present application, an electronic device constructs a blank vector, in which one element corresponds to a data table node. When the electronic device determines the output vector corresponding to any non-target data table node, for each other data table node, if the electronic device determines that the non-target data table node is interconnected with the other data table node, the value of the field corresponding to the other data table node in the blank vector is set to a first preset value; if the non-target data table node and the other data table node are not interconnected, the value of the field corresponding to the other data table node in the blank vector is set to a second preset value.

[0093] Generally, the first preset value is 1, and the second preset value is 0. The first preset value and the second preset value may also be other values, but the first preset value is not equal to the second preset value.

[0094] In order to reduce the resource loss of the large model and improve the efficiency of SQL statement generation, on the basis of the above embodiments, in the embodiment of the present application, the activation value is determined according to the preset activation function, the input vector of the target data table node and the output vector of the non-target data table, including:

[0095] Determining a first activation value according to the activation function, the input vector of the target data table node, and the table vector of the non-target data table of the non-target data table node;

[0096] Determining a second activation value according to the activation function, the initial table vector of the target data table and the output vector;

[0097] Determine a third activation value according to the activation function, a negative vector corresponding to the initial table vector of the target data table, and the output vector;

[0098] Determine a fourth activation value according to the activation function, a negative vector corresponding to the transposed vector of the input vector, and a table vector of the non-target data table;

[0099] The first activation value, the second activation value, the third activation value, and the fourth activation value are determined as activation values.

[0100] In an embodiment of the present application, when the electronic device determines the activation value according to a preset activation function, the input vector of the target data table node and the output vector of the non-target data table, the electronic device determines multiple activation values.

[0101] Specifically, the electronic device determines a first activation value according to an activation function, an input vector of a target data table node, and a table vector of a non-target data table of a non-target data table node; determines a second activation value according to the activation function, an initial table vector of the target data table, and an output vector; determines a third activation value according to the activation function, a negative vector corresponding to the initial table vector of the target data table, and an output vector; determines a fourth activation value according to the activation function, a negative vector corresponding to the transposed vector of the input vector, and a table vector of the non-target data table; and determines the first activation value, the second activation value, the third activation value, and the fourth activation value as activation values.

[0102] In the embodiment of the present application, the activation function used by the electronic device when calculating the activation value may be a tanh function, and the first activation value that the electronic device may determine may be The second activation value is The third activation value is The fourth activation value is in, represents the initial table vector of the target data table node i, is the initial table vector of non-target data table node i, represents the output vector of non-target data table node j, Represents the input vector of node i in the target data table.

[0103] In order to reduce the resource loss of the large model and improve the efficiency of SQL statement generation, based on the above embodiments, in the embodiment of the present application, the loss value of the data table corresponding to the non-target data table node and the data table corresponding to the target data table node is determined according to whether the non-target data table node and the target data table node are connected to each other and the activation value, including:

[0104] In a case where the non-target data table node and the target data table node are connected to each other, determining the weight of the first activation value and the weight of the second activation value to be a first preset value;

[0105] In a case where the non-target data table node and the target data table node are not connected to each other, determining the weight of the first activation value and the weight of the second activation value to be a second preset value;

[0106] Determine the difference between the first preset value and the weight of the first activation value as the weight of the third activation value and the weight of the fourth activation value;

[0107] The loss value is determined based on each activation value and the corresponding weight.

[0108] In an embodiment of the present application, the process of an electronic device determining the loss value of a data table corresponding to a non-target data table node and a data table corresponding to a target data table node may be as follows: when the non-target data table node and the target data table node are interconnected, the electronic device determines the weight of the first activation value and the weight of the second activation value to be a first preset value; when the non-target data table node and the target data table node are not interconnected, the weight of the first activation value and the weight of the second activation value are determined to be a second preset value; the electronic device determines the difference between the first preset value and the weight of the first activation value as the weight of the third activation value and the weight of the fourth activation value; and determines the loss value based on each activation value and the corresponding weight.

[0109] The first preset value is 1, the second preset value is 0, the first preset value and the second preset value may also be other values, but the first preset value is not equal to the second preset value.

[0110] Specifically, the electronic device may use the following formula to calculate the loss value of the data table corresponding to the non-target data table node and the data table corresponding to the target data table node:

[0111]

[0112]

[0113] Among them, v i Indicates the target data table node i, v j Indicates non-target data table node j, C ij Indicates whether the target data table node i and the non-target data table node j are associated. If yes, it is 1, otherwise it is 0; σ is the activation function, and the tanh function is selected here. is the first activation value, is the second activation value, is the third activation value, is the fourth activation value; represents the initial table vector of the target data table node i, is the initial table vector of non-target data table node i, represents the output vector of non-target data table node j, Represents the input vector of node i in the target data table.

[0114] In the embodiment of the present application, the above loss value calculation formula indicates that if two data tables share more common fields, the representation vectors will be more similar. The loss value calculation formula can help learn the structural information in the graph data, but the historical query information for training still needs sample problem nodes for supervision.

[0115] In an embodiment of the present application, the electronic device may use an adaptive moment estimation algorithm (Adaptive Moment Estimation, Adam) as a gradient descent method to reduce the loss value and optimize the table vector of any two data table nodes.

[0116] In order to reduce the resource loss of large models and improve the efficiency of SQL statement generation, based on the above embodiments, in the embodiment of the present application,

[0117] After determining the similarity between the table vector of the target data table and the target vector, the method further includes:

[0118] Constructing an adjacency matrix and a degree matrix based on the table graph data containing the target data;

[0119] Update the table vector of the target data table according to the adjacency matrix, the degree matrix and the table vector of the data table corresponding to each data table node in the graph data;

[0120] And the similarity between the table vector of the target data table and the target vector is updated.

[0121] In order to improve the accuracy of determining the target data table as a candidate data table for the SQL statement used to determine the question text, in an embodiment of the present application, the electronic device updates the similarity between the table vector of the target data table and the target vector of the question text, and determines again whether the target data table is a candidate data table for the SQL statement used to determine the question text based on the updated similarity.

[0122] Specifically, in an embodiment of the present application, the electronic device constructs an adjacency matrix and a degree matrix based on graph data containing a target data table; and updates the table vector of the target data table according to the table vector of the data table corresponding to each data table node in the adjacency matrix, the degree matrix, and the graph data; and then updates the similarity between the table vector of the target data table and the target vector.

[0123] Among them, when the electronic device updates the table vector of the target data table according to the adjacency matrix, the degree matrix and the table vector of the data table corresponding to each data table node in the graph data, the electronic device can use a graph neural network (GNN) model to update the table vector corresponding to the target data table.

[0124] Specifically, the GNN model has powerful graph data fitting and reasoning capabilities. The GNN model can optimize the table vector corresponding to the target data table node according to the connection relationship between any two nodes in the graph data, thereby realizing the aggregation of structural information and semantic information.

[0125] The electronic device determines the updated table vector corresponding to the target data table according to the output of the GNN model, and recalculates the similarity between the target data table and the question text according to the updated table vector corresponding to the target data table and the target vector corresponding to the question text, and updates the original similarity with the calculation result. The electronic device re-determines whether the target data table can be used as a candidate data table for determining the SQL statement of the question text according to the updated similarity and the preset conditions. The method for the electronic device to recalculate the similarity is shown in the above embodiment.

[0126] In addition, in order to reduce the computational pressure of the electronic device, in an embodiment of the present application, the electronic device can also sort the similarity between the table vector corresponding to each data table contained in the graph data and the target vector in order from large to small. If the similarity between the table vector of the target data table and the target vector is the top K, the electronic device performs the above-mentioned process of updating the table vector of the target data table. If the similarity between the table vector of the target data table and the target vector is not the top K, it means that the target data table cannot be used as a candidate data table. K is an integer greater than 1. The process of sorting the top K similarities between the electronic device and the target vector can also be called recalling the K data tables with the highest similarity.

[0127] In the embodiment of the present application, by combining the GNN model and the M3E model, semantic information and table structural information are extracted at the same time. The information richness of the table vector is enriched, which helps to improve the accuracy of sorting. In addition, the idea of ​​first recalling K data tables and then recalculating the table vector of the target data table reduces the amount of calculation in the sorting stage and alleviates the time-consuming problem caused by it.

[0128] In order to reduce the resource loss of the large model and improve the efficiency of SQL statement generation, based on the above embodiments, in the embodiment of the present application, the table vector of the target data table is updated according to the table vector of the data table corresponding to each data table node in the adjacency matrix, the degree matrix and the graph data, including:

[0129] Constructing a feature vector matrix according to the table vector of the data table corresponding to each data table node included in the graph data and the vector of the sample problem corresponding to each sample problem node;

[0130] The eigenvector matrix is ​​updated according to the adjacency matrix, the degree matrix and the eigenvector matrix, and the updated table vector of the target data table is determined according to the updated eigenvector matrix.

[0131] In an embodiment of the present application, the graph data carries data table nodes and table vectors corresponding to each table data, sample question nodes and vectors corresponding to each sample question text, and a connection relationship between any two nodes.

[0132] In this embodiment of the present application, the connection relationship between any two nodes may be a connection relationship between two data table nodes, a connection relationship between two sample question nodes, or a connection relationship between a data table node and a sample question node.

[0133] The electronic device constructs an initial feature vector matrix according to the table vector of each data table included in the graph data and the vector of each sample question text; wherein a row or a column of the initial feature vector matrix corresponds to a table vector or a vector. The electronic device determines an adjacency matrix and a degree matrix according to the connection relationship of each data table; wherein the adjacency matrix is ​​used to represent the connection relationship between every two nodes in the graph data, and the degree matrix is ​​used to represent the number of nodes connected to each node.

[0134] The electronic device updates the initial eigenvector matrix according to the adjacency matrix and the degree matrix to obtain an optimized eigenvector matrix, wherein the optimized eigenvector matrix carries an updated table vector corresponding to each data table.

[0135] Among them, in the embodiment of the present application, the following formula can be used to optimize the initial eigenvector matrix:

[0136]

[0137] Among them, H l represents the initial eigenvector matrix, H l+1 represents the optimized eigenvector matrix, represents the degree matrix, represents the adjacency matrix, W l is a pre-configured parameter matrix, and σ is an activation function. In the embodiment of the present application, the values ​​of the diagonal of the adjacency matrix can be set to 1.

[0138] In addition, in an embodiment of the present application, the process of updating the table vector of the target data table according to the adjacency matrix, the degree matrix and the table vector of the data table corresponding to each data table node in the graph data can also be completed by the GNN model, that is, the graph data is input into the GNN model, and the GNN model executes the above-mentioned update process.

[0139] Optionally, in the embodiment of the present application, the process of updating the table vector of the target data table can also be called a feature aggregation process, and the table vector finally optimized is equivalent to summarizing the structural information and semantic information. In addition, multiple vector aggregations can be performed, and the feature vector matrix corresponding to each vector aggregation except the first vector aggregation is the previous aggregation result.

[0140] In an embodiment of the present application, the electronic device can train the GNN model by randomly sampling data table nodes and sample problem nodes and designing a loss function so as to maximize the cosine similarity between the embedding vector of the user query and the target table vector. If the randomly sampled data table node and the sample problem node have a connection relationship in the graph data, the data table node is a positive node; if the randomly sampled data table node and the sample problem node do not have a connection relationship in the graph data, the data table node is a negative node.

[0141] Among them, the electronic device can randomly sample data table nodes and sample problem nodes, and the designed loss function is as follows:

[0142]

[0143]

[0144] in, represents the loss value, represents the sample problem node i, Represents data table node j, Indicates that there is a connection between data table node i and sample problem node j. Indicates that there is no connection between data table node i and sample problem node j. represents the updated table vector corresponding to data table node j, Represents the updated vector corresponding to the sample problem node i.

[0145] The electronic device trains the GNN model by maximizing the cosine similarity between the vector corresponding to the sample problem node and the table vector corresponding to the data table node.

[0146] In order to reduce the resource consumption of the large model and improve the efficiency of SQL statement generation, based on the above embodiments, in the embodiment of the present application, if there are multiple candidate data tables, the structured query statement of the question text is generated according to the candidate data table, including:

[0147] For each candidate data table, a table lookup process is performed according to the candidate data table to generate a candidate structured query statement corresponding to the question text;

[0148] From each candidate structured query statement, a structured query statement of the question text is screened out.

[0149] In an embodiment of the present application, if the electronic device determines that there are multiple candidate data tables for determining the SQL statement of the question text, then for each candidate data table, the electronic device performs table lookup processing based on the candidate data table to generate a candidate structured query statement corresponding to the question text; and from each candidate structured query statement, the SQL statement of the question text is filtered out.

[0150] When the structured query statement of the question text is screened out from each candidate structured query statement, the electronic device can determine each query result corresponding to each SQL statement according to each SQL statement, and determine the SQL statement of the question text based on each query result.

[0151] Figure 2 The SQL statement generation process diagram provided in the embodiment of the present application is as follows: Figure 2 As shown, the process includes:

[0152] S201: Construct graph data.

[0153] For the data table that the user wants to query, the graph data is established according to the table name and field relationship of the data table, and the data tables are connected through the foreign keys of the data tables. That is, two data tables with the same fields are connected, and the nodes corresponding to the data tables are used as non-label nodes (data table nodes).

[0154] S202: Expand the label node.

[0155] For the sample question text in the training set, the M3E model is used to embed it into a vector and connect it as a label node (sample question node) with the node corresponding to the target data table of the query, so that the label node is expanded to the previously constructed graph data.

[0156] S203: Node representation vector learning.

[0157] For the data graph data obtained above, each non-label node (data table node) stores three representation vectors, namely, a table vector, an output vector, and an input vector.

[0158] For non-label nodes, three vectors are first randomly initialized, and then a sampling operation is performed to randomly sample non-label node pairs. Then the structural loss is calculated, and Adam is used to reduce the loss and optimize the representation vector to determine the table vector corresponding to each table.

[0159] S204: GNN model training.

[0160] At this point, we can extract the adjacency matrix, degree matrix, and initial feature vector matrix consisting of the table vectors corresponding to the data table nodes and the vectors corresponding to the sample problem nodes of the graph data, and use the GCN model to complete feature aggregation to obtain each optimized table vector.

[0161] S205: User query input.

[0162] User input can be obtained through the front-end page to obtain the question text entered by the user.

[0163] S206: Model recall.

[0164] The M3E model is used to determine the target vector corresponding to the question text, and the cosine similarity is calculated with the table vector calculated in S203 to recall the top K data tables with the highest similarity.

[0165] S207: Model sorting.

[0166] According to the GNN model trained in S204, the structural information and semantic information are summarized and each table vector is optimized. The cosine similarity between the optimized table vectors of the top K data tables and the target vector of the question text is calculated to represent the matching possibility between the query and the current table. The top 1 data table is used as the target data table to be queried when generating the SQL statement corresponding to the question text, and is provided to the downstream generation model.

[0167] S208: Generate a template.

[0168] After obtaining the target data table selected by the model, it is spliced ​​with the question text according to the template as prompt information for generating the large model and then used as input to the large model.

[0169] S209: Generate SQL statements.

[0170] Get the SQL statement output by the large model.

[0171] In a possible implementation, assuming that the question text input by the user is "All information in the partition full_account that satisfies the data date of '20230630' and the account number of 431896826", the electronic device recalls the top K candidate data tables with the highest similarity ranking according to the table vector of each data table:

[0172] 0.898 Partition Full Volume_Repayment Account Table

[0173] 0.892 Partition Full_Account Bill History Table

[0174] 0.290 Daily Full Data_Account Information Table

[0175] The electronic device recalculates the similarities corresponding to the K candidate data tables according to the optimized table vector output by the GNN model, and obtains:

[0176] 0.896 Partition Full_Account Bill History Table

[0177] 0.732 Partition Full Volume_Repayment Account Table

[0178] 0.023 Daily Full Data_Account Information Table

[0179] The electronic device determines that the target data table corresponding to the question text is "Partition Full_Account Bill History Table".

[0180] In the embodiment of the present application, the structural features of the table are extracted by combining graph representation learning and the GNN model, which solves the problem of recall difficulties when the table description information is insufficient. Because the structural features are extracted, each data table has its own information, and the domain information can also be used as a supplement to its own information to improve the accuracy of the model in the recall part. In addition, historical queries are used as label nodes to participate in training, which can also assist new queries in determining which table vector they are semantically closer to. In addition, the use of a recall-ranking architecture also reduces the time overhead in the retrieval module.

[0181] Based on the same technical concept, on the basis of the above embodiments, the present application provides a SQL statement generation device, Figure 3 A schematic diagram of the structure of a SQL statement generating device provided in an embodiment of the present application is shown in FIG. Figure 3 As shown, the device comprises:

[0182] Processing module 301 is used to determine the target vector of the question text; determine the similarity between the table vector of the target data table and the target vector; if the similarity meets the preset condition, the target data table is used as a candidate data table;

[0183] The generating module 302 is used to generate a structured query statement for the question text according to the candidate data table when entering the process of generating a query statement for the question text.

[0184] In a possible implementation, the target data table is at least one of a plurality of data tables; the processing module 301 is specifically used for the similarity to be greater than or equal to a similarity threshold; or, the similarity is higher than the similarity of a non-target data table, and the similarity of the non-target data table refers to the similarity between the table vector of the non-target data table among the plurality of data tables and the target vector.

[0185] In a possible implementation, the processing module 301 is specifically configured to determine graph data including the target data table; and determine a table vector of the target data table according to the graph data.

[0186] In a possible implementation, the graph data includes data table nodes corresponding to the data table and sample question nodes corresponding to the sample question, the data table nodes include target data table nodes corresponding to the target data table, the data table nodes and sample question nodes having a corresponding relationship are connected to each other, and the data table corresponding to a data table node is used to generate a sample structured query statement of the sample question of the corresponding sample question node;

[0187] The processing module 301 is specifically used to determine the target sample problem node connected to the target data table node in the graph data, and determine the vector of the target sample problem corresponding to the target sample problem node, and determine the vector as the input vector of the target data table node; for each non-target data table node in the graph data, determine the output vector of the non-target data table node according to whether the non-target data table node is connected to other data table nodes in the graph data except the non-target data table node; determine the loss value of the data table corresponding to the non-target data table node and the data table corresponding to the target data table node according to a preset activation function, the input vector of the target data table node and the output vector of the non-target data table; optimize the initial table vector of the target data table based on the loss value of each non-target data table node and the target data table node, and determine the table vector of the target data table.

[0188] In one possible implementation, the processing module 301 is specifically used to determine an activation value based on a preset activation function, an input vector of the target data table node, and an output vector of the non-target data table; and determine the loss value of the data table corresponding to the non-target data table node and the data table corresponding to the target data table node based on whether the non-target data table node and the target data table node are connected to each other and the activation value.

[0189] In one possible implementation, the processing module 301 is specifically used to construct a blank vector, in which one element corresponds to one data table node; determine the connected data table nodes in the graph data that are interconnected with the non-target data table nodes; set the value of the element corresponding to the connected data table node in the blank vector to a first preset value, and set the values ​​of other fields to a second preset value, to obtain an output vector of the non-target data table node.

[0190] In a possible implementation, the processing module 301 is specifically used to determine a first activation value according to the activation function, the input vector of the target data table node, and the table vector of the non-target data table of the non-target data table node; determine a second activation value according to the activation function, the initial table vector of the target data table, and the output vector; determine a third activation value according to the activation function, the negative vector corresponding to the initial table vector of the target data table, and the output vector; determine a fourth activation value according to the activation function, the negative vector corresponding to the transposed vector of the input vector, and the table vector of the non-target data table; and determine the first activation value, the second activation value, the third activation value, and the fourth activation value as activation values.

[0191] In a possible implementation, the processing module 301 is specifically used to determine that the weight of the first activation value and the weight of the second activation value are first preset values ​​when the non-target data table node and the target data table node are interconnected; when the non-target data table node and the target data table node are not interconnected, determine that the weight of the first activation value and the weight of the second activation value are second preset values; determine the difference between the first preset value and the weight of the first activation value as the weight of the third activation value and the weight of the fourth activation value; and determine the loss value based on each activation value and the corresponding weight.

[0192] In one possible implementation, the processing module 301 is specifically used to construct an adjacency matrix and a degree matrix based on graph data including the target data table; update the table vector of the target data table according to the adjacency matrix, the degree matrix and the table vector of the data table corresponding to each data table node in the graph data; and update the similarity between the table vector of the target data table and the target vector.

[0193] In a possible implementation, the processing module 301 is specifically used to construct a eigenvector matrix based on the table vector of the data table corresponding to each data table node included in the graph data and the vector of the sample problem corresponding to each sample problem node; update the eigenvector matrix based on the adjacency matrix, the degree matrix and the eigenvector matrix, and determine the updated table vector of the target data table based on the updated eigenvector matrix.

[0194] In a possible implementation, if there are multiple candidate data tables, the structured query statement of the question text is generated based on the candidate data tables. The generation module 301 is specifically used to perform table lookup processing on each candidate data table according to the candidate data tables to generate a candidate structured query statement corresponding to the question text; and filter out the structured query statement of the question text from each candidate structured query statement.

[0195] Based on the same technical concept, the present application also provides an electronic device, Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application is shown in FIG. Figure 4 As shown, it includes: a processor 401, a communication interface 402, a memory 403 and a communication bus 404, wherein the processor 401, the communication interface 402, and the memory 403 communicate with each other through the communication bus 404;

[0196] The memory 403 stores a computer program. When the program is executed by the processor 401, the processor 401 performs the following steps:

[0197] Determine the target vector of the question text;

[0198] Determining the similarity between the table vector of the target data table and the target vector;

[0199] If the similarity meets the preset condition, the target data table is used as a candidate data table;

[0200] When entering the process of generating a query statement for the question text, a structured query statement for the question text is generated according to the candidate data table.

[0201] In a possible implementation manner, the target data table is at least one of a plurality of data tables;

[0202] The processor is specifically used for:

[0203] The similarity is greater than or equal to a similarity threshold; or,

[0204] The similarity is higher than the similarity of a non-target data table, where the similarity of the non-target data table refers to the similarity between a table vector of the non-target data table among the multiple data tables and the target vector.

[0205] In a possible implementation manner, the processor is specifically configured to:

[0206] Determine graph data including the target data table;

[0207] A table vector of the target data table is determined according to the graph data.

[0208] In a possible implementation, the graph data includes data table nodes corresponding to the data table and sample question nodes corresponding to the sample question, the data table nodes include target data table nodes corresponding to the target data table, the data table nodes and sample question nodes having a corresponding relationship are connected to each other, and the data table corresponding to a data table node is used to generate a sample structured query statement of the sample question of the corresponding sample question node;

[0209] The processor is specifically used for:

[0210] Determine a target sample problem node connected to a target data table node in the graph data, determine a vector of the target sample problem corresponding to the target sample problem node, and determine the vector as an input vector of the target data table node;

[0211] For each non-target data table node in the graph data, determining an output vector of the non-target data table node according to whether the non-target data table node is connected to other data table nodes in the graph data except the non-target data table node;

[0212] Determine the loss value of the data table corresponding to the non-target data table node and the data table corresponding to the target data table node according to a preset activation function, the input vector of the target data table node and the output vector of the non-target data table;

[0213] The initial table vector of the target data table is optimized based on the loss value of each non-target data table node and the target data table node to determine the table vector of the target data table.

[0214] In a possible implementation manner, the processor is specifically configured to:

[0215] Determine an activation value according to a preset activation function, an input vector of the target data table node, and an output vector of the non-target data table;

[0216] The loss values ​​of the data table corresponding to the non-target data table node and the data table corresponding to the target data table node are determined according to whether the non-target data table node and the target data table node are connected to each other and the activation value.

[0217] In a possible implementation manner, the processor is specifically configured to:

[0218] Construct a blank vector, where one element in the blank vector corresponds to one data table node;

[0219] Determine a connection data table node in the graph data that is interconnected with the non-target data table node;

[0220] The value of the element corresponding to the connection data table node in the blank vector is set to a first preset value, and the values ​​of other fields are set to a second preset value, to obtain an output vector of the non-target data table node.

[0221] In a possible implementation manner, the processor is specifically configured to:

[0222] Determining a first activation value according to the activation function, the input vector of the target data table node, and the table vector of the non-target data table of the non-target data table node;

[0223] Determining a second activation value according to the activation function, the initial table vector of the target data table and the output vector;

[0224] Determine a third activation value according to the activation function, a negative vector corresponding to the initial table vector of the target data table, and the output vector;

[0225] Determine a fourth activation value according to the activation function, a negative vector corresponding to the transposed vector of the input vector, and a table vector of the non-target data table;

[0226] The first activation value, the second activation value, the third activation value, and the fourth activation value are determined as activation values.

[0227] In a possible implementation manner, the processor is specifically configured to:

[0228] In a case where the non-target data table node and the target data table node are connected to each other, determining the weight of the first activation value and the weight of the second activation value to be a first preset value;

[0229] In a case where the non-target data table node and the target data table node are not connected to each other, determining the weight of the first activation value and the weight of the second activation value to be a second preset value;

[0230] Determine the difference between the first preset value and the weight of the first activation value as the weight of the third activation value and the weight of the fourth activation value;

[0231] The loss value is determined based on each activation value and the corresponding weight.

[0232] In a possible implementation manner, the processor is specifically configured to:

[0233] Constructing an adjacency matrix and a degree matrix based on the table graph data containing the target data;

[0234] Update the table vector of the target data table according to the adjacency matrix, the degree matrix and the table vector of the data table corresponding to each data table node in the graph data;

[0235] And the similarity between the table vector of the target data table and the target vector is updated.

[0236] In a possible implementation manner, the processor is specifically configured to:

[0237] Constructing a feature vector matrix according to the table vector of the data table corresponding to each data table node included in the graph data and the vector of the sample problem corresponding to each sample problem node;

[0238] The eigenvector matrix is ​​updated according to the adjacency matrix, the degree matrix and the eigenvector matrix, and the updated table vector of the target data table is determined according to the updated eigenvector matrix.

[0239] In a possible implementation manner, the processor is specifically configured to:

[0240] If there are multiple candidate data tables, then for each candidate data table, table lookup processing is performed according to the candidate data table to generate a candidate structured query statement corresponding to the question text;

[0241] From each candidate structured query statement, a structured query statement of the question text is screened out.

[0242] Since the principle of solving the problem by the above electronic device is similar to the sentence generation method, the implementation of the above electronic device can refer to the embodiment of the method, and the repeated parts will not be repeated.

[0243] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The communication interface 402 is used for communication between the above electronic device and other devices. The memory may include a random access memory (RAM) and may also include a non-volatile memory (NVM), such as at least one disk storage. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0244] The above-mentioned processor can be a general-purpose processor, including a central processing unit, a network processor (Network Processor, NP), etc.; it can also be a digital signal processing processor (Digital Signal Processing, DSP), an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, etc.

[0245] Based on the same technical concept, an embodiment of the present application provides a computer-readable storage medium, in which a computer program executable by an electronic device is stored. When the program is run on the electronic device, the processor implements the following steps when executing:

[0246] Determine the target vector of the question text;

[0247] Determining the similarity between the table vector of the target data table and the target vector;

[0248] If the similarity meets the preset condition, the target data table is used as a candidate data table;

[0249] When entering the process of generating a query statement for the question text, a structured query statement for the question text is generated according to the candidate data table.

[0250] In a possible implementation, the target data table is at least one of a plurality of data tables; and the similarity satisfies a preset condition, including:

[0251] The similarity is greater than or equal to a similarity threshold; or,

[0252] The similarity is higher than the similarity of a non-target data table, where the similarity of the non-target data table refers to the similarity between a table vector of the non-target data table among the multiple data tables and the target vector.

[0253] In a possible implementation manner, the process of determining the table vector of the target data table includes:

[0254] Determine graph data including the target data table;

[0255] A table vector of the target data table is determined according to the graph data.

[0256] In a possible implementation, the graph data includes data table nodes corresponding to the data table and sample question nodes corresponding to the sample question, the data table nodes include target data table nodes corresponding to the target data table, the data table nodes and sample question nodes having a corresponding relationship are connected to each other, a data table corresponding to a data table node is used to generate a sample structured query statement of a sample question of the corresponding sample question node, and determining the table vector of the target data table according to the graph data includes:

[0257] Determine a target sample problem node connected to a target data table node in the graph data, determine a vector of the target sample problem corresponding to the target sample problem node, and determine the vector as an input vector of the target data table node;

[0258] For each non-target data table node in the graph data, determining an output vector of the non-target data table node according to whether the non-target data table node is connected to other data table nodes in the graph data except the non-target data table node;

[0259] Determine the loss value of the data table corresponding to the non-target data table node and the data table corresponding to the target data table node according to a preset activation function, the input vector of the target data table node and the output vector of the non-target data table;

[0260] The initial table vector of the target data table is optimized based on the loss value of each non-target data table node and the target data table node to determine the table vector of the target data table.

[0261] In a possible implementation, determining the loss value of the data table corresponding to the non-target data table node and the data table corresponding to the target data table node according to a preset activation function, the input vector of the target data table node, and the output vector of the non-target data table includes:

[0262] Determine an activation value according to a preset activation function, an input vector of the target data table node, and an output vector of the non-target data table;

[0263] The loss values ​​of the data table corresponding to the non-target data table node and the data table corresponding to the target data table node are determined according to whether the non-target data table node and the target data table node are connected to each other and the activation value.

[0264] In a possible implementation manner, determining the output vector of the non-target data table node according to whether the non-target data table node in the graph data is connected to other non-target data table nodes includes:

[0265] Construct a blank vector, where one element in the blank vector corresponds to one data table node;

[0266] Determine a connection data table node in the graph data that is interconnected with the non-target data table node;

[0267] The value of the element corresponding to the connection data table node in the blank vector is set to a first preset value, and the values ​​of other fields are set to a second preset value, to obtain an output vector of the non-target data table node.

[0268] In a possible implementation, determining the activation value according to a preset activation function, an input vector of the target data table node, and an output vector of the non-target data table includes:

[0269] Determining a first activation value according to the activation function, the input vector of the target data table node, and the table vector of the non-target data table of the non-target data table node;

[0270] Determining a second activation value according to the activation function, the initial table vector of the target data table and the output vector;

[0271] Determine a third activation value according to the activation function, a negative vector corresponding to the initial table vector of the target data table, and the output vector;

[0272] Determine a fourth activation value according to the activation function, a negative vector corresponding to the transposed vector of the input vector, and a table vector of the non-target data table;

[0273] The first activation value, the second activation value, the third activation value, and the fourth activation value are determined as activation values.

[0274] In a possible implementation, determining the loss value of the data table corresponding to the non-target data table node and the data table corresponding to the target data table node according to whether the non-target data table node and the target data table node are connected to each other and the activation value includes:

[0275] In a case where the non-target data table node and the target data table node are connected to each other, determining the weight of the first activation value and the weight of the second activation value to be a first preset value;

[0276] In a case where the non-target data table node and the target data table node are not connected to each other, determining the weight of the first activation value and the weight of the second activation value to be a second preset value;

[0277] Determine the difference between the first preset value and the weight of the first activation value as the weight of the third activation value and the weight of the fourth activation value;

[0278] The loss value is determined based on each activation value and the corresponding weight.

[0279] In a possible implementation manner, after determining the similarity between the table vector of the target data table and the target vector, the method further includes:

[0280] Constructing an adjacency matrix and a degree matrix based on the table graph data containing the target data;

[0281] Update the table vector of the target data table according to the adjacency matrix, the degree matrix and the table vector of the data table corresponding to each data table node in the graph data;

[0282] And the similarity between the table vector of the target data table and the target vector is updated.

[0283] In a possible implementation, updating the table vector of the target data table according to the adjacency matrix, the degree matrix, and the table vector of the data table corresponding to each data table node in the graph data includes:

[0284] Constructing a feature vector matrix according to the table vector of the data table corresponding to each data table node included in the graph data and the vector of the sample problem corresponding to each sample problem node;

[0285] The eigenvector matrix is ​​updated according to the adjacency matrix, the degree matrix and the eigenvector matrix, and the updated table vector of the target data table is determined according to the updated eigenvector matrix.

[0286] In a possible implementation manner, if there are multiple candidate data tables, generating a structured query statement of the question text according to the candidate data tables includes:

[0287] For each candidate data table, a table lookup process is performed according to the candidate data table to generate a candidate structured query statement corresponding to the question text;

[0288] From each candidate structured query statement, a structured query statement of the question text is screened out.

[0289] Since the principle of solving the problem by the above-mentioned computer-readable storage medium is similar to that of the statement generation method, the implementation of the above-mentioned computer-readable storage medium can refer to the embodiment of the method, and the repeated parts will not be repeated.

[0290] The above-mentioned computer-readable storage medium can be any available medium or data storage device that can be accessed by the processor in the electronic device, including but not limited to magnetic storage such as floppy disks, hard disks, magnetic tapes, MO (magneto-optical disks), etc., optical storage such as CD, DVD, BD, HVD, etc., and semiconductor storage such as ROM, EPROM, EEPROM, NAND FLASH (non-volatile memory), SSD (solid state drive), etc.

[0291] Based on the same technical concept, an embodiment of the present application further provides a computer program product, which, when executed by a computer, implements the sentence generation method described in any of the above method embodiments applied to an electronic device.

[0292] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof, and all or part of the embodiments may be implemented in the form of a computer program product. The computer program product includes one or more computer instructions, and when the computer instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present application are generated.

[0293] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0294] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0295] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0296] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0297] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.

Claims

1. A sentence generation method, characterized in that: The method comprises: Determine the target vector of the question text; Determining the similarity between the table vector of the target data table and the target vector; If the similarity meets the preset condition, the target data table is used as a candidate data table; When entering the process of generating a query statement for the question text, a structured query statement for the question text is generated according to the candidate data table.

2. The method according to claim 1, characterized in that The target data table is at least one of a plurality of data tables; the similarity satisfies a preset condition, including: The similarity is greater than or equal to a similarity threshold; or, The similarity is higher than the similarity of a non-target data table, where the similarity of the non-target data table refers to the similarity between a table vector of the non-target data table among the multiple data tables and the target vector.

3. The method according to claim 1, characterized in that The process of determining the table vector of the target data table includes: Determine graph data including the target data table; A table vector of the target data table is determined according to the graph data.

4. The method according to claim 3, characterized in that The graph data includes data table nodes corresponding to the data table and sample question nodes corresponding to the sample question, the data table nodes include target data table nodes corresponding to the target data table, the data table nodes and sample question nodes having a corresponding relationship are connected to each other, a data table corresponding to a data table node is used to generate a sample structured query statement of the sample question of the corresponding sample question node, and determining the table vector of the target data table according to the graph data includes: Determine a target sample problem node connected to a target data table node in the graph data, determine a vector of the target sample problem corresponding to the target sample problem node, and determine the vector as an input vector of the target data table node; For each non-target data table node in the graph data, determining an output vector of the non-target data table node according to whether the non-target data table node is connected to other data table nodes in the graph data except the non-target data table node; Determine the loss value of the data table corresponding to the non-target data table node and the data table corresponding to the target data table node according to a preset activation function, the input vector of the target data table node and the output vector of the non-target data table; The initial table vector of the target data table is optimized based on the loss value of each non-target data table node and the target data table node to determine the table vector of the target data table.

5. The method according to claim 4, characterized in that The determining, according to a preset activation function, an input vector of the target data table node, and an output vector of the non-target data table, a loss value of a data table corresponding to the non-target data table node and a data table corresponding to the target data table node comprises: Determine an activation value according to a preset activation function, an input vector of the target data table node, and an output vector of the non-target data table; The loss values ​​of the data table corresponding to the non-target data table node and the data table corresponding to the target data table node are determined according to whether the non-target data table node and the target data table node are connected to each other and the activation value.

6. The method according to claim 4, characterized in that The step of determining the output vector of the non-target data table node according to whether the non-target data table node and other non-target data table nodes in the graph data are connected to each other includes: Construct a blank vector, where one element in the blank vector corresponds to one data table node; Determine a connection data table node in the graph data that is interconnected with the non-target data table node; The value of the element corresponding to the connection data table node in the blank vector is set to a first preset value, and the values ​​of other fields are set to a second preset value, to obtain an output vector of the non-target data table node.

7. The method according to claim 5, characterized in that The determining of the activation value according to a preset activation function, an input vector of the target data table node, and an output vector of the non-target data table includes: Determining a first activation value according to the activation function, the input vector of the target data table node, and the table vector of the non-target data table of the non-target data table node; Determining a second activation value according to the activation function, the initial table vector of the target data table and the output vector; Determine a third activation value according to the activation function, a negative vector corresponding to the initial table vector of the target data table, and the output vector; Determine a fourth activation value according to the activation function, a negative vector corresponding to the transposed vector of the input vector, and a table vector of the non-target data table; The first activation value, the second activation value, the third activation value, and the fourth activation value are determined as activation values.

8. The method according to claim 7, characterized in that The determining, according to whether the non-target data table node and the target data table node are connected to each other and the activation value, the loss value of the data table corresponding to the non-target data table node and the data table corresponding to the target data table node comprises: In a case where the non-target data table node and the target data table node are connected to each other, determining the weight of the first activation value and the weight of the second activation value to be a first preset value; In a case where the non-target data table node and the target data table node are not connected to each other, determining the weight of the first activation value and the weight of the second activation value to be a second preset value; Determine the difference between the first preset value and the weight of the first activation value as the weight of the third activation value and the weight of the fourth activation value; The loss value is determined based on each activation value and the corresponding weight.

9. The method according to claim 1, characterized in that: After determining the similarity between the table vector of the target data table and the target vector, the method further includes: Constructing an adjacency matrix and a degree matrix based on the table graph data containing the target data; Update the table vector of the target data table according to the adjacency matrix, the degree matrix and the table vector of the data table corresponding to each data table node in the graph data; And the similarity between the table vector of the target data table and the target vector is updated.

10. The method according to claim 9, characterized in that The updating of the table vector of the target data table according to the adjacency matrix, the degree matrix and the table vector of the data table corresponding to each data table node in the graph data comprises: Constructing a feature vector matrix according to the table vector of the data table corresponding to each data table node included in the graph data and the vector of the sample problem corresponding to each sample problem node; The eigenvector matrix is ​​updated according to the adjacency matrix, the degree matrix and the eigenvector matrix, and the updated table vector of the target data table is determined according to the updated eigenvector matrix.

11. The method according to claim 1, characterized in that: If there are multiple candidate data tables, generating a structured query statement of the question text according to the candidate data tables includes: For each candidate data table, a table lookup process is performed according to the candidate data table to generate a candidate structured query statement corresponding to the question text; From each candidate structured query statement, a structured query statement of the question text is screened out.

12. A sentence generating device, characterized in that: The device comprises: A processing module, used to determine a target vector of the question text; determine the similarity between a table vector of a target data table and the target vector; if the similarity meets a preset condition, use the target data table as a candidate data table; A generating module is used to generate a structured query statement for the question text according to the candidate data table when entering the process of generating a query statement for the question text.

13. An electronic device, characterized in that: The electronic device comprises at least a processor and a memory, and the processor is used to implement the steps of the sentence generation method according to any one of claims 1 to 11 when executing a computer program stored in the memory.

14. A computer storage medium, characterized in that: It stores a computer program executable by an electronic device. When the program runs on the electronic device, the electronic device executes the steps of the sentence generation method described in any one of claims 1 to 11.

15. A computer program product, characterized in that The computer program product comprises: a computer program code, and when the computer program code is executed on the electronic device, the electronic device executes the steps of the sentence generation method according to any one of claims 1 to 11.

Citation Information

Patent Citations

  • Database natural language query method and device, electronic equipment and storage medium

    CN114328823A

  • Data processing method and related equipment

    CN115618065A

  • Generating Answer Variants Based on Tables of a Corpus

    US20170351677A1

  • Method, Computer Program, and System for Processing of Natural Language

    US20220067281A1

  • Optimizing structured query language queries using candidate sets

    US20240220488A1