Model training method and device and data processing method
By generating and traversing structured query language templates and combining with data objects in the target database, the problem of inefficient preparation of annotated data in TextToSQL model training is solved, and a more efficient model training and annotation process is achieved.
Patent Information
- Application Number
- CN202510207191.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-24
- Publication Date
- 2025-06-13
AI Technical Summary
In the training of existing TextToSQL models, the preparation process of labeling data is time-consuming and labor-intensive. Due to the limitations of the professional knowledge and understanding ability of the labeling personnel, the accuracy and consistency of the labeling results are difficult to ensure, resulting in inefficient training.
By obtaining multiple structured query language templates, traversing these templates and finding mapping relationships in the target database, generating random character replacement placeholders, forming target statements, and determining the data object corresponding to the statement in the database, thereby determining the answer message of the large language model, and finally training the model based on the answer message.
This method significantly improves the labeling speed and efficiency, reduces the possibility of labeling errors, and improves the training efficiency and model performance of large language models.
Smart Images

Figure CN120144606A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of large language models, and more particularly, to a model training method, apparatus, and data processing method. Background Art
[0002] With the rapid development of big data and artificial intelligence technologies, natural language processing has been increasingly widely applied in various vertical fields. Especially in the field of database query, TextToSQL technology plays a crucial role. The TextToSQL technology aims to automatically convert natural language questions raised by users into structured query language (SQL) statements to achieve effective query of databases. This technology is of great significance for improving the convenience and efficiency of user interaction with databases and promoting the intelligent process of data analysis and information retrieval.
[0003] In vertical industries such as finance, healthcare, and retail, the application of TextToSQL technology is particularly critical. The database structures in these fields are complex, containing a large number of professional terms and business logics, requiring the TextToSQL model to not only accurately understand natural language questions but also generate SQL query statements that meet industry standards and business requirements. However, training a high-quality TextToSQL model faces huge challenges, and the most significant one is the preparation of labeled data.
[0004] Labeled data is the cornerstone of training a TextToSQL model, which directly determines the accuracy and generalization ability of the model. Traditional labeling methods often require labelers to first understand natural language questions and then manually write or select corresponding SQL statements. This forward labeling process is not only time-consuming and laborious, but also due to the limitations of labelers' professional knowledge and understanding ability, it is difficult to guarantee the accuracy and consistency of labeling results. Especially in scenarios involving complex queries or specific industry terms, the labeling work may become extremely complex, seriously affecting the efficiency and quality of labeling. In addition, with the increase in model complexity, higher requirements are also put forward for the quantity and diversity of labeled data. A single labeling method is difficult to meet the needs of large-scale model training and is prone to problems such as incomplete data coverage and unbalanced labeling, which will further affect the training effect and practical application performance of the model.
[0005] In response to the above problems, no effective solutions have been proposed yet. Summary of the Invention
[0006] This application provides a model training method, apparatus, and data processing method to at least solve the technical problem that the labeling method for the training set requires labelers to understand both natural language questions and structured query language simultaneously, resulting in slow labeling speed and easy errors, and thus low training efficiency for large language models.
[0007] According to one aspect of the present application, a model training method is provided, including: obtaining a plurality of Structured Query Language (SQL) templates; traversing the plurality of SQL templates, and when traversing the plurality of SQL templates, finding a target function in a target database that has a mapping relationship with the SQL template; generating random characters using the target function, and replacing placeholders in the SQL template with the random characters to obtain a target statement; determining a data object corresponding to the target statement in the target database, and determining a response message in a large language model according to the data object; receiving a question message that matches the response message, and training the large language model according to the response message and the question message that matches the response message.
[0008] Optionally, after replacing the placeholders in the SQL template with random characters to obtain the target statement, the method further includes: parsing the target statement into an abstract syntax tree, and extracting target information from the abstract syntax tree, where the target information includes at least one of the following: table name, operation type, filtering condition; traversing preconfigured rules to determine whether the target statement and the target information conform to the preconfigured rules; after completing the traversal of the preconfigured rules, generating a judgment result, where the judgment result uses a boolean value to indicate whether the target statement and the target information conform to the preconfigured rules; in the case where the judgment result indicates that the target statement and / or the target information do not conform to the preconfigured rules, generating a target message for characterizing the reason for not conforming to the preconfigured rules.
[0009] Optionally, traversing the preconfigured rules to determine whether the target statement and the target information conform to the preconfigured rules includes: in the case of traversing to a prohibited deletion rule, determining whether the operation type is a first preset character, and checking whether the data table associated with the operation type is in a preset list, where the first preset character includes: a character used to indicate a deletion operation; in the case of traversing to a query filtering condition rule, determining whether the target statement includes a target filtering condition specified in the rule; in the case of traversing to a maximum record number limit rule, determining whether the target statement includes a first preset clause, where the first preset clause is used to limit the number of rows returned by a query result set; in the case where the target statement includes the first preset clause, determining whether the number of records specified by the first preset clause is within the maximum record number limit range, and in the case where the target statement does not include the first preset clause, determining an estimated size of the query result set of the target statement, and determining whether the estimated size is within the maximum record number limit range.
[0010] Optionally, generating random characters using an objective function includes: determining a target number of random numbers to be generated according to the number of placeholders in a Structured Query Language (SQL) template; determining different preset numerical ranges corresponding to SQL statements in different dimensions, and for each preset numerical range, generating a first random number, where the first random number divides the preset numerical range into two sub-ranges; for each preset numerical range, when generating the nth random number, randomly selecting a target number from n preset numbers, determining a target sub-range from n sub-ranges according to the value of the target number, and generating a random number in the target sub-range, where n is a positive integer, sequentially from 2 to N, and N is the target number.
[0011] Optionally, after replacing the placeholders in the SQL template with random characters to obtain a target statement, the method further includes: determining whether a first latency between a submission node and a running node of the target statement is greater than a first preset threshold; splitting the target statement into multiple running phases according to the abstract syntax tree of the target statement, determining a time interval between each running phase, and determining whether the time interval between each running phase is greater than a second preset threshold; determining a business complexity metric of the target statement according to the number of library tables associated with the target statement, the number of subqueries included in the target statement, whether there is a cross-table association and the number of cross-table associations in the target statement, and the number of functions included in the target statement; determining whether a first difference between the running time of the target statement and the running time of a historical statement is greater than a third preset threshold, where the difference between the business complexity metrics of the target statement and the historical statement is less than a preset threshold; and performing optimization processing on the target statement when the first latency is greater than the first preset threshold and / or the time interval between each running phase is greater than the second preset threshold and / or the first difference is greater than the third preset threshold.
[0012] Optionally, performing optimization processing on the target statement includes: traversing the abstract syntax tree of the target statement to identify a subquery structure in the abstract syntax tree; determining whether the target subquery structure can be converted into a join operation according to whether there is an association condition between the target subquery structure and an external query structure, and whether the result corresponding to the target subquery structure can be obtained through a join operation; when it is determined that the target subquery structure can be converted into a join operation, deleting the target subquery structure from the abstract syntax tree, and adding the table and join condition corresponding to the target subquery structure to a second preset clause in the external query structure to obtain a target abstract syntax tree, where the second preset clause includes: a first statement for specifying a data source for querying data and a second statement for filtering the data source specified by the first statement; and regenerating the target statement according to the target abstract syntax tree.
[0013] Optionally, perform optimization processing on the target statement, including: generating multiple candidate execution plans based on the abstract syntax tree of the target statement and the metadata information of the target database, where the metadata information includes at least one of the following: table structure and index information, and there are differences in the levels of the candidate execution plans in a preset dimension, and the preset dimension includes at least one of the following: access order for tables, connection methods, and whether to use indexes; in the case where the candidate execution plan uses an index to access data, determine the number of times to read index pages and data pages from the disk according to the structure and data distribution of the index, and in the case where the candidate execution plan performs a full table scan, determine the number of I / O operations required to read the entire table data; determine the I / O cost of the candidate execution plan according to the number of times to read index pages and data pages from the disk or the number of I / O operations required to read the entire table data; determine the CPU cost according to the CPU computation amount required for the candidate execution plan to perform a first operation on the data, where the first operation includes at least one of the following: filtering, sorting, and joining; determine the memory cost according to the memory capacity required for the candidate execution plan to perform a second operation on the data, where the second operation includes at least one of the following: sorting and joining; determine the target cost of each candidate execution plan according to the I / O cost, CPU cost, and memory cost, and determine the target execution plan with the minimum target cost; regenerate the target statement according to the target execution plan.
[0014] According to another aspect of the present application, there is also provided a data processing method, including: receiving a question message, and analyzing the question message using a large language model to obtain an answer message corresponding to the question message, where the large language model is obtained by training through the above model training method.
[0015] According to another aspect of the present application, there is also provided a model training device, including: an acquisition module, configured to acquire a plurality of structured query language templates; a search module, configured to traverse the plurality of structured query language templates, and when traversing the plurality of structured query language templates, search for a target function in the target database that has a mapping relationship with the structured query language template; a generation module, configured to generate random characters using the target function, and replace the placeholders in the structured query language template with the random characters to obtain a target statement; a determination module, configured to determine a data object corresponding to the target statement in the target database, and determine an answer message in the large language model according to the data object; a training module, configured to receive a question message that matches the answer message, and train the large language model according to the answer message and the question message that matches the answer message.
[0016] According to another aspect of the present application, there is also provided a non-volatile storage medium, where the storage medium includes a stored program, and when the program runs, it controls the device where the storage medium is located to execute the above model training method.
[0017] According to another aspect of the present application, an electronic device is further provided, including: a memory and a processor, where the processor is configured to run a program stored in the memory, and when the program runs, it executes the above model training method.
[0018] According to another aspect of the present application, a computer program is further provided, where when the computer program is executed by a processor, it implements the above model training method.
[0019] According to another aspect of the present application, a computer program product is further provided. The computer program product includes a non-volatile computer-readable storage medium. The non-volatile computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, it implements the above model training method.
[0020] In the present application, by adopting the steps of obtaining a plurality of Structured Query Language (SQL) templates; traversing the plurality of SQL templates, and when traversing the plurality of SQL templates, searching for a target function in a target database that has a mapping relationship with the SQL template; generating random characters using the target function, and replacing the placeholder in the SQL template with the random characters to obtain a target statement; determining a data object corresponding to the target statement in the target database, and determining an answer message in a large language model according to the data object; receiving a question message that matches the answer message, and training the large language model according to the answer message and the question message that matches the answer message, the purpose of improving the annotation speed of the training set is achieved, thereby realizing the technical effect of improving the training efficiency of the large language model, and further solving the technical problem that the related annotation method for the training set requires annotators to understand both natural language problems and Structured Query Language at the same time, resulting in slow annotation speed and easy errors, and further leading to low training efficiency of the large language model. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The drawings described herein are used to provide a further understanding of the present application and form a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation to the present application. In the drawings:
[0022] Figure 1 is a flowchart of a model training method according to an embodiment of the present application;
[0023] Figure 2 is a schematic diagram of a reverse intelligent annotation method according to an embodiment of the present application;
[0024] Figure 3 is a structural diagram of a model training device according to an embodiment of the present application;
[0025] Figure 4Hardware block diagram of a computer terminal for a model training method according to an embodiment of the present application. Detailed implementation manners
[0026] In order to enable those skilled in the art to better understand the solution of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work shall fall within the protection scope of the present application.
[0027] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily need to be used to describe a specific order or sequence. It should be understood that such data used in appropriate cases can be interchanged so that the embodiments of the present application described herein can be implemented in an order different from those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device including a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0028] According to an embodiment of the present application, a method embodiment of a model training method is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions. And although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that here.
[0029] Figure 1 is a flowchart of a model training method according to an embodiment of the present application, as Figure 1 shown, the method includes the following steps:
[0030] Step S101, obtain a plurality of Structured Query Language templates.
[0031] In order to improve the annotation efficiency and ensure coverage of all capabilities to be trained, it is first necessary to obtain a plurality of Structured Query Language templates from the table of capabilities to be trained. These templates will serve as the basis for generating annotation data, and each template corresponds to a database operation ability, such as aggregation ability, sorting ability, etc.
[0032] Among them, the table of capabilities to be trained is, for example:
[0033]
[0034]
[0035] Step S102, traverse multiple Structured Query Language templates, and when traversing the multiple Structured Query Language templates, search for a target function in the target database that has a mapping relationship with the Structured Query Language template.
[0036] Traverse the SQL templates. For each template, based on the information in the to-be-covered training library table knowledge base (target database), search for a target function in the target database that has a mapping relationship with the placeholder in the template. For example, if the template contains functions, identify which functions (such as aggregation, filtering, conversion, etc.) can correspond to the SQL syntax capabilities to be trained, so as to ensure that the generated SQL statements are meaningful.
[0037] Among them, the to-be-covered training library table knowledge base is, for example:
[0038]
[0039] Step S103, use the target function to generate random characters, and replace the placeholder in the Structured Query Language template with the random characters to obtain a target statement.
[0040] Specifically, traverse the to-be-trained ability table. For example: In the first loop: Generate the basic template SQL: Select count(1) from $table_name. Then, at this time, $table will be replaced with the English names of all involved tables, and all table information is obtained from the to-be-covered training library table knowledge base; In the second loop: Select count(1) from $table_name where $field1 $function $value; There are 56 functions to be trained in this list, and the first one is "equal". Then, in the inner loop function list: Select count(1) from $table_name where $field1 = $value, and then loop one more level inside, traverse all fields, and the corresponding functions for generating random numbers as needed.
[0041] Generally speaking, traverse all to-be-trained abilities, to-be-trained tables, to-be-trained functions, and to-be-covered fields. Then, each time a loop is performed, according to the library, table, field, function, etc. in the current loop, map and search for the automatically generated functions required in the to-be-covered training library table knowledge base, and replace $value with the corresponding random value.
[0042] Step S104, determine the data object corresponding to the target statement in the target database, and based on the data object, determine the response message in the large language model.
[0043] Execute the generated target statement in the target database to determine its corresponding data object. Based on the data object and the result it returns, the response message in the large language model can be determined. For example, if the SQL statement is "SELECT AVG(salary) AS average_salary FROM salaries", the response message might be "The average salary of Zhang San in the past three months is 8000 yuan."
[0044] In step S104, it is necessary to receive the annotation content of the data object by the annotator, and determine the data object and its annotation content as the response message in the large language model.
[0045] In step S105, receive the question message that matches the response message, and train the large language model based on the response message and the question message that matches the response message.
[0046] The annotator constructs a question message that matches the generated response message in reverse. Collect these question messages and combine them with the response messages to form question-answer pairs. These question-answer pairs will be used to train the large language model. When constructing the question message, the annotator can use various ways of asking to ensure that the model can handle natural language inputs in different forms.
[0047] The above steps significantly improve the efficiency and quality of data annotation through a unique process of first annotating the answer (SQL statement) and then annotating the question (natural language query). Specifically, its advantages are reflected in the following aspects: 1. Compared with the annotator that generates questions and answers simultaneously, after generating the SQL answer, it allows the annotator to freely create the corresponding question according to the content of the SQL statement. This way injects human thinking and language habits, and the generated questions are more natural, diverse, and more in line with the actual human language usage scenarios, thus effectively enhancing the model's recognition ability of colloquial and natural language. 2. It is particularly suitable for the iterative optimization process of model training. Starting from high-quality SQL statements, combined with the language creativity of different annotators, continuously enrich and improve the question set, providing more comprehensive and accurate training data for the model, thereby promoting the continuous improvement of the model's performance.
[0048] The following gives Figure 1 an exemplary illustration and explanation of the
[0049] According to some alternative embodiments of the present application, after replacing the placeholder in the structured query language template with random characters to obtain the target statement, the following steps may further be performed: parsing the target statement into an abstract syntax tree, and extracting target information from the abstract syntax tree, where the target information includes at least one of the following: table name, operation type, filtering condition; traversing the preconfigured rules to determine whether the target statement and the target information conform to the preconfigured rules; after completing the traversal of the preconfigured rules, generating a judgment result, where the judgment result is represented by a boolean value indicating whether the target statement and the target information conform to the preconfigured rules; in the case where the judgment result indicates that the target statement and / or the target information do not conform to the preconfigured rules, generating a target message for characterizing the reason for non-conformity with the preconfigured rules.
[0050] Specifically, call an SQL parsing library, such as SQLparse, JSQLParser, or ANTLR, to parse the target statement into an abstract syntax tree (AST). The AST is a tree structure that can clearly represent the syntax structure and semantic information of the SQL statement. From the constructed AST, extract the target information, including the table name, operation type (such as SELECT, INSERT, UPDATE, DELETE, etc.), and filtering condition (the conditional expression in the WHERE clause). These information are crucial for subsequent rule matching.
[0051] Traverse the preconfigured rules. For each rule, check whether the target statement and the extracted target information meet the rule requirements. For example, if the rule stipulates that the query statement must include a date range filter, check whether there is a corresponding date filtering condition in the WHERE clause.
[0052] After completing the traversal of the preconfigured rules, generate a judgment result represented by a boolean value. If all checks pass, the boolean value is true; otherwise, it is false. If the judgment result is true, it means that the target statement and information meet the preconfigured rules and data verification and annotation can continue. If the judgment result is false, a detailed cause analysis is required.
[0053] In the case where the judgment result indicates non-conformity with the preconfigured rules, analyze which rule or rules are not satisfied, and which parts of the target statement and the target information violate the rules. Generate a target message that details the reason for non-conformity with the preconfigured rules. For example, if the target statement lacks a necessary filtering condition, the target message may be: "The SQL statement does not contain the necessary date range filtering condition, and all queries must be restricted within a specific date range." The target message will be fed back to the annotator, and the annotator will correct the target statement according to the feedback information to ensure that it conforms to all preconfigured rules. The corrected SQL statement will be re-parsed into an abstract syntax tree and rule-matched until it conforms to the preconfigured rules.
[0054] Preferably, by traversing the pre-configured rules, it can be determined whether the target statement and the target information conform to the pre-configured rules through the following methods: when traversing the prohibited deletion rule, determine whether the operation type is the first preset character, and check whether the data table associated with the operation type is in the preset list, where the first preset character includes: a character used to indicate a deletion operation; when traversing the query filtering condition rule, determine whether the target statement includes the target filtering condition specified in the rule; when traversing the maximum record number limit rule, determine whether the target statement includes the first preset clause, where the first preset clause is used to limit the number of rows returned by the query result set; when the target statement includes the first preset clause, determine whether the record number specified by the first preset clause is within the maximum record number limit range, and when the target statement does not include the first preset clause, determine the estimated size of the result set queried by the target statement, and determine whether the estimated size is within the maximum record number limit range.
[0055] To execute the pre-configured rules more precisely, when traversing the rules, the judgment logic for specific rules is refined to ensure that the target statement meets the business requirements and data security requirements. The following is the detailed judgment process for the prohibited deletion rule, query filtering condition rule, and maximum record number limit rule:
[0056] 1. Judgment of the prohibited deletion rule. Check whether the operation type of the SQL statement is "DELETE", that is, whether it contains the first preset character used to indicate a deletion operation. If the operation type is "DELETE", further check whether the data table is in the preset list, that is, whether it belongs to the predefined sensitive tables or key tables, which have a special status in the business logic and may contain sensitive data or key business information.
[0057] 2. Judgment of the query filtering condition rule. Determine whether the target statement contains the target filtering conditions specified in the rule, such as date range, user permissions, etc.
[0058] 3. Judgment of the maximum record number limit rule. First, determine whether the target statement contains the first preset clause used to limit the number of rows returned by the query result set, that is, the LIMIT clause.
[0059] If the target statement already contains the LIMIT clause, further determine whether the record number specified by the LIMIT clause is within the preset maximum record number limit range.
[0060] If the target statement does not contain a LIMIT clause, estimate the size of the result set after the SQL statement is executed. The estimation methods include but are not limited to: by querying the metadata of the database to understand the number of rows and index information of the table, and thus estimating the size of the query result set. Using statistical information and historical query results, analyze the average result set size of similar queries, and use this as the basis for estimation.
[0061] Furthermore, determine whether the estimated number of records meets the maximum record number limit to ensure that the query result will not be too large and affect system performance and user experience.
[0062] It should be noted that if the target statement or information is judged to not conform to the rules at any step, a detailed target message will be generated, indicating which rule is specifically violated and the reason for the violation, such as "the SQL statement contains a delete operation, involving a sensitive table, and does not meet the security requirements" or "the query does not contain the necessary date filtering conditions, violating the query filtering condition rule".
[0063] In some alternative embodiments of the present application, generating random characters using an objective function can be achieved by the following method: determine the target number of random numbers to be generated according to the number of placeholders in the structured query language template; determine different preset numerical intervals corresponding to different dimensions of the structured query statement. For each preset numerical interval, generate a first random number, where the first random number divides the preset numerical interval into two sub-intervals; for each preset numerical interval, when generating the nth random number, randomly select a target number from n preset numbers, and according to the value of the target number, determine the target sub-interval among the n sub-intervals, and generate a random number in the target sub-interval, where n is a positive integer, successively from 2 to N, and N is the target number.
[0064] Specifically, first determine the target number of random numbers to be generated according to the number of placeholders in the structured query language template. For example, if the template contains 3 placeholders, then the target number is 3. Set a preset numerical interval for each placeholder, and this interval can be adjusted according to the field type and range represented by the placeholder. For example, for a placeholder representing age, its preset numerical interval can be from 1 to 100.
[0065] For each preset numerical interval that needs to fill a placeholder, first generate a first random number (for example, for the interval from 1 to 100, the generated random number is 23). This random number divides the preset numerical interval into two sub-intervals (for example, 1 to 22 and 24 to 100).
[0066] For each preset numerical range, starting from the second random number, randomly select a target number from n preset numbers (for example, the target number is 0 or 1). Determine the target sub-range (for example, if the target number is 0, select the first sub-range; if the target number is 1, select the second sub-range). Generate a new random number within the target sub-range to fill the next placeholder. For example, after selecting the sub-range from 1 to 22, generate a new random number, such as 15, to fill the next placeholder. The above process continues until all placeholders are filled.
[0067] As some alternative embodiments of the present application, after replacing the placeholder in the structured query language template with random characters to obtain the target statement, the following steps may further be performed: Determine whether the first delay between the submission node and the running node of the target statement is greater than a first preset threshold; according to the abstract syntax tree of the target statement, split the target statement into multiple running stages, determine the time interval between each running stage, and determine whether the time interval between each running stage is greater than a second preset threshold; according to the number of library tables associated with the target statement, the number of sub-queries included in the target statement, whether there is a cross-table association and the number of cross-table associations in the target statement, and the number of functions included in the target statement, determine the business complexity index of the target statement; determine whether the first difference between the running time of the target statement and the running time of the historical statement is greater than a third preset threshold, where the difference in the business complexity index between the target statement and the historical statement is less than the preset threshold; in the case where the first delay is greater than the first preset threshold and / or the time interval between each running stage is greater than the second preset threshold and / or the first difference is greater than the third preset threshold, perform optimization processing on the target statement.
[0068] Specifically, determine whether the network delay (the first delay) between the submission node and the running node of the target statement is greater than a preset first threshold. This step is implemented through a heartbeat detection algorithm, aiming to identify whether there is a network delay problem that affects the query performance.
[0069] Based on the abstract syntax tree of the target statement, split it into multiple running stages, such as data reading, condition filtering, join operation, aggregation calculation, etc. Then, record the execution time of each stage and determine whether the time interval between each running stage is greater than a preset second threshold.
[0070] According to factors such as the number of library tables associated with the target statement, the number of sub-queries, whether there is a cross-table association and the number of cross-table associations, and the number of function uses, comprehensively evaluate the business complexity index of the target statement. The business complexity index reflects the complexity of the business logic processed by the SQL statement and has direct guiding significance for performance optimization.
[0071] Compare the running time of the target statement with the running time of SQL statements with similar historical business complexities, and calculate the time difference (the first difference) between the two. If the first difference is greater than a preset third threshold, it indicates that the execution efficiency of the target statement is lower than the historical average, and optimization is required.
[0072] In summary, when any of the following conditions is met, optimize the target statement: 1. The first latency is greater than the first preset threshold, indicating that network latency is the performance bottleneck; 2. The time interval between running phases is greater than the second preset threshold, indicating that there is a phase with low execution efficiency; 3. The first difference is greater than the third preset threshold, indicating that the execution efficiency of the target statement is lower than the historical average level.
[0073] In some alternative embodiments of the present application, the optimization process of the target statement can be achieved through the following method: traverse the abstract syntax tree of the target statement to identify the subquery structure in the abstract syntax tree; based on whether there is an association condition between the target subquery structure and the external query structure, and whether the result corresponding to the target subquery structure can be obtained through a join operation, determine whether the target subquery structure can be converted into a join operation; when it is determined that the target subquery structure can be converted into a join operation, delete the target subquery structure in the abstract syntax tree, and add the table and join conditions corresponding to the target subquery structure to the second preset clause in the external query structure to obtain the target abstract syntax tree, where the second preset clause includes: a first statement for specifying the data source of the query data and a second statement for filtering the data source specified by the first statement; regenerate the target statement according to the target abstract syntax tree.
[0074] In the above embodiment, by traversing the abstract syntax tree of the target statement, the subquery structure therein is identified. For example, a subquery appears as a query statement nested in a WHERE clause, a FROM clause, or a SELECT clause.
[0075] For each identified subquery structure, it will be checked whether there is an association condition between it and the external query structure, and whether the result corresponding to the subquery structure can be obtained through a join operation. If the following conditions are met: 1. There is a clear association condition (such as a common field) between the subquery and the external query; 2. The result of the subquery can be integrated with the external query through a JOIN operation (such as an inner join, an outer join) without having to execute the subquery again, it will be determined that the subquery structure can be converted into a join operation to improve the query efficiency.
[0076] Delete the identified target subquery structure in the abstract syntax tree to prepare for the subsequent addition of join operations. Add the table corresponding to the target subquery structure and the join condition to the FROM clause and WHERE clause in the outer query structure to implement the conversion from subquery to join operation. The specific operations are as follows: Add the table in the target subquery structure to the FROM clause of the outer query structure. Add the association condition (such as the equality condition of common fields) to the WHERE clause of the outer query structure. After completing these operations, the system will obtain the optimized target abstract syntax tree, in which the subquery has been converted into a join operation.
[0077] Regenerate the target statement according to the optimized target abstract syntax tree. At this time, the SQL statement has been optimized from subquery to join, and the execution efficiency will be improved.
[0078] Through the above steps, the subquery structure is identified and converted from the abstract syntax tree of the SQL statement, and the subquery operation is converted into a more efficient join operation, thereby improving the execution efficiency of the query statement. This optimization strategy is especially applicable to SQL statements involving multi-table joins and complex subqueries, which can significantly reduce the response time of database queries and improve the user experience and system performance.
[0079] As some other optional embodiments of this application, the target statement can be optimized by the following method: Generate multiple candidate execution plans according to the abstract syntax tree of the target statement and the metadata information of the target database, where the metadata information includes at least one of the following: table structure and index information. There are differences in the levels of the candidate execution plans in a preset dimension, and the preset dimension includes at least one of the following: access order for tables, join method, and whether to use an index; In the case where the candidate execution plan accesses data using an index, determine the number of times to read index pages and data pages from the disk according to the structure and data distribution of the index. In the case where the candidate execution plan performs a full table scan, determine the number of I / O operations required to read the entire table data; Determine the I / O cost of the candidate execution plan according to the number of times to read index pages and data pages from the disk or the number of I / O operations required to read the entire table data; Determine the CPU cost according to the CPU computation amount required for the candidate execution plan to perform the first operation on the data, where the first operation includes at least one of the following: filtering, sorting, joining; Determine the memory cost according to the memory capacity required for the candidate execution plan to perform the second operation on the data, where the second operation includes at least one of the following: sorting, joining; Determine the target cost of each candidate execution plan according to the I / O cost, CPU cost, and memory cost, and determine the target execution plan with the minimum target cost; Regenerate the target statement according to the target execution plan.
[0080] In the above embodiments, multiple candidate execution plans are generated based on the abstract syntax tree of the target statement and the metadata information of the target database. The metadata information includes key database design details such as table structures and index information. The candidate execution plans differ in preset dimensions, such as the access order of tables, connection methods (nested loop, hash join, merge join, etc.), and whether to use indexes.
[0081] For a candidate execution plan that accesses data using an index, estimate the number of times to read index pages and data pages from disk based on the index structure (such as B-tree, bitmap index) and data distribution. For a candidate execution plan that performs a full table scan, determine the number of I / O operations required to read the entire table data. Estimate the required CPU computation based on the complexity of the first operation (such as filtering, sorting, joining) performed in the candidate execution plan to determine the CPU cost. Determine the memory cost based on the memory capacity required for the second operation (such as sorting, joining). For example, a hash join operation may require building a hash table in memory, which consumes additional memory resources.
[0082] Taking into account the I / O cost, CPU cost, and memory cost comprehensively, calculate the total cost of each candidate execution plan. For example, the total cost is the weighted sum of each cost, and the weights may be adjusted according to the specific configuration of the database and the query load.
[0083] Select the execution plan with the minimum target cost as the target execution plan to optimize the execution efficiency of the SQL statement. Based on the selected target execution plan, regenerate the target statement to ensure that its execution method is consistent with the optimal execution plan. For example, if the target execution plan selects to use a hash join and a specific index, the generated target statement will include the corresponding join method and index usage.
[0084] Through the above refinement steps, not only can a SQL statement with correct syntax and consistent with the business logic be generated, but also its execution plan can be further optimized to ensure fast and resource-saving execution in the actual database environment. This cost-based optimization strategy is a key link in ensuring the high quality and efficient utilization of labeled data in the reverse intelligent annotation algorithm, and is crucial for improving the training quality and application performance of the TextToSQL large model.
[0085] The embodiments of this application also provide a data processing method, including: receiving a question message, and analyzing the question message using a large language model to obtain an answer message corresponding to the question message, where the large language model is obtained by Figure 1 the model training method shown.
[0086] Receive the question messages input by the user through the interface. These messages can be in the form of text, voice, or other forms of natural language input. Perform necessary preprocessing on the question messages, including removing irrelevant information, correcting spelling mistakes, standardizing formats, etc., to improve the accuracy and efficiency of subsequent analysis.
[0087] Use a pre-trained large language model to deeply analyze the preprocessed question messages. The model will extract the key entities and concepts in the question messages, understand the user's question intention, and provide the necessary information support for generating answer messages later.
[0088] Based on the results of the analysis of the question messages, the large language model will generate accurate, complete, and context-compliant answer messages. This includes providing direct answers, explaining complex concepts, giving suggestions or guidance, etc.
[0089] Perform semantic adjustment on the generated answer messages to ensure they conform to business logic and user habits. At the same time, optimize the language expression to make the answers more natural and fluent. Provide a user feedback interface to collect feedback information such as the user's satisfaction with the answer messages and the need for question clarification. According to the user feedback, adjust the training parameters of the large language model, optimize the model performance, and improve the model's understanding ability and answer quality through continuous learning and iteration.
[0090] Figure 2 It is a schematic diagram of a reverse intelligent annotation method according to an embodiment of the present application, as Figure 2 shown. The method includes the following steps:
[0091] Step S201, the stage of formulating annotation specifications.
[0092] Step S2011, draw up annotation specifications and formats. AI engineers and front-end and back-end developers agree on and review the interaction link and data format between the large model and the front-end and back-end according to the product requirements and general design to ensure the standardization and consistency of the annotation process.
[0093] Step S2012, import annotation specifications and formats. Import the determined annotation specifications and formats into the system as the standard template for subsequent annotation operations.
[0094] Step S2013, import library tables. Import the data of the library tables to be annotated into the system as the basic data source for generating annotations.
[0095] Step S202, the stage of generating SQL.
[0096] Step S2021, generate fields and field values.
[0097] To improve the annotation efficiency and ensure coverage of all capabilities to be trained, it is first necessary to obtain multiple Structured Query Language templates from the table of capabilities to be trained. These templates will serve as the basis for generating annotation data, with each template corresponding to a database operation ability, such as aggregation ability, sorting ability, etc.
[0098] Among them, the table of capabilities to be trained is, for example:
[0099]
[0100] Traverse the table of capabilities to be trained. For example, in the first loop: generate the basic template SQL: Select count(1) from $table_name. Then, at this time, $table will be replaced with the English names of all involved tables, and all table information is obtained from the knowledge base of the tables in the training library to be covered; in the second loop: Select count(1) from $table_name where $field1 $function $value; there are 56 functions in the function list to be trained this time, and the first one is "equal". Then, the inner loop function list: Select count(1) from $table_name where $field1 = $value, and then loop one more level inside, traverse all fields, and the corresponding functions for generating random numbers as needed.
[0101] Among them, the knowledge base of the tables in the training library to be covered is, for example:
[0102]
[0103]
[0104] To sum up, traverse all capabilities to be trained, tables to be trained, functions to be trained, and fields to be covered. Then, in each loop, according to the database, table, field, function, etc. in the current loop, map and find the automatic generation functions needed in the knowledge base of the tables in the training library to be covered. Replace $value with the corresponding random value.
[0105] The process of generating query fields and conditional fields based on random numbers: Read the knowledge base of the tables in the training library to be covered. It can be known how many fields this table has, for example, 20 fields. Case 1, now generate 1 random number: For Java, it is: import java.util.Random; random.nextInt(20). When the generated random number is 3, obtain the 3rd field of this table. For Java: field = array.get(3).
[0106] The number of random numbers generated is actually more than 1. One, two, three, … seven random numbers will be randomly generated in sequence, corresponding to 1 to 7 random fields (these fields are non-repeating).
[0107] When randomly generating 3 fields, the following method is used to ensure that the random fields are non-repeating: Suppose the number randomly generated in the range of 1 - 20 for the first time is 3. When generating the number for the second time, the previously selected number divides the random number range into two segments, the left and the right; First, randomly generate 0 or 1 to determine which segment of the number range to select for the next random generation. If it is 0, then randomly generate a number from 1 - 2 again. If it is 1, then randomly generate a number from 4 - 20. For the third random generation: Suppose there are already 3 and 7, then the data range is divided into three segments: 1 - 2, 4 - 6, 8 - 20. First, randomly generate 0, 1, 2 to select the random number range, and then generate it for the second time. Finally, the generated number corresponds to getting the x-th field. In this way, the fields to be used as query conditions or query fields are randomly selected, that is, $fields is filled.
[0108] Step S2022, function generation. The relevant functions are randomly selected from the standard function list to ensure that the functions used in the generated SQL queries conform to common database operations and can effectively handle actual query requirements.
[0109] Step S2023, generate SQL statements. Combining the above generation rules, the data annotation answers that meet the expectations are automatically generated. These annotation answers will be presented in the specified format and used for model training and verification.
[0110] Step S2024, answer classification. The answers are grouped according to the involved library tables, fields, and syntax, ensuring that the answers for the same table and the same syntax are grouped together. In this way, when annotating, the annotators can refer to the question asking methods within the same group, thereby improving the annotation efficiency.
[0111] Step S203, the annotator matches and annotates the corresponding questions according to the annotation standard and by reading the SQL answers.
[0112] Step S204, data verification stage.
[0113] Full-scale verification: To ensure the general direction of the annotation results is accurate, the first 10 received annotations need to be strictly quality inspected. In the initial stage of annotation, the system will limit each annotator to only annotate 10 pieces of data and submit them for inspection. After the annotation is completed, the inspectors will check each item one by one according to the annotation standard and business knowledge, and make comments and send back the annotations that do not meet the requirements. The annotator needs to modify the sent-back data and resubmit it. After passing the initial inspection, the system will cancel the annotation limit and allow the annotator to perform a large amount of annotation.
[0114] Sampling verification: When half of the annotation work has been completed, it is necessary to conduct sampling quality inspection to ensure subsequent quality. The specific verification methods include: Judging from a business perspective, whether the query results meet expectations (using methods such as rule matching and semantic analysis to determine whether the SQL meets business requirements. Rule matching is relatively simple and direct, suitable for handling some clear business rules; semantic analysis is more complex and requires the aid of natural language processing technology to handle more complex business logics). If it does not meet expectations, mark it as a marking error and return it for modifying the marked problems.
[0115] In addition to understanding the business meaning, it is possible to check whether the SQL is correct by aligning the query fields and conditional fields. Generate the number of query fields and conditional fields according to random numbers, ensuring that these fields logically come from the same table. During the generation process, the system will ensure that the query fields, conditional fields, and aggregation fields meet the actual structure and business logic requirements of the database table. In addition, it is also possible to verify whether the running efficiency meets expectations. If it does not meet expectations, it will be marked as an efficiency problem and the SQL statement needs to be rolled back for optimization.
[0116] The reverse intelligent annotation method proposed in this embodiment has the following differences compared with the prior art: First, annotate the answer:
[0117] SELECT AVG(salary)AS average_salary
[0118] FROM salaries
[0119] WHERE name='Zhang San'
[0120] AND date>=DATE_SUB(CURDATE(),INTERVAL 3MONTH);
[0121] Then, create a reasonable question for the answer. Maybe multiple questions can be created at once: Query the average salary of Zhang San in the past three months; Query the average salary of Zhang San in the most recent three months; Query the salary of a person in the past three months, and this person's name is: Zhang San.
[0122] While the prior art first annotates the question: Query the average salary of Zhang San in the past three months
[0123] Then annotate the answer: SELECT AVG(salary)AS average_salary
[0124] FROM salaries
[0125] WHERE name='Zhang San'
[0126] AND date >= DATE_SUB(CURDATE(), INTERVAL 3 MONTH).
[0127] For example, an intelligent customer service system of a certain App requires a large model that can perform speech recognition on the user's speech, convert the speech into text, and then convert the text into corresponding query SQL to query the business system. Such a system requires a text2SQL large model base for capacity support. This base requires 200 person-days of annotation work. At this time, it is found that the human input is too large and the accuracy of the annotation is not high. The verification work requires 150 person-days. Then, at this time, an optimizer for reverse intelligent annotation is used to assist in annotation and improve efficiency.
[0128] Reverse annotation process: 1. The annotation administrator uses the system to import the knowledge base and customize the annotation standards; 2. Start automatically generating SQL, the algorithm for generating SQL; 3. Standard personnel perform annotation on the questions and try to be as colloquial as possible; 4. Perform verification on the questions and answers, and the verification algorithm has been described above; 5. Train and publish the marked "question-answer pairs"; 6. After publication, during the user usage stage, for the questions asked, such as: "I want to query the detailed usage of my monthly traffic", the query result is: "Your total monthly traffic consumption is 200 yuan." At this time, the user is not satisfied with this query result because there is no specific details, no specific description of the package details, and the charging situation for the part exceeding the package. At this time, the user clicks "Dissatisfied". The system log will record the following information:
[0129] {
[0130] "question": "I want to query the detailed usage of my monthly traffic",
[0131] "SQL": "SELECT SUM(usage_amount) AS total_monthly_usage FROM traffic_usage WHERE usage_date >= DATE_TRUNC('month', CURRENT_DATE) AND usage_date < DATE_TRUNC('month', CURRENT_DATE) INTERVAL '1 month';",
[0132] "mark": "SQL error"
[0133] }
[0134] It is also possible that the user feels that the response is too slow and clicks "Too slow", and the system log marks the following information:
[0135] {
[0136] "question": "I want to check my total monthly data usage.",
[0137] "SQL": "SELECT SUM(usage_amount) AS total_monthly_usage FROM traffic_usage WHERE usage_date >= DATE_TRUNC('month', CURRENT_DATE) AND usage_date < DATE_TRUNC('month', CURRENT_DATE) + INTERVAL '1 month';",
[0138] "mark": "timetabling"
[0139] }
[0140] 7. The annotation tool regularly collects these logs, summarizes them for the annotators to modify. For incorrect SQL, modify the SQL. For SQL that needs to be optimized, optimize the SQL performance.
[0141] The above steps use reverse annotation technology to first generate high-quality SQL answers, and then let the annotators match the questions, effectively solving the problem of low efficiency in traditional annotation methods. This annotation process significantly reduces the workload of the annotators and improves the annotation speed. By having the annotators create natural language questions for the generated SQL statements, it injects the diversity and flexibility of human language, enhancing the model's understanding and processing ability of colloquial queries.
[0142] Figure 3 It is a structural diagram of a model training device according to an embodiment of the present application. As Figure 3 shown, the device includes:
[0143] An acquisition module 31, configured to acquire a plurality of structured query language templates.
[0144] A search module 32, configured to traverse a plurality of structured query language templates, and when traversing the plurality of structured query language templates, search for a target function in a target database that has a mapping relationship with the structured query language template.
[0145] A generation module 33, configured to generate random characters using the target function, and replace the placeholder in the structured query language template with the random characters to obtain a target statement.
[0146] A determination module 34, configured to determine a data object corresponding to the target statement in the target database, and determine a response message in the large language model according to the data object.
[0147] The training module 35 is configured to receive question messages that match the answer messages, and train the large language model based on the answer messages and the question messages that match the answer messages.
[0148] Optionally, the model training device is further configured to, after replacing the placeholders in the structured query language template with random characters to obtain a target statement, perform the following steps: parse the target statement into an abstract syntax tree, and extract target information from the abstract syntax tree, where the target information includes at least one of the following: table name, operation type, filtering condition; traverse the pre-configured rules to determine whether the target statement and the target information conform to the pre-configured rules; after completing the traversal of the pre-configured rules, generate a judgment result, where the judgment result is represented by a boolean value indicating whether the target statement and the target information conform to the pre-configured rules; in the case where the judgment result indicates that the target statement and / or the target information do not conform to the pre-configured rules, generate a target message for characterizing the reason for non-conformity with the pre-configured rules.
[0149] Optionally, traversing the pre-configured rules to determine whether the target statement and the target information conform to the pre-configured rules includes: in the case of traversing the prohibited deletion rule, determining whether the operation type is a first preset character, and checking whether the data table associated with the operation type is in a preset list, where the first preset character includes: a character indicating a deletion operation; in the case of traversing the query filtering condition rule, determining whether the target statement includes the target filtering condition specified in the rule; in the case of traversing the maximum record number limit rule, determining whether the target statement includes a first preset clause, where the first preset clause is used to limit the number of rows returned by the query result set; in the case where the target statement includes the first preset clause, determining whether the number of records specified by the first preset clause is within the maximum record number limit range, and in the case where the target statement does not include the first preset clause, determining the estimated size of the result set queried by the target statement and determining whether the estimated size is within the maximum record number limit range.
[0150] Optionally, the generation module 33 is further configured to perform the following steps: determine the target number of random numbers to be generated according to the number of placeholders in the structured query language template; determine different preset numerical intervals corresponding to structured query statements in different dimensions, and for each preset numerical interval, generate a first random number, where the first random number divides the preset numerical interval into two sub-intervals; for each preset numerical interval, when generating the nth random number, randomly select a target number from n preset numbers, determine a target sub-interval according to the value of the target number, and generate a random number in the target sub-interval, where n is a positive integer, sequentially from 2 to N, and N is the target number.
[0151] Optionally, the model training device is further configured to, after replacing the placeholder in the structured query language template with random characters to obtain a target statement, perform the following steps: determine whether a first latency between a submission node of the target statement and a running node of the target statement is greater than a first preset threshold; according to the abstract syntax tree of the target statement, split the target statement into multiple running phases, determine a time interval between each running phase, and determine whether the time interval between each running phase is greater than a second preset threshold; determine a business complexity metric of the target statement according to the number of library tables associated with the target statement, the number of subqueries included in the target statement, whether there is a cross-table association and the number of cross-table associations in the target statement, and the number of functions included in the target statement; determine whether a first difference between the running time of the target statement and the running time of a historical statement is greater than a third preset threshold, where the difference between the business complexity metrics of the target statement and the historical statement is less than a preset threshold; and perform an optimization process on the target statement when the first latency is greater than the first preset threshold and / or the time interval between each running phase is greater than the second preset threshold and / or the first difference is greater than the third preset threshold.
[0152] Optionally, performing an optimization process on the target statement includes: traversing the abstract syntax tree of the target statement to identify a subquery structure in the abstract syntax tree; determining whether the target subquery structure can be converted into a join operation according to whether there is an association condition between the target subquery structure and an external query structure and whether the result corresponding to the target subquery structure can be obtained through a join operation; when it is determined that the target subquery structure can be converted into a join operation, deleting the target subquery structure from the abstract syntax tree, and adding the table and join condition corresponding to the target subquery structure to a second preset clause in the external query structure to obtain a target abstract syntax tree, where the second preset clause includes: a first statement for specifying a data source for querying data and a second statement for filtering the data source specified by the first statement; and regenerating the target statement according to the target abstract syntax tree.
[0153] Optionally, perform optimization processing on the target statement, including: generating multiple candidate execution plans according to the abstract syntax tree of the target statement and the metadata information of the target database, where the metadata information includes at least one of the following: table structure and index information, and there are differences in the levels of each candidate execution plan in a preset dimension, and the preset dimension includes at least one of the following: access order for tables, connection method, and whether to use an index; in the case where the candidate execution plan uses an index to access data, determine the number of times of reading index pages and data pages from the disk according to the structure and data distribution of the index, and in the case where the candidate execution plan performs a full table scan, determine the number of I / O operations required to read all table data; determine the I / O cost of the candidate execution plan according to the number of times of reading index pages and data pages from the disk or the number of I / O operations required to read all table data; determine the CPU cost according to the CPU computing amount required for the candidate execution plan to perform a first operation on the data, where the first operation includes at least one of the following: filtering, sorting, and joining; determine the memory cost according to the memory capacity required for the candidate execution plan to perform a second operation on the data, where the second operation includes at least one of the following: sorting and joining; determine the target cost of each candidate execution plan according to the I / O cost, CPU cost, and memory cost, and determine the target execution plan with the minimum target cost; regenerate the target statement according to the target execution plan.
[0154] It should be noted that the above Figure 3 Each module in can be a program module (for example, a set of program instructions that implements a specific function), or a hardware module. For the latter, it can be presented in the following forms, but not limited to: the presentation form of each of the above modules is a processor, or the functions of each of the above modules are implemented by a processor.
[0155] It should be noted that Figure 3 The preferred implementation manners of the embodiments shown can be referred to Figure 1 the relevant descriptions of the embodiments shown, and will not be elaborated here.
[0156] Figure 4 shows a hardware structure block diagram of a computer terminal for implementing a model training method. As Figure 4As shown, the computer terminal 40 may include one or more processors 402 (shown as 402a, 402b, ……, 402n in the figure) (the processor 402 may include, but is not limited to, processing devices such as a microprocessor MCU or a programmable logic device FPGA), a memory 404 for storing data, and a transmission module 406 for communication functions. In addition, it may further include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the BUS bus), a network interface, a power supply, and / or a camera. Those of ordinary skill in the art can understand that Figure 4 the structure shown is only schematic and does not limit the structure of the above-mentioned electronic device. For example, the computer terminal 40 may further include more or fewer components than Figure 4 shown in, or have a different configuration from Figure 4 that shown.
[0157] It should be noted that the above one or more processors 402 and / or other data processing circuits can generally be referred to as "data processing circuits" in this article. The data processing circuit may be embodied in software, hardware, firmware, or any combination thereof, in whole or in part. In addition, the data processing circuit may be a single independent processing module, or be incorporated in whole or in part into any one of the other elements in the computer terminal 40. As involved in the embodiments of the present application, the data processing circuit is a kind of processor control (such as the selection of a variable resistance terminal path connected to an interface).
[0158] The memory 404 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the model training method in the embodiments of the present application. The processor 402 executes various functional applications and data processing by running the software programs and modules stored in the memory 404, that is, implements the above-mentioned model training method. The memory 404 may include a high-speed random access memory, and may further include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memories. In some instances, the memory 404 may further include a memory remotely set relative to the processor 402, and these remote memories can be connected to the computer terminal 40 through a network. Examples of the above network include, but are not limited to, the Internet, an enterprise intranet, a local area network, a mobile communication network, and combinations thereof.
[0159] The transmission module 406 is used to receive or send data via a network. Specific examples of the above-mentioned network may include a wireless network provided by the communication provider of the computer terminal 40. In one example, the transmission module 406 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission module 406 can be a Radio Frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0160] The display can be, for example, a touch-screen liquid crystal display (LCD), which enables users to interact with the user interface of the computer terminal 40.
[0161] It should be noted here that in some alternative embodiments, the above Figure 4 shown computer terminal may include hardware elements (including circuits), software elements (including computer code stored on a computer-readable medium), or a combination of both hardware elements and software elements. It should be pointed out that Figure 4 is only an example of a specific specific instance and is intended to show the types of components that may exist in the above computer terminal.
[0162] It should be noted that Figure 4 the shown computer terminal is used to execute Figure 1 the shown model training method. Therefore, the relevant explanations in the execution method of the above commands also apply to this electronic device, which will not be elaborated here.
[0163] The embodiment of the present application also provides a non-volatile storage medium. The non-volatile storage medium includes a stored program, wherein when the program runs, it controls the device where the storage medium is located to execute the above model training method.
[0164] The program executed by the non-volatile storage medium has the following functions: obtaining a plurality of Structured Query Language templates; traversing the plurality of Structured Query Language templates, and when traversing the plurality of Structured Query Language templates, searching for a target function in a target database that has a mapping relationship with the Structured Query Language template; using the target function to generate random characters, and replacing the placeholder in the Structured Query Language template with the random characters to obtain a target statement; determining a data object corresponding to the target statement in the target database, and determining an answer message in the large language model according to the data object; receiving a question message that matches the answer message, and training the large language model according to the answer message and the question message that matches the answer message.
[0165] An embodiment of the present application also provides an electronic device, including: a memory and a processor, where the processor is configured to run a program stored in the memory, and when the program runs, it executes the above model training method.
[0166] The processor is configured to run a program that performs the following functions: obtaining a plurality of Structured Query Language templates; traversing the plurality of Structured Query Language templates, and when traversing the plurality of Structured Query Language templates, searching for a target function in a target database that has a mapping relationship with the Structured Query Language template; generating random characters using the target function, and replacing the placeholder in the Structured Query Language template with the random characters to obtain a target statement; determining a data object corresponding to the target statement in the target database, and determining an answer message in the large language model according to the data object; receiving a question message that matches the answer message, and training the large language model according to the answer message and the question message that matches the answer message.
[0167] The serial numbers of the embodiments of the present application above are only for description and do not represent the advantages or disadvantages of the embodiments.
[0168] In the above embodiments of the present application, the descriptions of each embodiment have their own emphases. For parts not detailed in a certain embodiment, reference may be made to the relevant descriptions of other embodiments.
[0169] In the above embodiments of the present application, the information collected is information and data authorized by the user or fully authorized by all parties, and the processing of relevant data such as collection, storage, use, processing, transmission, provision, disclosure, and application complies with relevant laws, regulations, and standards, takes necessary protection measures, does not violate public order and good customs, and provides a corresponding operation entry for the user to choose to authorize or refuse.
[0170] In several embodiments provided by the present application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only illustrative. For example, the division of the units can be a logical function division, and in actual implementation, there can be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection between each other can be through some interfaces, and the indirect coupling or communication connection of units or modules can be in an electrical or other form.
[0171] The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they can be located in one place, or they can be distributed to multiple units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0172] In addition, each functional unit in various embodiments of the present application may be integrated into one processing unit, may exist separately physically for each unit, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of a software functional unit.
[0173] If the above-mentioned integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it may be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present application, in essence, or the part that contributes to the related technology, or all or part of the technical solution, may be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present application. The foregoing storage medium includes: various media such as USB flash drives, read-only memories (ROMs), random access memories (RAMs), mobile hard disks, magnetic disks, or optical discs that can store program codes.
[0174] The above are only the preferred embodiments of the present application. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present application, several improvements and refinements can be made, and these improvements and refinements should also be regarded as the protection scope of the present application.
Claims
1. A model training method, characterized in that: include: Get multiple structured query language templates; Traversing the plurality of structured query language templates, and searching a target database for a target function that has a mapping relationship with the structured query language template when traversing the plurality of structured query language templates; Generating random characters using the target function, and replacing placeholders in the structured query language template with the random characters to obtain a target statement; Determine a data object corresponding to the target sentence in the target database, and determine a response message in a large language model according to the data object; A question message matching the answer message is received, and a large language model is trained based on the answer message and the question message matching the answer message.
2. The method according to claim 1, characterized in that After replacing the placeholders in the structured query language template with the random characters to obtain the target sentence, the method further includes: Parsing the target statement into an abstract syntax tree, and extracting target information from the abstract syntax tree, wherein the target information includes at least one of the following: table name, operation type, and filter condition; Traversing the preconfigured rules, and determining whether the target statement and the target information conform to the preconfigured rules; After completing the traversal of the pre-configured rules, generating a judgment result, wherein the judgment result indicates whether the target statement and the target information conform to the pre-configured rules through a Boolean value; In a case where the judgment result indicates that the target sentence and / or the target information does not conform to the preconfigured rule, a target message is generated for characterizing the reason for not conforming to the preconfigured rule.
3. The method according to claim 2, characterized in that Traversing the preconfigured rules to determine whether the target statement and the target information conform to the preconfigured rules includes: In the case of traversing to the deletion prohibition rule, determining whether the operation type is a first preset character, and checking whether the data table associated with the operation type is in a preset list, wherein the first preset character includes: a character used to indicate a deletion operation; In the case of traversing to the query filter condition rule, determining whether the target statement includes the target filter condition specified in the rule; In the case of traversing to the maximum record number restriction rule, determining whether the target statement includes a first preset clause, wherein the first preset clause is used to limit the number of rows returned by the query result set; In the case where the target statement includes the first preset clause, determine whether the number of records specified by the first preset clause is within the maximum record number limit range; in the case where the target statement does not include the first preset clause, determine the estimated size of the result set queried by the target statement, and determine whether the estimated size is within the maximum record number limit range.
4. The method according to claim 1, characterized in that: Generating random characters using the objective function includes: Determining a target number of random numbers to be generated according to the number of placeholders in the structured query language template; Determine different preset numerical intervals corresponding to structured query statements of different dimensions, and for each of the preset numerical intervals, generate a first random number, wherein the first random number divides the preset numerical interval into two sub-intervals; For each of the preset numerical intervals, when generating the nth random number, a target number is randomly selected from the n preset numbers, and based on the value of the target number, a target sub-interval is determined from the n sub-intervals, and a random number is generated in the target sub-interval, where n is a positive integer ranging from 2 to N, and N is the target number.
5. The method according to claim 1, characterized in that After replacing the placeholders in the structured query language template with the random characters to obtain the target sentence, the method further includes: Determining whether a first delay between a submission node of the target statement and an execution node of the target statement is greater than a first preset threshold; According to the abstract syntax tree of the target sentence, split the target sentence into multiple running stages, determine the time interval between each running stage, and judge whether the time interval between each running stage is greater than a second preset threshold; Determine the business complexity index of the target statement according to the number of library tables associated with the target statement, the number of subqueries included in the target statement, whether there is a cross-table association in the target statement and the number of the cross-table associations, and the number of functions included in the target statement; Determine whether a first difference between the running time of the target statement and the running time of the historical statement is greater than a third preset threshold, wherein a difference in the business complexity index between the target statement and the historical statement is less than the preset threshold; When the first delay is greater than the first preset threshold and / or the time interval between each running stage is greater than the second preset threshold and / or the first difference is greater than the third preset threshold, the target statement is optimized.
6. The method according to claim 5, characterized in that Optimizing the target sentence includes: Traversing an abstract syntax tree of the target statement to identify a subquery structure in the abstract syntax tree; According to whether there is an association condition between the target sub-query structure and the external query structure, and whether the result corresponding to the target sub-query structure can be obtained through a join operation, determining whether the target sub-query structure can be converted into a join operation; In the case where it is determined that the target subquery structure can be converted into the join operation, the target subquery structure is deleted in the abstract syntax tree, and the table and the join condition corresponding to the target subquery structure are added to the second preset clause in the external query structure to obtain a target abstract syntax tree, wherein the second preset clause includes: a first statement for specifying a data source of query data and a second statement for filtering the data source specified by the first statement; Regenerate a target statement according to the target abstract syntax tree.
7. The method according to claim 5, characterized in that Optimizing the target sentence includes: Generate multiple candidate execution plans according to the abstract syntax tree of the target statement and metadata information of the target database, wherein the metadata information includes at least one of the following: table structure and index information, and there are differences between the candidate execution plans in terms of preset dimensions, and the preset dimensions include at least one of the following: access order for tables, connection mode, and whether to use indexes; In the case where the candidate execution plan uses an index to access data, determining the number of times to read index pages and data pages from the disk according to the structure of the index and the data distribution, and in the case where the candidate execution plan performs a full table scan, determining the number of I / O operations required to read the full table data; Determine the I / O cost of the candidate execution plan according to the number of times the index page and the data page are read from the disk or the number of I / O operations required to read the full table data; determine the CPU cost according to the CPU computing amount required for the candidate execution plan to perform a first operation on the data, wherein the first operation includes at least one of the following: filtering, sorting, and joining; determine the memory cost according to the memory capacity required for the candidate execution plan to perform a second operation on the data, wherein the second operation includes at least one of the following: sorting and joining; Determine a target cost for each of the candidate execution plans according to the I / O cost, the CPU cost, and the memory cost, and determine a target execution plan with the minimum target cost; According to the target execution plan, the target statement is regenerated.
8. A data processing method, characterized in that: include: Receive a question message, analyze the question message using a large language model, and obtain an answer message corresponding to the question message, wherein the large language model is obtained by training using the model training method described in any one of claims 1 to 7.
9. A model training device, characterized in that: include: An acquisition module, used for acquiring multiple structured query language templates; A search module, configured to traverse the plurality of structured query language templates, and when traversing the plurality of structured query language templates, search in a target database for a target function that has a mapping relationship with the structured query language template; A generating module, configured to generate random characters using the target function, and replace the placeholders in the structured query language template with the random characters to obtain a target statement; A determination module, configured to determine a data object corresponding to the target sentence in the target database, and determine a response message in a large language model according to the data object; The training module is used to receive a question message that matches the answer message, and train a large language model based on the answer message and the question message that matches the answer message.
10. A non-volatile storage medium, characterized in that: The non-volatile storage medium includes a stored program, wherein when the program is running, the device where the non-volatile storage medium is located is controlled to execute the model training method described in any one of claims 1 to 7.
11. An electronic device, characterized in that: include: A memory and a processor, wherein the processor is used to run a program stored in the memory, wherein the program executes the model training method described in any one of claims 1 to 7 when running.
12. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the model training method described in any one of claims 1 to 7 is implemented.
Citation Information
Cited By
SQL (Structured Query Language) statement analysis optimization method and system based on large language model
CN120353822A
Method for generating SQL (structured query language) from natural language based on bidirectional mapping and semantic analysis
CN120910087A
Query plan result data set rapid generation method
CN121188092A
Question and answer query method, system and equipment for data table and medium
CN121560925A