Data query statement generation method, apparatus and device, and storage medium
Through logic-driven methods and a generative large language model based on thinking chains, natural language is converted into data query statements, solving the problems of complex conversion process and poor interpretation in the existing technology, and achieving high transparency and accuracy data query statement generation.
Patent Information
- Application Number
- PCT/CN2024/110694
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-11-06
- Filing Date
- 2024-08-08
- Publication Date
- 2025-05-15
AI Technical Summary
The prior art has problems in the transformation process of natural language to data query statements that are difficult to adapt to complex and diverse query needs, lack of training data, poor results, large computing resources, poor model interpretation, and long interaction and training time.
Through a logic-driven method, natural language is converted into data query statements, and the generational large language model based on pre-constructed thinking chains is used to generate intermediate generation results and target data query statements, and the requirements are displayed through the prompt word instruction construction process to improve the measurability and controllability of the conversion process.
It improves the transparency and accuracy of the data query statement generation process, enhances the interpretability of the output results, reduces the possibility of errors, and makes the statement conversion processing process more intuitive and controllable.
Smart Images

Figure CN2024110694_15052025_PF_FP_ABST
Abstract
Description
Data query statement generation method, device, equipment and storage medium
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on November 6, 2023, with application number 202311468107.4, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of data processing technology, and for example, to a method, apparatus, device, and storage medium for generating a data query statement. Background Art
[0003] In today's digital age, the need to extract useful information from large datasets is increasingly urgent. Data query languages are widely used in databases to extract, modify, and manage data. For example, Structured Query Language (SQL) is often used in relational databases for data management and other operations. However, for users unfamiliar with data query languages or database structures, writing effective data query statements can be a challenging task. To simplify user interaction with databases, the conversion of natural language into data query statements has become a hot research topic.
[0004] Large language models, deep learning models trained on large amounts of text, are used to generate corresponding data query statements from user-provided natural language questions. This allows non-expert users to issue queries directly in natural language without having to learn complex data query language syntax and database structures. Currently, a variety of methods exist for converting natural language to data query statements, including mapping natural language to data query statements based on manually formulated rules and templates, modeling and matching natural language with corresponding data query statements using machine learning algorithms and training data, using deep learning techniques to perform end-to-end modeling and mapping of natural language and data query statements, and using reinforcement learning algorithms to learn and optimize strategies for generating data query statements through interaction with the database.
[0005] However, manually developing rules and templates requires extensive manual effort and expertise, making them difficult to adapt to complex and diverse query requirements. Machine learning algorithms based on maximum entropy models, hidden Markov models, and conditional random fields may not be effective for specific domains or complex queries that lack training data. Methods using deep learning techniques, such as models based on recurrent neural networks and attention mechanisms, and transformer-based models, while enabling more flexible and accurate natural language-to-data query conversion through large-scale training data and parameter optimization, require large amounts of labeled data and computing resources, and their models offer relatively weak interpretability. Data query generation methods based on reinforcement learning algorithms require lengthy interaction and training times, and incur high database access costs. Furthermore, none of these methods are intuitive or controllable in their natural language-to-data query process, making it difficult for users to obtain logical explanations during actual operations and failing to meet the needs of non-expert users for data query generation.
[0006] Summary of the Invention
[0007] This application provides a charge and discharge control method, device, equipment and storage medium, which can be driven by logic to
[0008] The language is converted into data query statements, making the statement conversion process measurable and controllable, improving the interpretability of the output results, enhancing the transparency of the data query statement generation process, and reducing possible errors in the data query statement generation process.
[0009] In a first aspect, an embodiment of the present application provides a method for generating a data query statement, comprising:
[0010] Acquisition process display requirements and natural sentences to be converted;
[0011] Construct prompt word instructions based on process demonstration requirements;
[0012] Based on the prompt word instruction, the natural sentence to be converted is input into the pre-trained data query sentence generation model, and the intermediate generation result and target data query sentence corresponding to the process display requirements are determined and output according to the model output result;
[0013] The pre-trained data query statement generation model is a generative large language model trained based on a pre-built thought chain. The pre-built thought chain is a thought chain constructed by logically segmenting the logical plan corresponding to the data query statement.
[0014] Among them, the prompt word instructions are constructed according to the process display requirements, including:
[0015] Determine intermediate output requirements and target output requirements based on process demonstration requirements;
[0016] Determine the corresponding intermediate prompt question template according to the intermediate output requirement; wherein the intermediate prompt question template is set to prompt the input and output targets from the original data to the intermediate output requirement;
[0017] Determine the corresponding target prompt question template according to the target output requirement; wherein the target prompt question template is set to prompt the input and output targets from the intermediate output corresponding to the intermediate output requirement to the target output requirement;
[0018] splicing the intermediate prompt question template and the target prompt question template to determine the prompt word instruction;
[0019] Among them, the intermediate output requirements include at least the original thinking chain output requirements, the optimized thinking chain output requirements and the original data query statement output requirements; the target output requirements include at least the original data query statement output requirements and the optimized data query statement output requirements;
[0020] Before obtaining the process display requirements and the natural sentences to be converted, it also includes:
[0021] Obtaining a statement conversion data set; the statement conversion data set includes at least two sets of statement conversion data, each set of statement conversion data including a one-to-one correspondence between a natural statement, semantic description information, and a data query statement;
[0022] Determine an original thinking chain corresponding to each sentence conversion data according to an original logical plan corresponding to each sentence conversion data, and determine an original training sample set corresponding to the sentence conversion data set according to each sentence conversion data and each original thinking chain;
[0023] The initial data query statement generation model is trained using the original training sample set to obtain an intermediate data query statement generation model;
[0024] According to the optimization logic plan corresponding to each sentence conversion data, determine the optimization thinking chain corresponding to each sentence conversion data;
[0025] Input each optimized thinking chain into the intermediate data query statement generation model to obtain the intermediate model output results corresponding to each optimized thinking chain, and determine the optimized training sample set corresponding to the statement conversion data set based on each statement conversion data, each original thinking chain, each optimized thinking chain and each intermediate model output result;
[0026] The intermediate data query statement generation model is trained by optimizing the training sample set to obtain a data query statement generation model.
[0027] In a second aspect, an embodiment of the present application provides a data query statement generating device, comprising:
[0028] The demand statement acquisition module is configured to display the demand and the natural statement to be converted during the acquisition process;
[0029] An instruction building module is configured to build prompt word instructions according to process display requirements;
[0030] A query statement generation module is configured to input the natural sentence to be converted into a pre-trained data query statement generation model based on the prompt word instruction, and determine and output the intermediate generation result and target data query statement corresponding to the process display requirements according to the model output result;
[0031] Among them, the pre-trained data query statement generation model is a generative large language model obtained by training based on a pre-constructed thinking chain, and the pre-constructed thinking chain is a thinking chain constructed after logical segmentation of the logical plan corresponding to the data query statement.
[0032] In a third aspect, an embodiment of the present application further provides a data query statement generating device, comprising:
[0033] at least one processor; and
[0034] a memory communicatively connected to at least one processor; wherein,
[0035] The memory stores a computer program that can be executed by at least one processor. The computer program is executed by at least one processor so that the at least one processor can execute the data query statement generation method provided in the embodiment of the present application.
[0036] In a fourth aspect, an embodiment of the present application further provides a storage medium comprising computer-executable instructions, which, when executed by a computer processor, are used to execute the data query statement generation method provided in an embodiment of the present application.
[0037] The embodiments of the present application provide a data query statement generation method, apparatus, device and storage medium, which obtain process display requirements and natural sentences to be converted; construct prompt word instructions according to the process display requirements; input the natural sentences to be converted into a pre-trained data query statement generation model based on the prompt word instructions, and determine and output the intermediate generation results and target data query statements corresponding to the process display requirements according to the model output results; wherein the pre-trained data query statement generation model is a generative large language model obtained by training based on a pre-constructed thinking chain, and the pre-constructed thinking chain is a thinking chain constructed after logical segmentation of the logical plan corresponding to the data query statement. By adopting the above technical solution, since the applied data query statement generation model is a generative large language model obtained by training based on a pre-built thinking chain, and the thinking chain is constructed after logical segmentation according to the corresponding logical plan of the data query statement, when the data query statement is applied to the conversion process of the natural statement to be converted into the data query statement, the corresponding thinking chain can be generated by the data query statement generation model to indicate the conversion logic of the input natural statement to be converted into the target data query statement. At the same time, the prompt word instruction can be completed according to the process display requirements pre-given by the user to guide the data query statement generation model to output and display information such as the thinking chain containing the logical conversion process as an intermediate generation result, clarifying the logic-driven conversion process of the natural statement to be converted into the target data query statement, making the statement conversion process measurable and controllable, improving the interpretability of the output results, and enhancing the transparency of the target data query statement generation process. At the same time, since the data query statement generation model is obtained by training based on logical segmentation to construct a thinking chain, it can analyze and correct errors that may occur in the data query statement generation process based on the multi-level logic contained in the thinking chain, thereby improving the accuracy of the conversion from the natural statement to be converted to the target data query statement. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] FIG1 is a flow chart of a method for generating a data query statement provided in Example 1 of the present application;
[0039] FIG2 is a flow chart of a method for generating a data query statement provided in Example 2 of the present application;
[0040] FIG3 is a training flow chart of a data query statement generation model provided in Example 2 of the present application;
[0041] FIG4 is a flowchart illustrating a method for determining an original thought chain corresponding to each sentence conversion data based on an original logic plan corresponding to each sentence conversion data, and determining an original training sample set corresponding to the sentence conversion data set based on each sentence conversion data and each original thought chain, provided in Example 2 of the present application;
[0042] FIG5 is a flowchart illustrating an example of determining an optimization thought chain corresponding to each statement conversion data according to an optimization logic plan corresponding to each statement conversion data, provided in the second embodiment of the present application;
[0043] FIG6 is a flowchart illustrating a method for determining an optimized training sample set corresponding to a sentence conversion data set based on sentence conversion data, original thought chains, optimized thought chains, and output results of intermediate models, provided in Example 2 of the present application;
[0044] FIG7 is a schematic diagram of the structure of a data query statement generating device provided in Example 3 of the present application;
[0045] FIG8 is a schematic structural diagram of a data query statement generating device provided in Example 4 of the present application. DETAILED DESCRIPTION
[0046] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in a sequence other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0047] Example 1
[0048] Figure 1 is a flowchart of a data query statement generation method provided in Example 1 of the present application. This embodiment of the present application is applicable to situations where a natural language question posed by a user is converted into a data query statement that can be used for data query management in a database. The method can be executed by a data query statement generation device, which can be configured in a data query statement generation device. Optionally, the data query statement generation device can be a laptop, desktop computer, smart tablet, etc., which is not limited by the present embodiment of the application.
[0049] As shown in FIG1 , a method for generating a data query statement provided in an embodiment of the present application specifically includes the following steps:
[0050] S101. Acquisition process display requirements and natural sentences to be converted.
[0051] In this embodiment, the process display requirement can be specifically understood as the requirement proposed and input by the user, hoping to clarify the conversion logic and final conversion target of the natural statement to the data query statement.
[0052] The natural language question description raised and input by the user needs to be converted into a data query statement.
[0053] Specifically, digital assistant products in the financial sector often answer customer questions intelligently. Intelligent question-answering systems in related technologies can retrieve answers from knowledge bases based on customer questions, but they often cannot provide answers that require database queries. However, this solution, by building a new data query statement generation model, can generate data query statements that can be used for database queries from natural statements. Therefore, questions raised by customers can be received externally, and natural language customer questions can be identified as natural statements to be converted. At the same time, users can be prompted to enter their requirements for the conversion logic from natural statements to data query statements and the final conversion target, which can be identified as process display requirements.
[0054] It is understandable that the process display requirements may only include the final display result requirements that the user expects to obtain, but not the intermediate process display requirements. The user can be prompted based on the type of intermediate results that can be generated by the data query statement generation model, so that the user can enter the process display requirements that meet the output capabilities of this solution.
[0055] S102: Construct prompt word instructions according to process display requirements.
[0056] In this embodiment, the prompt word instruction can be specifically understood as an artificial intelligence prompt word (prompt) that uses natural language to guide or inspire the artificial intelligence model to complete a specific task. In this embodiment, it can be understood as an instruction constructed according to the process display requirements to prompt the content of the data query statement generation model input at different stages, as well as prompt the data query statement generation model output content.
[0057] Specifically, the process display requirements are broken down to clarify the user's desire to ultimately obtain a data query statement, as well as the user's desire to display intermediate results during the conversion process from the natural statement to be converted to the data query statement. The resulting intermediate result requirements and data query statement requirements can then be arranged in order of execution, and the process from the previous requirement to the next requirement can be defined as a task. Using pre-defined templates or clarifying task descriptions based on task objectives, required operations, and related conditions, task prompts are written using common vocabulary, taking into account context and context. The corresponding prompts for each task are then combined in chronological order to obtain prompt word instructions corresponding to the process display requirements.
[0058] It’s important to be clear that when constructing prompts, they should be concise, easy to understand, and relevant to the task being described.
[0059] S103: Based on the prompt word instruction, the natural sentence to be converted is input into the pre-trained data query sentence generation model, and the intermediate generation result and target data query sentence corresponding to the process display requirements are determined and output according to the model output result.
[0060] Among them, the pre-trained data query statement generation model is a generative large language model obtained by training based on a pre-constructed thinking chain, and the pre-constructed thinking chain is a thinking chain constructed after logical segmentation of the logical plan corresponding to the data query statement.
[0061] In this embodiment, the data query statement generation model can be specifically understood as a generative large language model that converts natural language input statements into chains of thought, and vice versa. Chain-of-thought (CoT) can be specifically understood as an improved prompting strategy for improving the performance of large language models in complex reasoning tasks, which may include inference prompting information between input and output.
[0062] Specifically, each data query statement corresponding to the database has the logic for executing the data query statement. Before being converted into a physical execution plan, it can be called the logical plan corresponding to the data query statement. In order to logically implement a logical plan, multiple logical execution operations for serial or parallel processing will be required. There is a dependency relationship between each logical execution operation. The execution order of each execution operation and the serial and parallel execution mode can be determined according to the corresponding dependency relationship. Therefore, the execution logic of the data query statement can be determined by logically segmenting the logical plan, and the thinking chain can be used to describe the deduction prompt information of each logical execution operation in the execution logic. Therefore, the thinking chain corresponding to the data query statement can be constructed based on the logical plan corresponding to the logically segmented data query statement, and the thinking chain can be used as an intermediate node between natural language and data query statement to complete the training of the data query statement generation model, so that the trained data query statement generation model has the ability to output a thinking chain based on the natural statement input therein, and the ability to output a data query statement based on the thinking chain input therein. Because a thought chain containing reasoning prompts from natural sentences to data query sentences can be output as an intermediate node, when the natural sentence to be converted is input into the pre-trained data query sentence generation model based on the prompt word instruction, not only the target data query sentence corresponding to the natural sentence to be converted is obtained, but also a thought chain containing reasoning prompt information corresponding to the natural sentence to be converted is obtained as an intermediate generation result. The intermediate generation result required to be output by the data query sentence generation model is determined based on the process demonstration requirements, and the intermediate generation result is again used as the input of the data query sentence generation model, so that the final model output result is determined as the target data query sentence.
[0063] The technical solution of this embodiment is to obtain process display requirements and natural sentences to be converted; construct prompt word instructions according to the process display requirements; input the natural sentences to be converted into a pre-trained data query statement generation model based on the prompt word instructions, and determine and output the intermediate generation results and target data query statements corresponding to the process display requirements according to the model output results; wherein the pre-trained data query statement generation model is a generative large language model obtained by training based on a pre-constructed thinking chain, and the pre-constructed thinking chain is a thinking chain constructed after logical segmentation of the logical plan corresponding to the data query statement. By adopting the above technical solution, since the applied data query statement generation model is a generative large language model obtained by training based on a pre-built thinking chain, and the thinking chain is constructed after logical segmentation according to the corresponding logical plan of the data query statement, when the data query statement is applied to the conversion process of the natural statement to be converted into the data query statement, the corresponding thinking chain can be generated by the data query statement generation model to indicate the conversion logic of the input natural statement to be converted into the target data query statement. At the same time, the prompt word instruction can be completed according to the process display requirements pre-given by the user to guide the data query statement generation model to output and display information such as the thinking chain containing the logical conversion process as an intermediate generation result, clarifying the logic-driven conversion process of the natural statement to be converted into the target data query statement, making the statement conversion process measurable and controllable, improving the interpretability of the output results, and enhancing the transparency of the target data query statement generation process. At the same time, since the data query statement generation model is obtained by training based on logical segmentation to construct a thinking chain, it can analyze and correct errors that may occur in the data query statement generation process based on the multi-level logic contained in the thinking chain, thereby improving the accuracy of the conversion from the natural statement to be converted to the target data query statement.
[0064] Example 2
[0065] Figure 2 is a flowchart of a data query statement generation method provided in Example 2 of the present application. The technical solution of the embodiment of the present application is further optimized on the basis of the above-mentioned optional technical solutions. By analyzing the process display requirements, the intermediate prompt question template and the target prompt question template corresponding to them are determined respectively according to the division into intermediate output requirements and target output requirements. The intermediate prompt question template and the target prompt question template are spliced to obtain prompt word instructions for prompting the data query statement generation model to output according to the user process display requirements, so that the data query statement generation model can generate an intermediate generation result for the input natural sentence to be converted according to the intermediate prompt question template, and obtain the target data query statement according to the input intermediate generation result according to the target prompt question template, thereby realizing the display of the target data query statement generation process, making the statement conversion processing process measurable and controllable, improving the interpretability of the output results, and enhancing the transparency of the target data query statement generation process. At the same time, this embodiment also provides a training method for the data query statement generation model. By obtaining a statement conversion data set, the logical plan corresponding to the data query statement in the statement conversion data set is determined using methods with different degrees of optimization, and then the logical plan is logically segmented according to the dependency relationship, and the corresponding original thinking chain and optimized thinking chain are constructed. Then, the original training sample set is constructed based on the original thinking chain and the statement conversion data set to complete the preliminary training of the initial data query statement generation model, so that the intermediate data query statement generation model obtained by training has the ability to generate natural statements->thinking chains->data query statements while retaining maximum logical semantic information. Then, based on the optimized thinking chain and the intermediate data query statement generation model, the construction of the optimized training sample set is completed, and the intermediate data query statement generation model is further optimized and trained through the optimized training sample set, so that the final data query statement generation model not only has the ability to generate natural statements->thinking chains->data query statements while retaining the maximum logical semantic information, but also has the ability to generate natural statements->thinking chains->data query statements while optimizing logical semantic information, as well as the ability to convert between the two thinking chains under different logical semantic information. This further enriches the types of intermediate generation results that can be generated by the data query statement generation model, so that the generation logic from natural statements to data query statements can be displayed more clearly and in detail, and then, based on the multi-level logic contained in the thinking chain, errors that may occur in the data query statement generation process can be analyzed and corrected, thereby improving the accuracy of the conversion from the natural statement to be converted to the target data query statement.
[0066] As shown in FIG2 , a method for generating a data query statement provided in the second embodiment of the present application specifically includes the following steps:
[0067] S201. Acquisition process display requirements and natural sentences to be converted.
[0068] S202: Determine intermediate output requirements and target output requirements based on process display requirements.
[0069] Among them, the intermediate output requirements include at least the original thinking chain output requirements, the optimized thinking chain output requirements and the original data query statement output requirements; the target output requirements include at least the original data query statement output requirements and the optimized data query statement output requirements.
[0070] In this embodiment, the original thinking chain output requirement can be specifically understood as the requirement that the data query statement generation model outputs the corresponding unoptimized thinking chain based on the input natural statement, which retains the logical semantic information to the greatest extent. The optimized thinking chain output requirement can be specifically understood as the requirement that the data query statement generation model outputs the corresponding optimized thinking chain based on the input natural statement or the original thinking chain, which has been processed by optimization strategies such as "predicate pushdown". The original data query statement output requirement can be specifically understood as the requirement that the data query statement generation model outputs the corresponding original data query statement based on the input original thinking chain. Each of the above output requirements can be considered as the output requirement of the intermediate result of the data query statement converted from the natural statement to the end user's requirement, so it can be considered that each of the above output requirements is an intermediate output requirement. The optimized data query statement output requirement can be specifically understood as the requirement that the data query statement generation model outputs the corresponding optimized data query statement based on the input optimized thinking chain. It is understandable that both the original data query statement and the optimized data query statement can be used as the data query statement that the user ultimately needs. They only represent that the data query statement generation model produces different results due to different thought chains input into it when performing the generation task. Therefore, the original data query statement output requirements and the optimized data query statement output requirements can both be used as optional target output requirements.
[0071] Optionally, prompts for intermediate output requirements and target output requirements can be set based on the ability to generate a model based on trained data query statements, so that users can configure process display requirements according to their own needs.
[0072] S203: Determine a corresponding intermediate prompt question template according to the intermediate output requirement.
[0073] Among them, the intermediate prompt question template is set to prompt the input and output targets from original data to intermediate output requirements.
[0074] Specifically, based on a specific intermediate output requirement, the original data desired to be input into the data query statement generation model, as well as the intermediate output desired to be obtained by the data query statement generation model for the input original data, are determined. Based on the original data, intermediate output, conversion target, and required operations, an intermediate prompt question template corresponding to the intermediate output requirement is determined, which is used to prompt the input and output targets from the original data to the intermediate output requirement. Optionally, the intermediate prompt question template can be pre-set based on the intermediate results that can be output by the data query statement generation model, or can be determined in real time each time based on the intermediate output requirement provided by the user. This embodiment of the present application is not limited to this.
[0075] For example, assuming that the intermediate output requirement is the original thought chain, the intermediate prompt question template can be expressed as: "It is known that the natural sentence to be converted that the user wants to convert is as follows {} Please generate an original thought chain containing a detailed description of the implementation steps based on the above natural sentence to be converted." The above intermediate prompt question template is only an example provided in the embodiment of this application. The specific implementation method can be adaptively set according to actual conditions, and the embodiment of this application does not limit this.
[0076] S204: Determine a corresponding target prompt question template according to the target output requirement.
[0077] Among them, the target prompt question template is set to prompt the input and output targets from the intermediate output corresponding to the intermediate output requirement to the target output requirement.
[0078] Specifically, based on the specific target output requirement, the intermediate output corresponding to the intermediate output requirement input into the data query statement generation model is determined, as well as the data query statement that the user desires the data query statement generation model to ultimately output for the intermediate output. Based on the intermediate output, the data query statement, the conversion target, and the required operations, a target prompt question template corresponding to the target output requirement is determined, which is used to prompt the input and output targets from the intermediate output to the target output requirement. Optionally, the target prompt question template can be pre-set based on the desired data query statement that the data query statement generation model can output, or it can be determined in real time each time based on the target output requirement provided by the user. This embodiment of the present application is not limited to this.
[0079] For example, assuming the target output requirement is a raw data query statement output requirement, the target prompt question template can be expressed as: "Follow the following steps {} Please generate the raw data query statement corresponding to the question step by step according to the above steps." The "{}" can be entered as the step description information contained in the original thought chain corresponding to the raw data query statement. The above target prompt question template is only an example provided in the embodiments of this application. The specific implementation method can be adaptively set according to actual circumstances and is not limited in this embodiment of the application.
[0080] S205: The intermediate prompt question template and the target prompt question template are combined to form a prompt word instruction.
[0081] Specifically, sort the intermediate prompt question templates in the execution order, and
[0082] The target prompt question template is sequentially spliced together, and the spliced content is determined as the prompt word instruction.
[0083] It is understandable that when determining the process display requirements, the user may not provide intermediate output requirements, but only provide target output requirements. In this case, the prompt word instruction is the target prompt question template.
[0084] S206. Input the natural sentence to be converted into the pre-trained data query sentence generation model according to the intermediate prompt question template, and determine the obtained model output result as the intermediate generation result.
[0085] Specifically, when there is only one intermediate prompt question template, the natural sentence to be converted will be input into the pre-trained data query statement generation model based on the intermediate prompt question template, and the model output result obtained at this time will be determined as the intermediate generation result. When there are multiple intermediate prompt question templates, the corresponding content will be input into the data query statement generation model based on the input requirements contained in the intermediate prompt question template, and the output result of the data query statement generation model will be determined as the intermediate generation result corresponding to the intermediate prompt question template. It can be understood that at this time, the input corresponding to the first intermediate prompt question template should be the natural sentence to be converted, and the input corresponding to the intermediate prompt question template that is chronologically subsequent to it can be the model output of the previous data query statement generation model.
[0086] S207: Input the intermediate generated result into the data query statement generation model based on the target prompt question template, and determine the obtained model output result as the target data query statement. Furthermore, before obtaining the process display requirements and the natural statement to be converted, the data query statement generation model will be trained. Figure 3 is a training flow chart of a data query statement generation model provided in Example 2 of this application. As shown in Figure 3, it specifically includes the following steps:
[0087] S301: Obtain a statement conversion data set.
[0088] The statement conversion data set includes at least two groups of statement conversion data, and each group of statement conversion data contains a one-to-one correspondence of natural sentences, semantic description information and data query statements.
[0089] In this embodiment, the statement conversion dataset can be specifically understood as a collection of multiple sets of corresponding database table description information, query questions, and data query statements, organized based on the intended application scenario. Each set of database table description information, query question, and data query statement can be considered as a set of statement conversion data in the statement conversion dataset. It is understood that the natural statements in the statement conversion data can be specifically understood as the natural language query questions provided by users when performing data queries in the database; the semantic description information can be specifically understood as the semantically relevant description information corresponding to the data query statements required by the database.
[0090] For example, taking the financial database assisted query scenario as an example, the types of problems that the financial digital assistant can handle include table-based problems, information retrieval problems, content summary problems, hot spot searches, etc., among which table-based problems are problems that rely on database queries to output results. In the embodiment of the present application, for the collation and acquisition of statement conversion data sets, each set of table descriptions, query questions, and data query statements can be used as a set of statement conversion data in the statement conversion data set based on the query questions and corresponding data query statements related to the table descriptions and data collation in the financial database. Taking the equity incentive table t_inc_esop_info in the financial database as an example, each statement conversion data in the statement conversion data set obtained after corpus collation may include natural statements, that is, descriptions of query questions in natural language, which may be referred to as Query here; data query statements corresponding to natural statements, here taking SQL query statements as an example, and subsequently referred to as SQL; and semantic description information, that is, semantic description information, which may be referred to as schema here. An example of one set of statement conversion data is shown as follows:
[0091] {"question":"From January 1, 2022 to date, how many listed companies have successfully implemented equity incentives?"
[0092] "sql":"select count(distinct(S_INFO_WINDCODE))from t_inc_esop_info where trunc(now(),'YYYY-MM-DD')>='2022-01-01'and progress_name='Completed'",
[0093] "schema":"create table t_inc_esop_info(\n id,\n s_info_windcode, stock code.\n ns_info_name, stock name.\n preplan_ann_date, draft announcement date.\n s_inc_firstinc, grant date.\n ns_inc_initexecpri, grant price.\n s_inc_quantity, total number of incentives (10,000 shares / 10,000 shares).\n inc_return_rate, equity incentive return rate (%).\n citics_1, CITIC industry level 1.\n citics_2, CITIC industry level 2.\n citics_3, CITIC industry level 3.\n s_info_province, province.\n s_info_city, city.\n wind_sec_code, company type.\n progress_name, plan progress.\n inc_execpct_set varchar2(50), unlocking ratio for each period.\ninc_intervaltime_set, lockup time for each batch (months).\n script_type, incentive tool.\n discount, nominal discount rate = grant price / benchmark price.\n discount_real, actual discount rate = grant price / closing price on grant date.\n inc_count, current number of incentives, same draft date counted as the same period.\n total_inc_times, cumulative number of incentives (periods).\n person_count number(20,0), number of incentives.\n staff, total number of employees.\n interval_months, lockup period (months).\n locked_period, lockup period (years).\n s_info_listdate, listing date.\n s_info_exchmarket, listing exchange.\n days_from_ipo_to_firstinc, number of days from first equity incentive to listing. Negative value indicates equity incentives were implemented before listing.\n agency name.\n)",
[0094] "lan":"zh"}
[0095] S302. Determine the original thinking chain corresponding to each statement conversion data according to the original logical plan corresponding to each statement conversion data, and determine the original training sample set corresponding to the statement conversion data set according to each statement conversion data and each original thinking chain.
[0096] In this embodiment, the original logical plan can be specifically understood as a logical plan generated by compiling the SQL in the statement conversion data without undergoing optimization strategy processing, which can retain the logical semantic information in the SQL to the greatest extent. The original thinking chain can be specifically understood as a thinking chain that is constructed based on the logical relationship chain contained in the original logical plan, after being segmented and hierarchically divided according to the dependency relationship, and includes introductions to logical execution at different levels. The original training sample set can be specifically understood as a set of training samples used for preliminary training of the data query statement generation model, so that the data query statement generation model can have the ability to determine the original thinking chain from natural statements, and the data query statement corresponding to the natural statement from the original thinking chain.
[0097] Specifically, for each statement conversion data, the data query statement contained therein is compiled without optimization processing to obtain an original logical plan that can retain the logical semantic information in the data query statement to the greatest extent. The original logical plan can be a logical plan syntax tree structure, and then the forks of the logical plan syntax tree can be divided according to the dependency relationship to determine the serial and parallel relationships and hierarchical relationships of multiple execution operations and the corresponding operation steps of each execution operation. Then, based on the above-mentioned serial and parallel relationships and hierarchical relationships, combined with the semantic description information in the statement conversion data, the description of each execution operation and execution step is determined, and then they are combined to form an original thinking chain corresponding to the original logical plan, and the original thinking chain is associated with the statement conversion data to construct an original training sample corresponding to each statement conversion data, and the set composed of each original training sample is determined as the original training sample set.
[0098] Optionally, FIG4 is a flowchart of a process for determining an original thought chain corresponding to each statement conversion data based on an original logic plan corresponding to each statement conversion data, and determining an original training sample set corresponding to the statement conversion data set based on each statement conversion data and each original thought chain, provided in Example 2 of the present application. As shown in FIG4 , the process specifically includes the following steps:
[0099] S3021. For each set of statement conversion data, determine an original logical plan corresponding to the data query statement in the statement conversion data.
[0100] Specifically, by traversing the statement conversion data set, the data query statements contained in each set of statement conversion data can be determined, and then by compiling each data query statement without an optimization strategy, the original logical plan corresponding to each data query statement can be determined.
[0101] Continuing with the above example, assuming that the statement conversion dataset can be represented as a Query-SQL dataset, where a set of one-to-one corresponding Query-SQL-schemas can be used as a set of statement conversion data, when generating the original training sample set, the Query-SQL dataset will first be traversed, and an original training sample will be generated for each set of statement conversion data. The SQL query statement in each set of statement conversion data will be extracted, and it can be recorded as SQL_i, where i is the sample sequence number. SQL_i is then input into the query performance analysis tool provided by the database management system to generate the logical plan corresponding to SQL_i. Since the query performance analysis tool may assume that no optimization strategy is adopted when determining the logical plan, the logical plan corresponding to SQL_i generated at this time can be considered as the original logical plan. Optionally, in the embodiment of the present application, Oracle's SQL Developer can be used to obtain a visual original logical plan.
[0102] S3022. Logically segment the original logical plan according to the dependency relationship, and determine the original logical segmentation result including the hierarchical order of execution operations and the hierarchical order of operation steps.
[0103] Continuing with the above example, since the original logical plan can be represented in the form of a logical plan syntax tree, which may contain logical relationships between multiple different execution operations, a relational link segmentation method can be used to divide each execution operation into different stages i_Lj according to the bifurcation of the logical plan syntax tree of the original logical plan. The serial and parallel processing relationships between each execution operation are determined based on execution dependencies, where i is the operation sequence number and j is the execution operation level sequence number. If there are no execution dependencies between different execution operations, they can be placed in the same execution operation level for parallel processing; otherwise, they can be placed in different levels for serial processing. Furthermore, each stage i_Lj can be divided into different operation steps stepk_Ph based on different data inputs and different data processing methods. The serial and parallel processing relationships between each operation step are determined based on execution dependencies, where k is the operation step sequence number and h is the operation step level sequence number. Operation steps with the same input data and the same data processing method can be placed at the same operation step level for serial processing, and operation steps involving different input data or different data processing methods can be placed at different operation step levels for parallel processing. This will result in the original logical segmentation result corresponding to the original logical plan, which includes the execution operation level sequence and the operation step level sequence.
[0104] In an embodiment of the present application, by constructing an original logical segmentation result including a hierarchical order of execution operations and a hierarchical order of operation steps, the parallel computing capabilities of multi-core processors and distributed systems can be maximized, thereby improving data computing efficiency.
[0105] S3023. Determine the original thinking chain corresponding to the sentence conversion data based on the original logical segmentation results and semantic description information, and determine the original training sample corresponding to the sentence conversion data based on the natural sentence, the original thinking chain and the data query sentence to obtain an original training sample set composed of the original training samples.
[0106] The original training samples include a first original training sub-sample consisting of a natural sentence and an original thought chain, and a second original training sub-sample consisting of an original thought chain and a data query sentence.
[0107] Specifically, since the original logical segmentation result contains the execution operation level sequence and the operation step level sequence, it can be used to indicate the execution relationship and execution structure of the corresponding data query statement in the execution process, in order to generate the original thinking chain containing the step explanation, that is, to change the coding object of the original logical segmentation result, the execution operations and operation steps in the serial space can be encoded respectively according to the execution operation level sequence and the operation step level sequence to identify the parallel and serial execution relationship. Among them, the execution operation level coding and the operation step level coding are performed in sequence, and the same coding indicates that the execution operation or operation step can be executed in parallel. After encoding step by step, the semantic description information with semantic annotations is used to generate a detailed description of the implementation of each execution operation and operation step, and it is spliced according to the structure corresponding to the original logical segmentation result to obtain the original thinking chain corresponding to the statement conversion data. Furthermore, the original thought chain can be used as a label for the natural sentence in the corresponding sentence conversion data to construct a first original training sub-sample, and the data query sentence in the sentence conversion data can be used as a label for the corresponding original thought chain to construct a second original training sub-sample. The first original training sub-sample and the second original training sub-sample are combined to determine the original training sample corresponding to the sentence conversion data, and the set composed of the original training samples is determined as the original training sample set.
[0108] For example, the content generation capability of the big data analysis model can be combined with multiple tables and field information in the semantic description information schema to construct a prompt word instruction from the semantic description information schema and data query statement SQL to the thinking chain CoT. Taking the equity incentive table t_inc_esop_info and the SQL in S301 as an example, the specific prompt word instruction can be expressed as follows:
[0109] {The known data table information is as follows: "" requires multiple steps. Please explain the content of each step step by step and generate the final SQL statement"." In each step, please explain the applicable SQL keywords, SQL functions, etc.
[0110] The schema and SQL from S301 can be inserted into the double quotes in the prompt word instruction, respectively, to guide the big data analysis model to output a specific step description. After the big data analysis model outputs the thought chain, the corresponding description in the thought chain can be cleaned up through manual verification or third-party evaluation models such as METEOR or BERTScore, ultimately obtaining the original thought chain CoT_P corresponding to the SQL.
[0111] Continuing with the above example, the CoT_P output by the big data analysis model can be described as:
[0112] [L1][stage 1]Step 1: Filter the t_inc_esop_info table.
[0113] <p1> <step101>Scan the table t_inc_esop_info that stores information about employee stock option plans
[0114] [L2][stage 2]Step 2: Filter rows that meet the conditions
[0115] <p1> <step201>Filter data from January 1, 2022. Use the NOW() function to obtain the current date. Then use the TRUNC function to truncate it to a day-based format. For example, truncate the current date to the day level to obtain a date in the 'YYYY-MM-DD' format. Next, compare the truncated date with '2022-01-01'. If the truncated date is greater than or equal to '2022-01-01', the row meets the criteria and is retained. If the truncated date is less than '2022-01-01', the row does not meet the criteria and is discarded.
[0116] <p2> <step202>Filter out companies that have successfully implemented equity incentives. Use the progress_name field to determine the progress of the equity incentive plan. If progress_name equals 'Completed', it means the company has successfully implemented equity incentives. Therefore, the row meets the criteria and is retained. Otherwise, the row is discarded.
[0117] [L3][stage 3]Step 3: Count the number of companies that meet the requirements.
[0118] <p1> <step301>Group the retained rows by the S_INFO_WINDCODE column. Then, use the DISTINCT function to remove duplicate values from the S_INFO_WINDCODE column within each group, obtaining the unique S_INFO_WINDCODE values within each group. Then, use the COUNT function to count the number of unique S_INFO_WINDCODE values within each group. Finally, use a SELECT statement to output the results.
[0119] Among them, [stage 1] and so on are used to indicate the execution operation sequence number of the execution operation in the original thinking chain, and [L1][L2] and so on are used to indicate the execution operation level sequence number corresponding to different execution operations in the original thinking chain. <step101>etc. are used to indicate the sequence of different steps in an execution operation in the original thinking chain. <p1>Etc. are used to indicate the hierarchical sequence numbers of the operation steps corresponding to different operation steps under an execution operation in the original thinking chain.
[0120] S303: Train the initial data query statement generation model using the original training sample set to obtain an intermediate data query statement generation model.
[0121] In this embodiment, the initial data query statement generation model can be specifically understood as a data query statement generation model that has not been adjusted by weight parameters.
[0122] Specifically, when training the initial data query statement generation model, two training tasks can be constructed based on the original training sample set. One training task is to train the initial data query statement generation model to learn the ability to generate thought chain descriptions based on natural sentences, and the other training task is to train the initial data query statement generation model to learn the ability to generate data query statements based on the input thought chain description.
[0123] Optionally, the initial data query statement generation model can be trained using a first original training sub-sample set composed of each first original training sub-sample to obtain a stage intermediate data query statement generation model; and the stage intermediate data query statement generation model can be trained using a second original training sub-sample set composed of each second original training sub-sample to obtain an intermediate data query statement generation model.
[0124] Specifically, since the first original training subsamples are training samples constructed using original thought chains as natural sentence labels, the initial data query statement generation model can be trained using the first original training subsample set composed of each first original training subsample, and the trained model is determined as the stage intermediate data query statement generation model. This stage intermediate data query statement generation model is capable of understanding natural sentences and generating corresponding original thought chain descriptions. Next, the stage intermediate data query statement generation model can be trained using the second original training subsample set composed of each second original training subsample using data query sentences as labels for their corresponding original thought chains. The trained model is determined as the intermediate data query statement generation model, so that the output intermediate data query statement generation model not only has the ability to generate original thought chain descriptions from natural sentences, but also has the ability to convert original thought chain descriptions into data query statements.
[0125] S304: Determine the optimization thinking chain corresponding to each statement conversion data according to the optimization logic plan corresponding to each statement conversion data.
[0126] In this embodiment, the optimized logical plan can be specifically understood as a logical plan generated by compiling the SQL in the statement conversion data after processing the optimization strategy, optimizing the logical and semantic information in the SQL. The optimized thought chain can be specifically understood as a thought chain constructed based on the logical relationship chain contained in the optimized logical plan, segmented and hierarchically divided according to dependencies, and including logical execution instructions at different levels.
[0127] It can be understood that the generation of optimized logical plans and optimized thinking chains, compared with the generation of original logical plans and original thinking chains, only differs in whether an optimization strategy is used to process the data query statements in the statement conversion data, which is consistent with the processing method in S302.
[0128] For example, FIG5 is a flowchart of an example of determining an optimization thinking chain corresponding to each statement conversion data based on an optimization logic plan corresponding to each statement conversion data provided in the second embodiment of the present application. As shown in FIG5 , the flowchart specifically includes the following steps:
[0129] S3041. For each set of statement conversion data, determine an optimization logic plan corresponding to the data query statement in the statement conversion data according to a preset optimization processing strategy.
[0130] S3042. Logically segment the optimized logical plan according to the dependency relationship, and determine the optimized logical segmentation result including the hierarchical order of execution operations and the hierarchical order of operation steps.
[0131] S3043. Determine the optimized thinking chain corresponding to the sentence conversion data based on the optimized logic segmentation result and the semantic description information.
[0132] S305. Input each optimized thinking chain into the intermediate data query statement generation model to obtain the intermediate model output result corresponding to each optimized thinking chain, and determine the optimized training sample set corresponding to the statement conversion data set based on each statement conversion data, each original thinking chain, each optimized thinking chain and each intermediate model output result.
[0133] Specifically, each optimized thought chain is sequentially input into the intermediate data query statement generation model. Since the intermediate data query statement generation model has the ability to determine data query statements based on thought chains, the intermediate model output result can be considered to be the data query statement generation result given by the intermediate data query statement generation model for the optimized optimized thought chain. At this time, the intermediate model output result can be compared with the data query statement output by the expected model contained in the data conversion data. Based on the comparison result, it is determined whether the intermediate model output result generated by the intermediate data query statement generation model can be adopted. Then, based on each statement conversion data, each original thought chain, each optimized thought chain, and each intermediate model output result, an optimized training sample set corresponding to the statement conversion data set is determined.
[0134] Optionally, FIG6 is a flowchart illustrating a process for determining an optimized training sample set corresponding to a sentence conversion data set based on each sentence conversion data, each original thought chain, each optimized thought chain, and each intermediate model output result, provided in Example 2 of the present application. As shown in FIG6 , the process specifically includes the following steps:
[0135] S3051. For each intermediate model output result, the intermediate model output result is verified through the data query statement in the corresponding statement conversion data. If the verification passes, the intermediate model output result is determined as the optimized data query statement corresponding to the statement conversion data.
[0136] Exemplarily, for each intermediate model output result, the intermediate model output result can be compared and verified with the data query statement in the corresponding statement conversion data through a verifier. If the results are consistent, the verification can be considered to have passed, and the intermediate model output result output by the intermediate data query statement generation model can be considered to be a correct result. At this time, the intermediate model output result is determined as the optimized data query statement corresponding to the statement conversion data to form a correspondence between the optimized data chain and the optimized data query statement, so that the corresponding relationship between the optimized data chain and the optimized data query statement can be used to complete the optimization training of the intermediate data query statement generation model.
[0137] S3052. Determine the optimized training samples corresponding to the sentence conversion data according to the natural sentences, original thought chains, optimized thought chains and optimized data query sentences in the sentence conversion data to obtain an optimized training sample set composed of the optimized training samples.
[0138] Among them, the optimized training samples include a first optimized training sub-sample consisting of natural sentences and optimized thinking chains, a second optimized training sub-sample consisting of optimized thinking chains and optimized data query sentences, and a third optimized training sub-sample consisting of original thinking chains and optimized thinking chains.
[0139] Specifically, the optimized thinking chain is used as a label for the natural sentence in the corresponding sentence conversion data to construct a first optimized training subsample, so that the first optimized training subsample can be used to train the model's ability to generate optimized thinking chains from natural data; the optimized data query sentence is used as a label for the corresponding optimized thinking chain to construct a second optimized training subsample, so that the second optimized training subsample can be used to train the ability to generate optimized data query sentences from optimized thinking chains; the optimized thinking chain is used as a label for the corresponding original thinking chain to construct a third optimized training subsample, so that the third optimized training subsample can be used to train the model's ability to transform the original thinking chain composed of unoptimized logical plans into the optimized thinking chain composed of optimized logical plans. Furthermore, the first optimized training subsample, the second optimized training subsample, and the third optimized training subsample are combined to determine the optimized training sample corresponding to the sentence conversion data, and the set composed of each optimized training sample is determined as the optimized training sample set.
[0140] S306: Train the intermediate data query statement generation model by optimizing the training sample set to obtain a data query statement generation model.
[0141] Specifically, the intermediate data query statement generation model is trained by the first optimized training sub-sample set composed of each first optimized training sub-sample to obtain the first-stage data query statement generation model; the first-stage data query statement generation model is trained by the second optimized training sub-sample set composed of each second optimized training sub-sample to obtain the second-stage data query statement generation model; the second-stage data query statement generation model is trained by the third optimized training sub-sample set composed of each third optimized training sub-sample to obtain the data query statement generation model.
[0142] Optionally, the optimization training of the data query statement generation model in S304-S306 is an optional technical solution. Based on the verification of the intermediate model output results determined in S3051, it can be determined whether the data query statement generation model needs to be optimized and trained. If the proportion of verification failures exceeds a preset ratio threshold, optimization training of the data query statement generation model can be initiated to improve the data generation accuracy of the data query statement generation model through optimization training. It is understandable that the original thought chain and the optimized thought chain can also be trained directly during the training process, and this embodiment of the application is not limited to this.
[0143] The technical solution of this embodiment analyzes the process display requirements, determines the corresponding intermediate prompt question template and target prompt question template according to the division into intermediate output requirements and target output requirements, splices the intermediate prompt question template and the target prompt question template to obtain prompt word instructions for prompting the data query statement generation model to output according to the user process display requirements, so that the data query statement generation model can generate an intermediate generation result for the input natural sentence to be converted according to the intermediate prompt question template, and obtain the target data query statement according to the input intermediate generation result according to the target prompt question template, thereby realizing the display of the target data query statement generation process, making the statement conversion processing process measurable and controllable, improving the interpretability of the output results, and enhancing the transparency of the target data query statement generation process. At the same time, this embodiment also provides a training method for the data query statement generation model. By obtaining a statement conversion data set, the logical plan corresponding to the data query statement in the statement conversion data set is determined using methods with different degrees of optimization, and then the logical plan is logically segmented according to the dependency relationship, and the corresponding original thinking chain and optimized thinking chain are constructed. Then, the original training sample set is constructed based on the original thinking chain and the statement conversion data set to complete the preliminary training of the initial data query statement generation model, so that the intermediate data query statement generation model obtained by training has the ability to generate natural statements->thinking chains->data query statements while retaining maximum logical semantic information. Then, based on the optimized thinking chain and the intermediate data query statement generation model, the construction of the optimized training sample set is completed, and the intermediate data query statement generation model is further optimized and trained through the optimized training sample set, so that the final data query statement generation model not only has the ability to generate natural statements->thinking chains->data query statements while retaining the maximum logical semantic information, but also has the ability to generate natural statements->thinking chains->data query statements while optimizing logical semantic information, as well as the ability to convert between the two thinking chains under different logical semantic information. This further enriches the types of intermediate generation results that can be generated by the data query statement generation model, so that the generation logic from natural statements to data query statements can be displayed more clearly and in detail, and then, based on the multi-level logic contained in the thinking chain, errors that may occur in the data query statement generation process can be analyzed and corrected, thereby improving the accuracy of the conversion from the natural statement to be converted to the target data query statement.
[0144] Example 3
[0145] Figure 7 is a structural diagram of a data query statement generation device provided in Example 3 of the present application. As shown in Figure 7, the data query statement generation device may include a requirement statement acquisition module 41, an instruction construction module 42 and a query statement generation module 43.
[0146] Among them, the requirement statement acquisition module 41 is configured to acquire process display requirements and natural statements to be converted; the instruction construction module 42 is configured to construct prompt word instructions according to the process display requirements; the query statement generation module 43 is configured to input the natural statements to be converted into the pre-trained data query statement generation model based on the prompt word instructions, and determine and output the intermediate generation results and target data query statements corresponding to the process display requirements according to the model output results; wherein the pre-trained data query statement generation model is a generative large language model obtained by training based on a pre-constructed thinking chain, and the pre-constructed thinking chain is a thinking chain constructed after logical segmentation of the logical plan corresponding to the data query statement.
[0147] The technical solution of the embodiment of the present application is that the data query statement generation model used is a generative large language model obtained by training based on a pre-built thinking chain, and the thinking chain is constructed after logical segmentation according to the corresponding logical plan of the data query statement. Therefore, when the data query statement is applied to the conversion process of the natural statement to be converted to the data query statement, the corresponding thinking chain can be generated by the data query statement generation model to indicate the conversion logic of the input natural statement to be converted to the target data query statement. At the same time, the construction of the prompt word instruction can be completed according to the process display requirements given in advance by the user to guide the data query statement generation model to output and display information such as the thinking chain containing the logical conversion process as an intermediate generation result, clarifying the logic-driven conversion process of the natural statement to be converted to the target data query statement, making the statement conversion processing process measurable and controllable, improving the interpretability of the output results, and enhancing the transparency of the target data query statement generation process. At the same time, since the data query statement generation model is obtained by training based on logical segmentation to construct a thinking chain, it can analyze and correct errors that may occur in the data query statement generation process based on the multi-level logic contained in the thinking chain, thereby improving the accuracy of the conversion from the natural statement to be converted to the target data query statement.
[0148] Optionally, the instruction building module 42 includes:
[0149] A demand determination unit, configured to determine intermediate output demands and target output demands based on process display demands;
[0150] The intermediate template construction unit is configured to determine a corresponding intermediate prompt question template according to the intermediate output requirement; wherein the intermediate prompt question template is configured to prompt the input and output targets from the original data to the intermediate output requirement;
[0151] A target template construction unit is configured to determine a corresponding target prompt question template according to a target output requirement; wherein the target prompt question template is configured to prompt an input and output target from an intermediate output corresponding to an intermediate output requirement to the target output requirement;
[0152] The instruction determination unit is configured to splice the intermediate prompt question template with the target prompt question template to determine it as a prompt word instruction; wherein the intermediate output requirements at least include the original thinking chain output requirements, the optimized thinking chain output requirements and the original data query statement output requirements; the target output requirements at least include the original data query statement output requirements and the optimized data query statement output requirements.
[0153] Optionally, the query statement generating module 43 includes:
[0154] An intermediate result generating unit is configured to input the natural sentence to be converted into a pre-trained data query sentence generating model according to the intermediate prompt question template, and determine the obtained model output result as the intermediate generated result;
[0155] The target sentence generation unit is configured to input the intermediate generation result into the data query sentence generation model according to the target prompt question template, and determine the obtained model output result as the target data query sentence.
[0156] Optionally, the data query statement generating device further includes: a model training module, specifically configured to:
[0157] Before obtaining the process display requirements and the natural sentences to be converted, a sentence conversion dataset is obtained; the sentence conversion dataset includes at least two sets of sentence conversion data, each set of sentence conversion data contains a one-to-one correspondence between natural sentences, semantic description information and data query statements;
[0158] Determine an original thinking chain corresponding to each sentence conversion data according to an original logical plan corresponding to each sentence conversion data, and determine an original training sample set corresponding to the sentence conversion data set according to each sentence conversion data and each original thinking chain;
[0159] The initial data query statement generation model is trained using the original training sample set to obtain an intermediate data query statement generation model;
[0160] According to the optimization logic plan corresponding to each sentence conversion data, determine the optimization thinking chain corresponding to each sentence conversion data;
[0161] Input each optimized thinking chain into the intermediate data query statement generation model to obtain the intermediate model output results corresponding to each optimized thinking chain, and determine the optimized training sample set corresponding to the statement conversion data set based on each statement conversion data, each original thinking chain, each optimized thinking chain and each intermediate model output result;
[0162] The intermediate data query statement generation model is trained by optimizing the training sample set to obtain a data query statement generation model.
[0163] Optionally, determining an original thought chain corresponding to each sentence conversion data according to an original logical plan corresponding to each sentence conversion data, and determining an original training sample set corresponding to the sentence conversion data set according to each sentence conversion data and each original thought chain, including:
[0164] For each set of statement conversion data, determine an original logical plan corresponding to the data query statement in the statement conversion data;
[0165] Logically segment the original logical plan based on the dependency relationship to determine the original logical segmentation result including the hierarchical sequence of execution operations and the hierarchical sequence of operation steps;
[0166] Determine the original thought chain corresponding to the sentence conversion data based on the original logical segmentation result and the semantic description information, and determine the original training sample corresponding to the sentence conversion data based on the natural sentence, the original thought chain and the data query sentence, so as to obtain an original training sample set composed of the original training samples;
[0167] The original training samples include a first original training sub-sample consisting of a natural sentence and an original thought chain, and a second original training sub-sample consisting of an original thought chain and a data query sentence.
[0168] Optionally, the initial data query statement generation model is trained using the original training sample set to obtain an intermediate data query statement generation model, including:
[0169] The initial data query statement generation model is trained using the first original training sub-sample set formed by each first original training sub-sample to obtain a stage intermediate data query statement generation model;
[0170] The intermediate data query statement generation model is trained using the second original training sub-sample set formed by each second original training sub-sample to obtain the intermediate data query statement generation model.
[0171] Optionally, according to the optimization logic plan corresponding to each statement conversion data, an optimization thinking chain corresponding to each statement conversion data is determined, including:
[0172] For each set of statement conversion data, determine the optimization logic plan corresponding to the data query statement in the statement conversion data according to the preset optimization processing strategy;
[0173] Logically segment the optimization logic plan based on the dependency relationship, and determine the optimization logic segmentation result including the hierarchical order of execution operations and the hierarchical order of operation steps;
[0174] The optimized thinking chain corresponding to the sentence conversion data is determined based on the optimized logic segmentation results and semantic description information.
[0175] Optionally, determining an optimized training sample set corresponding to the sentence conversion data set according to each sentence conversion data, each original thinking chain, each optimized thinking chain, and each intermediate model output result includes:
[0176] For each intermediate model output result, the intermediate model output result is verified by the data query statement in the corresponding statement conversion data. If the verification passes, the intermediate model output result is determined as the optimized data query statement corresponding to the statement conversion data;
[0177] Determine the optimized training samples corresponding to the sentence conversion data according to the natural sentences, original thought chains, optimized thought chains, and optimized data query sentences in the sentence conversion data to obtain an optimized training sample set consisting of the optimized training samples;
[0178] Among them, the optimized training samples include a first optimized training sub-sample consisting of natural sentences and optimized thinking chains, a second optimized training sub-sample consisting of optimized thinking chains and optimized data query sentences, and a third optimized training sub-sample consisting of original thinking chains and optimized thinking chains.
[0179] Optionally, the intermediate data query statement generation model is trained by optimizing the training sample set to obtain a data query statement generation model, including:
[0180] The intermediate data query statement generation model is trained using a first optimized training subsample set composed of the first optimized training subsamples to obtain a first-stage data query statement generation model;
[0181] The first-stage data query statement generation model is trained using a second optimized training subsample set composed of the second optimized training subsamples to obtain a second-stage data query statement generation model;
[0182] The second-stage data query statement generation model is trained using the third optimized training sub-sample set composed of the third optimized training sub-samples to obtain a data query statement generation model.
[0183] The charge and discharge control device provided in the embodiment of the present application can execute the data query statement generation method proposed in any embodiment of the present application, and has the corresponding functional modules and beneficial effects of the execution method.
[0184] Example 4
[0185] Figure 8 is a structural diagram of a data query statement generating device provided in Example 4 of the present application. The data query statement generating device 50 may be an electronic device intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present application described and / or required herein.
[0186] As shown in FIG8 , the data query statement generating device 50 includes at least one processor 51 and a memory, such as a read-only memory (ROM) 52 and a random access memory (RAM) 53, that is communicatively connected to the at least one processor 51. The memory stores a computer program that can be executed by the at least one processor, and the processor 51 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 52 or the computer program loaded from the storage unit 58 into the random access memory (RAM) 53. Various programs and data required for the operation of the data query statement generating device 50 can also be stored in the RAM 53. The processor 51, ROM 52, and RAM 53 are connected to each other via a bus 54. An input / output (I / O) interface 55 is also connected to the bus 54.
[0187] Multiple components in the data query statement generating device 50 are connected to an I / O interface 55, including an input unit 56, such as a keyboard and mouse; an output unit 57, such as various types of displays and speakers; a storage unit 58, such as a magnetic disk and optical disk; and a communication unit 59, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 59 allows the data query statement generating device 50 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.
[0188] The processor 51 can be any general-purpose and / or specialized processing component with processing and computing capabilities. Some examples of the processor 51 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various specialized artificial intelligence (AI) computing chips, various processors that run machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 51 executes the various methods and processes described above, such as the data query statement generation method.
[0189] In some embodiments, the data query statement generation method can be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 58. In some embodiments, part or all of the computer program can be loaded and / or installed on the data query statement generation device 50 via the ROM 52 and / or the communication unit 59. When the computer program is loaded into the RAM 53 and executed by the processor 51, one or more steps of the data query statement generation method described above can be performed. Alternatively, in other embodiments, the processor 51 can be configured to execute the data query statement generation method by any other appropriate means (e.g., by means of firmware).
[0190] Various embodiments of the systems and techniques described herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system-on-chip systems (SOCs), programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0191] Computer programs for implementing the methods of the present application may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when the computer program is executed by the processor, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The computer program may be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0192] In the context of the present application, a computer-readable storage medium can be a tangible medium that can contain or store a computer program for use by an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. A computer-readable storage medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium can be a machine-readable signal medium. A more specific example of a machine-readable storage medium can include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0193] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0194] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0195] A computing system may include clients and servers. The clients and servers are typically remote from each other and typically interact via a communication network. This client-server relationship arises through computer programs running on the respective computers, creating a client-server relationship. The server may be a cloud server, also known as a cloud computing server or cloud host. This server is a host product within a cloud computing service ecosystem that addresses the management difficulties and limited scalability of physical hosts and VPS services in related technologies.
[0196] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in this application can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of this application can be achieved. This is not limited herein. < / p1> < / p2> < / p1> < / p1>
Claims
1. A method for generating a data query statement, comprising: Acquisition process display requirements and natural sentences to be converted; Construct prompt word instructions according to the process display requirements; Based on the prompt word instruction, the natural sentence to be converted is input into a pre-trained data query sentence generation model, and according to the model output result, an intermediate generation result and a target data query sentence corresponding to the process display requirement are determined and output; The pre-trained data query sentence generation model is a generative large language model trained based on a pre-constructed thinking chain, and the pre-constructed thinking chain is a thinking chain constructed after logical segmentation of the logic plan corresponding to the data query sentence; The intermediate generated result is a thought chain corresponding to the natural sentence to be converted and including reasoning prompt information; The step of constructing a prompt word instruction according to the process display requirements includes: Determine intermediate output requirements and target output requirements based on the process demonstration requirements; Determine a corresponding intermediate prompt question template according to the intermediate output requirement; wherein the intermediate prompt question template is set to prompt the input and output targets from the original data to the intermediate output requirement; Determine a corresponding target prompt question template according to the target output requirement; wherein the target prompt question template is configured to prompt the input and output targets from the intermediate output corresponding to the intermediate output requirement to the target output requirement; splicing the intermediate prompt question template with the target prompt question template to determine as a prompt word instruction; Among them, the intermediate output requirements at least include the original thinking chain output requirements, the optimized thinking chain output requirements and the original data query statement output requirements; the target output requirements at least include the original data query statement output requirements and the optimized data query statement output requirements; Before the acquisition process displays the requirements and the natural sentences to be converted, it also includes: Acquire a statement conversion data set; the statement conversion data set includes at least two groups of statement conversion data, each group of the statement conversion data includes a one-to-one correspondence of natural sentences, semantic description information and data query statements; Determine the original thinking chain corresponding to each of the sentence conversion data according to the original logic plan corresponding to each of the sentence conversion data, and determine the original training sample set corresponding to the sentence conversion data set according to each of the sentence conversion data and each of the original thinking chains; The initial data query statement generation model is trained by using the original training sample set to obtain an intermediate data query statement generation model; Determine an optimization thinking chain corresponding to each of the sentence conversion data according to the optimization logic plan corresponding to each of the sentence conversion data; Input each of the optimized thinking chains into the intermediate data query statement generation model to obtain the intermediate model output results corresponding to each of the optimized thinking chains, and determine the optimized training sample set corresponding to the statement conversion data set according to each of the statement conversion data, each of the original thinking chains, each of the optimized thinking chains and each of the intermediate model output results; The intermediate data query statement generation model is trained using the optimized training sample set to obtain a data query statement generation model.
2. The method according to claim 1, wherein: The step of inputting the natural sentence to be converted into a pre-trained data query sentence generation model based on the prompt word instruction, and determining and outputting an intermediate generation result and a target data query sentence corresponding to the process display requirement according to the model output result includes: Inputting the natural sentence to be converted into the pre-trained data query sentence generation model according to the intermediate prompt question template, and determining the obtained model output result as the intermediate generation result; The intermediate generated result is input into the data query statement generation model according to the target prompt question template, and the obtained model output result is determined as the target data query statement.
3. The method according to claim 1, wherein: Determining the original thinking chain corresponding to each of the sentence conversion data according to the original logic plan corresponding to each of the sentence conversion data, and determining the original training sample set corresponding to the sentence conversion data set according to each of the sentence conversion data and each of the original thinking chains, includes: For each group of the statement conversion data, determining an original logical plan corresponding to the data query statement in the statement conversion data; Logically segment the original logic plan according to the dependency relationship, and determine the original logic segmentation result including the hierarchical order of execution operations and the hierarchical order of operation steps; Determine an original thought chain corresponding to the sentence conversion data according to the original logic segmentation result and the semantic description information, and determine an original training sample corresponding to the sentence conversion data according to the natural sentence, the original thought chain and the data query sentence, so as to obtain an original training sample set composed of the original training samples; The original training sample includes a first original training sub-sample consisting of the natural sentence and the original thought chain, and a second original training sub-sample consisting of the original thought chain and the data query sentence.
4. The method according to claim 3, wherein: The initial data query statement generation model is trained by the original training sample set to obtain an intermediate data query statement generation model, including: The initial data query statement generation model is trained by using the first original training sub-sample set formed by each of the first original training sub-samples to obtain a stage intermediate data query statement generation model; The intermediate data query statement generation model of the stage is trained by using the second original training sub-sample set formed by each of the second original training sub-samples to obtain the intermediate data query statement generation model.
5. The method according to claim 1, wherein: Determining the optimization thinking chain corresponding to each of the statement conversion data according to the optimization logic plan corresponding to each of the statement conversion data includes: For each group of the statement conversion data, determining an optimization logic plan corresponding to the data query statement in the statement conversion data according to a preset optimization processing strategy; Logically segment the optimization logic plan according to the dependency relationship, and determine the optimization logic segmentation result including the hierarchical order of execution operations and the hierarchical order of operation steps; An optimized thinking chain corresponding to the sentence conversion data is determined according to the optimized logic segmentation result and the semantic description information.
6. The method according to claim 1, wherein: The step of determining an optimized training sample set corresponding to the sentence conversion data set according to each of the sentence conversion data, each of the original thought chains, each of the optimized thought chains, and each of the intermediate model output results comprises: For each of the intermediate model output results, the intermediate model output result is verified by a data query statement in the corresponding statement conversion data, and if the verification passes, the intermediate model output result is determined as an optimized data query statement corresponding to the statement conversion data; Determine an optimized training sample corresponding to the sentence conversion data according to the natural sentence in the sentence conversion data, the original thinking chain, the optimized thinking chain and the optimized data query sentence, so as to obtain an optimized training sample set composed of the optimized training samples; Among them, the optimized training sample includes a first optimized training sub-sample consisting of the natural sentence and the optimized thinking chain, a second optimized training sub-sample consisting of the optimized thinking chain and the optimized data query sentence, and a third optimized training sub-sample consisting of the original thinking chain and the optimized thinking chain.
7. The method according to claim 6, wherein: The step of training the intermediate data query statement generation model by using the optimized training sample set to obtain a data query statement generation model includes: The intermediate data query statement generation model is trained by using a first optimized training sub-sample set formed by each of the first optimized training sub-samples to obtain a first-stage data query statement generation model; The first-stage data query statement generation model is trained by using the second optimized training sub-sample set formed by each of the second optimized training sub-samples to obtain the second-stage data query statement generation model; The second-stage data query statement generation model is trained by using the third optimized training sub-sample set composed of the third optimized training sub-samples to obtain a data query statement generation model.
8. A data query statement generating device, comprising: A demand sentence acquisition module, configured to display the demand and the natural sentence to be converted during the acquisition process; An instruction construction module, configured to construct prompt word instructions according to the process display requirements; The query statement generation module is configured to input the natural sentence to be converted into a pre-trained data query statement generation model based on the prompt word instruction, and determine and output the intermediate generation corresponding to the process display requirement according to the model output result. Results and target data query statements; The pre-trained data query sentence generation model is a generative large language model trained based on a pre-constructed thinking chain, and the pre-constructed thinking chain is a thinking chain constructed after logical segmentation of the logic plan corresponding to the data query sentence; The intermediate generated result is a thought chain corresponding to the natural sentence to be converted and including reasoning prompt information; Wherein, the instruction building module includes: A demand determination unit, which determines intermediate output demand and target output demand according to the process display demand; An intermediate template construction unit determines a corresponding intermediate prompt question template according to the intermediate output requirement; wherein the intermediate prompt question template is set to prompt an input and output target from the original data to the intermediate output requirement; A target template construction unit determines a corresponding target prompt question template according to the target output requirement; wherein the target prompt question template is configured to prompt an input / output target from an intermediate output corresponding to the intermediate output requirement to the target output requirement; The instruction determination unit splices the intermediate prompt question template with the target prompt question template to determine a prompt word instruction; wherein the intermediate output requirement at least includes the original thinking chain output requirement, the optimized thinking chain output requirement and the original data query statement output requirement; the target output requirement at least includes the original data query statement output requirement and the optimized data query statement output requirement; Wherein, the data query statement generating device further includes: a model training module, which is configured as: Before the acquisition process displays the demand and the natural statements to be converted, a statement conversion data set is acquired; the statement conversion data set includes at least two groups of statement conversion data, each group of the statement conversion data includes a one-to-one correspondence of natural statements, semantic description information and data query statements; Determine the original thinking chain corresponding to each of the sentence conversion data according to the original logic plan corresponding to each of the sentence conversion data, and determine the original training sample set corresponding to the sentence conversion data set according to each of the sentence conversion data and each of the original thinking chains; The initial data query statement generation model is trained by using the original training sample set to obtain an intermediate data query statement generation model; Determine an optimization thinking chain corresponding to each of the sentence conversion data according to the optimization logic plan corresponding to each of the sentence conversion data; Input each of the optimized thinking chains into the intermediate data query statement generation model to obtain the intermediate model output results corresponding to each of the optimized thinking chains, and determine the optimized training sample set corresponding to the statement conversion data set according to each of the statement conversion data, each of the original thinking chains, each of the optimized thinking chains and each of the intermediate model output results; The intermediate data query statement generation model is trained using the optimized training sample set to obtain a data query statement generation model.
9. A data query statement generating device, comprising: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the data query statement generating method according to any one of claims 1 to 7.
10. A storage medium comprising computer executable instructions, wherein the computer executable instructions are used to execute the data query statement generating method according to any one of claims 1 to 7 when executed by a computer processor.
Citation Information
Patent Citations
Implementation method for automatically generating complex graph database query statement service
CN116340584A
Method for generating query statement set of database and method for training sorting model
CN116756167A
Method for interactively generating data report and computing equipment
CN116756169A
Improved NL2SQL method based on generative large language model
CN116821168A
Data query statement generation method and device, equipment and storage medium
CN117453717A
Cited By
Method and device for processing data by using intelligent agent, equipment, medium and product
CN120181126A
Agent-based tool combination and task processing method and device, equipment and medium
CN120276875A
Question and answer model training method and device
CN120509486A
Bayesian automatic cue word optimization method based on meta cue word
CN120832540A
Model training data generation method and device applied to table, equipment and medium
CN120930807A