Method and device for generating training sample for target model

By analyzing the object code to obtain predetermined slot values and generating thinking chain text, the stability and generalization problems of machine learning models when converting natural language text into target programming language code are solved, and efficient training sample generation and model update are achieved.

CN120297441APending Publication Date: 2025-07-11ALIPAY (HANGZHOU) INFORMATION TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510402961.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-31
Publication Date
2025-07-11

AI Technical Summary

Technical Problem

When converting natural language text into target programming language code, existing machine learning models have low stability and poor generalization, and the cost of manually labeling thinking chain text is high and iterative updates are slow.

Method used

The slot values of several predefined slots are obtained by analyzing the target code, and the thinking chain text is generated based on the predefined thinking chain template, and the training samples are automatically constructed, which reduces manual intervention and improves the stability and generalization of the model.

Benefits of technology

The high-quality training sample generation of the model is realized, which reduces the cost of data collection and labeling, improves the stability and generalization capabilities of the model, and can quickly adapt to changes in the data analysis field.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120297441A_ABST
    Figure CN120297441A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a method for generating a training sample for a target model, and the method comprises the steps: obtaining an initial sample which comprises a target text and a target code which is matched with the target text and is based on a target programming language, and the target text is used for expressing a data analysis demand of a user; and analyzing the target code to obtain slot position values of a plurality of preset slot positions of the structured description target text. Obtaining a thinking chain template which describes a reasoning process from a natural language text to a code based on a target programming language, and comprises a plurality of reasoning steps corresponding to a plurality of preset slot positions; and correspondingly supplementing a plurality of reasoning steps according to the slot position values of the plurality of preset slot positions to obtain a first thinking chain text. And generating a training sample for training the target model based on the target text, the first thinking chain text and the target code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of this specification belong to the field of machine learning, and particularly relate to a method and device for generating training samples for a target model. Background Art

[0002] In the field of data analysis, it is usually necessary to convert natural language text into code based on a target programming language. For example, it is necessary to convert a data analysis problem into Domain Specific Language Code (DSL) code, and then analyze a data table based on the DSL code to finally obtain corresponding results.

[0003] With the development of machine learning, training a machine learning model to convert natural language text into code based on a target programming language has become a research hotspot. However, currently, the machine learning model is only trained based on sample pairs formed by natural language text and code based on the target programming language. The machine learning model trained based on such sample pairs has low stability and poor generalization. Therefore, a reasonable solution is needed to improve the stability and generalization of the model. Summary of the Invention

[0004] The purpose of the present invention is to provide a method and device for generating training samples for a target model, which can generate high-quality training samples containing a thought chain text from natural language text to target code for the target model, thereby improving the stability and generalization of the target model.

[0005] The first aspect of this specification provides a method for generating training samples for a target model, including:

[0006] Obtain an initial sample, which includes a target text and a target code based on the target programming language that matches it; the target text is used to express the user's data analysis requirements;

[0007] Parse the target code to obtain slot values of several predetermined slots that structurally describe the target text;

[0008] Obtain a thought chain template, which describes the reasoning process from natural language text to code based on the target programming language and includes several reasoning steps corresponding to the several predetermined slots;

[0009] Correspondingly supplement the several reasoning steps according to the slot values of the several predetermined slots to obtain a first thought chain text;

[0010] Generate a training sample for training the target model based on the target text, the first thought chain text, and the target code.

[0011] The second aspect of this specification provides a method for training a target model, including:

[0012] Obtain a target training sample, which is generated according to the method described in the first aspect, and the sample features therein include sample text, and the sample labels include labeled thought chain text and labeled code; the sample text is used to express the user's data analysis requirements;

[0013] Input the sample text into the target model to obtain a predicted thought chain text and a predicted code;

[0014] Determine a first loss according to the difference between the predicted thought chain text and the labeled thought chain text, and determine a second loss according to the difference between the predicted code and the labeled code;

[0015] Update the parameters of the target model according to the combined loss of the first and second losses.

[0016] The third aspect of this specification provides a device for generating training samples for a target model, including:

[0017] An acquisition unit for acquiring an initial sample, which includes a target text and a target code based on a target programming language that matches it; the target text is used to express the user's data analysis requirements;

[0018] An analysis unit for analyzing the target code to obtain slot values of several predetermined slots that structurally describe the target text;

[0019] The acquisition unit is further configured to acquire a thought chain template, which describes the reasoning process from a natural language text to a code based on a target programming language, and includes several reasoning steps corresponding to the several predetermined slots;

[0020] A supplement unit for respectively supplementing the several reasoning steps according to the slot values of the several predetermined slots to obtain a first thought chain text;

[0021] A generation unit for generating a training sample for training the target model based on the target text, the first thought chain text, and the target code.

[0022] The fourth aspect of this specification provides a device for training a target model, including:

[0023] An acquisition unit for acquiring a target training sample, which is generated according to the method described in the first aspect, and the sample features therein include sample text, and the sample labels include labeled thought chain text and labeled code; the sample text is used to express the user's data analysis requirements;

[0024] An input unit for inputting the sample text into the target model to obtain a predicted thought chain text and a predicted code;

[0025] A determination unit for determining a first loss according to the difference between the predicted thought chain text and the annotated thought chain text, and determining a second loss according to the difference between the predicted code and the annotated code;

[0026] An update unit for updating the parameters of the target model according to the combined loss of the first and second losses.

[0027] The fifth aspect of this specification provides a computer-readable storage medium with a computer program stored thereon. When the computer program is executed on a computer, the computer is made to execute the method described in the first aspect.

[0028] The sixth aspect of this specification provides a computing device including a memory and a processor. An executable code is stored in the memory. When the processor executes the executable code, the method described in the first aspect is implemented.

[0029] The seventh aspect of this specification provides a computer program product including a computer program / instructions. When the computer program / instructions are executed by a processor, the steps of the method described in the first aspect are implemented.

[0030] A method and device for generating training samples for a target model provided by one or more embodiments of this specification first determine the slot values of several predetermined slots for structuring natural language text, and then supplement the slot values of these predetermined slots into a predefined thought chain template. In this way, a thought chain text from natural language text to target code is generated. Subsequently, based on the natural language text, target code, and thought chain text, training samples for training the target model are generated. That is to say, this solution can generate high-quality training samples containing the thought chain text from natural language text to target code for the target model, thereby improving the stability and generalization ability of the target model. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] To more clearly illustrate the technical solutions of the embodiments of this specification, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the drawings described below are only some embodiments recorded in this specification. For those of ordinary skill in the art, other drawings can also be obtained based on these drawings without creative efforts.

[0032] Figure 1 It is a schematic diagram of the implementation scenario of an embodiment disclosed in this specification;

[0033] Figure 2Schematic diagram showing the mapping relationship of each predetermined slot in an example of this specification;

[0034] Figure 3 Flowchart showing a method for generating training samples for a target model according to an embodiment of this specification;

[0035] Figure 4 Schematic diagram showing the chain-of-thought template in an example of this specification;

[0036] Figure 5 Schematic diagram showing the chain-of-thought text in an example of this specification;

[0037] Figure 6 Schematic diagram showing a method for generating training samples for a target model in an example of this specification;

[0038] Figure 7 Flowchart showing a method for training a target model according to an embodiment of this specification;

[0039] Figure 8 Schematic diagram showing a device for generating training samples for a target model according to an embodiment of this specification;

[0040] Figure 9 Schematic diagram showing a device for training a target model according to an embodiment of this specification. Detailed implementation manners

[0041] In order to enable those skilled in the art of this technology to better understand the technical solutions in this specification, the following will clearly and completely describe the technical solutions in the embodiments of this specification in conjunction with the accompanying drawings in the embodiments of this specification. Obviously, the described embodiments are only a part of the embodiments of this specification, rather than all the embodiments. Based on the embodiments in this specification, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the scope of protection of this specification.

[0042] As mentioned above, a machine learning model (abbreviated as model) is usually trained to convert natural language text into code based on a target programming language. Among them, training large language models is the most popular. However, the current training of large language models is usually end-to-end training, that is, directly using natural language text as sample features and code based on the target programming language as sample labels to form training samples. As a result, the currently trained models have the following disadvantages:

[0043] 1. Poor interpretability: Since there are no intermediate logical steps in model training and reasoning, the output of the model is not interpretable.

[0044] 2. Poor generalization performance: Large language models have hallucination problems during inference, resulting in poor generalization ability. In addition, without considering the intermediate reasoning process, large language models are unable to provide stable and reliable outputs when faced with complex problems.

[0045] Therefore, related technical solutions propose using the method of Chain of Thought (CoT) for model training. Chain of Thought refers to the process of decomposing a problem into a series of step-by-step reasoning processes when solving complex problems, and each step has a clear logical relationship. However, the current idea of applying Chain of Thought is to manually annotate the Chain of Thought text, that is, to manually annotate the Chain of Thought text from natural language text to code based on the target programming language, and add this Chain of Thought text to the initial training sample set, and then train the model based on the training sample set after adding the Chain of Thought text. However, this solution has the following disadvantages:

[0046] 1. High cost: Collecting a sufficient number and diverse Chain of Thought texts is not only time-consuming and laborious, but also requires a high level of professional knowledge for the annotation work, which greatly increases the time cost and labor cost of data collection, and it is difficult to perform in batches and automatically.

[0047] 2. Slow iterative update: Manually annotating the Chain of Thought text is difficult to adapt to the rapidly changing needs of the data analysis field. Each update requires re-annotation, resulting in slow iteration.

[0048] Therefore, this solution proposes to automatically generate the Chain of Thought text from natural language text to the target code based on a number of predefined slots and predefined Chain of Thought templates. Among them, these predefined slots are used to structurally describe the natural language text, and the Chain of Thought text includes a number of reasoning steps corresponding to the predefined slots. Specifically, by parsing the target code, the slot values of the predefined slots are obtained, and then these slot values of the predefined slots are filled into the Chain of Thought template. In this way, the Chain of Thought text from natural language text to the target code is generated. After that, training samples can be generated based on the natural language text, the target code, and the Chain of Thought text, and the model can be trained based on this training sample.

[0049] It should be noted that after adding the above-mentioned Chain of Thought text to the training sample, an intermediate reasoning step can be provided for the model, which can not only improve the accuracy of the model's understanding of natural language text, but also make the output of the model interpretable. In addition, after training the model based on the training sample with the added Chain of Thought text, the model can reason or predict by thinking about the Chain of Thought, which enables it to handle more complex problems and improve the stability and generalization of the model.

[0050] The above is the inventive concept provided by this specification. Based on this inventive concept, this solution can be implemented. The following provides a detailed description of this solution.

[0051] Figure 1 It is a schematic diagram of the implementation scenario of an embodiment disclosed in this specification. Figure 1 In it, a single initial sample in the initial sample set includes a target text and target code based on the target programming language that matches it, where the target text is used to express the user's data analysis requirements. For any initial sample, by parsing the target code of this initial sample, the slot values of several predetermined slots that structurally describe the target text can be obtained. After that, the slot values of the several predetermined slots can be respectively used to correspondingly supplement several inference steps in the thought chain template that correspond to the several predetermined slots, so as to obtain the thought chain text corresponding to this initial sample, that is, the thought chain text from the target text of the initial sample to the target code. Finally, based on this thought chain text, target text and target code, a training sample for training the target model can be generated. It should be understood that after generating the corresponding training sample for each initial sample in the initial sample set, a training sample set for training the target model is obtained. Where the target model here is used to convert natural language text into code based on the target programming language.

[0052] As can be seen from the above, this solution is based on several predetermined slots to generate the thought chain text from the target text to the target code. The following describes these several predetermined slots.

[0053] Figure 2 It shows a schematic diagram of the mapping relationship of each predetermined slot in an example of this specification. Figure 2 In it, each predetermined slot includes Dimension, Measure, Filter, and Sort, and a single predetermined slot has several attributes.

[0054] Among them, Dimension refers to the categorical attribute in the data, usually describing different aspects or features of the data. Dimension determines the perspective of data analysis and is the basis of the entire data analysis task.

[0055] Dimension can have attributes such as dimension columns. Further, the attribute values of the dimension column attribute can be divided into the following three categories: 1. Time - type attribute values, such as year, month, day, fiscal year, etc.; 2. Geographic - type attribute values, such as country, city, province, etc.; 3. User - type attribute values, such as user hobbies, user occupations, etc.

[0056] Of course, in practice, the attribute values of the dimension column can also include product - category - type attribute values, etc. This specification does not limit this.

[0057] A metric refers to a data indicator that requires calculation or statistics, i.e., the data content that the user hopes to obtain. It usually needs to be aggregated in some form, such as summation, etc., in order to extract valuable information from the data.

[0058] Metrics can be further divided into the following two subcategories: simple metrics and predefined metrics. Among them, simple metrics have attributes such as metric columns and aggregation methods. Further, the attribute values of the metric column attribute can be divided into the following two categories: 1. Sales-related attribute values, such as sales amount, profit, sales growth rate, year-on-year and month-on-month comparisons, etc.; 2. User-related attribute values: number of new users, number of active users, retention rate, etc. The attribute values of the aggregation method can include, but are not limited to, summation, averaging, maximum value, daily average, etc. Predefined metric columns also have attributes such as metric columns and aggregation methods. Among them, the attribute values of the metric column attribute can be, for example, user sales amount, number of users in City A, etc.

[0059] Filtering is short for filter conditions, which is used to limit the scope and conditions of data analysis, making the analysis results more targeted and accurate. For example, users may only be interested in data for a specific time period, specific region, or specific product category.

[0060] Filtering can be further divided into the following two subcategories: time filtering and geographical filtering. Among them, geographical filtering has attributes such as filter columns (also called dimension value columns), judgment conditions, and filter values (also called dimension values). Further, the attribute values of the filter column attribute can be, for example, city, occupation, etc. The attribute values of the judgment condition attribute column can be, for example, greater than, less than, equal to, is, includes, belongs to, etc. The attribute values of the filter value attribute column can be, for example, City A, high-net-worth users, etc. Time filtering also has attributes such as filter columns, judgment conditions, and filter values. Among them, the attribute values of the filter value attribute can be, for example, from May 1, 2023 to May 2, 2023, etc.

[0061] Sorting refers to how the user hopes to arrange the data analysis results in order to more intuitively display the analysis results. For example, the user may hope to sort by sales amount from high to low, or arrange in chronological order. Sorting information can help users find the data they care about more quickly.

[0062] Sorting can have attributes such as sorting method, sorted column, and return row count limit. Among them, the attribute values of the sorting method attribute can be, for example, ascending sorting, descending sorting, etc. The attribute values of the sorted column attribute can be, for example, sales volume, occupation, etc. The attribute values of the return row count limit attribute can be, for example, top five, 100, etc.

[0063] In this solution, by predefining the above-mentioned slots, complex and diverse target texts can be decomposed into clear and operable structured data, making the data analysis task more systematic and standardized. That is to say, this solution introduces a framework that abstracts data analysis problems into fixed slots, building a structured and standardized bridge between data analysis problems and code. This slot-based abstraction can clearly describe the analysis intention, reduce the ambiguity of natural language, and provide the possibility for subsequent automated generation of chain-of-thought texts.

[0064] It should be understood that Figure 2 this is only an exemplary illustration. In practice, more or fewer slots can be predefined, and this specification does not make any limitations in this regard.

[0065] Figure 3 FIG. shows a flowchart of a method for generating training samples for a target model according to an embodiment of this specification. This method can be executed by any device, equipment, platform, or device cluster with computing and processing capabilities. As Figure 3 shown, this method may include the following steps:

[0066] Step S302, obtain an initial sample, which includes a target text and a target code based on the target programming language that matches it.

[0067] Among them, the target text here is used to express the user's data analysis requirements, and it can also be called a data analysis problem.

[0068] Among them, the above-mentioned target programming language may refer to a programming language with concise syntax, easy to read and write, which may include but is not limited to domain-specific language DSL, JSON (a lightweight data interchange format), etc.

[0069] Taking DSL as an example of the target programming language, when the target text is: "What are the sales volumes of each commodity category on November 10, 2024? Please sort in descending order of sales volume", the target code can be as follows:

[0070]

[0071]

[0072] Step S304, parse the target code to obtain the slot values of several predefined slots.

[0073] Among them, the several predefined slots may include Figure 2 one or more of the predefined slots shown.

[0074] In one embodiment, a syntax parsing tool can be used to parse the target code into a code syntax tree. Then, for any predetermined slot, the corresponding node is determined from the code syntax tree. According to the node value of the target child node of the corresponding node, the slot value of the predetermined slot is determined, where the target child node corresponds to the attribute of the predetermined slot.

[0075] The above code syntax tree is also called an Abstract Syntax Tree (AST), which is used to describe the syntax structure of code statements, and each node in it represents a structure, such as an expression, a statement, or a declaration.

[0076] Taking the target code as an example of code based on a domain-specific language (DSL), the abstract syntax tree may include nodes representing literals (referred to as literal nodes for short), nodes representing operators (referred to as operator nodes for short), nodes representing identifiers (referred to as identifier nodes for short), nodes representing statements (referred to as statement nodes for short), and nodes representing function calls (referred to as function call nodes for short).

[0077] The above statement nodes may further include one or more of the following nodes: group by nodes, measure nodes, filter nodes, topn nodes, etc.

[0078] Among them, the group by node is used to perform a grouping operation on data. It divides the data set according to the values of one or more specified fields and groups the data with the same field values into one group. In the code syntax tree, the group by node usually contains one or more child nodes representing grouping fields. Since the grouping operation is usually used in combination with an aggregation function (a function used to perform statistical calculations on the data within a group), the group by node usually also includes a child node representing the aggregation function.

[0079] It can be seen that the function of the group by node matches the meaning of the dimension slot, so the group by node can be used as the corresponding node of the dimension slot, and the child node of the group by node representing the grouping field corresponds to the dimension column attribute of the dimension slot, that is, the node value of the above-mentioned child node representing the grouping field can be used as the slot value of the dimension slot. Of course, in practice, the slot value of the dimension slot can also be determined according to the node value of the child node corresponding to other attributes of the dimension slot, which is not limited in this specification.

[0080] The measure node is used to define a metric value, which is usually a statistical indicator obtained by performing a certain calculation on data. It can be the result of an aggregation function or a more complex calculation expression. In the code syntax tree, this measure node usually contains child nodes representing the fields used for statistical calculation and child nodes representing the calculation method.

[0081] It can be seen that the function of the measure node matches the meaning of the metric slot, so the measure node can be used as the corresponding node of the metric slot. And the above two child nodes of the measure node respectively correspond to the metric column attribute and the aggregation method attribute of the metric slot, that is, the node values of the above two child nodes can be used as the slot values of the metric slot. Of course, in practice, the slot values of the metric slot can also be determined according to the node values of the child nodes corresponding to other attributes of the metric slot, which is not limited in this specification.

[0082] The filter node is used to perform a filtering operation on data. It filters out the data that does not meet the specified conditions and only retains the data records that meet the conditions. In the code syntax tree, this filter node usually contains child nodes representing the filtering fields, child nodes representing the judgment method, and child nodes representing the filtering values, etc.

[0083] It can be seen that the function of the filter node matches the meaning of the filtering slot, so the filter node can be used as the corresponding node of the filtering slot. And the above three child nodes of the filter node respectively correspond to the filtering column attribute, the judgment condition attribute, and the filtering value attribute of the filtering slot, that is, the node values of the above three child nodes can be used as the slot values of the filtering slot. Of course, in practice, the slot values of the filtering slot can also be determined according to the node values of the child nodes corresponding to other attributes of the filtering slot, which is not limited in this specification.

[0084] The topn node is used to select the top n records from a data set. The ranking is usually based on a certain metric value and can be in ascending or descending order. In the code syntax tree, the topn node usually contains a child node representing the sorting method, a child node representing the sorting basis, and a child node representing the selected quantity n.

[0085] It can be seen that the function of the topn node matches the meaning of the sorting slot, so that the topn node can be used as the corresponding node of the sorting slot, and the above three child nodes of the topn node respectively correspond to the sorting method attribute, the sorted column attribute, and the return row number limit attribute of the sorting slot, that is, the node values of the above three child nodes can be used as the slot values of the sorting slot. Of course, in practice, the slot values of the sorting slot can also be determined according to the node values of the child nodes corresponding to other attributes of the sorting slot, which is not limited in this specification.

[0086] It should be understood that in practice, the code syntax tree parsed from the target code may only include several of the above four types of nodes (group by node, measure node, filter node, and topn node), and the child nodes of each type of node may also only include a part of the child nodes described above.

[0087] For example, for the aforementioned target code, the corresponding code syntax tree includes a group by node, a measure node, a filter node, and a topn node. The group by node includes a child node representing the grouping field, and the node value of this child node is: "product category", so the slot value of the dimension slot includes: "product category". The measure node includes a child node representing the field used for statistical calculation, and the node value of this child node is: "order ID", so the slot value of the measure slot includes: "order ID". The filter node includes a child node representing the filtering field, and the node value is: "order date", and a child node representing the filtering value, and the node value is: "November 10, 2024", so the slot values of the filter slot include: "order date" and "November 10, 2024". The topn node includes a child node representing the sorting basis, and the node value is: "sales volume", and a child node representing the sorting method, and the node value is: "DESC (i.e., descending order)", so the slot values of the sorting slot include: "sales volume" and "descending order".

[0088] Of course, in practice, the slot values of each prediction slot can also include other explanatory contents. For example, the slot value of the measure slot can also include statistical calculation indicators, etc. For example, in the above example, the slot value of the measure slot can also include: "sales volume".

[0089] In other embodiments, regular expressions can also be used to extract the slot values of several predetermined slots from the target code, which is not limited in this specification.

[0090] Additionally, after obtaining the slot values of the above-mentioned several predetermined slots, the slot values of the several predetermined slots can also be verified for correctness based on the target text. For example, determining whether each item in the slot value is included in the target text.

[0091] In summary, in this solution, by determining the slot values of the above-mentioned several predetermined slots, a reasonable data analysis problem can be abstracted into fixed slots, thereby facilitating the structured expression of data analysis problems.

[0092] Step S306: Obtain a thought chain template, which describes the reasoning process from a natural language text to code based on the target programming language and includes several reasoning steps corresponding to several predetermined slots.

[0093] In one embodiment, the above-mentioned several reasoning steps respectively include the names of the corresponding predetermined slots, but the slot values are empty.

[0094] In another embodiment, the above-mentioned thought chain template may further include a summary of the several reasoning steps, and in this summary, the slot values of each predetermined slot are empty.

[0095] Figure 4 Show a schematic diagram of the thought chain template in an example of this specification. Figure 4 In it, the thought chain template includes four reasoning steps. The first reasoning step corresponds to the dimension slot, the second reasoning step corresponds to the metric slot, the third reasoning step corresponds to the filter slot, and the fourth reasoning step corresponds to the sort slot. Each reasoning step contains the name of the corresponding predetermined slot, and the slot value is empty. In addition, the thought chain template also includes a summary of the four reasoning steps, and in this summary, the slot values of the dimension slot, metric slot, filter slot, and sort slot are all empty.

[0096] Step S308: Respectively supplement several reasoning steps according to the slot values of several predetermined slots to obtain an initial thought chain text.

[0097] Taking the aforementioned target code and target text as an example, after correspondingly supplementing the slot values of the dimension slot, metric slot, filter slot, and sort slot obtained based on the target code into Figure 4 the shown thought chain template, the obtained initial thought chain text can be as Figure 5 shown. Compared with Figure 4 , Figure 5The first inference step in supplements the slot value of the dimension slot: "Commodity Category". The second inference step supplements the slot value of the metric slot: "Sales Volume (Order ID Deduplicated Counting)". The third inference step supplements the slot value of the filtering slot: "November 10, 2024 (Order Date and Time Filtering)". The fourth inference step supplements the slot value of the sorting slot: "Sorted by Sales Volume (No Limit)".

[0098] It should be noted that the method of generating the thought chain text based on the thought chain template proposed in this solution has the advantages of high automation, accuracy, reliability, and strong scalability. Among them, the high automation is mainly reflected in that once the slot values of the predetermined slots are obtained, the thought chain text can be automatically generated. The accuracy and reliability are reflected in that based on the parsing results of the code, the slot values of the predetermined slots can be accurately determined. The strong scalability is reflected in that other predetermined slots can be quickly expanded on the existing basis.

[0099] In summary, in this solution, the slot values of each predetermined slot can be automatically converted into a thought chain process, and the integrity and rationality of the thought chain text structure can be ensured.

[0100] Step S310, generate a training sample for training the target model based on the target text, the initial thought chain text, and the target code.

[0101] Among them, the target model here is used to convert the data analysis problem into code based on the target programming language. It can be implemented based on a traditional machine learning model for classification functions or based on a large language model. This specification does not make any limitations in this regard.

[0102] In one embodiment, the target text can be used as a sample feature, and the initial thought chain text and the target code can be used as sample labels to generate a training sample for training the target model.

[0103] It should be noted that although the initial thought chain text contains the structured information of the data analysis problem, it may have insufficient expression or loose logic. Therefore, the powerful language generation ability of the large language model can be used to further optimize and expand it to further improve the quality and diversity of the thought chain text, so as to ensure its effectiveness and adaptability in practical applications.

[0104] In another embodiment, the target text can be used as a sample feature, and the optimized initial thought chain text (hereinafter referred to as the target thought chain text) and the target code can be used as sample labels to generate a training sample for training the target model.

[0105] The process of optimizing the initial thought chain text using the large language model is described below:

[0106] Specifically, a prompt can be constructed based on the target text and the initial chain of thought text. This prompt instructs to optimize the expression of the initial chain of thought text based on the target text without changing the logical structure of the initial chain of thought text. Subsequently, this prompt is input into the large language model to obtain the optimized initial chain of thought text, that is, the target chain of thought text.

[0107] Of course, in practice, the above prompt can also include other information. For example, in the case where the data analysis problem involves the target data table, the prompt can also include the metadata of the target data table, where the metadata indicates each column or each field included in the target data table.

[0108] It should be understood that in the case where the above prompt also includes the metadata of the target data table, then the prompt can indicate to optimize the expression of the initial chain of thought text based on the target text and the metadata of the target data table.

[0109] Still taking the above target text and target code as an example, the constructed prompt can be as follows:

[0110] Please help me optimize the following expression of the chain of thought, note that the logical structure remains unchanged:

[0111] #begin#

[0112] The data analysis problem is: What is the sales volume of each product category on November 10, 2024? Please sort in descending order of sales volume

[0113] Metadata: Product category (String), Order ID (string), Order date (Date)

[0114] Let's think step by step:

[0115] Step 1: Find the dimensional information in the problem: Product category

[0116] Step 2: The metrics and aggregation methods in the problem: Sales volume (distinct count of Order ID)

[0117] Step 3: The filtering in the problem: November 10, 2024 (Order date time filtering)

[0118] Step 4: The sorting in the problem: Sort in descending order of sales volume (without Limit)

[0119] To summarize: This DSL needs to calculate the distinct count of Order ID for the product category dimension under the time filtering where the order date is November 10, 2024, and sort in descending order of sales volume.

[0120] #end#

[0121] After inputting the above prompt into the large language model, the large language model can perform the following optimizations: logical improvement (conducting a logical check on the initial chain of thought text to ensure it matches the data analysis text), and language optimization (polishing the language of the initial chain of thought text to make it more understandable, increasing readability and diversity).

[0122] For example, the target chain of thought text output by the large language model can be as follows:

[0123] Step 1: Determine the dimension in the question, which is the product category. This means that we need to perform data analysis based on different product categories.

[0124] Step 2: Define the metrics and aggregation methods. Here, we are concerned with sales volume, which is specifically measured by calculating the unique order count for each product category, that is, counting after removing duplicates from the order IDs.

[0125] Step 3: Define the filtering conditions. In this example, we only need to consider the data records with the order date of November 10, 2024.

[0126] Step 4: Set the sorting rule. The final result needs to be sorted in descending order of sales volume without an upper limit.

[0127] In summary, the data query statement (DSL) should meet the following requirements: First, select relevant orders based on November 10, 2024 as the time filter; then group by product category and count the number of independent orders for each category; finally, display these results in reverse order according to the sales volume.

[0128] It should also be noted that in practice, if the data analysis problem involves the target data table, then when generating the above training samples, the metadata of the target data table can also be used as sample features.

[0129] This solution integrates the automatically generated chain of thought text into the training sample set of the target model, creating a training sample set containing intermediate reasoning steps. Based on such a training sample set, the generalization of the model can be improved, and the dependence on manual annotation can be greatly reduced, thereby accelerating the iteration speed and reducing costs.

[0130] Figure 6 A schematic diagram of a method for generating training samples for a target model is shown in an example of this specification. Figure 6Among them, for each initial sample (including data analysis problems and DSL code) in the initial sample set, by parsing the DSL code in the initial sample, the slot values of the dimension slot, measure slot, filter slot, and sort slot of the data analysis problem that match the structured description are obtained. After that, the obtained slot values of each slot are correspondingly supplemented into the thought chain template to generate the initial thought chain text. Then, the data analysis problem, the initial thought chain text, and the metadata of the data table can be input into the large language model to obtain the target thought chain text. Finally, the target thought chain text can be added to the initial sample, thereby generating a training sample for training the target model. It should be understood that after generating the corresponding training sample based on each initial sample in the initial sample set, a training sample set for training the target model is obtained.

[0131] In summary, this solution proposes a technical implementation solution for automatically constructing thought chain text, that is, this solution can automatically generate an intermediate thought chain from natural language text to code based on the target programming language for training without a large amount of manual intervention, and use the automatically generated thought chain text for model training, which not only ensures that the model has good generalization and interpretability, but also effectively reduces the development and maintenance costs, and solves the problem of difficult construction of thought chain text. That is to say, this solution can significantly reduce the time cost and annotation cost of thought chain collection from natural language text to code based on the target programming language in the field of data analysis, and has practical application value in the field of business intelligence. In addition, this solution can quickly adapt to new requirements and changes. For example, when a user proposes a new data analysis problem, new thought chain text can be automatically generated quickly and merged into the training sample set, thereby improving the flexibility of the model.

[0132] The following is a description of the process of training the target model using the training samples generated by the above Figure 3 shown method steps.

[0133] Figure 7 Shown is a method flow chart for training the target model according to an embodiment of the present specification. This method can be executed by any device, equipment, platform, or device cluster with computing and processing capabilities. This method includes multiple rounds of iteration, Figure 7 Shown are the method steps included in the t-th (t is a positive integer) round of iteration. It can be understood that by repeatedly executing the steps shown, multi-round iterative updates of the target model can be achieved, and then the target model updated in the last round is used as the finally used target model. As Figure 7 shown, this method may include the following steps:

[0134] Step S702, obtain the target training sample.

[0135] The target training sample can be any training sample in the training sample set for training the target model, and it is generated according to Figure 3 the method steps shown. That is, the sample features in the target training sample include sample text, which is used to express the user's data analysis requirements, and the sample label includes the labeled thought chain text and the labeled code.

[0136] Of course, in practice, the above sample features may also include the metadata of the target data table involved in the above data analysis requirements.

[0137] Step S704: Input the sample text into the target model to obtain the predicted thought chain text and the predicted code.

[0138] Among them, the target model here is used to convert natural language text into code based on the target programming language.

[0139] It should be understood that when the sample features also include the metadata of the target data table, the input of the target model also includes the metadata of the target data table.

[0140] Step S706: Determine the first loss according to the difference between the predicted thought chain text and the labeled thought chain text, and determine the second loss according to the difference between the predicted code and the labeled code.

[0141] Specifically, the first loss can be determined by using the cross-entropy loss function according to the difference between the predicted thought chain text and the labeled thought chain text. And the second loss can be calculated by using the cross-entropy loss function according to the difference between the predicted code and the labeled code.

[0142] Step S708: Update the parameters of the target model according to the combined loss of the first and second losses.

[0143] For example, the first loss and the second loss can be summed, and the summation result is used as the above combined loss. After calculating the combined losses corresponding to each training sample in the training sample set, the update gradient of the parameters corresponding to the target model is calculated by using the backpropagation method, and the parameters of the target model are updated based on it to obtain the trained target model.

[0144] Thus, one round of update or training of the target model is completed. It should be understood that by repeatedly executing step S702-step S708, multiple rounds of training of the target model can be achieved, and then the finally used target model can be obtained. After that, the finally obtained target model can be used to perform inference and prediction for new data analysis problems, that is, inputting the new data analysis problem into the finally obtained target model, the corresponding code based on the target programming language can be obtained. In addition, the thought chain text from the new data analysis problem to the code can also be obtained.

[0145] It should be noted that when training the target model based on a high-quality training sample set containing chain-of-thought texts, this solution can provide an intermediate logical reasoning step for the model, enabling the model to not only understand the user's data analysis requirements but also improve the interpretability of the results. In addition, when the trained target model performs inference and prediction, it can better handle complex problems by thinking in terms of the chain of thought, which can not only enhance the generalization of the model but also reduce the occurrence of hallucinations. In short, the target model trained by this solution can better understand and solve the data analysis problems proposed by users, thus improving the overall performance of the model.

[0146] Corresponding to the above method for generating training samples for the target model, an embodiment of this specification also provides a device for generating training samples for the target model, as Figure 8 shown. The device may include:

[0147] An acquisition unit 802, configured to acquire an initial sample, which includes a target text and a target code based on the target programming language that matches it, and the target text is used to express the user's data analysis requirements.

[0148] An analysis unit 804, configured to analyze the target code to obtain slot values of several predetermined slots that structurally describe the target text.

[0149] The acquisition unit 802 is further configured to acquire a chain-of-thought template, which describes the reasoning process from a natural language text to a code based on the target programming language and includes several reasoning steps corresponding to several predetermined slots.

[0150] A supplement unit 806, configured to respectively supplement several reasoning steps according to the slot values of several predetermined slots to obtain a first chain-of-thought text.

[0151] A generation unit 808, configured to generate a training sample for training the target model based on the target text, the first chain-of-thought text, and the target code.

[0152] In one embodiment, the analysis unit 804 includes:

[0153] An analysis sub-module 8042, configured to analyze the target code into a code syntax tree by using a syntax analysis tool;

[0154] A determination sub-module 8044, configured to determine a corresponding first node from the code syntax tree for any first predetermined slot;

[0155] The determination sub-module 8044 is further configured to determine the slot value of the first predetermined slot according to the node value of the target child node of the first node, where the target child node corresponds to the attribute of the first predetermined slot.

[0156] In one embodiment, the device further includes:

[0157] A verification unit 810, configured to verify the correctness of the slot values of a plurality of predetermined slots according to the target text;

[0158] The supplement unit 806 is specifically configured to:

[0159] After the correctness verification passes, respectively supplement a plurality of reasoning steps according to the slot values of the plurality of predetermined slots.

[0160] In one embodiment, the above-mentioned plurality of predetermined slots include one or more of the following:

[0161] Dimension, which indicates the data analysis angle;

[0162] Metric, which indicates the data result to be obtained;

[0163] Filter, which indicates the scope and conditions of data analysis;

[0164] Sort, which indicates the arrangement method of the data result.

[0165] In a more specific embodiment,

[0166] The attribute of the dimension includes: dimension column;

[0167] The attribute of the metric includes: metric column, aggregation method;

[0168] The attribute of the filter includes: filter column, judgment condition, filter value;

[0169] The attribute of the sort includes: sort column, sort method.

[0170] In one embodiment, the device further includes:

[0171] An input unit 812, configured to input the target text and the first thought chain text into a large language model, so that, without changing the logical structure of the first thought chain text, optimize the expression of the first thought chain text based on the target text to obtain an optimized second thought chain text;

[0172] The generation unit 808 is specifically configured to:

[0173] Generate training text for training the target model based on the target text, the second thought chain text, and the target code.

[0174] In one embodiment, the user's data analysis requirement involves a target data table;

[0175] The input of the large language model further includes the metadata of the target data table, which indicates each column included in the target data table.

[0176] In one embodiment, the generating unit 808 is specifically configured to:

[0177] Use the target text as sample features, and use the first thought chain text and the target code as sample labels to generate training samples for training the target model.

[0178] The functions of the functional units of the device in the above embodiments of this specification can be implemented by the steps of the above method embodiments. Therefore, the specific working process of the device provided in an embodiment of this specification will not be repeated here.

[0179] A device for generating training samples for a target model provided in an embodiment of this specification can generate high-quality training samples for the target model.

[0180] Corresponding to the above method for training a target model, an embodiment of this specification also provides a device for training a target model, as Figure 9 shown. The device may include:

[0181] An obtaining unit 902, configured to obtain target training samples, which are generated according to Figure 3 the method steps shown, and the sample features therein include sample texts, and the sample labels include labeled thought chain texts and labeled codes, and the sample texts are used to express the user's data analysis requirements.

[0182] An input unit 904, configured to input the sample text into the target model to obtain a predicted thought chain text and a predicted code.

[0183] A determining unit 906, configured to determine a first loss according to the difference between the predicted thought chain text and the labeled thought chain text, and determine a second loss according to the difference between the predicted code and the labeled code.

[0184] An updating unit 908, configured to update the parameters of the target model according to the combined loss of the first and second losses.

[0185] The functions of the functional units of the device in the above embodiments of this specification can be implemented by the steps of the above method embodiments. Therefore, the specific working process of the device provided in an embodiment of this specification will not be repeated here.

[0186] The device for training a target model provided in an embodiment of this specification can improve the stability and generalization ability of the target model.

[0187] According to an embodiment of another aspect, a computer-readable storage medium is further provided, on which a computer program is stored. When the computer program is executed in a computer, the computer is made to execute the method described in conjunction with Figure 3 this.

[0188] According to an embodiment of still another aspect, there is also provided a computing device, including a memory and a processor, wherein executable code is stored in the memory, and when the processor executes the executable code, the method described in conjunction with Figure 3 is implemented.

[0189] Each embodiment in this specification is described in a progressive manner. For the same or similar parts among the embodiments, reference can be made to each other. Each embodiment focuses on the differences from other embodiments. In particular, for the medium or device embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and for the relevant parts, reference can be made to the partial description of the method embodiments.

[0190] The steps of the method or algorithm described in conjunction with the disclosure of this specification can be implemented in a hardware manner or by a processor executing software instructions. The software instructions can be composed of corresponding software modules, and the software modules can be stored in a RAM memory, a flash memory, a ROM memory, an EPROM memory, an EEPROM memory, a register, a hard disk, a removable hard disk, a CD-ROM, or any other form of storage medium well-known in the art. An exemplary storage medium is coupled to the processor, so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an ASIC. In addition, the ASIC can be located in a server. Of course, the processor and the storage medium can also exist as discrete components in the server.

[0191] In the 1990s, improvements to a technology could be clearly distinguished as either hardware improvements (e.g., improvements to the circuit structures of diodes, transistors, switches, etc.) or software improvements (improvements to method flows). However, with the development of technology, many method flow improvements today can be regarded as direct improvements to hardware circuit structures. Almost all designers obtain the corresponding hardware circuit structures by programming the improved method flows into the hardware circuits. Therefore, it cannot be said that an improvement to a method flow cannot be implemented using a hardware entity module. For example, a Programmable Logic Device (PLD) (e.g., a Field Programmable Gate Array (FPGA)) is such an integrated circuit whose logic function is determined by the user programming the device. The designer programs it himself to "integrate" a digital system on a single PLD, without having to ask a chip manufacturer to design and fabricate a dedicated integrated circuit chip. Moreover, nowadays, instead of manually fabricating integrated circuit chips, this programming is mostly implemented using "logic compiler" software, which is similar to the software compiler used in program development and writing. The original code before compilation also has to be written in a specific programming language, which is called a Hardware Description Language (HDL). There is not just one kind of HDL, but many kinds, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones currently are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also be aware that by simply performing a little logical programming on the method flow using the above-mentioned several hardware description languages and programming it into the integrated circuit, it is easy to obtain the hardware circuit that implements the logical method flow.

[0192] The controller can be implemented in any suitable manner. For example, the controller can take the form of, for example, a microprocessor or a processor and a computer-readable medium storing computer-readable program code (such as software or firmware) executable by the (micro)processor, logic gates, switches, an application specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller. Examples of the controller include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26k20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that in addition to implementing the controller in the form of pure computer-readable program code, it is entirely possible to make the controller implement the same function in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, such a controller can be considered a hardware component, and the devices included therein for implementing various functions can also be regarded as the structures within the hardware component. Or even, the devices for implementing various functions can be regarded as either software modules for implementing the method or the structures within the hardware component.

[0193] The systems, devices, modules, or units illustrated in the above embodiments can be specifically implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a server system. Of course, this application does not exclude that with the development of future computer technologies, the computers for implementing the functions of the above embodiments can be, for example, personal computers, laptop computers, in-vehicle human-machine interaction devices, cellular phones, camera phones, smart phones, personal digital assistants, media players, navigation devices, email devices, game consoles, tablet computers, wearable devices, or any combination of these devices.

[0194] Although one or more embodiments of this specification provide method operation steps as described in the embodiments or flowcharts, more or fewer operation steps may be included based on conventional or non-creative means. The order of steps listed in the embodiments is only one way among the execution orders of numerous steps and does not represent the only execution order. When the actual device or terminal product is executed, it may be executed in the order of the method shown in the embodiments or the drawings or executed in parallel (for example, in a parallel processor or multi-threaded processing environment, or even in a distributed data processing environment). The terms "including", "comprising" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, product or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent to such process, method, product or device. Without further limitation, there is no exclusion of additional identical or equivalent elements in the process, method, product or device including the said elements. For example, if terms such as first and second are used to denote names, they do not denote any particular order.

[0195] For the convenience of description, the above device is described by dividing it into various modules according to functions. Of course, when implementing one or more of this specification, the functions of each module can be implemented in the same or multiple software and / or hardware, or the modules implementing the same function can be realized by a combination of multiple sub-modules or sub-units, etc. The device embodiments described above are only illustrative. For example, the division of the units is only a logical function division, and there may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling, direct coupling or communication connection to each other can be through some interfaces, and the indirect coupling or communication connection of the device or unit can be in electrical, mechanical or other forms.

[0196] The present invention is described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, and the combination of processes and / or blocks in the flowcharts and / or block diagrams can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate a device for realizing the functions specified in Figure 1 one process or multiple processes and / or blocks Figure 1 one block or multiple blocks.

[0197] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a particular manner, such that the instructions stored in the computer-readable memory produce a manufacture including an instruction device that implements the functions specified in one or more processes and / or boxes Figure 1 in one or more processes and / or boxes Figure 1 specified in the boxes.

[0198] These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more processes and / or boxes Figure 1 in one or more processes and / or boxes Figure 1 specified in the boxes.

[0199] In a typical configuration, a computing device includes one or more processors (CPUs), an input / output interface, a network interface, and memory.

[0200] The memory may include non-permanent memory in the form of computer-readable media, random access memory (RAM) and / or non-volatile memory such as read-only memory (ROM) or flash memory (flash RAM). Memory is an example of computer-readable media.

[0201] Computer-readable media includes permanent and non-permanent, removable and non-removable media and can store information by any method or technology. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette tapes, magnetic disk storage, graphene storage or other magnetic storage devices, or any other non-transmission media that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media such as modulated data signals and carrier waves.

[0202] Those skilled in the art should understand that one or more embodiments of this specification can be provided as a method, a system, or a computer program product. Therefore, one or more embodiments of this specification can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, one or more embodiments of this specification can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0203] One or more embodiments of this specification can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. One or more embodiments of this specification can also be practiced in a distributed computing environment, where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.

[0204] Each embodiment in this specification is described in a progressive manner. For the same or similar parts among the embodiments, reference can be made to each other. Each embodiment focuses on the differences from other embodiments. In particular, for system embodiments, since they are basically similar to method embodiments, the description is relatively simple. For related parts, reference can be made to the partial description of the method embodiments. In the description of this specification, the description of reference terms such as "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of this specification. In this specification, the schematic expressions of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments or examples. In addition, without contradiction, those skilled in the art can combine and combine different embodiments or examples described in this specification and the features of different embodiments or examples.

[0205] The above description is only for the embodiments of one or more embodiments of this specification and does not limit one or more embodiments of this specification. For those skilled in the art, one or more embodiments of this specification can have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this specification shall be included within the scope of the claims.

Claims

1. A method for generating training samples for a target model, comprising: Obtaining initial samples, including a target text and target code based on a target programming language that matches the target text; The target text is used to express the user's data analysis requirements; Parsing the target code to obtain slot values for several predetermined slots that structurally describe the target text; Obtaining a chain-of-thought template that describes the reasoning process from a natural language text to code based on a target programming language and includes several reasoning steps corresponding to the several predetermined slots; Respectively supplementing the several reasoning steps according to the slot values of the several predetermined slots to obtain a first chain-of-thought text; Generating training samples for training the target model based on the target text, the first chain-of-thought text, and the target code.

2. The method according to claim 1, wherein The parsing the target code includes: Using a syntax parsing tool to parse the target code into a code syntax tree; For any first predetermined slot, determining a corresponding first node from the code syntax tree; Determining the slot value of the first predetermined slot according to the node values of the target child nodes of the first node, where the target child nodes correspond to the attributes of the first predetermined slot.

3. The method according to claim 1, wherein Before the corresponding supplementing of the several reasoning steps, further comprising: Verifying the correctness of the slot values of the several predetermined slots according to the target text; The respectively supplementing the several reasoning steps according to the slot values of the several predetermined slots includes: After the correctness verification passes, respectively supplementing the several reasoning steps according to the slot values of the several predetermined slots.

4. The method according to claim 1, wherein The several predetermined slots include one or more of the following: Dimension, which indicates the data analysis perspective; Measure, which indicates the data result to be obtained; Filter, which indicates the scope and conditions of data analysis; Sort, which indicates the arrangement method of the data result.

5. The method according to claim 4, wherein, The attribute of the dimension includes: dimension column; The attributes of the measure include: measure column, aggregation method; The attributes of the filter include: filter column, judgment condition, filter value; The attributes of the sort include: sort column, sort method.

6. The method according to claim 1, wherein Before generating the training samples for training the target model, further comprising: Inputting the target text and the first chain-of-thought text into a large language model, and enabling it to optimize the expression of the first chain-of-thought text based on the target text without changing the logical structure of the first chain-of-thought text to obtain an optimized second chain-of-thought text; The generating the training samples for training the target model includes: Generating training text for training the target model based on the target text, the second chain-of-thought text, and the target code.

7. The method according to claim 6, wherein, The user's data analysis requirements relate to a target data table; The input of the large language model further includes metadata of the target data table, which indicates the columns included in the target data table.

8. The method according to claim 1, wherein The generating the training samples for training the target model includes: Using the target text as a sample feature and the first thought chain text and the target code as sample labels, generate training samples for training the target model.

9. A method for training a target model, comprising: Obtain a target training sample, which is generated according to the method described in any one of claims 1-8, and wherein the sample feature includes a sample text, and the sample label includes an annotated thought chain text and an annotated code; the sample text is used to express the user's data analysis requirements; Input the sample text into the target model to obtain a predicted thought chain text and a predicted code; Determine a first loss according to the difference between the predicted thought chain text and the annotated thought chain text, and determine a second loss according to the difference between the predicted code and the annotated code; Update the parameters of the target model according to the combined loss of the first and second losses.

10. An apparatus for generating training samples for a target model, comprising: An acquisition unit for acquiring an initial sample, which includes a target text and a target code based on a target programming language that matches it; The target text is used to express the user's data analysis requirements; An analysis unit for analyzing the target code to obtain slot values of a plurality of predetermined slots that structurally describe the target text; The acquisition unit is further configured to acquire a thought chain template, which describes the reasoning process from a natural language text to a code based on a target programming language, and includes a plurality of reasoning steps corresponding to the plurality of predetermined slots; A supplement unit for respectively supplementing the plurality of reasoning steps according to the slot values of the plurality of predetermined slots to obtain a first thought chain text; A generation unit for generating training samples for training the target model based on the target text, the first thought chain text, and the target code.

11. An apparatus for training a target model, comprising: An acquisition unit for acquiring a target training sample, which is generated according to the method described in any one of claims 1-8, and wherein the sample feature includes a sample text, and the sample label includes an annotated thought chain text and an annotated code; the sample text is used to express the user's data analysis requirements; An input unit for inputting the sample text into the target model to obtain a predicted thought chain text and a predicted code; A determination unit for determining a first loss according to the difference between the predicted thought chain text and the annotated thought chain text, and determining a second loss according to the difference between the predicted code and the annotated code; An update unit for updating the parameters of the target model according to the combined loss of the first and second losses.

12. A computing device, comprising a memory and a processor, wherein the memory stores executable code, and when the processor executes the executable code, the method described in any one of claims 1-9 is implemented.

Citation Information

Cited By

  • Dynamic construction method and device for electric power material bid evaluation sample

    CN121146304A