Structured query statement generation method and system
In the process of generating structured query statements, a small model obtained by distilling knowledge based on a large language model is used to disassemble and generate natural language query statements into structured query statements, solving the problems of high cost and high resource consumption in the existing technology, and achieving efficient and accurate generation results.
Patent Information
- Application Number
- CN202411595541.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-08
- Publication Date
- 2025-04-01
AI Technical Summary
The prior art requires calling a large language model when generating natural language query statements into structured query statements, resulting in high cost and high resource consumption.
By distilling knowledge based on the large language model, a second large model with fewer parameters is obtained. This model is used to disassemble natural language query statements into several natural language query clauses and generate these clauses into structured query statements.
While maintaining high performance, the amount of model parameters is reduced, the generation efficiency is improved, the calculation resource occupation is reduced, and the generation accuracy and reliability are improved.
Smart Images

Figure CN119739728A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a method and system for generating structured query statements. Background Art
[0002] With the development of artificial intelligence, large language models are applied to more scenarios. For example, large language models can be applied to scenarios where natural language query statements need to be generated into structured query statements.
[0003] In this scenario, the large language model may be trained to train the large language model into a structured query statement generation model for generating structured query statements from natural language query statements.
[0004] However, this method of training and applying a large language model will incur high costs because it requires calling a large language model, and running the large language model also consumes a lot of resources.
[0005] It is worth noting that the contents of the above-mentioned related technologies are merely information known to the inventor personally, which does not mean that the above-mentioned information has entered the public domain before the filing date of this specification, nor does it mean that it can become the prior art of this specification. Summary of the invention
[0006] The present specification provides a method and system for generating a structured query statement to avoid at least one of the above technical problems.
[0007] In a first aspect, this specification provides a method for generating a structured query statement, comprising:
[0008] Based on the structured query statement generation model, the natural language query statement is decomposed into a plurality of natural language query clauses, wherein the structured query statement generation model is a second largest model obtained by distillation based on the first largest model, and the second largest model has fewer parameters than the first largest model;
[0009] Based on the structured query statement generation model, the plurality of natural language query clauses are generated into a structured query statement.
[0010] In a second aspect, this specification provides a system for generating a structured query statement, comprising:
[0011] at least one storage medium storing at least one instruction set for generating a structured query statement;
[0012] At least one processor is communicatively connected to the at least one storage medium, wherein when the at least one processor is running, it reads the at least one instruction set and executes the method as described in the first aspect according to the instructions of the at least one instruction set.
[0013] In a third aspect, the present specification provides a computer-readable non-temporary storage medium, wherein the computer-readable non-temporary storage medium stores at least one instruction set, and the at least one instruction set is executed by at least one processor to implement the method described in the first aspect.
[0014] It can be seen from the above technical solutions that the method and system for generating structured query statements provided in this specification include: based on the structured query statement generation model, decomposing the natural language query statement into a number of natural language query clauses, and based on the structured query statement generation model, generating a number of natural language query clauses into a structured query statement. Among them, the structured query statement generation model is a second largest model obtained by distillation based on the first large model, and the second largest model has fewer parameters than the first large model. By applying a small model that has undergone knowledge distillation technology to the generation method, the small model significantly reduces the number of parameters while maintaining high performance, thereby improving generation efficiency and reducing the occupation of computing resources. In addition, by decomposing complex natural language query statements into one or more simple natural language query clauses, it is easier to understand and process the query intent, thereby improving the accuracy and reliability of the generation.
[0015] Other functions of the method and system for generating structured query statements provided in this specification will be partially listed in the following description. The creative aspects of the method and system for generating structured query statements provided in this specification can be fully explained by practicing or using the methods, systems and combinations described in the following detailed examples. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the embodiments of this specification, 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 this specification. 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 an application scenario of a method for generating a structured query statement provided in an embodiment of this specification;
[0018] Figure 2 A schematic diagram of the structure of a system for generating structured query statements provided in an embodiment of this specification;
[0019] Figure 3 A schematic diagram of a flow chart of a method for generating a structured query statement provided in an embodiment of this specification;
[0020] Figure 4A schematic diagram of the principle of a method for generating a structured query statement provided in an embodiment of this specification;
[0021] Figure 5 A schematic diagram of the principle of a structured query statement generation model obtained by distillation provided in an embodiment of this specification. DETAILED DESCRIPTION
[0022] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementations described in the following exemplary embodiments do not represent all implementations consistent with this specification. Instead, they are merely examples of devices and methods consistent with some aspects of this specification as detailed in the appended claims.
[0023] It should be understood that the terms "including" and "having" and any variations thereof in the embodiments of this specification are intended to cover but not exclude inclusion. For example, a product or device comprising a series of components is not necessarily limited to those components explicitly listed, but may include other components not explicitly listed or inherent to these products or devices.
[0024] In the embodiments of this specification, the term "and / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B may represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the associated objects before and after are in an "or" relationship.
[0025] The term "plurality" in the embodiments of the present specification refers to two or more than two, and other quantifiers are similar.
[0026] The terms "first", "second", "third", etc. in this specification are used to distinguish similar or similar objects or entities, and do not necessarily mean to limit a specific order or sequence, unless otherwise indicated. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, for example, they can be implemented in an order other than those given in the diagrams or descriptions of the embodiments of this specification.
[0027] The term "unit / module" as used in this specification refers to any known or later developed hardware, software, firmware, artificial intelligence, fuzzy logic or combination of hardware and / or software code that is capable of performing the functions associated with that element.
[0028] To facilitate readers' understanding of this specification, the application scenarios of this specification are now introduced.
[0029] The method for generating a structured query statement provided in this specification (hereinafter referred to as the generating method) is applicable to a scenario where a natural query statement needs to be generated into a structured query statement.
[0030] Exemplarily, the generation method provided in this specification can be applied to application scenarios such as question and answering (QA), dialogue, and search. Among them, the question and answer application scenarios include: knowledge graph question and answering (KGQA), table question and answer (TableQA), database question and answer (DBQA), and other application scenarios.
[0031] Take the search scenario as an example:
[0032] The search platform supports language input and text input. Users can input natural language query statements through text input. The search platform can determine the structured query statement corresponding to the natural language query statement by executing the generation method provided in this specification.
[0033] In practical applications, a large language model (LLM) can be used as the basic network model for pre-training to obtain a structured query statement generation model (such as ChatGPT4). Correspondingly, in the application stage, natural language query statements can be converted into structured query statements based on the structured query statement generation model.
[0034] Among them, the large language model can be understood as a deep learning model trained with a large amount of text data, which can generate natural language text or understand the meaning of language text. The large language model can handle a variety of natural language tasks, such as the above-mentioned question answering.
[0035] However, this generation method based on a large language model requires calling a large language model to complete, which brings high costs.
[0036] In some embodiments, a small model (such as llama2) can be distilled from the large language model to replace the large language model to complete the generation work. Distillation is also called knowledge distillation, which is a model compression technology. By allowing the small model to learn the knowledge of the large model, the number of parameters of the small model can be significantly reduced while maintaining high performance.
[0037] Among them, the distillation methods include: a method based on multiple answers and voting, and a method based on an additional verification model.
[0038] The method based on multiple answers and voting has the following process: for the same natural language query statement, call the same large language model multiple times or call multiple different large language models, vote on all generated structured query statements, and use the structured query statement with the most votes as the data to supervise the training of the small model.
[0039] However, this method can only select one or part of the available training data for a natural language query statement, and the other data is discarded. This method does not fully utilize the data generated by the large language model. When the amount of training data is insufficient, it is difficult to train a small model with better performance.
[0040] The method based on the additional verification model works as follows: First, a verification model is trained using some labeled positive and negative sample data. Then the verification model evaluates all the output results of the large language model. If the output results of the large language model are considered correct, they can be used as data to supervise the training of the small model.
[0041] However, this method only retains the data that the verification model determines to be correct samples, and there is also the problem of insufficient utilization of the data generated by the large language model mentioned above. In addition, this method has high requirements for data annotation, and requires a large initial investment to annotate whether the results generated by the large language model are correct, in order to obtain a large amount of high-quality annotated data for training the verification model.
[0042] That is to say, the above distillation method also has some challenges: using all the structured query statements generated by the large language model directly as training data for the small model will introduce illusions or errors in the corpus; if only the structured query statements generated by the corpus that can be executed to obtain the correct query results (or correct answers) are selected as training data, a large amount of data generated by the corpus will be wasted, and it may not be possible to obtain sufficient training data.
[0043] Accordingly, when the small model obtained by the above method is applied to the generation method, there may be problems of low accuracy and reliability.
[0044] It is worth noting that the contents of the above-mentioned related technologies are merely information known to the inventor personally, which does not mean that the above-mentioned information has entered the public domain before the filing date of this specification, nor does it mean that it can become the prior art of this specification.
[0045] In order to avoid at least one of the above problems, the present specification proposes a technical conception that is the result of creative labor: decomposing a natural language query statement based on a small model obtained by distillation of a large language model to obtain one or more natural language query clauses, and generating a structured query statement based on the decomposed natural language query clauses based on the small model.
[0046] Based on the above analysis, it can be seen that applying the small model that has been distilled by knowledge technology to the generation method can significantly reduce the number of parameters of the small model while maintaining high performance, thereby improving the generation efficiency and reducing the occupation of computing resources. In addition, by decomposing complex natural language query statements into one or more simple natural language query clauses, it is easier to understand and process the query intent, thereby improving the accuracy and reliability of the generation.
[0047] Figure 1 is a schematic diagram of an application scenario of the generation method of an embodiment of this specification, wherein the generation method of this specification can be applied to Figure 1 The application scenario 100 shown. Figure 1 As shown, the application scenario 100 may include a target user 101 , a client 102 , a server 103 , and a network 104 .
[0048] The target user 101 may be a user who triggers the conversion of a natural language query statement into a structured query statement. For example, the target user 101 may perform a target operation on the client 102 to trigger the conversion of a natural language query statement into a structured query statement.
[0049] The client 102 may be an electronic device that provides interactive functions to the target user 101. For example, the client 102 may provide an interactive interface to the target user 101, and the target user 101 may perform interactive operations in the interactive page. In some embodiments, the client 102 executes the generation method described in this specification in response to detecting an operation of converting a natural language query statement into a structured query statement triggered by the target user 101. At this time, the client 102 may store data or instructions for executing the generation method described in this specification, and may execute or be used to execute the data or instructions. In some embodiments, the client 102 may include a hardware device with a data information processing function and a necessary program required to drive the hardware device to work, so as to execute the generation method described in this specification.
[0050] In some embodiments, the client 102 may include a mobile device, a tablet computer, a laptop computer, a built-in device of a motor vehicle, or the like, or any combination thereof. In some embodiments, the mobile device may include a smart home device, a smart mobile device, a virtual reality device, an augmented reality device, or the like, or any combination thereof. In some embodiments, the smart home device may include a smart TV, a desktop computer, or the like, or any combination thereof. In some embodiments, the smart mobile device may include a smart phone, a personal digital assistant, a gaming device, a navigation device, or the like, or any combination thereof. In some embodiments, the built-in device in a motor vehicle may include an onboard computer, an onboard TV, or the like.
[0051] In some embodiments, the client 102 may be installed with one or more applications (Application, APP). APP can provide the target user 101 with the ability and interface to interact with the outside world through the network 104. APP includes but is not limited to: web browser APP programs, search APP programs, chat APP programs, shopping APP programs, video APP programs, financial management APP programs, instant messaging tools, email clients, social platform software, etc.
[0052] like Figure 1 As shown, the client 102 can be connected to the server 103 for communication. The server 103 can be connected to one client 102 for communication, or can be connected to multiple clients 102 for communication. In some embodiments, the client 102 can interact with the server 103 through the network 104 to receive or send messages, etc.
[0053] The server 103 may be a server that provides various services. For example, the server 103 may be a cloud server or a local server. The server 103 may be connected to a client 102 for communication and receive data sent by the client 102, or may be connected to multiple clients 102 for communication and receive data sent by each client 102.
[0054] In some embodiments, the generation method described in this specification can be executed on the server 103. In this case, the server 103 can store data or instructions for executing the generation method described in this specification, and can execute or be used to execute the data or instructions. The server 103 can include a hardware device with a data information processing function and a necessary program required to drive the hardware device to work.
[0055] The network 104 is a medium for providing a communication connection between the client 102 and the server 103. The network 104 can facilitate the exchange of information or data. Figure 1 As shown, the client 102 and the server 103 can be connected to the network 104 respectively, and transmit information or data to each other through the network 104.
[0056] In some embodiments, the network 104 may be any type of wired or wireless network, or a combination thereof. For example, the network 104 may include a cable network, a wired network, a fiber optic network, a telecommunications network, an intranet, the Internet, a local area network (LAN), a wide area network (WAN), a wireless local area network (WLAN), a metropolitan area network (MAN), a public switched telephone network (PSTN), a Bluetooth network TM, a short-range wireless network (ZigBee TM), a near field communication (NFC) network, or a similar network.
[0057] In some embodiments, the network 104 may include one or more network access points. For example, the network 104 may include a wired or wireless network access point, such as a base station or an Internet exchange point, through which one or more components of the client 102 and the server 103 can connect to the network 104 to exchange data or information.
[0058] It is worth mentioning that Figure 1 The number of clients 102, servers 103, and networks 104 in the example are merely illustrative. Depending on the implementation requirements, there may be any number of clients 102, servers 103, and networks 104. The generation method provided in this specification may be executed entirely on the client 102, entirely on the server 103, or partially on the client 102 and partially on the server 103.
[0059] That is to say, Figure 1 and for Figure 1 The above description is only used to illustrate the application scenarios to which the generation method of this specification may be applicable, and should not be understood as a limitation on the application scenarios.
[0060] Figure 2 The hardware structure diagram of a generation system 200 provided according to an embodiment of the present specification is shown. The generation system 200 can execute the generation method described in the present specification. The generation method is introduced in other parts of the present specification. When the generation method is executed on the client 102, the generation system 200 can be the client 102. When the generation method is executed on the server 103, the generation system 200 can be the server 103. When the generation method can be partially executed on the client 102 and partially executed on the server 103, the generation system 200 can be a system including the client 102 and the server 103.
[0061] like Figure 2 As shown, the generation system 200 may include at least one storage medium 203 and at least one processor 202. In some embodiments, the generation system 200 may further include a communication port 204 and an internal communication bus 201. The generation system 200 may further include an I / O component 205.
[0062] The internal communication bus 201 can connect different system components. For example, the internal communication bus 201 can connect the storage medium 203, the processor 202, the communication port 204 and the I / O component 205.
[0063] I / O component 205 supports input / output between generation system 200 and other components.
[0064] The communication port 204 is used to generate data communication between the system 200 and the outside world. For example, the communication port 204 can be used to generate data communication between the system 200 and the network 104. The communication port 204 can be a wired communication port or a wireless communication port.
[0065] The storage medium 203 may include a data storage device. The data storage device may be a non-temporary storage medium or a temporary storage medium. For example, the data storage device may include one or more of a disk 2031, a read-only storage medium (ROM) 2032, or a random access storage medium (RAM) 2033. The storage medium 203 also includes at least one instruction set stored in the data storage device. The instruction set includes computer program code, and the computer program code may include a program, a routine, an object, a component, a data structure, a process, a module, etc. for executing the generation method provided in this specification.
[0066] At least one processor 202 may be connected in communication with at least one storage medium 203. At least one processor 202 is used to execute the above-mentioned at least one instruction set. When the generation system 200 is running, at least one processor 202 reads the at least one instruction set and executes the generation method provided in this specification according to the instructions of the at least one instruction set. The processor 202 may execute all the steps included in the generation method. The processor 202 may be in the form of one or more processors. In some embodiments, the processor 202 may include one or more hardware processors, such as a microcontroller, a microprocessor, a reduced instruction set computer (RISC), an application-specific integrated circuit (ASIC), an application-specific instruction set processor (ASIP), a central processing unit (CPU), a graphics processing unit (GPU), a physical processing unit (PPU), a microcontroller unit, a digital signal processor (DSP), a field programmable gate array (FPGA), an advanced RISC machine (ARM), a programmable logic device (PLD), any circuit or processor capable of performing one or more functions, etc., or any combination thereof.
[0067] For illustration purposes only, only one processor 202 is shown in the generation system 200 in the accompanying drawings. However, it should be noted that the generation system 200 in this specification may also include multiple processors, and therefore, the operations and / or method steps disclosed in this specification may be performed by one processor or by multiple processors in combination. For example, if the processor 202 of the generation system 200 is described in this specification as performing step A and step B, it should be understood that step A and step B may also be performed jointly or separately by two different processors 202 (e.g., the first processor performs step A, the second processor performs step B, or the first and second processors perform steps A and B together).
[0068] See also Figure 3 , Figure 3 This is a flow chart of the generation method provided in the embodiment of this specification. Figure 3 As shown, the method includes the following S301 and S302:
[0069] S301: Based on a structured query statement generation model, a natural language query statement is decomposed into a plurality of natural language query clauses, wherein the structured query statement generation model is a second largest model obtained by distillation based on the first largest model, and the second largest model has fewer parameters than the first largest model.
[0070] Exemplarily, the first large model may be a large language model, and the second large model may be llama2.
[0071] In this embodiment, the model used by the generation system to generate the operation is a small model obtained by distillation (i.e., the second largest model, the structured query statement generation model). This means that the structured query statement generation model has fewer parameters while maintaining the higher performance of the first largest model, thereby improving the efficiency of the structured query statement generation model and the feasibility of deployment.
[0072] The input of the structured query statement generation model is a natural language query statement, and the output is one or more natural language query clauses (ie, several natural language query clauses).
[0073] This step can be understood as: the generation system uses the structured query statement generation model to decompose the relatively more complex natural language query statement to obtain one or more relatively simpler natural language query clauses. Among them, a natural language query statement usually contains an independent query intent or condition.
[0074] Therefore, by breaking down a more complex natural language query statement into one or more simpler natural language query clauses, it is easier to understand and process the query intent. For example, when the subsequent generation system or query system determines the query result corresponding to the natural language query statement, it can better understand the user's query intent, thereby improving the accuracy and reliability of the query result and improving the user's query experience.
[0075] In some embodiments, in combination Figure 4 It can be seen that the generation system can decompose the natural language query statement into several natural language query clauses based on the preset prompt. In order to distinguish the different prompts in this specification, the prompt involved here is called the question step prompt. Other prompts involved in the following text will not be described in detail.
[0076] Among them, the question step prompt can be understood as a set of pre-set templates or guide words, which are used to guide the generation system on how to process the input natural language query statement to decompose the natural language query statement into several natural language query clauses.
[0077] For example, question step hints can help the generation system better understand the input natural language query statement and decompose it into one or more natural language query clauses. Question step hints can contain specific grammatical structures, keywords or indicators to guide the structured query statement generation model to decompose.
[0078] The input of the structured query statement generation model is a natural language query statement and a question step prompt, and the output is one or more natural language query clauses (ie, several natural language query clauses).
[0079] In this embodiment, the question step prompt can help the structured query statement generation model to better generalize to different natural language query clauses. Even if the input natural language query statement has a complex structure or contains uncommon words, the structured query statement generation model can effectively decompose it through the question step prompt. That is, by using the question step prompt, the generation system can effectively decompose the natural language query statement into several natural language query clauses. In addition, the generalization ability of the structured query statement generation model is also enhanced.
[0080] In some embodiments, the generation system decomposes the natural language query statement into a plurality of natural language query clauses based on the structured query statement generation model and the question step prompts, including:
[0081] The i-th sub-step prompt in the question step prompt and the first i-1 natural language query clauses in the plurality of natural language query clauses are input into the structured query statement generation model, and the i-th natural language query clause in the plurality of natural language query clauses is output, where i is an integer greater than 0.
[0082] Exemplarily, the sub-step prompts usually include specific query intent or conditions, which are used to guide the structured query statement generation model to generate corresponding natural language query clauses.
[0083] Take i as 3 as an example: the generation system can use the third sub-step prompt and the first two natural language query clauses among several natural language query clauses as the input of the structured query statement generation model. Among them, the first two natural language query clauses among several natural language query clauses contain the query intent and conditions of the previous steps, which are used to provide context information. Accordingly, the structured query statement generation model predicts the third natural language query clause among several natural language query clauses based on its input.
[0084] In this embodiment, the generation system inputs the i-th sub-step prompt and the first i-1 natural language query clauses in the question step prompt into the structured query statement generation model so that the structured query statement generation model can gradually generate each natural language query clause. This approach makes the generation process more controllable and accurate. In addition, the first i-1 natural language query clauses provide contextual information, which can help the structured query statement generation model better understand the query intent of the current step and ensure that the currently generated clause maintains consistency and coherence with the previous clause.
[0085] S302: Based on the structured query statement generation model, generate a plurality of natural language query clauses into a structured query statement.
[0086] The input of the structured query statement generation model is a number of natural language query clauses, and the output is a structured query statement.
[0087] That is, the generation system uses the structured query statement generation model to convert the disassembled natural language query clauses into structured query statements (such as SQL statements, etc.). For example, the generation system can convert each natural language query clause into a corresponding structured query clause, and finally combine them into a complete structured query statement.
[0088] Combined with the above analysis, it can be seen that several natural language query clauses can better understand the user's intention. Therefore, the generation system generates structured query statements through several natural language query clauses, which can make the structured query statements highly consistent with the natural language query statements at the level of intention and semantics. That is, the accuracy and reliability of converting natural language query statements into structured query statements can be improved.
[0089] In some embodiments, S302 may include: generating a number of natural language query clauses into a structured query statement based on a structured query statement generation model and a query generation prompt (Query Generate Prompt).
[0090] For example, Figure 4 As shown, when the structured query statement generation model generates a structured query statement, its input includes two parts: a number of natural language query clauses and query generation prompts. That is, the input of the structured query statement generation model is a number of natural language query clauses and query generation prompts, and the output is a structured query statement.
[0091] The query generation hint can be understood as a set of pre-set templates or guide words for guiding the generation system on how to process a number of input natural language query clauses so as to integrate the several natural language query clauses into a structured query statement.
[0092] For example, query generation hints can help the generation system better understand several natural language query clauses input and integrate them into a structured query statement. The query generation hints can include specific grammatical structures, keywords or indicators to guide the structured query statement generation model to generate, so as to integrate several natural language query clauses to obtain a structured query statement.
[0093] In this embodiment, the query generation prompt can help the structured query statement generation model to better understand and integrate the structured query statement, thereby improving the accuracy and reliability of the generated structured query statement.
[0094] In some embodiments, when the generated structured query statement is a failed query, a model is generated based on the structured query statement to convert the failed query into a successful query.
[0095] A failed query can be understood as a query that cannot be executed, and a successful query can be understood as a structured query statement that can be executed and obtains a correct query result.
[0096] It is worth noting that the structured query statement generated by the generation system based on the structured query statement generation model may be a failed query or a successful query. If it is a successful query, the generation system can output the successful query. Conversely, if it is a failed query, the generation system can transform the failed query based on the structured query statement generation model to transform the failed query into a successful query.
[0097] The input of the structured query statement generation model is a failed query, and the output is a successful query.
[0098] In this embodiment, when the structured query statement is a failed query, the generation system can convert the failed query into a successful query based on the structured query statement generation model, which can improve the effectiveness and reliability of generation and improve the user experience.
[0099] In some embodiments, when the generated structured query statement is an error query, a model is generated based on the structured query statement to convert the error query into a successful query.
[0100] The query that reports an error may be understood as a structured query statement that can be executed, but the query result obtained after the execution is an error.
[0101] In combination with the above examples, the structured query statement generated by the generation system based on the structured query statement generation model may be a successful query. For example, the structured query statement can be executed and the correct query result can be obtained. The structured query statement may also be a failed query. For example, the structured query statement cannot be executed. The structured query statement may also be an error query. For example, the structured query statement can be executed, but the correct query result cannot be obtained, but an incorrect query result is obtained.
[0102] In this embodiment, if the structured query statement is a query that reports an error, the generation system may transform the query that reports an error based on the structured query statement to transform the failed query into a successful query.
[0103] The input of the structured query statement generation model is the query with an error, and the output is the successful query.
[0104] In this embodiment, when the structured query statement is an error query, the generation system can convert the error query into a successful query based on the structured query statement generation model, which can improve the effectiveness and reliability of generation and improve the user experience.
[0105] In some embodiments, failed queries and / or erroneous queries are determined by the generation system based on an evaluation of the structured query statement.
[0106] Exemplarily, when generating a structured query statement, the generating system may evaluate the structured query statement to determine whether the structured query statement is a correct query, a failed query, or an error query.
[0107] This embodiment does not limit the evaluation method. For example, the generation system can be evaluated based on the unit test module method, the test query method, the classification model method, or the discriminant model method.
[0108] like Figure 4 As shown, when the generation system generates a structured query statement, it can perform unit testing on the structured query statement. If the structured query statement passes the unit test, it means that the structured query statement is a successful query, and the generation system can output a successful query.
[0109] Continue reading Figure 4 It can be seen that the structured query statement may also fail the unit test, which means that the structured query statement is a failed query or an error query. The generation system can correct the failed query or the error query based on the structured query statement generation model to obtain a successful query that can pass the unit test.
[0110] In this embodiment, the generation system determines whether the structured query statement is a correct query, a failed query, or an error query by means of evaluation, so as to achieve accurate determination of the structured query statement.
[0111] In some embodiments, in combination Figure 4 It can be seen that if the generated structured query statement is a failed query or an erroneous query, the generation system can convert the failed query or the erroneous query into a successful query based on the structured query statement generation model and the preset query correction prompt (QueryCorrect Prompt).
[0112] The query correction hint can be understood as a set of preset templates or guiding words for guiding the generation system on how to correct a structured query statement that cannot pass the unit test into a structured query statement that can pass the unit test, so as to obtain a successful query.
[0113] like Figure 4 As shown, the input of the structured query statement generation model includes query correction prompts and structured query statements that fail unit testing, and the output is a successful structured query statement.
[0114] In this embodiment, query correction prompts can help the structured query statement generation model to better correct failed queries or query errors, so as to finally determine successful queries, thereby improving the effectiveness and reliability of query statements generated.
[0115] In some embodiments, Figure 4 As shown, if the generated structured query statement fails the unit test, the unit test can also output corresponding feedback information - error information (err). The structured query statement generation model can further modify the failed query or the erroneous query in combination with the error information to obtain a successful query.
[0116] The error message may indicate the reason why the generated structured query statement fails the unit test. In this embodiment, by correcting the failed query or the query with an error in combination with the error message, the reliability and efficiency of the correction may be improved.
[0117] Combined with the above analysis, it can be seen that the technical solution provided in this specification is mainly implemented based on the structured query statement generation model. Among them, the structured query statement generation model is implemented by using knowledge distillation technology. The following will mainly explain the technical solution of distilling the structured query statement generation model.
[0118] It is worth noting that the execution subject of the structured query statement generation model obtained by distillation can be a training system. The training system can be a generation system, or a system different from the generation system. This embodiment takes the training system and the generation system as the same system as an example for exemplary explanation.
[0119] In some embodiments, the structured query statement generation model is a second large model with decomposition and generation capabilities obtained by distilling the first large model based on the training data set.
[0120] Among them, the decomposition capability is used to decompose a natural language query statement into a number of natural language query clauses; the generation capability is used to generate a number of natural language query clauses into a structured query statement.
[0121] For example, Figure 5 As shown, the first large model is a large language model, and the second model is llama2. Through distillation, llama2 can have both disassembly and generation capabilities.
[0122] Correspondingly, the training of the structured query statement generation model can be understood as two stages of training: training of decomposition ability and training of generation ability.
[0123] It is worth noting that in order to avoid distinguishing the same type of data in the distillation phase (i.e., training phase) and the above application phase examples, the data in the training phase is prefixed with "sample". For example, in order to distinguish the natural language query statements in the training phase and the above application phase, the natural language query statements in the training data set in the training phase are called sample natural language query statements. And so on, they are not listed here, and they will not be repeated in the following text.
[0124] The training of disassembly ability is described as follows:
[0125] The training data set includes sample natural language query statements. Figure 5 As shown, the input of the large language model includes: a sample natural language query statement and a sample question step prompt, and the output is a first clause set. The first clause set includes a plurality of first sample natural language query clauses. That is, the generation system is based on the large language model and, under the guidance of the sample question step prompt, decomposes the sample natural language query statement into one or more first sample natural language query clauses.
[0126] Continue reading Figure 5 , the input of llama2 is the first clause set, so as to train the disassembly capability of llama2 based on several first sample natural language query clauses in the first clause set.
[0127] In some embodiments, the generation system can construct the loss function L shown in Formula 1 Stage1 , with the goal of minimizing the loss function, train the disassembly ability of llama2. Formula 1:
[0128]
[0129] Among them, Question is a sample natural language query sentence, is the i-th clause in the first clause set, are the first i-1 clauses in the first clause set, log is the logarithm, P is the probability, and ∑ is the sum.
[0130] In some embodiments, the first clause set includes a plurality of first sample natural language query clauses obtained by disassembling the sample natural language query statement multiple times and removing redundancy, which can enhance the richness of the training data, thereby improving the effectiveness and reliability of the training.
[0131] For example, the generation system decomposes the sample natural language query sentence five times based on the large language model, and performs redundancy removal on the clauses obtained from the five decompositions to obtain a first clause set including several first sample natural language query clauses.
[0132] The training of generative ability is described as follows:
[0133] In some embodiments, the generating capability includes a transforming capability and a correcting capability.
[0134] The conversion capability refers to the capability of converting several natural language query clauses into successful queries, as in the above example. The correction capability refers to the capability of converting failed queries into successful queries and converting error queries into correct queries, as in the above example.
[0135] For example, Figure 5 As shown, the training of llama2's generation ability includes the training of llama2's conversion ability and the training of its correction ability.
[0136] Taking the training of conversion capability as an example, in some embodiments, the queries corresponding to the training data set include successful queries, and the conversion capability is obtained based on the successful query training in the queries corresponding to the training data set.
[0137] like Figure 5 As shown, based on llama2 with disassembly capability, the sample natural language query statement is disassembled to obtain a second clause set, which includes a number of second sample natural language query clauses. The sample natural language query statement, the second clause set, and the sample query generation prompt are used as inputs of llama2, and the query generated by the large language model that can execute the correct result (i.e., the sample successful query) is used as the generation target to construct the loss function shown in Formula 2, Formula 2:
[0138] L qry_gen = -logP(Qry t-succ |SubQ s ;Question)
[0139] Among them, Question is a sample natural language query sentence, Qry t-succ For successful sample query, SubQ s is the second clause set, log is the logarithm, and P is the probability.
[0140] Taking the training of correction capability as an example, the corresponding queries in the training data set include failed queries and / or erroneous queries, and the correction capability is obtained through training based on the failed queries and / or erroneous queries in the queries corresponding to the training data set.
[0141] like Figure 5 As shown, based on llama2 with disassembly capability, the sample natural language query statement is disassembled to obtain a second clause set, which includes a number of second sample natural language query clauses. The sample natural language query statement, the second clause set, the query that failed the evaluation (such as the sample failed query or the sample error query), and the sample query correction prompt are used as the input of llama2, and the query generated by the large language model that can execute the correct result (that is, the sample successful query) is used as the generation target to construct the loss function shown in Formula 3, Formula 3:
[0142] L correct = -logP(Qry t-succ |SubQ s ;Question;Qry t-fail ; err)
[0143] Among them, Question is a sample natural language query sentence, Qry t-succ For successful sample query, SubQ s is the second clause set, log is the logarithm, P is the probability, Qry t-fail It is a sample failed query or sample error query, and err is the sample error information.
[0144] Similarly, the sample success query, sample failure query, and sample error query in this embodiment can be determined by evaluation, such as by a test unit, and will not be described in detail here.
[0145] Combined with the above analysis, it can be seen that the conversion ability can be trained by formula 2, and the correction ability can be trained by formula 3. That is to say, the loss function of the second largest model obtained by distillation based on the first largest model includes: the first loss function corresponding to the conversion ability (such as the loss function shown in formula 2) and the second loss function corresponding to the correction ability (such as the loss function shown in formula 3).
[0146] In some embodiments, the loss function L corresponding to the generation capability training is Stage2 It can be expressed by formula 4:
[0147] L Stage2 =a1L qry_gen +a2L correct
[0148] Among them, a1 is the first loss function L qry_gen The hyperparameters of a2 are the second loss function L correct Hyperparameters of .
[0149] It is worth noting that the above examples are only used to illustrate possible implementations of the generation method of this specification, and cannot be understood as limiting the implementation of the generation method of this specification. Exemplarily, based on the above technical concept, some of the above technical features can be combined to obtain a new embodiment; new technical features can be added on the basis of the above examples to obtain a new embodiment; some technical features can be reduced on the basis of the above examples to obtain a new embodiment; some technical features in the above examples can be replaced with other technical features; some technical features and the order of the above examples can be adjusted to obtain a new embodiment, etc., which will not be listed here one by one.
[0150] According to the above technical concept, this specification also provides a computer-readable non-temporary storage medium, in which at least one instruction set is stored. When the at least one instruction set is executed by a processor, the steps of the generation method described in this specification are implemented.
[0151] In some possible implementations, the various aspects of this specification can also be implemented as a form of a program product, which includes program code. When the program product is run on the generation system 200, the program code is used to make the generation system 200 perform the steps of the generation method described in this specification. The program product for implementing the above method can adopt a portable compact disk read-only memory (CD-ROM) to include program code, and can be run on the generation system 200. However, the program product of this specification is not limited to this. In this specification, the readable storage medium can be any tangible medium containing or storing a program, which can be used by the instruction execution system or used in combination with it. The program product can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can be, for example, but not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples of readable storage media include: an electrical connection with one or more conductors, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. The computer-readable storage medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The readable storage medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, device, or device. The program code contained on the readable storage medium may be transmitted using any suitable medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the above. Program code for performing the operations of the present specification may be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the generation system 200, partially on the generation system 200, as a stand-alone software package, partially on the generation system 200 and partially on a remote generation system, or entirely on a remote generation system 200.
[0152] It should be noted that the collection, storage, use, processing, transmission, provision and disclosure of relevant user information (natural language query statements, etc.) involved in the technical solution of this specification are in compliance with the relevant laws and regulations and do not violate public order and good morals.
[0153] The above is a description of a specific embodiment of the present specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require a specific order or a continuous order to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0154] In summary, after reading this detailed disclosure, those skilled in the art will appreciate that the foregoing detailed disclosure may be presented only by way of example and may not be limiting. Although not explicitly stated herein, those skilled in the art will appreciate that this specification requires various reasonable changes, improvements and modifications to the embodiments. These changes, improvements and modifications are intended to be proposed by this specification and are within the spirit and scope of the exemplary embodiments of this specification.
[0155] In addition, certain terms in this specification have been used to describe embodiments of this specification. For example, "one embodiment", "an embodiment" and / or "some embodiments" mean that a particular feature, structure or characteristic described in conjunction with the embodiment may be included in at least one embodiment of this specification. Therefore, it can be emphasized and should be understood that two or more references to "an embodiment" or "one embodiment" or "an alternative embodiment" in various parts of this specification do not necessarily refer to the same embodiment. In addition, specific features, structures or characteristics may be appropriately combined in one or more embodiments of this specification.
[0156] It should be understood that in the foregoing description of the embodiments of this specification, in order to help understand a feature and for the purpose of simplifying this specification, this specification combines various features in a single embodiment, figure or its description. However, this does not mean that the combination of these features is necessary. When reading this specification, it is entirely possible for a person skilled in the art to mark out some of the devices as separate embodiments. In other words, the embodiments in this specification can also be understood as the integration of multiple secondary embodiments. And the content of each secondary embodiment is also valid when it is less than all the features of a single aforementioned disclosed embodiment.
[0157] Each patent, patent application, publication of patent applications, and other materials, such as articles, books, specifications, publications, documents, articles, etc., cited herein, except to the extent that it is inconsistent or conflicting with this document or that has a limiting effect on the broadest scope of the claims, may be incorporated herein by reference and used for all purposes now or hereafter associated with this document. In addition, in the event of any inconsistency or conflict between the description, definition, and / or use of a term in any material and the description, definition, and / or use of a term in this document, the term in this document shall prevail.
[0158] Finally, it should be understood that the embodiments of the application disclosed herein are explanations of the principles of the embodiments of this specification. Other modified embodiments are also within the scope of this specification. Therefore, the embodiments disclosed in this specification are only used as examples and not as limitations. Those skilled in the art can adopt alternative configurations according to the embodiments in this specification to implement the applications in this specification. Therefore, the embodiments of this specification are not limited to the embodiments accurately described in the application.
Claims
1. A method for generating a structured query statement, comprising: Based on the structured query statement generation model, the natural language query statement is decomposed into a plurality of natural language query clauses, wherein the structured query statement generation model is a second largest model obtained by distillation based on the first largest model, and the second largest model has fewer parameters than the first largest model; Based on the structured query statement generation model, the plurality of natural language query clauses are generated into a structured query statement.
2. The method according to claim 1, further comprising: When the generated structured query statement is a failed query, a model is generated based on the structured query statement to convert the failed query into a successful query.
3. The method according to claim 2, comprising: When the generated structured query statement is an error query, a model is generated based on the structured query statement to convert the error query into a successful query.
4. The method according to claim 2 or 3, further comprising: Failed queries or queries with errors are determined based on evaluation of structured query statements.
5. The method according to claim 1, wherein: The structured query statement generation model decomposes the natural language query statement into a plurality of natural language query clauses, including: Based on the structured query statement generation model and question step prompts, the natural language query statement is decomposed into the plurality of natural language query clauses.
6. The method according to claim 5, wherein: The step of generating the model and the question step prompt based on the structured query statement, breaking down the natural language query statement into the plurality of natural language query clauses, comprises: The i-th sub-step prompt in the question step prompt and the first i-1 natural language query clauses in the plurality of natural language query clauses are input into the structured query statement generation model, and the i-th natural language query clause in the plurality of natural language query clauses is output.
7. The method according to claim 1, wherein: The generating the plurality of natural language query clauses into a structured query statement based on the structured query statement generating model comprises: Based on the structured query statement generation model and the query generation prompt, the plurality of natural language query clauses are generated into a structured query statement.
8. The method according to claim 1, wherein: The structured query statement generation model is a second large model with decomposition and generation capabilities obtained by distilling the first large model based on the training data set; The decomposition capability is used to decompose the natural language query statement into the plurality of natural language query clauses; and the generation capability is used to generate the plurality of natural language query clauses into the structured query statement.
9. The method according to claim 8, wherein: The generation capabilities include: A capability to convert the plurality of natural language query clauses into successful queries; Corrective capabilities to convert failed queries into successful queries and / or convert queries reporting errors into correct queries.
10. The method according to claim 9, wherein: The loss function of the second large model obtained by distillation based on the first large model includes: a first loss function corresponding to the conversion ability and a second loss function corresponding to the correction ability.
11. The method according to claim 9, wherein: The queries corresponding to the training data set include successful queries, and the conversion capability is obtained based on successful query training among the queries corresponding to the training data set; The queries corresponding to the training data set include failed queries and / or queries reporting errors, and the correction capability is obtained through training based on the failed queries and / or queries reporting errors in the queries corresponding to the training data set.
12. A system for generating structured query statements, comprising: at least one storage medium storing at least one instruction set for generating a structured query statement; At least one processor is communicatively connected to the at least one storage medium, wherein when the at least one processor is running, the at least one instruction set is read, and the method as described in any one of claims 1 to 11 is executed according to the instructions of the at least one instruction set.
Citation Information
Cited By
Data management method, system and equipment based on double-track verification and self-healing mechanism and medium
CN122332420A