Text2SQL data set construction method and device based on large model
Through the Text2SQL dataset construction method based on large models, problem templates and SQL templates are automatically generated and filled, which solves the problem of low dataset construction efficiency in the existing technology, and realizes efficient dataset construction and automated data enhancement.
Patent Information
- Application Number
- CN202411194884.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-29
- Publication Date
- 2024-11-12
AI Technical Summary
In the prior art, data set construction efficiency is low, and it is necessary to manually understand database design ideas and write SQL statements, resulting in inefficiency.
Using the Text2SQL dataset construction method based on the big model, the problem template and SQL template are generated by inputting the problem text, prompt text and database field information to be enhanced into the big model, and the problem template and SQL template are filled according to the corresponding relationship between the pre-save field information and the value. , realize automatic data enhancement.
No need to manually write problem templates and SQL templates, which improves data set construction efficiency, realizes automated data enhancement, and simplifies the semantic gap between database schema and natural language query.
Smart Images

Figure CN118940740A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a method and device for constructing a Text2SQL data set based on a large model. Background Art
[0002] In the industry, one of the mainstream ways to improve model stability and accuracy is to increase the data size and improve data quality. Data augmentation is to use limited labeled data to obtain more training samples, which plays a certain role in improving model performance.
[0003] When manually labeling data in a dataset, relevant personnel need to fully understand the design ideas of the database when modeling, and be able to correctly use each field in the database to build a high-quality dataset. This requires relevant personnel to understand the meaning of each field in the database, that is, relevant personnel can only construct high-quality data after carefully studying the database design documents. It takes a lot of time for relevant personnel to study the database design text, and the larger the data scale included in the dataset, the lower the efficiency of manually constructing the dataset.
[0004] Therefore, how to improve the efficiency of dataset construction becomes an urgent problem to be solved. Summary of the invention
[0005] The embodiment of the present application provides a Text2SQL dataset construction method and device based on a large model, so as to solve the problem of low efficiency of dataset construction in the prior art.
[0006] In a first aspect, the present application provides a method for constructing a Text2SQL dataset based on a large model, the method comprising:
[0007] The question text to be enhanced, the first prompt text, and the field information included in the database are spliced and input into the first large model to obtain a question template of the question text to be enhanced, wherein the first prompt text is used to prompt the first large model to analyze the field information and the question text to be enhanced to generate a question template of the question text to be enhanced;
[0008] Searching the field information for first field information corresponding to the character area to be filled in the question template; inputting the question template, the first field information and the second prompt text into the second large model to obtain an SQL template;
[0009] According to the pre-saved correspondence between different field information and field values, the target field value corresponding to the first field information is determined, and the target field value is correspondingly filled into the question template and the SQL template to obtain the target question text and the target SQL statement.
[0010] In a second aspect, the present application provides a device for constructing a Text2SQL dataset based on a large model, the device comprising:
[0011] A generation module is used to splice the question text to be enhanced, the first prompt text, and the field information included in the database and input them into the first large model to obtain a question template of the question text to be enhanced, wherein the first prompt text is used to prompt the first large model to analyze the field information and the question text to be enhanced to generate the question template of the question text to be enhanced; search the field information for the first field information corresponding to the character area to be filled in the question template; input the question template, the first field information and the second prompt text into the second large model to obtain an SQL template;
[0012] A filling module is used to determine the target field value corresponding to the first field information according to the pre-saved correspondence between different field information and field values, and fill the target field value into the question template and the SQL template to obtain the target question text and the target SQL statement.
[0013] In a third aspect, the present application further provides an electronic device, comprising a processor, wherein the processor is configured to implement the steps of any of the above-described methods for constructing a Text2SQL dataset based on a large model when executing a computer program stored in a memory.
[0014] In a fourth aspect, the present application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of any of the above-mentioned methods for constructing a Text2SQL dataset based on a large model.
[0015] Because in the embodiment of the present application, the question text to be enhanced, the first prompt text, and the field information included in the database are spliced and input into the first large model, so that the first large model analyzes the field information and the question text to be enhanced, thereby obtaining a question template of the question text to be enhanced, without the need to manually write the question template, and search the field information for the first field information corresponding to the character area to be filled in the question template, and input the question template, the first field information and the second prompt text into the second large model to obtain an SQL template, without the need to manually write an SQL template corresponding to the question template, and then determine the target field value corresponding to the first field information according to the correspondence between different field information and field values saved in advance, and fill the target field value into the question template and the SQL template accordingly, to obtain the target question text and the target SQL statement, and search the field information in the database for matching target field values and fill them into the question template and the SQL template, thereby realizing automatic data enhancement and improving the efficiency of data set construction. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solution of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0017] Figure 1 A schematic diagram of a SQL statement determination idea provided in an embodiment of the present application;
[0018] Figure 2 A flowchart of a Text2SQL dataset construction process based on a large model provided in an embodiment of the present application;
[0019] Figure 3 A flowchart of a Text2SQL dataset construction provided in an embodiment of the present application;
[0020] Figure 4 A flowchart of a Text2SQL dataset construction provided in an embodiment of the present application;
[0021] Figure 5 A schematic diagram of the structure of a Text2SQL data set construction device based on a large model provided in an embodiment of the present application;
[0022] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0023] In order to make the purpose, technical solution and advantages of the present application clearer, the technical solution of the embodiment of the present application will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiment is only a part of the embodiment of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field belong to the scope of protection of this application.
[0024] As structured metadata, the database schema provides very limited business knowledge. Without understanding the business knowledge of database modeling, it is difficult to accurately construct a Structured Query Language (SQL) statement that implements a correct query function. You need to rely on the detailed database design document to write SQL statements. For example, Figure 1 The content shown, Figure 1A schematic diagram of an SQL statement determination idea provided for an embodiment of the present application, the question raised by the user is "Are there more key drivers whose driver's licenses in Xiamen expired this month than last month?" In order to correctly generate the SQL statement corresponding to this question, it is necessary to determine the table name and column name involved in this question, so you need to think about what a key driver is? Which field should be used for expired driver's license? Which field should be used for time? In addition, it needs to be understood that key drivers refer to drivers whose permitted driving types are large passenger cars, tractors, city buses, medium-sized passenger cars, and large trucks, while the table names of the database model only include drivers and motor vehicles, and the column names corresponding to the data table only include administrative divisions, permitted driving types, initial license issuance dates, license renewal dates, etc., and do not include the knowledge of key drivers. This requires business personnel who write SQL statements to have sufficient knowledge of the field, and the requirements for business personnel are relatively high.
[0025] Based on this, an embodiment of the present application provides a Text2SQL data set construction method, device, equipment and medium based on a large model. In this method, the question text to be enhanced, the first prompt text, and the field information included in the database are spliced and input into the first large model to obtain a question template of the question text to be enhanced. The first prompt text is used to prompt the first large model to analyze the field information and the question text to be enhanced, and generate a question template of the question text to be enhanced; the first field information corresponding to the character area to be filled in the question template is searched in the field information; the question template, the first field information and the second prompt text are input into the first large model to obtain a SQL template; according to the correspondence between different field information and field values saved in advance, the target field value corresponding to the first field information is determined, and the target field value is correspondingly filled into the question template and the SQL template to obtain the target question text and the target SQL statement.
[0026] Figure 2 A flowchart of a Text2SQL dataset construction process based on a large model provided in an embodiment of the present application is shown in FIG. Figure 2 As shown, the process includes the following steps:
[0027] S201: The question text to be enhanced, the first prompt text, and the field information included in the database are spliced and input into the first large model to obtain the question template of the question text to be enhanced. The first prompt text is used to prompt the first large model to analyze the field information and the question text to be enhanced to generate the question template of the question text to be enhanced.
[0028] The large model-based text-to-SQL (Text2SQL) data set construction method provided in the present application is applied to an electronic device, which may be a server, a PC, a mobile terminal, etc.
[0029] In order to improve the efficiency of constructing the Text2SQL dataset, in an embodiment of the present application, a large model can be used to generate a question template, so that the corresponding data can be filled in the question template later to obtain different question texts and achieve data enhancement.
[0030] In an embodiment of the present application, the question text to be enhanced, the first prompt text, and the field information included in the database can be spliced and input into the first large model to obtain a question template for the question text to be enhanced. Among them, the question text to be enhanced can be manually written and input into the electronic device, or it can be obtained from the Internet. The embodiment of the present application does not limit the acquisition method of the question text to be enhanced. Exemplarily, the question text to be enhanced can be uploaded to the electronic device after being written by a business person. The first prompt text is used to prompt the first large model to analyze the semantics of the field information and the question text to be enhanced, determine which or which word segments in the question text to be enhanced are similar to the semantics of the content recorded in the field information, determine the position of the similar word segmentation in the question text to be enhanced as the character area to be filled, and delete the corresponding word segmentation to obtain the question template of the question text to be enhanced. The first large model can be any large model with semantic analysis and understanding capabilities, that is, the first large model can be any large language model (Large Language Model, LLM). The field information records the data tables included in the database, as well as information such as the data table structure of each data table. In order to facilitate the understanding of the first model, the field information may also include text explaining each field.
[0031] Suppose that the question text to be enhanced is "Query how many drivers there are in Qingdao". Among them, the word "Qingdao" is similar in semantics to the content "place" in the field information, so the question template of the question text to be enhanced generated by the first model can be "Query how many drivers there are in {______}". The position corresponding to "{}" represents the character area to be filled. The character area to be filled included in the question template can be one or more. Subsequently, the field value can be filled in the position corresponding to "{}" to obtain the target question text.
[0032] S202: searching the field information for first field information corresponding to the character area to be filled in the question template; inputting the question template, the first field information and the second prompt text into the second large model to obtain an SQL template.
[0033] What is generally stored in the Text2SQL data set is a text-SQL statement pair. After obtaining the question template, the SQL template corresponding to the question template can be determined, so as to determine the target SQL statement based on the SQL template later. In an embodiment of the present application, the SQL template corresponding to the question template can be generated based on the second largest model. The second largest model can be the same as the first largest model or different. The embodiment of the present application does not limit this, and technicians in this field can configure it as needed. In order to make the second largest model know which field in the database the character area to be filled in the question template corresponds to, so as to generate the corresponding SQL template based on the field, in an embodiment of the present application, the first field information corresponding to the character area to be filled in the question template can be found in the field information. Since the question text to be enhanced is known, and the question template generated according to the question text to be enhanced is also known, then it can be determined by comparing the question text to be enhanced and the question template that the character area to be filled in the question template corresponds to the original content originally filled in the question text to be enhanced. After determining the original content, the subfield that matches the semantics of the original content can be found in the field information included in the database, so as to determine the subfield as the first field information.
[0034] After determining the first field information, the question template, the first field information and the second prompt text are input into the second largest model to obtain the SQL template. Among them, the second prompt text can be a text used to prompt the second largest model to generate an SQL statement corresponding to the question template. The second largest model can analyze the question template and the first field information according to the second prompt text to generate an SQL statement corresponding to the question template, and the generated SQL statement also includes a character area to be filled. In other words, the area that needs to be filled with content in the question template is also the area that needs to be filled with content in the generated SQL statement. Since the SQL statement generated by the second largest model also includes a character area to be filled, in the embodiment of the present application, the SQL statement generated by the second largest model can be called an SQL template.
[0035] S203: Determine the target field value corresponding to the first field information according to the pre-saved correspondence between different field information and field values, and fill the target field value into the question template and the SQL template to obtain the target question text and the target SQL statement.
[0036] After obtaining the question template and the SQL template, the corresponding target field values can be filled in the question template and the SQL template to obtain the target question text and the target SQL statement, which can be saved as a text-SQL statement pair in the Text2SQL dataset. The Text2SQL dataset can be used for model training later. Of course, the Text2SQL dataset can also be applied to other purposes, which is not limited in the present embodiment.
[0037] In the embodiment of the present application, the correspondence between different field information and field values can be pre-saved according to the field information included in the database. For example, the field value corresponding to the field information of "driving status" can be normal, transferred out, detained, locked, etc.; the field value corresponding to the field information of "driving license period" can be 6 years, 10 years, long-term, etc.; the field value corresponding to the field information of "location" can be Beijing, Shanghai, Qingdao, etc.
[0038] Since the first field information corresponding to the character area to be filled has been determined when the SQL template is generated, after the question template and the SQL template are obtained, the target field value corresponding to the first field information can be determined according to the correspondence between different field information and field values saved in advance. In other words, according to the first field information, it is determined which field values can be filled in the question template and the SQL template. Thus, the determined target field value is correspondingly filled into the question template and the SQL template to obtain the target question text and the target SQL statement.
[0039] Because in the embodiment of the present application, the question text to be enhanced, the first prompt text, and the field information included in the database are spliced and input into the first large model, so that the first large model analyzes the field information and the question text to be enhanced, thereby obtaining a question template of the question text to be enhanced, without the need to manually write the question template, and search the field information for the first field information corresponding to the character area to be filled in the question template, and input the question template, the first field information and the second prompt text into the second large model to obtain an SQL template, without the need to manually write an SQL template corresponding to the question template, and then determine the target field value corresponding to the first field information according to the correspondence between different field information and field values saved in advance, and fill the target field value into the question template and the SQL template accordingly, to obtain the target question text and the target SQL statement, and search the field information in the database for matching target field values and fill them into the question template and the SQL template, thereby realizing automatic data enhancement and improving the efficiency of data set construction.
[0040] For ease of understanding, an example of field information included in a database is given below. It should be noted that the following example is only for ease of understanding of this solution, and the content included in the field information is not limited to the following example:
[0041] Initial license issuance date, cclzrq. When counting the number of driver registrations based on time, the field values that can be selected include time ranges such as the previous three months, or a single time such as 2021.
[0042] Administrative division of registered residence, djzsxzqh. Enumeration values include: 132123: Quzhou County, Hebei Province; 411600: Zhoukou City, Henan Province; 610124: Zhouzhi County, Shaanxi Province; 612222: Zhouzhi County, Shaanxi Province; 412701: Zhoukou City, Henan Province, etc.
[0043] Issuing authority, fzjg. This field is used for screening when counting the changes in the number of driving licenses by region. For example, the rule for screening vehicles in Henan is: fzjg in('Yu P'). Enumeration values include: Yu P: Vehicle Management Office of Zhoukou Public Security Bureau, Henan Province; Liao E: Vehicle Management Detachment of Benxi Public Security Bureau Traffic Police, Liaoning Province; Yu A: Vehicle Management Office of Chongqing Public Security Bureau Traffic Police, etc.
[0044] Management department, glbm. Enumeration values include: 371322101248: Zhougaoce Village Committee; 371625103256: Xiangzhoucun Village Committee; 371082112000: Renhe Town; 371083104211: Shangce Village Committee; 370323105258: Zhoujiashangzhuang Village Committee, etc.
[0045] Driver's license term, jzqx. Enumeration values include: 5: old term; 4: old license; 1: 6-year term; 2: 10-year term; 3: long term.
[0046] Driver source, ly. Enumeration values include: A: local; E: foreign; C: transferred in; B: from other places; D: military and police; G: Macau, China; F: Hong Kong, China; I: embassy and consulate; H: Taiwan, China; J: agricultural machinery.
[0047] Personnel status, ryzt. Enumeration values include: 4: less than three years since the compulsory isolation drug rehabilitation measures were lifted; 2: undergoing drug treatment.
[0048] Gender, xb. Enumeration values include: 1: male; 2: female; 9: not specified.
[0049] Administrative division, xzqh. Enumeration values include: 132123: Quzhou County, Hebei Province; 350925: Zhouning County, Fujian Province; 411600: Zhoukou City, Henan Province; 610124: Zhouzhi County, Shaanxi Province; 612222: Zhouzhi County, Shaanxi Province, etc.
[0050] Permitted driving type, zjcx. Enumeration values include: P: tram, C: small car, F: light motorcycle, B1: medium-sized passenger car, B2: large truck, A2: tractor, C2: small automatic car, C3: low-speed truck, A1: large passenger car, E: two-wheeled motorcycle, D: three-wheeled motorcycle, C4: three-wheeled car, A3: city bus, etc.
[0051] Driving license status, zt. Enumeration values include: G: cancelled, R: cancelled but recoverable, B: 12 points, N: delayed renewal, M: overdue renewal, T: delayed inspection, K: seized, I: accident not handled, F: revoked, D: temporarily detained, P: delayed physical examination, H: violation not handled, U: detained, C: transferred out, S: overdue inspection, etc.
[0052] In order to further improve the efficiency of constructing the data set, based on the above embodiment, in the embodiment of the present application, the process in which the first large model analyzes the field information and the question text to be enhanced and generates a question template for the question text to be enhanced includes:
[0053] The first model determines each word in the question text to be enhanced as a word to be deleted if there is a subfield in the field information that matches the semantics of the word;
[0054] The position of at least one to-be-deleted word segment in the question text to be enhanced is determined as a character region to be filled, and the to-be-deleted word segment is deleted from the question text to be enhanced to obtain the question template.
[0055] Since the embodiment of the present application is to use the information of each field recorded in the database to perform data enhancement on the question text to be enhanced, when generating the question template, the first large model can determine which word or words in the question text to be enhanced to be deleted based on the content included in the field information of the database.
[0056] In an embodiment of the present application, when the first large model generates a question template, the first large model can determine whether there is a subfield in the received field information that matches the semantics of the participle for each participle in the question text to be enhanced. If so, it means that the position of the participle can be filled with the data in the field information, and the participle can be determined as a participle to be deleted. If not, the participle is not processed. It should be noted that since the large model has a powerful semantic analysis capability, how the first large model determines whether there is a subfield in the field information that matches the semantics of the participle is an internal processing mechanism of the first large model, and the embodiment of the present application does not limit this. The embodiment of the present application can limit how the first large model determines the question template by writing prompt words.
[0057] After the analysis of each word segment in the question text to be enhanced is completed, the first large model can randomly select at least one word segment to be deleted from all the determined words segment to be deleted. The position of the at least one word segment to be deleted in the question text to be enhanced is determined as the character area to be filled, and the word segment to be deleted is deleted from the question text to be enhanced, thereby obtaining a question template. In other words, the question template can include one or more character areas to be filled.
[0058] Specifically, assuming that the question text to be enhanced is "What is the highest temperature in Beijing today?", "Beijing", "today" and "temperature" in the question text to be enhanced are determined as participles to be deleted. If the randomly selected participle to be deleted is "today", then the resulting question template is "What is the highest temperature in Beijing {______}?"
[0059] In order to facilitate determining the first field information corresponding to the character area to be filled in the question template, on the basis of the above embodiments, in the embodiment of the present application, after deleting the to-be-deleted word segment in the to-be-enhanced question text and before obtaining the question template, the method further includes:
[0060] According to the semantics of the subfield matching the to-be-deleted word, an identification word is determined, and the to-be-filled character region corresponding to the to-be-deleted word is identified by using the identification word.
[0061] In order to facilitate the subsequent determination of the first field information corresponding to the character area to be filled in the question template, in an embodiment of the present application, after deleting the to-be-deleted participle in the to-be-enhanced question text and before obtaining the question template, an identification word corresponding to the to-be-deleted participle can also be obtained, so as to facilitate the subsequent determination of the first field information of the corresponding character area to be filled according to the identification word. Since the first large model knows which subfield in the field information the to-be-deleted participle matches when determining the to-be-deleted participle, the identification word can be determined according to the semantics of the matched subfield.
[0062] In a possible implementation, the field name corresponding to the matched sub-field may be obtained, and the field name may be determined as the identifier.
[0063] In a possible implementation, the semantics of the subfield can be analyzed, and an identifier can be obtained based on the semantic expansion obtained from the analysis. Exemplary, the subfield is "Date of initial license issuance, cclzrq. According to the time statistics of driver registrations, the field values that can be selected include time ranges such as the previous three months and single time such as 2021". According to the semantics, it can be known that the subfield is related to time, so the determined identifier can be "time", "time range", etc.
[0064] After the identification word is determined, the identification word can be used to identify the character region to be filled corresponding to the word to be deleted.
[0065] Specifically, assuming that the question text to be enhanced is "Query how many people in Qingdao received a driver's license last month", the participle "last month" matches the subfield "Initial license date, cclzrq. According to the time statistics of driver registration volume, the field values that can be selected include time ranges such as the previous three months and single times such as 2021" in the field information. Among them, "Initial license date, cclzrq" represents the field value corresponding to the subfield, and "According to the time statistics of driver registration volume, the field values that can be selected include time ranges such as the previous three months and single times such as 2021" means that when the question text to be enhanced is to count the driver registration volume based on time, the field value that can be selected can be a time range, for example, the previous three months, or a single time, such as 2021. Then, after deleting the participle "last month" in the question text to be enhanced, "Initial license date" can be determined as an identifier, and the identifier is used to identify the character area to be filled corresponding to the participle to obtain a question template. The resulting question template may be “Query how many people have obtained a driver's license in Qingdao {first license date}”, where the position of “{first license date}” is the character area to be filled.
[0066] In an embodiment of the present application, the first large model can also be expanded to obtain an identifier based on the semantics of the content included in the matched subfield. For example, according to the above subfield semantics, the subfield is related to time, so the identifier obtained by the expansion of the first large model can be time or time range, and the obtained question template can be "Query how many people in Qingdao have received a driver's license at {time}", where "{time}" is located as the character area to be filled. It can also be "Query how many people in Qingdao have received a driver's license at {time range}", where "{time range}" is located as the character area to be filled.
[0067] In order to ensure the diversity of data in the constructed data set, based on the above embodiments, in the embodiment of the present application, the method further includes:
[0068] Determining a supplementary word according to the semantics of the question template and the semantics of each subfield in the field information;
[0069] Based on the semantics of the question template, a character region to be filled in the question template is added, and the added character region to be filled is identified by using the supplementary word.
[0070] In order to ensure the diversity of data in the constructed data set, when determining the question template, the first large model can also add other character areas to be filled in the question template according to the semantics of the question template and each subfield in the field information. In an embodiment of the present application, after obtaining the question template, the first large model can also analyze the semantics of the question template and the semantics of each subfield in the field information to determine which subfield information in the field information can exist in the question template, but the character area to be filled corresponding to the information of the subfield does not exist in the current question template. Among them, the information of the subfield can exist in the question template, which can be understood as adding the field value of the corresponding subfield to the appropriate position of the question template, and the semantic fluency of the latest question template can still be guaranteed. For example, the question template is "query {time} temperature", usually, when asking about the temperature at a certain time, a specific place is generally asked, and the question template does not include the place. Assume that the field information includes subfields related to the place. Then, when the first large model analyzes the semantics of the question template and the field information, "place" can be determined as a supplementary word.
[0071] After the supplementary word is determined, the character region to be filled in the question template can be increased based on the semantics of the question template, and the increased character region to be filled can be identified using the supplementary word. That is, according to the semantics of the question template, it is determined to which position of the question template the character region to be filled corresponding to the supplementary word is added.
[0072] Specifically, assuming that the question text to be enhanced is "Query how many drivers transferred in last month", the question template for the question text to be enhanced generated by the first model can be "Query how many drivers of {driver source} there are at {time}?". After analyzing the semantics of the question template, the first model believes that the supplementary word "administrative division location" can also be added to the question template. Then, the first model can expand the area to be filled in according to the semantics of the question template. The final question template can be "Query how many {driver source} there are at {time} {administrative division location}".
[0073] It should be noted that the first model can generate one question template or multiple different question templates based on a question text to be enhanced.
[0074] To enable the first large model to determine the question template for output as expected, in the embodiments of the present application, the first large model can be prompted to determine the idea of the question template by means of prompt words. In the embodiments of the present application, the first prompt text may also include examples of question template generation, enabling the first large model to learn the generation idea of the question template. In the embodiments of the present application, the question text to be enhanced can be concatenated with the following example prompt words and then input into the first large model. The example prompt words include the first prompt text and the field information in the database. The example prompt words can be:
[0075] ## You are an expert in generating question templates. Now the task is to ask questions about the driver's information based on the input example sentences, generate questions containing templates, and the return value must be a complete sentence with expandable templates. Do not explain the templates {}.
[0076] # The template information to be generated can only refer to the following field information and cannot be fabricated out of thin air:
[0077] Initial license issuance date, cclzrq. When counting the number of driver registrations according to time, the selected field values can include time ranges such as the previous three months or a single time such as 2021.
[0078] Registered residence administrative division, djzsxzqh. Enumeration values include: 132123: Quzhou County, Hebei Province; 411600: Zhoukou City, Henan Province; 610124: Zhouzhi County, Shaanxi Province; 612222: Zhouzhi County, Shaanxi Province; 412701: Zhoukou City, Henan Province, etc.
[0079] Issuing authority, fzjg. This field is used for screening when counting the number of driver's license changes by region. For example, the rule for screening vehicles in Henan is: fzjg in('Yu P'). Enumeration values include: Yu P: Vehicle Management Office of Zhoukou Public Security Bureau, Henan Province; Liao E: Vehicle Management Office of Benxi Public Security Bureau Traffic Police Detachment, Liaoning Province; Yu A: Vehicle Management Office of Chongqing Public Security Bureau Traffic Police Administration, etc.
[0080] Management department, glbm. Enumeration values include: 371322101248: Zhougaoce Village Committee; 371625103256: Xiangzhoucun Village Committee; 371082112000: Renhe Town; 371083104211: Shangce Village Committee; 370323105258: Zhoujiashangzhuang Village Committee, etc.
[0081] Driver's license term, jzqx. Enumeration values include: 5: old term; 4: old license; 1: 6-year term; 2: 10-year term; 3: long term.
[0082] Driver origin, ly. Enumeration values include: A: local, E: foreign, C: transferred, B: other places, D: military and police, G: Macau, China, F: Hong Kong, China, I: embassy and consulate, H: Taiwan, China, J: agricultural machinery.
[0083] Personnel status, ryzt. Enumeration values include: 4: less than three years after the compulsory isolation and detoxification measures were lifted, 2: undergoing detoxification treatment.
[0084] Gender, xb. Enumeration values include: 1: male, 2: female, 9: unspecified.
[0085] Administrative division, xzqh. Enumeration values include: 132123: Quzhou County, Hebei Province, 350925: Zhouning County, Fujian Province, 411600: Zhoukou City, Henan Province, 610124: Zhouzhi County, Shaanxi Province, 612222: Zhouzhi County, Shaanxi Province, etc.
[0086] Permitted driving type, zjcx. Enumeration values include: P: tram, C: small car, F: light motorcycle, B1: medium-sized passenger car, B2: large truck, A2: tractor, C2: small automatic car, C3: low-speed truck, A1: large passenger car, E: two-wheeled motorcycle, D: three-wheeled motorcycle, C4: three-wheeled car, A3: city bus, etc.
[0087] Driving license status, zt. Enumeration values include: G: cancelled, R: cancelled but recoverable, B: 12 points, N: delayed renewal, M: overdue renewal, T: delayed inspection, K: seized, I: accident not handled, F: revoked, D: temporarily detained, P: delayed physical examination, H: violation not handled, U: detained, C: transferred out, S: overdue inspection, etc.
[0088] ##When there are synonyms or near-synonyms in the question, they need to be replaced with standard enumeration values in the corresponding fields.
[0089] ##Refer to the intent of the user's input sentence and output 3 templates with similar intents.
[0090] ##Refer to the following example for output:
[0091] Example 1:
[0092] User input: Check how many transferred drivers there are in Qingdao.
[0093] Output: [Query {first license date} how many drivers are {driver source};
[0094] Check how many drivers there are from {driver source} in {administrative division};
[0095] Check how many drivers in {administrative division} are {driver source} and are allowed to drive {allowed driving type}.]
[0096] Example 2:
[0097] User input: Which district in Qingdao had the smallest increase in drivers’ license revoked last year?
[0098] Output: [Check {time range} {issuing authority} which district {driver status} has the least increase in drivers;
[0099] Check {time} {issuing authority} which district has the least increase in {driver source} drivers;
[0100] Check the {issuing authority} for which district has the least increase in {driver license expiration date}.]
[0101] It should be noted that the above example prompt words are only provided for ease of understanding and do not mean that the example prompt words are limited thereto. Those skilled in the art may configure them as needed.
[0102] Assume that the question template is "Query how many drivers of {driver source} are there at {time} {issuing authority}";
[0103] The first field information is "{"cclzrq":"{time}","fzjg":"{issuing authority}","ly":"{driver source}"}". Among them, "cclzrq", "fzjg", and "ly" represent the recording method of the corresponding fields in the database, that is, the field names recorded in the database. "cclzrq" represents the date of first license issuance, "fzjg" represents the issuing authority, and "ly" represents the driver source.
[0104] Based on the above question template and the first field information, the SQL template generated by the second largest model can be:
[0105] SELECT count(v.xh)FROM drivinglicense v JOIN frm_code t1 ON REGEXP_LIKE(v.ly,t1.dmz)JOIN frm_codetype t1_1ON t1.dmlb=t1_1.dmlb JOIN frm_code t2ON REGEXP_LIKE(v.fzjg,t2.dmz)JOIN frm_codetype t2_1ON t2.dmlb=t2_1.dmlbWHERE t1_1.xtlb='02'AND t1_1.lbsm='Driver source'AND t1.dmsm1 LIKE'%{Driver source}%'AND t2_1.xtlb='00'AND t2_1.lbsm='Vehicle administration office code'AND t2.dmsm1 LIKE'%{Issuing authority}%'AND to_char(v.cclzrq,'{time format}') = '{time}'.
[0106] Among them, "drivinglicense", "frm_code", and "frm_codetype" represent different data tables respectively; "%{driver source}%", "%{issuing authority}%", and "{time}" represent the character areas to be filled.
[0107] In order to make the second largest model output the determined SQL template as expected, in an embodiment of the present application, the second largest model can be prompted to determine the SQL template by means of prompt words. In an embodiment of the present application, the second prompt text can also include an SQL template determination sample, so that the second largest model can learn the determination idea of the SQL template. In an embodiment of the present application, the question template can be spliced with the following example prompt words and input into the second largest model. The example prompt words include the second prompt text, the field information in the database, and the determined first field information. The example prompt words can be:
[0108] ##You are a database expert. Your task now is to generate the corresponding SQL statement based on the user input question. The \{\} in the user input is the template content, and the template should also be marked with \{\} in the output SQL statement. The database data table and related fields are defined as follows:
[0109] Date of first license issuance, cclzrq. Driver registration statistics based on time. The field values that can be selected include time ranges such as the previous three months and single time such as 2021.
[0110] Registered residence administrative division, djzsxzqh. Enumeration values include: 132123: Quzhou County, Hebei Province; 411600: Zhoukou City, Henan Province; 610124: Zhouzhi County, Shaanxi Province; 612222: Zhouzhi County, Shaanxi Province; 412701: Zhoukou City, Henan Province, etc.
[0111] Issuing authority, fzjg. This field is used for filtering when statistically analyzing the changes in driver's licenses by region. For example, the rule for filtering vehicles in Henan is: fzjg in('Yu P'). Enumeration values include: Yu P: Vehicle Management Office of Zhoukou Public Security Bureau, Henan Province; Liao E: Vehicle Management Office of Benxi Public Security Bureau Traffic Police Detachment, Liaoning Province; Yu A: Vehicle Management Office of Chongqing Public Security Bureau Traffic Police Administration, etc.
[0112] Administrative department, glbm. Enumeration values include: 371322101248: Zhougaoce Village Committee; 371625103256: Xiangzhoucun Village Committee; 371082112000: Renhe Town; 371083104211: Shangce Village Committee; 370323105258: Zhoujiashangzhuang Village Committee, etc.
[0113] Driver's license term, jzqx. Enumeration values include: 5: Old term; 4: Old license; 1: 6-year term; 2: 10-year term; 3: Long term.
[0114] Driver source, ly. Enumeration values include: A: Local; E: Foreign; C: Transferred in; B: From other places; D: Military and police; G: Macau, China; F: Hong Kong, China; I: Embassy; H: Taiwan, China; J: Agricultural machinery.
[0115] Personnel status, ryzt. Enumeration values include: 4: Less than three years since the compulsory isolation drug rehabilitation measures were lifted; 2: Undergoing drug treatment.
[0116] Gender, xb. Enumeration values include: 1: Male; 2: Female; 9: Not specified.
[0117] Administrative division, xzqh. Enumeration values include: 132123: Quzhou County, Hebei Province; 350925: Zhouning County, Fujian Province; 411600: Zhoukou City, Henan Province; 610124: Zhouzhi County, Shaanxi Province; 612222: Zhouzhi County, Shaanxi Province, etc.
[0118] Authorized driving models, zjcx. Enumeration values include: P: Tram; C: Small car; F: Moped; B1: Medium-sized bus; B2: Large truck; A2: Tractor; C2: Small automatic car; C3: Low-speed truck; A1: Large bus; E: Two-wheeled motorcycle; D: Three-wheeled motorcycle; C4: Three-wheeled vehicle; A3: City bus, etc.
[0119] Driving license status, zt. Enumeration values include: G: cancelled, R: cancelled but recoverable, B: 12 points, N: delayed renewal, M: overdue renewal, T: delayed inspection, K: seized, I: accident not handled, F: revoked, D: temporarily detained, P: delayed physical examination, H: violation not handled, U: detained, C: transferred out, S: overdue inspection, etc.
[0120] ##SQL generation: SQL statements should be generated even when there is no extra explanation, no inquiry, no supplement, or no specific information.
[0121] ##Pay special attention that the fields in the generated SQL must exist in the data table.
[0122] ##**Always remember that the output must be a SQL statement**.
[0123] ##Refer to the following example for output:
[0124] Example 1:
[0125] User input: Question "Query how many drivers of {driver source} there are at {time} {issuing authority}". When generating SQL, refer to the following content, where the fields corresponding to the slots are {"cclzrq":"{time}","fzjg":"{issuing authority}","ly":"{driver source}"}.
[0126] Output: "SELECT count(v.xh) FROM drivinglicense v JOIN frm_codet1 ON REGEXP_LIKE(v.RYZT,t1.dmz) JOIN frm_codetype t1_1ON t1.dmlb=t1_1.dmlb JOIN frm_code t2 ON REGEXP_LIKE(v.fzjg,t2.dmz) JOIN frm_codetypet2_1ON t2.dmlb=t2_1.dmlb WHERE t1_1.xtlb='02' AND t1_1.lbsm='driver source' AND t1.dmsm1 LIKE '%{driver source}%' and t2_1.xtlb='00' AND t2_1.lbsm = 'Vehicle Administration Office Code'\n AND t2.dmsm1 LIKE '%{Issuing Authority}%'\n AND to_char(v.cclzrq,'{Time Format}') = '{Time}'".
[0127] In order to accurately generate an SQL template, based on the above embodiments, in an embodiment of the present application, searching the field information for the first field information corresponding to the character area to be filled in the question template includes:
[0128] Input the question template, the field information and the third prompt text into the third model, so that the third model searches for a target field name that matches a keyword identified in the to-be-filled character area in the question template in the field information according to the prompt of the third prompt text, and determines the target field name as the first field information; the keyword includes an identification word and a supplementary word;
[0129] The determining, according to the pre-stored correspondence between different field information and field values, a target field value corresponding to the first field information includes:
[0130] Obtaining, in the pre-saved correspondence between different field information and field values, each field value saved for the first field information;
[0131] Randomly select any field value from each field value as the target field value.
[0132] Since the identification words and supplementary words that identify the character area to be filled in the problem template may not be the field names used in the database, if the subsequent second largest model generates an SQL template based on the identification words and supplementary words, the generated SQL template is also inaccurate. Therefore, in order to ensure the accuracy of the generated SQL template, in the embodiment of the present application, when determining the first field information corresponding to the character area to be filled, the third largest model can be used for determination. The third largest model can be the same as the first largest model and the second largest model, or it can be different.
[0133] In the embodiment of the present application, the question template, the field information and the third prompt text can be input into the third large model, so that the third large model searches the field information for a target field name that matches the keyword identified in the character area to be filled in the question template according to the prompt of the third prompt text. In other words, the target field name corresponding to the identification word and the supplementary word in the database is determined. After the target field name is determined, the target field name can be determined as the first field information.
[0134] Specifically, assume that the question template is "Query how many drivers from {driver source} are there in {time} at the {issuing authority}", and the output of the third largest model can be "{"cclzrq":"{time}","fzjg":"{issuing authority}","ly":"{driver source}"}". Among them, "cclzrq":"{time}" means that the first field information corresponding to the character area to be filled marked as "{time}" in the question template is cclzrq; "fzjg":"{issuing authority}" means that the first field information corresponding to the character area to be filled marked as "{issuing authority}" in the question template is fzjg; "ly":"{driver source}" means that the first field information corresponding to the character area to be filled marked as "{driver source}" in the question template is ly.
[0135] In order to enable the third largest model to determine the question template according to the expected output, in the embodiments of the present application, the third largest model can be prompted to determine the first field information by means of prompt words. In the embodiments of the present application, the third prompt text may further include an example of determining the first field information, so that the third largest model can learn the determination idea of the first field information. In the embodiments of the present application, the question template can be concatenated with the following example prompt words and then input into the third largest model. The example prompt words include the third prompt text and the field information in the database. The example prompt words can be:
[0136] ##You are a slot extraction expert. Now the task is to extract slots from the user input sentence and standardize the extracted values. The return value format must be JSON, without explanation.
[0137] ##The slot information to be extracted is as follows:
[0138] Initial license date, cclzrq. When counting the driver registration volume according to time, the selected field values can include time ranges such as the previous three months, and single times such as 2021.
[0139] Administrative division of registered residence, djzsxzqh. Enumeration values include: 132123: Quzhou County, Hebei Province, 411600: Zhoukou City, Henan Province, 610124: Zhouzhi County, Shaanxi Province, 612222: Zhouzhi County, Shaanxi Province, 412701: Zhoukou City, Henan Province, etc.
[0140] Issuing authority, fzjg. This field is used for screening when counting the changes in driver's licenses by region. For example, the rule for screening vehicles in Henan is: fzjg in('Yu P'), and the enumeration values include: Yu P: Vehicle Management Office of Zhoukou Public Security Bureau, Henan Province, Liao E: Vehicle Management Office of Benxi Public Security Bureau Traffic Police Detachment, Liaoning Province, Yu A: Vehicle Management Office of Chongqing Public Security Bureau Traffic Police Administration, etc.
[0141] Management department, glbm. Enumeration values include: 371322101248: Zhougaoce Village Committee, 371625103256: Xiangzhou Village Committee, 371082112000: Renhe Town, 371083104211: Shangce Village Committee, 370323105258: Zhoujiashangzhuang Village Committee, etc.
[0142] Driving license expiration, jzqx. Enumeration values include: 5: old expiration, 4: old license, 1: 6-year period, 2: 10-year period, 3: long-term.
[0143] Driver origin, ly. Enumeration values include: A: local, E: foreign, C: transferred, B: other places, D: military and police, G: Macau, China, F: Hong Kong, China, I: embassy and consulate, H: Taiwan, China, J: agricultural machinery.
[0144] Personnel status, ryzt. Enumeration values include: 4: less than three years after the compulsory isolation and detoxification measures were lifted, 2: undergoing detoxification treatment.
[0145] Gender, xb. Enumeration values include: 1: male, 2: female, 9: unspecified.
[0146] Administrative division, xzqh. Enumeration values include: 132123: Quzhou County, Hebei Province, 350925: Zhouning County, Fujian Province, 411600: Zhoukou City, Henan Province, 610124: Zhouzhi County, Shaanxi Province, 612222: Zhouzhi County, Shaanxi Province, etc.
[0147] Permitted driving type, zjcx. Enumeration values include: P: tram, C: small car, F: light motorcycle, B1: medium-sized passenger car, B2: large truck, A2: tractor, C2: small automatic car, C3: low-speed truck, A1: large passenger car, E: two-wheeled motorcycle, D: three-wheeled motorcycle, C4: three-wheeled car, A3: city bus, etc.
[0148] Driving license status, zt. Enumeration values include: G: cancelled, R: cancelled but recoverable, B: 12 points, N: delayed renewal, M: overdue renewal, T: delayed inspection, K: seized, I: accident not handled, F: revoked, D: temporarily detained, P: delayed physical examination, H: violation not handled, U: detained, C: transferred out, S: overdue inspection, etc.
[0149] ##The target field name of the return value must be one of the above fields. Do not make it up out of thin air.
[0150] ##The West Coast New District that appears in the user's sentence needs to be converted to Huangdao District.
[0151] ##Standardizes mapping of extracted user terms to values in the field enumeration value.
[0152] ##Refer to the following example for output:
[0153] Example 1:
[0154] User input: Query how many drivers of {driver source} there are at {time} {issuing authority}.
[0155] Output: {"cclzrq":"{time}","fzjg":"{issuing authority}","ly":"{driver source}"}.
[0156] Example 2:
[0157] User input: Check {time range} {administrative division location} which district has the least increase in {driver status}.
[0158] Output: {"cclzrq":"{time range}","xzqh":"{administrative division location}","zt":"{driver status}"}.
[0159] It should be noted that the above example prompt words are only provided for ease of understanding and do not mean that the example prompt words are limited thereto. Those skilled in the art may configure them as needed.
[0160] Since a field name in the database may have multiple field values, when determining the target field value corresponding to the first field information, the correspondence between different field information and field values saved in advance can be obtained, and each field value saved for the first field information can be randomly selected from all the field values as the target field value. In other words, when determining which target field value to use to fill the template, the selected strategy is random, which can ensure the diversity of the target question text and target SQL statement as much as possible. For example, if there are 10 field values saved corresponding to a certain first field information, then at least 10 target questions and target SQL statements can be generated based on these 10 field values.
[0161] In order to further ensure the accuracy of the data in the data set, on the basis of the above embodiments, in the embodiment of the present application, the correspondence between the pre-saved different field information and the field value stores a text description and a code description for any field information;
[0162] The step of filling the target field value into the question template and the SQL template to obtain a target question text and a target SQL statement includes:
[0163] Fill the text description of the target field value into the question template to obtain the target question text;
[0164] The code description of the target field value is filled into the SQL template accordingly to obtain the target SQL statement.
[0165] Since the question text is generally filled with text, and the SQL statement is generally filled with a code identifier, the correspondence between different field information and field values saved in advance stores text descriptions and code descriptions for any field information. In other words, the correspondence between different field information and field values saved in advance can be in the form of key-value. For example, the correspondence stored for the field information of gender can be "gender, xb, enumeration values include: 1: male, 2: female, 9: unspecified", where "gender, xb" means that the field name of gender is represented by the code "xb" in the data table, "gender" is a text description, and "xb" is a code description. All field values corresponding to the field name of gender can be male, female, and unspecified. "1: Male" means that the value of the male field is represented by the code "1" in the data table, "male" is a text description, and "1" is a code description; "2: Female" means that the value of the female field is represented by the code "2" in the data table, "female" is a text description, and "2" is a code description; "9: Unspecified" means that the value of the unspecified field is represented by the code "9" in the data table, "unspecified" is a text description, and "9" is a code description. In the embodiment of the present application, value represents an operator, that is, a code description used in the data table, and key represents the natural language expression of value, that is, a text description, such as "gender", "male", "female", etc. in the above examples.
[0166] In one possible implementation, the correspondence between different pre-saved field information and field values may be saved in a data dictionary. For example, each field and the corresponding field value are saved in a data dictionary, and the first field information is subsequently determined in the data dictionary. In other words, the data contained in the database can be defined and described through the data dictionary, and all descriptive information constitutes the entire content of the data dictionary. The data dictionary provides a basis for converting text into SQL statements. Exemplarily, the data dictionary can be saved in the following example format, and the field values corresponding to different field names can be recorded in the data dictionary, and each field value uses the key-value record format:
[0167] "Driving license period": {"6 years": ["1"], "10 years": ["2"], "Long term": ["3"], "Old license": ["4"], "Old period": ["5"]};
[0168] “Driving License Status”: {“Normal”: [“A”], “12 points or more”: [“B”], “Transfer out”: [“C”], “Temporarily detained”: [“D”], “Revoked”: [“E”], “Suspended”: [“F”], “Cancelled”: [“G”], “Unhandled violation”: [“H”], “Unhandled accident”: [“I”], “Stop using”: [“J”], “Seized”: [“K”], “Locked”: [“L”], “Overdue for renewal”: [“M”], “Deferred for renewal”: [“N”], “Deferred for physical examination”: [“P”], “Cancellation can be restored”: [“R”], “Overdue for inspection”: [“S”], “Deferred for inspection”: [“T”], “Detained”: [“U”]}.
[0169] The field values corresponding to "driving license period" in the above data dictionary may include: 6-year period, 10-year period, long-term, old license, old period, among which "6-year period" can be represented by "1", "10-year period" can be represented by "2", "long-term" can be represented by "3", "old license" can be represented by "4", and "old period" can be represented by "5". The field values corresponding to "driving license status" may include: normal, full 12 points, transferred out, temporarily detained, revoked, revoked, cancelled, violation not handled, accident not handled, stop using, detained, locked, overdue license renewal, delayed license renewal, delayed physical examination, cancellation can be restored, overdue inspection, delayed inspection, detained, etc. Among them, "normal" can be represented by "A", "full 12 points" can be represented by "B", "transfer out" can be represented by "C", "temporary seizure" can be represented by "D", "revocation" can be represented by "E", "suspension" can be represented by "F", "cancellation" can be represented by "G", "unhandled violation" can be represented by "H", "unhandled accident" can be represented by "I", "stop using" can be represented by "J", "seizure" can be represented by "K", "locked" can be represented by "L", "overdue renewal" can be represented by "M", "deferred physical examination" can be represented by "P", "cancellation can be restored" can be represented by "R", "overdue inspection" can be represented by "S", "deferred inspection" can be represented by "T", and "detention" can be represented by "U".
[0170] When the target field value is filled into the question template and the SQL template to obtain the target question text and the target SQL statement, the text description of the target field value can be filled into the corresponding position of the question template to obtain the target question text. The code description of the target field value can be filled into the corresponding position of the SQL template to obtain the target SQL statement.
[0171] In order to further improve the accuracy of data set construction, based on the above embodiments, in the embodiment of the present application, after generating the question template of the question text to be enhanced, before searching the field information for the first field information corresponding to the character area to be filled in the question template, the method further includes:
[0172] Determining the semantic similarity between the question text to be enhanced and the question template;
[0173] If the semantic similarity meets the preset threshold requirement, then continue to perform the subsequent step of searching the field information for the first field information corresponding to the character area to be filled in the question template;
[0174] If the semantic similarity does not meet the preset threshold requirement, the question template is deleted.
[0175] If data enhancement is performed based on an incorrect question template, the enhanced data obtained must also be incorrect. Therefore, in an embodiment of the present application, after obtaining the question template of the question text to be enhanced, before searching the field information for the first field information corresponding to the character area to be filled in the question template, the accuracy of the question template can also be verified. In an embodiment of the present application, the semantic similarity between the question text to be enhanced and the question template can be determined. When determining the semantic similarity, the semantic feature vectors between the question text to be enhanced and the question template can be determined based on a pre-trained semantic feature extraction model, and then the semantic similarity between the two semantic feature vectors can be calculated. The semantic similarity between the question text to be enhanced and the question template can also be directly determined based on a pre-trained similarity comparison model. The semantic similarity between the question text to be enhanced and the question template can also be determined based on a large language model, i.e., a large model.
[0176] After the semantic similarity is determined, it can be determined whether the semantic similarity meets a preset threshold requirement.
[0177] If so, it means that the question template generated by the first large model is accurate, and the subsequent step of searching the field information for the first field information corresponding to the character area to be filled in the question template can be continued.
[0178] If not, it means that the semantics of the question template generated by the first large model deviates greatly from the semantics of the question text to be enhanced, which indirectly indicates that the accuracy of the question template generated by the first large model is low. Therefore, the question template can be deleted.
[0179] Specifically, assuming that the preset threshold is 0.8, the semantic similarity between the question text to be enhanced and the question template is determined to be 0.76. Since the semantic similarity 0.76 is less than the preset threshold 0.8, it can be determined that the semantic similarity does not meet the preset threshold requirement, and the question template can be deleted.
[0180] Assume that the preset threshold is 0.8. The semantic similarity between the question text to be enhanced and the question template is determined to be 0.98. Since the semantic similarity of 0.98 is greater than the preset threshold of 0.8, it can be determined that the semantic similarity meets the preset threshold requirement, and then the subsequent step of searching the field information for the first field information corresponding to the character area to be filled in the question template can be continued.
[0181] It should be noted that the preset threshold value can be any value, and technicians in this field can configure it as needed, and the embodiments of the present application are not limited to this.
[0182] In order to further improve the accuracy of data set construction, based on the above embodiments, in the embodiment of the present application, before the question text to be enhanced, the first prompt text, and the field information included in the database are spliced and input into the first large model, the method also includes:
[0183] Acquire domain knowledge corresponding to the target domain to which the question text to be enhanced belongs, wherein the domain knowledge includes exclusive nouns and their corresponding explanation texts;
[0184] splicing the question text to be enhanced, the fourth prompt text and the domain knowledge and inputting them into the fourth model, so that the fourth model updates the exclusive nouns in the question text to be enhanced using the explanation texts corresponding to the exclusive nouns according to the prompt of the fourth prompt text, when the question text to be enhanced includes the exclusive nouns, to obtain a standard text;
[0185] The question text to be enhanced is updated using the standard text.
[0186] Since some specific fields have some exclusive domain knowledge, the large model may not have learned these domain knowledge during the training process. Therefore, in an embodiment of the present application, before using the first large model to generate a question template, the fourth large model can also be used to replace some domain knowledge.
[0187] Since the fields to which the constructed data set can be applied are known in advance, in the embodiments of the present application, corresponding field knowledge can be saved for different fields. For example, the field knowledge in the driving field can be: key drivers refer to drivers who are allowed to drive [large passenger vehicles|tractors|city buses|medium-sized passenger vehicles|large trucks]. Among them, "key drivers" is an exclusive noun, and "refers to drivers who are allowed to drive [large passenger vehicles|tractors|city buses|medium-sized passenger vehicles|large trucks]" is the explanatory text corresponding to the exclusive noun. In other words, field knowledge includes exclusive nouns and their corresponding explanatory texts.
[0188] In an embodiment of the present application, the domain knowledge corresponding to the target domain to which the question text to be enhanced belongs can be obtained. The question text to be enhanced, the fourth prompt text and the domain knowledge are spliced and input into the fourth model, so that the fourth model uses the explanation text corresponding to the exclusive noun to update the exclusive noun in the question text to be enhanced according to the prompt of the fourth prompt text, when the question text to be enhanced includes exclusive nouns, to obtain the standard text. After obtaining the standard text, the standard text can be used to update the question text to be enhanced, that is, the obtained standard text is determined as the text problem to be enhanced, and the Text2SQL data set is subsequently constructed based on the standard text.
[0189] In order to make the fourth model output the standard text as expected, in the embodiment of the present application, the fourth model can be prompted to determine the standard text by means of prompt words. In the embodiment of the present application, the fourth prompt text can also include a confirmed example of the standard text, so that the fourth model can learn the determination idea of the standard text. In the embodiment of the present application, the problem text to be enhanced can be spliced with the following example prompt words and then input into the fourth model. The example prompt words include the fourth prompt text and domain knowledge. The example prompt words can be:
[0190] ##You are an expert in the field of transportation. Your current task is to pre-process the domain knowledge in the input example sentences and convert them into specific field value information that can be queried. Do not explain them.
[0191] #The field information that may be involved in domain knowledge is as follows, and it cannot be created out of thin air:
[0192] Permitted driving type, zjcx. Enumeration values include: P: tram, C1: small car, F: light motorcycle, B1: medium-sized passenger car, B2: large truck, A2: tractor, C2: small automatic car, C3: low-speed truck, A1: large passenger car, E: two-wheeled motorcycle, D: three-wheeled motorcycle, C4: three-wheeled car, A3: city bus, etc.
[0193] Driving license status, zt. Enumeration values include: G: cancelled, R: cancelled but recoverable, B: 12 points, N: delayed renewal, M: overdue renewal, T: delayed inspection, K: seized, I: accident not handled, F: revoked, D: temporarily detained, P: delayed physical examination, H: violation not handled, U: detained, C: transferred out, S: overdue inspection, etc.
[0194] #The domain knowledge that can be referenced is as follows, and it cannot be created out of thin air:
[0195] Key drivers refer to drivers who are allowed to drive [large passenger vehicle|tractor|city bus|medium-sized passenger vehicle|large truck].
[0196] The number of drivers refers to the number of drivers whose driver's license status is not in [canceled|accumulated 12 points|revoked|detained|transferred].
[0197] ##When there are synonyms or near-synonyms in the question, they need to be replaced with standard enumeration values in the corresponding fields.
[0198] ##Refer to the following example for output:
[0199] Example 1:
[0200] User input: Check how many key drivers there are in Qingdao.
[0201] Output: Check how many drivers are there in Qingdao who are qualified to drive [large passenger car|tractor|city bus|medium-sized passenger car|large truck].
[0202] Example 2:
[0203] User input: How many drivers are there in Qingdao?
[0204] Output: Check how many drivers in Qingdao have their driver's license status not in [canceled|accumulated 12 points|revokated|detained|transferred].
[0205] In order to further improve the accuracy of data set construction, based on the above embodiments, in the embodiment of the present application, the method further includes:
[0206] The fifth prompt text, the field information, and the target question text and / or the target SQL statement are input into the fifth large model, so that the fifth large model analyzes the syntax and logic of the target question text and / or the target SQL statement according to the prompt of the fifth prompt text, and corrects the target question text and / or the target SQL statement if there are errors in the syntax or logic.
[0207] Since the target question text and target SQL statement are obtained by directly filling in the target field values in the question template and SQL template, it is very likely that there are grammatical or logical errors in the obtained target question text and target SQL statement. In order to ensure that the target question text and target SQL statement stored in the data set are correct, in an embodiment of the present application, after the target question text and target SQL statement are determined, the target question text and target SQL statement can be corrected. When making corrections, the grammar of the target question text and target SQL statement can be corrected based on the fourth model. In an embodiment of the present application, the fifth prompt text, field information, and the target question text and / or target SQL statement can be input into the fifth model, so that the fifth model analyzes the grammar and logic of the target question text and / or target SQL statement according to the prompt of the fifth prompt text, and corrects the target question text and / or target SQL statement in the event of grammatical or logical errors. In an embodiment of the present application, the target question text and the target SQL statement can be input into the fourth model together with the fifth prompt text and field information, or the target question text and the target SQL statement can be combined with the fifth prompt text and field information respectively and input into the fourth model respectively, so that the fourth model can modify the target question text and the target SQL statement respectively.
[0208] Exemplarily, when the grammar of the target question text is corrected using the fourth model, the target question text can be spliced and combined with the prompt text of the following example and then input into the fourth model. The prompt text of the following example includes the fifth prompt text and field information:
[0209] ##You are a statement rewriting expert. Your current task is to check and correct the input statements and output the correct statements.
[0210] #Correct existing grammatical errors, incorrect sentences, etc.
[0211] #The field values involved in standardization need to be selected from the fields provided below.
[0212] #The template information that needs to be generated can only refer to the following field information and cannot be created out of thin air:
[0213] Date of first license issuance, cclzrq. Driver registration statistics based on time. The field values that can be selected include time ranges such as the previous three months and single time such as 2021.
[0214] Administrative division of registered residence, djzsxzqh. Enumeration values include: 132123: Quzhou County, Hebei Province, 411600: Zhoukou City, Henan Province, 610124: Zhouzhi County, Shaanxi Province, 612222: Zhouzhi County, Shaanxi Province, 412701: Zhoukou City, Henan Province, etc.
[0215] Issuing authority, fzjg. This field is used for filtering when counting the changes in driver's licenses by region. For example, the rule for filtering vehicles in Henan is: fzjg in('Yu P'). The enumerated values include: Yu P: Vehicle Management Office of Zhoukou Public Security Bureau, Henan Province; Liao E: Vehicle Management Office of Benxi Traffic Police Detachment, Liaoning Province; Yu A: Vehicle Management Office of Chongqing Traffic Police Administration, etc.
[0216] Administrative department, glbm. The enumerated values include: 371322101248: Zhougaoce Village Committee; 371625103256: Xiangzhoucun Village Committee; 371082112000: Renhe Town; 371083104211: Shangce Village Committee; 370323105258: Zhoujiashangzhuang Village Committee, etc.
[0217] Driver's license term, jzqx. The enumerated values include: 5: Old term; 4: Old license; 1: 6-year term; 2: 10-year term; 3: Long term.
[0218] Driver source, ly. The enumerated values include: A: Local; E: Foreign; C: Transferred in; B: From other places; D: Military and police; G: Macau, China; F: Hong Kong, China; I: Embassy or consulate; H: Taiwan, China; J: Agricultural machinery.
[0219] Personnel status, ryzt. The enumerated values include: 4: Less than three years since the compulsory isolation drug rehabilitation measures were lifted; 2: Undergoing drug treatment.
[0220] Gender, xb. The enumerated values include: 1: Male; 2: Female; 9: Not specified.
[0221] Administrative division, xzqh. The enumerated values include: 132123: Quzhou County, Hebei Province; 350925: Zhouning County, Fujian Province; 411600: Zhoukou City, Henan Province; 610124: Zhouzhi County, Shaanxi Province; 612222: Zhouzhi County, Shaanxi Province, etc.
[0222] Authorized driving types, zjcx. The enumerated values include: P: Tram; C: Small car; F: Moped; B1: Medium-sized bus; B2: Large truck; A2: Tractor; C2: Small automatic car; C3: Low-speed truck; A1: Large bus; E: Two-wheeled motorcycle; D: Three-wheeled motorcycle; C4: Three-wheeled vehicle; A3: City bus, etc.
[0223] Driver's license status, zt. The enumerated values include: G: Cancelled; R: Cancelled and can be restored; B: Score reaches 12 points; N: Extension of license renewal; M: Overdue license renewal; T: Extension of annual inspection; K: Seized; I: Accident not handled; F: Revoked; D: Suspended; P: Extension of physical examination; H: Violation not handled; U: Detained; C: Transferred out; S: Overdue annual inspection, etc.
[0224] ##When there are synonyms or near-synonyms in the question, they need to be replaced with standard enumeration values in the corresponding fields.
[0225] ## Refer to the following example for output:
[0226] Example 1:
[0227] User input: How many Qingdao drivers transferred in last month.
[0228] Output: How many drivers transferred to Qingdao last month.
[0229] Example 2:
[0230] User input: Check which district has the smallest increase in drivers with revoked licenses, Qingdao, in the past 3 years.
[0231] Output: Which district in Qingdao had the smallest increase in revoked drivers in the past three years?
[0232] Exemplarily, when the syntax of the target SQL statement is corrected using the fourth model, the target SQL statement can be combined with the prompt text of the following example and then input into the fourth model. The prompt text of the following example includes the fifth prompt text and field information:
[0233] ##You are an expert in rewriting SQL statements. Your current task is to check and correct the input statements and output the correct statements.
[0234] #Correct existing grammatical errors, incorrect sentences, etc.
[0235] #The field values involved in standardization need to be selected from the fields provided below.
[0236] #The template information that needs to be generated can only refer to the following field information and cannot be created out of thin air:
[0237] Date of first license issuance, cclzrq. Driver registration statistics based on time. The field values that can be selected include time ranges such as the previous three months and single time such as 2021.
[0238] Administrative division of registered residence, djzsxzqh. Enumeration values include: 132123: Quzhou County, Hebei Province, 411600: Zhoukou City, Henan Province, 610124: Zhouzhi County, Shaanxi Province, 612222: Zhouzhi County, Shaanxi Province, 412701: Zhoukou City, Henan Province, etc.
[0239] Issuing Authority, fzjg. This field is used for screening when counting the number of changes in driver's licenses by region. For example, the rule for screening vehicles in Henan is: fzjg in('豫P'). The enumerated values include: 豫P: Vehicle Management Office of Zhoukou Public Security Bureau, Henan Province; 辽E: Vehicle Management Office of Benxi Traffic Police Detachment, Liaoning Province; 渝A: Vehicle Management Office of Chongqing Traffic Police Administration, etc.
[0240] Administrative Department, glbm. The enumerated values include: 371322101248: Zhougaoce Village Committee; 371625103256: Xiangzhoucun Village Committee; 371082112000: Renhe Town; 371083104211: Shangce Village Committee; 370323105258: Zhoujiashangzhuang Village Committee, etc.
[0241] Driver's License Expiry Date, jzqx. The enumerated values include: 5: Old Expiry Date; 4: Old License; 1: 6-year Term; 2: 10-year Term; 3: Long Term.
[0242] Driver Source, ly. The enumerated values include: A: Local; E: Foreign; C: Transferred In; B: From Other Areas; D: Military and Police; G: Macau, China; F: Hong Kong, China; I: Embassy; H: Taiwan, China; J: Agricultural Machinery.
[0243] Personnel Status, ryzt. The enumerated values include: 4: Less than three years since the compulsory isolation drug rehabilitation measures were lifted; 2: Undergoing drug rehabilitation treatment.
[0244] Gender, xb. The enumerated values include: 1: Male; 2: Female; 9: Not Specified.
[0245] Administrative Division, xzqh. The enumerated values include: 132123: Quzhou County, Hebei Province; 350925: Zhouning County, Fujian Province; 411600: Zhoukou City, Henan Province; 610124: Zhouzhi County, Shaanxi Province; 612222: Zhouzhi County, Shaanxi Province, etc.
[0246] Authorized Driving Types, zjcx. The enumerated values include: P: Tram; C: Small Car; F: Moped; B1: Medium-sized Bus; B2: Large Truck; A2: Tractor; C2: Small Automatic Car; C3: Low-speed Truck; A1: Large Bus; E: Motorcycle; D: Three-wheeled Motorcycle; C4: Three-wheeled Vehicle; A3: City Bus, etc.
[0247] Driver's License Status, zt. The enumerated values include: G: Cancelled; R: Cancelled and Restorable; B: 12 Points Recorded; N: Extension of License Renewal; M: Overdue License Renewal; T: Extension of Annual Inspection; K: Seized; I: Accident Not Settled; F: Revoked; D: Suspended; P: Extension of Physical Examination; H: Unresolved Violation; U: Detained; C: Transferred Out; S: Overdue Annual Inspection, etc.
[0248] ##When there are synonyms or near-synonyms in the question, they need to be replaced with standard enumeration values in the corresponding fields.
[0249] ## Refer to the following example for output:
[0250] Example 1:
[0251] User input: "SELECT count(v.xh) FROM drivinglicense v JOIN frm_code t1 ON REGEXP_LIKE(v.RYZT,t1.dmz) JOIN frm_codetype t1_1 ON t1.dmlb=t1_1.dmlb JOIN frm_code t2 ON REGEXP_LIKE(v.fzjg,t2.dmz) JOIN frm_codetypet2_1 ON t2.dmlb=t2_1.dmlb WHERE t1_1.xtlb='02' AND t1_1.lbsm='Source' AND t1.dmsm1 LIKE '%{driver source}%' AND t2_1.xtlb='00' AND t2_1.lbsm='Vehicle Administration Office Code'\n AND t2.dmsm1LIKE'%{Administrative Division Location}%'\n AND to_char(v.cclzrq,'{Time Format}')='{Time}'".
[0252] Output: "SELECT count(v.xh) FROM drivinglicense v JOIN frm_codet1 ON REGEXP_LIKE(v.RYZT,t1.dmz) JOIN frm_codetype t1_1 ON t1.dmlb=t1_1.dmlb JOIN frm_code t2 ON REGEXP_LIKE(v.fzjg,t2.dmz) JOIN frm_codetypet2_1 ON t2.dmlb=t2_1.dmlb WHERE t1_1.xtlb='02' AND t1_1.lbsm='driver source' AND t1.dmsm1 LIKE '%{driver source}%' and t2_1.xtlb='00' AND t2_1.lbsm = 'Vehicle Administration Office Code'\n AND t2.dmsm1 LIKE '%{Administrative Division Location}%'\n AND to_char(v.cclzrq,'{Time Format}') = '{Time}'".
[0253] It should be noted that the above input text is only an example given for ease of understanding and does not mean that the input text is limited thereto. Those skilled in the art can configure the input text as needed.
[0254] In order to further improve the accuracy of data set construction, on the basis of the above embodiments, in the embodiment of the present application, after obtaining the enhanced question text, each participle in the enhanced text can be corrected to ensure the accuracy of subsequent question templates and SQL templates. In the embodiment of the present application, a vocabulary table can be pre-configured and saved. After obtaining the enhanced question text, for each participle in the enhanced question text, if a standard participle similar to the participle is saved in the vocabulary table, the participle can be replaced with the standard participle. The process of participle replacement can be understood as synonym and near-synonym replacement, such as the synonym of expired driver's license is overdue renewal. And when applied in vertical fields, there are rare and low-frequency vocabulary problems, and the processing capacity of large models is improved by vocabulary replacement, vocabulary correction, etc. Establish a domain-specific vocabulary table, and first determine whether it is in this table in actual application. To a certain extent, it can solve the problem that the large model cannot correctly understand or generate answers when processing unseen words.
[0255] When constructing a data set, the data set construction method based on a large model provided in this application can be repeatedly executed to achieve the generation of batch sample data.
[0256] In order to further improve the accuracy of data set construction, based on the above embodiments, in the embodiment of the present application, the method further includes:
[0257] Execute the target SQL statement to obtain the execution result;
[0258] If the execution result is abnormal, the target SQL statement and the corresponding target question text are deleted.
[0259] Since the amount of data included in the field information is huge, there may be special characters or dirty data, and the accuracy of the SQL statements generated by the large model is far from the output accuracy of human engineers. There is a confidence problem in the prediction of the large model itself, and it is impossible to ensure absolute reliability. The uncertainty of the output is also the biggest obstacle that currently limits the application of large models in enterprises. Therefore, in order to further improve the accuracy of data set construction, after obtaining the target SQL statement, the target SQL statement can be executed, and whether the target SQL statement is correct can be determined based on the execution result of the target SQL statement. Exemplarily, if the execution result of the target SQL statement is abnormal, it can be considered that there is an error in the generated target SQL statement, and the target SQL statement and the corresponding target problem text can be deleted. Among them, the abnormal execution result may include: the target SQL statement cannot be executed, some parameters in the target SQL statement do not exist in the database, etc.
[0260] Through research, it is found that the corresponding SQL statements in the question texts manually annotated or generated by large models are mostly relatively simple SQL statement patterns. In the actual testing process, it is found that when the data included in the data set are all simple SQL statements, the effect of the data set in the application process is not good. Therefore, in the process of constructing the data set, complex target question texts and target SQL statements can be constructed as much as possible. The data set construction method provided in this application can construct relatively complex target question texts and target SQL statements. Among them, relatively simple SQL statements can be understood as SQL statements that mostly involve a single database and multiple data tables, or multiple databases and a single data table. Relatively complex SQL statements can be understood as SQL statements that involve the connection or nesting of multiple data tables.
[0261] The following is a specific example to illustrate the process of building a Text2SQL dataset. Figure 3 A flowchart of a Text2SQL dataset construction provided in an embodiment of the present application is shown in FIG. Figure 3As shown, when constructing the Text2SQL data set, a question template is generated based on the first large model. After the question template is obtained, the template is screened according to the semantic similarity between the question template and the question text to be enhanced. Then, the target word that matches the participle in the question template is searched in the pre-saved synonym and near-synonymous word library, and the corresponding participle in the question template is replaced with the target word to obtain a new question template, thereby realizing template generalization. In an embodiment of the present application, the remaining question templates and the generalized question templates are both screened for subsequent data enhancement. The first field information corresponding to the character area to be filled in each question template is determined based on the third large model.
[0262] The first field information and the question template are processed based on the second largest model to obtain a SQL template.
[0263] The target field value corresponding to the first field information is filled into the question template and the SQL template to obtain the target question text and the target SQL statement. The obtained target question text and the target SQL statement are saved in the Text2SQL data set.
[0264] The following is a specific example to illustrate the process of building a Text2SQL dataset. Figure 4 A flowchart of a Text2SQL dataset construction provided in an embodiment of the present application. In an embodiment of the present application, when constructing a dataset, the intents included in the dataset can be pre-designed, and for each intent, a target question text and a target SQL statement corresponding to the intent are generated.
[0265] When generating a target question text and a target SQL statement corresponding to any intent, it can be determined whether a question template and an SQL template pre-saved for the intent are saved.
[0266] If so, the target field value can be determined based on the pre-saved data dictionary and the keywords corresponding to the character areas to be filled in the question template and SQL template, and the target field value can be filled into the question template and SQL template to obtain the target question text and target SQL statement.
[0267] If not, obtain the question text to be enhanced, and call the first model to generate a question template for the question text to be enhanced. After obtaining the question template, perform template screening based on the semantic similarity between the question template and the question text to be enhanced. Call the second model to generate an SQL template for the screened question template. Then perform the subsequent filling steps to obtain the target question text and the target SQL statement.
[0268] After obtaining all the target question texts and target SQL statements, execute each target SQL statement, obtain the execution result, and determine the accuracy of the target SQL statement based on the execution result. Delete the target SQL statements and corresponding target question texts with abnormal execution results. Save the remaining target question texts and target SQL statements in the Text2SQL dataset.
[0269] The method for constructing a Text2SQL dataset based on a large model provided in the embodiment of the present application can generate a large amount of Text2SQL data with high accuracy and comprehensive coverage, without the need for manual verification, saving time and effort, and bridging the semantic gap between database models and natural language queries. In addition, by means of vocabulary correction, the processing capability of the large model is improved, ensuring the accuracy of the constructed dataset. A large amount of new data can be generated, improving work efficiency, and the generated data can cover a variety of query situations.
[0270] Based on the same inventive concept, the embodiment of the present application also provides a Text2SQL data set construction device based on a large model, Figure 5 A schematic diagram of a structure of a Text2SQL data set construction device based on a large model provided in an embodiment of the present application, the device comprising:
[0271] A generation module 501 is used to splice the question text to be enhanced, the first prompt text, and the field information included in the database and input them into the first large model to obtain a question template of the question text to be enhanced, wherein the first prompt text is used to prompt the first large model to analyze the field information and the question text to be enhanced to generate the question template of the question text to be enhanced; search the field information for the first field information corresponding to the character area to be filled in the question template; input the question template, the first field information and the second prompt text into the second large model to obtain an SQL template;
[0272] Filling module 502 is used to determine the target field value corresponding to the first field information according to the pre-saved correspondence between different field information and field values, and fill the target field value into the question template and the SQL template to obtain the target question text and the target SQL statement.
[0273] In one possible implementation, generation module 501 is specifically used for the first large model to determine, for each word segment in the question text to be enhanced, the word segment as a word to be deleted if there is a subfield in the field information that matches the semantics of the word segment; the position of at least one word segment to be deleted in the question text to be enhanced is determined as a character area to be filled, and the word segment to be deleted is deleted from the question text to be enhanced to obtain the question template.
[0274] In a possible implementation, the generation module 501 is specifically configured to determine an identification word according to the semantics of the subfield matching the to-be-deleted word, and use the identification word to identify the to-be-filled character region corresponding to the to-be-deleted word.
[0275] In one possible implementation, the generation module 501 is specifically used to determine the supplementary words based on the semantics of the question template and the semantics of each subfield in the field information; based on the semantics of the question template, add a character area to be filled in the question template, and use the supplementary words to identify the added character area to be filled.
[0276] In a possible implementation, the generation module 501 is specifically used to input the question template, the field information and the third prompt text into the third large model, so that the third large model searches for a target field name that matches a keyword identified by the to-be-filled character area in the question template in the field information according to the prompt of the third prompt text, and determines the target field name as the first field information; the keyword includes an identification word and a supplementary word;
[0277] The filling module 502 is specifically used to obtain each field value stored in the first field information in the pre-stored correspondence between different field information and field values; and randomly select any field value from each field value as the target field value.
[0278] In a possible implementation manner, the pre-stored correspondence between different field information and field values stores a text description and a code description for any field information;
[0279] The filling module 502 is specifically used to fill the text description of the target field value into the question template to obtain the target question text; and fill the code description of the target field value into the SQL template to obtain the target SQL statement.
[0280] In a possible implementation, the device further includes:
[0281] The verification module 503 is used to determine the semantic similarity between the question text to be enhanced and the question template; if the semantic similarity meets the preset threshold requirement, continue to execute the subsequent step of searching the field information for the first field information corresponding to the character area to be filled in the question template; if the semantic similarity does not meet the preset threshold requirement, delete the question template.
[0282] In a possible implementation, the device further includes:
[0283] The standardization module 504 is used to obtain the domain knowledge corresponding to the target domain to which the question text to be enhanced belongs, and the domain knowledge includes exclusive nouns and their corresponding explanatory texts; the question text to be enhanced, the fourth prompt text and the domain knowledge are spliced and input into the fourth large model, so that the fourth large model updates the exclusive nouns in the question text to be enhanced according to the prompt of the fourth prompt text, when the question text to be enhanced includes the exclusive nouns, using the explanatory texts corresponding to the exclusive nouns to obtain a standard text; and the question text to be enhanced is updated using the standard text.
[0284] In a possible implementation, the verification module 503 is also used to input the fifth prompt text, the field information, and the target question text and / or the target SQL statement into the fifth large model, so that the fifth large model analyzes the syntax and logic of the target question text and / or the target SQL statement according to the prompt of the fifth prompt text, and corrects the target question text and / or the target SQL statement if there are errors in the syntax or logic.
[0285] In a possible implementation, the verification module 503 is further configured to execute the target SQL statement to obtain an execution result; if the execution result is abnormal, the target SQL statement and the corresponding target question text are deleted.
[0286] Based on the same inventive concept, an embodiment of the present application further provides an electronic device, Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application is shown in FIG. Figure 6 As shown, it includes: a processor 601, a communication interface 602, a memory 603 and a communication bus 604, wherein the processor 601, the communication interface 602, and the memory 603 communicate with each other through the communication bus 604;
[0287] The memory 603 stores a computer program. When the program is executed by the processor 601, the processor 601 performs the following steps:
[0288] The question text to be enhanced, the first prompt text, and the field information included in the database are spliced and input into the first large model to obtain a question template of the question text to be enhanced, wherein the first prompt text is used to prompt the first large model to analyze the field information and the question text to be enhanced to generate a question template of the question text to be enhanced;
[0289] Searching the field information for first field information corresponding to the character area to be filled in the question template; inputting the question template, the first field information and the second prompt text into the second large model to obtain an SQL template;
[0290] According to the pre-saved correspondence between different field information and field values, the target field value corresponding to the first field information is determined, and the target field value is correspondingly filled into the question template and the SQL template to obtain the target question text and the target SQL statement.
[0291] In a possible implementation manner, the process in which the first large model analyzes the field information and the question text to be enhanced to generate a question template for the question text to be enhanced includes:
[0292] The first model determines each word in the question text to be enhanced as a word to be deleted if there is a subfield in the field information that matches the semantics of the word;
[0293] The position of at least one to-be-deleted word segment in the question text to be enhanced is determined as a character region to be filled, and the to-be-deleted word segment is deleted from the question text to be enhanced to obtain the question template.
[0294] In a possible implementation, the method further includes:
[0295] According to the semantics of the subfield matching the to-be-deleted word, an identification word is determined, and the to-be-filled character region corresponding to the to-be-deleted word is identified by using the identification word.
[0296] In a possible implementation, the method further includes:
[0297] Determining a supplementary word according to the semantics of the question template and the semantics of each subfield in the field information;
[0298] Based on the semantics of the question template, a character region to be filled in the question template is added, and the added character region to be filled is identified by using the supplementary word.
[0299] In a possible implementation manner, searching the field information for first field information corresponding to the character area to be filled in the question template includes:
[0300] Input the question template, the field information and the third prompt text into the third model, so that the third model searches for a target field name that matches a keyword identified in the to-be-filled character area in the question template in the field information according to the prompt of the third prompt text, and determines the target field name as the first field information; the keyword includes an identification word and a supplementary word;
[0301] The determining, according to the pre-stored correspondence between different field information and field values, a target field value corresponding to the first field information includes:
[0302] Obtaining, in the pre-saved correspondence between different field information and field values, each field value saved for the first field information;
[0303] Randomly select any field value from each field value as the target field value.
[0304] In a possible implementation manner, the pre-stored correspondence between different field information and field values stores a text description and a code description for any field information;
[0305] The step of filling the target field value into the question template and the SQL template to obtain a target question text and a target SQL statement includes:
[0306] Fill the text description of the target field value into the question template to obtain the target question text;
[0307] The code description of the target field value is filled into the SQL template accordingly to obtain the target SQL statement.
[0308] In a possible implementation, after generating the question template of the question text to be enhanced and before searching the field information for first field information corresponding to the character region to be filled in the question template, the method further includes:
[0309] Determining the semantic similarity between the question text to be enhanced and the question template;
[0310] If the semantic similarity meets the preset threshold requirement, then continue to perform the subsequent step of searching the field information for the first field information corresponding to the character area to be filled in the question template;
[0311] If the semantic similarity does not meet the preset threshold requirement, the question template is deleted.
[0312] In a possible implementation manner, before the question text to be enhanced, the first prompt text, and the field information included in the database are spliced and input into the first large model, the method further includes:
[0313] Acquire domain knowledge corresponding to the target domain to which the question text to be enhanced belongs, wherein the domain knowledge includes exclusive nouns and their corresponding explanation texts;
[0314] splicing the question text to be enhanced, the fourth prompt text and the domain knowledge and inputting them into the fourth model, so that the fourth model updates the exclusive nouns in the question text to be enhanced using the explanation texts corresponding to the exclusive nouns according to the prompt of the fourth prompt text, when the question text to be enhanced includes the exclusive nouns, to obtain a standard text;
[0315] The question text to be enhanced is updated using the standard text.
[0316] In a possible implementation, the method further includes:
[0317] The fifth prompt text, the field information, and the target question text and / or the target SQL statement are input into the fifth large model, so that the fifth large model analyzes the syntax and logic of the target question text and / or the target SQL statement according to the prompt of the fifth prompt text, and corrects the target question text and / or the target SQL statement if there are errors in the syntax or logic.
[0318] In a possible implementation, the method further includes:
[0319] Execute the target SQL statement to obtain the execution result;
[0320] If the execution result is abnormal, the target SQL statement and the corresponding target question text are deleted.
[0321] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The communication interface 602 is used for communication between the above electronic device and other devices. The memory can include a random access memory (RAM) and can also include a non-volatile memory (NVM), such as at least one disk storage. Optionally, the memory can also be at least one storage device located away from the aforementioned processor.
[0322] The above-mentioned processor can be a general-purpose processor, including a central processing unit, a network processor (Network Processor, NP), etc.; it can also be a digital signal processing processor (Digital Signal Processing, DSP), an application-specific integrated circuit, a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component, etc.
[0323] On the basis of the above embodiments, an embodiment of the present invention further provides a computer-readable storage medium, which stores a computer program executable by a processor. When the program runs on the processor, the processor implements the steps of the large model-based data set construction method described in the above embodiments.
[0324] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0325] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0326] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0327] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0328] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A method for constructing a Text2SQL dataset based on a large model, characterized in that: The method comprises: The question text to be enhanced, the first prompt text, and the field information included in the database are spliced and input into the first large model to obtain a question template of the question text to be enhanced, wherein the first prompt text is used to prompt the first large model to analyze the field information and the question text to be enhanced to generate a question template of the question text to be enhanced; Searching the field information for first field information corresponding to the character area to be filled in the question template; inputting the question template, the first field information and the second prompt text into the second large model to obtain an SQL template; According to the pre-saved correspondence between different field information and field values, the target field value corresponding to the first field information is determined, and the target field value is correspondingly filled into the question template and the SQL template to obtain the target question text and the target SQL statement.
2. The method according to claim 1, characterized in that The process of the first large model analyzing the field information and the question text to be enhanced to generate a question template for the question text to be enhanced includes: The first model determines each word in the question text to be enhanced as a word to be deleted if there is a subfield in the field information that matches the semantics of the word; The position of at least one to-be-deleted word segment in the question text to be enhanced is determined as a character region to be filled, and the to-be-deleted word segment is deleted from the question text to be enhanced to obtain the question template.
3. The method according to claim 2, characterized in that After deleting the to-be-deleted participle from the to-be-enhanced question text and before obtaining the question template, the method further includes: According to the semantics of the subfield matching the to-be-deleted word, an identification word is determined, and the to-be-filled character region corresponding to the to-be-deleted word is identified by using the identification word.
4. The method according to claim 3, characterized in that The method further comprises: Determining a supplementary word according to the semantics of the question template and the semantics of each subfield in the field information; Based on the semantics of the question template, a character region to be filled in the question template is added, and the added character region to be filled is identified by using the supplementary word.
5. The method according to claim 3 or 4, characterized in that: The searching the field information for the first field information corresponding to the character area to be filled in the question template includes: Input the question template, the field information and the third prompt text into the third model, so that the third model searches for a target field name that matches a keyword identified in the to-be-filled character area in the question template in the field information according to the prompt of the third prompt text, and determines the target field name as the first field information; the keyword includes an identification word and a supplementary word; The determining, according to the pre-stored correspondence between different field information and field values, a target field value corresponding to the first field information includes: Obtaining, in the pre-saved correspondence between different field information and field values, each field value saved for the first field information; Randomly select any field value from each field value as the target field value.
6. The method according to claim 1, characterized in that The pre-stored correspondence between different field information and field values stores text description and code description for any field information; The step of filling the target field value into the question template and the SQL template to obtain a target question text and a target SQL statement includes: Fill the text description of the target field value into the question template to obtain the target question text; The code description of the target field value is filled into the SQL template accordingly to obtain the target SQL statement.
7. The method according to claim 1, characterized in that After generating the question template of the question text to be enhanced, and before searching the field information for first field information corresponding to the character area to be filled in the question template, the method further includes: Determining the semantic similarity between the question text to be enhanced and the question template; If the semantic similarity meets the preset threshold requirement, then continue to perform the subsequent step of searching the field information for the first field information corresponding to the character area to be filled in the question template; If the semantic similarity does not meet the preset threshold requirement, the question template is deleted.
8. The method according to claim 1, characterized in that Before the question text to be enhanced, the first prompt text, and the field information included in the database are spliced and input into the first large model, the method further includes: Acquire domain knowledge corresponding to the target domain to which the question text to be enhanced belongs, wherein the domain knowledge includes exclusive nouns and their corresponding explanation texts; splicing the question text to be enhanced, the fourth prompt text and the domain knowledge and inputting them into the fourth model, so that the fourth model updates the exclusive nouns in the question text to be enhanced using the explanation texts corresponding to the exclusive nouns according to the prompt of the fourth prompt text, when the question text to be enhanced includes the exclusive nouns, to obtain a standard text; The question text to be enhanced is updated using the standard text.
9. The method according to claim 1, characterized in that: The method further comprises: The fifth prompt text, the field information, and the target question text and / or the target SQL statement are input into the fifth large model, so that the fifth large model analyzes the syntax and logic of the target question text and / or the target SQL statement according to the prompt of the fifth prompt text, and corrects the target question text and / or the target SQL statement if there are errors in the syntax or logic.
10. An electronic device, characterized in that: The electronic device includes a processor, and the processor is used to implement the steps of the large model-based Text2SQL data set construction method as described in any one of claims 1 to 9 when executing a computer program stored in a memory.
Citation Information
Cited By
Mail theme generation method and device, equipment and storage medium
CN119558295A
SQL statement generation method and device
CN119782340A
