A NL2SQL data set construction method, device, equipment and medium
Through structural analysis and semantic expansion of the NL2SQL data set, combined with automation and manual verification, a high-quality NL2SQL data set is generated, which solves the problems of insufficient data coverage and low quality, and improves the performance and robustness of the model.
Patent Information
- Application Number
- CN202410962254.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-18
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2044-07-18
AI Technical Summary
It is difficult to build high-quality NL2SQL data sets. The data coverage is insufficient and the data quality is not high, resulting in poor model performance in unknown query patterns. Automatically generating data is costly and time-consuming, and manually generating data is difficult to implement on a large scale.
By obtaining the structural analysis results of the database to be processed, a seed data set is generated based on the preset large model and prompt project, and semantic expansion and statement verification are performed to form a target NL2SQL data set for model training. The data set is improved by combining automation and manual verification. accuracy and diversity.
It effectively reduces the difficulty of constructing NL2SQL data sets, improves the accuracy and diversity of the data sets, and improves the performance and robustness of the model, making it more accurate and efficient when facing various query tasks.
Smart Images

Figure CN118503270B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a method, device, equipment and medium for constructing an NL2SQL data set. Background Art
[0002] In the data governance industry, the conversion of natural language (NL) to SQL (Structured Query Language) (also known as NL2SQL) is a widely used link. By using the fine-tuning technology of large models, NL2SQL models can be trained for specific business scenarios to improve data query efficiency and better perform data governance. However, building a high-quality NL2SQL dataset is a challenge. In actual application scenarios, this task is particularly difficult, and the following problems currently exist:
[0003] 1. Insufficient data coverage: The constructed dataset may not cover all possible query scenarios, which causes the model to perform poorly when encountering unknown query patterns.
[0004] 2. Low data quality: Automatically generated data may contain errors, while manually generating data is costly and difficult to implement on a large scale, because sorting out questions and writing SQL statements requires not only expertise but also time-consuming and labor-intensive. Summary of the invention
[0005] In view of this, the purpose of the present invention is to provide a NL2SQL dataset construction method, device, equipment and medium, which can effectively reduce the difficulty of constructing the NL2SQL dataset, and improve the accuracy and diversity of the NL2SQL dataset, thereby effectively improving the performance and robustness of the model. The specific scheme is as follows:
[0006] In a first aspect, the present application provides a method for constructing an NL2SQL dataset, comprising:
[0007] Acquire the current database to be processed, and perform structural analysis on the database to be processed to obtain corresponding structural analysis results;
[0008] Generate a seed data set corresponding to the database to be processed based on the preset large model, the preset prompt project and the structural analysis result; wherein the seed data set includes a corresponding number of seed questions and target SQL statements corresponding to each of the seed questions;
[0009] Based on the preset large model and the preset prompt project, semantically expand each of the seed questions in the seed data set to obtain a corresponding expanded data set;
[0010] The expanded SQL statements corresponding to the expanded questions in the expanded data set are verified and screened through preset statement verification rules to obtain a target NL2SQL data set corresponding to the database to be processed, so as to complete a model training operation corresponding to the preset data processing model based on the target NL2SQL data set.
[0011] Optionally, completing a model training operation corresponding to a preset data processing model based on the target NL2SQL data set includes:
[0012] Constructing corresponding training sets and test sets using the target NL2SQL dataset by random sampling;
[0013] Based on the training set and the test set, corresponding model training and model evaluation are performed on the preset data processing model to obtain a corresponding target data processing model, so as to complete a corresponding query operation based on the target data processing model.
[0014] Optionally, performing structural analysis on the database to be processed to obtain corresponding structural analysis results includes:
[0015] By analyzing the tables, fields and the relationship between the two in the database to be processed, the corresponding structural analysis operation is completed to obtain the corresponding structural analysis results.
[0016] Optionally, the step of generating a seed data set corresponding to the database to be processed based on a preset large model, a preset prompting project and the structural analysis result includes:
[0017] In the process of understanding the structural analysis results based on the preset large model, the preset large model is guided by the preset prompt project to obtain a number of seed questions corresponding to the database to be processed and a target SQL statement corresponding to each seed question.
[0018] Optionally, after generating a seed data set corresponding to the database to be processed based on the preset large model, the preset prompt project and the structural analysis result, the method further includes:
[0019] By automatically selecting a plurality of the target SQL statements from the seed data set, a corresponding plurality of SQL statements to be checked are obtained;
[0020] By judging whether each of the SQL statements to be checked is executed successfully and whether the corresponding execution structure meets the corresponding preset expectations, the corresponding statement checking operation is completed, and the corresponding first statement judgment result is obtained;
[0021] When any of the first statement judgment results indicates that the corresponding SQL statement to be checked fails to execute or the corresponding execution structure does not meet the preset expectation, a corresponding statement modification operation is triggered to obtain the updated seed data set.
[0022] Optionally, the semantic expansion of each of the seed questions in the seed data set based on the preset large model and the preset prompt project to obtain a corresponding expanded data set includes:
[0023] In the process of analyzing and semantically understanding each of the seed questions in the seed data set based on the preset big model, the preset prompting project is used to guide the preset big model to generate a plurality of new questions corresponding to each of the seed questions, so as to obtain a plurality of expanded questions corresponding to each of the seed questions;
[0024] Semantic verification is performed on each of the expanded questions, and when it is determined that the semantic information of each of the expanded questions is consistent with the semantic information of the corresponding seed question, an expanded SQL statement corresponding to each of the expanded questions is generated to obtain a corresponding expanded data set.
[0025] Optionally, the method of verifying and screening the expanded SQL statements corresponding to the expanded questions in the expanded data set by using preset statement verification rules to obtain a target NL2SQL data set corresponding to the database to be processed includes:
[0026] For any expanded SQL statement in the expanded data set, obtaining a first statement execution result of the expanded SQL statement and a second statement execution result of the corresponding seed question;
[0027] By comparing whether the first statement execution result is consistent with the second statement execution result, a corresponding second statement judgment result is obtained;
[0028] When the second statement judgment result indicates that the first statement execution result is consistent with the second statement execution result, retaining the expanded SQL statement;
[0029] When the second statement judgment result indicates that the first statement execution result is inconsistent with the second statement execution result, the expanded SQL statement is deleted to obtain a target NL2SQL data set corresponding to the database to be processed.
[0030] In a second aspect, the present application provides a NL2SQL data set construction device, comprising:
[0031] A database analysis module is used to obtain the current database to be processed and perform structural analysis on the database to be processed to obtain corresponding structural analysis results;
[0032] A data set construction module, used to generate a seed data set corresponding to the database to be processed based on a preset large model, a preset prompt project and the structural analysis result; wherein the seed data set includes a corresponding number of seed questions and a target SQL statement corresponding to each of the seed questions;
[0033] A data set expansion module, used for semantically expanding each of the seed questions in the seed data set based on the preset large model and the preset prompt project to obtain a corresponding expanded data set;
[0034] The target data set acquisition module is used to verify and screen the expanded SQL statements corresponding to the expanded questions in the expanded data set through preset statement verification rules to obtain the target NL2SQL data set corresponding to the database to be processed, so as to complete the model training operation corresponding to the preset data processing model based on the target NL2SQL data set.
[0035] In a third aspect, the present application provides an electronic device, including:
[0036] Memory, used to store computer programs;
[0037] The processor is used to execute the computer program to implement the steps of the aforementioned NL2SQL data set construction method.
[0038] In a fourth aspect, the present application provides a computer-readable storage medium for storing a computer program, wherein the computer program implements the steps of the aforementioned NL2SQL dataset construction method when executed by a processor.
[0039] It can be seen that in the present application, the current database to be processed is obtained, and the structure analysis of the database to be processed is performed to obtain the corresponding structure analysis results; a seed data set corresponding to the database to be processed is generated based on the preset large model, the preset prompt project and the structure analysis results; wherein the seed data set includes a corresponding number of seed questions and target SQL statements corresponding to each of the seed questions; semantic expansion is performed on each of the seed questions in the seed data set based on the preset large model and the preset prompt project to obtain a corresponding expanded data set; the expanded SQL statements corresponding to the expanded questions in the expanded data set are verified and screened by the preset statement verification rules to obtain a target NL2SQL data set corresponding to the database to be processed, so as to complete the model training operation corresponding to the preset data processing model based on the target NL2SQL data set. That is, in this embodiment, the questions and corresponding SQL statements corresponding to the database to be processed are automatically generated by the preset large model, and semantic expansion is performed to obtain the corresponding expanded data set, and then the preset statement verification rules are used to perform corresponding inspections to obtain the target NL2SQL data set, so as to complete the model training using the target NL2SQL data set. That is, in this embodiment, the questions and corresponding SQL statements corresponding to the database to be processed are automatically generated by the preset large model, and the semantic expansion is performed to obtain the corresponding expanded data set, and then the preset statement verification rules are used to perform corresponding inspections to obtain the target NL2SQL data set, so as to complete the model training using the target NL2SQL data set. In this way, the difficulty of constructing the NL2SQL dataset can be effectively reduced, and the accuracy and diversity of the NL2SQL dataset can be improved, thereby effectively improving the performance and robustness of the model. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0041] Figure 1 A flow chart of a NL2SQL dataset construction method provided in this application;
[0042] Figure 2 A schematic diagram of a specific NL2SQL dataset construction method provided in this application;
[0043] Figure 3 A schematic diagram of the structure of an NL2SQL data set construction device provided in this application;
[0044] Figure 4 A structural diagram of an electronic device provided for this application. DETAILED DESCRIPTION
[0045] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0046] However, building a high-quality NL2SQL dataset is a challenge. In actual application scenarios, this task is particularly difficult, and the following problems currently exist: 1. Insufficient data coverage: The constructed dataset may not cover all possible query scenarios, which causes the model to perform poorly when encountering unknown query patterns. 2. Low data quality: Automatically generated data may contain errors, while manually generating data is costly and difficult to implement on a large scale. Because organizing problems and writing SQL statements requires not only professional knowledge, but also time-consuming and labor-intensive. To this end, the present application provides a NL2SQL dataset construction scheme that can effectively reduce the difficulty of building the NL2SQL dataset, and improve the accuracy and diversity of the NL2SQL dataset, thereby effectively improving the performance and robustness of the model.
[0047] See also Figure 1 As shown, the embodiment of the present invention discloses a method for constructing an NL2SQL data set, including:
[0048] Step S11, obtaining the current database to be processed, and performing structural analysis on the database to be processed to obtain corresponding structural analysis results.
[0049] Specifically, in this embodiment, when building an efficient data processing system, the generation of a seed data set is a crucial step. Prior to this, in order to more accurately generate a seed data set, it is necessary to first analyze the structure of the database, including tables, fields, and the relationship between them, so that these structures can be understood using a preset large model to complete the generation of the seed data set. That is, the structural analysis of the database to be processed to obtain the corresponding structural analysis results includes: by analyzing the tables, fields, and the relationship between the two in the database to be processed, completing the corresponding structural analysis operation to obtain the corresponding structural analysis results.
[0050] Step S12, generating a seed data set corresponding to the database to be processed based on the preset large model, the preset prompt project and the structural analysis result; wherein the seed data set includes a corresponding number of seed questions and a target SQL statement corresponding to each of the seed questions.
[0051] Specifically, in this embodiment, combined with Figure 2As shown, the seed data set corresponding to the database to be processed is generated based on the preset big model, the preset prompt project and the structural analysis results, including: in the process of understanding the structural analysis results based on the preset big model, the preset prompt project is used to guide the preset big model to obtain a number of seed questions corresponding to the database to be processed and a target SQL statement corresponding to each of the seed questions. That is, in this embodiment, a series of questions related to the database content are generated by the preset big model. These questions cover various possible query requirements, from simple data retrieval to complex joint queries and aggregation operations. In this process, the prompt project can guide the model to generate questions that are closer to actual business scenarios.
[0052] Further, in this embodiment, the generated questions and their corresponding SQL statements then enter the screening stage. At this stage, experienced data engineers will select 100-200 (the number is not specifically limited during the specific implementation, depending on the actual situation) typical query requirements in the most representative business scenarios from the many automatically generated query requirements. These typical query requirements can not only reflect the common functions of the database, but also ensure the diversity and wide applicability of the data set. That is, after the seed data set corresponding to the database to be processed is generated based on the preset large model, the preset prompt project and the structural analysis results, it also includes: by automatically selecting multiple target SQL statements from the seed data set, a corresponding plurality of SQL statements to be tested are obtained; by judging whether each of the SQL statements to be tested is executed successfully and whether the corresponding execution structure meets the corresponding preset expectations, the corresponding statement verification operation is completed, and the corresponding first statement judgment result is obtained; when any of the first statement judgment results indicates that the corresponding SQL statement to be tested fails to execute or the corresponding execution structure does not meet the preset expectations, the corresponding statement modification operation is triggered to obtain the updated seed data set. It can be understood that manual verification and modification links are key steps to ensure the correctness of SQL statements. In this phase, data engineers will carefully check the selected SQL statements to ensure that each statement can be executed correctly and get the expected results. If any errors or inaccuracies are found, they will be corrected immediately to ensure the quality of the data set. Through this combination of automation and manual verification, the seed data set generation module can efficiently generate high-quality data sets, laying a solid foundation for subsequent data processing and analysis. In this way, not only the efficiency of data processing is improved, but also the accuracy and reliability of the data are ensured, which is indispensable for any system that relies on database operations.
[0053] Step S13: semantically expand each of the seed questions in the seed data set based on the preset large model and the preset prompt project to obtain a corresponding expanded data set.
[0054] Specifically, in this embodiment, in order to increase the diversity of the data set and improve the depth and breadth of the model's semantic understanding, it is necessary to perform diversified semantic expansion on the questions in the seed data set through the method of the preset large model and the prompt project. That is, the semantic expansion of each of the seed questions in the seed data set based on the preset large model and the preset prompt project to obtain the corresponding expanded data set includes: in the process of problem analysis and semantic understanding of each of the seed questions in the seed data set based on the preset large model, the preset prompt project is used to guide the preset large model to generate multiple new questions corresponding to each of the seed questions to obtain multiple expanded questions corresponding to each of the seed questions; semantic verification is performed on each of the expanded questions, and when it is determined that the semantic information of each of the expanded questions is consistent with the semantic information of the corresponding seed question, an expanded SQL statement corresponding to each of the expanded questions is generated to obtain the corresponding expanded data set. It should be understood that when expanding the data set again, the preset large model is first used to conduct an in-depth analysis of each seed question in the seed data set to understand the semantic meaning behind it. Then, the preset large model is guided by the prompt engineering to generate multiple new questions that are semantically similar but expressed differently. These new questions not only retain the core semantics of the original questions, but also enrich the diversity of questions through different expressions. For example, for an original question "Query the sales in 2022", the model may generate questions with similar semantics but different expressions, such as "Count the total sales in 2022" or "Show last year's sales performance".
[0055] Step S14: verify and screen the expanded SQL statements corresponding to the expanded questions in the expanded data set through preset statement verification rules to obtain a target NL2SQL data set corresponding to the database to be processed, so as to complete a model training operation corresponding to the preset data processing model based on the target NL2SQL data set.
[0056] It should be understood that in this embodiment, after generating new questions, manual inspection and modification are still particularly critical. At this stage, professional data engineers will carefully review the expanded semantic questions to ensure that each new question is semantically consistent with the original question. If any problem deviating from the original semantics is found, they will make necessary modifications to ensure the semantic accuracy of the data set. That is, the expanded SQL statements corresponding to the expanded questions in the expanded data set are verified and screened by the preset statement verification rules to obtain the target NL2SQL data set corresponding to the database to be processed, including: for any expanded SQL statement in the expanded data set, obtaining the first statement execution result of the expanded SQL statement and the corresponding second statement execution result of the seed question; by comparing whether the first statement execution result is consistent with the second statement execution result, the corresponding second statement judgment result is obtained; when the second statement judgment result shows that the first statement execution result is consistent with the second statement execution result, the expanded SQL statement is retained; when the second statement judgment result shows that the first statement execution result is inconsistent with the second statement execution result, the expanded SQL statement is deleted to obtain the target NL2SQL data set corresponding to the database to be processed.
[0057] That is to say, in order to further improve the quality and diversity of the data set, an innovative method is used in this embodiment to verify and screen the expanded SQL statements. This process ensures that each generated expanded SQL statement is not only consistent with the seed question in semantics, but also completely correct in execution results. Specifically, after the expanded new question and its corresponding expanded SQL statement are generated by the preset large model and prompt engineering method, the query results of these expanded SQL statements will be compared with the target SQL statement of the corresponding seed question. Only when the query result of the generated expanded SQL statement is completely consistent with the query result of the target SQL statement of the seed question, the generated expanded SQL statement will be judged to be correct and retained as a candidate SQL statement of the original question group. In this way, each seed question will be expanded into a group of questions with multiple semantically similar but different expressions. Each question in each question group corresponds to multiple candidate SQL statements, which, although different in style and expression, can obtain the same database query results. This method not only increases the diversity and complexity of the data set, but also ensures the accuracy and reliability of the data set.
[0058] Furthermore, after the target NL2SQL data set is determined, the model is trained by constructing a corresponding training data set to complete the construction of an efficient data processing system. That is, the model training operation corresponding to the preset data processing model is completed based on the target NL2SQL data set, including: constructing a corresponding training set and a test set using the target NL2SQL data set by random sampling; performing corresponding model training and model evaluation on the preset data processing model based on the training set and the test set to obtain a corresponding target data processing model, so as to complete the corresponding query operation based on the target data processing model. That is to say, when constructing the training data set, a SQL statement is randomly extracted from the candidate SQL statements of each problem group as the corresponding SQL of the problem. This random extraction method ensures that the training data set has good diversity while maintaining a high degree of accuracy. This diversity is crucial to avoiding the problem of overfitting of the model during the training process, because it enables the model to be exposed to more diverse data, thereby improving the generalization ability of the model.
[0059] In this way, a diverse and accurate dataset can be constructed, which can not only improve the model's ability to understand semantics, but also help the model better generalize to unseen data, thus showing higher performance and adaptability in practical applications.
[0060] In summary, in this embodiment, 1) automatic generation of questions and corresponding SQL statements: the automatic generation of questions and their corresponding SQL statements is realized by presetting a large model, which not only significantly reduces the difficulty of manually organizing and writing SQL statements, but also greatly improves the generation efficiency. 2) Semantic expansion increases the diversity and complexity of the data set: the semantic understanding ability of the preset large model is used to semantically expand the generated natural language questions, and multiple new questions with similar semantics but different expressions are generated, which not only increases the diversity of the data set, but also increases the complexity of the data set, so that it can better cover various business scenarios and query requirements. This improvement in diversity and complexity is crucial for training more intelligent and generalized data processing models. 3) Improve model performance and robustness: The training set and test set constructed by this embodiment are not only highly accurate, but also have good diversity. This data set can effectively improve the performance of the model, so that it can be executed more accurately and efficiently when facing various query tasks. At the same time, the diversity of the data set also helps to improve the robustness of the model, so that it can maintain stable performance when encountering unseen queries or complex data structures.
[0061] It can be seen that in the embodiment of the present application, the current database to be processed is obtained, and the structure analysis of the database to be processed is performed to obtain the corresponding structure analysis results; based on the preset large model, the preset prompt project and the structure analysis results, a seed data set corresponding to the database to be processed is generated; wherein the seed data set includes a corresponding number of seed questions and target SQL statements corresponding to each of the seed questions; based on the preset large model and the preset prompt project, each of the seed questions in the seed data set is semantically expanded to obtain a corresponding expanded data set; the expanded SQL statements corresponding to the expanded questions in the expanded data set are verified and screened by the preset statement verification rules to obtain the target NL2SQL data set corresponding to the database to be processed, so as to complete the model training operation corresponding to the preset data processing model based on the target NL2SQL data set. That is, in this embodiment, the questions and corresponding SQL statements corresponding to the database to be processed are automatically generated by the preset large model, and the semantic expansion is performed to obtain the corresponding expanded data set, and then the preset statement verification rules are used to perform corresponding inspections to obtain the target NL2SQL data set, so as to complete the model training using the target NL2SQL data set. That is, in this embodiment, the questions and corresponding SQL statements corresponding to the database to be processed are automatically generated by the preset large model, and the semantic expansion is performed to obtain the corresponding expanded data set, and then the preset statement verification rules are used to perform corresponding inspections to obtain the target NL2SQL data set, so as to complete the model training using the target NL2SQL data set. In this way, the difficulty of constructing the NL2SQL dataset can be effectively reduced, and the accuracy and diversity of the NL2SQL dataset can be improved, thereby effectively improving the performance and robustness of the model.
[0062] See also Figure 3 As shown, the embodiment of the present application also discloses a NL2SQL data set construction device, including:
[0063] The database analysis module 11 is used to obtain the current database to be processed and perform structural analysis on the database to be processed to obtain corresponding structural analysis results;
[0064] A data set construction module 12 is used to generate a seed data set corresponding to the database to be processed based on a preset large model, a preset prompt project and the structural analysis result; wherein the seed data set includes a corresponding number of seed questions and a target SQL statement corresponding to each of the seed questions;
[0065] A data set expansion module 13, used for semantically expanding each of the seed questions in the seed data set based on the preset large model and the preset prompting project to obtain a corresponding expanded data set;
[0066] The target data set acquisition module 14 is used to verify and screen the expanded SQL statements corresponding to the expanded questions in the expanded data set through preset statement verification rules to obtain the target NL2SQL data set corresponding to the database to be processed, so as to complete the model training operation corresponding to the preset data processing model based on the target NL2SQL data set.
[0067] Among them, for more specific working processes of the above-mentioned modules, please refer to the corresponding contents disclosed in the aforementioned embodiments, which will not be repeated here.
[0068] It can be seen that in this application, the current database to be processed is obtained, and the structure analysis of the database to be processed is performed to obtain the corresponding structure analysis results; based on the preset large model, the preset prompt project and the structure analysis results, a seed data set corresponding to the database to be processed is generated; wherein the seed data set includes a corresponding number of seed questions and target SQL statements corresponding to each of the seed questions; semantic expansion is performed on each of the seed questions in the seed data set based on the preset large model and the preset prompt project to obtain a corresponding expanded data set; the expanded SQL statements corresponding to the expanded questions in the expanded data set are verified and screened by the preset statement verification rules to obtain the target NL2SQL data set corresponding to the database to be processed, so as to complete the model training operation corresponding to the preset data processing model based on the target NL2SQL data set. That is, in this embodiment, the questions and corresponding SQL statements corresponding to the database to be processed are automatically generated by the preset large model, and semantic expansion is performed to obtain the corresponding expanded data set, and then the preset statement verification rules are used to perform corresponding inspections to obtain the target NL2SQL data set, so as to complete the model training using the target NL2SQL data set. That is, in this embodiment, the questions and corresponding SQL statements corresponding to the database to be processed are automatically generated by the preset large model, and the semantic expansion is performed to obtain the corresponding expanded data set, and then the preset statement verification rules are used to perform corresponding inspections to obtain the target NL2SQL data set, so as to complete the model training using the target NL2SQL data set. In this way, the difficulty of constructing the NL2SQL dataset can be effectively reduced, and the accuracy and diversity of the NL2SQL dataset can be improved, thereby effectively improving the performance and robustness of the model.
[0069] In some specific embodiments, the target data set acquisition module 14 may specifically include:
[0070] A data set extraction unit, used to construct a corresponding training set and a test set using the target NL2SQL data set by random extraction;
[0071] The target model acquisition unit is used to perform corresponding model training and model evaluation on the preset data processing model based on the training set and the test set to obtain the corresponding target data processing model, so as to complete the corresponding query operation based on the target data processing model.
[0072] In some specific embodiments, the database analysis module 11 may specifically include:
[0073] The structure analysis result acquisition unit is used to complete the corresponding structure analysis operation by analyzing the tables, fields and the relationship between the two in the database to be processed, so as to obtain the corresponding structure analysis result.
[0074] In some specific embodiments, the data set construction module 12 may specifically include:
[0075] The data set construction unit is used to guide the preset big model by using the preset prompt project in the process of understanding the structural analysis results based on the preset big model, so as to obtain a number of seed questions corresponding to the database to be processed and a target SQL statement corresponding to each of the seed questions.
[0076] In some specific embodiments, the NL2SQL data set construction device may further include:
[0077] A statement selection unit, configured to automatically select a plurality of the target SQL statements from the seed data set to obtain a corresponding plurality of SQL statements to be checked;
[0078] A first statement judgment unit, used to complete a corresponding statement verification operation and obtain a corresponding first statement judgment result by judging whether each of the SQL statements to be verified is executed successfully and whether the corresponding execution structure meets the corresponding preset expectation;
[0079] A statement modification trigger unit is used to trigger a corresponding statement modification operation to obtain the updated seed data set when any of the first statement judgment results indicates that the corresponding SQL statement to be checked fails to execute or the corresponding execution structure does not meet the preset expectation.
[0080] In some specific embodiments, the data set expansion module 13 may specifically include:
[0081] A new question generating unit is used to guide the preset big model to generate a plurality of new questions corresponding to each of the seed questions by using the preset prompt engineering in the process of analyzing and understanding the semantics of each of the seed questions in the seed data set based on the preset big model, so as to obtain a plurality of expanded questions corresponding to each of the seed questions;
[0082] The SQL statement generation unit is used to perform semantic verification on each of the expanded questions, and when it is determined that the semantic information of each of the expanded questions is consistent with the semantic information of the corresponding seed question, generate an expanded SQL statement corresponding to each of the expanded questions to obtain a corresponding expanded data set.
[0083] In some specific embodiments, the target data set acquisition module 14 may specifically include:
[0084] A statement execution result acquisition unit, used for acquiring, for any expanded SQL statement in the expanded data set, a first statement execution result of the expanded SQL statement and a second statement execution result of the corresponding seed question;
[0085] A result comparison unit, used to obtain a corresponding second statement judgment result by comparing whether the first statement execution result is consistent with the second statement execution result;
[0086] A statement retaining unit, configured to retain the expanded SQL statement when the second statement judgment result indicates that the first statement execution result is consistent with the second statement execution result;
[0087] A statement deleting unit is used to delete the expanded SQL statement when the second statement judgment result indicates that the first statement execution result is inconsistent with the second statement execution result, so as to obtain a target NL2SQL data set corresponding to the database to be processed.
[0088] Furthermore, the present application also discloses an electronic device. Figure 4 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content in the diagram cannot be considered as any limitation on the scope of use of the present application.
[0089] Figure 4 The present invention provides a schematic diagram of the structure of an electronic device 20 provided in an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the NL2SQL data set construction method disclosed in any of the aforementioned embodiments. In addition, the electronic device 20 in this embodiment may specifically be an electronic computer.
[0090] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.
[0091] In addition, the memory 22, as a carrier for storing resources, can be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage method can be temporary storage or permanent storage.
[0092] The operating system 221 is used to manage and control the hardware devices and computer program 222 on the electronic device 20, which can be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program that can be used to complete the NL2SQL data set construction method performed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program that can be used to complete other specific tasks.
[0093] Furthermore, the present application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the aforementioned disclosed NL2SQL data set construction method is implemented. For the specific steps of the method, reference may be made to the corresponding contents disclosed in the aforementioned embodiments, and no further description will be given here.
[0094] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0095] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0096] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0097] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0098] The technical solution provided by the present application is introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technicians in this field, according to the idea of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A method for constructing an NL2SQL dataset, characterized in that: include: Acquire the current database to be processed, and perform structural analysis on the database to be processed to obtain corresponding structural analysis results; Generate a seed data set corresponding to the database to be processed based on the preset large model, the preset prompt project and the structural analysis result; wherein the seed data set includes a corresponding number of seed questions and target SQL statements corresponding to each of the seed questions; Based on the preset large model and the preset prompt project, semantically expand each of the seed questions in the seed data set to obtain a corresponding expanded data set; The expanded SQL statements corresponding to the expanded questions in the expanded data set are verified and screened through preset statement verification rules to obtain a target NL2SQL data set corresponding to the database to be processed, so as to complete a model training operation corresponding to the preset data processing model based on the target NL2SQL data set.
2. The NL2SQL dataset construction method according to claim 1, characterized in that: The completing a model training operation corresponding to a preset data processing model based on the target NL2SQL data set includes: Constructing corresponding training sets and test sets using the target NL2SQL dataset by random sampling; Based on the training set and the test set, corresponding model training and model evaluation are performed on the preset data processing model to obtain a corresponding target data processing model, so as to complete a corresponding query operation based on the target data processing model.
3. The NL2SQL dataset construction method according to claim 1, characterized in that: The performing structural analysis on the database to be processed to obtain corresponding structural analysis results includes: By analyzing the tables, fields and the relationship between the two in the database to be processed, the corresponding structural analysis operation is completed to obtain the corresponding structural analysis results.
4. The NL2SQL dataset construction method according to claim 1, characterized in that: The step of generating a seed data set corresponding to the database to be processed based on the preset large model, the preset prompting project and the structural analysis result includes: In the process of understanding the structural analysis results based on the preset large model, the preset large model is guided by the preset prompt project to obtain a number of seed questions corresponding to the database to be processed and a target SQL statement corresponding to each seed question.
5. The NL2SQL dataset construction method according to claim 1, characterized in that: After generating a seed data set corresponding to the database to be processed based on the preset large model, the preset prompt project and the structural analysis result, the method further includes: By automatically selecting a plurality of the target SQL statements from the seed data set, a corresponding plurality of SQL statements to be checked are obtained; By judging whether each of the SQL statements to be checked is executed successfully and whether the corresponding execution structure meets the corresponding preset expectations, the corresponding statement checking operation is completed, and the corresponding first statement judgment result is obtained; When any of the first statement judgment results indicates that the corresponding SQL statement to be checked fails to execute or the corresponding execution structure does not meet the preset expectation, a corresponding statement modification operation is triggered to obtain the updated seed data set.
6. The NL2SQL dataset construction method according to any one of claims 1 to 5, characterized in that: The semantic expansion of each of the seed questions in the seed data set based on the preset large model and the preset prompt project to obtain a corresponding expanded data set includes: In the process of analyzing and semantically understanding each of the seed questions in the seed data set based on the preset big model, the preset prompting project is used to guide the preset big model to generate a plurality of new questions corresponding to each of the seed questions, so as to obtain a plurality of expanded questions corresponding to each of the seed questions; Semantic verification is performed on each of the expanded questions, and when it is determined that the semantic information of each of the expanded questions is consistent with the semantic information of the corresponding seed question, an expanded SQL statement corresponding to each of the expanded questions is generated to obtain a corresponding expanded data set.
7. The NL2SQL dataset construction method according to claim 6, characterized in that: The method of verifying and screening the expanded SQL statements corresponding to the expanded questions in the expanded data set by using preset statement verification rules to obtain a target NL2SQL data set corresponding to the database to be processed includes: For any expanded SQL statement in the expanded data set, obtaining a first statement execution result of the expanded SQL statement and a second statement execution result of the corresponding seed question; By comparing whether the first statement execution result is consistent with the second statement execution result, a corresponding second statement judgment result is obtained; When the second statement judgment result indicates that the first statement execution result is consistent with the second statement execution result, retaining the expanded SQL statement; When the second statement judgment result indicates that the first statement execution result is inconsistent with the second statement execution result, the expanded SQL statement is deleted to obtain a target NL2SQL data set corresponding to the database to be processed.
8. A NL2SQL data set construction device, characterized in that: include: A database analysis module is used to obtain the current database to be processed and perform structural analysis on the database to be processed to obtain corresponding structural analysis results; A data set construction module, used to generate a seed data set corresponding to the database to be processed based on a preset large model, a preset prompt project and the structural analysis result; wherein the seed data set includes a corresponding number of seed questions and a target SQL statement corresponding to each of the seed questions; A data set expansion module, used for semantically expanding each of the seed questions in the seed data set based on the preset large model and the preset prompt project to obtain a corresponding expanded data set; The target data set acquisition module is used to verify and screen the expanded SQL statements corresponding to the expanded questions in the expanded data set through preset statement verification rules to obtain the target NL2SQL data set corresponding to the database to be processed, so as to complete the model training operation corresponding to the preset data processing model based on the target NL2SQL data set.
9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the NL2SQL dataset construction method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: Used to store a computer program, which, when executed by a processor, implements the NL2SQL dataset construction method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Adaptive rule-guided large language model generation SQL (Structured Query Language) system
CN117131070A
Method, device and equipment for converting natural language into SQL (Structured Query Language) and storage medium
CN118093646A
Medical insurance intelligent query method and system based on NL2SQL
CN118132579A
Data generation method, data generation device, computer equipment and storage medium
CN118277412A
Natural language data analysis, visualization and editing system
US11960500B1
