Data processing method and device, electronic equipment, computer readable storage medium and computer program product
By expanding the training dataset and conducting multiple rounds of training, the training data of the Text-to-SQL model was improved, which addressed the model's shortcomings in diversity and complexity, improved the accuracy and adaptability of query statements, and achieved more efficient database query and analysis.
Patent Information
- Application Number
- CN202510329582.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-19
- Publication Date
- 2025-09-26
AI Technical Summary
In existing technologies, Text-to-SQL models lack the diversity and complexity of SQL query statements in training datasets, resulting in limited reasoning capabilities of the models when faced with the diversity and complexity of the real world, and an inability to accurately parse and generate complex SQL query statements.
By expanding the model training data set, the first model is preliminarily trained using the first training data, and the second training data is generated to correct model errors. Through multiple rounds of training, the model's ability to handle diverse inputs is improved, including matching database pattern items and generating predictive query statements.
The accuracy and generalization ability of the model's query generation have been improved, enabling it to better handle diverse inputs and enhancing its adaptability to different database models and the accuracy of query statements.
Smart Images

Figure CN120705164A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a data processing method, device, electronic device, computer-readable storage medium, and computer program product. Background Art
[0002] Semantic parsing is one of the core tasks of natural language processing technology. The text-to-query statement (Text-to-SQL) task is one of the semantic parsing technologies. The Text-to-SQL task allows the machine to automatically convert natural language questions entered by users into database query statements (SQL query statements) that can be operated by the database, realizing automatic question-answering capabilities based on the database.
[0003] However, the inference path of the training samples of SQL query statements in related technologies is single, and the SQL query statements used in the training data set mainly follow one or several fixed patterns, or are too focused on certain specific query structures, association methods, condition combinations, etc. when designing queries, lacking sufficient diversity to fully reflect the complexity and richness of SQL query statements in the real world. Summary of the Invention
[0004] The embodiments of the present application provide a data processing method, device, electronic device, computer-readable storage medium, and computer program product, which can effectively improve the accuracy of the first model in converting questions into query statements by expanding the data set for model training.
[0005] The technical solution of the embodiment of the present application is implemented as follows:
[0006] The present invention provides a data processing method, including:
[0007] Based on a first question sample included in first training data, a first database pattern item matching the first question sample, and a first real query statement matching the first question sample, performing first training on a first model to obtain a first model that has undergone the first training;
[0008] Based on the first model trained by the first step, a second question sample and a second database pattern item matching the second question sample are converted to obtain a first predicted query statement;
[0009] In response to a mismatch between the first predicted query and the second question sample, generating second training data based on a difference between a second real query corresponding to the second question sample and the first predicted query;
[0010] Based on the first training data and the second training data, the first model that has undergone the first training is subjected to second training to obtain the first model that has undergone the second training.
[0011] The present application also provides a data processing method, including:
[0012] performing matching processing on the fifth question sample and the third database pattern item to obtain a third predicted correlation between the fifth question sample and the third database pattern item;
[0013] determining, based on the third predicted relevance, a fourth database pattern item that matches the fifth question sample from the third database pattern items;
[0014] The fifth question sample and the fourth database pattern item are transformed to obtain a fourth prediction query statement corresponding to the fifth question sample.
[0015] An embodiment of the present application provides a data processing device, including:
[0016] A first training module is configured to perform a first training on a first model based on a first question sample included in first training data, a first database pattern item matching the first question sample, and a first real query statement matching the first question sample, to obtain a first model that has undergone the first training;
[0017] a first prediction module, configured to convert a second question sample and a second database pattern item matching the second question sample based on the first trained first model to obtain a first prediction query statement;
[0018] an expansion module, configured to generate second training data based on a difference between a second real query statement corresponding to the second question sample and the first predicted query statement in response to a mismatch between the first predicted query statement and the second question sample;
[0019] The second training module is used to perform second training on the first model that has undergone the first training based on the first training data and the second training data to obtain the first model that has undergone the second training.
[0020] The present invention further provides a data processing device, including:
[0021] a first matching module, configured to perform matching processing on the fifth question sample and the third database pattern item to obtain a third predicted correlation between the fifth question sample and the third database pattern item;
[0022] The first matching module is further configured to determine, based on the third predicted relevance, a fourth database pattern item that matches the fifth question sample from the third database pattern items;
[0023] The second prediction module is used to convert the fifth question sample and the fourth database pattern item to obtain a fourth prediction query statement corresponding to the fifth question sample.
[0024] An embodiment of the present application provides an electronic device, including:
[0025] a memory for storing computer-executable instructions or computer programs;
[0026] The processor is used to implement the data processing method provided in the embodiment of the present application when executing the computer-executable instructions or computer programs stored in the memory.
[0027] An embodiment of the present application provides a computer-readable storage medium storing a computer program or computer-executable instructions, which is used to implement the data processing method provided in the embodiment of the present application when executed by a processor.
[0028] An embodiment of the present application provides a computer program product, including a computer program or computer-executable instructions. When the computer program or computer-executable instructions are executed by a processor, the data processing method provided in the embodiment of the present application is implemented.
[0029] The embodiments of the present application have the following beneficial effects:
[0030] First, a first model is preliminarily trained based on a first question sample, a first database pattern item matching the first question sample, and a real query statement corresponding to the first question sample contained in the first training data to obtain a first model after preliminarily training, thereby helping the first model understand the mapping relationship between the question and the query statement; then, the second question sample and the second database pattern item matching the second question sample are transformed and processed using the preliminarily trained first model to obtain a first predicted query statement, thereby evaluating the training effect of the preliminarily trained first model; subsequently, in response to a mismatch between the first predicted query statement and the second real query statement, second training data is generated based on the difference between the first predicted query statement and the second real query statement, which can subsequently help the model correct errors and correct the model output; using the first training data and the newly added second training data to perform a second training on the model can enable the model to better handle diverse inputs, help the model to better generalize, and thus improve the accuracy of the model in generating query statements based on the question. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1This is a schematic diagram of the model structure of the text-to-query statement task in related technologies;
[0032] Figure 2 1 is a schematic diagram of the architecture of a data processing system 100 provided in an embodiment of the present application;
[0033] Figure 3A is a structural diagram of an electronic device 500 provided in an embodiment of the present application;
[0034] Figure 3B 6 is a schematic structural diagram of an electronic device 600 provided in an embodiment of the present application;
[0035] Figure 4 Schematic diagram of the data processing method provided in the embodiment of the present application;
[0036] Figure 5 Schematic diagram of the data processing method provided in the embodiment of the present application;
[0037] Figure 6 Schematic diagram of the data processing method provided in the embodiment of the present application;
[0038] Figure 7 This is a flowchart of the Text-to-SQL task processing provided by an embodiment of the present application;
[0039] Figure 8 This is an architectural diagram of a table selection model provided in an embodiment of the present application;
[0040] Figure 9 This is an architectural diagram of the SQL parsing model provided in the embodiments of the present application. DETAILED DESCRIPTION
[0041] In order to make the purpose, technical solutions and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limiting this application. All other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0042] In the following description, reference is made to “some embodiments”, which describes a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0043] It is understandable that in the embodiments of the present application, when user information and other related data are involved, when the embodiments of the present application are applied to specific products or technologies, user permission or consent must be obtained, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards.
[0044] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program that has a predetermined function and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories) or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.
[0045] In the following description, the terms "first\second\..." are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It is understandable that "first\second\..." can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.
[0046] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application pertains. The terms used herein are for the purpose of describing the embodiments of this application only and are not intended to limit this application.
[0047] Before further explaining the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.
[0048] 1) Large Language Model (LLM): A large language model (LLM) is a language model with an extremely high parameter count, typically exceeding billions or even hundreds of billions. Trained with large amounts of text data, LLMs are capable of understanding and generating complex natural language text and performing various natural language processing tasks, such as text generation, machine translation, question answering, and conversational systems.
[0049] 2) Structured Query Language (SQL): Structured Query Language is a programming language specifically used to communicate with databases. It is the core language of relational database management systems and is used to manage (query, update, and delete) data in relational databases.
[0050] 3) Sequence to Sequence (Seq2Seq) Model: The Seq2Seq model is a deep learning model that is primarily used to process tasks where both input and output are sequence data, such as machine translation, speech recognition, and text summarization. The Seq2Seq model consists of two parts: an encoder and a decoder. Its core idea is to encode the input sequence into a fixed-length context vector, and then the decoder generates a target sequence based on this context vector.
[0051] In natural language processing tasks, semantic parsing is one of the core tasks of natural language processing technology. Text-to-SQL tasks are a type of semantic parsing technology. Text-to-SQL tasks allow machines to automatically convert natural language questions entered by users into SQL query statements that can be operated by the database, thereby realizing automatic question answering capabilities based on the database. Figure 1 , Figure 1 This is a schematic diagram of the model structure of the text-to-query statement task in related technologies, such as Figure 1 As shown in the figure, the Text-to-SQL task consists of two parts: a SQL parser and a SQL executor. The SQL parser takes as input a given database 110 and a question 120 for that database, and outputs a SQL query statement 130 corresponding to the question. The SQL executor executes the query statement 130 on the database and produces the query result 140. In the context of current deep learning research, the Text-to-SQL task can be viewed as a sequence-to-sequence generation task similar to neural machine translation, primarily employing the Seq2Seq model framework. By incorporating mechanisms such as attention and copying into the Seq2Seq model, the model can achieve an accuracy of over 80% on single-domain datasets, but performs poorly on multi-domain datasets.
[0052] In related technologies, during the training process of Seq2Seq models, the inference path of SQL training samples is single, and the SQL queries used in the training datasets mainly follow one or several fixed patterns. Alternatively, the query design is overly focused on certain specific query structures, association methods, and condition combinations, lacking sufficient diversity to fully reflect the complexity and richness of SQL queries in the real world. This can be manifested in the following aspects:
[0053] (1) Dominated by fixed patterns: SQL queries in training datasets often show a high reliance on one or several specific query patterns. These specific query patterns may be intentionally or unintentionally set by the designer when constructing the dataset. For example, they prefer to use simple one-to-one or one-to-many single-table queries, or only cover basic SELECT-FROM-WHERE structures while ignoring more complex query constructs such as multi-table joins, subqueries, and window functions. When the model learns on the dataset constructed above, it is easy to over-adapt to these fixed patterns. When faced with the widespread diversity and complexity in the real world, the model's reasoning ability will be severely restricted.
[0054] (2) Limited by query structure: The constructed training dataset may be overly focused on specific query structures. For example, it may focus too much on simple SELECT-FROM-WHERE queries while neglecting the combination of set operations such as UNION, INTERSECT, and EXCEPT, or advanced query functions such as GROUP BY, HAVING, and ORDER BY. This limitation in query structure restricts the model's understanding of the full scope of the SQL language, making it unable to accurately parse and generate corresponding SQL query statements when faced with complex query structures in real applications.
[0055] (3) Single association method: SQL queries in a dataset may be concentrated on a few association methods, such as only including inner joins while ignoring other association types such as left / right joins, full outer joins, and natural joins, or failing to reflect complex ON clause expressions under different join conditions. However, in real-world SQL queries, the association methods between data tables are often diverse and flexible. If the model is not fully exposed to these diverse association strategies during training, it will be difficult to cope with actual query requirements.
[0056] (4) Lack of condition combinations: The query conditions in the training dataset may be too simple or repetitive. For example, they may only contain basic comparison operations such as equal, not equal, greater than, and less than, but rarely use logical operators such as AND, OR, and NOT to construct complex Boolean expressions. There may also be a lack of special conditions such as IN, BETWEEN, LIKE, and IS NULL. In the real world, user queries often involve multiple nested and heterogeneous condition combinations. Therefore, the model needs to learn to handle such complex condition structures through a variety of training samples.
[0057] Based on this, the embodiments of the present application provide a data processing method, device, electronic device, computer-readable storage medium and computer program product, which can effectively improve the accuracy of query statements generated by the model by expanding the data set for model training. The electronic device provided by the embodiment of the present application is described below. The electronic device provided by the embodiment of the present application can be implemented as a server, or as a terminal, or can be implemented in collaboration with a server and a terminal. The following is an example of the data processing method provided by the embodiment of the present application being implemented in collaboration with a server and a terminal.
[0058] For example, see Figure 2 , Figure 2 This is a schematic diagram of the architecture of the data processing system 100 provided in an embodiment of the present application, which is used to support a data processing application, such as Figure 2 As shown, the data processing system 100 includes: a server 200, a network 300, a terminal 400 and a database 110. The terminal 400 is connected to the server 200 via the network 300, and the server 200 is connected to the database 110. The network 300 can be a local area network or a wide area network, or a combination of the two; the database 110 is used to store structured data (such as text data, query statements and other data).
[0059] In some embodiments, the server 200 may first obtain first training data from the database 110; then, the server 200 performs a first training on the first model based on the first question sample, the first database pattern item matching the first question sample, and the first real query statement matching the first question sample included in the first training data, to obtain a first model that has undergone the first training; then, based on the first model that has undergone the first training, the server 200 performs a transformation process on the second question sample and the second database pattern item matching the second question sample to obtain a first predicted query statement; then, in response to the mismatch between the first predicted query statement and the second question sample, the server 200 performs a transformation process on the second question sample and the second database pattern item matching the second question sample to obtain a first predicted query statement; The second training data is generated by comparing the difference between the second real query statement corresponding to the second question sample and the first predicted query statement; then, the server 200 performs a second training on the first model that has undergone the first training based on the first training data and the second training data to obtain the first model that has undergone the second training; then, the user inputs the query question through the terminal 400 and transmits the query question to the server 200 through the network 300; thereafter, the first model that has undergone the second training in the server 200 makes a prediction based on the query question to obtain a second predicted query statement; finally, the server 200 transmits the obtained second query statement to the terminal 400 through the network 300 and displays it on the terminal 400.
[0060] It should be noted that the technical solutions provided in the embodiments of this application can be applied to various scenarios such as data analysis and query, business management and decision-making, education and research, and software development and testing.
[0061] In some embodiments, taking a data analysis and query scenario as an example, first, a first model (e.g., a Text-to-SQL conversion model) is first trained based on a first question sample (e.g., a natural language question) included in first training data, a first database schema item matching the first question sample, and a real query statement (e.g., an SQL query statement) corresponding to the first question sample, to obtain a first model that has undergone first training; then, based on the first model that has undergone first training, a second question sample and a second database schema item matching the second question sample are converted to obtain a first predicted query statement; then, in response to a mismatch between the first predicted query statement and the second question sample, second training data is generated based on the difference between the second real query statement corresponding to the second question sample and the first predicted query statement; then, based on the first training data and the second training data, a second training is performed on the first model that has undergone first training to obtain a second trained first model; then, the question content to be queried input by the user is obtained, and the second trained first model is predicted based on the query question to obtain a second predicted query statement, so as to query the corresponding data for analysis based on the second predicted query statement. In this way, SQL query statements can be quickly generated through the Text-to-SQL tool, thereby more efficiently extracting and analyzing data from relational databases.
[0062] In other embodiments, taking software development and testing scenarios as an example, first, based on the first question (e.g., natural language question) sample included in the first training data, the first database schema item matching the first question sample, and the real query statement (e.g., SQL query statement) corresponding to the first question sample, a first model (e.g., Text-to-SQL conversion model) is first trained to obtain a first model that has undergone the first training; then, based on the first model that has undergone the first training, the second question sample and the second database schema item matching the second question sample are converted to obtain a first predicted query statement; then, in response to the mismatch between the first predicted query statement and the second question sample, second training data is generated based on the difference between the second real query statement corresponding to the second question sample and the first predicted query statement; then, based on the first training data and the second training data, the first model that has undergone the first training is second trained to obtain a first model that has undergone the second training; then, the question content to be queried input by the user is obtained, and the first model that has undergone the second training performs prediction based on the query question to obtain a second predicted query statement, and the test database is queried based on the generated predicted query statement to obtain the corresponding required test data. In this way, Text-to-SQL technology SQL query statements can be used to quickly match corresponding test data based on SQL query statements to achieve automated testing, which can effectively improve software testing efficiency.
[0063] For example, Figure 2 The server 200 in the example can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms. The terminal 400 can be a smart phone, tablet computer, laptop computer, desktop computer, smart speaker, smart watch, car terminal, etc., but is not limited to these. The terminal 400 and the server 200 can be directly or indirectly connected via wired or wireless communication, which is not limited in the embodiments of the present application.
[0064] The following continues to describe the structure of the electronic device provided in the embodiment of the present application. Take the electronic device as an example, see Figure 3A , Figure 3A is a structural diagram of an electronic device 500 provided in an embodiment of the present application, Figure 3AThe electronic device 500 shown includes: at least one processor 510, a memory 540, and at least one network interface 520. The various components in the electronic device 500 are coupled together via a bus system 530. It is understood that the bus system 530 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 530 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, the bus system 530 is not described in detail. Figure 3A Various buses are labeled as bus system 530 .
[0065] The processor 510 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., where the general-purpose processor can be a microprocessor or any conventional processor, etc.
[0066] The memory 540 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state memory, hard drives, optical drives, etc. The memory 540 may optionally include one or more storage devices that are physically remote from the processor 510.
[0067] The memory 540 includes volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory may be a read-only memory (ROM), and the volatile memory may be a random access memory (RAM). The memory 540 described in the embodiments of the present application is intended to include any suitable type of memory.
[0068] In some embodiments, the memory 540 can store data to support various operations, examples of which include programs, modules, and data structures, or a subset or superset thereof, as exemplified below.
[0069] Operating system 541, including system programs for processing various basic system services and performing hardware-related tasks, such as the framework layer, core library layer, and driver layer, which are used to implement various basic services and process hardware-based tasks;
[0070] A network communication module 542 for reaching other computing devices via one or more (wired or wireless) network interfaces 620 , exemplary network interfaces 620 including Bluetooth, Wireless LAN (WiFi), and Universal Serial Bus (USB);
[0071] In some embodiments, the apparatus provided in the embodiments of the present application may be implemented in software. Figure 5 The data processing device 543 stored in the memory 540 is shown. It can be software in the form of a program or plug-in, and includes the following software modules: a first training module 5431, a first prediction module 5432, an expansion module 5433, a second training module 5434, a third training module 5435, and a second matching module 5436. These modules are logical and can be arbitrarily combined or further split according to the functions implemented. It should be noted that in Figure 3A For the sake of convenience, all the above modules are shown at once, but it should not be considered that the data processing device 543 excludes the implementation of only including the first training module 5431, the first prediction module 5432, the expansion module 5433 and the second training module 5434. The functions of each module will be explained below.
[0072] The structure of the electronic device for implementing the data processing method provided in the embodiment of the present application is further described below. Taking the electronic device 600 as an example, see Figure 3B , Figure 3B is a structural diagram of an electronic device 600 provided in an embodiment of the present application, Figure 3B The electronic device 600 shown includes a data processing device 643, which can be software in the form of programs and plug-ins, including the following software modules: a first matching module 6431 and a second prediction module 6432. These modules are logical and can therefore be arbitrarily combined or further split according to the functions implemented.
[0073] It should be noted that Figure 3B The electronic device 600 shown includes a processor 610, a network interface 620, a bus system 630, an operating system 641, and a network communication module 642. Figure 3A The corresponding modules included in have the same structure and the same function, and the embodiments of the present application will not be repeated here.
[0074] The data processing method provided in the embodiment of the present application will be described in detail below in combination with the exemplary application and implementation of the server provided in the embodiment of the present application.
[0075] See also Figure 4 , Figure 4 This is a flow chart of the data processing method provided in the embodiment of the present application, which will be combined with Figure 4 The steps shown are explained.
[0076] In step 101, a first model is first trained based on a first question sample included in first training data, a first database pattern item matching the first question sample, and a first real query statement matching the first question sample to obtain a first model that has undergone the first training.
[0077] It should be noted that database schema items refer to the basic components of the database schema, which define the structure of the database and the organization of data. In the database, the schema defines the logical structure of all objects in the database, including tables, views, indexes, data types, functions, stored procedures, triggers, and constraints. Database schema items mainly include tables, views, indexes, data types, functions, stored procedures, triggers, constraints, default values, and rules.
[0078] As an example, taking the database schema item including the tables and columns in the database as an example, there is a table "Student" in the database, and the table "Student" contains the "Name" and "Score" columns, then the database schema item includes the table "Student" and the "Name" and "Score" columns.
[0079] In some embodiments, the above-mentioned step 101 can be implemented in the following manner: encoding the first problem sample based on the first model to obtain a second code, and encoding the first database pattern item based on the first model to obtain a third code; decoding the second code and the third code based on the first model to obtain a second predicted query statement corresponding to the first problem sample; determining a second loss function based on the error between the second predicted query statement and the first true query statement; updating the parameters of the first model based on the second loss function to obtain the first model that has undergone the first training. In this way, users can describe query requests in natural language and meet query requirements without in-depth understanding of query statement syntax, making database queries more intuitive and easy to operate; in addition, through encoding and decoding processing, the model can learn the complex mapping relationship between problem samples and database pattern items, improving the model's generalization ability on different database patterns.
[0080] As an example, taking a dataset related to online education as an example, assuming that the first question sample is "Xiao Ming's grades in mathematics courses", the database schema item includes two tables in the database, one is the student information table, which contains student name and student ID columns; the other is the score table, which contains student ID, course name and score columns; first, the first model receives the question sample "Xiao Ming's grades in mathematics courses" and encodes it into a second code C2. At the same time, the first model encodes the database schema item (i.e., the structural information of the student information table and the score table) to obtain a third code C3; then, the first model decodes the second code C2 and the third code C3 to obtain the second prediction query statement P2 corresponding to the first question sample (for example, SELECT score FROM Grades WHERE student_id = (SELECT student_id FROM Students WHERE name = 'Xiao Ming') AND (course_name = 'Mathematics'); Subsequently, based on the error between the second predicted query P2 and the first true query R1, a corresponding second loss function L2 is determined. Here, a binary cross-entropy loss function or other loss functions can be used, without specific limitation. Finally, the model calculates the gradient of the loss function with respect to the parameters through a backpropagation algorithm, and updates the model parameters through backpropagation to obtain the first trained model. This achieves the conversion of natural language to SQL queries.
[0081] As another example, the model first receives a large number of natural language questions and corresponding SQL query statements, as well as related database schema item information as training data, where the natural language question is the input of the model, and the database schema provides structural information such as tables, columns, and relationships involved in the query. Training samples are constructed based on the above data, and each training sample includes a natural language question, a database schema item, and a corresponding SQL query statement; during the training process, the encoder can be used to convert the input natural language question and database schema into an encoding vector; then, the decoder gradually generates each token in the SQL query statement based on the output of the encoder. The decoder adopts an autoregressive generation method, that is, the generation of each step depends on the previously generated token and the encoding information of the current context. In each step, the decoder calculates the conditional probability of each possible token and selects the token with the maximum probability as the output. The above generation process is step-by-step. The decoder gradually constructs a complete SQL query by generating tokens again and again. Subsequently, the cross-entropy loss function can be used to measure the difference between the SQL query generated by the model and the real SQL query. In each prediction step, the model calculates the probability of generating the next token based on the current context information (including the generated part of the SQL query and the semantic representation of the question), and adjusts the model parameters according to the real SQL query to reduce the prediction error, thereby obtaining the first model after the first training, realizing the conversion process of complex natural language to corresponding SQL query statements.
[0082] In some embodiments, see Figure 5 , Figure 5 is a flow chart of the data processing method provided in the embodiment of the present application, such as Figure 5 As shown, before executing step 101, you can also execute Figure 7 Steps 5 to 107 shown are implemented by combining Figure 5 The steps shown are explained.
[0083] In step 105, based on the third question sample, the third database pattern item, and the correlation annotation between the third question sample and the third database pattern item, the second model is subjected to the third training to obtain the second model that has undergone the third training.
[0084] In some embodiments, step 105 can be implemented as follows: encoding the first data including the third question sample and the third database pattern item based on the second model to obtain a first code; mapping the first code based on the second model to obtain a second predicted correlation between the third question sample and each of the third database pattern items; determining a first loss function based on the second predicted correlation and the correlation annotations between the third question sample and the third database pattern items; and updating the parameters of the second model based on the first loss function to obtain a second model that has undergone the third training. In this manner, encoding the question sample and the third database pattern item based on the second model and mapping the predicted correlation between the two enable the model to more accurately understand the user's query intent.
[0085] As an example, taking the intelligent customer service application scenario as an example, it is necessary to train a second model to predict the correlation between the user query and the third database pattern item; assuming that the third question sample is "understand the price of brand A mobile phone in 20xx", the corresponding third database pattern item includes a product information table and a sales data table, wherein the product information table includes product name, release year and price columns, and the sales data table includes product name, release year and sales volume columns; first, the second model receives the third question sample and the third database pattern item, and encodes them to obtain a first encoding vector C1; then, the second model maps the first encoding vector C1 to obtain a second predicted correlation R between the user query and each third database pattern item. predict ; Then, compare the second prediction correlation R predict Correlation with the true R truth The error between them is used as the first loss; finally, the parameters of the second model are updated according to the first loss to obtain the second model after the third training, so that the model learns the mapping relationship between the problem sample and the database pattern item.
[0086] In step 106, the first question sample and the third database pattern item are matched based on the second model that has undergone the third training to obtain a first predicted correlation between the first question sample and the third database pattern item.
[0087] As an example, by combining the first question sample Q and the third database pattern item set {S1, S2, S3, ..., S n The first question sample Q is input into the second model, and prediction processing is performed based on the second model to obtain a first predicted relevance R between the first question sample Q and each third database pattern item in the set of third database pattern items. The third database pattern items are sorted based on the relevance scores, thereby selecting the most relevant database pattern item for subsequent query generation or data retrieval operations.
[0088] In step 107 , based on the first predicted relevance, a first database pattern item matching the first question sample is determined from the third database pattern items.
[0089] As an example, the third database pattern item set {S1, S2, S3, ..., S n The first prediction correlation R between i , and according to the first prediction correlation R i Determine the best database pattern item S that matches the first question sample Q. Here, the database pattern item with the highest first prediction relevance can be selected from the third database pattern item set as the best database pattern item, or other methods can be used for selection, which are not specifically limited here.
[0090] To sum up, on the one hand, through the third training, the second model learns how to more accurately predict the correlation between the question sample and the database pattern item, thereby improving the matching accuracy; on the other hand, by using the third question sample and its correlation annotation for the third training, it can help the model learn a wider range of matching patterns, thereby enhancing the generalization ability of the model.
[0091] In step 102, based on the first model trained by the first step, a second question sample and a second database pattern item matching the second question sample are transformed to obtain a first predicted query statement.
[0092] In some embodiments, step 102 can be implemented as follows: encoding the second question sample based on the first model trained by the first step to obtain a fourth code, and encoding the second database schema item based on the first model trained by the first step to obtain a fifth code; and decoding the fourth code and the fifth code based on the first model trained by the first step to obtain a first predicted query statement corresponding to the second question sample. In this way, based on the prediction of the first question sample using the first model trained by the first step, an accurate predicted query statement can be generated, thereby achieving accurate prediction of the first question sample.
[0093] As an example, assume that the first question sample is "Xiao Ming's grades in mathematics." The database schema item includes two tables in the database: a student information table containing student name and student ID columns; and a grade table containing student ID, course name, and grade columns. First, the first model receives the question sample "Xiao Ming's grades in mathematics" and encodes it into a fourth code C4. At the same time, the first model encodes the schema item (i.e., the structural information of the student information table and the grade table) to obtain a fifth code C5. Next, the first model decodes the fourth code C4 and the fifth code C5 to obtain the first predicted query statement P1 corresponding to the first question sample (e.g., SELECT score FROM Grades WHERE student_id = (SELECT student_id FROM Students WHERE name = 'Xiao Ming') AND course_name = 'Mathematics'). In this way, the model can understand the user's natural language query and generate corresponding SQL query statements to obtain information from the database, effectively reducing the user's need to enter SQL syntax, improving the convenience of user interaction and the intelligence level of the system.
[0094] In step 103 , in response to the mismatch between the first predicted query statement and the second question sample, second training data is generated based on the difference between a second real query statement corresponding to the second question sample and the first predicted query statement.
[0095] In some embodiments, step 103 can be implemented by determining the prediction error type corresponding to the difference; and generating the second training data based on the first prediction query, the prediction error type, and the second problem sample. By comparing the differences and determining the prediction error type, the model's prediction deviations can be identified, allowing for targeted improvements to the model. Furthermore, enhancing the first training data based on the error type increases the diversity of the model's training data, allowing the model to learn from more situations and thus improve the accuracy of the model's predictions.
[0096] Here, determining the prediction error type corresponding to the difference is mainly about identifying the incorrect SQL generated by the model. It can be compared and analyzed with the correct answer to extract the key differences and error types (such as logical errors, syntax errors, or pattern understanding errors).
[0097] In some embodiments, generating the second training data based on the first predicted query, the predicted error type, and the second question sample can be achieved by: generating a fourth question sample with the same query intent as the second question sample; modifying the first predicted query based on the predicted error type to obtain a third predicted query; and combining the fourth question sample, the third predicted query, and the second database pattern item to form the second training data. In this way, the training set can be expanded through data augmentation to generate data similar to the original data, thereby assisting in model correction and improving the model output.
[0098] As an example, first use large models such as GPT to design prompts, and generate natural language-SQL pairs based on correct SQL that are similar to the original data but have certain variations. For example, the training data can be expanded by modifying conditions, adjusting structures, introducing similar logic, etc. For example, the constructed prompt words can be "You will receive an original query Query containing grammatical errors and the corresponding SQL statement. Your job is to identify these grammatical problems and generate 10 sets of corrected similar queries and SQL statements based on the original intent. Each similar data should maintain the core purpose of the original query, but may differ in wording or structure, while ensuring that the new SQL statement has no grammatical errors. Input format: - Question: [Original query Query]; - Corresponding SQL: [SQL statement with grammatical errors]; Output format: Similar question: [Query similar to the input]; Corrected SQL: [Corrected, grammatically correct SQL statement]". In this way, it is ensured that the generated data is not only similar to the original data in the query fields, table names and conditions, but also similar in the purpose and intent of the query.
[0099] In step 104, based on the first training data and the second training data, the first model that has undergone the first training is subjected to second training to obtain the first model that has undergone the second training.
[0100] It should be noted that the specific implementation of the above step 104 is similar to the implementation of step 101. For details, please refer to the implementation of step 101 and will not be repeated here.
[0101] In some embodiments, see Figure 6 , Figure 6 This is a flow chart of the data processing method provided in the embodiment of the present application, which will be combined with Figure 6 The steps shown are explained.
[0102] In step 201 , a matching process is performed on the fifth question sample and the third database pattern item to obtain a third predicted correlation between the fifth question sample and the third database pattern item.
[0103] Here, the matching processing of the fifth question sample and the second database pattern item is realized through the second model, and the second model is obtained by training the data processing method in the above steps 105 to 107. It should be noted that the specific implementation method of the above step 201 is similar to the specific implementation method of step 106. Please refer to the implementation method of step 106 for details, which will not be repeated here.
[0104] In step 202, based on the third predicted relevance, a fourth database pattern item matching the fifth question sample is determined from the third database pattern items.
[0105] Here, determining the fourth database pattern item that matches the fifth question sample from the third database pattern item is achieved through the second model, and the second model is trained by the data processing method in the above steps 105 to 107.
[0106] It should be noted that the specific implementation of the above step 202 is similar to the specific implementation of step 107. For details, please refer to the implementation of step 107 and will not be repeated here.
[0107] In step 203, the fifth question sample and the fourth database pattern item are transformed to obtain a fourth prediction query statement corresponding to the fifth question sample.
[0108] Here, the conversion processing of the fifth question sample and the second database pattern item is implemented through the first model, and the first model is obtained by training through the data processing method in the above steps 101 to 104.
[0109] It should be noted that the specific implementation of the above step 203 is similar to the specific implementation of step 102. For details, please refer to the implementation of step 102 and will not be repeated here.
[0110] The following describes an exemplary application of the embodiment of the present application in a practical application scenario, which describes the specific implementation process of the data processing method in a Text-to-SQL scenario.
[0111] In related technologies, the reasoning paths of SQL training samples exhibit a single characteristic. The SQL query statements in the training datasets used are mainly constructed according to one or several fixed patterns. In other words, when constructing SQL training samples, the designed SQL query statements are often too focused on a few specific query structures, association methods, and condition combinations. This results in a serious lack of diversity in the dataset and is unable to fully reflect the complexity and richness of SQL query statements in the real world. The above limitations in constructing training samples have the following negative impacts on the learning effect of the model:
[0112] (1) The model's understanding of SQL syntax tends to be one-sided and limited to the fixed patterns it encounters. It lacks a deep understanding of the overall picture and flexible application of the SQL language. In addition, the model may only be good at processing query structures and operations that frequently appear in the training dataset, but has little knowledge or understanding of other legal and practical SQL syntax forms.
[0113] (2) When the model faces actual query tasks, its query strategy tends to be solidified, tending to follow the query patterns repeatedly seen during the training process, and lacks the ability to flexibly adapt and innovate query paths. This rigidity not only limits the adaptability of the model when facing novel or complex query requirements, but also reduces its efficiency and quality in solving problems in practical applications. In addition, due to the lack of diversity in the training data set, the generalization ability of the model is significantly restricted. When faced with query structures, association methods or condition combinations that have not been encountered in training, the model may show difficulty in recognition, improper handling or even be completely unable to cope. This greatly weakens the effectiveness and reliability of the model when facing complex and changeable query scenarios in the real world. Based on this, this application uses data enhancement techniques such as proxy models to generate diverse SQL answers, transform question requirements, exchange attribute column order and replace similar words, etc., to systematically expand the reasoning path of SQL training samples and comprehensively improve the model's understanding of SQL syntax and query diversity. In this way, the model can have greater accuracy and flexibility in complex query scenarios, and can more accurately and efficiently generate SQL query statements that meet expectations when facing the ever-changing SQL query requirements in the real world.
[0114] See also Figure 7 , Figure 7 This is a flowchart of the Text-to-SQL task provided by the embodiment of this application. Figure 7 The specific implementation process of the Text-to-SQL task of this application is explained.
[0115] First, obtain the original data that needs to be converted into SQL query statements and add the original data to the processing flow; then, in order to improve the conversion ability of the model, perform data expansion through data enhancement, and add the expanded data to the original data to obtain an expanded data set to expand the reasoning path. Here, the data set can be expanded by generating diverse SQL query statements through proxy models, transforming problem requirements to stimulate different query strategies, exchanging the order of attribute columns, replacing similar words, etc., so that the model can better understand and process it.
[0116] After obtaining the expanded data set, the data in the expanded data set can be preprocessed to obtain preprocessed data. Here, preprocessing includes operations such as selecting data content and converting data formats to ensure that the model can correctly receive and parse the data.
[0117] After preprocessing the expanded data set, the table column selection model is trained using the preprocessed expanded data set so that the table column selection model (corresponding to the second model mentioned above) learns the mapping relationship from text to tables and columns. By continuously iterating and optimizing parameters, the prediction ability of the table column selection model is improved.
[0118] It should be noted that the table and column selection model is to filter out tables and columns related to the input natural language query from the database schema; see Figure 8 , Figure 8 This is an architectural diagram of the table selection model provided in the embodiment of the present application, such as Figure 8 As shown, the training of the table and column selection model is modeled in the form of a classification problem. For each table and column, it is determined whether it is relevant to the current query. The training dataset contains the question, database schema (including the database table name and column name), and label (for each database schema, a label is provided to indicate whether it is relevant to the current question). The question, database table name, and column name are used as input to the table and column selection model. The table and column selection model is usually based on a deep learning classification model and consists of two modules: an encoder and a classification head. They output the probability of each database table and column being relevant to the question, respectively, to classify the database tables and columns, and sort them based on the relevant probability, filtering out irrelevant database schemas. The training process of the table and column selection model can be achieved through the following steps:
[0119] (1) Training data preparation. In the table and column selection model, the training dataset consists of questions, database schemas (including table and column names), and annotations. The annotations indicate whether each database schema is relevant to the input question, usually represented by a binary label. A label of 1 indicates that the database schema is relevant to the input question, and 0 indicates that the database schema is not relevant to the input question. Questions are usually natural language queries; database schemas include tables and columns in the database.
[0120] As an example, suppose the question is: "Show student names and grades", and there is a "Student" table in the database (including two columns: "Name" and "Score", then the "Student" table and its "Name" column and "Score" column are marked as 1, that is, the "Student" table and its "Name" column and "Score" column are related to the question.
[0121] (2) Determine the model input. The input of the table column selection model mainly includes the query text (i.e., the question in the training dataset) and the database schema (i.e., the table name, column name, and optional foreign key relationship in the database).
[0122] (3) Determine the model structure. The column selection model is generally based on the split structure of deep learning, and usually includes two main modules: the encoder and the classifier head. The encoder uses a neural network (such as LSTM, Transformer, etc.) to encode the query text and database schema items to capture the semantic relationship between the query and the database schema items. The classifier head is usually a fully connected layer that maps the vector output by the encoder to the category label (0 or 1) of each column item and outputs the probability that the column item is related to the query.
[0123] (4) Model training. During the training of the table column selection model, the input query text and database schema (including table name, column name, and optional foreign key information) are first encoded by the encoder to obtain multiple encoding vectors; each encoding vector is then classified by the classification head to generate a relevance score for each table column, where the relevance score represents the degree of relevance between the current table column and the query text (i.e., the question in the training dataset), and the difference between the relevance probability output by the model and the actual label is calculated to determine the loss function, where the loss function can be a binary cross entropy loss or other loss function; after determining the loss function, the table column selection model calculates the gradient of the loss function with respect to the parameters through the backpropagation algorithm, and uses the optimizer (such as the Adam optimizer) to update the parameters of the table column selection model, thereby minimizing the loss and improving the prediction accuracy. The entire training process continuously adjusts the parameters of the table column selection model so that it can better learn from the relationship between the query and the database schema, thereby achieving efficient table column selection for new queries.
[0124] After the column selection model is trained, its performance needs to be evaluated. This can be done using a dedicated test set, cross-validation, bootstrapping, or other methods, without further limitation.
[0125] After obtaining the trained table column selection model, the data preprocessing and the output of the table column selection model can be used to train the SQL parsing model (corresponding to the first model mentioned above), wherein the SQL parsing model can learn the mapping relationship from the query text to the SQL query statement.
[0126] It should be noted that the SQL parsing model is trained using large-scale natural language question-SQL alignment data, see Figure 9 , Figure 9 This is an architectural diagram of the SQL parsing model provided in the embodiment of the present application, such as Figure 9 As shown, the SQL parsing model maps user questions to SQL components by learning the alignment between natural language and SQL. For example, the natural language question "What is the name of the employee with the highest salary?" is converted into the SQL query "SELECT name FROM employees ORDER BY salary DESC LIMIT 1;." The SQL parsing model uses semantic parsing to understand the meaning of the natural language (for example, "highest salary" corresponds to ORDER BY salary DESC). It then gradually generates logical queries based on SQL grammar rules. The SQL parsing model training process can be achieved through the following steps:
[0127] The SQL parsing model uses autoregressive generation and sequence alignment methods to gradually generate logical SQL query statements by learning the mapping relationship between natural language and SQL query statements.
[0128] During the training process, the SQL parsing model first receives a large number of natural language questions and corresponding SQL query statements, as well as related database schemas as training data. The natural language questions are the input to the model, while the database schema provides structural information such as the tables, columns, and relationships involved in the query. This data is used to construct training samples. Each sample includes a natural language question, a database schema, and a corresponding SQL query statement. By inputting these samples, the SQL parsing model learns the alignment relationship between natural language and SQL query statements.
[0129] When training the SQL parsing model, an encoder can be used to convert the input natural language questions and database schemas into high-dimensional vector representations to obtain corresponding encoding vectors. The generated encoding vectors capture the semantic information of the natural language questions and the structural information of the database schema, which can help the SQL parsing model understand the query intent and related database structure.
[0130] Next, the decoder gradually generates each token of the SQL query statement based on the output of the encoder. The decoder uses an autoregressive generation method, that is, each step of generation depends on the previously generated token and the encoded information of the current context. In each step-by-step generation process, the decoder calculates the conditional probability of each token and selects the token with the maximum probability as the output. Among them, this generation process is gradual. The decoder can gradually construct a complete SQL query statement by generating tokens again and again.
[0131] In addition, during the SQL parsing model training process, the SQL parsing model improves its accuracy by optimizing the prediction probability of each token. Here, the cross-entropy loss function can be used to measure the difference between the SQL query statements generated by the model and the actual SQL query statements. In each prediction step, the SQL parsing model calculates the probability of generating the next token based on the current context information (including the generated SQL query statements and the semantic representation of the question) and adjusts the model parameters based on the actual SQL query statements to reduce prediction errors.
[0132] As the SQL parsing model is trained, it gradually learns to infer correct SQL queries from natural language questions and database schemas, and generates queries that conform to SQL syntax and logic. The goal of the SQL parsing model is to maximize the probability of correct prediction for each token, thereby ensuring both syntactically correct and logically sound SQL queries when generating SQL queries. Through large-scale training data and repeated optimization, the SQL parsing model can gradually improve its ability to understand and generate SQL queries, enabling it to process complex natural language queries and generate corresponding SQL queries.
[0133] After the SQL parsing model is trained, its performance needs to be evaluated. This can be done using a validation set or a test set. Indicators such as EM and EX are calculated in real-world scenarios to determine the model's performance. It should be noted that EM and EX are often used together to comprehensively evaluate the effectiveness of the SQL parsing model. EM focuses on the model's prediction accuracy, while EX focuses on its practicality. By considering both metrics simultaneously, a more comprehensive assessment of model performance is achieved.
[0134] If, during the model evaluation process, the SQL parsing model is found to have generated incorrect SQL queries, a proxy model can be used to expand the training set and generate data similar to the original data. This similar data can help the SQL parsing model correct errors and improve the model's output. During the model evaluation process, the incorrect SQL queries generated by the SQL parsing model can be compared and analyzed with the correct answers to extract key differences and error types (such as logical errors, syntax errors, or pattern misunderstanding errors). Then, using large model design hints such as GPT, natural language-SQL pairs similar to the original data but with certain variations can be generated based on the correct SQL queries. For example, the training data can be expanded by modifying conditions, adjusting structures, or introducing similar logic.
[0135] It should be noted that the proxy model can be a large language model, either open source or closed source. Generating data similar to the original data through prompt engineering is a data augmentation method that is particularly effective when there is a lack of sufficient labeled data. This method can guide the model to generate synthetic data that conforms to the target data distribution by constructing carefully designed prompts. The entire process starts with clarifying the goal of generating data. First, the characteristics of the target data are determined. For example, if the goal is to generate query data similar to the original SQL query statement, then the generated data must be consistent with the original data in terms of grammatical structure and semantics. In other words, the generated data must not only be similar to the original data in terms of query fields, table names, and conditions, but also ensure that the purpose and intent of the query are reflected.
[0136] Here, the core of using proxy models to generate similar data lies in designing appropriate prompts. Prompts are inputs that interact with large language models. The model generates the desired output by receiving these prompts. In order to generate data similar to the original data, the prompts need to accurately convey the type, structure, and diversity requirements of the generated data. For example, if the question is a query asking for the names of employees under a certain condition, the SQL query uses "ORDER BY salary DESC LIMIT 1" to filter out the employees with the highest salary. This means that the generated similar data should maintain the semantic consistency of the question and follow a similar SQL query structure in terms of syntax, but some changes can be made to the question or query to increase diversity. The question can involve different fields, table names, or sorting conditions, and the structure of the SQL query should still follow the form of "selecting a column from a table and sorting according to a certain condition."
[0137] After the prompt is designed, the proxy model begins generating data based on the prompt. By inputting carefully constructed prompts, the model, based on its own training, generates content similar to the target data characteristics. For example, given a query question, the model may generate multiple SQL query variations, such as "SELECT name FROM employees WHERE salary>60000" or "SELECT name, department FROM employees WHERE salary>50000." The generated queries not only conform to the syntax of the original data but also provide diverse query samples by adjusting query conditions, adding fields, modifying table names, and so on, thereby helping to expand the dataset.
[0138] As the amount of generated data increases and the model is trained, prompts can be continuously optimized to improve the quality and diversity of similar data generated. For example, if the data generated by the proxy model is too monotonous, the conditions in the prompt can be changed to require the proxy model to generate more diverse queries or use more detailed context descriptions to guide the model. Here, the process of optimizing prompts is a process of continuous experimentation and adjustment, aiming to ensure that the generated data not only conforms to the semantics of the original question but also has sufficient diversity and variation.
[0139] By continuously optimizing the prompts of the proxy model and using large language models and prompt engineering to generate data similar to the original data, we can not only effectively expand the dataset and improve data diversity, but also help the model learn a wider range of query patterns and complexities during training. The generated data can not only improve model performance but also support the model to adapt to more types of problems.
[0140] After generating similar data, you can verify the generated similar data to ensure its accuracy. Then, add the verified data to the original data and retrain the table column selection model and SQL parsing model together with the original data. After training is completed, you can use an independent test set to evaluate the trained model and adjust and optimize the model based on the test results.
[0141] This application aims to improve the generalization and robustness of the model by increasing the diversity and complexity of the training dataset. In the context of SQL training samples, the inference path is introduced into the Text-to-SQL task. A series of specific technical measures, such as data augmentation, are used to expand the model's inference path. This deepens the model's understanding of SQL syntax and query diversity through the following methods:
[0142] (1) Generate diverse SQL samples using proxy models. First, with the help of proxy models, we can accurately simulate the complex data relationships and rich query patterns in the real world. For the same data query task, we can creatively generate a variety of different, legal and efficient SQL samples through the proxy model. By incorporating these diverse SQL samples generated by the proxy model into the training dataset, we can quickly expand its coverage, including more diverse query structures (such as multi-table joins, subqueries, window functions, etc.), association methods (such as inner joins, outer joins, self-joins, etc.), and condition combinations (such as complex Boolean expressions, special query conditions, etc.). This strategy not only increases the diversity of SQL reasoning paths, but also enables the model to learn multiple solutions to the same problem during training, thereby deepening its understanding of the flexibility of SQL syntax and semantic diversity.
[0143] (2) Transform the question requirements to stimulate different query strategies. By actively transforming the original question statement to stimulate the model to adopt different query strategies, and then generate differentiated SQL reasoning paths, this is mainly achieved by changing the question questioning method, emphasizing different query focuses, introducing additional constraints, etc. For example, the question "List the products with the highest sales" is cleverly rephrased as "Find products with sales exceeding the average". Although the core query goals of the two are the same, the model needs to face new challenges when constructing the SQL query logic and structure. This strategy aims to train the model to keenly capture and adapt to the diversity of user questioning methods, thereby improving the model's ability to accurately identify intent and generate appropriate SQL queries when receiving different statements.
[0144] (3) Swapping the order of attribute columns in SQL selections and replacing similar words. Through micro-level operations - swapping the order of attribute columns in the SQL SELECT clause, and replacing keywords in the query conditions with synonyms and antonyms, we can generate SQL query statements that are slightly different in form but semantically equivalent. This can help the model understand the relationship between attribute columns and their order and related words in the question, grasp the subtle differences in keyword semantics, and learn to adapt to vocabulary flexibility while maintaining semantic consistency. This strategy can strengthen the model's understanding of the structural diversity and lexical richness of SQL query statements, and can maintain stable and accurate performance when faced with similar statement changes in actual applications.
[0145] This application systematically expands the inference path of SQL training samples by comprehensively utilizing the aforementioned proxy model to generate diverse SQL answers, transform question requirements, swap attribute column order, and replace similar terms. This comprehensively enhances the model's understanding of SQL syntax and query diversity. By training the model, it achieves greater accuracy and flexibility in complex query scenarios, enabling it to more easily and efficiently generate expected SQL query statements in response to the ever-changing SQL query requirements of the real world, thereby achieving higher-quality automatic SQL parsing and generation tasks.
[0146] The following continues to describe the exemplary structure of the data processing device 543 provided in the embodiment of the present application implemented as a software module. In some embodiments, such as Figure 3A As shown, the software modules stored in the data processing device 543 of the memory 540 may include: a first training module 5431 , a first prediction module 5432 , an expansion module 5433 and a second training module 5434 .
[0147] The first training module 5431 is used to perform a first training on the first model based on the first question sample, the first database pattern item matching the first question sample, and the first real query statement matching the first question sample included in the first training data, to obtain the first model that has undergone the first training; the first prediction module 5432 is used to transform the second question sample and the second database pattern item matching the second question sample based on the first model that has undergone the first training, to obtain the first predicted query statement; the expansion module 5433 is used to generate second training data in response to the mismatch between the first predicted query statement and the second question sample based on the difference between the second real query statement corresponding to the second question sample and the first predicted query statement; the second training module 5434 is used to perform a second training on the first model that has undergone the first training based on the first training data and the second training data, to obtain the first model that has undergone the second training.
[0148] In some embodiments, the data processing device 543 further includes a third training module 5435 and a second matching module 5436 .
[0149] The third training module 5435 is used to perform a third training on the second model based on the third problem sample, the third database pattern item and the correlation annotation between the third problem sample and the third database pattern item, so as to obtain the second model that has undergone the third training; the second matching module 5436 is used to perform matching processing on the first problem sample and the third database pattern item based on the second model that has undergone the third training, so as to obtain the first predicted correlation between the first problem sample and the third database pattern item; based on the first predicted correlation, determine the first database pattern item that matches the first problem sample from the third database pattern item.
[0150] In some embodiments, the third training module 5435 is also used to encode the first data including the third problem sample and the third database pattern item based on the second model to obtain a first code; map the first code based on the second model to obtain a second predicted correlation between the third problem sample and each of the third database pattern items; determine a first loss function based on the second predicted correlation and the correlation annotation between the third problem sample and the third database pattern item; and update the parameters of the second model based on the first loss function to obtain a second model that has undergone the third training.
[0151] In some embodiments, the first training module 5431 is also used to encode the first problem sample based on the first model to obtain a second code, and encode the first database pattern item based on the first model to obtain a third code; decode the second code and the third code based on the first model to obtain a second predicted query statement corresponding to the first problem sample; determine a second loss function based on the error between the second predicted query statement and the first true query statement; and update the parameters of the first model based on the second loss function to obtain the first model that has undergone the first training.
[0152] In some embodiments, the first prediction module 5432 is also used to encode the second question sample based on the first model trained by the first method to obtain a fourth code, and to encode the second database pattern item based on the first model trained by the first method to obtain a fifth code; and to decode the fourth code and the fifth code based on the first model trained by the first method to obtain a first prediction query statement corresponding to the second question sample.
[0153] In some embodiments, the expansion module 5433 is further configured to determine a prediction error type corresponding to the difference; and generate the second training data based on the first prediction query statement, the prediction error type, and the second question sample.
[0154] In some embodiments, the expansion module 5433 is also used to generate a fourth question sample having the same query intent as the second question sample; correct the first prediction query statement based on the prediction error type to obtain a third prediction query statement; and combine the fourth question sample, the third prediction query statement and the second database pattern item into the second training data.
[0155] The following continues to describe the exemplary structure of the data processing device 643 provided in the embodiment of the present application implemented as a software module. In some embodiments, such as Figure 3B As shown, the software modules stored in the data processing device 643 of the memory 640 may include: a first matching module 6431 and a second prediction module 6432 .
[0156] The first matching module 6431 is used to match the fifth question sample and the third database pattern item to obtain a third predicted correlation between the fifth question sample and the third database pattern item; the first matching module 6431 is also used to determine, based on the third predicted correlation, a fourth database pattern item that matches the fifth question sample from the third database pattern item; the second prediction module 6432 is used to transform the fifth question sample and the fourth database pattern item to obtain a fourth predicted query statement corresponding to the fifth question sample.
[0157] In some embodiments, the conversion processing of the fifth question sample and the fourth database schema item is implemented through a first model.
[0158] It should be noted that the description of the device in the embodiment of the present application is similar to the description of the method embodiment above, and has similar beneficial effects as the method embodiment, so it will not be repeated here. Figure 4 、 Figure 5 ,or Figure 6 The present invention should be understood by referring to the description of any one of the accompanying drawings.
[0159] An embodiment of the present application provides a computer program product, which includes a computer program or computer-executable instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer-executable instructions from the computer-readable storage medium and executes the computer-executable instructions, causing the electronic device to perform the data processing method described in the embodiment of the present application.
[0160] The embodiment of the present application provides a computer-readable storage medium in which computer-executable instructions or computer programs are stored. When the computer-executable instructions or computer programs are executed by a processor, the processor will execute the data processing method provided in the embodiment of the present application, for example, Figure 4 、 Figure 5 ,or Figure 6 The data processing method is shown.
[0161] In some embodiments, the computer-readable storage medium may be a ferroelectric random access memory (FRAM), ROM, programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), flash memory, magnetic surface memory, optical disk, or compact disc read-only memory (CD-ROM); or various devices including one or any combination of the above memories.
[0162] In some embodiments, computer-executable instructions may be in the form of a program, software, software module, script, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine, or other unit suitable for use in a computing environment.
[0163] As an example, computer-executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file that stores other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinating files (e.g., files storing one or more modules, subroutines, or code portions).
[0164] By way of example, computer-executable instructions may be deployed to be executed on one electronic device, or on multiple electronic devices located at one site, or on multiple electronic devices distributed across multiple sites and interconnected by a communication network.
[0165] To sum up, through the embodiment of the present application, first, the first model is preliminarily trained according to the first question sample contained in the first training data, the first database pattern item matching the first question sample, and the real query statement corresponding to the first question sample, to obtain the first model after preliminarily training, thereby helping the first model understand the mapping relationship between the question and the query statement; then, using the preliminarily trained first model, the second question sample and the second database pattern item matching the second question sample are transformed and processed to obtain the first predicted query statement, thereby explaining the manifestation of the first model in practical applications; subsequently, in response to the mismatch between the first predicted query statement and the second real query statement, according to the difference between the first predicted query statement and the second real query statement, the second training data is generated through data enhancement to help the model correct errors and correct the output of the model; finally, the model is trained for the second time using the first training data and the newly added second training data, which can enable the model to better handle diverse inputs, help the model to better generalize, and thus improve the accuracy of the model in generating query statements based on the question.
[0166] The above description is merely an embodiment of the present application and is not intended to limit the scope of protection of the present application. Any modifications, equivalent replacements, and improvements made within the spirit and scope of the present application are included in the scope of protection of the present application.
Claims
1. A data processing method, characterized in that: The method comprises: Based on a first question sample included in first training data, a first database pattern item matching the first question sample, and a first real query statement matching the first question sample, performing first training on a first model to obtain a first model that has undergone the first training; Based on the first model trained by the first step, a second question sample and a second database pattern item matching the second question sample are converted to obtain a first predicted query statement; In response to a mismatch between the first predicted query and the second question sample, generating second training data based on a difference between a second real query corresponding to the second question sample and the first predicted query; Based on the first training data and the second training data, the first model that has undergone the first training is subjected to second training to obtain the first model that has undergone the second training.
2. The method according to claim 1, characterized in that Before performing a first training on the first model based on the first question sample included in the first training data, the first database pattern item matching the first question sample, and the first real query statement matching the first question sample to obtain the first trained first model, the method further includes: Based on the third question sample, the third database pattern item, and the correlation annotation between the third question sample and the third database pattern item, performing a third training on the second model to obtain a second model that has undergone the third training; performing matching processing on the first question sample and the third database pattern item based on the third trained second model to obtain a first predicted correlation between the first question sample and the third database pattern item; Based on the first predicted relevance, a first database pattern item matching the first question sample is determined from the third database pattern items.
3. The method according to claim 2, characterized in that The third training of the second model based on the third question sample, the third database pattern item, and the correlation annotation between the third question sample and the third database pattern item to obtain the third trained second model includes: encoding the first data including the third question sample and the third database pattern item using the second model to obtain a first code; Mapping the first code using the second model to obtain a second predicted correlation between the third question sample and each of the third database pattern items; determining a first loss function based on the second predicted relevance, the relevance annotation between the third problem sample and the third database pattern item; The parameters of the second model are updated based on the first loss function to obtain the second model that has undergone the third training.
4. The method according to claim 1, wherein The first training of the first model based on the first question sample included in the first training data, the first database pattern item matching the first question sample, and the first real query statement matching the first question sample to obtain the first model after the first training includes: encoding the first question sample based on the first model to obtain a second code, and encoding the first database pattern item based on the first model to obtain a third code; Decoding the second code and the third code based on the first model to obtain a second predicted query statement corresponding to the first question sample; determining a second loss function based on an error between the second predicted query and the first true query; The parameters of the first model are updated based on the second loss function to obtain the first model that has undergone the first training.
5. The method according to claim 1, wherein The converting process of the second question sample and the second database pattern item matching the second question sample based on the first model trained by the first step to obtain a first prediction query statement includes: encoding the second question sample based on the first model trained by the first step to obtain a fourth code, and encoding the second database pattern item based on the first model trained by the first step to obtain a fifth code; Based on the first model trained by the first step, the fourth code and the fifth code are decoded to obtain a first predicted query statement corresponding to the second question sample.
6. The method according to claim 1, wherein The generating second training data based on the difference between the second real query statement corresponding to the second question sample and the first predicted query statement includes: determining a type of prediction error corresponding to the difference; The second training data is generated based on the first prediction query statement, the prediction error type, and the second question sample.
7. The method according to claim 6, characterized in that The generating the second training data based on the first prediction query statement, the prediction error type, and the second question sample includes: generating a fourth question sample having the same query intent as the second question sample; Correcting the first predicted query statement based on the prediction error type to obtain a third predicted query statement; The fourth question sample, the third prediction query statement and the second database pattern item are combined into the second training data.
8. A data processing method, characterized in that: The method comprises: performing matching processing on the fifth question sample and the third database pattern item to obtain a third predicted correlation between the fifth question sample and the third database pattern item; determining, based on the third predicted relevance, a fourth database pattern item that matches the fifth question sample from the third database pattern items; The fifth question sample and the fourth database pattern item are transformed to obtain a fourth prediction query statement corresponding to the fifth question sample.
9. The method according to claim 8, characterized in that The conversion processing of the fifth question sample and the fourth database pattern item is implemented through a first model, and the first model is obtained by processing through the method according to any one of claims 1 to 7.
10. A data processing device, characterized in that: The device comprises: A first training module is configured to perform a first training on a first model based on a first question sample included in first training data, a first database pattern item matching the first question sample, and a first real query statement matching the first question sample, to obtain a first model that has undergone the first training; a first prediction module, configured to convert a second question sample and a second database pattern item matching the second question sample based on the first trained first model to obtain a first prediction query statement; an expansion module, configured to generate second training data based on a difference between a second real query statement corresponding to the second question sample and the first predicted query statement in response to a mismatch between the first predicted query statement and the second question sample; The second training module is used to perform second training on the first model that has undergone the first training based on the first training data and the second training data to obtain the first model that has undergone the second training.
11. A data processing device, characterized in that: The device comprises: a first matching module, configured to perform matching processing on the fifth question sample and the third database pattern item to obtain a third predicted correlation between the fifth question sample and the third database pattern item; The first matching module is further configured to determine, based on the third predicted relevance, a fourth database pattern item that matches the fifth question sample from the third database pattern items; The second prediction module is used to convert the fifth question sample and the fourth database pattern item to obtain a fourth prediction query statement corresponding to the fifth question sample.
12. An electronic device, characterized in that: include: a memory for storing computer-executable instructions or computer programs; The processor is configured to implement the data processing method according to any one of claims 1 to 9 when executing the computer-executable instructions or computer programs stored in the memory.
13. A computer-readable storage medium storing computer-executable instructions or a computer program, characterized in that: When the computer-executable instructions or computer programs are executed by a processor, the data processing method according to any one of claims 1 to 9 is implemented.
14. A computer program product comprising computer executable instructions or a computer program, characterized in that When the computer executable instructions or computer program are executed by a processor, the data processing method according to any one of claims 1 to 9 is implemented.
Citation Information
Cited By
Training data set synthesis method, device and equipment based on error driving
CN121434795A
An error-driven training data set forming method, device and equipment
CN121434795B