Human-in-the-loop text2sql iterative data labeling method for large model fusion

By employing an iterative data annotation method based on human loops, and utilizing expert analysis and reinforcement learning mechanisms, the static and diverse issues of data annotation in existing technologies are addressed, thereby improving the data quality and efficiency of converting natural language queries into structured query language.

CN120030034BActive Publication Date: 2025-11-11JOINT WARFARE COLLEGE NAT DEFENSE UNIV OF THE CHINESE PEOPLES LIBERATION ARMY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510059365.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-01-14
Publication Date
2025-11-11
Estimated Expiration
2045-01-14

AI Technical Summary

Technical Problem

Existing data annotation methods face challenges in converting natural language queries into structured query languages, such as the inability to dynamically annotate static training datasets and the lack of diversity in labeled data. This results in an inability to cover complex query scenarios and SQL query statements.

Method used

We employ a human-in-the-loop Text2SQL iterative data annotation method that integrates large models. We train a structured query generation model using a pre-built initial training dataset, extend the model with semantic diversity using a natural language query extension model, and combine expert analysis and reinforcement learning mechanisms for manual annotation and incremental training until the query results meet expectations.

Benefits of technology

It improves data quality and the generalization ability of the generated model in complex query scenarios, enhances the accuracy and efficiency of data annotation, and adapts to changing query scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120030034B_ABST
    Figure CN120030034B_ABST
Patent Text Reader

Abstract

This invention provides a human-in-the-loop Text2SQL iterative data annotation method that integrates large models. First, a generative model is trained and fine-tuned using pre-constructed manually annotated training samples. Then, an extended model is used to semantically diversify the training samples. Next, multiple extended training samples are input into the generative model to obtain a first SQL query. For each first SQL query, the model parameters of the extended model are assigned reward / penalty values ​​based on expert analysis results and reinforcement learning mechanisms to determine the target training sample. This sample is then manually annotated, and the results are used to incrementally train the generative model to obtain a second SQL query. When the verification result of the second SQL query does not meet the query expectations, the target training samples are repeatedly manually annotated until the verification result meets the query expectations. This method improves the efficiency of data annotation through human-computer collaboration and reinforcement learning.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of artificial intelligence technology, and in particular relates to a human-in-the-loop Text2SQL iterative data annotation method for integrating large models. Background Technology

[0002] With the continuous development and application of artificial intelligence (AI) technology, data annotation has become a crucial aspect of AI development. Especially in the task of converting Natural Language Query (NLQ) to Structured Query Language (SQL) (i.e., the Text2SQL task), existing data annotation methods face several challenges and problems. For example, current data annotation methods mostly obtain static training datasets, making dynamic annotation impossible; secondly, the labeled data lacks diversity, resulting in an inability to cover all possible complex query scenarios and complex SQL query statements.

[0003] Therefore, based on the above problems, there is an urgent need to propose a data annotation method based on human-computer collaboration to improve annotation efficiency in complex query scenarios. Summary of the Invention

[0004] In order to at least solve one or more of the technical problems mentioned above, this invention proposes a human-in-the-loop Text2SQL iterative data annotation scheme in several aspects.

[0005] In a first aspect, embodiments of the present invention provide a human-in-the-loop Text2SQL iterative data annotation method that integrates large models. This method includes training and fine-tuning a structured query generation model to be trained using a pre-constructed initial training dataset to obtain a trained structured query generation model. The initial training dataset includes multiple training sample pairs, each pair including a natural language query training sample and an annotated structured query statement corresponding to the natural language query training sample. The annotated structured query statement is obtained through manual annotation. The trained natural language query extension model is used to perform semantic diversification extensions on each natural language query training sample to obtain multiple extended training samples corresponding to each natural language query training sample. The multiple extended training samples are input into the structured query generation model to obtain a first structured query statement corresponding to each extended training sample. The process involves several steps: For each first structured query statement, the model parameters of the natural language query extension model are assigned reward / penalty values ​​based on expert analysis and reinforcement learning mechanisms. The extended training samples corresponding to the first structured query statement receiving reward feedback are then used as target training samples. These target training samples are manually annotated to obtain annotated structured query statements. Based on the target training samples and the corresponding annotated structured query statements, the structured query statement generation model is incrementally trained to obtain second structured query statements corresponding to the target training samples. If the verification result of the second structured query statement indicates that the query result does not meet the query expectations, the process returns to the step of manually annotating the target training samples and continues until the verification result indicates that the query result of the second structured query statement meets the query expectations, at which point the loop stops.

[0006] In some embodiments, for each first structured query statement, the model parameters of the natural language query expansion model are assigned reward and penalty values ​​based on expert analysis results and reinforcement learning mechanisms, including: determining whether the first structured query statement meets the query requirements; when it is determined that the first structured query statement meets the query requirements, assigning penalty feedback values ​​to the model parameters of the natural language query expansion model; or, when it is determined that the first structured query statement does not meet the query requirements, assigning reward feedback values ​​to the model parameters of the natural language query expansion model, thereby determining the expanded training samples corresponding to the first structured query statement that does not meet the query requirements as target training samples; using the natural language query expansion model to perform semantic diversification expansion on the target training samples to obtain multiple unlabeled target training samples corresponding to the target training samples; and updating the multiple unlabeled target training samples as new target training samples.

[0007] In some embodiments, incremental training of a structured query generation model is performed based on target training samples and labeled structured query statements corresponding to the target training samples. This includes: constructing an incremental training dataset based on new target training samples and labeled structured query statements corresponding to the new target training samples; and incrementally training the structured query generation model using the incremental training dataset to obtain an optimized structured query generation model and a second structured query statement corresponding to each new target training sample.

[0008] In some embodiments, when the verification result of the second structured query statement indicates that the query result of executing the second structured query statement does not meet the query expectation, the process returns to the step of manually annotating the target training samples and continues processing until the verification result indicates that the query result of executing the second structured query statement meets the query expectation and the loop stops. This includes: querying the second structured query statement using a professional database to obtain the query result corresponding to the second structured query statement; verifying whether the query result meets the query expectation and obtaining the verification result; when the verification result indicates that the query result does not meet the query expectation, marking the target training sample corresponding to the second structured query statement as a new target training sample; and returning to the step of manually annotating the target training samples and continuing processing until the verification result indicates that the second structured query statement meets the query expectation.

[0009] In some embodiments, manually labeling the target training samples includes: for each target training sample, obtaining the labeling structured query statement corresponding to the target training sample; and establishing a mapping relationship between the target training samples and the labeling structured query statement corresponding to the target training samples.

[0010] In some embodiments, the natural language query extension model is a deep learning model based on the Transformer architecture.

[0011] In some embodiments, the structured query generation model is a deep learning model based on the Transformer architecture.

[0012] The present invention provides a human-in-the-loop Text2SQL iterative data annotation method for a fusion large model. This method includes: training and fine-tuning a structured query generation model (i.e., SQL generation model) using a pre-constructed initial training dataset to obtain a trained structured query generation model; then, using a trained natural language query extension model (i.e., NLQ extension model) to perform semantic diversification extensions on each natural language query training sample, resulting in multiple extended training samples corresponding to each natural language query training sample; inputting these multiple extended training samples into the SQL generation model to obtain a first SQL query statement corresponding to each extended training sample; and for each first SQL query statement, adjusting the N... based on expert analysis results and a reinforcement learning mechanism. The LQ extended model assigns reward and penalty values ​​to its model parameters to determine the extended training sample corresponding to the first SQL query statement that receives reward feedback as the target training sample. The target training sample is manually annotated to obtain an annotated SQL query statement corresponding to it. Based on the target training sample and the annotated SQL query statement, the SQL generation model is incrementally trained to obtain a second SQL query statement corresponding to the target training sample. If the verification result of the second SQL query statement indicates that the query result does not meet the query expectation, the process returns to the step of manually annotating the target training sample and continues until the verification result indicates that the query result of the second SQL query statement meets the query expectation, at which point the loop stops. The technical solution provided by this invention uses human-in-loop technology for dynamic iterative annotation. Based on expert analysis results and reinforcement learning mechanisms, it improves the data quality of natural language query text generated by the natural language query extended model for complex query scenarios. Manual annotation of semantically similar extended training samples, and incremental training of the generation model using the manually annotated results, can further optimize the generation model and improve its generalization ability in handling complex queries. Simultaneously, verifying the second SQL query statement generated during incremental training can improve the accuracy of data annotation. Attached Figure Description

[0013] Other features, objects, and advantages of the present invention will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings:

[0014] Figure 1 This is a schematic flowchart of a human-in-the-loop Text2SQL iterative data annotation method 100 according to an embodiment of the present invention;

[0015] Figure 2 A schematic flowchart of step S104 is shown for some other embodiments of the present invention;

[0016] Figure 3A schematic flowchart of a human-in-loop Text2SQL iterative data annotation method 300 for fusion of large models according to other embodiments of the present invention is shown;

[0017] Figure 4 This is a schematic diagram of the structure of a human-in-the-loop Text2SQL iterative data annotation device 400 according to an embodiment of the present invention;

[0018] Figure 5 A schematic block diagram of an electronic device 500 according to an embodiment of the present invention is shown.

[0019] The same or similar reference numerals in the accompanying drawings represent the same or similar parts. Detailed Implementation

[0020] To better understand and explain this invention, a further detailed description will be provided below with reference to the accompanying drawings. This invention is not limited to these specific embodiments. Rather, any modifications or equivalent substitutions made to this invention should be covered within the scope of the claims.

[0021] It should be noted that numerous specific details are provided in the following detailed embodiments. Those skilled in the art should understand that the present invention can be practiced without these specific details. In the various detailed embodiments given below, principles, structures, and components well known in the art are not described in detail in order to highlight the spirit of the invention.

[0022] The human-in-the-loop Text2SQL iterative data annotation method for large-scale fusion models provided by this invention can be executed by a computer device, which can be a terminal or a server. The terminal can be a smartphone, tablet, laptop, touchscreen, personal computer (PC), personal digital assistant (PDA), or other similar device, and may also include a client. The server can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms.

[0023] Please refer to Figure 1 , Figure 1 This is a schematic flowchart of a human-in-the-loop Text2SQL iterative data annotation method 100 according to an embodiment of the present invention. Figure 1 As shown, the method includes:

[0024] In step S101, the structured query generation model to be trained is trained and fine-tuned using a pre-constructed initial training data set to obtain a trained structured query generation model. The initial training data set includes multiple training sample pairs. Each training sample pair includes a natural language query training sample and a labeled structured query statement corresponding to the natural language query training sample. The labeled structured query statement is obtained through manual annotation.

[0025] In the above steps, the natural language query training samples are samples of natural language query text. Natural language query text refers to a user's query request for a database in natural language form. For example, it can represent an NLP sample. The labeled structured query statement corresponding to the natural language query training samples refers to the structured query statement (i.e., SQL query statement) obtained by manually labeling the NLP samples. Training sample pairs can be represented as (NLP, SQL). The initial training dataset includes multiple training sample pairs and can be represented as {(NLP0, SQL0), (NLP1, SQL1), (NLP2, SQL2), (NLP3, SQL3), ..., (NLP...} N SQL N The natural language query training samples are manually selected by domain experts. The corresponding SQL query statements are manually written and annotated. The annotators can be experts in the relevant domain.

[0026] For example, in a database query scenario, experts selected the following typical natural language queries: "Query the total number of employees in each department," and "Compare the number of employees in the sales department and the finance department." For these natural language queries, the corresponding SQL query statements are annotated. For "Query the total number of employees in each department," the annotated SQL query statement is:

[0027] SELECT department_name,COUNT(employee_id)AS total_count

[0028] FROM employees

[0029] GROUP BY department_name;

[0030] The SQL query statement for "comparing the number of employees in the sales and finance departments" is as follows:

[0031] SELECT department_name,COUNT(employee_id)AS total_count

[0032] FROM employees

[0033] WHERE department_name IN('Sales','Finance')

[0034] GROUP BY department_name;

[0035] These labeled data were organized into a standard format and used as a preliminary training data set.

[0036] Structured query generation models can be deep learning models based on the Transformer architecture. Examples include large language models and open-source large models. Basic open-source large models include Qwen and Lamma. For instance, based on an initial training dataset, standard large language model fine-tuning methods are used to train a basic open-source large model, enabling it to learn the mapping rules from NLQ to SQL queries. During the training phase, the model can gradually master the syntactic structure and semantic information of natural language, as well as the rules for generating SQL statements.

[0037] Given the natural language query training sample "Query the total number of employees in each department", the structured query generation model, after training, generates the corresponding SQL query statement as follows:

[0038] SELECT department_name,COUNT(employee_id)AS total_count

[0039] FROM employees

[0040] GROUP BY department_name;

[0041] The pre-trained structured query generation model can generate SQL queries based on given natural language query training samples. During the training phase, although the model can generate basic SQL queries, the limited size of the training dataset means that some generated queries may contain syntax errors, incomplete query logic, or be inconsistent with actual business needs. For example, for a more complex query, such as "compare the number of employees in the sales department and the finance department," the trained structured query generation model might generate the following incorrect SQL query:

[0042] SELECT department_name,employee_count

[0043] FROM employees

[0044] WHERE department_name IN('Sales','Finance')

[0045] GROUP BY department_name;

[0046] The SQL query lacks the COUNT() function, causing it to fail to correctly count the number of employees. This means the query results may not meet the query requirements.

[0047] In step S102, the trained natural language query expansion model is used to perform semantic diversification expansion on each natural language query training sample to obtain multiple expanded training samples corresponding to each natural language query training sample.

[0048] In the steps described above, the Natural Language Query Expansion Model (NLEEM) is used to semantically diversify the natural language query training samples. The NLEEM can be a deep learning model based on the Transformer architecture, such as a large language model or an open-source large model. Semantic diversification involves generating diverse natural language query samples through the NLEEM. These samples can cover different query patterns, such as single-table queries, multi-table joins, and nested queries, and involve scenarios with varying query complexities. The generated natural language query samples are then fed into the structured query generation model trained in the preceding steps to generate SQL query statements. The structured query generation model is then optimized through expert review and reinforcement learning mechanisms.

[0049] Each natural language query training sample is diversified and expanded to obtain multiple expanded training samples corresponding to each natural language query training sample. For example, a natural language query (NLQ) could be: "Query the comparison of the number of employees in each department in different quarters between January 1, 2023 and December 31, 2023, and calculate the difference in the number of employees in each department in each quarter." This semantic diversification expansion generates self-expanding training samples that can cover more similar query needs, such as: "Query the comparison of the number of employees in all departments in each quarter of 2023 and calculate the difference," "Get the changes in the number of employees in each department in each quarter of 2023 and display the difference in the number of employees," and "Calculate the number of employees in each department in each quarter based on a time period and calculate the difference in the number of employees in each quarter."

[0050] In step S103, multiple extended training samples are input into the structured query statement generation model to obtain a first structured query statement corresponding to each of the extended training samples.

[0051] In step S104, for each first structured query statement, the model parameters of the natural language query extension model are assigned reward and penalty values ​​based on the expert analysis results and reinforcement learning mechanism, so as to determine the extended training sample corresponding to the first structured query statement that is given reward feedback as the target training sample.

[0052] In the above steps, experts can review the first structured query statement based on the actual query requirements of natural language queries, and a reinforcement learning mechanism is introduced for supervision and recording. The first structured query statement is the SQL query statement generated by the structured query statement generation model that corresponds to the extended training samples. If the generated SQL query statement meets the query requirements, the reinforcement learning mechanism will assign a penalty to reduce the probability of generating that SQL query statement, prompting the model to improve its generation ability. If the generated SQL query statement does not meet the query requirements, the reinforcement learning mechanism will assign a reward to encourage the natural language query extension model to continue generating high-quality extended training samples that meet the query requirements. Extended training samples are natural language query texts that have the same semantics as the natural language training samples but different language expressions.

[0053] Target training samples refer to natural language query texts that contain complex query logic (such as cross-table queries, multi-table joins, nested queries, etc.) and cannot generate correct structured query statements during the training and fine-tuning phase of the structured query generation model. Target training samples can also be called "query-hard samples".

[0054] In step S105, the target training samples are manually labeled to obtain the labeled structured query statements corresponding to the target training samples.

[0055] In step S106, the structured query statement generation model is incrementally trained based on the target training sample and the labeled structured query statement corresponding to the target training sample to obtain the second structured query statement corresponding to the target training sample.

[0056] In the above steps, the target training samples are manually labeled by annotation experts. For example, annotation experts can write SQL query statements corresponding to the target training samples based on actual business needs and database structure, i.e., obtain the SQL query statements corresponding to the target training samples, and then establish a mapping relationship between the target training samples and the SQL query statements, thus completing the annotation. The SQL query statements corresponding to the target training samples are then called labeled structured query statements.

[0057] After expert annotation specialists manually annotate multiple target training samples one by one, a new training dataset is obtained. Using this new training dataset, the structured query generation model is incrementally trained, generating SQL queries that correspond one-to-one with the multiple target training samples. These SQL queries corresponding to the target training samples are called the second structured query statements.

[0058] Through the incremental training process described above, the ability of the structured query generation model to handle complex queries can be effectively improved.

[0059] In step S107, when the verification result of the second structured query statement indicates that the query result of executing the second structured query statement does not meet the query expectation, the process returns to the step of manually annotating the target training samples and continues until the verification result indicates that the query result of executing the second structured query statement meets the query expectation and the loop stops.

[0060] In the above steps, the second structured query statement generated during incremental training is validated using a business database or a professional database. If the query result of the second structured query statement meets the user's query expectations, the target training sample and the second structured query statement are output as annotation results. If the query result of the second structured query statement does not meet the user's query expectations, the process returns to the step of annotating the target training sample. Annotation experts analyze and correct the second generated SQL query statement to obtain a corrected second generated SQL query statement. The corrected second generated SQL query statement is then validated using a professional database. If the query result of the second generated SQL query statement meets the query expectations, a mapping relationship is established between the target training sample and the corrected second generated SQL query statement, resulting in new training data pairs.

[0061] This invention proposes a human-in-the-loop Text2SQL iterative data annotation method that integrates large-scale models. It utilizes a pre-constructed initial training dataset to train a structured query generation model, and then uses a natural language query extension model to semantically expand the natural language query training samples, improving the generalization ability for complex queries. Furthermore, based on expert analysis and reinforcement learning mechanisms, it enhances the data quality of natural language query text generated by the natural language query extension model for complex query scenarios. Manual annotation of semantically expanded training samples, followed by incremental training using these expanded training samples, improves the query generation model's ability to handle complex queries. Validation with a second SQL query improves the accuracy and consistency of the data annotation results. In summary, by applying reinforcement learning to iterative annotation in a human-in-the-loop manner, this approach effectively improves the efficiency and accuracy of data annotation.

[0062] Figure 2 A schematic flowchart relating to step S104 of some other embodiments of the present invention is shown. It will be understood that... Figure 2 The steps S2041-S2045 shown are a specific implementation of the aforementioned step S104, therefore the preceding text Figure 1 The relevant characteristics described can be similarly applied here. For example... Figure 2 As shown, the method includes:

[0063] In step S2041, it is determined whether the first structured query statement meets the query requirements.

[0064] In step S2042, when it is determined that the first structured query statement meets the query requirements, a penalty feedback value is assigned to the model parameters of the natural language query extension model.

[0065] In step S2043, when it is determined that the first structured query statement does not meet the query requirements, a reward feedback value is given to the model parameters of the natural language query extension model so as to determine the extended training sample corresponding to the first structured query statement that does not meet the query requirements as the target training sample.

[0066] In step S2044, the target training samples are semantically diversified by using a natural language query expansion model to obtain multiple unlabeled target training samples corresponding to the target training samples.

[0067] In step S2045, multiple unlabeled target training samples are updated to new target training samples.

[0068] In the steps described above, determining whether an SQL query meets the query requirements can be evaluated from multiple perspectives. For example, query requirements can include factors used to achieve the query, such as the query objective, filtering conditions, aggregate functions, sorting, and grouping. The query objective can be a specific data object to be queried, such as querying sales data for a specific time period or querying product inventory in a specific region. Filtering conditions are used to limit the range of query results, such as time range, geographical restrictions, product categories, etc. By narrowing the range of query results, the relevance of the results can be ensured. Whether the aggregate functions match the natural language query can be considered; for example, the SQL aggregate functions for statistical analysis of the data can be determined through analysis of the natural language query text. SQL aggregate functions include, but are not limited to, summation, counting, and averaging. Sorting and grouping can be used to sort or group the results as needed for analysis or presentation.

[0069] After clarifying the above query requirements, determine whether the SQL query statement meets those requirements. This involves checking whether each component of the SQL query statement, such as SELECT, FROM, WHERE, GROUP BY, and ORDER BY, is used correctly to ensure the accuracy and efficiency of the query results.

[0070] The Natural Language Query Extension Model generates multiple semantically equivalent Natural Language Query Samples (i.e., extended training samples). These Natural Language Query Samples can cover a variety of scenarios, from simple to complex (such as cross-table joins and nested queries). The generated semantically equivalent Natural Language Query Samples are then input into a trained Structured Query Generation Model to generate SQL query statements corresponding to the extended training samples.

[0071] Annotation experts review the SQL queries corresponding to the expanded training samples based on the query requirements of natural language queries, and a reinforcement learning mechanism is introduced for supervision and recording. If the SQL queries corresponding to the expanded training samples meet the query requirements, the reinforcement learning mechanism will penalize them, which can be done by assigning penalty feedback values ​​to the model parameters of the natural language query expansion model. If the SQL queries corresponding to the expanded training samples do not meet the query requirements, the reinforcement learning mechanism will reward them, i.e., reward feedback values ​​will be assigned to the model parameters of the natural language query expansion model, to determine the expanded training samples corresponding to the SQL queries that do not meet the query requirements as target training samples. Through the reinforcement learning mechanism, the natural language query expansion model is encouraged to continue generating natural language query text that meets the query requirements.

[0072] Through the reinforcement learning mechanism described above, the ability of the natural language query extension model to generate natural language query question samples that conform to complex query scenarios can be improved.

[0073] Suppose the natural language query text is: "Query the number of employees in each department in different quarters from January 1, 2023 to December 31, 2023, and calculate the difference in the number of employees in each department in each quarter." This natural language query text involves the following key points: it needs to obtain data from multiple tables (such as employees, departments, and orders), which involves cross-table queries; the query conditions involve date range filtering; and it needs to calculate and compare the number of employees in each quarter, which involves complex aggregation operations.

[0074] The SQL query generated by the structured query generation model is as follows:

[0075] SELECT department_name,quarter,COUNT(employee_id)AS total_count

[0076] FROM employees

[0077] WHERE hi re_date BETWEEN'2023-01-01'AND'2023-12-31'

[0078] GROUP BY department_name,quarter;

[0079] The generated SQL query statement is considered to not meet the query requirements. For example, the SQL query statement does not include the requirement expression parameter corresponding to "the difference in the number of employees in each department"; the SQL query statement does not include the requirement expression parameter for calculating "the difference in the number of employees in each department each quarter".

[0080] Annotation experts discovered that the generated SQL queries did not meet the query requirements, especially lacking the parameter to express the requirement of "statistics on the differences in the number of employees in each department." Reinforcement learning mechanisms can reward these queries, providing feedback values ​​so that the natural language query expansion model can generate more natural language query samples that cover similar query requirements. When the generated SQL queries do not meet the actual query requirements of the natural language query text, reinforcement learning mechanisms can be used to reward the model parameters of the natural language query expansion model, encouraging it to generate multiple natural language query texts to cover the query requirements, thereby improving its adaptability to complex query scenarios.

[0081] The human-in-the-loop Text2SQL iterative data annotation method provided by this invention dynamically increases training samples through expert review and reinforcement learning mechanisms. While ensuring data quality, it reduces the time cost of constructing natural language expression samples of complex queries and corresponding SQL query statements, and significantly improves data annotation efficiency.

[0082] Figure 3 This is a schematic flowchart of a human-in-the-loop Text2SQL iterative data annotation method 300 for fusing large models according to an embodiment of the present invention. It can be understood that... Figure 3 The steps S3071-S3075 shown are a specific implementation of the aforementioned step S107, therefore the preceding text Figure 1 The relevant characteristics described can be similarly applied here. For example... Figure 3 As shown, the method includes:

[0083] In step S301, the structured query generation model to be trained is trained and fine-tuned using a pre-constructed initial training data set to obtain a trained structured query generation model. The initial training data set includes multiple training sample pairs. Each training sample pair includes a natural language query training sample and a labeled structured query statement corresponding to the natural language query training sample. The labeled structured query statement is obtained through manual annotation.

[0084] In step S302, the trained natural language query expansion model is used to expand each natural language query training sample in a variety of ways to obtain multiple expanded training samples corresponding to each natural language query training sample.

[0085] In step S303, multiple extended training samples are input into the structured query statement generation model to obtain a first structured query statement corresponding to each of the extended training samples.

[0086] In step S304, for each first structured query statement, the model parameters of the natural language query extension model are assigned reward and penalty values ​​based on the expert analysis results and reinforcement learning mechanism, so as to determine the extended training sample corresponding to the first structured query statement that is given reward feedback as the target training sample.

[0087] In step S305, the target training samples are manually labeled to obtain the labeled structured query statements corresponding to the target training samples.

[0088] In step S306, the structured query statement generation model is incrementally trained based on the target training sample and the labeled structured query statement corresponding to the target training sample to obtain the second structured query statement corresponding to the target training sample.

[0089] In step S3071, the second structured query statement is queried using a professional database to obtain the query results corresponding to the second structured query statement.

[0090] In step S3072, the query results are verified to see if they meet the expected query results.

[0091] In step S3073, when the verification result indicates that the query result does not meet the query expectation, the target training sample corresponding to the second structured query statement is marked as a new target training sample, and then step S3074 is executed.

[0092] In step S3074, return to step S105 to continue processing until the verification result indicates that the second structured query statement meets the query expectation, and then stop the loop.

[0093] In step S3075, if the verification result indicates that the query result meets the query expectations, it means that the generation capability of the optimized structured query generation model obtained through incremental training does not need to be dynamically adjusted. The optimized structured query generation model can be directly applied to business scenarios for continued use.

[0094] In the steps described above, query expectation refers to the desired result set based on query requirements before executing a database query. For example, the result obtained by executing a specific SQL query. Query expectations may include, but are not limited to: expecting the query results to accurately reflect the information stored in the database, without omissions or errors; expecting the query to return all data records that meet the query conditions, neither more nor less; and expecting the query logic to be consistent with business logic, such as using aggregate functions correctly and ensuring correct grouping and sorting logic when performing statistical summaries. Verification can be achieved through comparative analysis, such as comparing the actual query results with the query expectation to analyze whether there are any differences and their causes.

[0095] The SQL queries generated by the incrementally trained structured query generation model are then fed into a professional database for practical query validation. If the SQL query executes correctly and returns the expected results, the model's generation capability has improved and it can continue to be used. If the SQL query executes correctly but the returned results do not meet expectations, the corresponding target training sample is marked as a "hard sample." These "hard samples" are then returned to the manual annotation step for expert annotation, where they are corrected and re-annotated. The expert annotator reviews the SQL query and its corresponding natural language query text, identifies the causes of problems, and corrects them to generate correct SQL queries. Subsequently, these corrected SQL queries and their corresponding natural language query texts can be used as new incremental datasets for incremental training of the structured query generation model. Through repeated correction and feedback, the structured query generation model's ability to handle complex query scenarios can be improved, meeting diverse query needs and generating SQL queries accurately and efficiently.

[0096] For example, if the generated SQL query is "Query the number of employees in each department during a certain quarter," and the returned query results do not match the actual data, it indicates a problem with the query logic. In this case, the generated SQL query is marked as a "hard sample," and the process is returned to the step of manually annotating the target training samples. The annotation expert reviews the generated SQL query again and finds that the filtering conditions for the quarterly data are incorrectly expressed. The annotation expert corrects the generated SQL query, resulting in the corrected SQL query:

[0097] SELECT department_name,COUNT(employee_id)AS total_count

[0098] FROM employees

[0099] WHERE quarter = 'correct quarter'

[0100] GROUP BY department_name;

[0101] This invention proposes a human-in-the-loop Text2SQL iterative data annotation method that integrates large models. Through reinforcement learning and dynamic feedback mechanisms, it overcomes the shortcomings of existing technologies in handling complex queries, multi-domain adaptability, and data annotation efficiency, effectively improving the data quality of natural language query text generated by the natural language query extension model for complex query scenarios. Manual annotation of semantically equivalent extended training samples, followed by incremental training of the generative model using the manually annotated results, further optimizes the model and enhances its generalization ability for handling complex queries. Simultaneously, validation of the second SQL query statement generated during incremental training improves the accuracy of data annotation.

[0102] In summary, the human-in-the-loop Text2SQL iterative data annotation method that integrates large models significantly improves the flexibility, adaptability, and accuracy of data annotation.

[0103] Please refer to Figure 4 , Figure 4 This is a schematic diagram of the structure of a human-in-the-loop Text2SQL iterative data annotation device 400 according to an embodiment of the present invention. Figure 4 As shown, the device includes:

[0104] The model training and fine-tuning module 401 is configured to train and fine-tune the structured query generation model to be trained using a pre-built initial training dataset to obtain a trained structured query generation model. The initial training dataset includes multiple training sample pairs, each of which includes a natural language query training sample and a labeled structured query statement corresponding to the natural language query training sample. The labeled structured query statement is obtained through manual annotation.

[0105] The sample diversification extension module 402 is configured to use the trained natural language query extension model to perform semantic diversification extension on each natural language query training sample, so as to obtain multiple extended training samples corresponding to each natural language query training sample.

[0106] The query statement generation module 403 is configured to input multiple extended training samples into the structured query statement generation model to obtain a first structured query statement corresponding to each extended training sample.

[0107] The expert reinforcement learning module 404 is configured to assign reward and penalty values ​​to the model parameters of the natural language query extension model for each first structured query statement based on expert analysis results and reinforcement learning mechanism, so as to determine the extended training sample corresponding to the first structured query statement that is given reward feedback as the target training sample.

[0108] The manual annotation module 405 is configured to manually annotate the target training samples and obtain the annotated structured query statement corresponding to the target training samples.

[0109] The incremental training module 406 is configured to incrementally train the structured query statement generation model based on the target training sample and the labeled structured query statement corresponding to the target training sample, so as to obtain the second structured query statement corresponding to the target training sample.

[0110] The query statement verification module 407 is configured to return to the step of manually annotating the target training samples when the verification result of the second structured query statement indicates that the query result of executing the second structured query statement does not meet the query expectations, and continue processing until the verification result indicates that the query result of executing the second structured query statement meets the query expectations and the loop stops.

[0111] In some embodiments, the expert reinforcement learning module 404 is configured to: determine whether a first structured query statement satisfies the query requirement; when it is determined that the first structured query statement satisfies the query requirement, assign a penalty feedback value to the model parameters of the natural language query expansion model; or, when it is determined that the first structured query statement does not satisfy the query requirement, assign a reward feedback value to the model parameters of the natural language query expansion model, thereby determining the expanded training sample corresponding to the first structured query statement that does not satisfy the query requirement as the target training sample; use the natural language query expansion model to perform semantic diversification expansion on the target training sample to obtain multiple unlabeled target training samples corresponding to the target training sample; and update the multiple unlabeled target training samples as new target training samples.

[0112] In some embodiments, the manual annotation module 405 is further configured to obtain a structured annotation query statement corresponding to the target training sample for each target training sample; and establish a mapping relationship between the target training sample and the structured annotation query statement corresponding to the target training sample.

[0113] In some embodiments, the model incremental training module 406 is configured to construct an incremental training dataset based on new target training samples and labeled structured query statements corresponding to the new target training samples; and to incrementally train the structured query statement generation model using the incremental training dataset to obtain an optimized structured query statement generation model and a second structured query statement corresponding to each new target training sample.

[0114] In some embodiments, the query statement verification module 407 can also be configured to query the second structured query statement using a professional database to obtain query results corresponding to the second structured query statement; verify whether the query results meet the query expectations to obtain verification results; when the verification results indicate that the query results do not meet the query expectations, mark the target training sample corresponding to the second structured query statement as a new target training sample; return to the step of manually annotating the target training sample to continue processing until the verification results indicate that the second structured query statement meets the query expectations.

[0115] In some embodiments, the natural language query extension model is a deep learning model based on the Transformer architecture.

[0116] In some embodiments, the structured query generation model is a deep learning model based on the Transformer architecture.

[0117] The human-in-the-loop Text2SQL iterative data annotation device proposed in this invention integrates large models with expert annotations. By combining the model's reasoning ability with expert annotations, it can ensure that the data set after each iteration is reviewed by experts, effectively improving the accuracy and reliability of SQL query statements. By combining reinforcement learning and dynamic iterative annotation methods, it can continuously optimize the structured query statement generation model when dealing with new and complex query patterns, significantly improving the adaptability of the structured query statement generation model in changing scenarios.

[0118] Figure 5 A schematic block diagram of an electronic device 500 according to an embodiment of the present invention is shown. Figure 5 As shown, the electronic device 500 may include a processor 501 and a memory 502. The memory 502 stores computer program instructions for executing the human-in-the-loop Text2SQL iterative data annotation method for fusion large models. When the computer program instructions are executed by the processor 501, the electronic device 500 executes the method according to the preceding description. Figures 1 to 3 The method described. For example, in some embodiments, the electronic device 500 is used to implement the human-in-the-loop Text2SQL iterative data annotation method for fusing large models, as can be seen in the foregoing embodiments, which will not be repeated here.

[0119] An embodiment of the present invention provides an electronic device, the device comprising: a processor; and a memory storing computer program instructions implemented by a computer for executing a human-in-the-loop Text2SQL iterative data annotation method for fusing large models, wherein when the computer program instructions are executed by the processor, the electronic device performs, as follows: Figures 1 to 3 The method described.

[0120] This invention provides a computer-readable storage medium comprising computer-implemented computer program instructions for executing a human-in-the-loop Text2SQL iterative data annotation method for fusion large models. When executed by a processor, the computer program instructions cause the implementation of... Figures 1 to 3 The method described.

[0121] Those skilled in the art will recognize that embodiments of the present invention can be implemented as a system, method, or computer program product. Therefore, the present invention can be specifically implemented as entirely hardware, entirely software (including firmware, resident software, microcode, etc.), or a combination of hardware and software, generally referred to herein as a "circuit," "module," "unit," or "system." Furthermore, in some embodiments, the present invention can also be implemented as a computer program product contained in one or more computer-readable media, which contains computer-readable program code.

[0122] Any combination of one or more computer-readable media may be used. A computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. A computer-readable storage medium can be, for example,, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples (not exhaustive) of a computer-readable storage medium may include: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in connection with an instruction execution system, apparatus, or device.

[0123] Program code contained on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.

[0124] It should be understood that each block of a flowchart and / or block diagram, as well as combinations of blocks in a flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device to produce a machine that, when executed by a computer or other programmable data processing device, creates means for implementing the functions / operations specified in the blocks of the flowchart and / or block diagram.

[0125] While numerous embodiments of the invention have been shown and described herein, it will be apparent to those skilled in the art that such embodiments are provided by way of example only. Many modifications, alterations, and alternatives will occur to those skilled in the art without departing from the spirit and essence of the invention. It should be understood that various alternatives to the embodiments of the invention described herein may be employed in the practice of the invention. The appended claims are intended to define the scope of protection of the invention and therefore cover equivalents or alternatives within the scope of these claims.

Claims

1. A method for iterative text-to-SQL data annotation in a fusion model of large models, characterized in that, The method includes: The structured query generation model to be trained is trained and fine-tuned using a pre-constructed initial training data set to obtain a trained structured query generation model. The initial training data set includes multiple training sample pairs, each training sample pair including a natural language query training sample and a labeled structured query statement corresponding to the natural language query training sample. The labeled structured query statement is obtained through manual labeling. The trained natural language query expansion model is used to perform semantic diversification expansion on each natural language query training sample to obtain multiple expanded training samples corresponding to each natural language query training sample. Multiple extended training samples are input into the structured query statement generation model to obtain a first structured query statement corresponding to each of the extended training samples. For each of the first structured query statements, the model parameters of the natural language query extension model are assigned reward and penalty values ​​based on the expert analysis results and reinforcement learning mechanism, so as to determine the extended training sample corresponding to the first structured query statement that is given reward feedback as the target training sample. The target training samples are manually labeled to obtain labeled structured query statements corresponding to the target training samples. Based on the target training sample and the labeled structured query statement corresponding to the target training sample, the structured query statement generation model is incrementally trained to obtain a second structured query statement corresponding to the target training sample. If the verification result of the second structured query statement indicates that the query result of executing the second structured query statement does not meet the query expectation, return to the step of manually annotating the target training sample and continue processing until the verification result indicates that the query result of executing the second structured query statement meets the query expectation and the loop stops.

2. The method according to claim 1, characterized in that, For each of the first structured query statements, the model parameters of the natural language query extension model are assigned reward or penalty values ​​based on expert analysis results and reinforcement learning mechanisms, including: Determine whether the first structured query statement meets the query requirements; When it is determined that the first structured query statement satisfies the query requirements, a penalty feedback value is assigned to the model parameters of the natural language query extension model; or, When it is determined that the first structured query statement does not meet the query requirements, a reward feedback value is applied to the model parameters of the natural language query extension model to determine the extended training sample corresponding to the first structured query statement that does not meet the query requirements as the target training sample. The target training sample is semantically diversified by using the natural language query expansion model to obtain multiple unlabeled target training samples corresponding to the target training sample. Update the multiple unlabeled target training samples to new target training samples.

3. The method according to claim 2, characterized in that, Based on the target training samples and the labeled structured query statements corresponding to the target training samples, the structured query statement generation model is incrementally trained, including: Based on the new target training samples and the labeled structured query statements corresponding to the new target training samples, an incremental training data set is constructed. The structured query generation model is incrementally trained using the incremental training dataset to obtain an optimized structured query generation model and a second structured query corresponding to each new target training sample.

4. The method according to claim 1, characterized in that, When the verification result of the second structured query statement indicates that the query result of executing the second structured query statement does not meet the query expectation, the process returns to the step of manually annotating the target training samples and continues processing until the verification result indicates that the query result of executing the second structured query statement meets the query expectation, at which point the loop stops, including: The second structured query statement is queried using a professional database to obtain the query results corresponding to the second structured query statement; Verify whether the query results meet the query expectations, and obtain the verification results; When the verification result indicates that the query result does not meet the query expectation, the target training sample corresponding to the second structured query statement is marked as a new target training sample; Return to the step of manually annotating the target training samples and continue processing until the verification result indicates that the query result of executing the second structured query statement meets the query expectation, at which point the loop stops.

5. The method according to claim 1, characterized in that, The target training samples are manually labeled, including: For each target training sample, obtain the labeled structured query statement corresponding to the target training sample; establish a mapping relationship between the target training sample and the labeled structured query statement corresponding to the target training sample.

6. The method according to claim 1, characterized in that, The natural language query expansion model is a deep learning model based on the Transformer architecture.

7. The method according to claim 1, characterized in that, The structured query generation model is a deep learning model based on the Transformer architecture.

Citation Information

Patent Citations

  • Method and system for generating nl2sql training set based on large model and suitable for all industries

    CN118964579A

  • Database Query Generation from Natural Language Statements

    US20240273090A1