A sentence generation model optimization method and device, electronic equipment and medium
By encoding and optimizing the natural language description information and the loss function, accurate SQL query statements are generated, which solves the problem of runtime errors in the NL2SQL model and improves the accuracy and efficiency of queries.
Patent Information
- Application Number
- CN202211358219.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-01
- Publication Date
- 2026-02-06
- Estimated Expiration
- 2042-11-01
AI Technical Summary
Existing Natural Language to Structured Query (NL2SQL) models are prone to runtime errors when generating SQL query statements, affecting accuracy and performance.
By determining the encoding vectors of words and fields corresponding to natural language description information, a predefined statement generation model is used to generate predicted SQL query statements. The model is then optimized using loss functions for labeled SQL query statements and predicted SQL query statements to improve generation accuracy.
It effectively improves the accuracy of generated SQL query statements, solves runtime error problems, supports multi-round query tasks, and improves query accuracy.
Smart Images

Figure CN115630088B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the technical field of database, and particularly relate to a sentence generation model optimization method and device, electronic equipment and medium. BACKGROUND
[0002] With the development of society and technology, converting natural language questions into accurate executable structured query language (SQL) query statements has attracted much attention and has been applied in many fields.
[0003] At present, although the existing natural language to SQL (NL2SQL) model can realize the conversion of natural language questions to SQL query statements, the NL2SQL is a technology for converting user natural language statements into executable SQL query statements to obtain query results from a database. However, this method depends on the execution of SQL query statements on the database, and SQL query statement running errors often occur, which greatly affects the performance of the conversion of natural language questions to SQL query statements and reduces the accuracy of the conversion of natural language questions to SQL query statements. SUMMARY
[0004] Embodiments of the present application provide a sentence generation model optimization method, device, electronic equipment and medium to improve the accuracy of SQL query statement generation.
[0005] According to an aspect of the embodiments of the present application, a sentence generation model optimization method is provided, comprising:
[0006] For a set number of natural language description information, at least one word and at least one field corresponding to the natural language description information are determined, the word is the smallest semantic unit constituting the natural language description information, and the field is the field corresponding to the natural language description information in a set database table;
[0007] The first encoding vector corresponding to each word of the natural language description information and the second encoding vector corresponding to each field of the natural language description information are determined;
[0008] According to the first encoding vector corresponding to each natural language description information, the second encoding vector corresponding to each natural language description information, and a set sentence generation model, a predicted SQL query statement corresponding to each natural language description information is determined;
[0009] The loss function of the set statement generation model is determined according to the predicted SQL query statements respectively corresponding to the natural language description information and the label SQL query statements respectively corresponding to the natural language description information, and the set statement generation model is optimized according to the loss function.
[0010] According to another aspect of the embodiment of the present application, a statement generation model optimization device is provided, comprising:
[0011] The first determination module is configured to determine, for a set number of natural language description information, at least one word and at least one field corresponding to the natural language description information, the word being the smallest semantic unit constituting the natural language description information, and the field being a field corresponding to the natural language description information in a set database table;
[0012] The second determination module is configured to determine a first encoding vector respectively corresponding to each of the words corresponding to the natural language description information and a second encoding vector respectively corresponding to each of the fields corresponding to the natural language description information;
[0013] The third determination module is configured to determine, according to each of the first encoding vectors corresponding to each of the natural language description information, each of the second encoding vectors corresponding to each of the natural language description information, and a set statement generation model, a predicted structured query language (SQL) query statement respectively corresponding to each of the natural language description information;
[0014] The optimization module is configured to determine a loss function of the set statement generation model according to the predicted SQL query statements respectively corresponding to the natural language description information and the label SQL query statements respectively corresponding to the natural language description information, and optimize the set statement generation model according to the loss function.
[0015] According to another aspect of the embodiment of the present application, an electronic device is provided, comprising:
[0016] at least one processor; and
[0017] a memory connected with the at least one processor in communication; wherein
[0018] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to execute the statement generation model optimization method according to any one of the embodiments of the present application.
[0019] According to another aspect of the embodiment of the present application, a computer readable storage medium is provided, which stores computer instructions for enabling a processor to execute the statement generation model optimization method according to any one of the embodiments of the present application when executed.
[0020] The technical scheme of the embodiment of the present application firstly determines at least one word and at least one field corresponding to the natural language description information for a set number of natural language description information, the word being the smallest semantic unit constituting the natural language description information, and the field being the field corresponding to the natural language description information in a set database table; then determines a first encoding vector corresponding to each word of the natural language description information and a second encoding vector corresponding to each field; thereafter, according to the first encoding vector corresponding to each natural language description information, the second encoding vector corresponding to each natural language description information, and a set sentence generation model, determines a predicted SQL query statement corresponding to each natural language description information; finally, according to the predicted SQL query statement corresponding to each natural language description information and the label SQL query statement corresponding to each natural language description information, determines a loss function of the set sentence generation model, and optimizes the set sentence generation model according to the loss function. The method encodes the words and fields of a set number of natural language description information, generates the corresponding predicted SQL query statement based on the encoding vector through the set sentence generation model, and optimizes the set sentence generation model through the loss function between the label SQL query statement and the predicted SQL query statement, so as to generate a more accurate SQL query statement through the optimized set sentence generation model, thereby effectively improving the accuracy of the SQL query statement generation.
[0021] It should be understood that the content described in this part is not intended to identify the key or important features of the embodiments of the present application, nor is it used to limit the scope of the present application. Other features of the present application will become apparent from the following description. BRIEF DESCRIPTION OF DRAWINGS
[0022] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.
[0023] Figure 1 A flowchart of a sentence generation model optimization method provided for the first embodiment of the present application;
[0024] Figure 2 A flowchart of a sentence generation model optimization method provided for the second embodiment of the present application;
[0025] Figure 3 A structural schematic diagram of a sentence generation model optimization device provided for the third embodiment of the present application;
[0026] Figure 4A structural schematic diagram of an electronic device provided for the fourth embodiment of the present application. DETAILED DESCRIPTION
[0027] In order to enable persons skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by persons skilled in the art without creative work should fall within the protection scope of the present application.
[0028] It should be noted that the terms "first", "second", and the like in the specification and claims of the present application and the above-described drawings are used to distinguish similar objects, and do not necessarily indicate a specific order or a chronological sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device including a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0029] Embodiment One
[0030] Figure 1 A flowchart of a sentence generation model optimization method provided for the first embodiment of the present application. The method can be applied to optimize the sentence generation model to improve the accuracy of SQL query statement generation. The method can be executed by a sentence generation model optimization device, which can be implemented by software and / or hardware and is generally integrated on an electronic device. In the present embodiment, the electronic device includes but is not limited to desktop computers, notebook computers, servers and other devices.
[0031] As shown in Figure 1 A sentence generation model optimization method provided by the first embodiment of the present application, the method comprising the following steps:
[0032] S110, for a set number of natural language description information, determining at least one word and at least one field corresponding to the natural language description information.
[0033] In the embodiment, the set quantity can be understood as a pre-set quantity, which is not limited specifically herein, and can be, for example, 1000 or 2000, etc. The natural language description information can be understood as description information in the form of natural language related to the data query. The natural language can generally refer to a language that evolves naturally with culture. For example, the natural language description information can be a natural language question, and specifically can be a sentence such as "query C data in table A and table B".
[0034] The word can be understood as the smallest semantic unit constituting the natural language description information; that is, the word can be considered as a single word contained in the natural language description information, and the natural language description information can include at least one word, such as "table", "A", and "in", which can all be considered as a word.
[0035] The field can be understood as a corresponding field of the natural language description information in the set database table. The set database table can be understood as at least one pre-set database table; which is not limited specifically herein, and can include all database tables in the queried database, or can include part of the database tables in the queried database. In a relational database, a database table is a collection of a series of two-dimensional arrays, used to represent and store the relationship between data objects, which is composed of vertical columns and horizontal rows. For example, a database table related to author information, each column contains a certain type of information of all authors, such as "surname", "name", and "address", etc., and each row contains all information of a certain author: surname, name, and address, etc. In the database table, "surname", "name", and "address" can be considered as a field, which can be located at the column header position of the corresponding column; that is, the column header of each column is a field.
[0036] For each of the set quantity of natural language description information, at least one word and at least one field corresponding to the natural language description information are determined; one natural language description information corresponds to at least one word and at least one field.
[0037] How to determine the at least one word corresponding to the natural language description information is not limited specifically herein; for example, the natural language description information can be processed by word segmentation to obtain at least one word contained in the natural language description information; on this basis, the obtained at least one word can also be filtered to filter out useless and / or duplicate words, and how to filter is not limited specifically herein.
[0038] The determination of the at least one field corresponding to the natural language description information is not specifically limited here, for example, the words associated with the table in the natural language description information can be determined first, the words are regarded as a plurality of strings, all the fields included in the set database table are also regarded as a plurality of strings, and the at least one string corresponding to the words in the natural language description information is searched from all the fields included in the set database table through a string matching algorithm, and the at least one string is regarded as the at least one field determined.
[0039] In S120, a first encoding vector corresponding to each word in the natural language description information and a second encoding vector corresponding to each field are determined.
[0040] In this embodiment, one word can correspond to one first encoding vector. The first encoding vector can be understood as an encoding vector obtained after encoding processing of the corresponding word. One field can correspond to one second encoding vector. The second encoding vector can be understood as an encoding vector obtained after encoding processing of the corresponding field.
[0041] The determination of the first encoding vector and the second encoding vector is not specifically limited here; for example, each word and each field corresponding to the natural language description information can be input as input data into a pre-trained long short-term memory neural network (LSTM) to obtain the first encoding vector corresponding to each word and the second encoding vector corresponding to each field. The LSTM is not specifically limited, for example, a bidirectional LSTM (Bi-LSTM) can be used.
[0042] In S130, a predicted SQL query statement corresponding to each natural language description information is determined according to the first encoding vector corresponding to each natural language description information, the second encoding vector corresponding to each natural language description information, and a set sentence generation model.
[0043] In this embodiment, the set sentence generation model can be understood as a network model for SQL query statement generation set in advance; the set sentence generation model is not specifically limited here, for example, it can be a network model based on a deep biaffine attention (DeepBiaffine Attention) mechanism. The predicted SQL query statement can be understood as a SQL query statement generated by the set sentence generation model.
[0044] Each natural language description information can correspond to its own first encoding vector and second encoding vector. According to the first encoding vector and the second encoding vector corresponding to each natural language description information and the set sentence generation model, the predicted SQL query statement corresponding to each natural language description information can be determined.
[0045] Herein the determination of the predicted SQL query statement corresponding to each natural language description information according to the first encoding vector, the second encoding vector and the set statement generation model corresponding to each natural language description information is not specifically limited; for example, the first encoding vector and the second encoding vector can be input as input data into the set statement generation model, since the set statement generation model is pre-trained, the first encoding vector and the second encoding vector can be processed to obtain the corresponding predicted SQL query statement, for example, the first encoding vector and the second encoding vector with a larger association relationship can be taken as the basis, and the corresponding word and field information can be filled into the pre-set SQL query statement framework to obtain the corresponding predicted SQL query statement.
[0046] S140, according to the predicted SQL query statement corresponding to each natural language description information and the label SQL query statement corresponding to each natural language description information, determine the loss function of the set statement generation model, and optimize the set statement generation model according to the loss function.
[0047] In this embodiment, the label SQL query statement can be understood as the correct SQL query statement determined by the relevant technical personnel in advance according to the natural language description information. One natural language description information can correspond to one label SQL query statement and one predicted SQL query statement.
[0048] The loss function can be understood as a function representing the gap between the predicted SQL query statement generated by the set statement generation model and the label SQL query statement. Herein the determination of the loss function is not specifically limited, for example, for each natural language description information, a loss value can be determined between the label SQL query statement and the predicted SQL query statement of the natural language description information; the loss value can be understood as a value representing the gap between the label SQL query statement and the corresponding predicted SQL query statement; on this basis, a corresponding function can be constructed from the loss value of each natural language description information to serve as the loss function.
[0049] The loss function is not specifically limited herein. For example, a threshold value can be preset for determining the loss function. Specifically, after generating a set number of predicted SQL query statements corresponding to the set number of natural language description information by the setting statement generation model, a set number of loss values can be obtained according to the label SQL query statements corresponding to the set number of natural language description information and the current obtained predicted SQL query statements. A loss function can be determined according to the obtained set number of loss values. It is determined whether the loss function reaches the preset threshold value. If yes, the setting statement generation model can not be optimized. If not, the parameters of the setting statement generation model can be automatically adjusted according to the loss function. The operation of generating a predicted SQL query statement by the setting statement generation model after the parameters are adjusted is executed. A loss function is continuously obtained. It is determined whether the loss function reaches the preset threshold value. If yes, the current setting statement generation model is the optimized setting statement generation model. If not, the parameters of the setting statement generation model are continuously automatically adjusted according to the loss function. The operation of generating a predicted SQL query statement by the setting statement generation model after the parameters are adjusted is executed. This is repeated until the obtained loss function reaches the preset threshold value.
[0050] It can be understood that after the optimized setting statement generation model is obtained, after receiving the natural language description information input by the user, a more accurate SQL query statement corresponding to the natural language description information can be generated by the optimized setting statement generation model.
[0051] The embodiment one of the present application provides a sentence generation model optimization method. First, for a set number of natural language description information, at least one word and at least one field corresponding to the natural language description information are determined, the word is the smallest semantic unit constituting the natural language description information, and the field is a field corresponding to the natural language description information in a set database table. Then, a first encoding vector corresponding to each word of the natural language description information and a second encoding vector corresponding to each field are determined. Then, according to the first encoding vector corresponding to each natural language description information, the second encoding vector corresponding to each natural language description information and a set sentence generation model, a predicted SQL query statement corresponding to each natural language description information is determined. Finally, according to the predicted SQL query statement corresponding to each natural language description information and a label SQL query statement corresponding to each natural language description information, a loss function of the set sentence generation model is determined, and the set sentence generation model is optimized according to the loss function. The method encodes the words and fields of the set number of natural language description information, generates the corresponding predicted SQL query statement based on the encoding vector through the set sentence generation model, and optimizes the set sentence generation model through the loss function between the label SQL query statement and the predicted SQL query statement, so as to generate a more accurate SQL query statement through the optimized set sentence generation model, thereby effectively improving the accuracy of the SQL query statement generation.
[0052] Embodiment two
[0053] Figure 2 The flowchart of the sentence generation model optimization method provided by the embodiment two of the present application is shown. The embodiment two is based on the above-mentioned embodiments and is refined. In the embodiment, the process of determining at least one word and at least one field corresponding to the natural language description information for a set number of natural language description information, the process of determining the first encoding vector corresponding to each word of the natural language description information and the second encoding vector corresponding to each field, and the process of determining the predicted SQL query statement corresponding to each natural language description information according to the first encoding vector corresponding to each natural language description information, the second encoding vector corresponding to each natural language description information and the set sentence generation model are described in detail. It should be noted that the technical details not described in detail in the embodiment can be referred to the above-mentioned embodiments. As shown in the embodiment, the method comprises the following steps. Figure 2
[0054] As shown in the embodiment, the method provided by the embodiment two of the present application comprises the following steps. Figure 2
[0055] S210, for a set number of natural language description information, performing word segmentation processing on the natural language description information to obtain at least one word corresponding to the natural language description information.
[0056] In the embodiment, the word segmentation processing can be understood as a text processing method in natural language processing, that is, a classification processing on a word level of a text content. The natural language description information is taken as a text content, and the natural language description information is subjected to the word segmentation processing to obtain at least one word. For a set number of natural language description information, one natural language description information can correspond to at least one word thereof.
[0057] S220, searching at least one field corresponding to the natural language description information from the set database table through a semantic parsing algorithm.
[0058] In the embodiment, the semantic parsing algorithm can be understood as an algorithm for parsing semantics and syntax of a text content. Here, how to search at least one field corresponding to the natural language description information from the set database table through the semantic parsing algorithm is not specifically limited, for example, the natural language description information can be taken as a text content, the natural language description information is parsed through the semantic parsing algorithm to obtain information (such as age) related to table query, and according to the information, a field (such as age, age and age) associated and matched with the information is searched from all fields contained in the set database table to serve as at least one field corresponding to the natural language description information.
[0059] S230, inputting each word corresponding to the natural language description information and each field into a bidirectional encoder representation model of a transformer to obtain a first embedding vector corresponding to each word and a second embedding vector corresponding to each field.
[0060] In the embodiment, one word can correspond to one first embedding vector. The first embedding vector can be understood as a vector obtained after embedding processing of a word; the embedding can be understood as a vector representation of a word or a text, that is, the word is converted into a fixed-dimension vector representation. One field can correspond to one second embedding vector. The second embedding vector can be understood as a vector obtained after embedding processing of a field.
[0061] The words and the fields corresponding to the natural language description information are taken as input data and input into a bidirectional encoder representation (Bidirectional Encoder Representations from Transformers, BERT) model of a transformer to output the first embedding vector corresponding to each word and the second embedding vector corresponding to each field.
[0062] S240, input each first embedding vector and each second embedding vector into a bidirectional long short-term memory neural network encoder to obtain a first encoding vector corresponding to each first embedding vector and a second encoding vector corresponding to each second embedding vector.
[0063] In this embodiment, each first embedding vector and each second embedding vector is input as input data into a bidirectional long short-term memory neural network encoder (Bi-LSTM), and a first encoding vector corresponding to each first embedding vector and a second encoding vector corresponding to each second embedding vector can be output. One first embedding vector can correspond to one first encoding vector; one second embedding vector can correspond to one second encoding vector.
[0064] S250, for each natural language description information, dimension reduction processing is performed on each first encoding vector and each second encoding vector corresponding to the natural language description information to obtain a first dimension reduction vector corresponding to each first encoding vector and a second dimension reduction vector corresponding to each second encoding vector.
[0065] In this embodiment, the dimension reduction processing can be understood as a processing of reducing the dimension, such as converting a vector from a high dimension to a low dimension; the dimension can be understood as the dimension of the features of the vector. One first encoding vector can correspond to one first dimension reduction vector; the first dimension reduction vector can be understood as a vector obtained by performing dimension reduction processing on the first encoding vector. One second encoding vector can correspond to one second dimension reduction vector; the second dimension reduction vector can be understood as a vector obtained by performing dimension reduction processing on the second encoding vector.
[0066] For each natural language description information, dimension reduction processing is performed on each first encoding vector and each second encoding vector corresponding to the natural language description information to obtain a first dimension reduction vector corresponding to each first encoding vector and a second dimension reduction vector corresponding to each second encoding vector. Here, how to perform dimension reduction processing is not specifically limited, such as dimension reduction processing can be performed on the first encoding vector and the second encoding vector by using a corresponding algorithm or network model for dimension reduction processing.
[0067] Optionally, dimension reduction processing is performed on each first encoding vector and each second encoding vector corresponding to the natural language description information to obtain a first dimension reduction vector corresponding to each first encoding vector and a second dimension reduction vector corresponding to each second encoding vector, including: inputting each first encoding vector and each second encoding vector corresponding to the natural language description information into a feed forward neural network (FFN) to obtain a first dimension reduction vector corresponding to each first encoding vector and a second dimension reduction vector corresponding to each second encoding vector.
[0068] In this embodiment, the first dimension-reduced vectors and the second dimension-reduced vectors corresponding to the natural language description information can be input into the FFN as input data, so as to output the first dimension-reduced vectors corresponding to each first dimension-reduced vector and the second dimension-reduced vectors corresponding to each second dimension-reduced vector.
[0069] In S260, the first dimension-reduced vectors and the second dimension-reduced vectors corresponding to the natural language description information are input into the set sentence generation model, and a dependency relationship value between each first dimension-reduced vector and each second dimension-reduced vector is determined.
[0070] In this embodiment, the dependency relationship value can be understood as a value indicating the dependency relationship between the features corresponding to two vectors; and the dependency can be understood as the association. For each first dimension-reduced vector, there can be a dependency relationship value between the first dimension-reduced vector and each second dimension-reduced vector, which is used to indicate the feature association relationship between the first dimension-reduced vector and the corresponding second dimension-reduced vector.
[0071] The first dimension-reduced vectors and the second dimension-reduced vectors corresponding to the natural language description information are input into the set sentence generation model as input data, so as to output the dependency relationship value between each first dimension-reduced vector and each second dimension-reduced vector.
[0072] In S270, a predicted SQL query statement corresponding to the natural language description information is determined according to the words, the fields, and the dependency relationship values corresponding to the natural language description information.
[0073] In this embodiment, how to determine the predicted SQL query statement corresponding to the natural language description information according to the words, the fields, and the dependency relationship values corresponding to the natural language description information is not specifically limited. For example, for each first dimension-reduced vector, the maximum dependency relationship value can be found from all the dependency relationship values corresponding to the first dimension-reduced vector; each first dimension-reduced vector can find a corresponding maximum dependency relationship value, and the maximum dependency relationship value represents that the feature association relationship between the two vectors corresponding to the maximum dependency relationship value is greater; based on the words and the fields corresponding to the natural language description information, the words and the fields corresponding to each maximum dependency relationship value are determined; and the words and the fields corresponding to each maximum dependency relationship value are filled into a pre-set SQL query statement framework one by one, so as to obtain the predicted SQL query statement corresponding to the natural language description information.
[0074] Optionally, the predicted SQL query statement corresponding to the natural language description information is determined according to the words, the fields and the dependency values corresponding to the natural language description information, including: for each first dimension reduction vector, determining a maximum dependency value of the first dimension reduction vector from all dependency values corresponding to the first dimension reduction vector; and filling the words and the fields corresponding to the maximum dependency values into the SQL query statement framework to obtain the predicted SQL query statement corresponding to the natural language description information.
[0075] In this embodiment, the maximum dependency value can be understood as the dependency value with the largest value. One first dimension reduction vector can correspond to at least one dependency value, and correspondingly, one first dimension reduction vector can correspond to one maximum dependency value, that is, the dependency value with the largest value among the at least one dependency value corresponding to the first dimension reduction vector. The SQL query statement framework can be understood as a statement framework pre-set for generating a predicted SQL query statement; here, the SQL query statement framework is not specifically limited, for example, it can include various clauses (such as SELECT clause, FROM clause and WHERE clause, etc.) for querying, wherein the information corresponding to the query condition under each clause is empty, waiting for subsequent filling to generate a corresponding predicted SQL query statement.
[0076] For each first dimension reduction vector, the dependency value with the largest value can be determined as the maximum dependency value of the first dimension reduction vector from all dependency values corresponding to the first dimension reduction vector. For each maximum dependency value, the first dimension reduction vector and the second dimension reduction vector corresponding to the maximum dependency value are determined, and then based on the words and the fields corresponding to the natural language description information, the word corresponding to the first dimension reduction vector and the field corresponding to the second dimension reduction vector are determined, which can be considered as the word and the field corresponding to the maximum dependency value. On this basis, the determined words and fields corresponding to each maximum dependency value are filled into the areas under each clause of the SQL query statement framework for placing information related to the query condition, and a predicted SQL query statement corresponding to the natural language description information can be obtained. Here, how to fill into each clause is not specifically limited.
[0077] S280, determining a loss function of the set statement generation model according to the predicted SQL query statement corresponding to each natural language description information and the label SQL query statement corresponding to each natural language description information, and optimizing the set statement generation model according to the loss function.
[0078] In the embodiment, according to the predicted SQL query statements corresponding to each natural language description information and the label SQL query statements corresponding to each natural language description information, a plurality of loss values can be obtained, a loss function of the setting sentence generation model can be determined according to the plurality of loss values, and the setting sentence generation model can be optimized according to the loss function. After the optimized setting sentence generation model is obtained, for the natural language description information input by the user, the corresponding SQL query statement can be obtained through the optimized setting sentence generation model.
[0079] Optionally, the setting sentence generation model is optimized according to the loss function, and the operation comprises:
[0080] It is judged whether the loss function reaches a preset condition; if yes, the setting sentence generation model is taken as the optimized setting sentence generation model; otherwise, parameters of the setting sentence generation model are updated according to the loss function, and the operation of determining the predicted SQL query statement corresponding to each natural language description information according to the first encoding vector corresponding to each natural language description information, the second encoding vector corresponding to each natural language description information and the setting sentence generation model is repeatedly executed until the loss function reaches the preset condition, and the current corresponding setting sentence generation model is taken as the optimized setting sentence generation model.
[0081] In the embodiment, the parameters of the setting sentence generation model can be understood as parameters associated with the setting sentence generation model for generating the predicted SQL query statement, which is not specifically limited here. The preset condition can be understood as a threshold value for judging whether the loss function reaches the standard, which is not specifically limited here and can be flexibly set according to actual needs.
[0082] The process of optimizing the setting sentence generation model according to the loss function can be that it is judged whether the current obtained loss function reaches the preset condition; if yes, the current setting sentence generation model is taken as the optimized setting sentence generation model; otherwise, the parameters of the setting sentence generation model are updated according to the loss function, and the operation of determining the predicted SQL query statement corresponding to each natural language description information according to the first encoding vector corresponding to each natural language description information, the second encoding vector corresponding to each natural language description information and the setting sentence generation model (which can be understood as the setting sentence generation model with updated parameters) is repeatedly executed until the obtained loss function reaches the preset condition, and the current corresponding setting sentence generation model is taken as the optimized setting sentence generation model.
[0083] The embodiment two of the present application provides a method, which specifically implements the process of determining at least one word and at least one field corresponding to natural language description information for a set number of natural language description information, the process of determining a first encoding vector corresponding to each word and a second encoding vector corresponding to each field of the natural language description information, and the process of determining a predicted SQL query statement corresponding to each natural language description information according to each first encoding vector corresponding to each natural language description information, each second encoding vector corresponding to each natural language description information and a set sentence generation model. The method can obtain the field associated with the natural language description information in the set database table through the semantic analysis algorithm; the embedding vector representing the characteristics of the word and the field can be obtained through the BERT model, and the corresponding encoding vector can be obtained by inputting the embedding vector into the Bi-LSTM encoder; the feature dimension of the encoding vector can be reduced by performing dimension reduction processing on the encoding vector, so as to reduce the calculation amount of the set sentence generation model when processing the encoding vector, and save the calculation resources and time cost; and the set sentence generation model is optimized through the loss function, so that the accuracy of the SQL query statement generated by the set sentence generation model can be effectively improved.
[0084] The present application is exemplarily described below.
[0085] The existing NL2SQL model method depends on the execution of the SQL statement on the database, which greatly reduces the reasoning speed, thereby affecting the actual application; and errors occurring at runtime also occur, which are mainly caused by the mismatch between the generated table header (field) and the operator (for example, the data type of the field and the data type of the operator do not match); the existing method cannot adapt to the multi-round query task, and the accuracy of the query is also relatively low. In order to solve the problem of errors occurring at runtime, the embodiment proposes a method, which aims to more efficiently capture the complex interaction relationship between the question (i.e., the natural language question) and the table header, so as to accurately improve the accuracy of the SQL query statement generation.
[0086] The embodiment of the present application can improve the speed and accuracy without sacrificing the overall performance of the model, and at the same time, solve the runtime errors occurring in the running process, and support multi-round queries while obtaining high accuracy.
[0087] In the embodiment of the present application, a plurality of questions and their corresponding SQL query statements (i.e., label SQL query statements) are given, and alignment is used to construct the dependency relationship between the questions and the table headers.
[0088] The words and fields corresponding to the question are input as input data into the BERT model, and the corresponding embedding vectors are output. The output embedding vectors are fed into a two-layer Bi-LSTM encoder to obtain corresponding encoding vectors, where two layers represent two hidden layers. The encoding vectors are dimensionally reduced by a single-layer feedforward network (FFN) to obtain corresponding reduced dimension vectors.
[0089] The dependency relationship between the question and the table header is obtained by the deep-biaffine mechanism. The obtained reduced dimension vectors are input into the deep-biaffine mechanism-based setting sentence generation model to obtain corresponding dependency relationship values. Based on the dependency relationship values, corresponding processing can be performed to obtain the corresponding predicted SQL query statement.
[0090] The setting sentence generation model is optimized using cross-entropy loss. In this embodiment, an adaptive loss function can be used to automatically learn the weight values from the data to optimize the setting sentence generation model parameters.
[0091] The method proposed in this embodiment improves the reasoning efficiency, sacrifices a small performance, and provides greater flexibility for actual use. At the same time, the model proposed has a high accuracy, can capture the dependency relationship between the question and the table header, and improve the accuracy of the model generating the SQL query statement.
[0092] Embodiment three
[0093] Figure 3 A structural schematic diagram of a sentence generation model optimization device provided for the third embodiment of the present application. The device can be implemented by software and / or hardware. As shown in the figure, the device includes: Figure 3
[0094] The first determination module 310 is configured to determine at least one word and at least one field corresponding to the natural language description information for a set number of natural language description information, the word being the smallest semantic unit constituting the natural language description information, and the field being the field corresponding to the natural language description information in a set database table;
[0095] The second determination module 320 is configured to determine the first encoding vector corresponding to each word of the natural language description information and the second encoding vector corresponding to each field of the natural language description information;
[0096] The third determination module 330 is configured to determine the predicted SQL query statement corresponding to each natural language description information according to the first encoding vector corresponding to each natural language description information, the second encoding vector corresponding to each natural language description information, and the setting sentence generation model;
[0097] The optimization module 340 is configured to determine a loss function of the set statement generation model according to the predicted SQL query statement corresponding to each natural language description information and the label SQL query statement corresponding to each natural language description information, and optimize the set statement generation model according to the loss function.
[0098] In the embodiment, the device first determines, by the first determination module 310, at least one word and at least one field corresponding to the natural language description information for a set number of natural language description information, the word being the smallest semantic unit constituting the natural language description information, and the field being the field corresponding to the natural language description information in the set database table. Then, the second determination module 320 is used to determine the first encoding vector corresponding to each word of the natural language description information and the second encoding vector corresponding to each field. Then, the third determination module 330 is used to determine the predicted SQL query statement corresponding to each natural language description information according to the first encoding vector corresponding to each natural language description information, the second encoding vector corresponding to each natural language description information, and the set statement generation model. Finally, the optimization module 340 is used to determine the loss function of the set statement generation model according to the predicted SQL query statement corresponding to each natural language description information and the label SQL query statement corresponding to each natural language description information, and optimize the set statement generation model according to the loss function. The device encodes the words and fields of the set number of natural language description information, generates the corresponding predicted SQL query statement based on the encoding vector through the set statement generation model, optimizes the set statement generation model through the loss function between the label SQL query statement and the predicted SQL query statement, and generates a more accurate SQL query statement through the optimized set statement generation model, thereby effectively improving the accuracy of the SQL query statement generation.
[0099] Optionally, the second determination module 310 includes:
[0100] The first input unit is configured to input the words and the fields corresponding to the natural language description information into a bidirectional encoder representation (BERT) model of a transformer to obtain the first embedding vector corresponding to each word and the second embedding vector corresponding to each field.
[0101] The second input unit is configured to input the first embedding vector and the second embedding vector into a bidirectional long short-term memory (Bi-LSTM) neural network encoder to obtain the first encoding vector corresponding to each first embedding vector and the second encoding vector corresponding to each second embedding vector.
[0102] Optionally, the third determination module 330 includes:
[0103] a dimension reduction unit, configured to perform dimension reduction processing on each of the first encoding vectors and each of the second encoding vectors corresponding to the natural language description information, to obtain a first dimension-reduced vector corresponding to each of the first encoding vectors and a second dimension-reduced vector corresponding to each of the second encoding vectors;
[0104] a third input unit, configured to input each of the first dimension-reduced vectors and each of the second dimension-reduced vectors corresponding to the natural language description information into the set sentence generation model, to determine, for each first dimension-reduced vector, a dependency relationship value between the first dimension-reduced vector and each second dimension-reduced vector;
[0105] a sentence determination unit, configured to determine, according to each of the words, each of the fields, and each of the dependency relationship values corresponding to the natural language description information, a predicted SQL query sentence corresponding to the natural language description information.
[0106] Optionally, the sentence determination unit comprises:
[0107] a determination sub-unit, configured to determine, for each first dimension-reduced vector, a maximum dependency relationship value of the first dimension-reduced vector from all dependency relationship values corresponding to the first dimension-reduced vector;
[0108] a padding sub-unit, configured to fill words and fields corresponding to each of the maximum dependency relationship values into a SQL query sentence framework, to obtain the predicted SQL query sentence corresponding to the natural language description information.
[0109] Optionally, the dimension reduction unit comprises:
[0110] an input sub-unit, configured to input each of the first encoding vectors and each of the second encoding vectors corresponding to the natural language description information into a feedforward neural network, to obtain the first dimension-reduced vector corresponding to each of the first encoding vectors and the second dimension-reduced vector corresponding to each of the second encoding vectors.
[0111] Optionally, the optimization module 340 comprises:
[0112] a judgment unit, configured to judge whether the loss function meets a preset condition;
[0113] a first optimization unit, configured to, if the loss function meets the preset condition, take the set sentence generation model as an optimized set sentence generation model;
[0114] The second optimization unit is configured to update parameters of the set sentence generation model according to the loss function if the loss function does not meet the preset condition, and repeatedly perform operations of determining the predicted SQL query statement corresponding to each piece of natural language description information according to each first encoding vector corresponding to each piece of natural language description information, each second encoding vector corresponding to each piece of natural language description information, and the set sentence generation model until the obtained loss function meets the preset condition, and take the current corresponding set sentence generation model as the optimized set sentence generation model.
[0115] Optionally, the first determination module 310 comprises:
[0116] The word segmentation unit is configured to perform word segmentation processing on the natural language description information to obtain at least one word corresponding to the natural language description information.
[0117] The searching unit is configured to search for at least one field corresponding to the natural language description information from a set database table by using a semantic analysis algorithm.
[0118] The sentence generation model optimization apparatus provided by the embodiments of the present application can perform the sentence generation model optimization method provided by any of the embodiments of the present application, and has the corresponding function modules and beneficial effects of performing the method.
[0119] Embodiment four
[0120] Figure 4 A structural schematic diagram of an electronic device is provided for the fourth embodiment of the present application. The electronic device is intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular telephones, smart phones, wearable devices (such as headsets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions, are meant to be examples only, and are not intended to limit the implementations of the present application described and / or claimed in this document.
[0121] As Figure 4As shown, the electronic device 10 includes at least one processor 11, and a memory, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., communicatively connected to the at least one processor 11, where the memory stores a computer program executable by the at least one processor. The processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or loaded into the random access memory (RAM) 13 from the storage unit 18. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0122] Various components in the electronic device 10 are connected to the I / O interface 15, including an input unit 16, such as a keyboard, a mouse, etc., an output unit 17, such as various types of displays, a speaker, etc., a storage unit 18, such as a magnetic disk, an optical disk, etc., and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network, such as the Internet, and / or various telecommunication networks.
[0123] The processor 11 can be various general and / or special-purpose processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 performs various methods and processes described above, such as the sentence generation model optimization method.
[0124] In some embodiments, the sentence generation model optimization method can be implemented as a computer program tangibly embodied in a computer readable storage medium, such as the storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed onto the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded onto the RAM 13 and executed by the processor 11, one or more steps of the sentence generation model optimization method described above can be performed. Alternatively, in other embodiments, the processor 11 can be configured to perform the sentence generation model optimization method by any other appropriate means, such as by means of firmware.
[0125] The various embodiments of the systems and techniques described above can be implemented in digital electronic circuitry, integrated circuitry, a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on a chip (SOC), a load programmable logic device (CPLD), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include implementation in one or more computer programs that are executable and / or interpretable on a programmable system including at least one programmable processor, which can be special or general purpose, coupled to receive data and instructions from, and to transmit data and instructions to, a storage system, at least one input device, and at least one output device.
[0126] Computer programs used to implement the processes of the application can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the computer program, when executed, can cause instructions defined in the flow charts and / or block diagrams to be implemented. The computer program can be executed entirely on a machine, partially on a machine, partially on a machine as a standalone software package and partially on a remote machine or entirely on a remote machine or server.
[0127] In the context of the present application, a computer-readable storage medium can be a tangible medium that can contain or store computer programs for use by or in connection with an instruction execution system, apparatus, or device. Computer-readable storage media can include, but are not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium can be a machine-readable signal medium. More specific examples of the machine-readable storage medium will include one or more lines of electrical connections, portable computer disks, hard disk drives, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or Flash memory), optical fibers, portable compact disc read-only memories (CD-ROMs), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0128] To provide for interaction with a user, the systems and techniques described here can be implemented on an electronic device having a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the electronic device. Other kinds of devices can be used to provide for interaction with a user as well; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form, including acoustic, speech, or tactile input.
[0129] The systems and techniques described here can be implemented in a computing system that includes a back end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front end component (e.g., a user computer having a graphical user interface or a Web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back end, middleware, or front end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0130] The computing system can include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. A server can be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system, to solve the defects of large management difficulty and weak business scalability in traditional physical host and VPS service.
[0131] It should be understood that the various forms of flow shown above can be re-ordered, added to, or deleted from without departing from the scope of the present disclosure. For example, the steps recited in the present disclosure can be executed in parallel, executed in sequence, or executed in a different order, as long as the desired results of the present disclosure are achieved, and the present disclosure is not limited herein.
[0132] The specific embodiments described above are not intended to be limiting, and persons skilled in the art will appreciate that various modifications, combinations, sub-combinations and alternatives can be made to the specific embodiments without departing from the spirit and principles of the disclosure. Accordingly, the disclosure is not limited to the specific embodiments described above, but only by the scope of the appended claims.
Claims
1. A method for optimizing a statement generation model, characterized in that, The method comprises: For a set number of natural language description information, determining at least one word and at least one field corresponding to the natural language description information, the word being the smallest semantic unit constituting the natural language description information, and the field being the field corresponding to the natural language description information in a set database table; Determine the first encoding vector corresponding to each of the words and the second encoding vector corresponding to each of the fields corresponding to the natural language description information; According to each first encoding vector corresponding to each of the natural language description information, each second encoding vector corresponding to each of the natural language description information and a set sentence generation model, determine the predicted structured query language (SQL) query statement corresponding to each of the natural language description information respectively; According to the predicted SQL query statement corresponding to each of the natural language description information and the label SQL query statement corresponding to each of the natural language description information, determine the loss function of the set sentence generation model, and optimize the set sentence generation model according to the loss function; Wherein, according to each first encoding vector corresponding to each of the natural language description information, each second encoding vector corresponding to each of the natural language description information and a set sentence generation model, determine the predicted SQL query statement corresponding to each of the natural language description information respectively, comprising: For each natural language description information, dimension reduction processing is performed on each first encoding vector and each second encoding vector corresponding to the natural language description information to obtain a first dimension reduction vector corresponding to each first encoding vector and a second dimension reduction vector corresponding to each second encoding vector; Input each first dimension reduction vector and each second dimension reduction vector corresponding to the natural language description information into the set sentence generation model to determine the dependency relationship value between each first dimension reduction vector and each second dimension reduction vector for each first dimension reduction vector. According to each word, each field and each dependency relationship value corresponding to the natural language description information, determine the predicted SQL query statement corresponding to the natural language description information.
2. The method of claim 1, wherein, Determine the first encoding vector corresponding to each of the words and the second encoding vector corresponding to each of the fields corresponding to the natural language description information, comprising: Input each word and each field corresponding to the natural language description information into a bidirectional encoder representation (BERT) model of a transformer to obtain a first embedding vector corresponding to each word and a second embedding vector corresponding to each field; Input each first embedding vector and each second embedding vector into a bidirectional long short-term memory (LSTM) neural network encoder to obtain a first encoding vector corresponding to each first embedding vector and a second encoding vector corresponding to each second embedding vector.
3. The method of claim 1, wherein, According to each word, each field and each dependency relationship value corresponding to the natural language description information, determine the predicted SQL query statement corresponding to the natural language description information, comprising: For each first dimension reduction vector, determine the maximum dependency relationship value of the first dimension reduction vector from all dependency relationship values corresponding to the first dimension reduction vector. Fill the words and fields corresponding to each of the maximum dependency relationship values into a SQL query statement framework to obtain a predicted SQL query statement corresponding to the natural language description information.
4. The method of claim 1, wherein, The dimension reduction processing on each of the first encoding vectors and each of the second encoding vectors corresponding to the natural language description information obtains a first dimension-reduced vector corresponding to each of the first encoding vectors and a second dimension-reduced vector corresponding to each of the second encoding vectors, including: The dimension reduction processing on each of the first encoding vectors and each of the second encoding vectors corresponding to the natural language description information obtains a first dimension-reduced vector corresponding to each of the first encoding vectors and a second dimension-reduced vector corresponding to each of the second encoding vectors.
5. The method of claim 1, wherein, According to the loss function, the set sentence generation model is optimized, including: determining whether the loss function meets a preset condition; if yes, the set sentence generation model is used as an optimized set sentence generation model; otherwise, the parameters of the set sentence generation model are updated according to the loss function, and the operation of determining a predicted SQL query statement corresponding to each of the natural language description information according to each of the first encoding vectors corresponding to each of the natural language description information, each of the second encoding vectors corresponding to each of the natural language description information, and the set sentence generation model is repeatedly performed until the loss function meets the preset condition, and the current corresponding set sentence generation model is used as the optimized set sentence generation model.
6. The method of claim 1, wherein, The determination of at least one word and at least one field corresponding to the natural language description information includes: performing word segmentation processing on the natural language description information to obtain at least one word corresponding to the natural language description information; finding at least one field corresponding to the natural language description information from a set database table through a semantic parsing algorithm.
7. A sentence generation model optimization apparatus characterized by comprising: including: The first determination module is configured to determine at least one word and at least one field corresponding to a set number of natural language description information, the word being a smallest semantic unit constituting the natural language description information, and the field being a field corresponding to the natural language description information in a set database table. The second determination module is configured to determine a first encoding vector corresponding to each of the words and a second encoding vector corresponding to each of the fields. The third determination module is configured to determine a predicted structured query language (SQL) query statement corresponding to each of the natural language description information according to each of the first encoding vectors corresponding to each of the natural language description information, each of the second encoding vectors corresponding to each of the natural language description information, and a set sentence generation model. The optimization module is configured to determine a loss function of the set sentence generation model according to a predicted SQL query statement corresponding to each of the natural language description information and a label SQL query statement corresponding to each of the natural language description information, and optimize the set sentence generation model according to the loss function. The third determination module includes: The dimension reduction unit is configured to perform dimension reduction processing on each of the first encoding vectors and each of the second encoding vectors corresponding to the natural language description information to obtain a first dimension-reduced vector corresponding to each of the first encoding vectors and a second dimension-reduced vector corresponding to each of the second encoding vectors. The third input unit is configured to input each of the first dimension-reduced vectors and each of the second dimension-reduced vectors corresponding to the natural language description information into the set sentence generation model to determine, for each first dimension-reduced vector, a dependency relationship value between the first dimension-reduced vector and each second dimension-reduced vector. The sentence determination unit is configured to determine, according to each of the words, each of the fields, and each of the dependency relationship values corresponding to the natural language description information, a predicted SQL query sentence corresponding to the natural language description information.
8. An electronic device, comprising: The electronic device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to execute the sentence generation model optimization method of any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer instructions for causing a processor to implement the sentence generation model optimization method of any one of claims 1-6 when executed by the processor.
Citation Information
Patent Citations
Structured query language statement generation method and system
CN114610742A
Method, apparatus, device and medium for generating recruitment position description text
US20210216726A1