Structured query language generation method and system and electronic equipment
By obtaining database information and generating prompt information, and using dialogue model analysis to generate structured query language, the problem of SQL statement generation in the existing technology is solved, and a more accurate and realistic SQL statement generation is achieved.
Patent Information
- Application Number
- CN202311659941.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-05
- Publication Date
- 2025-06-10
AI Technical Summary
It is difficult for the existing technology to effectively generate structured query language (SQL) statements, especially in the process of data development. The traditional natural language to SQL (NL2SQL) model lacks modeling of database information, which makes the generated SQL statements out of reality and difficult to apply.
By detecting the client's query information to be converted, the database information matching the query information is obtained, prompt information is generated, and the query information and database information in the prompt information are analyzed using the dialogue model to output the structured query language.
It realizes the effective generation of structured query language, improves the accuracy of generated SQL statements and the degree of fit with practical applications, and solves the problem of SQL statements being divorced from reality in traditional methods.
Smart Images

Figure CN120123356A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of large model technologies and application development. Specifically, it relates to a method, system, and electronic device for generating Structured Query Language (SQL). Background Art
[0002] Currently, in the era of big data, data development has become an important task. In this important task, it is very important to quickly determine Structured Query Language (SQL) statements to improve production efficiency.
[0003] In the related art, only a traditional model that can convert natural language into executable SQL statements (Natural Language to SQL, abbreviated as NL2SQL) can be used to determine SQL. This technology only determines SQL statements based on the mapping between natural language (NL) and SQL statements. However, it lacks modeling of database information that matches the SQL statements, is divorced from reality, and is difficult to apply to actual data development. Therefore, there is still a technical problem that structured query language cannot be effectively generated.
[0004] For the above technical problems, no effective solution has been proposed yet. Summary of the Invention
[0005] Embodiments of the present application provide a method, system, and electronic device for generating Structured Query Language to at least solve the technical problem of low efficiency of data scheduling.
[0006] According to one aspect of the embodiments of the present application, a method for generating Structured Query Language is provided. This method is applied to the cloud and may include the following steps: detecting inquiry information to be converted from a client, where the inquiry information is used to represent the semantics of the Structured Query Language to be converted; obtaining database information that matches the Structured Query Language to be converted, where the database information is used to represent the data structure required to execute the operation function corresponding to the Structured Query Language to be converted in the database; generating prompt information based at least on the database information; inputting the prompt information into a dialogue model, and using the dialogue model to analyze the inquiry information and database information in the prompt information, and outputting the Structured Query Language.
[0007] According to another aspect of the embodiments of the present application, there is also provided a method for generating a model. The method may include the following steps: obtaining a database information sample set corresponding to a structured query language sample set; inputting the database information sample set into an initial dialogue model, and using the initial dialogue model to analyze the database information sample set, and outputting an inquiry information sample set corresponding to the structured query language sample set, wherein the initial dialogue model is trained at least based on an initial structured query language sample set, and the inquiry information samples in the inquiry information sample set are used to represent the semantics of the corresponding structured query language samples in the structured query language sample set; training a large model based on the database information sample set and the inquiry information sample set to obtain a dialogue model, wherein the dialogue model is used to analyze the inquiry information and database information in the prompt information to generate a structured query language, the prompt information is generated at least based on the database information matching the structured query language, the inquiry information is used to represent the semantics of the structured query language, and the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language in the database.
[0008] According to another aspect of the embodiments of the present application, there is also provided another method for generating a structured query language. The method is applied to a client and may include the following steps: detecting the inquiry information received in the interaction interface, wherein the inquiry information is used to represent the semantics of the structured query language to be generated; in response to the inquiry information, displaying the database information matching the structured query language to be generated in the interaction interface, wherein the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language to be generated in the database; on the interaction interface, displaying prompt information generated at least based on the database information; inputting the prompt information into the dialogue model, and displaying on the interaction interface the structured query language obtained by using the dialogue model to analyze the inquiry information and database information in the prompt information.
[0009] According to another aspect of the embodiments of the present application, there is also provided another method for generating a structured query language. The method may include: in response to multi-modal information received in the dialogue interface, wherein the multi-modal information includes the inquiry information corresponding to the structured query language to be generated, and the inquiry information is used to represent the semantics of the structured query language to be generated; displaying in the dialogue interface the database information matching the structured query language to be generated, wherein the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language to be generated in the database; on the dialogue interface, displaying prompt information generated at least based on the database information; inputting the prompt information into the dialogue model, and using the dialogue model to analyze the inquiry information and database information in the prompt information to output a structured query language; displaying in the dialogue interface the reply information generated based on the structured query language.
[0010] According to another aspect of the embodiments of the present application, another method for generating a structured query language is also provided. The method may include: detecting the query information to be converted by invoking a first interface, where the first interface includes a first parameter, and the parameter value of the first parameter is the query information, and the query information is used to represent the semantics of the structured query language to be converted; obtaining database information that matches the structured query language to be converted, where the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language to be converted in the database; generating prompt information based at least on the database information; inputting the prompt information into a dialogue model, and using the dialogue model to analyze the query information and the database information in the prompt information, and outputting a structured query language; and outputting the structured query language by invoking a second interface, where the second interface includes a second parameter, and the parameter value of the second parameter is the structured query language.
[0011] According to another aspect of the embodiments of the present application, a system for generating a structured query language is also provided. The system may include: an input end for inputting the query information to be converted, where the query information is used to represent the semantics of the structured query language to be converted; a processing end for obtaining database information that matches the structured query language to be converted, and generating prompt information based at least on the database information, where the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language to be converted in the database; and a model inference end for inputting the prompt information into a dialogue model, and using the dialogue model to analyze the query information and the database information in the prompt information, and outputting a structured query language.
[0012] According to another aspect of the embodiments of the present application, an electronic device is also provided. The electronic device may include a memory and a processor: the memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions. When the computer-executable instructions are executed by the processor, the method for generating a structured query language according to any one of the above is implemented.
[0013] According to another aspect of the embodiments of the present application, a processor is also provided. The processor is used to run a program, and when the program runs, the method for generating a structured query language according to any one of the above is executed.
[0014] According to another aspect of the embodiments of the present application, a computer-readable storage medium is also provided. The computer-readable storage medium includes a stored program, and when the program runs, it controls the device where the storage medium is located to execute the method for generating a structured query language according to any one of the above.
[0015] In an embodiment of the present application, when a client needs Structured Query Language (SQL) to assist in data development, the corresponding semantics capable of generating the SQL can be input on the interaction interface of the client, that is, the query information corresponding to the SQL. After detecting that there is query information to be converted into SQL in the interaction interface of a certain client, the query information can be transmitted from the client to the cloud. Based on the query information, the cloud can determine, from the database, the data structure required for the operation function when executing the SQL corresponding to the query information, that is, the database information matching the SQL, and can transmit it to the interaction interface of the corresponding client for display. The cloud can generate, at least based on the database information, the prompt information corresponding to the SQL, and can transmit it to the interaction interface of the corresponding client for display. The cloud can use the prompt information to prompt the dialogue model to generate the required corresponding SQL, and can transmit it to the interaction interface of the corresponding client for display. Considering that in the related art, generating SQL only based on the mapping between natural language and SQL may result in a situation that is divorced from reality and difficult to apply, the present application can further model the database information corresponding to the structured information, avoiding the abnormal situation in the above-mentioned related art, thereby achieving the purpose of improving the accuracy of the required generated structured information and the degree of fitting with actual applications, and further realizing the technical effect of effectively generating SQL, and solving the technical problem of being unable to effectively generate SQL.
[0016] It is easy to note that the above general description and the following detailed description are only for exemplifying and explaining the present application, and do not constitute a limitation to the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The drawings described herein are used to provide a further understanding of the present application, and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application, and do not constitute an improper limitation to the present application. In the drawings:
[0018] Figure 1 is a schematic diagram of an application scenario of a method for generating a Structured Query Language according to an embodiment of the present application;
[0019] Figure 2 is a flowchart of a method for generating a Structured Query Language according to an embodiment of the present application;
[0020] Figure 3 is a flowchart of a method for generating a model according to an embodiment of the present application;
[0021] Figure 4It is a flowchart of another method for generating a structured query language according to an embodiment of the present application;
[0022] Figure 5 It is a flowchart of another method for generating a structured query language according to an embodiment of the present application;
[0023] Figure 6 It is a flowchart of another method for generating a structured query language according to an embodiment of the present application;
[0024] Figure 7 It is a schematic diagram of a SQL classification result according to an embodiment of the present application;
[0025] Figure 8 It is a schematic diagram of a model inference according to an embodiment of the present application;
[0026] Figure 9 It is a schematic diagram of a system for generating a structured query language according to an embodiment of the present application;
[0027] Figure 10 It is a schematic diagram of a device for generating a structured query language according to an embodiment of the present application;
[0028] Figure 11 It is a schematic diagram of a device for generating a model according to an embodiment of the present application;
[0029] Figure 12 It is a schematic diagram of another device for generating a structured query language according to an embodiment of the present application;
[0030] Figure 13 It is a schematic diagram of another device for generating a structured query language according to an embodiment of the present application;
[0031] Figure 14 It is a schematic diagram of another device for generating a structured query language according to an embodiment of the present application;
[0032] Figure 15 It is a block diagram of a computer terminal according to an embodiment of the present application;
[0033] Figure 16 It is a block diagram of an electronic device for a method of generating a structured query language according to an embodiment of the present application. Detailed implementation
[0034] To enable those skilled in the art to better understand the solution of this application, the technical solution in the embodiments of this application will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of this application. Obviously, the described embodiments are only a part of the embodiments of this application, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in this application without creative efforts shall fall within the scope of protection of this application.
[0035] It should be noted that the terms "first", "second", etc. in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily need to be used to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments of this application described here can be implemented in an order other than those illustrated or described here. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or are inherent to these processes, methods, products, or devices.
[0036] The technical solution provided by this application is mainly implemented by large model technology. Here, the large model refers to a deep learning model with a large number of model parameters, which usually can include hundreds of millions, tens of billions, hundreds of billions, trillions or even more than one quadrillion model parameters. The large model can also be called the Foundation Model. Through large-scale pre-training of the large model with unlabeled corpora, a pre-trained model with more than hundreds of millions of parameters is produced. This model can adapt to a wide range of downstream tasks and has good generalization ability, such as large language models (LLMs), multi-modal pre-training models, etc.
[0037] It should be noted that in actual applications, the large model can be fine-tuned with a small number of samples for the pre-trained model, enabling the large model to be applied to different tasks. For example, the large model can be widely applied in fields such as Natural Language Processing (NLP), computer vision, and speech processing. Specifically, it can be applied to tasks in the field of computer vision such as Visual Question Answering (VQA), Image Caption (IC), and image generation. It can also be widely applied to tasks in the field of natural language processing such as text-based sentiment classification, text summary generation, and machine translation. Therefore, the main application scenarios of the large model include but are not limited to digital assistants, intelligent robots, search, online education, office software, e-commerce, intelligent design, etc.
[0038] Embodiment 1
[0039] According to an embodiment of the present application, a method for generating a structured query language is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. And although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here.
[0040] Considering that the large model has a huge number of model parameters and the computing resources of mobile terminals are limited, the method for generating the structured query language provided in the embodiments of the present application can be applied to the Figure 1 application scenarios shown, but not limited thereto. In the Figure 1 application scenarios shown, the large model is deployed in the server 10, and this server can be a cloud. The server 10 can be connected to one or more client devices 20 through a local area network connection, a wide area network connection, an Internet connection, or other types of data networks. Here, the client devices 20 can include but are not limited to: smart phones, tablet computers, laptop computers, handheld computers, personal computers, smart home devices, in-vehicle devices, etc. The client devices together constitute the client opposite to this server. An interactive interface for obtaining application generation instructions can be deployed on the graphical user interface of the client device, and this interactive interface can be a generative dialogue interface. The client device 20 can interact with the user through the graphical user interface to implement the call of the large model, and further implement the method for generating the structured query language provided in the embodiments of the present application.
[0041] In the embodiments of the present application, the system composed of a client device and a server can perform the following steps: When there is a need to determine the requirements of Structured Query Language (SQL) during the data development process, the semantics corresponding to the required SQL can be input on the interaction interface of the client device, that is, the query information corresponding to the SQL. The client device can obtain this query information and send it to the server via the network. After receiving the query information, the server can perform the following steps: Step S102, detect the query information to be converted from the client, where the query information is used to represent the semantics of the SQL to be converted; Step S104, obtain the database information that matches the SQL to be converted, where the database information is used to represent the data structure required to perform the operation function corresponding to the SQL to be converted in the database; Step S106, generate prompt information based at least on the database information; Step S108, input the prompt information into the dialogue model, and use the dialogue model to analyze the query information and database information in the prompt information, and output the SQL. The SQL can be output to the client device. During the above process, the database information and prompt information determined in the server can be sent to the client device via the network. The database information and prompt information during the generation process of the SQL can be displayed on the interaction interface of the client device. According to the above two pieces of information presented, if the accuracy is insufficient, it can be adjusted on the interaction interface to ensure the accuracy of the finally required SQL. It is also possible that after the server determines the SQL, it is transmitted to the corresponding client device via the network, and after the client device receives the SQL, the SQL can be displayed. It should be noted that in the case where the operating resources of the client device can meet the deployment and running conditions of the large model, the embodiments of the present application can be performed on the client device.
[0042] The embodiments of the present application propose the following method from the technical implementation side. Under the above operating environment, Embodiment 1 of the present application provides a method for generating SQL as follows Figure 2 shown. Figure 2 It is a flowchart of a method for generating SQL according to the present application. As Figure 2 shown, this method can be applied to the cloud and includes the following steps:
[0043] Step S202, detect the query information to be converted from the client, where the query information is used to represent the semantics of the SQL to be converted.
[0044] In the technical solution provided in step S202 of the present application above, through the cloud, it is possible to real-time check whether the client transmits inquiry information to be converted. Among them, the inquiry information may include the language used to describe the structured query language to be obtained after conversion. For example, natural language. Natural language (NL) can be used to represent the semantics of the structured query language to be generated. There is an interaction interface in the client device included in the client. The interaction interface can be a dialogue interface for the user of the client device to communicate with an SQL assistant capable of issuing SQL statements to generate the SQL statements required by the user. The structured query language can be used to write code. That is, the code written using the SQL language can be an SQL statement.
[0045] Optionally, when a certain structured query language is needed to assist in data development, inquiry information capable of describing the required structured query language can be input on the interaction interface of the corresponding client. Optionally, this embodiment performs real-time detection on the interaction interface to determine whether inquiry information is input. After determining that inquiry information is input, the input inquiry information can be detected.
[0046] Optionally, the client can perform real-time detection on whether natural language to be converted into structured query semantics is written on its interaction interface. If it is detected that natural language is written, the natural language can be transmitted to the cloud through transmission methods such as the network. Through the cloud, the semantics of the natural language from the client can be detected and analyzed, and information such as the characteristics of the required structured query language expressed by the natural language can be parsed, facilitating the matching of a structured query language that conforms to the semantics of the natural language.
[0047] Optionally, before determining the structured query language described by the natural language input through the interaction interface, a dialogue model that can be deployed in the cloud and can determine SQL statements through natural language in a dialogue form can be pre-trained. For example, a pre-trained code language model can be used to build an automated conversion method from natural language to SQL language, that is, an automated NL2SQL conversion method. After the pre-trained code language model is trained, a final dialogue model is obtained and deployed in the corresponding cloud. Through this dialogue model, when the user inputs natural language from the interaction interface of the corresponding client, after the natural language is transmitted to the cloud, the effect of communicating with the SQL assistant in the dialogue model in the cloud can be achieved, and an SQL statement that conforms to the natural language input by the user can be matched for the user. Among them, the pre-trained code language model can be the pre-trained language source code large model (StarCoder).
[0048] Optionally, in the process of constructing the automated conversion method of NL2SQL, the basic understanding ability of the large language model can be mainly relied on, which can include the understanding ability of natural language and code. In the process of constructing this method, processes such as data organization, model training, model evaluation, and model inference mainly need to be carried out.
[0049] Step S204: Obtain database information matching the structured query language to be converted, where the database information is used to represent the data structure required to execute the operation function corresponding to the structured query language to be converted in the database.
[0050] In the technical solution provided in step S204 of the present application, after detecting the natural language to be converted from the client, the database information matching the structured query language corresponding to the natural language can be determined based on the natural language, and the database information can be displayed in the interaction interface. The database information can be a Data Definition Language (DDL), which can include tables and fields in the database. The database information matching the structured language can be used to represent the data structure required to execute the operation function corresponding to the generated structured query language in the database, that is, the tables and fields beneficial to generating the corresponding structured query language selected from a large number of tables and fields in the database. The database can be a cloud data warehouse in the Software-as-a-Service (SaaS) mode, which is an enterprise-level software suitable for data analysis scenarios. For example, it can be a MaxCompute platform. The operation function can be the function that the corresponding structured query language can achieve. For example, it mainly can include the following types: SQL generation, SQL error correction, SQL annotation writing, SQL rewriting, and SQL question answering. This is only for illustration, and there is no specific limitation on the functions that the SQL statement can achieve and the types of functions. The data structure can be tables (table information) and fields. This is only for illustration, and there is no specific limitation on the data structure.
[0051] Optionally, after obtaining a certain structured query language in the interaction interface and transmitting it to the cloud, the structured query language can be processed in the cloud. The database can be called in the cloud to screen out the data structure matching the SQL statement corresponding to the natural language from a large number of data structures in the database, that is, to screen out the tables and fields beneficial to generating the SQL statement from a large number of tables and fields in the database.
[0052] Optionally, during the model inference process included in the automated conversion method for NL2SQL, a database information screening process can be performed. For example, during this process, a table and field screening model can be used to screen the DDL in the automatically obtained database, and the tables and fields beneficial for generating the corresponding SQL can be extracted from a large amount of DDL as the model input for the dialogue model. It should be noted that the above process and method for extracting the DDL matching the SQL are only for illustrative purposes and are not specifically limited here.
[0053] Step S206: Generate prompt information based at least on the database information.
[0054] In the technical solution provided in step S206 of the present application, after determining the database information matching the structured query language corresponding to the natural language based on the natural language, the corresponding prompt information can be determined based at least on the database information and sent to the interactive interface for display, where the prompt information can be the prompt corresponding to the SQL function.
[0055] Optionally, during the model inference process included in the automated conversion method for NL2SQL, after the database information screening, zero-shot inference can be performed. During the zero-shot inference process, prompt information can be generated.
[0056] Optionally, corresponding prompt information can be generated for different operation functions. For example, for the function of SQL generation, for the database information matched based on the natural language in the cloud, that is, for the given database information, the corresponding prompt information can be determined by answering questions. It should be noted that the above process and method for determining the prompt information are only for illustrative purposes and are not specifically limited here.
[0057] Step S208: Input the prompt information into the dialogue model, and use the dialogue model to analyze the query information and database information in the prompt information, and output the structured query language.
[0058] In the technical solution provided in step S208 of the present application, after determining the corresponding prompt information based at least on the database information, the prompt information can be input into the dialogue model. The dialogue model starts to generate the corresponding structured query language based on the query information and database information in the prompt information, and after the dialogue model generates the structured query language, it is sent to the client device and can be displayed on the interactive interface of the client device, where the dialogue model can be a trained SQL dialogue model, and it can also be called an NL2SQL model.
[0059] Optionally, during the process of data organization and model training, the pre-trained code language model can be fine-tuned in a supervised manner so that the model has the ability of NL2SQL, and a trained dialogue model can be obtained. After the training is completed, model evaluation can be carried out. That is, during the model evaluation process, based on the trained dialogue model, its performance can be tested on a standard data set to evaluate the performance of the dialogue model. If the evaluation result passes, the dialogue model can be put into normal use. That is, the dialogue model can be deployed to the cloud for generating structured query language based on natural language.
[0060] Optionally, based on the NL2SQL model with good evaluation performance, it can be used for auxiliary data development. The NL2SQL model is deployed in the cloud. When a prompt message is sent to it, the NL2SQL model can be triggered to start the process of generating SQL statements. The SQL statements required by the user can be generated through the NL2SQL model and sent to the corresponding interaction interface for display.
[0061] Since only by using the mapping between NL and SQL statements through traditional NL2SQL to determine SQL statements, there will be a situation of being divorced from reality and difficult to apply to the actual data development process. Therefore, there is still a technical problem of being unable to effectively convert data. However, in the embodiments of the present application, in order to solve the above problems of the single NL to SQL statement mapping, the existing data needs to be organized so that the model can learn the rules from rich natural language (input information). It can be considered to further model the database information matching the SQL statements, so that the NL2SQL data is organized into the form of NL combined with DDL mapped to SQL, enabling the model to learn sufficient knowledge from natural language and database information, and then generating the corresponding SQL statements based on this. Based on the above method, the situation of being divorced from reality and difficult to apply can be avoided, achieving the purpose of conforming to reality and being easy to apply to data development, thus solving the technical problem of being unable to effectively generate SQL statements in the related art.
[0062] Through the above steps S202 to S208 of this application, when the client needs Structured Query Language (SQL) to assist in data development, the corresponding semantics that can generate the SQL can be input on the interaction interface of the client, that is, the query information corresponding to the SQL. After detecting that there is query information to be converted into SQL in the interaction interface of a certain client, the natural language can be transmitted from the client to the cloud. Based on the query information, the cloud can determine the data structure required for the operation function when executing the SQL corresponding to the query information from the database, that is, the database information matching the SQL, and can be transmitted to the interaction interface of the corresponding client for display. The cloud can generate prompt information corresponding to the SQL based at least on the database information and can be transmitted to the interaction interface of the corresponding client for display. The cloud can use the prompt information to prompt the dialogue model to generate the required corresponding SQL and can be transmitted to the interaction interface of the corresponding client for display.
[0063] Since it is considered that in the related art, generating SQL only based on the mapping between natural language and SQL will result in a situation that is divorced from reality and difficult to apply. This application can further model the database information corresponding to the structured information, avoiding the abnormal situation that appears in the above related art, thereby achieving the purpose of improving the accuracy of the required generated structured information and the degree of fitting with practical applications. Furthermore, the technical effect of effectively generating SQL is realized, and the technical problem of being unable to effectively generate SQL is solved.
[0064] The above method of this embodiment will be further introduced below.
[0065] As an optional implementation manner, step S204, obtaining database information matching the SQL to be converted, includes: determining the operation function type corresponding to the SQL to be generated; obtaining the database information matching the operation function type.
[0066] In this embodiment, the database information corresponding to different operation function types can be determined according to the operation function type corresponding to the structured query language to be generated, and the database information can be sent to the corresponding interaction interface for display. Among them, the operation function type can be used to represent the type to which the operation function belongs. For example, it can include types such as SQL generation, SQL error correction, SQL annotation writing, SQL rewriting, and SQL extraction. The database information corresponding to the SQL generation type is the SQL generation prompt; the database information corresponding to the SQL error correction type is the SQL error correction prompt; the database information corresponding to the SQL annotation writing type is the SQL annotation writing prompt; the database information corresponding to the SQL rewriting type is the SQL rewriting prompt; the database information corresponding to the SQL extraction type is the SQL extraction prompt.
[0067] It should be noted that the above operation function types are only for illustrative purposes and are not specifically limited here. As long as it is a process and method for determining database information and determining the structured query language in combination with the database information and natural language, it is within the protection scope of the embodiments of the present application.
[0068] Optionally, since SQL statements have a variety of functions and different function SQL statements may be needed to assist in data development in data development, therefore, for SQL statements of different operation function types, corresponding database information needs to be configured. Thus, when the user needs to generate the required SQL statement, the user can select the corresponding operation function type according to his own choice to specifically handle the problem, and match the corresponding database information under the corresponding operation function type for him from the database, thereby improving the pertinence and accuracy of determining the database information.
[0069] For example, corresponding database information can be configured for different operation function types in advance and then stored in the database in the form of classification, etc. The operation function type required by the user can be determined according to the user's selection in the natural language, and the database information that is beneficial to generating the SQL statement required by the user can be screened and extracted from the corresponding category in the database, and the database information corresponding to the structured query language thus screened is used as the model input of the dialogue model. By classifying the database information according to the operation function type, it is convenient to improve the efficiency of extracting the required database information, thereby achieving the technical effect of improving the efficiency of generating the structured query language.
[0070] As an alternative embodiment, step S206, generating prompt information based at least on the database information, includes: using an information generation template to generate prompt information from the operation function and the database information, where the information generation template is used to represent the rule for generating prompt information in the query scenario corresponding to the structured query language.
[0071] In this embodiment, the operation function and database information can both be input into the information generation template, which can be processed to obtain corresponding prompt information and sent to the interaction interface. The generated prompt information can be displayed on the interaction interface. Among them, the information generation template can be used to represent the rules for generating prompt information in the query scenarios corresponding to the Structured Query Language (SQL), and can be a predefined template. The query scenario is used to reflect the user's requirements for different operation functions of the Structured Query Language, that is, it can be used to reflect the user's selection of the operation functions of the required Structured Query Language.
[0072] Optionally, during the database information screening process in the model inference process, according to the different requirements of the user in different query scenarios, the questions raised by the different requirements of the user, that is, the user's selection of the operation functions of the Structured Query Language, can use a table and field screening model to automatically screen and extract from the database the database information beneficial to generating the SQL statement required by the user, that is, tables and fields. And use it as the model input of the dialogue model.
[0073] Optionally, after the database information screening process is completed, a zero-shot inference process can be performed. During this process, according to the different requirements of the user in different query scenarios, the user's question, that is, the user's operation function of the Structured Query Language, combined with the database information extracted in the above steps, can be embedded into a predefined template. The template with the operation function and database information embedded is used as the prompt information and input into the dialogue model. Through the analysis of the dialogue model, the Structured Query Language required by the user is inferred, and the Structured Query Language is used as the model output of the dialogue model. It is returned to the interaction interface of the corresponding client device for display, that is, the model output is returned to the user.
[0074] For example, the SQL generation prompt: Given the following Maxcompute database information: ${schema}, answer the question (if it is a partitioned table, add the partition field condition): ${prompt}. SQL error correction prompt: Please repair the SQL bug according to the requirements of ${prompt} based on the Maxcompute SQL syntax rules: ```sql\n${schema}. SQL comment writing prompt: Please write comments for the following maxcomputesql: ```sql\n${schema}\n``` and retain the original sql: ${prompt}. SQL rewriting prompt: Given the following sql: ```sql\n${schema}\n```, and return it after modifying according to the Maxcompute sql syntax rules: ${prompt}. SQL extraction prompt: Given the following text content: ${prompt}, extract the sql from it. It should be noted that the above are only examples of Prompts corresponding to several SQL functions, where schema is a DDL or SQL statement, and prompt is obtained according to the user's selection, that is, prompt is the user input.
[0075] As an optional implementation manner, the method further includes: determining, in the query information sample set, the query information sample with the highest similarity to the query information, and determining, in the structured query language sample set, the structured query language sample corresponding to the query information sample, where the query information sample set and the structured query language sample set are used to train a dialogue model, and the query information sample is used to represent the semantics of the structured query language sample; generating prompt information based at least on the database information, including: generating prompt information based on the structured query language sample, the natural language sample, and the database information; step S206, generating prompt information based at least on the database information, including: generating prompt information based on the structured query language sample, the query information sample, and the database information.
[0076] In this embodiment, in the query information sample set, the query information sample with the highest similarity to the query information can be determined, and in the structured query language sample set, the structured query language sample corresponding to the query information sample set can be determined. And the corresponding prompt information can be determined based on the structured query language sample, the query information sample, and the database information, and the prompt information can be sent to the interaction interface for display, where the query information sample set and the structured query language sample set can be used to train the final dialogue model. The query information sample set and the structured query language sample set can be collectively referred to as the training set. The query information sample set can be a natural language sample set.
[0077] Optionally, during the model inference process, after zero-shot inference, few-shot inference can be performed. Before performing few-shot inference, based on the user's query question, i.e., natural language, query questions similar to the query question and the SQL statements corresponding to the query question can be extracted from the training set. That is, natural language samples similar to the natural language presented by the current query question are determined from the natural language sample set in the training set, and structured query language samples corresponding to the natural language samples are determined from the structured query language sample set in the training set, obtaining a natural language sample-structured query language sample pair, i.e., a query question-SQL statement pair. Thus, during the few-shot inference process, the prompt information can be determined using the natural language sample-structured query language sample pair corresponding to the natural language sample with the highest similarity to the currently input natural language and the corresponding database information, and the prompt information is input into the dialogue model to help the dialogue model infer the structured query language corresponding to the current natural language.
[0078] For example, the prompt information can be as follows: <|system|> The following is a conversation between the SQL assistant and a human. The assistant answers questions according to the human's questions and only needs to output the SQL statements. The SQL is returned in markdown code format without generating redundant information. <|user|> The model can answer questions based on the following similar examples: \n Answer the following question: {similar question 1}\n{SQL statement corresponding to question 1}\n Answer the following question: {similar question 2}\n{SQL statement corresponding to question 2}\n Answer the following question: {similar question 3}\n{SQL statement corresponding to question 3}\n Given the following database information: {table information}, answer the SQL query question: {user question}. <|bot|>.
[0079] As an alternative implementation, determining the query information sample with the highest similarity to the query information in the query information sample set includes: using a similarity model to determine query information samples in the query information sample set, where the similarity model is used to determine the output data with the highest similarity to the input data.
[0080] In this embodiment, a similarity model can be used to determine the query information sample with the highest similarity to the current query information from the query information sample set, where the similarity model can be used to determine the output data with the highest similarity to the input data. In the embodiments of the present application, the input data can be the natural language input by the current user, and the output data can be the natural language sample with the highest similarity to the input natural language.
[0081] Optionally, before performing few-shot inference, a similarity model can be used to extract the natural language sample set with the highest similarity to the natural language from the natural language sample set in the training set based on the natural language input by the user, and extract the structured query language sample set corresponding to the natural language sample set from the structured query language sample set in the training set.
[0082] If only the natural language detected on the current interaction interface is input into the dialogue model for inference to obtain the structured query language corresponding to the natural language, there will be a technical problem of low accuracy of the determined structured query language. However, in the embodiments of the present application, a query problem with the highest similarity to the query problem input by the current user on the interaction interface can be extracted from a training set in advance, as well as the SQL statement corresponding to the query problem, and the pair of the query problem-SQL statement with the highest similarity and the corresponding database information can be used as a piece of prompt information and input into the dialogue model to help the dialogue model infer the natural language input by the current user. Thus, it is possible to compare the SQL statement corresponding to the current natural language inferred with the SQL statement in the prompt information. If the similarity is not high, it may indicate that there is a problem with the SQL statement inferred by the dialogue model. If the similarity is high, it can indicate that the SQL statement inferred by the dialogue model is accurate, thereby achieving the technical effect of improving the accuracy of determining the structured query language.
[0083] As an optional implementation manner, the method may further include: outputting the structured query language to the client.
[0084] In this embodiment, the structured query language can be output to the client, where the client can be a client device.
[0085] Optionally, after analyzing the query information and database information in the prompt information through the dialogue model in the cloud to obtain the structured query language, the structured query language can be transmitted through the network to the client device connected thereto. After the client device receives the structured query language, the structured query language can be displayed on the interaction interface of the client device.
[0086] The embodiments of the present application also provide a method for generating a model, Figure 3 which is a flowchart of a method for generating a model according to the embodiments of the present application. As Figure 3 shown, the method may include the following steps:
[0087] Step S302, obtaining a database information sample set corresponding to the structured query language sample set.
[0088] In the technical solution provided in step S302 of the present application, a structured query language sample set can be constructed, and a database information sample set corresponding to the structured query language can be obtained.
[0089] Optionally, in order to train the final dialogue model, it is necessary to pre - formulate a database information sample set and a structured query language sample set.
[0090] Step S304: Input the database information sample set into the initial dialogue model, and use the initial dialogue model to analyze the database information sample set, and output an inquiry information sample set corresponding to the structured query language sample set. The initial dialogue model is trained at least based on the initial structured query language sample set. The inquiry information samples in the inquiry information sample set are used to represent the semantics of the corresponding structured query language samples in the structured query language sample set.
[0091] In the technical solution provided in step S304 of the present application, the initial dialogue model is used to analyze the database information sample set corresponding to the structured query language sample set to generate a natural language sample set. The initial dialogue model is trained at least based on the initial structured query language sample set. The inquiry information samples in the inquiry information sample set are used to represent the semantics of the corresponding structured query language samples in the structured query language sample set.
[0092] Optionally, the initial dialogue model can be used to analyze the database information sample set corresponding to the structured query language sample set, so as to generate a corresponding natural language sample set. Based on the database information sample set and the natural language sample set, the large - model can be trained to obtain a dialogue model. The initial dialogue model can be a model trained at least based on the initial structured query language sample set. For example, it can be an SQL dialogue model trained based on open - source data such as the initial structured query language sample set. The initial structured query language sample set can include open - source NL2SQL data. The natural language samples in the natural language sample set can be used to represent the semantics of the corresponding structured query language samples in the structured query language sample set. The large - model can be a pre - trained code language model. For example, it can be the pre - trained language model Starcoder. The dialogue model can be a dialogue model with NL2SQL ability. For example, an NL2SQL model or an SQL dialogue model.
[0093] To solve the problems existing in the related art only through the mapping between NL and SQL, the embodiments of the present application can organize the existing open-source data so that the dialogue model can learn the rules from the rich information in the open-source data. Thus, the NLSQL data is organized into the form of NL+DDL to SQL, so that the dialogue model can learn sufficient knowledge from NL and DDL, and then generate the corresponding SQL statement based on this, which can ensure that the SQL statement is more accurate.
[0094] Step S306: Based on the database information sample set and the query information sample set, train the large model to obtain a dialogue model, where the dialogue model is used to analyze the query information and database information in the prompt information and generate a structured query language. The prompt information is at least generated based on the database information matching the structured query language. The query information is used to represent the semantics of the structured query language. The database information is used to represent the data structure required for performing the operation function corresponding to the structured query language in the database.
[0095] In the technical solution provided in step S306 of the present application, the large model can be trained based on the database information sample set and the query information sample set to obtain a dialogue model, where the dialogue model can be used to analyze the query information and database information in the prompt information and generate a structured query language. The prompt information can be at least generated based on the database information matching the structured query language. The query information can be used to represent the semantics of the structured query language. The database information can be used to represent the data structure required for performing the operation function corresponding to the structured query language in the database.
[0096] Optionally, based on the database information sample set and the query information sample set, train the large model to obtain a dialogue model.
[0097] Optionally, during the process of data organization, the acquisition and conversion of open-source data can be performed. During the acquisition and conversion of open-source data, open-source NLSQL data can be used, and the generation of open-source structured query language in a non-data warehouse tool (Hive) form can be converted into the Hive form, including DDL statements and SQL statements.
[0098] Through the above steps S302 to S306 of this application, a database information sample set corresponding to the structured query language sample set is obtained; the database information sample set is input into the initial dialogue model, and the initial dialogue model is used to analyze the database information sample set, and an inquiry information sample set corresponding to the structured query language sample set is output. Among them, the initial dialogue model is trained at least based on the initial structured query language sample set, and the inquiry information samples in the inquiry information sample set are used to represent the semantics of the corresponding structured query language samples in the structured query language sample set; based on the database information sample set and the inquiry information sample set, the large model is trained to obtain a dialogue model, where the dialogue model is used to analyze the inquiry information and database information in the prompt information to generate a structured query language. The prompt information is generated at least based on the database information matching the structured query language, the inquiry information is used to represent the semantics of the structured query language, and the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language in the database, thereby achieving the technical effect of effectively generating a structured query language and solving the technical problem of being unable to effectively generate a structured query language.
[0099] The above method of this embodiment will be further introduced below.
[0100] As an optional implementation manner, the method further includes: classifying the database information sample set according to the operation function corresponding to the structured query language sample set in the database; using the initial dialogue model to analyze the database information sample set, and outputting an inquiry information sample set corresponding to the structured query language sample set, including: using the initial dialogue model to analyze the classified database information sample set, and outputting an inquiry information sample set corresponding to the structured query language sample set.
[0101] In this embodiment, the database information sample set can be analyzed according to the operation function corresponding to the structured query language sample set in the database, and the initial dialogue model can be used to analyze the database information sample set corresponding to the structured query language sample set classified according to the operation function to generate the corresponding inquiry information sample set.
[0102] Optionally, in the process of data organization, after obtaining and converting the open-source data, the application function data automatic generation process can be carried out. In this process, the existing SQL statements in the application function data can be classified according to their operation functions, and several SQL statements in each category can be extracted for backup.
[0103] Optionally, after extracting several SQL statements in each category for backup, a natural language description can be generated using an SQL dialogue model trained based on the open-source data to form an NL2SQL data pair of the application function data.
[0104] Optionally, for the NL2SQL data pairs of application function data, manual verification and modification are required to ensure their accuracy.
[0105] For example, SQL can be classified into the following six categories: 1) Data Query Language (abbreviated as DQL); 2) Data Definition Language (abbreviated as DDL); 3) Data Manipulation Language (abbreviated as DML); 4) Tool Command Language (abbreviated as TCL); 5) Data Control Language (abbreviated as DCL); 6) COMMAND. It should be noted that the number and types of the above SQL classifications are only for illustrative purposes and are not specifically limited here.
[0106] For another example, the DQL class may include the following statements: CTE Select statements (such as, WITH SELECT), basic query Select statements (such as, Select, select distinct, Select fields, and Select From Table), branching statements (such as, Case WHEN), aggregate functions (such as, SUM, COUNT, AVG, MIN, MAX, and Having), built-in functions (such as, max_pt), window functions (such as, WINDOW, OVER, FILTER, and Row_Number), QUALIFY statements (such as, QUALIFY), transformation PIVOT statements (such as, PIVOT and UNPIVOT), subquery statements (such as, a Select statement nested within a Select statement), joined Select statements (such as, INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN, and SEMI JOIN), Union Select statements (such as, intersect, union, except, and minus), conditional query Select statements (such as, WHERE and partitioned and non-partitioned), sorted Select statements (such as, ORDER BY), grouped Select statements (such as, GROUP BY), and limited Select statements (such as, LIMIT). Among them, WHERE may include LIKE, RLIKE, REGEXP, IN, NOT IN, BETWEEN, IS NULL, IS NOT NULL, NOT, =, AND, OR, >, >=, <, and <=. ORDER BY may include DESC and ASC.
[0107] As an optional example, the DDL class may include the following statements: CREATE statements (such as, CreateTable and Create Function), ALTER statements (such as, ALTER TABLE), DROP statements (such as, DROP TABLE and DROP FUNCTION). Among them, Create Table may include Create Non Partition Table, Create Partition Table, and Create External Table.
[0108] For example, the following statements can be included in the DML class: INSERT statements (such as INSERT INTO and INSERT OVERWRITE), UPDATE statements (such as UPDATE SET), DELETE statements (such as DELETE), and MERGE statements (such as MERGE INTO). The following statements can be included in the TCL class: COMMIT statement and ROLLBACK statement. The following statements can be included in the DCL class: GRANT statement and REVOKE statement. The following statement can be included in the COMMAND class: SET statement.
[0109] It should be noted that the statements included in each category obtained by the above SQL classification are only for illustrative purposes and are not specifically restricted here.
[0110] As an alternative implementation, based on the database information sample set and the query information sample set, the large model is trained to obtain a dialogue model, including: based on the classified database information sample set and the query information sample set, the large model is supervised-trained to obtain a dialogue model.
[0111] In this embodiment, based on the classified database information sample set and the natural language sample set, the large model can be supervised-trained to obtain a dialogue model.
[0112] Optionally, after the data organization process is completed, the model training process can be started. In this process, based on the classified database information sample set, the large model can be supervised-trained, that is, supervised fine-tuned, to obtain a dialogue model with NL2SQL capabilities.
[0113] For example, based on the pre-trained language model Starcoder, supervised fine-tuning is performed so that the model obtains NL2SQL capabilities and becomes a dialogue model.
[0114] As an alternative implementation, the method further includes: training an initial dialogue model based on an initial structured query language sample set of data types matching different operation functions.
[0115] In this embodiment, an initial dialogue model can be trained based on an initial structured query language sample set of data types matching different operation functions, where the data type can be used to indicate whether the data form is in Hive form.
[0116] Optionally, using open-source NL2SQL data, the generation of structured query language in non-Hive form can be converted into Hive form, so as to train and obtain an initial dialogue model, that is, a pre-trained code language model.
[0117] In an embodiment of the present application, after detecting that there is inquiry information to be converted into Structured Query Language (SQL) in the interaction interface of a certain client, the inquiry information can be transmitted from the client to the cloud. Based on the inquiry information, the cloud can determine, from the database, the data structure required for the operation function executed when the SQL corresponding to the inquiry information is executed, and generate a prompt message corresponding to the SQL based on the matched data structure. The cloud can use the prompt message to prompt the dialogue model to generate the corresponding required SQL, and can transmit it to the interaction interface of the corresponding client for display. Since the present application can further model the database information corresponding to the structured information, it avoids the abnormal situations that occur in the above related technologies, thereby achieving the purpose of improving the accuracy of the required generated structured information and the degree of fit with the actual application. Furthermore, it realizes the technical effect of effectively converting data and solves the technical problem of being unable to effectively convert data.
[0118] The embodiment of the present application also provides a method for generating SQL from the client side. Figure 4 It is a flowchart of a method for generating SQL according to an embodiment of the present application. As Figure 4 shown, the method may include the following steps:
[0119] Step S402, detecting the inquiry information received in the interaction interface, where the inquiry information is used to represent the semantics of the SQL to be generated.
[0120] In the technical solution provided in step S402 of the present application above, the inquiry information received on the interaction interface can be detected. Among them, the inquiry information may include the natural language corresponding to the SQL to be generated, which may be the user selection submitted by the user of the client device for the required SQL, and the query question made for the required SQL.
[0121] Optionally, when it is necessary to display the SQL to be used for data development on the interaction interface of the client device, the natural language capable of describing the required SQL can be input on the interaction interface of the corresponding client device. The interaction interface can be detected in real time to determine whether there is inquiry information input. After determining that there is inquiry information input, the input inquiry information can be detected.
[0122] Step S404, in response to the inquiry information, displaying database information matching the SQL to be generated in the interaction interface, where the database information is used to represent the data structure required for the operation function executed by the SQL to be generated in the database.
[0123] In the technical solution provided in step S404 of the present application, after detecting that an inquiry message is received in the interaction interface, database information matching the structured query language corresponding to the inquiry message can be determined based on the inquiry message, and the database information can be displayed in the interaction interface.
[0124] Optionally, after detecting the inquiry message received in the interaction interface, the inquiry message can be transmitted to the cloud. Through the cloud, semantic analysis can be performed on the inquiry message to determine the structured query language corresponding to the natural language in the inquiry message, and further call the database information in the database that can match the structured query language.
[0125] Optionally, after the cloud determines the database information matching the SQL statement based on the above method, the database information can be transmitted through the cloud to the interaction interface corresponding to the input inquiry message for display. If the database information is inaccurate or does not meet the user's needs, corresponding adjustment operations can be performed on the interaction interface to send a corresponding request to modify the database information, and the modified accurate or user-demand-satisfying database information can be sent to the corresponding interaction interface for display, so as to ensure the accuracy of the obtained database information and further ensure the accuracy of the subsequently generated structured query language.
[0126] Step S406, display prompt information at least based on the database information on the interaction interface.
[0127] In the technical solution provided in step S406 of the present application, after responding to the inquiry message and displaying the database information matching the structured query language to be generated in the interaction interface, corresponding prompt information can be determined at least based on the database information and sent to the interaction interface for display.
[0128] Optionally, in the model inference process included in the automated conversion method for NL2SQL, after screening the database information, zero-shot inference can be performed. In the zero-shot inference process, prompt information can be generated.
[0129] Optionally, after determining the prompt information based on the above method, the prompt information can be transmitted through the cloud to the interaction interface corresponding to the input inquiry message for display. If the prompt information is inaccurate or does not meet the user's needs, corresponding adjustment operations can be performed on the interaction interface to send a corresponding request to modify the prompt information, and the modified accurate or user-demand-satisfying prompt information can be sent to the corresponding interaction interface for display, so as to ensure the accuracy of the obtained prompt information and further ensure the accuracy of the subsequently generated structured query language.
[0130] Step S408: Input the prompt information into the dialogue model, and display on the interaction interface the Structured Query Language obtained by analyzing the prompt information and the database information using the dialogue model.
[0131] In the technical solution provided in step S408 of the present application, after displaying on the interaction interface the prompt information generated at least based on the database information, the prompt information can be used to prompt the dialogue model to start generating the corresponding Structured Query Language. After the dialogue model generates the Structured Query Language, it can be displayed on the interaction interface. Among them, the dialogue model can be a trained SQL dialogue model, which can also be an NL2SQL model.
[0132] Optionally, based on an NL2SQL model with good evaluation performance, it can be used for auxiliary data development. The NL2SQL model is deployed in the cloud. When the prompt information gives a prompt to it, the NL2SQL model can be triggered to start the process of generating SQL statements. Through the NL2SQL model, the SQL statements required by the user can be generated and sent for display on the corresponding interaction interface.
[0133] Optionally, after displaying the required Structured Query Language on the interaction interface, if the Structured Query Language is inaccurate or does not meet the user's requirements, corresponding adjustment operations can be performed on the interaction interface to send a corresponding request to modify the Structured Query Language, and the accurate or user - requirement - meeting Structured Query Language after modification is sent to the corresponding interaction interface for display, thereby improving the accuracy of the required Structured Query Language.
[0134] In the embodiments of the present application, to solve the problem of single NL - to - SQL statement mapping, the existing data needs to be organized so that the model can learn the rules from rich query information (input information). It can be considered to further model the database information matching the SQL statements, so as to organize the NL2SQL data into the form of NL combined with DDL mapped to SQL, enabling the model to learn sufficient knowledge from natural language and database information, and then generate the corresponding SQL statements based on this. Based on the above method, the situation of being divorced from reality and difficult to apply can be avoided, achieving the purpose of conforming to reality and being easily applied to data development, thereby solving the technical problem in the related art of being unable to effectively generate SQL statements.
[0135] Through the above steps S402 to S408 of this application, when it is necessary to display the structured query language to be used for data development on the interaction interface of the client device, inquiry information composed of natural language capable of generating the structured query language can be input on the interaction interface. After detecting the existence of the inquiry information in the interaction interface, based on the inquiry information, database information matching the structured query language corresponding to the inquiry information is determined from the database and can be transmitted to the interaction interface for display. At least based on the database information, prompt information corresponding to the structured query language can be generated and can be transmitted to the interaction interface for display. The prompt information can be used to prompt the dialogue model to generate the required corresponding structured query language and can be transmitted to the interaction interface for display. Since further modeling can be performed on the database information corresponding to the structured information, the situations of being divorced from reality and difficult to apply in the above technologies are avoided, thereby achieving the purpose of improving the accuracy of the required generated structured information and the degree of fitting with the actual situation. Furthermore, the technical effect of effectively generating the structured query language is realized, and the technical problem of being unable to effectively generate the structured query language is solved.
[0136] The above method of this embodiment will be further introduced below.
[0137] As an optional implementation manner, in step S406, on the interaction interface, display the prompt information generated at least based on the database information, including: input the operation function and the database information into the information generation template, and display the generated prompt information on the interaction interface, where the information generation template is used to represent the rule for generating the prompt information in the query scenario corresponding to the structured query language.
[0138] In this embodiment, the information generation template can be used to generate the prompt information from the operation function and the database information, where the information generation template can be used to represent the rule for generating the prompt information in the query scenario corresponding to the structured query language.
[0139] Optionally, both the operation function and the database information are input into the information generation template, and it can be processed to obtain the corresponding prompt information, and can be sent to the interaction interface, and the generated prompt information can be displayed on the interaction interface.
[0140] Optionally, in the process of screening the database information during the model inference, for the different needs of users in different query scenarios, the questions raised by the different needs of users, that is, the selection of the operation function of the structured query language by the user, can be automatically screened and extracted from the database using the table and field screening model to obtain the database information beneficial to generating the SQL statement required by the user, that is, the table and the field. And use it as the model input of the dialogue model.
[0141] Optionally, after the database information screening process ends, a zero-shot inference process can be performed. During this process, according to the different needs of users in different query scenarios, the user's question, that is, the operation function of the user for the Structured Query Language, can be combined with the database information extracted in the above steps and embedded into a predefined template. The template after embedding the operation function and database information is used as the prompt information and input into the dialogue model. Through the analysis of the dialogue model, the Structured Query Language required by the user is inferred, and the Structured Query Language is used as the model output of the dialogue model. It is returned to the interaction interface of the corresponding client device for display, that is, the model output is returned to the user.
[0142] As an alternative implementation, the method further includes: inputting the operation function and database information into an information generation template, and displaying the generated prompt information on the interaction interface, where the information generation template is used to represent the rules for generating prompt information in the query scenario corresponding to the Structured Query Language.
[0143] In this embodiment, the operation function type corresponding to the Structured Query Language to be generated can be determined, and the database information matching the operation function type can be obtained, where the operation function type can be used to represent the type to which the operation function belongs.
[0144] Optionally, according to the operation function type corresponding to the Structured Query Language to be generated, the database information corresponding to different operation function types is determined, and the database information can be sent to the corresponding interaction interface for display.
[0145] In the embodiment of the present application, since SQL statements have a variety of operation functions, and in data development, SQL statements with different operation functions may be required to assist in data development. Therefore, for SQL statements of different operation function types, corresponding database information needs to be configured. Thus, when the user needs to generate the required SQL statement, the user can select the corresponding operation function type according to their own choice to specifically handle the problem, and match the corresponding database information under the corresponding operation function type from the database, thereby improving the pertinence and accuracy of determining the database information.
[0146] As an alternative implementation, the method further includes: determining, in the query information sample set, the query information sample with the highest similarity to the query information, and determining, in the structured query language sample set, the structured query language sample corresponding to the query information sample, where the query information sample set and the structured query language sample set are used to train a dialogue model, and the query information sample is used to represent the semantics of the structured query language sample; step S406, on the interaction interface, displaying prompt information generated at least based on database information, including: on the interaction interface, displaying prompt information generated based on the structured query language sample, the query information sample, and the database information.
[0147] In this embodiment, in the query information sample set, the query information sample with the highest similarity to the query information can be determined, and in the structured query language sample set, the structured query language sample corresponding to the query information sample set can be determined. And the corresponding prompt information can be determined based on the structured query language sample, the query information sample, and the database information, and the prompt information can be sent to the interaction interface for display.
[0148] Optionally, during the model inference process, after zero-shot inference, few-shot inference can be performed. Before performing few-shot inference, based on the user's query problem, that is, natural language, similar query problems and the SQL statements corresponding to the query problems can be extracted from the training set, that is, natural language samples similar to the natural language presented by the current query problem can be determined from the natural language sample set in the training set, and the structured query language samples corresponding to the natural language samples can be determined from the structured query language sample set in the training set, obtaining a natural language sample-structured query language sample pair, that is, a query problem-SQL statement pair. Thus, during the few-shot inference process, the prompt information can be determined using the natural language sample-structured query language sample pair corresponding to the natural language sample with the highest similarity to the currently input natural language and the corresponding database information, and the prompt information is input into the dialogue model to help the dialogue model infer the structured query language corresponding to the current natural language.
[0149] As an alternative implementation, the method further includes: responding to a modification operation on the interaction interface to modify the query information sample set.
[0150] In this embodiment, the query information sample set can be displayed on the interaction interface. When it is detected that there is a modification operation on the interaction interface to modify the query information sample set, a corresponding modification instruction can be generated to modify the corresponding query information sample set, and the modified query information sample set is displayed.
[0151] The embodiment of the present application also provides a method for generating a Structured Query Language from the interaction side. Here, the interaction side can be a dialogue generation system, also known as a dialogue interface.
[0152] Figure 5 It is a flowchart of another method for generating a Structured Query Language according to the embodiment of the present application. As Figure 5 shown, the method may include the following steps:
[0153] Step S502, in response to the multimodal information received in the dialogue interface, where the multimodal information includes the query information corresponding to the Structured Query Language to be generated, and the query information is used to represent the semantics of the Structured Query Language to be generated.
[0154] In the technical solution provided in step S502 of the present application above, multimodal information can be input in the dialogue interface for communicating with the SQL assistant. Among them, the query information can be used to represent the semantics of the Structured Query Language to be generated. The multimodal information can include the query information corresponding to the Structured Query Language to be generated.
[0155] Optionally, when it is necessary to generate the required Structured Query Language, on the dialogue interface of the client device that can communicate with the SQL assistant, it is possible to communicate with the SQL assistant about the Structured Query Language that the enterprise wants to use for the data it wants to develop. Multimodal information that can express the required Structured Query Language can be input in the dialogue interface, and the multimodal information can be displayed in the dialogue interface.
[0156] Optionally, after the multimodal information is received in the dialogue interface, the required Structured Query Language of the user can be generated based on the multimodal information.
[0157] Step S504, display the database information matching the Structured Query Language to be generated in the dialogue interface, where the database information is used to represent the data structure required for performing the operation function corresponding to the converted Structured Query Language in the database.
[0158] In the technical solution provided in step S504 of the present application above, the database information matching the Structured Query Language to be generated can be displayed in the dialogue interface, where the database information can be used to represent the data structure required for performing the operation function corresponding to the converted Structured Query Language in the database.
[0159] Optionally, after inputting the multimodal information corresponding to the required structured query language on the dialogue interface, the multimodal information can be transmitted to the server through the dialogue interface for processing. In the server, the database information matching the structured query language can be determined, and the database information can be sent to the dialogue interface of the corresponding client device for display.
[0160] Step S506, on the dialogue interface, display the prompt information generated at least based on the database information.
[0161] In this embodiment, on the dialogue interface, the prompt information generated at least based on the database information can be displayed.
[0162] Optionally, through the server, the corresponding prompt information can be determined at least based on the database information, and sent to the dialogue interface of the corresponding client device for display.
[0163] Step S508, input the prompt information into the dialogue model, and use the dialogue model to analyze the query information and the database information in the prompt information, and output the structured query language.
[0164] In this embodiment, the prompt information can be used to prompt the dialogue model to generate the corresponding structured query language.
[0165] Optionally, based on the dialogue model with good evaluation performance, it can be used for auxiliary data development. The dialogue model is deployed in the server. When the prompt information gives a prompt to it, the process of starting to generate the structured query language by the dialogue model can be triggered. Through the dialogue model, the structured query language required by the user can be generated and sent to the corresponding dialogue interface.
[0166] Step S510, display the reply information generated based on the structured query language on the dialogue interface.
[0167] In this embodiment, after the dialogue interface receives the structured query language sent by the server, the reply information generated based on the structured query language can be displayed on the dialogue interface.
[0168] Through the above steps S502 to S510 of the present application, in response to the multimodal information received in the dialogue interface, where the multimodal information includes the natural language corresponding to the structured query language to be generated, and the natural language is used to represent the semantics of the structured query language to be generated; display the database information matching the structured query language to be generated in the dialogue interface, where the database information is used to represent the data structure required to execute the operation function corresponding to the structured query language converted in the database; display at least the prompt information generated based on the database information on the dialogue interface; use the prompt information to prompt the dialogue model to generate the structured query language; and display the reply information generated based on the structured query language on the dialogue interface, thereby achieving the technical effect of being able to effectively generate the structured query language and solving the technical problem of being unable to effectively generate the structured query language.
[0169] The above method of this embodiment will be further introduced below.
[0170] As an optional implementation manner, the types of multimodal information include at least one of the following: text information containing character information, video frame information containing frame image information, and audio information, and the types of reply information include at least one of the following: text information, image information, video information, and voice information.
[0171] In this embodiment, the types of multimodal information may at least include one of the following: text information containing character information, video frame information containing frame images, and audio information. It should be noted that the above types of multimodal information are only for illustrative purposes and are not specifically limited here.
[0172] According to the embodiment of the present application, on the upper-layer software service side based on the computing edge, a data generation method is also provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here.
[0173] Figure 6 is a flowchart of another method for generating a structured query language according to an embodiment of the present application. As Figure 6 shown, the method may include the following steps:
[0174] Step S602, detecting the query information to be converted by calling the first interface, where the first interface includes a first parameter, and the parameter value of the first parameter is the query information, and the query information is used to represent the semantics of the structured query language to be converted.
[0175] In the technical solution provided in step S602 of the present application, a first interface can be called to detect whether there is query information to be converted on the interaction interface. Among them, the first interface can include a first parameter, and the parameter value of the first parameter can be the query information, and the query information is used to represent the semantics of the structured query language to be converted to.
[0176] Step S604, obtain database information that matches the structured query language to be converted, where the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language to be converted in the database.
[0177] In the technical solution provided in step S604 of the present application, database information that matches the structured query language to be converted can be obtained, where the database information can be used to represent the data structure required for performing the operation function corresponding to the structured query language to be converted in the database.
[0178] Optionally, after obtaining the query information about a certain structured query language in the interaction interface, the query information can be transmitted to the server for processing. The server can call the database to screen out the data structures that match the SQL statement required by the query information from a large number of data structures in the database, that is, screen out the tables and fields that are beneficial to generating the SQL statement from a large number of tables and fields in the database.
[0179] Optionally, in the model inference process included in the automated conversion method of NL2SQL, database information screening can be performed, that is, a table and field screening model can be used to screen the automatically obtained DDL, and extract the tables and fields that are beneficial to generating the corresponding SQL from a large number of DDLs as the model input.
[0180] Step S606, generate prompt information based on at least the database information.
[0181] In the technical solution provided in step S606 of the present application, prompt information can be generated based on at least the database information.
[0182] Optionally, in the model inference process included in the automated conversion method of NL2SQL, after performing database information screening, zero-shot inference can be performed. During the zero-shot inference process, prompt information can be generated first.
[0183] Step S608, input the prompt information into the dialogue model, and use the dialogue model to analyze the query information and database information in the prompt information, and output the structured query language.
[0184] In the technical solution provided in step S608 of the present application, a prompt message can be used to prompt the dialogue model to convert the query information in the prompt message into a structured query language.
[0185] Optionally, in the process of data organization and model training, the pre-trained code language model can be fine-tuned in a supervised manner so that the model has the ability of NL2SQL to obtain a trained dialogue model. After training is completed, model evaluation can be performed. That is, in the model evaluation process, based on the trained dialogue model, its effect can be tested on a standard data set to evaluate the performance of the dialogue model. If the evaluation result passes, the dialogue model can be put into normal use. That is, the dialogue model can be deployed to the server to generate a structured query language based on the query information.
[0186] Step S610, output a structured query language by calling a second interface, where the second interface includes a second parameter, and the parameter value of the second parameter is the structured query language.
[0187] In the technical solution provided in step S610 of the present application, a structured query language can be output by calling a second interface, where the second interface may include a second parameter, and the parameter value of the second parameter may be the structured query language.
[0188] Through steps S602 to S610 of the present application, a natural language to be converted is detected by calling a first interface, where the first interface includes a first parameter, and the parameter value of the first parameter is the natural language, and the natural language is used to represent the semantics of the structured query language to be converted; database information matching the structured query language to be converted is obtained, where the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language to be converted in the database; at least based on the database information, a prompt message is generated; the prompt message is used to prompt the dialogue model to convert the natural language into a structured query language; a structured query language is output by calling a second interface, where the second interface includes a second parameter, and the parameter value of the second parameter is the structured query language, thereby achieving the technical effect of being able to effectively generate a structured query language and solving the technical problem of being unable to effectively generate a structured query language.
[0189] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present application are all information and data authorized by the user or fully authorized by all parties, and the collection, use, and processing of relevant data need to comply with the relevant laws, regulations, and standards of relevant countries and regions, and corresponding operation entrances are provided for users to choose to authorize or refuse.
[0190] It should be noted that for the foregoing method embodiments, for the sake of simple description, they are all expressed as a series of action combinations. However, those skilled in the art should be aware that this application is not limited by the described action sequence, because according to this application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0191] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on such an understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disc), and includes several instructions for causing a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods of various embodiments of this application.
[0192] Embodiment 2
[0193] Currently, in the era of big data, data development has become an important task for enterprises. This project aims to help data developers form SQL statements in data development through natural language and improve production efficiency. In the related art, only a traditional NL2SQL model can be used to determine SQL. This model only determines the SQL statement based on the mapping between NL and the SQL statement. However, it lacks the modeling of database information that matches the SQL statement, resulting in being divorced from reality and being difficult to apply to actual data development. Therefore, there is still a technical problem of being unable to effectively convert data.
[0194] Optionally, this application provides a text-to-SQL conversion method based on a large language model. This method solves the technical problem of being unable to effectively convert data. Different from the traditional solution that does not model the database information that matches the SQL statement, it avoids the technical problem of being unable to effectively convert data caused by being divorced from reality and being difficult to apply to actual data development, and solves the technical problem of being unable to effectively convert data.
[0195] In an embodiment of the present application, after detecting that there is natural language to be converted into Structured Query Language (SQL) in the interaction interface of a certain client, the natural language can be transmitted from the client to the cloud. Based on the natural language, the cloud can determine, from a database, the data structure required for the operation function executed when the SQL corresponding to the natural language is executed, and generate prompt information corresponding to the SQL based on the matched data structure. The cloud can use the prompt information to prompt the dialogue model to generate the required corresponding SQL, and can transmit it to the interaction interface of the corresponding client for display.
[0196] Since the present application can further model the database information corresponding to the structured information, avoiding the abnormal situations that occur in the above-mentioned related technologies, it thus achieves the purpose of improving the accuracy of the required generated structured information and the degree of fitting with the actual application, and further realizes the technical effect of effectively converting data, and solves the technical problem of being unable to effectively convert data.
[0197] The above method of this embodiment will be further introduced below.
[0198] In this embodiment, an automated conversion method for realizing the conversion from natural language to SQL (NL2SQL) is constructed by using a pre-trained code language model. This method mainly relies on the basic understanding ability of the large language model, including the understanding of natural language and code. This method mainly relies on the following components: data organization, model training, model evaluation, and model inference.
[0199] In this embodiment, in order to solve the numerous problems existing in the related technology only through the mapping between NL and SQL, the embodiments of the present application can organize the existing open-source data so that the dialogue model can learn the rules from the rich information in the open-source data. Thus, the NLSQL data is organized into the form of NL + DDL to SQL, enabling the dialogue model to learn sufficient knowledge from NL and DDL, and then generating the corresponding SQL statement based on this can ensure that the SQL statement is more accurate.
[0200] Optionally, during the process of data organization, the acquisition and conversion of open-source data can be performed. During the acquisition and conversion of open-source data, open-source NLSQL data can be used, and the generation of open-source structured query language in a form other than the data warehouse tool (Hive) can be converted into the Hive form, including DDL statements and SQL statements.
[0201] Optionally, during the process of data organization, after obtaining and transforming open-source data, an automated generation process for application function data can be carried out. During this process, the existing SQL statements in the application function data can be classified according to their operation functions, and several SQL statements under each category can be extracted for backup.
[0202] Optionally, after extracting several SQL statements from each category for backup, a SQL dialogue model trained based on open-source data can be used to generate natural language descriptions to form NL2SQL data pairs for application function data. For the NL2SQL data pairs of application function data, manual verification and modification are required to ensure their accuracy.
[0203] For example, Figure 7 is a schematic diagram of a SQL classification result according to an embodiment of the present application. As Figure 7 shown, when classifying SQL, it can be divided into the following six categories: 1) Data query language category; 2) Database schema definition language category; 3) Data manipulation language category; 4) Script language category; 5) Data control language category; 6) Command category. It should be noted that the number and types of the above SQL classifications are only for illustrative purposes and are not specifically limited here.
[0204] For another example, as Figure 7As shown, the DQL class can include the following statements: CTE Select statements (e.g., WITH SELECT), basic query Select statements (e.g., "Select", select distinct, Select fields, and Select From Table), branch statements (e.g., Case WHEN), aggregate functions (e.g., SUM, COUNT, AVG, MIN, MAX, and Having), built-in functions (e.g., max_pt), window functions (e.g., WINDOW, OVER, FILTER, and Row_Number), QUALIFY statements (e.g., QUALIFY), transformation PIVOT statements (e.g., PIVOT and UNPIVOT), subquery statements (e.g., a Select statement nested within a Select statement), join Select statements (e.g., INNER JOIN, LEFTJOIN, RIGHT JOIN, FULL OUTER JOIN, and SEMI JOIN), Union Select statements (e.g., intersect, union, except, and minus), conditional query Select statements (e.g., WHERE and partitioning and non-partitioning), sorting Select statements (e.g., ORDER BY), grouping Select statements (e.g., GROUP BY), and limiting Select statements (e.g., LIMIT). Among them, WHERE can include LIKE, RLIKE, REGEXP, IN, NOT IN, BETWEEN, IS NULL, IS NOTNULL, NOT, =, AND, OR, >, >=, <, and <=. ORDER BY can include DESC and ASC.
[0205] As an optional example, as Figure 7 shown, the DDL class can include the following statements: CREATE statements (e.g., Create Table and Create Function), ALTER statements (e.g., ALTER TABLE), DROP statements (e.g., DROP TABLE and DROP FUNCTION). Among them, Create Table can include Create Non PartitionTable, Create Partition Table, and Create External Table.
[0206] For example, as Figure 7As shown, the following statements can be included in the DML class: INSERT statements (e.g., INSERT INTO and INSERT OVERWRITE), UPDATE statements (e.g., UPDATE SET), DELETE statements (e.g., DELETE), and MERGE statements (e.g., MERGE INTO). The following statements can be included in the TCL class: COMMIT and ROLLBACK. The following statements can be included in the DCL class: GRANT and REVOKE. The following statement can be included in the COMMAND class: SET.
[0207] In this embodiment, after the data organization process is completed, the model training process can be started. In this process, based on the classified database information sample set, the large model can be supervised trained, that is, supervised fine-tuned, to obtain a dialogue model with NL2SQL capabilities.
[0208] Optionally, supervised fine-tuning is performed based on the pre-trained language model Starcoder, so that the model obtains NL2SQL capabilities and becomes a dialogue model.
[0209] Optionally, after the model training, the model evaluation process is started. In this process, based on the trained dialogue model, its effect can be tested on a standard data set to evaluate the performance of the dialogue model. If the evaluation result passes, the dialogue model can be put into normal use, that is, the dialogue model can be deployed to the server for generating structured query language based on the query information.
[0210] Optionally, based on the NL2SQL model with good evaluation performance, it can be used for auxiliary data development. The NL2SQL model is deployed in the server. When a prompt message is sent to it, the NL2SQL model can be triggered to start the process of generating SQL statements. The SQL statements required by the user can be generated by the NL2SQL model and sent to be displayed on the corresponding interaction interface.
[0211] In this embodiment, after the model evaluation process is completed, model inference can be started.
[0212] Optionally, during the database information screening process in the model inference process, according to the different needs of users in different query scenarios, the questions raised by the different needs of users, that is, the selection of the operation functions of the structured query language by users, can use a table and field screening model to automatically screen and extract from the database the database information beneficial to generating the SQL statements required by the user, that is, tables and fields. Use this as the model input of the dialogue model. For example, use the table and field screening model to screen the automatically obtained DDL, and extract the tables and fields beneficial to generating SQL as the model input.
[0213] Optionally, after the database information screening process is completed, a zero-shot inference process can be carried out. During this process, according to the different needs of users in different query scenarios, the user's question, that is, the operation function of the user for the structured query language, combined with the database information extracted in the above steps, can be embedded into a predefined template, and the template with the operation function and database information embedded is used as the prompt information and input into the dialogue model. Through the analysis of the dialogue model, the structured query language required by the user is inferred, and the structured query language is used as the model output of the dialogue model. Return it to the interactive interface of the corresponding client device for display, that is, return the model output to the user.
[0214] For example, SQL generation prompt: Given the following Maxcompute database information: ${schema}, answer the question (if it is a partitioned table, add partition field conditions): ${prompt}. SQL error correction prompt: Please repair the bug of the SQL according to the requirements of ${prompt} based on the Maxcompute SQL syntax rules: ```sql\n${schema}. SQL comment writing prompt: Please write comments for the following maxcompute sql: ```sql\n${schema}\n``` and keep the original sql: ${prompt}. SQL rewriting prompt: Given the following sql: ```sql\n${schema}\n```, and modify it according to the Maxcompute sql syntax rules and return: ${prompt}. SQL extraction prompt: Given the following text content: ${prompt}, extract the sql and return it. It should be noted that the above are only examples of Prompts corresponding to several SQL functions, where schema is the DDL or SQL statement, and prompt is obtained according to the user's selection, that is, prompt is the user input.
[0215] Optionally, during the model inference process, after zero-shot inference, few-shot inference can be performed. Before performing few-shot inference, based on the user's query question, that is, the information being asked, similar query questions to this query question and the SQL statements corresponding to this query question can be extracted from the training set. That is, natural language samples similar to the natural language presented by the current query question are determined from the natural language sample set in the training set, and the structured query language samples corresponding to this natural language sample are determined from the structured query language sample set in the training set, obtaining a natural language sample-structured query language sample pair, that is, a query question-SQL statement pair. Thus, during the few-shot inference process, the prompt information can be determined using the natural language sample-structured query language sample pair corresponding to the natural language sample with the highest similarity to the currently input natural language and the corresponding database information, and the prompt information is input into the dialogue model to help the dialogue model infer the structured query language corresponding to the current natural language.
[0216] For example, Figure 8 is a schematic diagram of a model inference according to an embodiment of the present application, as Figure 8 shown. According to different user requirements, that is, user selections, for example, the user can select SQL generation, SQL correction, SQL annotation writing, SQL rewriting, or SQL answering questions. The user selection can be processed for the question, such as looking up a table or Prompting, and can be embedded into a predefined template to generate prompt information, and the prompt information can be output, and the prompt information can be input into the SQL dialogue model for inference, and the output of the model is returned to the user. That is, a structured query language can be generated and the structured query language can be output to the client device.
[0217] For another example, the prompt information can be as follows: <|system|> The following is a dialogue between the SQL assistant and a human. The assistant answers questions based on the human's questions and only needs to output the SQL statement. The SQL is returned in markdown code format without generating redundant information. <|user|> The model can answer questions based on the following several similar examples: \nAnswer the following question: {similar question 1}\n{SQL statement corresponding to question 1}\nAnswer the following question: {similar question 2}\n{SQL statement corresponding to question 2}\nAnswer the following question: {similar question 3}\n{SQL statement corresponding to question 3}\nGiven the following database information: {table information}, answer the SQL query question: {user question}. <|bot|>.
[0218] It should be noted that the preferred implementation schemes involved in the above embodiments of the present application are the same as the schemes, application scenarios, and implementation processes provided in Embodiment 1, but are not limited to the schemes provided in Embodiment 1.
[0219] Example 3
[0220] According to an embodiment of the present application, a system for generating a Structured Query Language is further provided. Figure 9 is a schematic diagram of a system for generating a Structured Query Language according to an embodiment of the present application. As Figure 9 shown, the system for generating a Structured Query Language may include: an input end 902, a processing end 904, and a model inference end 906.
[0221] The input end 902 is used to input query information to be converted, where the query information is used to represent the semantics of the Structured Query Language to be converted.
[0222] In the technical solution provided by the input end 902 of the present application above, natural language to be converted may be input through the input end 902, where the natural language may be used to represent the semantics of the Structured Query Language to be converted.
[0223] Optionally, it is detected whether there is natural language to be converted in the interaction interface. When it is detected that there is natural language to be converted, the natural language may be transmitted to the processing end 904 through the input end 902 for processing.
[0224] The processing end 904 is used to obtain database information matching the Structured Query Language to be converted, and generate prompt information at least based on the database information, where the database information is used to represent the data structure required for performing the operation function corresponding to the Structured Query Language to be converted in the database.
[0225] In the technical solution provided by the processing end 904 of the present application above, the natural language is processed by the processing end 904 to determine the database information matching the Structured Query Language to be converted, and prompt information may be generated at least based on the database information, where the database information may be used to represent the data structure required for performing the operation function corresponding to the Structured Query Language to be converted in the database.
[0226] Optionally, after obtaining the natural language about a certain Structured Query Language in the interaction interface, the natural language may be processed, and the data structure matching the SQL statement required by the natural language may be screened out from a large number of data structures in the database by calling the database, that is, the tables and fields beneficial to generating the SQL statement are screened out from a large number of tables and fields in the database.
[0227] Optionally, in the model inference process included in the automated conversion method of NL2SQL, after screening the database information, zero-shot inference may be performed. During the zero-shot inference process, prompt information may be generated.
[0228] Optionally, corresponding prompt messages can be generated for different operation functions. For example, for the function of SQL generation, for the database information matched based on the query information in the server, that is, for the given database information, the corresponding prompt messages can be determined by answering questions.
[0229] The model inference end 906 is used to input the prompt messages into the dialogue model, and analyze the query information and database information in the prompt messages by using the dialogue model, and output a structured query language.
[0230] In the technical solution provided by the model inference end 906 of the present application, the prompt messages can be used to prompt the dialogue model through the model inference end to generate a structured query language.
[0231] Optionally, based on the NL2SQL model with good evaluation performance, it can be used for auxiliary data development. The NL2SQL model is deployed in the server. When the prompt messages give prompts to it, the NL2SQL model can be triggered to start the process of generating SQL statements. The SQL statements required by the user can be generated through the NL2SQL model and sent to the corresponding interaction interface for display.
[0232] Through the structured query language generation system of the present application, through the input end, the natural language to be converted is input, where the natural language is used to represent the semantics of the structured query language to be converted; through the processing end, the database information matching the structured query language to be converted is obtained, and at least based on the database information, prompt messages are generated, where the database information is used to represent the data structure required to execute the operation function corresponding to the structured query language to be converted in the database; through the model inference end, the prompt messages are used to prompt the dialogue model to convert the natural language into a structured query language. Thus, the technical effect of effectively generating a structured query language is achieved, and the technical problem of being unable to effectively generate a structured query language is solved.
[0233] Embodiment 4
[0234] According to the embodiments of the present application, there is also provided a structured query language generation device for implementing the structured query language generation method shown above. Figure 2 The structured query language generation device shown above.
[0235] Figure 10 It is a schematic diagram of a structured query language generation device according to an embodiment of the present application. As Figure 10 shown, the structured query language generation device 1000 may include: a first detection unit 1002, a first acquisition unit 1004, a first generation unit 1006, and a first conversion unit 1008.
[0236] The first detection unit 1002 is configured to detect the query information to be converted from the client, where the query information is used to represent the semantics of the structured query language to which it is to be converted.
[0237] The first acquisition unit 1004 is configured to acquire database information that matches the structured query language to which it is to be converted, where the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language to which it is to be converted in the database.
[0238] The first generation unit 1006 is configured to generate prompt information based at least on the database information.
[0239] The first conversion unit 1008 is configured to input the prompt information into the dialogue model, and analyze the query information and the database information in the prompt information by using the dialogue model, and output the structured query language.
[0240] It should be noted here that the above-mentioned first detection unit 1002, first acquisition unit 1004, first generation unit 1006, and first conversion unit 1008 correspond to steps S202 to S208 in Embodiment 1. The instances and application scenarios realized by the four units and the corresponding steps are the same, but are not limited to the content disclosed in the above-mentioned Embodiment 1. It should be noted that the above units may be hardware components or software components stored in the memory and processed by one or more processors, and the above units may also be part of the device and can run in the computer terminal provided in Embodiment 5.
[0241] According to an embodiment of the present application, there is also provided a model generation device for implementing the Figure 3 model generation method of the model shown above.
[0242] Figure 11 is a schematic diagram of a model generation device according to an embodiment of the present application. As Figure 11 shown, the model generation device 1100 may include: a second acquisition unit 1102, a first processing unit 1104, and a first training unit 1106.
[0243] The second acquisition unit 1102 is configured to acquire a database information sample set corresponding to the structured query language sample set.
[0244] The first processing unit 1104 is configured to input the database information sample set into the initial dialogue model, and analyze the database information sample set by using the initial dialogue model, and output an inquiry information sample set corresponding to the structured query sample set, where the initial dialogue model is trained at least based on the initial structured query sample set, and the inquiry information samples in the inquiry information sample set are used to represent the semantics of the corresponding structured query language samples in the structured query language sample set.
[0245] The first training unit 1106 is configured to train the large model based on the database information sample set and the inquiry information sample set to obtain a dialogue model, where the dialogue model is used to analyze the inquiry information and the database information in the prompt information to generate a structured query language, the prompt information is generated at least based on the database information matching the structured query language, the inquiry information is used to represent the semantics of the structured query language, and the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language in the database.
[0246] It should be noted here that the above-mentioned second acquisition unit 1102, the first processing unit 1104, and the first training unit 1106 correspond to steps S302 to S306 in Embodiment 1. The instances and application scenarios implemented by the three units and the corresponding steps are the same, but are not limited to the content disclosed in the above-mentioned Embodiment 1. It should be noted that the above-mentioned units may be hardware components or software components stored in a memory and processed by one or more processors, and the above-mentioned units may also be part of a device and may run in the computer terminal provided in Embodiment 5.
[0247] According to an embodiment of the present application, there is also provided a structured query language generation device for implementing the Figure 4 structured query language generation method shown above.
[0248] Figure 12 is a schematic diagram of a structured query language generation device according to an embodiment of the present application. As Figure 12 shown, the structured query language generation device 1200 may include: a second detection unit 1202, a first display unit 1204, a second display unit 1206, and a third display unit 1208.
[0249] The second detection unit 1202 is configured to detect the inquiry information received in the interaction interface, where the inquiry information is used to represent the semantics of the structured query language to be generated.
[0250] The first display unit 1204 is configured to, in response to the inquiry information, display the database information matching the structured query language to be generated in the interaction interface, where the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language to be generated in the database.
[0251] A second display unit 1206, configured to display prompt information generated at least based on database information on the interaction interface.
[0252] A third display unit 1208, configured to input the prompt information into a dialogue model, and display on the interaction interface a structured query language obtained by analyzing the query information and database information in the prompt information by using the dialogue model.
[0253] It should be noted here that the above-mentioned second detection unit 1202, first display unit 1204, second display unit 1206, and third display unit 1208 correspond to steps S402 to S408 in Embodiment 1. The instances and application scenarios implemented by the four units and the corresponding steps are the same, but are not limited to the content disclosed in the above-mentioned Embodiment 1. It should be noted that the above-mentioned units may be hardware components or software components stored in a memory and processed by one or more processors, and the above-mentioned units may also be part of a device and may run in the computer terminal provided in Embodiment 5.
[0254] According to an embodiment of the present application, there is also provided a structured query language generation device for implementing the above Figure 5 structured query language generation method shown.
[0255] Figure 13 is a schematic diagram of another structured query language generation device according to an embodiment of the present application. As Figure 13 shown, the structured query language generation device 1300 may include: a first receiving unit 1302, a fourth display unit 1304, a fifth display unit 1306, a second generation unit 1308, and a sixth display unit 1310.
[0256] The first receiving unit 1302 is configured to respond to multimodal information received in the dialogue interface, where the multimodal information includes query information corresponding to the structured query language to be generated, and the query information is used to represent the semantics of the structured query language to be generated.
[0257] The fourth display unit 1304 is configured to display database information matching the structured query language to be generated in the dialogue interface, where the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language converted in the database.
[0258] The fifth display unit 1306 is configured to display prompt information generated at least based on database information on the dialogue interface.
[0259] A second generation unit 1308 is configured to input the prompt information into the dialogue model, and analyze the query information and database information in the prompt information by using the dialogue model, and output a structured query language.
[0260] A sixth display unit 1310 is configured to display, on the dialogue interface, a reply message generated based on the structured query language.
[0261] It should be noted here that the above first receiving unit 1302, fourth display unit 1304, fifth display unit 1306, second generation unit 1308, and sixth display unit 1310 correspond to steps S502 to S510 in Embodiment 1. The functions implemented by the five units and the corresponding steps have the same examples and application scenarios, but are not limited to the content disclosed in the above Embodiment 1. It should be noted that the above units may be hardware components or software components stored in a memory and processed by one or more processors, and the above units may also be part of a device and may run in the computer terminal provided in Embodiment 5.
[0262] According to an embodiment of the present application, there is also provided a structured query language generation device for implementing the structured query language generation method shown above. Figure 6
[0263] Figure 14 It is a schematic diagram of another structured query language generation device according to an embodiment of the present application. As Figure 14 shown, the structured query language generation device 1400 may include: a first call unit 1402, a third acquisition unit 1404, a third generation unit 1406, a second conversion unit 1408, and a second call unit 1410.
[0264] The first call unit 1402 is configured to detect the query information to be converted by calling a first interface, where the first interface includes a first parameter, and the parameter value of the first parameter is the query information, and the query information is used to represent the semantics of the structured query language to be converted to.
[0265] The third acquisition unit 1404 is configured to acquire database information matching the structured query language to be converted, where the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language to be converted in the database.
[0266] The third generation unit 1406 is configured to generate prompt information based at least on the database information.
[0267] The second conversion unit 1408 is configured to input the prompt information into the dialogue model, and analyze the query information and database information in the prompt information by using the dialogue model, and output a structured query language.
[0268] A second calling unit 1410, configured to output a Structured Query Language (SQL) by calling a second interface, where the second interface includes a second parameter, and the parameter value of the second parameter is the Structured Query Language (SQL).
[0269] It should be noted here that the above first calling unit 1402, third obtaining unit 1404, third generating unit 1406, second conversion unit 1408, and second calling unit 1410 correspond to steps S602 to S610 in Embodiment 1. The functions and application scenarios implemented by the five units and the corresponding steps are the same, but are not limited to the content disclosed in the above Embodiment 1. It should be noted that the above units may be hardware components or software components stored in a memory and processed by one or more processors, and the above units may also be part of a device and can run in the computer terminal provided in Embodiment 5.
[0270] In the above device, when a client needs a Structured Query Language (SQL) to assist in data development, corresponding semantics capable of generating the Structured Query Language (SQL), that is, the query information corresponding to the Structured Query Language (SQL), can be input on the interaction interface of the client. After detecting that there is query information to be converted into a Structured Query Language (SQL) in the interaction interface of a certain client, the query information can be transmitted from the client to the cloud. Based on the query information, the cloud can determine, from the database, the data structure required for the operation function when executing the Structured Query Language (SQL) corresponding to the query information, that is, the database information matching the Structured Query Language (SQL), and can be transmitted to the interaction interface of the corresponding client for display. The cloud can generate, at least based on the database information, a prompt information corresponding to the Structured Query Language (SQL), and can be transmitted to the interaction interface of the corresponding client for display. The cloud can use the prompt information to prompt the dialogue model to generate the required Structured Query Language (SQL) accordingly, and can be transmitted to the interaction interface of the corresponding client for display. Considering that in the related art, generating a Structured Query Language (SQL) only based on the mapping between query information and the Structured Query Language (SQL) may result in a situation that is divorced from reality and difficult to apply, this application can further model the database information corresponding to the structured information, avoiding the abnormal situation that appears in the above related art, thereby achieving the purpose of improving the accuracy of the required generated structured information and the degree of fitting with the actual application, and further achieving the technical effect of effectively generating a Structured Query Language (SQL), and solving the technical problem of being unable to effectively generate a Structured Query Language (SQL).
[0271] Embodiment 5
[0272] Embodiments of the present application may provide a computer terminal, which may be any computer terminal device in a computer terminal group. Optionally, in this embodiment, the above computer terminal may also be replaced with a terminal device such as a mobile terminal.
[0273] Optionally, in this embodiment, the above computer terminal may be located in at least one of multiple network devices in a computer network.
[0274] In this embodiment, the above computer terminal may execute the program code of the following steps in the method for generating a structured query language: detecting the query information to be converted from a client, where the query information is used to represent the semantics of the structured query language to be converted; obtaining database information that matches the structured query language to be converted, where the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language to be converted in the database; generating prompt information based at least on the database information; inputting the prompt information into a dialogue model, and using the dialogue model to analyze the query information and database information in the prompt information to output a structured query language.
[0275] Optionally, Figure 15 is a structural block diagram of a computer terminal according to an embodiment of the present application. As Figure 15 shown, the computer terminal A may include: one or more (only one is shown in the figure) processors 1502, a memory 1504, a storage controller, and a peripheral interface, where the peripheral interface is connected to a radio frequency module, an audio module, and a display.
[0276] Among them, the memory can be used to store software programs and modules, such as the program instructions / modules corresponding to the method and device for generating a structured query language in the embodiments of the present application. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, that is, implements the above method for generating a structured query language. The memory may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memories, or other non-volatile solid-state memories. In some instances, the memory may further include a memory remotely provided with respect to the processor, and these remote memories may be connected to the computer terminal A through a network. Examples of the above network include but are not limited to the Internet, an enterprise intranet, a local area network, a mobile communication network, and combinations thereof.
[0277] The processor may call the information and application programs stored in the memory through a transmission device to execute the following steps: determining the operation function type corresponding to the structured query language to be generated; obtaining database information that matches the operation function type.
[0278] Optionally, the above-mentioned processor may also execute the program code of the following steps: generate a template using information, and generate a prompt message from the operation function and database information.
[0279] Optionally, the above-mentioned processor may also execute the program code of the following steps: in the query information sample set, determine the query information sample with the highest similarity to the query information, and in the structured query language sample set, determine the structured query language sample corresponding to the query information sample, where the query information sample set and the structured query language sample set are used to train a dialogue model, and the query information sample is used to represent the semantics of the structured query language sample; generate a prompt message based on the structured query language sample, the query information sample, and the database information.
[0280] Optionally, the above-mentioned processor may also execute the program code of the following steps: use a similarity model to determine a query information sample in the query information sample set, where the similarity model is used to determine the output data with the highest similarity to the input data.
[0281] Optionally, the above-mentioned processor may also execute the program code of the following steps: output the structured query language to the client.
[0282] As another alternative example, the processor may call the information and application programs stored in the memory through a transmission device to execute the following steps: obtain a database information sample set corresponding to the structured query language sample set; input the database information sample set into an initial dialogue model, and use the initial dialogue model to analyze the database information sample set, and output a query information sample set corresponding to the structured query language sample set, where the initial dialogue model is trained at least based on an initial structured query language sample set, and the query information samples in the query information sample set are used to represent the semantics of the corresponding structured query language samples in the structured query language sample set; train a large model based on the database information sample set and the query information sample set to obtain a dialogue model, where the dialogue model is used to analyze the query information and database information in the prompt message to generate a structured query language, the prompt message is generated at least based on the database information matching the structured query language, the query information is used to represent the semantics of the structured query language, and the database information is used to represent the data structure required to execute the operation function corresponding to the structured query language in the database.
[0283] Optionally, the above-mentioned processor may also execute the program code of the following steps: classify the database information sample set according to the operation functions corresponding to the structured query language sample set in the database; use the initial dialogue model to analyze the classified database information sample set, and output a query information sample set corresponding to the structured query language sample set.
[0284] Optionally, the above-mentioned processor may also execute the program code of the following steps: Based on the classified database information sample set and the query information sample set, perform supervised training on the large model to obtain a dialogue model.
[0285] Optionally, the above-mentioned processor may also execute the program code of the following steps: Based on the initial structured query language sample set of data types matching different operation functions, train to obtain an initial dialogue model.
[0286] As another alternative example, the processor may call the information and application programs stored in the memory through the transmission device to execute the following steps: Detect the query information received in the interaction interface, where the query information is used to represent the semantics of the structured query language to be generated; In response to the query information, display the database information matching the structured query language to be generated in the interaction interface, where the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language to be generated in the database; On the interaction interface, display the prompt information generated at least based on the database information; Input the prompt information into the dialogue model, and display the structured query language obtained by analyzing the query information and the database information in the prompt information by using the dialogue model on the interaction interface.
[0287] Optionally, the above-mentioned processor may also execute the program code of the following steps: Determine the operation function type corresponding to the structured query language to be generated; Display the database information matching the operation function type in the interaction interface.
[0288] Optionally, the above-mentioned processor may also execute the program code of the following steps: Input the operation function and the database information into the information generation template, and display the generated prompt information on the interaction interface.
[0289] Optionally, the above-mentioned processor may also execute the program code of the following steps: In the query information sample set, determine the query information sample with the highest similarity to the query information, and in the structured query language sample set, determine the structured query language sample corresponding to the query information sample, where the query information sample set and the structured query language sample set are used to train the dialogue model, and the query information sample is used to represent the semantics of the structured query language sample; On the interaction interface, display the prompt information generated at least based on the database information, including: On the interaction interface, display the prompt information generated based on the structured query language sample, the query information sample, and the database information.
[0290] Optionally, the above-mentioned processor may also execute the program code of the following steps: In response to the modification operation on the interaction interface, modify the query information sample set.
[0291] As another alternative example, the processor can call the information and application programs stored in the memory through the transmission device to perform the following steps: in response to the multimodal information received in the dialogue interface, where the multimodal information includes the query information corresponding to the structured query language to be generated, and the query information is used to represent the semantics of the structured query language to be generated; display in the dialogue interface the database information matching the structured query language to be generated, where the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language converted to in the database; display on the dialogue interface the prompt information generated at least based on the database information; input the prompt information into the dialogue model, and use the dialogue model to analyze the query information and database information in the prompt information, and output the structured query language; display on the dialogue interface the response information generated based on the structured query language.
[0292] Optionally, the above processor can also execute the program code of the following steps: the types of the multimodal information include at least one of the following: text information containing character information, video frame information containing frame image information, audio information, and the types of the response information include at least one of the following: text information, image information, video information, and voice information
[0293] As another alternative example, the processor can call the information and application programs stored in the memory through the transmission device to perform the following steps: detect the query information to be converted by calling the first interface, where the first interface includes a first parameter, and the parameter value of the first parameter is the query information, and the query information is used to represent the semantics of the structured query language to be converted to; obtain the database information matching the structured query language to be converted to, where the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language to be converted to in the database; generate the prompt information at least based on the database information; input the prompt information into the dialogue model, and use the dialogue model to analyze the query information and database information in the prompt information, and output the structured query language; output the structured query language by calling the second interface, where the second interface includes a second parameter, and the parameter value of the second parameter is the structured query language.
[0294] With the embodiments of the present application, when a client needs Structured Query Language (SQL) to assist in data development, the corresponding semantics capable of generating the SQL can be input on the interaction interface of the client, that is, the query information corresponding to the SQL. After detecting that there is query information to be converted into SQL in the interaction interface of a certain client, the query information can be transmitted from the client to the cloud. Based on the query information, the cloud can determine from the database the data structure required for the operation function when executing the SQL corresponding to the query information, that is, the database information matching the SQL, and can be transmitted to the interaction interface of the corresponding client for display. The cloud can generate prompt information corresponding to the SQL at least based on the database information, and can be transmitted to the interaction interface of the corresponding client for display. The cloud can use the prompt information to prompt the dialogue model to generate the required SQL, and can be transmitted to the interaction interface of the corresponding client for display. Considering that in the related art, generating SQL only based on the mapping between natural language and SQL may result in a situation that is divorced from reality and difficult to apply, the present application can further model the database information corresponding to the structured information, avoiding the abnormal situation in the above-mentioned related art, thereby achieving the purpose of improving the accuracy of the required generated structured information and the degree of fitting with actual applications, and further realizing the technical effect of effectively generating SQL, and solving the technical problem of being unable to effectively generate SQL.
[0295] Those of ordinary skill in the art can understand that Figure 15 the structure shown is only illustrative, and the computer terminal can also be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a palm computer, and a Mobile Internet Devices (MID), a PAD and other terminal devices. Figure 15 It does not limit the structure of the above electronic device. For example, computer terminal A may further include more or fewer components (such as a network interface, a display device, etc.) than those shown Figure 15 in, or have a different configuration from that shown Figure 15 .
[0296] Those of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the relevant hardware of the terminal device through a program, and the program can be stored in a computer-readable storage medium. The storage medium can include: a flash drive, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disc, etc.
[0297] Example 6
[0298] An embodiment of the present application further provides a computer-readable storage medium. Optionally, in this embodiment, the above computer-readable storage medium may be used to store the program code executed by the method for generating a structured query language provided in the first embodiment above.
[0299] Optionally, in this embodiment, the above storage medium may be located in any one of the computer terminals in the computer terminal group in the computer network, or in any one of the mobile terminals in the mobile terminal group.
[0300] Optionally, in this embodiment, the storage medium is set to store program code for performing the following steps: detecting the query information to be converted from the client, where the query information is used to represent the semantics of the structured query language to be converted; obtaining database information matching the structured query language to be converted, where the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language to be converted in the database; generating prompt information based at least on the database information; inputting the prompt information into the dialogue model, and using the dialogue model to analyze the query information and database information in the prompt information, and outputting a structured query language.
[0301] Optionally, in this embodiment, the storage medium is set to store program code for performing the following steps: obtaining a database information sample set corresponding to the structured query language sample set; inputting the database information sample set into the initial dialogue model, and using the initial dialogue model to analyze the database information sample set, and outputting a query information sample set corresponding to the structured query language sample set, where the initial dialogue model is trained at least based on the initial structured query language sample set, and the query information samples in the query information sample set are used to represent the semantics of the corresponding structured query language samples in the structured query language sample set; training the large model based on the database information sample set and the query information sample set to obtain a dialogue model, where the dialogue model is used to analyze the query information and database information in the prompt information to generate a structured query language, the prompt information is generated at least based on the database information matching the structured query language, the query information is used to represent the semantics of the structured query language, and the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language in the database.
[0302] Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: detecting query information received in the interaction interface, where the query information is used to represent the semantics of the structured query language to be generated; in response to the query information, displaying database information matching the structured query language to be generated in the interaction interface, where the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language to be generated in the database; on the interaction interface, displaying prompt information generated at least based on the database information; inputting the prompt information into the dialogue model, and displaying, on the interaction interface, the structured query language obtained by analyzing the query information and the database information in the prompt information using the dialogue model.
[0303] Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: in response to multimodal information received in the dialogue interface, where the multimodal information includes query information corresponding to the structured query language to be generated, and the query information is used to represent the semantics of the structured query language to be generated; displaying database information matching the structured query language to be generated in the dialogue interface, where the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language to be generated in the database; on the dialogue interface, displaying prompt information generated at least based on the database information; inputting the prompt information into the dialogue model, and analyzing the query information and the database information in the prompt information using the dialogue model to output the structured query language; and displaying reply information generated based on the structured query language on the dialogue interface.
[0304] Optionally, in this embodiment, the storage medium is configured to store program code for performing the following steps: detecting the query information to be converted by calling a first interface, where the first interface includes a first parameter, and the parameter value of the first parameter is the query information, and the query information is used to represent the semantics of the structured query language to be converted; obtaining database information matching the structured query language to be converted, where the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language to be converted in the database; generating prompt information at least based on the database information; inputting the prompt information into the dialogue model, and analyzing the query information and the database information in the prompt information using the dialogue model to output the structured query language; and outputting the structured query language by calling a second interface, where the second interface includes a second parameter, and the parameter value of the second parameter is the structured query language.
[0305] In an embodiment of the present application, when a client needs Structured Query Language (SQL) to assist in data development, the corresponding semantics capable of generating the SQL can be input on the interaction interface of the client, that is, the query information corresponding to the SQL. After detecting that there is query information to be converted into SQL in the interaction interface of a certain client, the query information can be transmitted from the client to the cloud. Based on the query information, the cloud can determine, from the database, the data structure required for the operation function when executing the SQL corresponding to the query information, that is, the database information matching the SQL, and can transmit it to the interaction interface of the corresponding client for display. The cloud can generate, at least based on the database information, the prompt information corresponding to the SQL, and can transmit it to the interaction interface of the corresponding client for display. The cloud can use the prompt information to prompt the dialogue model to generate the required SQL, and can transmit it to the interaction interface of the corresponding client for display. Considering that in the related art, generating SQL only based on the mapping between natural language and SQL may result in situations that are divorced from reality and difficult to apply, the present application can further model the database information corresponding to the structured information, avoiding the abnormal situations in the above-mentioned related art, thereby achieving the purpose of improving the accuracy of the required generated structured information and the degree of fit with actual applications, and further realizing the technical effect of effectively generating SQL, and solving the technical problem of being unable to effectively generate SQL.
[0306] Embodiment 7
[0307] An embodiment of the present application can provide an electronic device, which may include a memory and a processor. Figure 16 It is a block diagram of an electronic device for a method of generating a Structured Query Language according to an embodiment of the present application. The electronic device is intended to represent various forms of digital computers, such as, laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as, personal digital processors, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are only examples and are not intended to limit the implementation of the present application described and / or claimed herein.
[0308] As Figure 16As shown, device 1600 includes a computing unit 1601, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 1602 or a computer program loaded from a storage unit 1608 into a random access memory (RAM) 1603. In the RAM 1603, various programs and data required for the operation of the device 1600 can also be stored. The computing unit 1601, the ROM 1602, and the RAM 1603 are connected to each other via a bus 1604. An input / output (I / O) interface 1605 is also connected to the bus 1604.
[0309] Multiple components in the device 1600 are connected to the I / O interface 1605, including: an input unit 1606, such as a keyboard, a mouse, etc.; an output unit 1604, such as various types of displays, speakers, etc.; a storage unit 1608, such as a magnetic disk, an optical disc, etc.; and a communication unit 16010, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 16010 allows the device 1600 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.
[0310] The computing unit 1601 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 1601 include, but are not limited to, a central processing unit (CPU), a graphic processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 1601 executes the various methods and processes described above, such as the method for generating a structured query language. For example, in some embodiments, the method for generating a structured query language can be implemented as a computer software program that is tangibly included in a machine-readable medium, such as the storage unit 1608. In some embodiments, part or all of the computer program can be loaded and / or installed onto the device 1600 via the ROM 1602 and / or the communication unit 1609. When the computer program is loaded into the RAM 1603 and executed by the computing unit 1601, one or more steps of the method for generating a structured query language described above can be executed. Alternatively, in other embodiments, the computing unit 1601 can be configured to execute the method for generating a structured query language by any other suitable means (e.g., by means of firmware).
[0311] The various embodiments of the systems and techniques described above in this specification can be implemented in digital electronic circuitry, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard parts (ASSPs), system on chip (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include: being implemented in one or more computer programs that are executable and / or interpretable on a programmable system including at least one programmable processor, which can be a special-purpose or general-purpose programmable processor that receives data and instructions from, and transmits data and instructions to, a storage system, at least one input device, and at least one output device.
[0312] The program code for implementing the methods of the present invention can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the program codes, when executed by the processor or controller, cause the functions / operations specified in the flowchart and / or block diagram to be implemented. The program code can be executed entirely on the machine, partly on the machine, as a stand-alone software package partly on the machine and partly on a remote machine, or entirely on the remote machine or server.
[0313] In the context of this application, a machine-readable medium can be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a random access memory, a read-only memory, an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0314] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a cathode ray tube or a liquid crystal display, a monitor); and a keyboard and a pointing device (e.g., a mouse or a trackball) through which the user can provide input to the computer. Other kinds of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0315] The systems and techniques described herein can be implemented in a computing system including backend components (e.g., as a data server), or a computing system including middleware components (e.g., an application server), or a computing system including frontend components (e.g., a user computer having a graphical user interface or a web browser through which the user can interact with an implementation of the systems and techniques described herein), or a computing system including any combination of such backend components, middleware components, or frontend components. The components of the system can be interconnected to each other by digital data communication in any form or medium (e.g., a communication network). Examples of communication networks include: local area networks, wide area networks, and the Internet.
[0316] A computer system can include a client device and a server. The client device and the server are generally far from each other and usually interact through a communication network. The relationship between the client device and the server is generated by computer programs running on the respective computers and having a client device-server relationship with each other. The server can be a cloud server, or a server of a distributed system, or a server incorporating a blockchain.
[0317] It should be noted that the serial numbers of the above embodiments of the present application are only for description and do not represent the superiority or inferiority of the embodiments.
[0318] In the above embodiments of the present application, the descriptions of the respective embodiments have their own emphases. For parts not detailed in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0319] In several embodiments provided in the present application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are merely illustrative. For example, the division of units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some interfaces, and the indirect couplings or communication connections of units or modules can be in electrical or other forms.
[0320] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they may be located in one place or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0321] In addition, in each embodiment of the present application, the functional units can be integrated in a processing unit, or each unit can exist physically alone, or two or more units can be integrated in one unit. The above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units.
[0322] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to enable a computer device (which can be a personal computer, a server or a network device, etc.) to execute all or part of the steps of the methods in each embodiment of the present application. The foregoing storage medium includes: various media such as USB flash drives, read-only memories, random access memories, mobile hard disks, magnetic disks or optical discs that can store program codes.
[0323] The above is only the preferred embodiment of the present application. It should be noted that for those of ordinary skill in the art, without departing from the principle of the present application, several improvements and refinements can be made, and these improvements and refinements should also be regarded as the protection scope of the present application.
Claims
1. A method for generating a Structured Query Language, characterized in that, applied to the cloud, it includes: detecting the query information to be converted from the client, where the query information is used to represent the semantics of the Structured Query Language to be converted; obtaining database information matching the Structured Query Language to be converted, where the database information is used to represent the data structure required for performing the operation function corresponding to the Structured Query Language to be converted in the database; generating prompt information based on at least the database information; inputting the prompt information into a dialogue model, and using the dialogue model to analyze the query information and the database information in the prompt information, and outputting the Structured Query Language.
2. The method according to claim 1, characterized in that, obtaining database information matching the Structured Query Language to be converted includes: determining the type of operation function corresponding to the Structured Query Language to be generated; obtaining the database information matching the type of operation function.
3. The method according to claim 1, characterized in that, generating prompt information based on at least the database information includes: using an information generation template to generate the prompt information from the operation function and the database information, where the information generation template is used to represent the rules for generating the prompt information in the query scenario corresponding to the Structured Query Language.
4. The method according to claim 1, characterized in that, the method further includes: determining the query information sample with the highest similarity to the query information in the query information sample set, and determining the Structured Query Language sample corresponding to the query information sample in the Structured Query Language sample set, where the query information sample set and the Structured Query Language sample set are used to train the dialogue model, and the query information sample is used to represent the semantics of the Structured Query Language sample; generating prompt information based on at least the database information includes: generating the prompt information based on the Structured Query Language sample, the query information sample, and the database information.
5. The method according to claim 4, characterized in that, determining the query information sample with the highest similarity to the query information in the query information sample set includes: using a similarity model to determine the query information sample in the query information sample set, where the similarity model is used to determine the output data with the highest similarity to the input data.
6. The method according to any one of claims 1 to 5, characterized in that, the method further includes: outputting the Structured Query Language to the client.
7. A method for generating a model, characterized in that, it includes: obtaining a database information sample set corresponding to a Structured Query Language sample set; Input the database information sample set into the initial dialogue model, and use the initial dialogue model to analyze the database information sample set, and output the query information sample set corresponding to the structured query language sample set, where the initial dialogue model is trained at least based on the initial structured query language sample set, and the query information samples in the query information sample set are used to represent the semantics of the corresponding structured query language samples in the structured query language sample set; Based on the database information sample set and the query information sample set, train a large model to obtain a dialogue model, where the dialogue model is used to analyze the query information and database information in the prompt information to generate a structured query language, the prompt information is generated at least based on the database information matching the structured query language, the query information is used to represent the semantics of the structured query language, and the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language in the database.
8. The method according to claim 7, characterized in that, the method further includes: Classify the database information sample set according to the operation function corresponding to the structured query language sample set in the database; Using the initial dialogue model to analyze the database information sample set and output the query information sample set corresponding to the structured query language sample set includes: using the initial dialogue model to analyze the classified database information sample set and output the query information sample set corresponding to the structured query language sample set.
9. The method according to claim 8, characterized in that, Training the large model based on the database information sample set and the query information sample set to obtain a dialogue model includes: Performing supervised training on the large model based on the classified database information sample set and the query information sample set to obtain the dialogue model.
10. The method according to claim 7, characterized in that, the method further includes: Training the initial dialogue model based on the initial structured query language sample set of data types matching different operation functions.
11. A method for generating a structured query language, characterized in that, including: Detect the query information received in the interaction interface, where the query information is used to represent the semantics of the structured query language to be generated; In response to the query information, display the database information matching the structured query language to be generated in the interaction interface, where the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language to be generated in the database; On the interaction interface, display the prompt information generated at least based on the database information; Input the prompt information into the dialogue model, and display the structured query language obtained by analyzing the query information and the database information in the prompt information by using the dialogue model on the interaction interface.
12. The method according to claim 11, characterized in that, Display database information in the interaction interface that matches the Structured Query Language to be generated, including: Determine the type of operation function corresponding to the Structured Query Language to be generated; Display the database information in the interaction interface that matches the type of operation function.
13. The method according to claim 11, wherein, On the interaction interface, display prompt information generated at least based on the database information, including: Input the operation function and the database information into an information generation template, and display the generated prompt information on the interaction interface, where the information generation template is used to represent the rules for generating the prompt information in the query scenario corresponding to the Structured Query Language.
14. The method according to claim 11, wherein, The method further includes: In the set of query information samples, determine the query information sample with the highest similarity to the query information, and in the set of Structured Query Language samples, determine the Structured Query Language sample corresponding to the query information sample, where the set of query information samples and the set of Structured Query Language samples are used to train the dialogue model, and the query information sample is used to represent the semantics of the Structured Query Language sample; On the interaction interface, display prompt information generated at least based on the database information, including: On the interaction interface, display the prompt information generated based on the Structured Query Language sample, the query information sample, and the database information.
15. The method according to claim 14, wherein, The method further includes: Respond to a modification operation on the interaction interface to modify the set of query information samples.
16. A method for generating a Structured Query Language, wherein, including: Respond to multimodal information received in the dialogue interface, where the multimodal information includes query information corresponding to the Structured Query Language to be generated, and the query information is used to represent the semantics of the Structured Query Language to be generated; In the dialogue interface, display database information that matches the Structured Query Language to be generated, where the database information is used to represent the data structure required to execute the operation function corresponding to the converted Structured Query Language in the database; On the dialogue interface, display prompt information generated at least based on the database information; Input the prompt information into a dialogue model, and use the dialogue model to analyze the query information and the database information in the prompt information, and output the Structured Query Language; On the dialogue interface, display reply information generated based on the Structured Query Language.
17. The method according to claim 16, wherein, The types of the multimodal information include at least one of the following: text information containing character information, video frame information containing frame image information, audio information, and the types of the reply information include at least one of the following: text information, image information, video information, and voice information.
18. A method for generating a Structured Query Language, wherein, including: detecting the query information to be converted by calling a first interface, where the first interface includes a first parameter, and the parameter value of the first parameter is the query information, and the query information is used to represent the semantics of the structured query language to be converted; obtaining database information matching the structured query language to be converted, where the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language to be converted in the database; generating a prompt message based at least on the database information; inputting the prompt message into a dialogue model, and using the dialogue model to analyze the query information and the database information in the prompt message, and outputting the structured query language; outputting the structured query language by calling a second interface, where the second interface includes a second parameter, and the parameter value of the second parameter is the structured query language.
19. A system for generating a structured query language, characterized in that, including: an input end for inputting query information to be converted, where the query information is used to represent the semantics of the structured query language to be converted; a processing end for obtaining database information matching the structured query language to be converted, and generating a prompt message based at least on the database information, where the database information is used to represent the data structure required for performing the operation function corresponding to the structured query language to be converted in the database; a model inference end for inputting the prompt message into a dialogue model, and using the dialogue model to analyze the query information and the database information in the prompt message, and outputting the structured query language.
20. An electronic device, characterized in that, including: a memory and a processor; the memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions, and when the computer-executable instructions are executed by the processor, the steps of the method according to any one of claims 1 to 18 are implemented.