Structured query language statement generation method and system
By using a two-stage generation method, structured query language statements are generated using semantic encoding and matching models. This solves the problems of high complexity and error susceptibility in existing technologies, and achieves efficient and accurate structured query language generation.
Patent Information
- Application Number
- CN202210157135.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-21
- Publication Date
- 2025-10-21
- Estimated Expiration
- 2042-02-21
AI Technical Summary
In existing technologies, structured query language generation methods are complex and error-prone, especially since multiple subtasks need to be completed collaboratively during table value generation, which increases the complexity of the model and the cumbersomeness of post-processing.
A two-stage generation method is adopted. First, a semantic encoding model is used to generate a joint representation of structured query language clauses and table headers. Then, a matching model is used to generate table values that match natural language text with candidate clauses, and these are then concatenated into a complete structured query language statement.
The generation process was simplified, the number of subtasks was reduced, the model running efficiency was improved, and the matching accuracy was significantly enhanced.
Smart Images

Figure CN114610742B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of natural language processing business technology, and in particular to a method and system for generating structured query language statements, an electronic device, and a storage medium. Background Art
[0002] Converting human natural language into machine-understandable structured query language (SQL) statements and returning the answers to database queries acts as an intelligent bridge between language and database, allowing users unfamiliar with databases to quickly retrieve desired data using only natural language. This technology holds immense value in human-computer interaction. Currently, table value generation in the decomposed-task SQL generation approach is very complex, requiring the collaborative work of two subtasks: first, selecting possible candidate table values from the natural language through sequence labeling, as there are multiple possible table values; and then, matching the selected table values to the corresponding conditional clauses through matching. Furthermore, post-processing is required. Since both labeling and matching tasks are relatively complex, this not only increases model complexity but also makes post-processing cumbersome, the method is not concise, and is prone to errors. Summary of the Invention
[0003] The present disclosure provides a structured query language statement generation method and system, an electronic device and a storage medium, to solve the technical defects existing in the prior art.
[0004] The present disclosure provides a method for generating a structured query language statement, comprising:
[0005] Inputting natural language text and several table headers in a query table into a semantic encoding model, and outputting a joint representation of a structured query language clause and the table headers; wherein the semantic encoding model is trained based on structured text and table samples and predetermined target labels;
[0006] generating candidate phrases based on the natural language text and the query table;
[0007] Inputting the natural language text and the candidate short sentences into a matching model respectively, and outputting table values of the candidate short sentences that match the natural language text; wherein the matching model is obtained by training based on labeled text and structured query language sentence samples and predetermined representation pairing labels;
[0008] The joint representation of the structured query language clause and the table header and the table values in the candidate short sentences that match the natural language text are concatenated to generate a structured query language statement.
[0009] According to the structured query language sentence generation method provided by the present disclosure, the step of generating candidate short sentences based on the natural language text and the query table includes:
[0010] Based on the natural language text, selecting a candidate unit in a query table, and selecting a table value corresponding to the candidate unit in the query table;
[0011] The candidate units and the table values in the candidate short sentences that match the natural language text are sequentially concatenated to form the candidate short sentences.
[0012] According to the structured query language statement generation method provided by the present disclosure, wherein the natural language text and several headers in the query table are input into the semantic encoding model, and the joint representation of the structured query language clause and the header is output, including:
[0013] Input the natural language text and several headers in the query table into the semantic encoding model, and output the joint representation of the structured query language clauses and the headers corresponding to several subtasks;
[0014] The joint representations of the structured query language clauses and table headers corresponding to several subtasks are concatenated to form a joint representation of the structured query language clauses and table headers.
[0015] According to the structured query language statement generation method provided by the present disclosure, the loss function used by the semantic coding model during training is:
[0016]
[0017] in, represents the predetermined generated target label, It represents the output result of semantic coding model training, and n1 represents the number of categories of the output result of semantic coding model.
[0018] According to the structured query language statement generation method provided by the present disclosure, the loss function used by the matching model during training is:
[0019]
[0020] in, represents a predetermined characterization pairing label, It represents the output result of the matching model training, and n2 represents the number of classifications of the matching model output result.
[0021] The present disclosure also provides a structured query language statement generation system, comprising:
[0022] A semantic encoding module, configured to input natural language text and several table headers from a query table into a semantic encoding model, and output a joint representation of a structured query language clause and the table headers; wherein the semantic encoding model is trained based on structured text and table samples and predetermined target labels for generation;
[0023] a candidate short sentence generating module, configured to generate candidate short sentences based on the natural language text and the query table;
[0024] a table value matching module, configured to input the natural language text and the candidate short sentence into a matching model, and output a table value in the candidate short sentence that matches the natural language text; wherein the matching model is trained based on labeled text and structured query language sentence samples and predetermined representation pairing labels;
[0025] The splicing module is used to splice the joint representation of the structured query language clause and the table header, and the table value matching the natural language text in the candidate short sentence to generate a structured query language statement.
[0026] According to the structured query language sentence generation system provided by the present disclosure, the candidate short sentence generation module is specifically used to:
[0027] Based on the natural language text, selecting a candidate unit in a query table, and selecting a table value corresponding to the candidate unit in the query table;
[0028] The candidate units and the table values in the candidate short sentences that match the natural language text are sequentially concatenated to generate the candidate short sentences.
[0029] According to the structured query language statement generation system provided by the present disclosure, the semantic encoding module is specifically used to:
[0030] Input the natural language text and several headers in the query table into the semantic encoding model, and output the joint representation of the structured query language clauses and the headers corresponding to several subtasks;
[0031] The joint representations of the structured query language clauses and table headers corresponding to several subtasks are concatenated to form a joint representation of the structured query language clauses and table headers.
[0032] The present disclosure also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of any of the above-described structured query language statement generation methods are implemented.
[0033] The present disclosure also provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of any of the above-mentioned methods for generating structured query language statements are implemented.
[0034] The present invention generates a joint representation of structured query language clauses and table headers through a semantic coding model, generates table values that match natural language text and candidate short sentences through a matching model, and then splices the joint representation of structured query language clauses and table headers and the table values to form a structured query language statement. It adopts an efficient two-stage generation method, reduces the number of subtasks and does not require post-processing, simplifies the structured query language statement generation process, ensures model operation efficiency, and significantly improves the matching accuracy of the two-stage model after optimization. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the technical solutions in the present disclosure or the prior art, a brief introduction will be given below to the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present disclosure. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0036] Figure 1 It is a flowchart of a method for generating a structured query language statement provided by an embodiment of the present disclosure;
[0037] Figure 2 is a schematic diagram of a semantic encoding model in a structured query language statement generation method provided by an embodiment of the present disclosure;
[0038] Figure 3 is a schematic diagram of a matching model in a method for generating a structured query language statement provided in an embodiment of the present disclosure;
[0039] Figure 4 is a schematic diagram of a structured query language statement generation system provided by the present disclosure;
[0040] Figure 5 It is a structural diagram of the electronic device provided by the present disclosure. DETAILED DESCRIPTION
[0041] To make the objectives, technical solutions, and advantages of this disclosure more clear, the technical solutions of this disclosure will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the embodiments described are only part of the embodiments of this disclosure, not all of them. All other embodiments obtained by persons of ordinary skill in the art based on the embodiments of this disclosure without creative effort shall fall within the scope of protection of this disclosure.
[0042] The present disclosure discloses a method for generating a structured query language statement. Figure 1 , the structured query language statement generation method includes:
[0043] S1. Input natural language text and several table headers in the query table into a semantic coding model, and output a joint representation of the structured query language clause and the table header; wherein the semantic coding model is obtained after training based on structured text and table samples and predetermined generation target labels.
[0044] In this embodiment, Structured Query Language (SQL) is a special-purpose programming language, a database query and programming language, used to access data and query, update and manage relational database systems.
[0045] SQL (Structured Query Language) statements themselves cannot be input into the semantic coding model for learning. SQL statements need to be converted into text statements to obtain a joint representation of structured query language clauses and table headers. The semantic coding model is obtained after training based on structured text and table samples and predetermined target labels. The content generated by the semantic coding model does not include value (table value). Through the semantic coding model, all content except value can be obtained, that is, a joint representation of structured query language clauses and table headers except value is generated. Several headers in a query table can be all the headers of the first row in the query table.
[0046] The model input is natural language text and multiple headers in the query table, and the output is a joint representation of the structured query language clause and the header. Figure 2 As shown, different subtasks can then be used to obtain the specific values of Agg (aggregation operations such as max and min), sel_column (columns in the selection clause), op (=, >, etc.), where_column (columns in the conditional clause), and conn (connectors such as AND). This part of the SQL statement generation method can be implemented using the principle of attacking each one separately, breaking down the SQL statement generation problem into multiple subtasks.
[0047] S2. generating candidate short sentences based on the natural language text and the query table;
[0048] S3. Inputting the natural language text and the candidate short sentence into a matching model, respectively, and outputting table values of the candidate short sentence that match the natural language text; wherein the matching model is trained based on labeled text and structured query language sentence samples and predetermined representation pairing labels;
[0049] A one-to-one match is performed between the natural language text and the candidate sentences. If the natural language text and the candidate sentences match, it is selected, indicating that this value is the value of the current candidate unit. On the contrary, if the natural language text and the candidate sentences do not match, it is not selected and the next one is matched until a matching value is found. The matching model is obtained after training based on labeled text and structured query language sentence samples and predetermined representation pairing labels. The matching model can generate table values that match the natural language text and the candidate sentences. The advantage is that the original sequence labeling and matching tasks are simplified into one matching task. At the same time, because the candidate values are taken from the query table and actually exist, there is no need to modify the values and configure additional vocabulary. The output of the matching model is a binary classification, that is, whether the current value is a value that conforms to the SQL statement. This process requires a column in the table to be used as a candidate unit, and then all the values in the column are checked, and finally a value that meets the matching conditions is obtained, that is, the value can be directly obtained through the matching model.
[0050] S4. Concatenate the joint representation of the structured query language clause and the table header, and the table values in the candidate short sentences that match the natural language text to generate a structured query language statement.
[0051] The joint representation of the structured query language clause and table header obtained in S1 and the table value in the candidate phrase obtained in S3 that matches the natural language text can be spliced together to generate a complete structured query language statement. The value obtained in S3 is combined with the output of the semantic encoding model to form the final SQL statement. In other words, the eight subtasks generated by the semantic encoding model plus the value generated by the matching model together constitute the SQL statement.
[0052] The disclosed embodiment generates a joint representation of a structured query language clause and a table header through a semantic coding model, generates a table value that matches the natural language text and the candidate short sentence through a matching model, and then splices the joint representation of the structured query language clause and the table header and the table value to form a structured query language statement. An efficient two-stage generation method is adopted, which reduces the number of subtasks and does not require post-processing, simplifies the structured query language statement generation process, ensures the model operation efficiency, and significantly improves the matching accuracy of the two-stage model after optimization.
[0053] According to the structured query language sentence generation method provided by an embodiment of the present disclosure, the step of generating candidate short sentences based on the natural language text and the query table includes:
[0054] Based on the natural language text, selecting a candidate unit in a query table, and selecting a table value corresponding to the candidate unit in the query table;
[0055] The candidate units and the table values in the candidate short sentences that match the natural language text are sequentially concatenated to form the candidate short sentences.
[0056] like Figure 3 As shown, Figure 3 The example in the example uses the selected where (conditional clause) column (date) to extract all the corresponding values (yesterday, today, tomorrow) in the table as candidates, and then sequentially concatenates the candidate units and values into several candidate short sentences.
[0057] According to the method for generating a structured query language statement provided by an embodiment of the present disclosure, the method of inputting a natural language text and several headers in a query table into a semantic encoding model and outputting a joint representation of the structured query language clause and the headers includes:
[0058] Input the natural language text and several headers in the query table into the semantic encoding model, and output the joint representation of the structured query language clauses and the headers corresponding to several subtasks;
[0059] The joint representations of the structured query language clauses and table headers corresponding to several subtasks are concatenated to form a joint representation of the structured query language clauses and table headers.
[0060] Multiple subtasks are generated using a semantic encoding model, meaning each clause of the SQL statement is generated separately. The semantic encoding model takes as input the natural language text and several table headers from the query table, ultimately outputting a joint representation of the structured query language clauses and headers corresponding to the subtasks. These joint representations of the structured query language clauses and headers are then concatenated to form a joint representation of the structured query language clauses and headers.
[0061] According to the structured query language statement generation method provided by the embodiment of the present disclosure, the loss function used by the semantic coding model during training is:
[0062]
[0063] in, represents the predetermined generated target label, This field represents the output of the semantic coding model during training, and n1 represents the number of categories in the output. During semantic coding model training, there are multiple tasks, and the number of n1s corresponding to each task may vary. If there are two fields, max and min, it is called a two-category classification, and if there are five, it is called a five-category classification.
[0064] The semantic coding model is trained by performing multiple iterative operations, which is a deep learning process. It can be determined whether the current iterative operation reaches the preset convergence condition based on the loss function used by the semantic coding model during the training process. If the convergence condition is reached, the iteration can be stopped.
[0065] According to the structured query language statement generation method provided by the embodiment of the present disclosure, the loss function used by the matching model during the training process is:
[0066]
[0067] in, represents a predetermined characterization pairing label, represents the output of the matching model during training, and n2 represents the number of classifications of the matching model output. During the training process, the output of the training has two categories: the first category is that the output natural language text and the candidate short sentence match, and the other category is that the output natural language text and the candidate short sentence do not match. In this case, n2 is 2.
[0068] The matching model is trained by performing multiple iterative operations, which is a deep learning process. It can be determined whether the current iterative operation reaches the preset convergence condition based on the loss function used by the matching model during the training process. If the convergence condition is reached, the iteration can be stopped.
[0069] According to the structured query language statement generation method provided by the embodiment of the present disclosure, wherein the semantic encoding model is obtained after training based on structured text and table samples and predetermined generation target labels, the method includes:
[0070] The semantic encoding model is obtained after training based on the RoBERTa model, structured text and table samples, and predetermined generation target labels.
[0071] The semantic encoding model can be further optimized using RoBERTa, a model that has been pre-trained on general Chinese corpora. This is equivalent to having initialized weights. This means that the RoBERTa model can be directly used as a semantic encoding model after training on a large corpus of general corpora. Further training using samples can be performed directly on the RoBERTa model. RoBERTa primarily improves upon BERT (Bidirectional Encoder Representations from Transformers, word embeddings) with several adjustments: 1) longer training time, larger batch sizes, and more training data; 2) removal of the next predict loss; 3) longer training sequences; and 4) dynamic adjustment of the masking mechanism. Compared to BERT, RoBERTa incorporates numerous improvements and adjustments, including using more data for pre-training. Experiments have shown that this model outperforms BERT by 1%.
[0072] To further understand the method of this embodiment, in a specific example, the method of generating a structured query language statement of this embodiment includes:
[0073] First, use the first model (that is, the semantic encoding model) to generate structured query clauses other than value (which may be numeric or character type):
[0074] The first model is a generative model. It is trained using structured text (text-SQL) and table samples (corresponding to a table) and predetermined target labels, that is, the various parts of the SQL statement. The input of the first model is consistent, and the output contains 8 subtasks. 6 of them are basic tasks: s_sum: how many are selected; w_sum: how many columns are in where; order: whether there is an order by; agg (aggregation operation): what is the agg (max, min, count) operation of the current column; conn_op (connector): what is the operator (>, <, =) between the current column and value; conns_op: what is the connector (And, or) of the current SQL statement.
[0075] In addition to the six basic tasks above, two auxiliary classification tasks have been added: determining whether the current column is selected in the select clause and whether the current where column is selected. These two subtasks provide the model with more learning labels, enabling it to fully utilize training data and facilitating the implementation of other subtasks. The two additional subtasks improve accuracy by approximately 1%.
[0076] Unlike other models, to further improve performance, we replaced the pre-trained BERT model with RoBERTa, which has better semantic performance. RoBERTa has undergone multiple improvements and adjustments compared to BERT, and its pre-training uses more data. Experiments have shown that this model outperforms BERT by 1%.
[0077] Secondly, using the second segment model (matching model), generate and output the table value that matches the natural language text in the candidate short sentence:
[0078] In the second model, we retrieve all corresponding values from the table using the selected where column. We then match the short sentences composed of these columns and values against the natural language. If a sentence is selected, it matches the value of the where column. This simplifies the original two tasks of sequence labeling and matching into a single matching task. Because the values in the table are used, the resulting SQL statement values are correct, eliminating the need for post-processing and configuring additional vocabulary tables.
[0079] To ensure the model's computational speed, we abandoned the pre-trained BERT model and instead used the lightweight CDSSM matching model. This model consists of only a few CNN layers and has extremely fast inference speed, thus hardly reducing model efficiency. Due to its relative simplicity, the model requires careful optimization to achieve good results. The specific optimizations are as follows:
[0080] 1) The default CDSSM model uses a convolution kernel length of 3, i.e., filter = 3, which has been proven to be extremely poor. After adjusting parameters, we found that larger convolution kernels resulted in poorer performance. Ultimately, experiments determined that filter = 1, 2 (using both convolution kernels 1 and 2) performed best. This is because the values matched in this matching task are short words or phrases, so setting a smaller convolution kernel facilitates better semantic understanding.
[0081] 2) During CDSSM training, the words encountered in the sample must be initialized into word vectors. Initializing only the query may not cover the words in the table, resulting in OOV (out of vocabulary) problems. Therefore, the words that appear in the table are also added to the vocabulary, reducing the frequency of OOV.
[0082] 3) In addition, in the experimental verification, it was found that the model can achieve the best effect when the ratio of positive and negative samples in the training set is increased and the number of epochs is increased. The positive and negative ratio of the training set samples is set to 1:20 and the number of model iterations is 40 epochs.
[0083] Table 1
[0084]
[0085] Table 1 above shows the parameter tuning experiment for this module. The experimental data consists of 10,000 high-quality data items that have been manually annotated in real business scenarios. After tuning, the accuracy of single value generation increased from 30% to 87%, and the final SQL statement generation result accuracy was 78.3%.
[0086] Finally, the structured query clauses except value generated by the first segment model and the table values matching the natural language text in the candidate short sentences generated by the second segment model are spliced to obtain a complete structured query language statement.
[0087] The present disclosure discloses a system for generating structured query language statements. Figure 4 , the structured query language statement generation system includes:
[0088] A semantic encoding module 10 is configured to input natural language text and several table headers into a semantic encoding model and output a joint representation of the structured query language clause and the table headers; wherein the semantic encoding model is trained based on structured text and table samples and predetermined target labels for generation;
[0089] a candidate short sentence generating module 20, configured to generate candidate short sentences based on the natural language text and the query table;
[0090] a table value matching module 30 for inputting the natural language text and the candidate short sentence into a matching model, and outputting table values in the candidate short sentence that match the natural language text; wherein the matching model is trained based on labeled text and structured query language sentence samples and predetermined representation pairing labels;
[0091] The concatenation module 40 is configured to concatenate the joint representation of the structured query language clause and the table header, and the table values in the candidate short sentences that match the natural language text, to generate a structured query language statement.
[0092] A complete SQL statement is generated by combining the structured query language clause and table header representation obtained by the semantic encoding module 10 with the table value matching module 30 that matches the natural language text in the candidate phrase. The value obtained by the table value matching module 30 is combined with the output of the semantic encoding model to form the final SQL statement. In other words, the eight subtasks generated by the semantic encoding model plus the value generated by the matching model together constitute the SQL statement.
[0093] According to the structured query language sentence generation system provided by the embodiment of the present disclosure, the candidate short sentence generation module 20 is specifically configured to:
[0094] Based on the natural language text, selecting a candidate unit in a query table, and selecting a table value corresponding to the candidate unit in the query table;
[0095] The candidate units and the table values in the candidate short sentences that match the natural language text are sequentially concatenated to form the candidate short sentences.
[0096] You can use the selected where (conditional clause) column (date) to extract all the corresponding values (yesterday, today, tomorrow) in the table as candidates, and then sequentially concatenate the candidate units and values into several candidate short sentences.
[0097] According to the structured query language statement generation system provided by the embodiment of the present disclosure, the semantic encoding module 10 is specifically used to:
[0098] Input natural language text and several table headers into the semantic encoding model, and output the joint representation of the structured query language clauses and the table headers corresponding to several subtasks;
[0099] The joint representations of the structured query language clauses and table headers corresponding to several subtasks are concatenated to form a joint representation of the structured query language clauses and table headers.
[0100] Multiple subtasks are generated using a semantic encoding model, meaning each SQL clause is generated separately. The semantic encoding model takes as input the natural language text and all headers in the first row of the query table, ultimately outputting a joint representation of the structured query language clauses and headers corresponding to the subtasks. These joint representations of the structured query language clauses and headers corresponding to the subtasks are then concatenated to form a joint representation of the structured query language clauses and headers.
[0101] According to the structured query language statement generation system provided by an embodiment of the present disclosure, the loss function used by the semantic coding model during training is:
[0102]
[0103] in, represents the predetermined generated target label, It represents the output result of semantic coding model training, and n1 represents the number of categories of the output result of semantic coding model.
[0104] The semantic coding model is trained by performing multiple iterative operations, which is a deep learning process. It can be determined whether the current iterative operation reaches the preset convergence condition based on the loss function used by the semantic coding model during the training process. If the convergence condition is reached, the iteration can be stopped.
[0105] According to the structured query language statement generation system provided by an embodiment of the present disclosure, the loss function used by the matching model during training is:
[0106]
[0107] in, represents a predetermined characterization pairing label, It represents the output result of the matching model training, and n2 represents the number of classifications of the matching model output result.
[0108] The matching model is trained by performing multiple iterative operations, which is a deep learning process. It can be determined whether the current iterative operation reaches the preset convergence condition based on the loss function used by the matching model during the training process. If the convergence condition is reached, the iteration can be stopped.
[0109] According to the structured query language statement generation system provided by an embodiment of the present disclosure, the semantic encoding model is obtained through training based on structured text and table samples and predetermined generation target labels, including:
[0110] The semantic encoding model is obtained after training based on the RoBERTa model, structured text and table samples, and predetermined generation target labels.
[0111] The semantic encoding model can be further optimized using RoBERTa, a model that has been pre-trained on general Chinese corpora. This is equivalent to having initialized weights. This means that the RoBERTa model can be directly used as a semantic encoding model after training on a large corpus of general corpora. Further training using samples can be performed directly on the RoBERTa model. RoBERTa primarily improves upon BERT (Bidirectional Encoder Representations from Transformers, word embeddings) with several adjustments: 1) longer training time, larger batch sizes, and more training data; 2) removal of the next predict loss; 3) longer training sequences; and 4) dynamic adjustment of the masking mechanism. Compared to BERT, RoBERTa incorporates numerous improvements and adjustments, including using more data for pre-training. Experiments have shown that this model outperforms BERT by 1%.
[0112] Figure 5 The following is a schematic diagram of the physical structure of an electronic device, which may include: a processor 510, a communication interface 520, a memory 530, and a communication bus 540. The processor 510, the communication interface 520, and the memory 530 communicate with each other via the communication bus 540. The processor 510 may call the logic instructions in the memory 530 to execute a structured query language statement generation method, which includes:
[0113] S1. Inputting natural language text and several table headers into a semantic encoding model, and outputting a joint representation of a structured query language clause and the table headers; wherein the semantic encoding model is trained based on structured text and table samples and predetermined target labels;
[0114] S2. generating candidate short sentences based on the natural language text and the query table;
[0115] S3. Inputting the natural language text and the candidate short sentence into a matching model, respectively, and outputting table values of the candidate short sentence that match the natural language text; wherein the matching model is trained based on labeled text and structured query language sentence samples and predetermined representation pairing labels;
[0116] S4. Concatenate the joint representation of the structured query language clause and the table header, and the table values in the candidate short sentences that match the natural language text to generate a structured query language statement.
[0117] In addition, the logic instructions in the above-mentioned memory 530 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the embodiment of the present disclosure is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present disclosure. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0118] In another aspect, an embodiment of the present disclosure further provides a computer program product, comprising a computer program stored on a non-transitory computer-readable storage medium, wherein the computer program comprises program instructions. When the program instructions are executed by a computer, the computer is capable of performing a structured query language statement generation method, the method comprising:
[0119] S1. Inputting natural language text and several table headers into a semantic encoding model, and outputting a joint representation of a structured query language clause and the table headers; wherein the semantic encoding model is trained based on structured text and table samples and predetermined target labels;
[0120] S2. generating candidate short sentences based on the natural language text and the query table;
[0121] S3. Inputting the natural language text and the candidate short sentence into a matching model, respectively, and outputting table values of the candidate short sentence that match the natural language text; wherein the matching model is trained based on labeled text and structured query language sentence samples and predetermined representation pairing labels;
[0122] S4. Concatenate the joint representation of the structured query language clause and the table header, and the table values in the candidate short sentences that match the natural language text to generate a structured query language statement.
[0123] In another aspect, an embodiment of the present disclosure further provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the computer program is implemented to perform a structured query language statement generation method, the method comprising:
[0124] S1. Inputting natural language text and several table headers into a semantic encoding model, and outputting a joint representation of a structured query language clause and the table headers; wherein the semantic encoding model is trained based on structured text and table samples and predetermined target labels;
[0125] S2. generating candidate short sentences based on the natural language text and the query table;
[0126] S3. Inputting the natural language text and the candidate short sentence into a matching model, respectively, and outputting table values of the candidate short sentence that match the natural language text; wherein the matching model is trained based on labeled text and structured query language sentence samples and predetermined representation pairing labels;
[0127] S4. Concatenate the joint representation of the structured query language clause and the table header, and the table values in the candidate short sentences that match the natural language text to generate a structured query language statement.
[0128] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, i.e., they may be located in one location or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of the present embodiment. Persons of ordinary skill in the art will be able to understand and implement the present invention without inventive effort.
[0129] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a necessary general hardware platform, or of course, by hardware. Based on this understanding, the essence of the above technical solution or the part that contributes to the existing technology can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or certain parts of the embodiments.
[0130] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present disclosure, rather than to limit them. Although the present disclosure 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 make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the various embodiments of the present disclosure.
Claims
1. A method for generating a structured query language statement, characterized in that: include: Inputting natural language text and several table headers from a query table into a semantic encoding model, and outputting a joint representation of a structured query language clause and the table headers; wherein the semantic encoding model is trained based on structured text and table samples and predetermined target labels; the semantic encoding model is trained through multiple subtasks, including six basic tasks and two auxiliary classification tasks; generating candidate phrases based on the natural language text and the query table; Inputting the natural language text and the candidate short sentences into a matching model respectively, and outputting table values of the candidate short sentences that match the natural language text; wherein the matching model is obtained by training based on labeled text and structured query language sentence samples and predetermined representation pairing labels; splicing the joint representation of the structured query language clause and the table header, and the table values in the candidate short sentences that match the natural language text to generate a structured query language statement; Generating candidate sentences based on the natural language text and the query table includes: Based on the natural language text, selecting a candidate unit in a query table, and selecting a table value corresponding to the candidate unit in the query table; The candidate units and the table values in the candidate short sentences that match the natural language text are sequentially concatenated to generate the candidate short sentences.
2. The method for generating a structured query language statement according to claim 1, wherein: The method of inputting the natural language text and several headers in the query table into the semantic encoding model and outputting the joint representation of the structured query language clause and the headers includes: Input the natural language text and several headers in the query table into the semantic encoding model, and output the joint representation of the structured query language clauses and the headers corresponding to several subtasks; The joint representations of the structured query language clauses and table headers corresponding to several subtasks are concatenated to form a joint representation of the structured query language clauses and table headers.
3. The method for generating a structured query language statement according to claim 1, wherein: The loss function used in the training process of the semantic coding model is: in, represents the predetermined generated target label, It represents the output result of semantic coding model training, and n1 represents the number of categories of the output result of semantic coding model.
4. The method for generating a structured query language statement according to claim 1, wherein: The loss function used by the matching model during training is: in, represents a predetermined characterization pairing label, It represents the output result of the matching model training, and n2 represents the number of classifications of the matching model output result.
5. A structured query language statement generation system, characterized in that: include: A semantic encoding module, configured to input natural language text and several table headers from a query table into a semantic encoding model, and output a joint representation of a structured query language clause and the table headers; wherein the semantic encoding model is trained based on structured text and table samples and predetermined target labels; the semantic encoding model is trained using multiple subtasks, including six basic tasks and two auxiliary classification tasks; a candidate short sentence generating module, configured to generate candidate short sentences based on the natural language text and the query table; a table value matching module, configured to input the natural language text and the candidate short sentence into a matching model, and output a table value in the candidate short sentence that matches the natural language text; wherein the matching model is trained based on labeled text and structured query language sentence samples and predetermined representation pairing labels; a concatenation module, configured to concatenate the joint representation of the structured query language clause and the table header, and the table values in the candidate short sentences that match the natural language text, to generate a structured query language statement; The candidate short sentence generation module is specifically used to: Based on the natural language text, selecting a candidate unit in a query table, and selecting a table value corresponding to the candidate unit in the query table; The candidate units and the table values in the candidate short sentences that match the natural language text are sequentially concatenated to generate the candidate short sentences.
6. The structured query language statement generation system according to claim 5, characterized in that: The semantic encoding module is specifically used for: Input the natural language text and several headers in the query table into the semantic encoding model, and output the joint representation of the structured query language clauses and the headers corresponding to several subtasks; The joint representations of the structured query language clauses and table headers corresponding to several subtasks are concatenated to form a joint representation of the structured query language clauses and table headers.
7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the steps of the structured query language statement generation method according to any one of claims 1 to 4 are implemented.
8. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for generating a structured query language statement according to any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Method for generating structured query statement based on natural language
CN111813802A