Power field Text2SQL intelligent generation method based on prompt enhancement and progressive optimization
By building an adaptive Text2SQL system in the power field, using prompt guidance SQL synthesizer, semantic mapping SQL generator and feedback-driven SQL optimizer, the problem of scarcity of data and low accuracy of multi-table association queries in the power field is solved, efficient natural language to SQL statement conversion is achieved, and the data processing capability of the power system is improved.
Patent Information
- Application Number
- CN202510526876.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-25
- Publication Date
- 2025-08-01
AI Technical Summary
Text2SQL technology in the power field faces the problem of insufficient data set coverage due to device coding and professional terms, and low accuracy of large language models in multi-table association query.
The modular design of three-level linkage includes a prompt-guided SQL synthesizer, a semantic mapping SQL generator and a feedback-driven SQL optimizer, and build an adaptive Text2SQL system in the power field, generate high-quality training data through the grid database Schema information, and combine large language models for multi-stage processing and multi-level evaluation to ensure that the generated SQL queries comply with power business logic and syntax specifications.
It significantly improves the ability to convert SQL statements from natural language query in the power field, solves the problems of scarcity of data and complex patterns, improves query accuracy and business adaptability, and improves the operation and maintenance efficiency of the power system and user satisfaction.
Smart Images

Figure CN120407604A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical fields of large language models and data processing technologies, and in particular, to a Text2SQL intelligent generation method for the power field based on prompt enhancement and progressive optimization. Background Art
[0002] In the power field, a large amount of business data is stored in relational databases, and operation and maintenance personnel need to frequently query key information such as grid operation status, equipment load, and fault records. Traditional SQL queries rely on professional technicians, resulting in significant barriers for business personnel to obtain data. Although Text2SQL technology can convert natural language into SQL queries, existing solutions face two core challenges in the power field: 1) The unique equipment coding and professional terms in the power industry (such as "loading ratio" and "feeder load rate") lead to insufficient coverage of general Text2SQL datasets (such as Spider), and the manual annotation cost is extremely high; 2) Existing large language models (such as GPT-4 and Llama) have low accuracy when generating complex queries involving multi-table associations (such as the three-level schema of substation-equipment-load data). Therefore, there is an urgent need for a Text2SQL solution that integrates domain-enhanced knowledge and progressive optimization to break through the dual limitations of data and models. Summary of the Invention
[0003] Object of the Invention: To overcome the deficiencies of the background art, the present invention discloses a Text2SQL intelligent generation method for the power field based on prompt enhancement and progressive optimization. Through a three-level linked modular design, domain adaptation of power Text2SQL is achieved: the prompt-guided SQL synthesizer constructs domain-specific training data, the semantic mapping SQL generator realizes high-precision pattern-aware conversion, and the feedback-driven SQL optimizer ensures business compliance, effectively improving the conversion ability from natural language queries to SQL statements in the power field and solving the three core problems of data scarcity, complex patterns, and business adaptation.
[0004] Technical Solution: The present invention discloses a Text2SQL intelligent generation method for the power field based on prompt enhancement and progressive optimization, including the following steps:
[0005] S1 Construct a prompt-guided SQL synthesizer, collect Schema information of the power grid database, and use a large language model to generate a high-quality Text2SQL dataset. The specific implementation steps are as follows:
[0006] S11 Collect the grid database table structure information, including core metadata such as table name (Table), column name (Column), primary keys, foreign keys, and field types (data types, such as INTEGER, VARCHAR, DATE), and at the same time supplement power business feature information such as the collection device coding rules and field business meaning annotations;
[0007] S12 Design a data generation prompt template to guide the large language model to generate natural language query SQL statement data pairs. The prompt template is designed as: Here is a table named {Table}, which contains {num} fields, namely {Columns}; among them, the grid database Schema information: Table: substation (substation table) Columns: id (primary key), name (name), location (location); please generate the corresponding natural language query and corresponding SQL according to the Schema;
[0008] S13 Generate training data. Use the ChatGPT-3.5 API to batch call the large language model, set parameters such as temperature = 0.7 and max_tokens = 256, and automatically generate 20 groups of query-SQL pairs for each Schema combination, covering training data for 6 typical query types such as single-table exact query, multi-table association query, and aggregation statistical query.
[0009] S2 Clean, optimize, and standardize the format of the data generated in S1 to construct a training data set and a test data set. The specific implementation steps are as follows:
[0010] S21 Text preprocessing. This includes data cleaning, term matching, part-of-speech tagging, and simple data augmentation;
[0011] S22 SQL preprocessing. This includes SQL syntax checking, SQL structure standardization, and Schema verification;
[0012] S23 Construct training and test data sets. This includes data partitioning and data storage.
[0013] S3 Design a semantic mapping SQL generator to accurately convert natural language queries into SQL statements that conform to power business logic through multi-stage processing. The specific implementation steps are as follows:
[0014] S31 Schema Linking. Use natural language processing technology to parse the user query: First, decompose the query text into lexical units and label the grammatical roles through a word segmentation and part-of-speech tagging tool; then calculate the semantic similarity between the query vocabulary and the database Schema based on the Word2Vec model enhanced with power domain knowledge, and finally determine which database tables and fields are relevant to the query through similarity measurement;
[0015] S32 Schema Ranking. Calculate the weight of the table based on historical queries, and then calculate the Schema correlation degree to avoid unnecessary participation of multiple tables;
[0016] S33 Generate candidate SQL based on the pre-trained G-model. The model uses power domain text and SQL statements for continuous pre-training to significantly improve the understanding ability of professional terms;
[0017] S34 Fine-tune the G-model, use the task of converting text to SQL, and construct a basic loss function;
[0018] S35 Introduce a dual-supervision mechanism: a query semantic matching loss function and a result consistency loss function to improve the generalization ability of the model;
[0019] S36 Use the Adam optimizer for model training, set the learning rate to 5e-5, the weight decay to 0.1, the batch size to 32, and prevent overfitting through the early stopping strategy (patience = 5).
[0020] S4 Construct a feedback-driven SQL optimizer to ensure that the generated SQL query has both syntactic correctness and business compliance through a multi-level evaluation mechanism. The specific steps are as follows:
[0021] S41 Collect SQL queries D related to power business from the SQL historical data in the power grid domain, and standardize the collected SQL queries, including query fields F i 、table names T i and filtering conditions C i etc.;
[0022] S42 Select the optimal SQL by comparing the generated SQL query with the actual query results in the historical data;
[0023] S43 Select the SQL query that best matches the historical data and business requirements through Few-shot Learning technology;
[0024] S44 After the generated SQL query is evaluated by the G-Model, sort the query results and select the optimal query as the final output;
[0025] S45 Multi-level evaluation and execution, select the SQL query with the shortest execution time and correct results as the final output.
[0026] S5 Set multiple key evaluation metrics and measure the performance of the model based on these metrics. Specifically include accuracy, execution accuracy, precision, recall, and F1 score.
[0027] S6 Based on the evaluation results, combine adversarial training to enhance the robustness of the model; at the same time, optimize the hyperparameters of the model through automatic hyperparameter tuning technology to finally achieve the optimal power large language model.
[0028] S61 Generate adversarial samples by adding random noise perturbations to enhance the robustness of the model;
[0029] S62 Introduce an adversarial loss function, and by minimizing the adversarial loss, make the model learn how to still generate correct SQL queries under irregular or perturbed data inputs;
[0030] S63 Use automatic hyperparameter tuning technology to optimize the model parameters, specifically including initializing the hyperparameter space, modeling the hyperparameter space using Gaussian processes, maximizing the objective function (F1 score), continuously updating the probability distribution of the hyperparameters to adjust the next search direction, and finally selecting the best hyperparameter combination;
[0031] S64 Combine adversarial training and automatic hyperparameter tuning to obtain an optimized power large language model.
[0032] S7 Efficiently deploy the optimized power large language model to the production environment and ensure the stability, response speed, and model performance of the system through real-time monitoring.
[0033] Advantages of the present invention: The present invention has made innovative designs for data processing and Text2SQL systems in the power field, effectively solving problems such as insufficient data, complex and difficult-to-understand database schemas, and difficult business adaptation, achieving remarkable results. Specifically, in response to the problem of the lack of high-quality training data in the power industry, the present invention first proposes a prompt-guided SQL synthesizer, designs a data generation prompt template based on the power field Schema, and combines large language models to automatically generate a training data set, making up for the defect of insufficient data. Secondly, in response to the challenge that the power grid database schema is complex and difficult to directly combine with large language models to generate SQL queries, the present invention adopts a semantic mapping SQL generator. Through domain-enhanced Schema linking technology and large model fine-tuning mechanisms, the model can provide more accurate SQL queries in different query types and complex data scenarios. Finally, this paper introduces a feedback-driven SQL optimizer module, which innovatively uses a multi-level evaluation mechanism to ensure that the generated SQL queries not only conform to syntax specifications but also meet the requirements of power business. In addition, the present invention provides strong data support for the operation and decision-making of power systems, comprehensively improving the power data analysis and processing capabilities, making power systems more intelligent and efficient in the face of complex query requirements, thereby improving operation and maintenance efficiency and user satisfaction. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] Figure 1 is a flowchart of the method of the present invention;
[0035] Figure 2 is a schematic diagram of the prompt template designed by the present invention and the generated data set;
[0036] Figure 3 is a schematic diagram of the use of the feedback-driven SQL optimizer designed by the present invention. DETAILED DESCRIPTION OF THE INVENTION
[0037] The following will describe the specific implementation manners of the present invention in conjunction with the drawings, so that those skilled in the art can better understand the present invention.
[0038] As Figure 1 shown, the specific process of the present invention includes the following steps:
[0039] S1 Construct a prompt-guided SQL synthesizer, collect Schema information of the power grid database, and use a large language model to generate a high-quality Text2SQL data set, as Figure 2 shown. The specific implementation steps are as follows:
[0040] S11 collects the structure information of the power grid database tables, including core metadata such as table names (Table), column names (Column), primary keys (Primary Keys), foreign keys (Foreign Keys), and column types (data types, such as INTEGER, VARCHAR, DATE), etc. At the same time, it supplements the power business feature information such as the acquisition device coding rules and annotations of the business meaning of the fields;
[0041] S12 designs a data generation prompt template to guide the large language model to generate natural language query SQL statement data pairs. The prompt template is designed as: Here is a table named {Table}, which contains {num} fields, namely {Columns}; among them, the power grid database Schema information: Table: substation (substation table), Columns: id (primary key), name (name), location (location); please generate the corresponding natural language query and corresponding SQL according to the Schema;
[0042] S13 generates training data. It uses the ChatGPT-3.5 API to batch call the large language model, sets parameters such as temperature = 0.7 and max_tokens = 256, and automatically generates 20 groups of query-SQL pairs for each Schema combination, covering the training data of 6 typical query types such as single-table exact query, multi-table association query, and aggregation statistical query.
[0043] S2 cleans, optimizes, and standardizes the format of the data generated in S1 to construct a training data set and a test data set. The specific implementation steps are as follows:
[0044] S21 Text preprocessing. Data cleaning uses regular expressions to remove HTML tags, special symbols, and non-standard characters:
[0045] Text cleaned = re.sub(<.*>,"",text)
[0046] Among them, re.sub represents the regular expression replacement operation, <.*> matches HTML tags, text represents the text, and Text cleaned represents the text with HTML tags removed. Data optimization and format standardization also use regular expressions to standardize line breaks, spaces, etc. to ensure that all text formats are consistent:
[0047] Text norm = re.sub('\s+',"",Text cleaned )
[0048] Among them, re.sub is used to remove the special characters '\s+' and "", and Textnorm Represents the preprocessed text. The text is tokenized based on spaces and punctuation marks, and part-of-speech tagging is performed on the tokenization results; at the same time, power industry terms (such as "load", "substation") are recognized, and synonyms are expanded using the power grid term library and the sentence component order is adjusted to improve data diversity and ensure the model's robustness to different expressions;
[0049] S22 SQL preprocessing. Use an SQL parser to check whether the SQL syntax is correct, and at the same time standardize the SQL statement format to ensure the consistency of the SQL structure. Compare with the power grid database Schema to ensure the validity of table names and field names (avoid using non-existent fields);
[0050] S23 Construct training and test datasets. Randomly divide the data into 80% training set and 20% test set, and ensure that the SQL complexity distributions of the training and test data are consistent.
[0051] S3 Design a semantic mapping SQL generator to accurately convert natural language queries into SQL statements that conform to power business logic through multi-stage processing. The specific implementation steps are as follows:
[0052] S31 Schema Linking. Use natural language processing techniques to parse user queries: First, decompose the query text into lexical units and label the syntactic roles using a tokenizer and part-of-speech tagger; then calculate the semantic similarity between the query terms and the database Schema based on the Word2Vec model enhanced with power domain knowledge:
[0053]
[0054] Among them, S(T,C) represents the similarity between the query text T and the database Schema C, t i is the query term, c i is the candidate Schema term, and sim(t i ,c i ) is the semantic similarity function. Determine which database tables and fields are relevant to the query through similarity measurement (set the threshold to 0.7);
[0055] S32 Schema Ranking. Calculate the weight of the table based on historical queries, and then calculate the Schema relevance to avoid unnecessary multi-table participation:
[0056] R(S) = αF freq (S) + βF join (S) + γF relevance (S)
[0057] Among them, R(S) is the sorting score of the table or field, Ffreq F is the access frequency of the table join F is the participation complexity of the table relevance α, β, and γ are adjustment parameters. According to the scores, a sorting value will be assigned to each candidate table and field, and the combination of the table and field with the highest score will be selected. This combination will be used as the basis for generating the SQL query;
[0058] S33 generates candidate SQLs based on the pre-trained G-model, which is continuously pre-trained using texts in the power domain and SQL statements, significantly improving the ability to understand professional terms;
[0059] S34 fine-tunes the G-model using the task of converting text to SQL, and its basic loss function is L Text2SQL :
[0060]
[0061] where N is the number of queries, M is the total number of tables and fields, and y ij represents the actual label, and P ij represents the model prediction probability;
[0062] S35 introduces a dual-supervision mechanism: a query semantic matching loss function and a result consistency loss function to improve the generalization ability of the model. The total loss function is expressed as:
[0063]
[0064] L = λ Text2SQL L Text2SQL + λ match L match + λ consistency L consistency
[0065] where λ Text2SQL , λ match , and λ consistency are weight coefficients, L match is the query semantic matching loss function, and L consistency is the result consistency loss function; Q i and S i are the vector representations of the i-th natural language query and its corresponding SQL query, respectively; <Q i , S i > is their inner product, indicating the similarity between the two; ||Q i || and ||S i || are the norms of the natural language query and the SQL query, respectively; R true is the result returned by the target query, and R pred is the result of the SQL query generated by the model; It is an indicator function that has a value of 1 when the two are inconsistent and a value of 0 when they are consistent;
[0066] In S36, the Adam optimizer is used for model training, with a learning rate of 5e-5, a weight decay of 0.1, and a batch size of 32. Early stopping (patience = 5) is used to prevent overfitting.
[0067] In S4, a feedback-driven SQL optimizer is constructed, and a multi-level evaluation mechanism is used to ensure that the generated SQL queries are both syntactically correct and business compliant, as Figure 3 shown. The specific steps are as follows:
[0068] In S41, SQL queries D related to power operations are collected from the SQL historical data in the power grid domain, and the collected SQL queries are standardized, including query fields F i , table names T i and filtering conditions C i etc.:
[0069] D = {S1, S2,..., S N}
[0070] D std = {(S i , F i , T i , C i )}
[0071] Among them, D std represents the set of standardized SQL, and S i represents the i-th SQL statement;
[0072] In S42, the generated SQL query is compared with the actual query results in the historical data to select the optimal SQL:
[0073] score(S gen , S i ) = ω1Sim(F gen , F i ) + ω2Sim(T gen , T i ) + ω3Sim(C gen , C i )
[0074] Among them, Sim(A, B) represents the Jaccard similarity between sets A and B, ω1, ω2, and ω3 are weight parameters. When score(S gen , S i ) is the largest: Select the optimal SQL candidate;
[0075] S43 selects the SQL query that best matches the historical data and business requirements through Few-shot Learning technology; the model input is defined as: where Q k is the natural language query, are multiple candidate results; calculate the matching degree between the SQL statement and the query Q k :
[0076]
[0077] where f(Q, S) is the matching score between the query Q and the SQL S. Conduct Few-shot training under the supervision of maximizing the likelihood loss:
[0078]
[0079] where is the optimal SQL;
[0080] After the SQL query generated by S44 is evaluated by the G-Model, the query results are sorted, and the optimal query is selected as the final output:
[0081]
[0082] where score(S i , Q i ) is the scoring value calculated by the G-model, indicating the matching degree between the SQL query S i and the natural language query Q i ;
[0083] S45 comprehensively evaluates and executes, and selects the SQL query with the shortest execution time and correct results as the final output.
[0084] S5 sets multiple key evaluation indicators and measures the performance of the model based on these indicators. Specifically, it includes execution accuracy, precision, recall, and F1 score.
[0085] Based on the evaluation results, S6 combines adversarial training to enhance the robustness of the model; at the same time, it optimizes the hyperparameters of the model through automatic tuning technology to finally achieve the optimal power large language model; the specific steps are as follows:
[0086] S61 Adversarial sample generation. Generate adversarial samples by adding random noise perturbations to enhance the robustness of the model;
[0087] S62 introduces an adversarial loss function. By minimizing the adversarial loss, the model learns how to generate correct SQL queries even under irregular or perturbed data inputs. The loss function consists of two parts, the standard cross-entropy loss (used to measure the correctness of the SQL queries generated by the model) and the adversarial loss (used to enhance the model's robustness to perturbations). The adversarial loss is described as:
[0088]
[0089] where Q orig is the original input, δ is the generated noise perturbation, f(Q orig + δ) is the SQL query generated by the model, and y i is the target SQL query;
[0090] S63 uses an automatic hyperparameter tuning technique to optimize the model parameters. Specifically, it includes initializing the hyperparameter space, modeling the hyperparameter space using a Gaussian process, maximizing the objective function (F1 score), continuously updating the probability distribution of the hyperparameters to adjust the next search direction, and finally selecting the best hyperparameter combination;
[0091] S64 combines adversarial training and automatic hyperparameter tuning to obtain an optimized power large language model.
[0092] S7 efficiently deploys the optimized power large language model to the production environment and ensures the stability, response speed, and model performance through real-time monitoring. Specifically, it containerizes the power large language model using Docker, then uses Kubernetes for cluster management and automatic scaling, and finally combines Prometheus and Grafana for real-time monitoring.
[0093] It should be further noted that:
[0094] (1) To fully verify the superiority of the methods of the present invention, it was compared with benchmark models. The benchmark models include resdsql, which ranks highest in the spider leaderboard, and RATSQL, a model widely recognized in the Text2SQL field. The execution accuracy (EX) and exact match accuracy (EM) are used to evaluate the models. The experimental results shown in Table 1 indicate that the present invention achieved excellent results in both EX and EM aspects.
[0095] Table 1 Performance comparison between the present invention and existing advanced methods
[0096] model EM EX RATSQL 51.6 65.8 resdsql 58.8 71.3 the present invention 67.9 81.2
[0097] (2) The implementation method of the present invention involves executing each step described in the present invention by means of computer program control of hardware. Specifically, to implement all or part of the processes in the above method, relevant hardware can be processed by computer program instructions. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, the corresponding operations can be completed in accordance with the processes of the above method embodiments. Among them, any reference to the memory, storage, database or other media involved in the embodiments provided in the present application may include non-volatile memory and / or volatile memory.
[0098] (3) Those of ordinary skill in the art can clearly understand that, for the sake of convenience and brevity of description, we use the above-mentioned division method of functional units or modules for illustrative purposes. However, in actual applications, the above functional units or modules can be divided into different functional units or modules according to needs to complete all or part of the functions in the method of the present invention.
[0099] (4) The above-described embodiments are only used to illustrate the technical solutions of the present invention and do not limit them. Although we have described the specific embodiments of the present invention in detail, those of ordinary skill in the art should understand that they can modify the technical solutions in the foregoing embodiments or perform equivalent replacements for some of the technical features; and these modifications or replacements do not deviate from the core spirit and scope embodied in the embodiments of the present invention and should be included within the protection scope of the present invention.
Claims
1. A Text2SQL intelligent generation method for the power field based on prompt enhancement and progressive optimization, characterized in that The high-quality data generation method and multi-stage progressive optimization strategy for large language models in the power industry include the following steps: S1 Construct a prompt-guided SQL synthesizer, collect the Schema information of the power grid database, and use a large language model to generate a high-quality Text2SQL dataset; S2 Preprocess the data generated in S1, and divide the training and test datasets; S3 Design a semantic mapping SQL generator, and accurately convert natural language queries into SQL statements that conform to the power business logic through multi-stage processing; S4 Construct a feedback-driven SQL optimizer, and ensure that the generated SQL queries have both syntactic correctness and business compliance through a multi-level evaluation mechanism; S5 Set multiple key evaluation indicators, and measure the performance of the model based on these indicators; specifically including accuracy, execution accuracy, precision, recall, and F1 score; S6 Based on the evaluation results, combine adversarial training to enhance the robustness of the model; at the same time, optimize the hyperparameters of the model through automatic tuning technology to finally achieve the optimal large language model for power; S7 Efficiently deploy the optimized large language model for power to the production environment, and ensure the stability, response speed, and model performance of the system through real-time monitoring.
2. The data intelligent optimization method for the power business system based on large language model-driven Text2SQL according to claim 1, wherein, The step S1 includes the following steps: S11 Collect the table structure information of the power grid database, and supplement the collection of power business feature information such as device coding rules and field business meaning annotations; S12 Design a data generation prompt template for guiding the large language model to generate natural language query SQL statement pairs; the prompt template is designed as: Here is a table named {Table}, which contains {num} fields, namely {Columns}; among them, the power grid database Schema information: Table: substation substation table Columns: id primary key, name name, location location; please generate the corresponding natural language query and corresponding SQL according to the Schema; S13 Generate training data: Batch call the large language model using the ChatGPT-3.5 API, set parameters such as temperature = 0.7 and max_tokens = 256, and automatically generate 20 groups of query-SQL pairs for each Schema combination, covering the training data of 6 types of typical queries such as single-table exact query, multi-table association query, and aggregation statistical query.
3. An intelligent optimization method for power business system data based on large language model-driven Text2SQL according to claim 1, characterized in that, The step S2 includes the following steps: S21 Text preprocessing: including data cleaning, term matching, part-of-speech tagging, and simple data augmentation; Text cleaned = re.sub(<.*>,"", text) It should be noted that there seems to be an error in the original Chinese expression " cleaned " which is not a standard Python syntax. And the original expression "<.*>” is also not in the correct Python regular expression format. The above translation is based on the best understanding and correction of the possible correct content. Text norm = re.sub('\s+', "", Text cleaned ) Among them, re.sub represents the regular expression replacement operation, <.*> matches HTML tags, text represents the text, and Text cleaned represents the text with HTML tags removed, Text norm represents the preprocessed text; S22 SQL preprocessing: including SQL syntax checking, SQL structure standardization, and Schema verification; S23 Construct training and test datasets: including data division and data storage.
4. An intelligent optimization method for power business system data based on large language model-driven Text2SQL according to claim 1, characterized in that, The step S3 includes the following steps: S31 Schema Linking: Parse natural language queries and extract keywords that may be related to the database Schema; S32 Schema Ranking: Establish a weighted scoring model based on historical queries to avoid unnecessary multi-table participation; S33 Use the G-model to generate SQL statements suitable for the power industry scenario; S34 Fine-tune the G-model, adopt the task of converting text to SQL, and construct a loss function: where N is the number of queries, M is the total number of tables and fields, and y ij represents the actual label, and P ij represents the model prediction probability; S35 Introduce a dual-supervision mechanism, construct a composite loss function, improve the generalization ability of the model, and then obtain the total loss function: L = λ Text2SQL L Text2SQL + λ match L match + λ consistency L consistency Among them, λ Text2SQL , λ match , λ consistency are weight coefficients, L match is the query semantic matching loss function, and L consistency is the result consistency loss function; Q i and S i are the vector representations of the i-th natural language query and its corresponding SQL query respectively; <Q i , S i > is their inner product, indicating the similarity between the two; ||Q i || and ||S i || are the norms of the natural language query and the SQL query; R true is the result returned by the target query, and R pred is the result of the SQL query generated by the model; is the indicator function, which is 1 when the two are inconsistent and 0 when they are consistent; S36 Model optimization, use the Adam optimizer to train the model.
5. A method for intelligent optimization of power business system data based on large language model-driven Text2SQL according to claim 1, characterized in that, The step S4 includes the following steps: S41 Collect SQL queries related to power operations from the SQL historical data in the power grid field, and standardize the collected SQL queries; S42 Select the optimal SQL by comparing the generated SQL query with the actual query results in the historical data: score(S gen ,S i ) = ω1Sim(F gen ,F i ) + ω2Sim(T gen ,T i ) + ω3Sim(C gen ,C i ) Among them, Sim(A,B) represents the Jaccard similarity between sets A and B, ω1, ω2, ω3 are weight parameters. When score(S gen ,S i ) is the maximum: Select the optimal SQL candidate; S43 Select the SQL query that best matches the historical data and business requirements through Few-shot Learning technology; After the generated SQL query is evaluated by the G-Model, sort the query results and select the optimal query as the final output; 6. The data intelligent optimization method for the power business system based on large language model-driven Text2SQL according to claim 1, characterized in that S45 Comprehensive evaluation and execution, select the SQL query with the shortest execution time and correct results as the final output. The step S6 includes the following steps: S61 Generate adversarial samples by adding random noise perturbations to enhance the robustness of the model; Among them, Q orig is the original input, δ is the generated noise perturbation, and f(Q orig +δ) is the SQL query generated by the model, and y i is the target SQL query; S62 Introduce an adversarial loss function, and by minimizing the adversarial loss, enable the model to learn how to generate correct SQL queries under irregular or perturbed data inputs: S63 Adopt an automatic hyperparameter tuning technique to optimize the model parameters, specifically including initializing the hyperparameter space, modeling the hyperparameter space using a Gaussian process, maximizing the objective function, continuously updating the probability distribution of the hyperparameters to adjust the next search direction, and finally selecting the best hyperparameter combination; S64 Combine adversarial training and automatic hyperparameter tuning to obtain an optimized large language model for power.
Citation Information
Cited By
Database sub-mode division-based txt-to-sql generation method
CN121636549A
Large model illusion suppression intelligent question answering system and method based on deep learning
CN121722786A