Code generation model training method, query code generation method and related device
By constructing a code generation model, the problem of low query efficiency in existing databases was solved, and the automatic conversion of natural language query statements into database query code was realized, thereby improving query efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- IFLYTEK CO LTD
- Filing Date
- 2026-01-20
- Publication Date
- 2026-05-12
AI Technical Summary
Existing database query methods require a high level of professional knowledge, and users need to learn query languages, resulting in low query efficiency.
A code generation model is constructed by obtaining attribute information of the filtering and return fields from the target database, constructing target mapping pairs as training samples, and using the training samples to train the pre-built code generation model to achieve automatic conversion of natural language query statements into database query code.
It improves the efficiency of generating data query code, thereby improving database query efficiency, allowing users to perform efficient queries without learning a query language.
Smart Images

Figure CN122019567A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of database query technology, and in particular to a training method for a code generation model, a query code generation method, and related apparatus. Background Technology
[0002] In the data-driven digital age, databases, as the core carrier of data storage and management, have been widely used in various fields such as scientific research, industry, finance, and healthcare. Currently, the mainstream implementation of database queries relies on specialized query languages. Users need to first have a deep understanding of the target database's structure, then write query statements that conform to the syntax rules according to their query requirements, submit query requests through database clients or API interfaces, and finally obtain the query results.
[0003] However, the above query methods require a high level of professional knowledge. Users need to learn query languages or rely on professional assistance to perform database queries, which severely restricts the efficiency of database queries. Furthermore, even if professionals write query statements, it still takes a certain amount of time, affecting the efficiency of database queries. Summary of the Invention
[0004] Based on the above requirements, this application proposes a training method for a code generation model, a query code generation method, and related devices, which can construct a code generation model and realize the automatic generation of corresponding database query codes based on natural language query statements, thereby improving the generation efficiency of data query codes and thus improving the database query efficiency.
[0005] To achieve the above objectives, this application proposes the following technical solution: According to a first aspect of the embodiments of this application, a method for training a code generation model is provided, comprising: Retrieve the filter fields and return fields from the target database, and determine the attribute information of the filter fields and the attribute information of the return fields; Based on the filtering field, the return field, the attribute information of the filtering field, and the attribute information of the return field, a target mapping pair is constructed, and the target mapping pair is used as a training sample; wherein, the target mapping pair includes: a natural language query statement and the query code corresponding to the natural language query statement; Using the training samples, the pre-built code generation model is trained to generate query code, resulting in a trained code generation model.
[0006] Optionally, the attribute information of the filter field includes all possible values corresponding to the filter field; Based on the filtering field, the returned field, the attribute information of the filtering field, and the attribute information of the returned field, a target mapping pair is constructed, including: Based on the filter field and the return field, a field combination is constructed, wherein the field combination includes at least one filter field and at least one return field; Based on all the values of the filter field, determine the filter conditions corresponding to the field combination, and construct the target combination based on the filter conditions and the returned fields in the field combination; Construct the target mapping pairs corresponding to the target combination.
[0007] Optionally, the attribute information of the returned field includes the code calling rules of the returned field; Constructing the target mapping pairs corresponding to the target combination includes: Generate natural language query statements corresponding to the target combination according to the pre-built natural language query statement template; Based on the pre-built query code generation rules and the code calling rules of the returned fields, the query code corresponding to the target combination is generated; The natural language query statement corresponding to the target combination and the query code corresponding to the target combination are used as the target mapping pair corresponding to the target combination.
[0008] Optionally, if there is only one filter field in the field combination, the filter conditions corresponding to the field combination are determined based on all values of the filter field, and a target combination is constructed based on the filter conditions and the returned fields in the field combination, including: Each value corresponding to the filter field in the field combination is assigned to the filter field to obtain the filter condition corresponding to each value. Each filter condition is combined with the returned fields in the field combination to form a target combination.
[0009] Optionally, when there are multiple filter fields in the field combination, the filter conditions corresponding to the field combination are determined based on all values of the filter fields, and a target combination is constructed based on the filter conditions and the returned fields in the field combination, including: Based on all possible values of the filter field, construct a value queue corresponding to the filter field; Assign the values output from the value queue corresponding to the filter field in the field combination to the filter field to obtain the filter conditions corresponding to each filter field in the field combination; The filter conditions corresponding to each filter field in the field combination and the returned fields in the field combination are combined to form a target combination.
[0010] Optionally, based on all values of the filtering field, the filtering conditions corresponding to the field combination are determined. After constructing the target combination based on the filtering conditions and the returned fields in the field combination, the method further includes: If the field combination includes multiple filter fields or multiple return fields, then the order of the multiple filter conditions and / or multiple return fields in the target combination is adjusted to obtain the target combination after the order adjustment.
[0011] Optionally, the attribute information of the filter field includes the data type corresponding to the filter field; Based on the filtering field, the returned field, the attribute information of the filtering field, and the attribute information of the returned field, constructing a target mapping pair further includes: If the data type of the filter field in the field combination matches the pre-set complex value type, then the edge value is extracted from all the values corresponding to the filter field in the field combination. The edge values corresponding to the filter fields in the field combination are assigned to the filter fields to obtain the edge filter conditions; Combine the edge filtering conditions with the returned fields from the field combination to form an edge target combination; Construct the target mapping pairs corresponding to the edge target combinations.
[0012] Optionally, after constructing the target mapping pair based on the filter field, the return field, the attribute information of the filter field, and the attribute information of the return field, the method further includes: According to the pre-set statement rewriting rules, the natural language query statements in the target mapping pairs are rewritten, and the rewritten target mapping pairs are used as training samples.
[0013] According to a second aspect of the embodiments of this application, a query code generation method is provided, including: Get the user's natural language query statement; The user's natural language query statement is input into a pre-trained code generation model to obtain the target query code corresponding to the user's natural language query statement; The code generation model is determined using the training method described above.
[0014] According to a third aspect of the embodiments of this application, a training apparatus for a code generation model is provided, comprising: The field acquisition module is used to obtain the filter field and the return field from the target database, and to determine the attribute information of the filter field and the attribute information of the return field; A construction module is used to construct target mapping pairs based on the filtering field, the return field, the attribute information of the filtering field, and the attribute information of the return field, and to use the target mapping pairs as training samples; wherein, the target mapping pair includes: a natural language query statement and the query code corresponding to the natural language query statement; The training module is used to train the pre-built code generation model to generate query code using the training samples, so as to obtain the trained code generation model.
[0015] According to a fourth aspect of the embodiments of this application, a query code generation apparatus is provided, comprising: The statement retrieval module is used to retrieve the user's natural language query statement; The code generation module is used to input the user's natural language query statement into a pre-trained code generation model to obtain the target query code corresponding to the user's natural language query statement; The code generation model is determined using the training method described above.
[0016] According to a fifth aspect of the embodiments of this application, an electronic device is provided, including: a memory and a processor; The memory is connected to the processor and is used to store programs; The processor is used to implement the training method of the above-mentioned code generation model or the above-mentioned query code generation method by running the program in the memory.
[0017] According to a sixth aspect of the embodiments of this application, a computer program product is provided, including computer program instructions, which, when executed by a processor, cause the processor to implement the training method of the above-described code generation model or the above-described query code generation method.
[0018] The code generation model training method proposed in this application obtains filter fields and return fields from the target database, and determines the attribute information of the filter fields and return fields. Based on the filter fields, return fields, and the attribute information of the filter fields and return fields, a target mapping pair is constructed, and this target mapping pair is used as training samples. The target mapping pair includes a natural language query statement and the corresponding query code. Using the training samples, the pre-constructed code generation model is trained to generate query code, resulting in a trained code generation model. By adopting the technical solution of this application, a code generation model can be constructed, enabling the automatic generation of corresponding database query code based on natural language query statements, thereby improving the efficiency of data query code generation and ultimately improving database query efficiency. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0020] Figure 1 This is a flowchart illustrating a training method for a code generation model provided in an embodiment of this application.
[0021] Figure 2 This is a schematic diagram of a process for constructing a target combination, provided as an embodiment of this application.
[0022] Figure 3 This is a schematic diagram of another process for constructing a target combination, provided in an embodiment of this application.
[0023] Figure 4 This is a schematic diagram of a process for constructing target mapping pairs provided in an embodiment of this application.
[0024] Figure 5 This is a schematic diagram of another process for constructing target mapping pairs provided in an embodiment of this application.
[0025] Figure 6 This is a flowchart illustrating another method for training a code generation model provided in an embodiment of this application.
[0026] Figure 7 This is a flowchart illustrating a query code generation method provided in an embodiment of this application.
[0027] Figure 8 This is a schematic diagram of the structure of a training device for a code generation model provided in an embodiment of this application.
[0028] Figure 9 This is a schematic diagram of a query code generation device provided in an embodiment of this application.
[0029] Figure 10 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0030] The technical solutions of this application are applicable to database query scenarios. By adopting the technical solutions of this application, a code generation model can be constructed to automatically generate corresponding database query code based on natural language query statements, thereby improving the efficiency of data query code generation and thus improving database query efficiency.
[0031] In the data-driven digital age, databases, as the core carrier of data storage and management, have been widely used in various fields such as scientific research, industry, finance, and healthcare. Whether it is a materials property database in the field of materials science (such as the MP database), a transaction record database in the financial field, or a medical case database in the medical field, users need to obtain target data through query operations to support key tasks such as scientific research analysis, business decision-making, and problem diagnosis.
[0032] Currently, the mainstream approach to database queries relies on specialized query languages (such as SQL for relational databases and MongoDB query syntax for non-relational databases). Specifically, users need to first thoroughly understand the structure of the target database (including table structure, field attributes, data types, etc.), then write query statements that conform to the syntax rules according to their query requirements, submit query requests through database clients or API interfaces, and finally obtain the query results.
[0033] However, the above query methods require a high level of professional knowledge. Users need to learn query languages or rely on professional assistance to perform database queries, which severely restricts the efficiency of database queries. Furthermore, even if professionals write query statements, it still takes a certain amount of time, affecting the efficiency of database queries.
[0034] Based on this, this application proposes a training method for a code generation model. This technical solution can construct a code generation model and automatically generate corresponding database query code based on natural language query statements, thereby solving the problems of low efficiency in generating database query code and low efficiency in database query in the prior art.
[0035] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0036] Exemplary methods See Figure 1 As shown in the embodiment of this application, a training method for a code generation model is proposed. The method includes: S101. Obtain the filter field and return field from the target database, and determine the attribute information of the filter field and the attribute information of the return field.
[0037] This embodiment uses the database to be queried as the target database and performs a comprehensive analysis of it. Specifically, it analyzes all query-related fields in the target database and extracts the filter fields and return fields. The filter fields and return fields can be obtained manually by analyzing the target database, or by constructing a command to retrieve them and using a large language model to retrieve these fields according to the command.
[0038] After obtaining the filter field and return field from the target database, this embodiment also needs to determine the attribute information of the filter field and the return field from the target database. The attribute information of the filter field includes: data type (such as int, float, boolean, enumeration type, tuple type, list type, string type, etc.), all possible values, and format requirements. For example, the data type of the filter field "crystal_system" is an enumeration type, and its possible values include triclinic, monoclinic, orthorhombic, etc. Based on the format requirements, the standard enumeration values are CrystalSystem.tri, CrystalSystem.mono, etc.
[0039] The attribute information of the returned fields includes: the name of the returned field, the data type, and the code calling rule of the returned field. For example, the name of the returned field is "material_id" (material identifier), and the code calling rule is fields=["material_id" in the corresponding code.
[0040] In this embodiment, the attribute information of the filter field and the attribute information of the return field can be determined manually, or the attribute information acquisition instructions for each field can be constructed simultaneously when constructing the acquisition instructions for the filter field and the return field. Using a large language model, the attribute information of each filter field and the attribute information of each return field are acquired from the target database according to the above acquisition instructions.
[0041] S102. Based on the filter field, the return field, the attribute information of the filter field, and the attribute information of the return field, construct the target mapping pair and use the target mapping pair as training samples.
[0042] This embodiment, after obtaining the filter fields, return fields, and attribute information of the filter fields and return fields from the target database, needs to utilize these fields to construct target mapping pairs consisting of a natural language query statement and its corresponding query code. These target mapping pairs are then used as training samples for the code generation model. Constructing target mapping pairs in this embodiment first requires selecting at least one filter field and at least one return field from all filter fields and all return fields. Then, based on the values of the filter fields, values are assigned to them to obtain corresponding filter conditions. The selected filter conditions and the selected return fields are used as the basis for constructing target mapping pairs. A natural language query statement containing the filter conditions and return fields is constructed, along with query code based on these filter conditions and return fields. The natural language query statement and query code are then used as target mapping pairs. Alternatively, this embodiment can randomly select filter fields and return fields from all filter fields and all return fields, and randomly assign values to the filter fields according to their values, thereby obtaining several sets of target mapping pairs. In addition, this embodiment can also arrange and combine all filter fields and all return fields, and iterate through the values assigned to the filter fields to obtain all filter conditions corresponding to the filter fields, thereby obtaining more target mapping pairs.
[0043] In one specific implementation, a target mapping pair is constructed based on the filter field, the return field, the attribute information of the filter field, and the attribute information of the return field, including the following steps: First, construct field combinations based on the filter fields and return fields.
[0044] In this embodiment, after obtaining the filter fields and return fields from the target database, at least one filter field and at least one return field need to be selected from all filter fields and all return fields to construct a field combination. This embodiment can randomly set the number of filter fields and return fields in the field combination, and then randomly select filter fields and return fields from all filter fields and all return fields according to that number. To improve the diversity of target mapping pairs, the filter fields and return fields can also be permuted and combined to obtain several sets of field combinations.
[0045] For example, if the target database includes three filter fields A, B, and C, and two return fields a and b, then the generated field combinations can include: {A, a}, {A, b}, {B, a}, {B, b}, {C, a}, {C, b}, {A, B, a}, {A, B, b}, {A, C, a}, {A, C, b}, {B, C, a}, {B, C, b}, {A, B, C, b}, {A, a, b}, {B, a, b}, {C, a, b}, {A, B, a, b}, {A, C, a, b}, {B, C, a, b}, {A, B, C, a, b}. This permutation and combination method can determine all possible combinations.
[0046] In addition, this embodiment can also select only a preset number of fields for each type of field combination, which can ensure data diversity while reducing the amount of data. For example, three fields can be selected for a combination of one filter field and one return field, three fields can be selected for a combination of two filter fields and one return field, two fields can be selected for a combination of three filter fields and one return field, two fields can be selected for a combination of one filter field and two return fields, two fields can be selected for a combination of two filter fields and two return fields, and one field can be selected for a combination of three filter fields and two return fields.
[0047] Second, based on all possible values of the filter field, determine the filter conditions corresponding to the field combination, and construct the target combination based on the filter conditions and the returned fields in the field combination.
[0048] In this embodiment, the attribute information of the filter field includes all the possible values of the filter field. After the field combination is determined, the filter field in the field combination needs to be assigned a value according to all the possible values of the filter field to obtain the filter condition corresponding to the filter field. The filter conditions corresponding to all the filter fields in the field combination are used as the filter conditions corresponding to the field combination. Then, the filter conditions corresponding to the field combination and the returned fields in the field combination are combined to form the target combination.
[0049] For example, when the filter field is "crystal system," all possible values include "triclinic," "monoclinic," and "orthorhombic." Assigning "triclinic" to "crystal system" results in the filter condition "the crystal system is triclinic." When the filter field is "total energy," all possible values include (-200eV, -150eV), (-150eV, -100eV), and (-100eV, -50eV). Assigning (-200eV, -150eV) to "total energy" results in the filter condition "total energy is (-200eV, -150eV)." When the combined filter fields are "crystal system" and "total energy," the filter condition after the above assignment is "the crystal system is triclinic, and the total energy is (-200eV, -150eV)."
[0050] In this embodiment, different values assigned to the filter field result in different generated filter conditions. Therefore, this embodiment can sequentially assign all possible values of the filter field to the filter field to obtain multiple filter conditions corresponding to the filter field. When the field combination contains multiple filter fields, each filter field corresponds to multiple filter conditions, so the field combination contains more filter conditions, thereby enabling the construction of more target combinations. Alternatively, this embodiment can randomly select a preset number of filter conditions from all filter conditions to form a target combination with the returned field; it can also randomly select one value from all possible values of the filter field and assign it to the filter field to obtain random filter conditions corresponding to each filter field, combine them to obtain random filter conditions corresponding to the field combination, and then combine the random filter conditions corresponding to the field combination with the returned field in the field combination to form a target combination.
[0051] Third, construct the target mapping pairs corresponding to the target combinations.
[0052] After constructing the target combination through the above steps, it is necessary to build corresponding target mapping pairs for the target combination. Specifically, the filter conditions and return fields in the target combination are used to generate a statement according to natural language rules, thereby obtaining a natural language query statement containing the filter conditions and return fields of the target combination. The filter conditions and return fields in the target combination are used to generate code according to the database query code generation rules, resulting in query code. The natural language query statement corresponding to the target combination and the query code corresponding to the target combination are used as the target mapping pair for that target combination. The specific steps are as follows: First, generate natural language query statements corresponding to the target combination according to the pre-built natural language query statement template.
[0053] In this embodiment, a natural language query statement template is pre-built. The template sets the filter conditions, return fields, and the location of the target database. The target database to which the filter conditions and return fields in the target combination belong, as well as the filter conditions and return fields in the target combination, are inserted into the corresponding positions in the natural language query statement template to obtain the natural language query statement corresponding to the target combination.
[0054] This embodiment allows for setting different natural language query templates for different types of target databases. For example, for material property databases in the field of materials science (such as the MP database), the natural language query template can be set to "Query materials in [target database name] with [filter conditions], and return the [return fields] of the materials". When the filter conditions in the target combination are "the crystal system is triclinic and the total energy is (-200eV, -150eV)", and the return fields in the target combination are "material identifier" and "number of lattice points", the natural language query generated according to the natural language query template is "Query materials in the MP database with the crystal system being triclinic and the total energy being (-200eV, -150eV), and return the material identifier and the number of lattice points of the materials". Secondly, based on the pre-built query code generation rules and the code calling rules of the returned fields, the query code corresponding to the target combination is generated.
[0055] This embodiment pre-constructs query code generation rules, which map the filtering conditions and returned fields in the target combination to code logic conforming to the target database's calling specifications. These rules can include, for example, complete logic such as class import statements, interface calls, filtering condition settings, and returned attribute specifications. The attribute information of the returned fields includes the code calling rules for those fields, which are essentially the code calling specifications for the returned fields. Based on the pre-constructed query code generation rules and the returned field code calling rules, query code corresponding to the target combination is generated. Specifically, this includes: parsing the filtering conditions and converting them into code parameters conforming to the specifications; parsing the returned fields according to the returned field code calling rules and converting them into the returned specified logic in the code; and integrating the above content to generate complete query code. For example, an automatic SQL statement generator can be used to generate the query code corresponding to the target combination.
[0056] Finally, the natural language query statement and the query code corresponding to the target combination are used as the target mapping pair corresponding to the target combination.
[0057] S103. Using training samples, perform query code generation training on the pre-built code generation model to obtain the trained code generation model.
[0058] After obtaining the training samples through the above steps, the pre-built code generation model is trained using these samples in a supervised manner to generate query codes, resulting in a trained code generation model. Specifically, the natural language query statements from the training samples are input into the pre-built code generation model. The model generates predicted query codes corresponding to the natural language query statements. The parameters of the code generation model are adjusted with the goal of minimizing the difference between the predicted query codes and the query codes corresponding to the natural language query statements in the training samples. The pre-built code generation model can employ a traditional neural network, preferably a large language model such as the LoRA model.
[0059] As described above, the training method for the code generation model proposed in this application involves obtaining filter fields and return fields from the target database, and determining the attribute information of the filter fields and return fields. Based on the filter fields, return fields, and the attribute information of the filter fields and return fields, a target mapping pair is constructed, and this target mapping pair is used as training samples. The target mapping pair includes a natural language query statement and the corresponding query code. Using the training samples, the pre-constructed code generation model is trained to generate query code, resulting in a trained code generation model. By employing the technical solution of this embodiment, a code generation model can be constructed, enabling the automatic generation of corresponding database query code based on natural language query statements, thereby improving the efficiency of data query code generation and ultimately improving database query efficiency.
[0060] As an optional implementation method, see [link to implementation details]. Figure 2 As shown, another embodiment of this application discloses that, when there is only one filter field in the field combination, the filter conditions corresponding to the field combination are determined based on all the values of the filter field, and the target combination is constructed based on the filter conditions and the returned fields in the field combination, including the following steps: S201. Assign each value corresponding to the filter field in the field combination to the filter field to obtain the filter conditions corresponding to each value.
[0061] When a field combination contains only one filter field, each value corresponding to that filter field is assigned to the filter field, thereby obtaining the filter conditions corresponding to each value. In other words, the number of filter conditions will be generated as many as the number of values the filter field has.
[0062] S202. Combine each filter condition with the returned fields in the field combination to form a target combination.
[0063] Each filter condition corresponding to the filter field in the above-determined field combination is combined with the return field in the field combination to obtain the target combination, and the number of target combinations is the same as the number of all values of the filter field.
[0064] By using the above permutation method, we can ensure that all values in the filtering field appear at least once, thereby guaranteeing the amount of training sample data and improving the training effect of the code generation model.
[0065] As an optional implementation method, see [link to implementation details]. Figure 3 As shown, another embodiment of this application discloses that, when there are multiple filter fields in a field combination, the filter conditions corresponding to the field combination are determined based on all values of the filter fields, and a target combination is constructed based on the filter conditions and the returned fields in the field combination, including the following steps: S301. Based on all possible values of the filter field, construct a value queue corresponding to the filter field.
[0066] This embodiment requires constructing a queue for all values of the extracted filter fields to obtain the value queues corresponding to each filter field. The value queues corresponding to each filter field conform to the rule of taking the head of the queue and adding the tail. For example, the value queue corresponding to filter field 1 is [value 11, value 12, value 13], the value queue corresponding to filter field 2 is [value 21, value 22], and the value queue corresponding to filter field 3 is [value 31, value 32, value 33, value 34].
[0067] S302. Assign the values output from the value queue corresponding to the filter field in the field combination to the filter field to obtain the filter conditions corresponding to each filter field in the field combination.
[0068] In this embodiment, the values output from the value queue corresponding to the filter field in the field combination are assigned to the filter field, thereby obtaining the filter conditions corresponding to each filter field in the field combination. The rule for outputting values from the value queue is to take the value at the head of the queue and add it to the queue as the tail. For example, if the first field combination contains filter field 1 and filter field 2, then the value 11 at the head of the value queue corresponding to filter field 1 is assigned to filter field 1 to obtain filter condition 11, and the value queue corresponding to filter field 1 is updated to [value 12, value 13, value 11]. The value 21 at the head of the value queue corresponding to filter field 2 is assigned to filter field 2 to obtain filter condition 21, and the value queue corresponding to filter condition 2 is updated to [value 22, value 21]. The second field combination contains filter fields Filter Field 1 and Filter Field 3. Then, the value 12 at the head of the value queue corresponding to Filter Field 1 is assigned to Filter Field 1 to obtain filter condition 12. The value queue corresponding to Filter Field 1 is updated to [value 13, value 11, value 12]. The value 31 at the head of the value queue corresponding to Filter Field 3 is assigned to Filter Field 3 to obtain filter condition 31. The value queue corresponding to Filter Field 3 is updated to [value 32, value 33, value 34, value 31]. The third field combination contains filter fields 1, 2, and 3. Therefore, the value 13 at the head of the value queue corresponding to filter field 1 is assigned to filter field 1, resulting in filter condition 13. The value queue corresponding to filter field 1 is then updated to [value 13, value 11, value 12]. The value 22 at the head of the value queue corresponding to filter field 2 is assigned to filter field 2, resulting in filter condition 22. The value queue corresponding to filter condition 2 is then updated to [value 21, value 22]. The value 32 at the head of the value queue corresponding to filter field 3 is assigned to filter field 3, resulting in filter condition 32. The value queue corresponding to filter field 3 is then updated to [value 33, value 34, value 31, value 32]. This assignment method is used to assign filter field values to all field combinations with multiple filter fields, thus obtaining the filter conditions corresponding to the field combinations.
[0069] S303. Combine the filter conditions corresponding to each filter field in the field combination with the return fields in the field combination to form a target combination.
[0070] Combine the filter conditions corresponding to all the filter fields in the field combination to form the filter conditions corresponding to that field combination. Combine the filter conditions corresponding to that field combination and the returned fields in that field combination to form the target combination corresponding to that field combination.
[0071] For example, based on the examples in the steps above, if the first field combination contains filter fields 1 and 2, and return fields 1 and 2, then filter condition 11 corresponding to filter field 1 and filter condition 21 corresponding to filter field 2 are used as the filter conditions for the first field combination, resulting in a first target combination including filter condition 11, filter condition 21, return field 1, and return field 2. If the second field combination contains filter fields 1 and 3, and return fields 2, 3, and 4, then filter condition 12 corresponding to filter field 1 and filter condition 31 corresponding to filter field 3 are used as the filter conditions for the second field combination, resulting in a second target combination including filter condition 12, filter condition 31, return field 2, return field 3, and return field 4. The third field combination contains filter fields 1, 2, and 3, and return fields 3 and 4. Filter conditions 13 (corresponding to filter field 1), 22 (corresponding to filter condition 2), and 32 (corresponding to filter field 3) are used as the filter conditions for the third field combination. This results in the third target combination containing filter conditions 13, 22, 32, return field 3, and return field 4.
[0072] By constructing a value queue for the filter fields as described above and assigning values to the filter fields in each field combination sequentially, it is possible to ensure that the values of each filter field are evenly distributed in the training samples, thereby improving the training effect of the training samples.
[0073] As an optional implementation method, see [link to implementation details]. Figure 4 As shown, another embodiment of this application discloses that constructing a target mapping pair based on the filter field, the return field, the attribute information of the filter field, and the attribute information of the return field may further include the following steps: S401. Construct field combinations based on filter fields and return fields.
[0074] S402. Based on all values of the filter field, determine the filter conditions corresponding to the field combination, and construct the target combination based on the filter conditions and the returned fields in the field combination.
[0075] S403. If the field combination includes multiple filter fields or multiple return fields, then the order of the multiple filter conditions and / or multiple return fields in the target combination is adjusted to obtain the target combination after the order adjustment.
[0076] If a field combination includes multiple filtering fields, the order of the multiple filtering conditions in the target combination corresponding to that field combination is adjusted to obtain a target combination with adjusted order. Similarly, if a field combination includes multiple return fields, the order of the multiple return fields in the target combination corresponding to that field combination is adjusted to obtain a target combination with adjusted order. Furthermore, this embodiment uses different order adjustment methods to obtain different target combinations. By adjusting the order, this embodiment can improve the diversity of target combinations, thereby increasing the data diversity of training samples and ultimately improving the training effect on the code generation model.
[0077] S404. Construct the target mapping pairs corresponding to the target combinations.
[0078] Steps S401, S402, and S404 in this embodiment have been specifically described in the above embodiments, and will not be repeated here.
[0079] As an optional implementation method, see [link to implementation details]. Figure 5 As shown, another embodiment of this application discloses that constructing a target mapping pair based on the filter field, the return field, the attribute information of the filter field, and the attribute information of the return field may further include the following steps: S501. If the data type of the filter field in the field combination matches the pre-set complex value type, then extract the edge values from all the values corresponding to the filter field in the field combination.
[0080] In this embodiment, a complex value type is pre-defined, meaning a data type with complex values, such as enumeration, boolean, or tuple types. The attribute information of the filtering field includes the data type. In this embodiment, after determining the field combination, it can first determine whether the data type corresponding to the field combination conforms to the pre-defined complex value type. If the data type corresponding to the field combination does not conform to the complex value type, meaning the data type of the filtering field included in the field combination is not a complex value type, then the target mapping pair is directly constructed according to the method described in the previous embodiment, and the following steps of this embodiment are not executed. If the data type corresponding to the field combination conforms to the complex value type, meaning the field combination contains a filtering field with a complex value type, then it is necessary to extract edge values from all values of the filtering field with a complex value type in the field combination.
[0081] S502. Assign the edge values corresponding to the filter fields in the field combination to the filter fields to obtain the edge filter conditions.
[0082] The edge values extracted in the above steps are assigned to the corresponding filter fields. That is, the edge values of the filter fields with complex data types in the field combination are assigned to the corresponding filter fields, thereby obtaining the edge filtering conditions corresponding to the filter fields.
[0083] S503. Combine the edge filtering conditions with the returned fields in the field combination to form an edge target combination.
[0084] The edge filter conditions corresponding to the filter fields with complex data types in the field combination, the filter conditions corresponding to the filter fields with non-complex data types in the field combination, and the returned fields in the field combination are combined to form an edge target combination.
[0085] S504. Construct the target mapping pairs corresponding to the edge target combinations.
[0086] The specific execution method for constructing the target mapping pair corresponding to the edge target combination in this embodiment is the same as the specific execution method for constructing the target mapping pair corresponding to the target combination in the above embodiment, and will not be repeated in this embodiment.
[0087] Since edge values are rarely assigned to filter fields with complex values, this embodiment can be used to assign edge values to filter fields with complex values, thereby improving the query training samples for edge scenarios and ensuring that each complex value has sufficient sample coverage, thus achieving sample augmentation of the training samples and improving the training effect of the code generation model.
[0088] In addition, sample augmentation of training samples can be achieved by setting the number of filtering fields and the number of returned fields in the field combination to be greater than the preset number (e.g., greater than 3). In this case, the field combination is a complex field combination, and the constructed target mapping pair is a complex target mapping pair, which increases the complexity of the training samples and thus enhances the ability of the code generation model to handle complex query requirements.
[0089] As an optional implementation, this application also proposes a training method for a code generation model. See [link to relevant documentation]. Figure 6 As shown, the method includes: S601. Obtain the filter field and return field from the target database, and determine the attribute information of the filter field and the attribute information of the return field.
[0090] S602. Based on the filter field, the return field, the attribute information of the filter field, and the attribute information of the return field, construct the target mapping pair and use the target mapping pair as training samples.
[0091] S603. Rewrite the natural language query statements in the target mapping pairs according to the pre-set statement rewriting rules, and use the rewritten natural language query statements as target mapping pairs as training samples.
[0092] This embodiment pre-defines natural language query rewriting rules. Using these rules, natural language queries in the training samples are rewritten to generate semantically unchanged but expressively diverse queries. The rewritten queries and their corresponding query codes are then used as target mapping pairs, which are then used as training samples. This embodiment can rewrite natural language queries manually according to the rules, or it can utilize a large language model. For example, rewriting instructions can be set according to the rules, and the large language model can rewrite the natural language queries by executing these instructions.
[0093] In this embodiment, the statement rewriting rules may include: terminology Chinese replacement (e.g., "Fe2O3" is changed to "iron oxide"), attribute term synonym replacement (e.g., "band gap" is changed to "bandwidth restriction"), redundant information removal, sentence structure adjustment (interrogative sentences, imperative sentences, etc.), and query condition order adjustment.
[0094] For example, the original natural language query statement is: "Query the MP database for materials with a volumetric capacity of less than 400.0, a discharge material energy higher than the convex hull value of less than 10.0, and a volumetric energy between 350. and 500.0, and return the material's unique battery identifier, charging state ID, and charging state stability." The first rewritten natural language query statement is: "Please filter materials from the MP database that have a volumetric capacity < 400.0, a discharge material energy superconvexity value < 10.0, and a volumetric energy between 350.0 and 500.0, and return the battery's unique identifier, charging state ID, and charging state stability."
[0095] The second rewritten natural language query is: "In the MP database, for materials with a volumetric capacity not exceeding 400.0, a discharge material energy difference of less than 10.0 from the convex hull, and a volumetric energy between 350.0 and 500.0, please return their unique battery identifier, charging state ID, and charging state stability attribute."
[0096] S604. Using training samples, perform query code generation training on the pre-built code generation model to obtain the trained code generation model.
[0097] In this embodiment, steps S601, S602, and S604 are the same as steps S101, S102, and S103 in the above embodiment, and will not be repeated here.
[0098] As an optional implementation, this application also proposes a query code generation method. See [link to relevant documentation]. Figure 7 As shown, the method includes: S701. Obtain the user's natural language query statement.
[0099] The user enters a natural language query statement according to their query needs. This embodiment obtains the user's natural language query statement.
[0100] S702. Input the user's natural language query statement into the pre-trained code generation model to obtain the target query code corresponding to the user's natural language query statement.
[0101] The obtained user natural language query statement is input into the code generation model trained according to the training method of the code generation model in the above embodiment. The code generation model generates query code corresponding to the user natural language query statement, which is then used as the target query code. The query task for the target database is achieved through this target query code.
[0102] As can be seen from the above description, the query code generation method proposed in this application can construct a code generation model, realize the automatic generation of corresponding database query code based on natural language query statements, thereby improving the generation efficiency of data query code and thus improving the database query efficiency.
[0103] Exemplary device Accordingly, embodiments of this application also provide a training apparatus for a code generation model, see [link to relevant documentation]. Figure 8 As shown, the device includes: The field acquisition module 100 is used to obtain the filter fields and return fields from the target database, and to determine the attribute information of the filter fields and the attribute information of the return fields. The construction module 110 is used to construct target mapping pairs based on the filter field, the return field, the attribute information of the filter field, and the attribute information of the return field, and to use the target mapping pairs as training samples; wherein, the target mapping pair includes: a natural language query statement and the query code corresponding to the natural language query statement; Training module 120 is used to train a pre-built code generation model using training samples to obtain a trained code generation model.
[0104] As can be seen from the above description, the training device for the code generation model proposed in this application can construct a code generation model, realize the automatic generation of corresponding database query code based on natural language query statements, thereby improving the generation efficiency of data query code and thus improving the database query efficiency.
[0105] As an optional implementation, another embodiment of this application discloses that the attribute information of the filtering field includes all values corresponding to the filtering field; the construction module 110 includes: a field combination construction unit, a target combination construction unit, and a target mapping pair construction unit.
[0106] A field combination building unit is used to construct field combinations based on filter fields and return fields, wherein the field combination includes at least one filter field and at least one return field; The target combination building unit is used to determine the filtering conditions corresponding to the field combination based on all the values of the filtering field, and to build the target combination based on the filtering conditions and the returned fields in the field combination; The target mapping pair building unit is used to construct the target mapping pairs corresponding to the target combination.
[0107] As an optional implementation, another embodiment of this application discloses that the attribute information of the returned field includes the code calling rules of the returned field; the target mapping pair construction unit is specifically used for: Generate natural language query statements corresponding to the target combination based on the pre-built natural language query statement template; Based on pre-built query code generation rules and code calling rules for returned fields, generate query code corresponding to the target combination; The natural language query statement and the query code corresponding to the target combination are used as the target mapping pair corresponding to the target combination.
[0108] As an optional implementation, another embodiment of this application discloses that, when there is only one filter field in the field combination, the target combination construction unit is specifically used for: Assign each value corresponding to the filter field in the field combination to the filter field to obtain the filter conditions corresponding to each value. Each filter condition is combined with the returned fields in the field combination to form a target combination.
[0109] As an optional implementation, another embodiment of this application discloses that, when there are multiple filter fields in the field combination, the target combination construction unit is specifically used for: Based on all possible values of the filter field, construct a value queue corresponding to the filter field; Assign the values output from the value queue corresponding to the filter field in the field combination to the filter field to obtain the filter conditions corresponding to each filter field in the field combination; Combine the filter conditions corresponding to each filter field in the field combination with the returned fields in the field combination to form the target combination.
[0110] As an optional implementation, another embodiment of this application discloses that the construction module 110 further includes: a sequence adjustment unit; The order adjustment unit is used to adjust the order of multiple filter conditions and / or multiple return fields in the target combination if the field combination includes multiple filter fields or multiple return fields, so as to obtain the target combination after order adjustment.
[0111] As an optional implementation, another embodiment of this application discloses that the construction module 110 further includes: an edge value extraction unit and an assignment unit; The edge value extraction unit is used to extract edge values from all values corresponding to the filter field in the field combination if the data type of the filter field in the field combination matches the pre-set complex value type. The assignment unit is used to assign the edge value corresponding to the filter field in the field combination to the filter field to obtain the edge filter condition; The target combination building unit is also used to combine edge filtering conditions with the returned fields in the field combination to form an edge target combination; The target mapping pair building unit is also used to construct target mapping pairs corresponding to combinations of edge targets.
[0112] As an optional implementation, another embodiment of this application discloses a training apparatus for a code generation model, which further includes a statement rewriting module; The statement rewriting module is used to rewrite the natural language query statements in the target mapping pairs according to the pre-set statement rewriting rules, and use the rewritten natural language query statements as target mapping pairs as training samples.
[0113] The training apparatus for the code generation model provided in this embodiment belongs to the same concept as the training method for the code generation model provided in the above embodiments of this application. It can execute the training method for the code generation model provided in any of the above embodiments of this application and has the corresponding functional modules and beneficial effects of the training method for the code generation model. Technical details not described in detail in this embodiment can be found in the specific processing content of the training method for the code generation model provided in the above embodiments of this application, and will not be repeated here.
[0114] As an optional implementation, this application also provides a query code generation device, see [link to relevant documentation]. Figure 9As shown, the device includes: The statement acquisition module 200 is used to acquire the user's natural language query statement; The code generation module 210 is used to input the user's natural language query statement into the pre-trained code generation model to obtain the target query code corresponding to the user's natural language query statement; As can be seen from the above description, the query code generation device proposed in this application can construct a code generation model and automatically generate corresponding database query codes based on natural language query statements, thereby improving the generation efficiency of data query codes and thus improving the database query efficiency.
[0115] The query code generation apparatus provided in this embodiment belongs to the same concept as the query code generation method provided in the above embodiments of this application. It can execute the query code generation method provided in any of the above embodiments of this application and has the corresponding functional modules and beneficial effects of executing the query code generation method. Technical details not described in detail in this embodiment can be found in the specific processing content of the query code generation method provided in the above embodiments of this application, and will not be repeated here.
[0116] Exemplary electronic devices Another embodiment of this application also provides an electronic device, see [link to relevant documentation] Figure 10 As shown, the device includes: Memory 300 and processor 310; The memory 300 is connected to the processor 310 and is used to store programs; The processor 310 is configured to implement the training method of the code generation model disclosed in any of the above embodiments or the query code generation method disclosed in any of the above embodiments by running the program stored in the memory 300.
[0117] Specifically, the aforementioned electronic device may also include: a bus, a communication interface 320, an input device 330, and an output device 340.
[0118] The processor 310, memory 300, communication interface 320, input device 330, and output device 340 are interconnected via a bus. Among them: A bus can include a pathway for transmitting information between various components of a computer system.
[0119] The processor 310 can be a general-purpose processor, such as a general-purpose central processing unit (CPU), a microprocessor, etc., or an application-specific integrated circuit (ASIC), or one or more integrated circuits used to control the execution of the program of the present invention. It can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), an off-the-shelf programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0120] Processor 310 may include a main processor, as well as a baseband chip, modem, etc.
[0121] The memory 300 stores a program that executes the technical solution of this invention, and may also store an operating system and other key business functions. Specifically, the program may include program code, which includes computer operation instructions. More specifically, the memory 300 may include read-only memory (ROM), other types of static storage devices capable of storing static information and instructions, random access memory (RAM), other types of dynamic storage devices capable of storing information and instructions, disk storage, flash memory, etc.
[0122] Input device 330 may include a device for receiving user input data and information, such as a keyboard, mouse, camera, scanner, light pen, voice input device, touch screen, pedometer, or gravity sensor.
[0123] Output device 340 may include devices that allow information to be output to a user, such as a display screen, printer, speaker, etc.
[0124] The communication interface 320 may include a device that uses any transceiver to communicate with other devices or communication networks, such as Ethernet, Radio Access Network (RAN), Wireless Local Area Network (WLAN), etc.
[0125] The processor 310 executes the program stored in the memory 300 and calls other devices, which can be used to implement the various steps of any training method of the code generation model or any query code generation method provided in the above embodiments of this application.
[0126] Exemplary computer program products and storage media In addition to the methods and devices described above, embodiments of this application may also be computer program products, which include computer program instructions that, when executed by a processor, cause the processor to perform steps in the training method or querying method of the code generation model according to various embodiments of this application as described in the "Exemplary Methods" section of this specification.
[0127] The computer program product can be written in any combination of one or more programming languages to perform the operations of the embodiments of this application. The programming languages include object-oriented programming languages such as Java and C++, as well as conventional procedural programming languages such as C or similar languages. The program code can be executed entirely on the user's computing device, partially on the user's computing device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0128] Furthermore, embodiments of this application may also be storage media storing a computer program, which is executed by a processor in the steps of the training method or the query method of the code generation model according to various embodiments of this application described in the "Exemplary Methods" section above.
[0129] For the foregoing method embodiments, in order to simplify the description, they are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, because according to this application, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0130] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For apparatus embodiments, since they are basically similar to method embodiments, the description is relatively simple; relevant parts can be referred to the descriptions in the method embodiments.
[0131] The steps in the methods of the various embodiments of this application can be adjusted, merged, or deleted in order according to actual needs, and the technical features described in each embodiment can be replaced or combined.
[0132] The modules and sub-modules in the various embodiments of the present application's devices and terminals can be merged, divided, and deleted according to actual needs.
[0133] It should be understood that the disclosed terminals, devices, and methods can be implemented in other ways, given the several embodiments provided in this application. For example, the terminal embodiments described above are merely illustrative. For instance, the division of modules or sub-modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple sub-modules or modules may be combined or integrated into another module, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or modules, and may be electrical, mechanical, or other forms.
[0134] The modules or submodules described as separate components may or may not be physically separate. The components that constitute a module or submodule may or may not be physical modules or submodules; that is, they may be located in one place or distributed across multiple network modules or submodules. Some or all of the modules or submodules can be selected to achieve the purpose of this embodiment's solution, depending on actual needs.
[0135] Furthermore, the functional modules or sub-modules in the various embodiments of this application can be integrated into one processing module, or each module or sub-module can exist physically separately, or two or more modules or sub-modules can be integrated into one module. The integrated modules or sub-modules described above can be implemented in hardware or in the form of software functional modules or sub-modules.
[0136] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0137] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software unit executed by a processor, or a combination of both. The software unit can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.
[0138] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0139] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A training method for a code generation model, characterized in that, include: Retrieve the filter fields and return fields from the target database, and determine the attribute information of the filter fields and the attribute information of the return fields; Based on the filtering field, the return field, the attribute information of the filtering field, and the attribute information of the return field, a target mapping pair is constructed, and the target mapping pair is used as a training sample; wherein, the target mapping pair includes: a natural language query statement and the query code corresponding to the natural language query statement; Using the training samples, the pre-built code generation model is trained to generate query code, resulting in a trained code generation model.
2. The training method for the code generation model according to claim 1, characterized in that, The attribute information of the filter field includes all possible values corresponding to the filter field; Based on the filtering field, the returned field, the attribute information of the filtering field, and the attribute information of the returned field, a target mapping pair is constructed, including: Based on the filter field and the return field, a field combination is constructed, wherein the field combination includes at least one filter field and at least one return field; Based on all the values of the filter field, determine the filter conditions corresponding to the field combination, and construct the target combination based on the filter conditions and the returned fields in the field combination; Construct the target mapping pairs corresponding to the target combination.
3. The training method for the code generation model according to claim 2, characterized in that, The attribute information of the returned field includes the code calling rules of the returned field; Constructing the target mapping pairs corresponding to the target combination includes: Generate natural language query statements corresponding to the target combination according to the pre-built natural language query statement template; Based on the pre-built query code generation rules and the code calling rules of the returned fields, the query code corresponding to the target combination is generated; The natural language query statement corresponding to the target combination and the query code corresponding to the target combination are used as the target mapping pair corresponding to the target combination.
4. The training method for the code generation model according to claim 2, characterized in that, When there is only one filter field in the field combination, the filter conditions corresponding to the field combination are determined based on all possible values of the filter field. Based on the filter conditions and the returned fields in the field combination, a target combination is constructed, including: Each value corresponding to the filter field in the field combination is assigned to the filter field to obtain the filter condition corresponding to each value. Each filter condition is combined with the returned fields in the field combination to form a target combination.
5. The training method for the code generation model according to claim 2, characterized in that, When there are multiple filter fields in the field combination, the filter conditions corresponding to the field combination are determined based on all values of the filter fields. Based on the filter conditions and the returned fields in the field combination, a target combination is constructed, including: Based on all possible values of the filter field, construct a value queue corresponding to the filter field; Assign the values output from the value queue corresponding to the filter field in the field combination to the filter field to obtain the filter conditions corresponding to each filter field in the field combination; The filter conditions corresponding to each filter field in the field combination and the returned fields in the field combination are combined to form a target combination.
6. The training method for the code generation model according to claim 2, after determining the filtering conditions corresponding to the field combination based on all values of the filtering field, and constructing the target combination based on the filtering conditions and the returned fields in the field combination, further includes: If the field combination includes multiple filter fields or multiple return fields, then the order of the multiple filter conditions and / or multiple return fields in the target combination is adjusted to obtain the target combination after the order adjustment.
7. The training method for the code generation model according to claim 2, characterized in that, The attribute information of the filter field includes the data type corresponding to the filter field; Based on the filtering field, the returned field, the attribute information of the filtering field, and the attribute information of the returned field, constructing a target mapping pair further includes: If the data type of the filter field in the field combination matches the pre-set complex value type, then the edge value is extracted from all the values corresponding to the filter field in the field combination. The edge values corresponding to the filter fields in the field combination are assigned to the filter fields to obtain the edge filter conditions; Combine the edge filtering conditions with the returned fields from the field combination to form an edge target combination; Construct the target mapping pairs corresponding to the edge target combinations.
8. The training method for the code generation model according to claim 1, characterized in that, After constructing the target mapping pair based on the filter field, the return field, the attribute information of the filter field, and the attribute information of the return field, the process further includes: According to the pre-set statement rewriting rules, the natural language query statements in the target mapping pairs are rewritten, and the rewritten target mapping pairs are used as training samples.
9. A method for generating query codes, characterized in that, include: Get the user's natural language query statement; The user's natural language query statement is input into a pre-trained code generation model to obtain the target query code corresponding to the user's natural language query statement; The code generation model is determined using the training method of the code generation model as described in any one of claims 1-8.
10. A training device for a code generation model, characterized in that, include: The field acquisition module is used to obtain the filter field and the return field from the target database, and to determine the attribute information of the filter field and the attribute information of the return field; A construction module is used to construct target mapping pairs based on the filtering field, the return field, the attribute information of the filtering field, and the attribute information of the return field, and to use the target mapping pairs as training samples; wherein, the target mapping pair includes: a natural language query statement and the query code corresponding to the natural language query statement; The training module is used to train the pre-built code generation model to generate query code using the training samples, so as to obtain the trained code generation model.
11. A query code generation device, characterized in that, include: The statement retrieval module is used to retrieve the user's natural language query statement; The code generation module is used to input the user's natural language query statement into a pre-trained code generation model to obtain the target query code corresponding to the user's natural language query statement; The code generation model is determined using the training method of the code generation model as described in any one of claims 1-8.
12. An electronic device, characterized in that, include: Memory and processor; The memory is connected to the processor and is used to store programs; The processor is configured to implement the training method of the code generation model as described in any one of claims 1 to 8 or the query code generation method as described in claim 9 by running the program in the memory.
13. A computer program product, characterized in that, It includes computer program instructions that, when executed by a processor, cause the processor to implement the training method of the code generation model as described in any one of claims 1 to 8 or the query code generation method as described in claim 9.