Query language generation method and system, electronic equipment, storage medium and program product
By combining a language routing model and a group of language expert models, the problem of low quality in query language generation across database dialects was solved, and efficient query language conversion and generation were achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- ALIBABA CLOUD COMPUTING CO LTD
- Filing Date
- 2024-11-15
- Publication Date
- 2026-05-15
AI Technical Summary
In existing technologies, the quality of query language generation across multiple database dialects is low, and it cannot effectively handle the grammatical differences between different database dialects.
A language routing model is used to assign text unit sets to target language expert model groups among multiple language expert model groups. The language expert models are then used to generate query language, which isolates the knowledge features of the database language and improves the generation quality.
This technology effectively generates query languages across multiple database dialects, improving the quality of query language generation and enabling efficient query language conversion across database dialects.
Smart Images

Figure CN122045337A_ABST
Abstract
Description
Technical Field
[0001] This application relates to large model technology and language processing, and more specifically, to a method, system, electronic device, storage medium, and program product for generating a query language. Background Technology
[0002] Currently, with the advancement of natural language processing technology, especially the development of large language models, the ability of large language models to transform natural language information into structured query languages has been significantly improved.
[0003] In related technologies, optimization is usually only performed for specific database dialects. However, when dealing with multiple database dialects, the technical problem of low quality in query language generation due to grammatical differences between different dialects is addressed.
[0004] There is currently no effective solution to the above problems. Summary of the Invention
[0005] This application provides a method, system, electronic device, storage medium, and program product for generating query languages, to at least solve the technical problem of low quality in query language generation.
[0006] According to one aspect of the embodiments of this application, a method for generating query language is provided. The method may include: obtaining text unit sets from multiple natural language information to be processed, wherein the text unit sets include language features in the natural language information that can be converted to a database language, and the database language includes structured database language and unstructured database language; assigning the text unit sets to target language expert model groups among multiple language expert model groups using a language routing model, wherein the language routing model is trained using text unit set samples, labels of the database language corresponding to the text unit set samples, and language expert model groups corresponding to the text unit set samples, different language expert model groups corresponding to different database languages, and the language expert model groups have learned knowledge data of the corresponding database languages; determining at least one language expert model matching the text unit set in the target language expert model group; and using the language expert model to convert the text unit sets into query language under the database language.
[0007] According to another aspect of the embodiments of this application, another method for generating query language is also provided. This method can be applied to a database management system and may include: obtaining text unit sets from multiple input natural language information sources, wherein the text unit sets include dialect features in the natural language information that allow conversion to a database dialect, and the database dialect includes structured database language and unstructured database language; invoking a dialect routing model to assign the text unit sets to target dialect expert model groups among multiple dialect expert model groups, wherein the dialect routing model is trained using text unit set samples, labels of the database dialect corresponding to the text unit set samples, and dialect expert model groups corresponding to the text unit set samples, different dialect expert model groups corresponding to different database dialects, and the dialect expert model groups have learned query syntax knowledge data of the corresponding database dialects; invoking an expert routing model to determine at least one dialect expert model matching the text unit set in the target dialect expert model group, wherein the expert routing model is trained using a text unit sample set and labels of the corresponding dialect expert model; and using the dialect expert model to convert the text unit sets into query language under the database dialect.
[0008] According to another aspect of the embodiments of this application, another method for generating query language is also provided. This method may include: responding to an input operation on an interface, displaying multiple natural language information to be processed on the interface, wherein the natural language information includes a set of text units, the set of text units includes language features in the natural language information that can be converted to a database language, and the database language includes structured database language and unstructured database language; responding to a generation operation on the interface, displaying the query language of the natural language information under the corresponding database language on the interface, wherein the query language under the database language is obtained by converting the set of text units using at least one language expert model that matches the set of text units in the natural language information, the language expert model comes from a target language expert model group, the target language expert model group is obtained by allocating the set of text units among multiple language expert model groups using a language routing model, and the language routing model uses text unit set samples, labels of the database language corresponding to the text unit set samples, and the text unit set.
[0009] According to another aspect of the embodiments of this application, another method for generating query language is also provided. The method may include: obtaining text unit sets from multiple natural language information to be processed by calling a first interface, wherein the first interface includes a first parameter, the parameter value of the first parameter including the text unit set, the text unit set including language features in the natural language information that can be converted to a database language, the database language including structured database language and unstructured database language; allocating the text unit sets to target language expert model groups among multiple language expert model groups using a language routing model, wherein the language routing model is trained using text unit set samples, labels of the database language corresponding to the text unit set samples, and language expert model groups corresponding to the text unit set samples, different language expert model groups corresponding to different database languages, and the language expert model groups learning knowledge data of the corresponding database languages; determining at least one language expert model matching the text unit set in the target language expert model group; converting the text unit set into query language under the database language using the language expert model; and outputting the query language under the database language by calling a second interface, wherein the second interface includes a second parameter, the parameter value of the second parameter including the query language under the database language.
[0010] According to another aspect of the embodiments of this application, a query language generation system is also provided. The system may include: a data input end, used to obtain text unit sets from multiple natural language information to be processed, wherein the text unit sets include language features in the natural language information that can be converted to a database language, and the database language includes structured database language and unstructured database language; a language routing end, used to route the text unit sets to a target language expert model group among multiple language expert model groups using a language routing model, wherein the language routing model is trained using text unit set samples, labels of the database language corresponding to the text unit set samples, and language expert model groups corresponding to the text unit set samples, different language expert model groups corresponding to different database languages, and the language expert model groups have learned knowledge data of the corresponding database languages; an expert routing end, used to determine at least one language expert model matching the text unit set in the target language expert model group; a data conversion end, used to convert the text unit sets into query language under the database language using the language expert model; and a data output end, used to output the query language under the database language.
[0011] According to another aspect of the embodiments of this application, an electronic device is also provided, including: a memory storing an executable program; and a processor for running the program, wherein the program executes the methods in various embodiments of this application when it runs.
[0012] According to another aspect of the embodiments of this application, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored executable program, wherein, when the executable program is running, it controls the device where the computer-readable storage medium is located to perform the methods of various embodiments of this application.
[0013] According to another aspect of the embodiments of this application, a computer program product is also provided, including a computer program that, when executed by a processor, implements the methods of various embodiments of this application.
[0014] According to another aspect of the embodiments of this application, a computer program product is also provided, including a non-volatile computer-readable storage medium storing a computer program, which, when executed by a processor, implements the methods in various embodiments of this application.
[0015] According to another aspect of the embodiments of this application, a computer program is also provided, which, when executed by a processor, implements the methods of the various embodiments of this application.
[0016] In this embodiment, text unit sets are obtained from multiple natural language information sets to be processed. Each text unit set includes language features in the natural language information that can be converted to a database language. The database language includes structured and unstructured database languages. A language routing model is used to assign the text unit sets to target language expert model groups within multiple language expert model groups. The language routing model is trained using text unit set samples, the labels of the corresponding database languages, and the corresponding language expert model groups. Different language expert model groups correspond to different database languages, and each language expert model group has learned the corresponding database language knowledge data. Within the target language expert model groups, at least one language expert model matching the text unit set is determined. The language expert model is then used to convert the text unit sets into query language under the database language. That is, in this embodiment of the application, a language expert model group (e.g., dialect expert group) is provided for each database language (e.g., database dialect). The language expert model can be used to learn the knowledge data of the corresponding database language to isolate dialect-specific knowledge and reduce interference during generation. The text unit set corresponding to the natural language information is routed to the corresponding target language expert model group. A language expert model is selected from the target language expert model group to generate the query language. In this way, the query language is effectively generated among multiple database dialects, improving the generation quality of the query language. This achieves the technical effect of improving the generation quality of the query language and solves the technical problem of low generation quality of the query language.
[0017] It is worth noting that the general description above and the detailed description that follow are merely for illustrative purposes and do not constitute a limitation on this application. Attached Figure Description
[0018] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:
[0019] Figure 1 This is a schematic diagram illustrating an application scenario of a query language generation method according to an embodiment of this application;
[0020] Figure 2 This is a flowchart of a query language generation method according to an embodiment of this application;
[0021] Figure 3 This is a flowchart of another query language generation method according to an embodiment of this application;
[0022] Figure 4 This is a flowchart of another query language generation method according to an embodiment of this application;
[0023] Figure 5 This is a flowchart of another query language generation method according to an embodiment of this application;
[0024] Figure 6 This is a schematic diagram of a query language generation system according to an embodiment of this application;
[0025] Figure 7 This is a schematic diagram of a MoMQ framework according to an embodiment of this application;
[0026] Figure 8 This is a hardware structure block diagram of a computer terminal (or mobile device) according to an embodiment of the present application of a query language generation method;
[0027] Figure 9 This is a schematic diagram of a query language generation apparatus according to an embodiment of this application;
[0028] Figure 10 This is a schematic diagram of an apparatus for generating a query language according to an embodiment of this application;
[0029] Figure 11 This is a schematic diagram of an apparatus for generating a query language according to an embodiment of this application;
[0030] Figure 12 This is a schematic diagram of an apparatus for generating a query language according to an embodiment of this application;
[0031] Figure 13 This is a structural block diagram of an electronic device according to an embodiment of this application. Detailed Implementation
[0032] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0033] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0034] The technical solution provided in this application is mainly implemented using large-scale model technology. Here, "large-scale model" refers to a deep learning model with a massive number of parameters, typically containing hundreds of millions, tens of billions, hundreds of billions, trillions, or even tens of trillions of parameters. Large-scale models can also be called foundation models. They are pre-trained using large-scale unlabeled corpora to produce pre-trained models with hundreds of millions of parameters. Such models can adapt to a wide range of downstream tasks and have good generalization ability. Examples include Large Language Models (LLMs) and multi-modal pre-training models.
[0035] It should be noted that, in practical applications, large models can be fine-tuned using a small number of samples to adapt them to different tasks. For example, large models can be widely used in Natural Language Processing (NLP), computer vision, and speech processing. Specifically, they can be applied to computer vision tasks such as Visual Question Answering (VQA), Image Captioning (IC), and Image Generation, as well as NLP tasks such as text-based sentiment classification, text summarization, and machine translation. Therefore, the main application scenarios for large models include, but are not limited to, digital assistants, intelligent robots, search, online education, office software, e-commerce, and intelligent design. In this embodiment, the example of data processing using a language expert model in a query language generation scenario is used for explanation.
[0036] First, some nouns or terms that appear in the description of the embodiments of this application shall be interpreted as follows:
[0037] A Mixture of Experts Model (MoE) is a machine learning architecture that can be used to handle complex tasks or situations with multiple subtasks. A MoE architecture can contain multiple expert models, each of which can focus on different aspects of the task or different subsets of data. These expert models can be controlled by a gate model. The MoE architecture can better utilize the strengths of different expert models and can handle a wider range of data distributions.
[0038] A gating model is a model used to describe cognitive processes, which are controlled by a series of gating mechanisms. These mechanisms control the flow and processing of information, ensuring the efficient operation of the cognitive system. The model can include various sub-models, such as working memory models and attention models. These sub-models interact through gating mechanisms to jointly complete cognitive tasks. The gating model can be used to determine which expert models or which expert models should participate in processing a given input.
[0039] Structured Query Language (SQL) is a standardized language for managing relational databases. It can be used to query data in a database, insert new data, update and delete existing data, and create, modify and delete database tables. It can be applied to various database management systems (such as MySQL, SQL Server, Oracle).
[0040] Natural Language to SQL (NL2SQL) refers to the process of converting questions in natural language into structured query language. This process allows non-technical users to ask questions to the database using everyday language without having to learn complex SQL syntax. With NL2SQL, users can easily retrieve the information they need from the database without having programming or database expertise.
[0041] Multi-dialect query generation, a natural language processing technique, can translate user queries into queries in multiple different languages and execute these queries in multiple language environments to obtain relevant information. This technology can be used to achieve cross-language communication and information retrieval, enabling users to use their familiar language to make queries without worrying about language barriers. Through multi-dialect query generation, users can obtain accurate and relevant information in different language environments, thereby improving the efficiency and convenience of information retrieval.
[0042] According to an embodiment of this application, a method for generating a query language is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0043] Considering the large number of model parameters in large models and the limited computing resources of mobile terminals, the query language generation method provided in this application embodiment can be applied to, for example, Figure 1 The application scenarios shown are not limited to these. Figure 1 This is a schematic diagram illustrating an application scenario of a query language generation method according to an embodiment of this application, such as... Figure 1 As shown, in Figure 1In the application scenario shown, the large model is deployed on server 10. Server 10 can connect to one or more client devices 20 via a local area network (LAN), wide area network (WAN), internet connection, or other types of data network. These client devices 20 may include, but are not limited to, smartphones, tablets, laptops, PDAs, personal computers, smart home devices, and in-vehicle devices. Client devices 20 can interact with users through a graphical user interface to access the large model, thereby implementing the method provided in this embodiment.
[0044] In this embodiment, the system consisting of a client device and a server can perform the following steps: Step S102, obtaining text unit sets from multiple natural language information to be processed, wherein the text unit sets include language features in the natural language information that can be converted to the database language; Step S104, using a language routing model, assigning the text unit sets to target language expert model groups among multiple language expert model groups, wherein different language expert model groups correspond to different database languages, and the language expert model groups have learned the knowledge data of the corresponding database languages; Step S106, determining at least one language expert model that matches the text unit set in the target language expert model group; Step S108, using the language expert model, converting the text unit sets into query language under the database language.
[0045] It should be noted that, provided that the client device's operating resources can meet the deployment and operation conditions of the large model, the embodiments of this application can be performed on the client device.
[0046] Under the aforementioned operating environment, this application provides the following: Figure 2 The method for generating the query language shown. Figure 2 This is a flowchart of a query language generation method according to an embodiment of this application. For example... Figure 2 As shown, the method may include the following steps:
[0047] Step S202: Obtain text unit sets from the multiple natural language information to be processed.
[0048] In the technical solution provided in step S202 of this application, the natural language information may include questions, everyday language, input statements, etc., in the form of natural language information. It can be natural language information or natural language questions input by the user. For example, it can be everyday language or questions input by a non-technical user. It should be noted that this is merely an example and does not impose specific limitations on the type of natural language information. The text unit set (tokens) may include language features in the natural language information that allow conversion to the database language. The text unit set may contain tokens with different dialect characteristics.
[0049] Optionally, the database language mentioned above may include structured database language and unstructured database language. This embodiment avoids the problem of being limited to relational dialects in related technologies by processing both structured and unstructured database languages.
[0050] Optionally, the structured database language mentioned above can be a relational database dialect (e.g., PostgreSQL, MySQL, etc.). The unstructured database language mentioned above can be a non-relational database dialect (e.g., Cypher, NgQL). The language features of a database language can be dialect features or dialect characteristics, also known as a database dialect. Database dialects can be used to characterize the differences in SQL syntax and functionality between different database management systems (DBMS). Each DBMS has its own specific SQL dialect, which can differ in syntax, functions, data types, etc. That is, the same SQL statement may have different processing results in different DBMSs. The existence of database languages means that using the same SQL statement in different DBMSs may cause compatibility issues, requiring adjustments and optimizations based on the specific DBMS. Database dialects can include open-source relational database management system (MySQL) dialects, relational database management system (Oracle) dialects, SQL Server dialects, etc. The above dialects can be understood as variations of the specific query languages used by different database management systems, and can be considered database languages. It should be noted that this is only an example and does not impose specific limitations on the type of database dialect.
[0051] Optionally, at least one language feature is extracted from multiple natural language information to obtain a set of text units.
[0052] In this embodiment, not only can relational database dialects be processed, but it can also be extended to non-relational graph databases.
[0053] For example, the system can receive natural language input from the user. This natural language information can be used to represent a request to retrieve information from a relational or non-relational database. Optionally, it could be a query request for a relational database (such as MySQL or PostgreSQL), for example, listing the ages and joining dates of all superheroes, or a query request for a graph database (such as Neo4j or NebulaGraph), such as finding other movies that share actors with this movie. After receiving the natural language information, it can be decomposed into a set of text units. This set of text units can include key elements from words, phrases, or sentences, containing semantic and syntactic features (i.e., linguistic features) that can be converted into database language. For example, in the relational database example above, "all," "superheroes," "age," and "joining date" would be identified as key text units, resulting in a set of text units that correspond to concepts such as select, from which table, and which columns to select in the database query language, respectively. In the graph database example, "find," "and," "this movie," "shares actors," and "other movies" would be extracted as text units, resulting in a set of text units that correspond to concepts such as search, based on, association, condition, and result in the graph database query language, respectively.
[0054] Step S204: Using the language routing model, the text unit set is assigned to the target language expert model group among multiple language expert model groups.
[0055] In the technical solution provided in step S204 of this application, the aforementioned multiple language expert model groups can be dialect expert groups, hybrid expert models, or language expert model groups (DialectExpert Groups) targeting different database languages. Different language expert model groups can correspond to different database languages; that is, this embodiment can create a dedicated dialect expert group for each dialect, and these language expert model groups can learn knowledge data corresponding to the database language. This knowledge data can be specific query syntax knowledge. The database language can be a database query language (e.g., MySQL, PostgreSQL, Cypher, or nGQL), or a set of instructions for creating, operating, and managing databases, used to interact with the database to perform operations such as data querying, updating, management, and control.
[0056] Optionally, the language routing model described above can be a dialect router, used to route text unit sets to the corresponding target language expert model group. It can be trained using text unit set samples, the labels of the corresponding database languages, and the language expert model group. The text unit set samples can contain multiple text unit samples (total number of tokens), which can be pre-acquired or pre-defined. The labels of the database languages can be dialect labels, used to determine the type of language features in the text unit set samples. It should be noted that this is merely an illustrative example, and no specific restrictions are placed on the method of constructing the language routing model.
[0057] Optionally, a set of language expert models can be pre-configured for each database language (i.e., dialect). These models are fine-tuned using a specific training dataset to learn and master the specific knowledge and grammar (i.e., knowledge data) of that database language. During the training phase of the language expert model group, each group learns a large number of question and query pairs related to the specific database language, enabling it to understand and generate queries in that language. For example, the MySQL language expert model group learns how to generate SQL queries containing keywords such as "selection," "source," and "place." After obtaining the text unit set, a suitable target language expert model group can be selected from multiple groups based on the language characteristics of the text units.
[0058] For example, based on language features, language expert model groups can be filtered to obtain target language expert model groups. Optionally, natural language information can be acquired, and its language features can be extracted, such as grammatical structure, keywords, and contextual clues, to obtain a text unit set. Based on the text unit set, the language features of the database language corresponding to the natural language information can be determined. Based on the language features, the text unit set can be assigned to a suitable target language expert model group for processing that text unit set. For example, if the acquired text unit set is about graph database queries, the text unit set can be routed to a target language expert model group of Cypher or nGQL.
[0059] Step S206: In the target language expert model group, identify at least one language expert model that matches the text unit set.
[0060] In the technical solution provided in step S206 of this application, at least one language expert model with a matching degree higher than a threshold with the text unit set can be identified from the target language expert model group. It should be noted that the method for identifying at least one language expert model here is merely illustrative and not specifically limited. The aforementioned language expert model (Low-Rank Adaptation experts, abbreviated as LoRA) can be an expert model, or a LoRA expert model (abbreviated as LoRA expert), and can be constructed based on low-rank adaptation techniques. It should be noted that the type of language expert model is not specifically limited here.
[0061] Optionally, each database language has a dedicated group of language expert models to learn the knowledge data specific to that database language, achieving sufficient isolation between multiple database language-specific knowledge data. Each language expert model group can consist of multiple LoRA experts. LoRA experts can be used to adapt the pre-trained model to learn new task or language features without updating the original weights.
[0062] Optionally, by using the text unit set, at least one language expert model matching the text unit set is determined in the target language expert model group, and the selected at least one language expert model is used to process the text unit set, thereby achieving the goal of maintaining the inference efficiency of the language expert model and improving the diversity of activations.
[0063] For example, when a user asks a question in the form of natural language information, the system (e.g., the MoMQ framework) can parse the input natural language information to identify and extract query language that can be converted into the database language. For instance, it can extract keywords such as "selection," "source," and "location," as well as related entities, attributes, and logical relationships. These keywords, entities, attributes, and logical relationships can constitute a set of text units. Furthermore, each language expert model group can correspond one-to-one with a database language, and the language expert model groups have already learned knowledge data specific to that database language through training. Therefore, based on the linguistic features of the database language, the text unit set can be directed to a specific target language expert model group. For example, if a text unit set contains MySQL-specific functions (e.g., DATE_ADD), the dialect router can direct this text unit set to the MySQL dialect's language expert model group.
[0064] Optionally, after the text unit set is directed to a specific target language expert model group, the expert router can perform more refined processing on the text unit set within that group. Based on the linguistic features of the text unit set, it can identify and activate at least one language expert model within the group that matches the text unit set. Since each language expert model has its own strengths in handling specific types of information or query structures, a suitable language expert model can be selected based on the attributes of the text unit set (e.g., the complexity of the grammatical structure, the occurrence of specific keywords, etc.). Through this selective activation, not only can the accuracy and efficiency of query language generation be improved, but redundant computations in the model can also be avoided, ensuring the effective utilization of resources.
[0065] Step S208: Using a language expert model, the text unit set is converted into a query language under the database language.
[0066] In the technical solution provided in step S208 of this application, the query language can be a structured query language, a standardized language for managing relational databases, or a specific language for operations such as querying data in a database, inserting new data, updating and deleting existing data, and creating, modifying, and deleting database tables. It can include relational database query languages (e.g., dialects of MySQL and PostgreSQL) and non-relational database query languages (e.g., the Cypher dialect for Neo4j graph database and the nGQL dialect for NebulaGraph graph database). It should be noted that the above are merely illustrative examples and do not impose specific limitations on the type of query language.
[0067] Optionally, the aforementioned query language can serve as a bridge between the database management system and the user, converting natural language information into query language to allow users to describe the data to be retrieved or manipulated from the database in a structured manner. Each database has its own specific query language, which may differ in syntax and functionality to suit the characteristics of different database types.
[0068] Because different relational database languages have different linguistic features, simply using an encoder-decoder structure to convert natural language information will result in low-quality query language generation. To address this issue, this embodiment pre-constructs different language expert model groups for different database languages. After acquiring the natural language information, it is processed to obtain text unit sets. Based on the linguistic features of these text unit sets, they are assigned to target language expert model groups within the different language expert model groups. Furthermore, at least one language expert model matching the text unit set can be identified within the target language expert model group. This at least one language expert model is then used to convert the text unit set to obtain the query language. This query language can then be used to perform queries on the database language, thereby improving the quality of the generated query language and solving the problem of low-quality query language generation.
[0069] Optionally, through the above process, users can ask questions to the database using everyday language (i.e., natural language information) without having to learn complex SQL syntax (i.e., language features).
[0070] For example, suppose the user inputs natural language information: "List all authors of science fiction books published in 2023". This natural language information can be analyzed into a series of linguistic features, such as lexical, grammatical, and semantic units, resulting in a set of text units: "list", "all", "published in 2023", "science fiction books", and "authors". Further, the text unit set is identified because "published" and "books" suggest a relational table structure that may contain dates and categories. Therefore, it can be determined that the query is likely related to a relational database dialect (such as MySQL or PostgreSQL). The text unit set can then be routed to a target language expert model group with a high degree of relevance. Once the target language expert model group is determined (let's assume it's the MySQL dialect), each linguistic feature in the text unit set can be further analyzed, and at least one language expert model from the target language expert model group suitable for handling these linguistic features can be determined. For example, "2023" might be routed to a language expert model that handles dates and times, and "science fiction books" might be routed to a language expert model that handles categories and keywords. The selected language expert model can transform the set of text units to obtain the query language. For example, "list all authors of science fiction books published in 2023" may be transformed into the SQL query: "SELECT author FROM books WHERE category='science fiction' AND publication_year=2023;".
[0071] Through steps S202 to S210, text unit sets are obtained from multiple natural language information sets to be processed. Each text unit set includes language features in the natural language information that can be converted to a database language. The database language includes structured and unstructured database languages. Using a language routing model, the text unit sets are assigned to target language expert model groups among multiple language expert model groups. The language routing model is trained using text unit set samples, the labels of the corresponding database languages, and the corresponding language expert model groups. Different language expert model groups correspond to different database languages, and each language expert model group has learned the corresponding database language knowledge data. In the target language expert model groups, at least one language expert model that matches the text unit set is determined. Using the language expert model, the text unit sets are converted into query language under the database language. That is, in this embodiment of the application, a language expert model group (e.g., dialect expert group) is provided for each database language (e.g., database dialect). The language expert model can be used to learn the knowledge data of the corresponding database language to isolate dialect-specific knowledge and reduce interference during generation. The text unit set corresponding to the natural language information is routed to the corresponding target language expert model group. A language expert model is selected from the target language expert model group to generate the query language. In this way, the query language is effectively generated among multiple database dialects, improving the generation quality of the query language. This achieves the technical effect of improving the generation quality of the query language and solves the technical problem of low generation quality of the query language.
[0072] The method described in this embodiment will be further described below.
[0073] As an optional implementation, step S204, using a language routing model, assigns the text unit set to a target language expert model group among multiple language expert model groups, including: calling the language routing model to determine the language expert model group corresponding to the language features among the multiple language expert model groups as the target language expert model group; and using the language routing model to route the text unit set to the target language expert model group.
[0074] In this embodiment, the language routing model can route a set of text units with linguistic features to the corresponding target language expert model group to complete the transmission of the text unit set and achieve the goal of correctly routing different text unit sets.
[0075] Optionally, based on the language features of the text unit set, the language expert model group corresponding to the language features among multiple language expert model groups can be determined. The corresponding language expert model group can be identified as the target language expert model group. Furthermore, using a language routing model, the text unit set can be routed to the identified target language expert model group.
[0076] Optionally, the dialect router can route tokens of a specific dialect to the corresponding target language expert model group, thereby solving the technical problem that tokens of different dialects are difficult to route correctly and achieving the technical effect that tokens of different dialects can be routed correctly.
[0077] For example, suppose there are four language expert model groups, corresponding to MySQL, PostgreSQL, Cypher (for Neo4j), and nGQL (for NebulaGraph), respectively. Each language expert model group contains at least one language expert model, which is used to understand and generate query language corresponding to the database dialect of natural language information. When a user submits natural language information (which can be a query), such as "list all superheroes' names and their clubs," this natural language information can be segmented into multiple text units. Each text unit can represent a word or grammatical structure, such as "superhero," "name," "club," etc., thus obtaining a set of text units. Further, a language routing model can be invoked. By utilizing the language routing model, it can determine which language expert model group the text units should be routed to. For example, if the query is designed for a MySQL database, the language routing model will recognize this. Optionally, the language routing model can analyze the linguistic features of the input text unit set, such as grammatical structure, keywords, and contextual features, to determine the language expert model group that matches these linguistic features. For example, keywords like “LIMIT” and “ORDERBY” are common across multiple database dialects, but “MATCH” might only be relevant to Cypher, and “GOFROM” might only be relevant to nGQL. By identifying linguistic features, the language routing model can determine which language expert model group (e.g., the MySQL language expert model group, the PostgreSQL language expert model group, the Cypher language expert model group, and the nGQL language expert model group) to route the text set to. Once the target language expert model group is determined, the language routing model can route the text set to that target language expert model group.
[0078] For another example, given the input natural language information: "List all the names of superheroes and the clubs they belong to," if this natural language information is designed for a MySQL database, the language routing model can identify keywords such as "superheroes," "names," and "clubs," and consider their relationship with the MySQL language expert model group. Furthermore, the text unit set can be routed to the MySQL language expert model group, allowing the language expert models within the group to selectively process the natural language information, thereby generating SQL code (i.e., the query language) that conforms to the characteristics of the MySQL language.
[0079] As an optional implementation, the method may further include: obtaining a routing loss, wherein the routing loss is used to allow multiple text units with a similarity greater than a similarity threshold to be routed to multiple language expert model groups; and training a language routing model using the routing loss, text unit set samples, the database language corresponding to the text unit set samples, and the language expert model groups corresponding to the text unit set samples.
[0080] In this embodiment, the aforementioned Dialect Router Loss (DRL) can be used to allow multiple unit texts with a similarity greater than a similarity threshold to be routed to multiple language expert model groups, and can be pre-built. It should be noted that this is only an illustrative example, and there are no specific restrictions on the way the routing loss is constructed.
[0081] Optionally, after constructing multiple language expert model groups, in order to correctly route tokens of different dialects to the corresponding target language expert model groups, routing loss is utilized to allow similar tokens to enter multiple language expert model groups, especially from resource-rich dialects to resource-poor language expert model groups, thereby promoting the transfer of general knowledge data.
[0082] Optionally, this embodiment obtains a routing loss, which can be used to allow multiple similar tokens to enter multiple language expert model groups. By using the routing loss, text unit set samples, the database language corresponding to the text unit set samples, and the language expert model groups corresponding to the text unit set samples, a language routing model can be trained.
[0083] Optionally, the language routing model can perform correct routing under the guidance of sentence-level dialect hard labels, thereby achieving complete isolation between different language expert model groups. However, there may be some similarities between different dialects; for example, "LIMIT" and "ORDER BY" are both valid tokens in relational and non-relational database dialects. Furthermore, different dialects have high similarity in natural language problem understanding and database pattern understanding. If these similar tokens have the opportunity to enter multiple dialect expert groups, especially from high-resource dialects to low-resource dialects, this will further facilitate the transfer of token-level general knowledge data. Therefore, in this embodiment, a language routing model trained using routing loss is designed. The trained language routing model can be used to further reduce the occurrence of dialect isolation by replacing hard dialect labels with a smooth distribution. The smooth distribution allocates lower values to real dialects and allocates some value to other dialects. Under the constraints of DRL, tokens from specific dialects are excluded from having a higher probability of being routed to language routing models on the output weights of various language expert model groups. This allows similar tokens to have the opportunity to enter multiple language expert model groups, especially from resource-rich dialects to resource-poor dialects, thereby promoting more comprehensive dialect information exchange and knowledge data transfer. DRL can be added to the training objective and defined as follows:
[0084]
[0085] Among them, y t It can be used to represent the label of the database language corresponding to the text unit sample M in the text unit set sample. It can be a one-hot encoded vector label, and ε∈[0,1] can be used to represent the smoothing factor. It can be used to represent a smoothed label. This can be used to represent the language expert model group corresponding to the text unit set samples in layer l, where L can represent the total number of layers, and T can represent the total number of input tokens. M can be used to represent the routing loss, and M can be used to represent the number of language expert model groups.
[0086] Alternatively, in addition to routing dialect-specific tokens to the corresponding language expert model groups, the routing loss can be used to enable the language routing model to distribute other tokens to all language expert model groups, thereby facilitating token-level knowledge transfer across all language expert model groups.
[0087] In this embodiment, dialect smoothing technology is also introduced, using smooth distribution instead of hard labels to reduce dialect isolation and allow tokens that are common to multiple dialects to have the opportunity to enter multiple dialect expert groups. In this process, the language routing model can consider the affinity between all text units and each dialect expert model group, and based on the routing loss, ensure that not only specific dialect keywords are correctly routed, but also general natural language processing knowledge is shared among different language expert model groups to promote the migration of knowledge data.
[0088] Optionally, if certain parts of the text unit set (such as “superheroes,” “names,” and “clubs”) have high affinity with multiple language expert model groups, the language routing model can ensure through routing loss that these parts will also influence the training of other language expert model groups, thereby promoting the sharing of general knowledge data and cross-dialect learning.
[0089] In summary, this embodiment utilizes a dialect router model for routing between different language expert model groups. This model ensures that a given token is directed to the appropriate target language expert model group based on its linguistic features, thus fully considering dialect-specific syntax and structure during query language generation. Furthermore, to avoid rigidly isolating dialect experts, dialect smoothing is introduced, using a smooth distribution instead of hard-hot encoding of dialect labels. This helps reduce the negative impact of completely isolating language expert model groups and promotes the exchange of knowledge data across dialects.
[0090] Optionally, routing loss facilitates the transfer of knowledge data by softening the token allocation for a specific dialect, allowing it to flow between different language expert model groups. DRL transforms the hard isolation of different dialects into a smooth distribution by introducing a smoothing factor ε, meaning that each token can not only be assigned to its corresponding language expert model group, but also has the opportunity to be assigned to other language expert model groups, thus helping to transfer knowledge data from high-resource dialects to low-resource dialects.
[0091] For example, suppose there are four language expert model groups, corresponding to the MySQL, PostgreSQL, Cypher, and nGQL dialects. For an input text unit, such as "LIMIT", this text unit is valid in all four dialects, but its usage may differ. We can calculate the probability that the text unit "LIMIT" is correctly routed to the MySQL language expert model group, while also considering the probability of it being routed to other language expert model groups. By using DRL, we can ensure that "LIMIT" (and other similar general tokens) is not only routed to the MySQL language expert model group, but also enters other language expert model groups with a certain probability. For example, suppose the routing probability of the "LIMIT" token in the MySQL language expert model group is 0.8, while the routing probabilities in other language expert model groups are lower, at 0.05, 0.05, and 0.05 respectively. We want to balance these probabilities so that the text unit is not only effectively routed to its specific language expert model group, but also has the opportunity to access the knowledge data of other language expert model groups. Therefore, through DRL, we can adjust the above probabilities by adjusting the ε value, making the probabilities smoother.
[0092] As an optional implementation, step S206, determining at least one language expert model that matches the text unit set in the target language expert model group, includes: invoking an expert routing model to determine the language expert model that matches the text unit set in the target language expert model group, wherein the expert routing model is trained using the text unit sample set and the labels of the corresponding language expert model.
[0093] In this embodiment, the expert routing model can be a Top-K Expert Router, which can be used to activate a language expert model that matches the text unit set. The expert routing model can be trained using the labels of the language expert models corresponding to the text unit sample set.
[0094] Optionally, the expert routing model can be used to activate the top K expert models in the dialect expert group in the input token.
[0095] Optionally, this embodiment may introduce a multi-level routing structure, which may include a language routing model and an expert routing model. The language routing model can be used to assign text unit sets with dialect characteristics to corresponding language expert models, and the expert routing model can be used to identify and activate language expert models that match the text unit sets.
[0096] In this embodiment, each database language has a dedicated group of language expert models to learn dialect-specific knowledge data and achieve sufficient isolation of dialect-specific knowledge. Each group of language expert models can consist of multiple LoRA experts and a top-k expert routing model. The language expert models can be used to adapt pre-trained models to learn new task or dialect features without updating the original weights. The expert routing model can be used to assign input tokens to appropriate language expert models.
[0097] Optionally, the language expert model group can learn dialect-specific knowledge while retaining general language understanding by adding an additional small, trainable matrix to the weight matrix of the pre-trained model, while keeping the original weights unchanged. The expert routing model described above can be used to calculate the weights between each token and multiple language expert models in the target language expert model group that match the text unit set. Based on these weights, the language expert models in the target language expert model group that match the text unit set can be determined. For example, the K language expert models with higher weights can be selected to process the text unit set, thereby maintaining the inference efficiency of the language expert models and improving the diversity of activations. It should be noted that the above method for determining the language expert models that match the text unit set is only illustrative and does not impose specific limitations.
[0098] As an optional implementation, an expert routing model is invoked to determine the language expert model that matches the text unit set in the target language expert model group. This includes: invoking the expert routing model to determine the weights between the text units in the text unit set and each language expert model in the target language expert model group, wherein the weights are used to represent the importance of the corresponding language expert model to the text units in the text unit set; and identifying the language expert models in the target language expert model group whose weights are greater than a weight threshold as the language expert models that match the text units in the text unit set.
[0099] In this embodiment, an expert routing model is invoked. Using this model, the weights between each text unit in the text unit set and each language expert model in the target language expert model group can be determined. Based on these weights, the importance of each language expert model to the text units in the text unit set can be determined. Language expert models in the target language expert model group whose weights are greater than a weight threshold are identified as matching the text units in the text unit set. The aforementioned weight threshold can be a pre-set value, used to filter out the group of language expert models that contribute the most to the text units.
[0100] Optionally, the expert routing model can calculate the weight between each token (i.e., text unit) and all language expert models, and select the K language expert models with the highest weights from multiple weights to process the token. That is, the language expert models with weights greater than the weight threshold in the target language expert model group are used to process the text unit, so as to improve the inference efficiency of the language expert models and activate the diversity of the language expert models.
[0101] For example, to obtain natural language information to be processed: List all employees who joined in 2023. From the natural language information, we can obtain a set of text units containing multiple text units. Taking the MySQL language expert model group as an example, this group can include 8 LoRA experts (i.e., language expert models). Each language expert model can focus on processing different types of SQL keywords or structures, such as select, source, location, etc. We can call the expert routing model, which can calculate the affinity (i.e., weight) between each text unit in the above text unit set and each language expert model in the MySQL language expert model group. For example, for the text unit set "employees who joined in 2023", the expert routing model can calculate the following weights: Language expert model group 1 (focusing on "SELECT"): weight 0.1; Language expert model group 2 (focusing on "FROM"): weight 0.05; Language expert model group 3 (focusing on time logic and "WHERE"): weight 0.6; Language expert model group 4 (focusing on "JOIN"): weight 0.01, etc. Assuming the weight threshold is set to 0.3, only the weight of language expert model group three (0.6) is greater than the threshold. Therefore, the expert routing model will determine that language expert model group three is the language expert model that matches the text unit "employees who joined in 2023". This means that when generating SQL queries, language expert model group three can be activated and will be responsible for processing the above set of text units, because language expert model group three is the only expert with a weight exceeding the threshold, indicating that language expert model group three has higher expertise in handling time logic and location conditions. Furthermore, language expert model group three can be activated through the expert routing model to generate SQL queries for MySQL dialects. For example, for the above set of text units, language expert model three can generate: "WHERE year(join_date) = 2023".
[0102] In this embodiment, by utilizing an expert routing model, the system achieves the goal of accurately generating multi-dialect database queries using the specific capabilities and domain knowledge of language expert models. Simultaneously, it avoids interference from language expert models with low weight or irrelevant information, thus improving the efficiency and accuracy of query language generation. By setting reasonable weight thresholds, the system can filter out unimportant language expert models and focus on those that significantly improve query generation quality, thereby achieving the technical effect of improving the quality of generated query language and solving the technical problem of low-quality generated query language.
[0103] As an optional implementation, the language expert models in the target language expert model group whose weights are greater than a weight threshold are identified as language expert models that match the text units in the text unit set. This includes: obtaining the expert-level balance loss corresponding to the target language expert model group, wherein the expert-level balance loss is used to balance the load of different language expert models in the target language expert model group; and using the expert-level balance loss, identifying the language expert models in the target language expert model group whose weights are greater than a weight threshold and whose loads meet the load threshold range as language expert models that match the text units in the text unit set.
[0104] In this embodiment, the aforementioned expert-level balance loss can be used to balance the workload of different language expert models in the target language expert model group. This workload can characterize the amount of work a language expert model does when processing input data, or the share of work undertaken in a specific task. For example, it can be the resources consumed by the language expert model during operation, or the number of input requests received by the language expert model. It should be noted that this is merely an illustrative example, and no specific limitation is made on the type of workload.
[0105] Optionally, in order to address the problem of unbalanced load that may occur during the routing process, leading to routing crashes, this embodiment introduces an expert-level balancing loss. By utilizing the expert-level balancing loss, text units can be more evenly distributed among different language expert models, preventing some language expert models from being overloaded while others are idle.
[0106] Optionally, the routing strategy within the language expert model group may face load imbalance issues, potentially leading to routing collapse. Furthermore, during training, the expert routing model continuously selects a limited set of language expert models, thus inhibiting their full training. Therefore, to mitigate the risk of routing collapse, an expert-level balancing loss is employed, calculated as follows:
[0107]
[0108] Among them, si,t It can be used to represent the probability that token t is routed to expert i; T can be used to represent the number of text units (also called tokens) processed; fi can be used to represent the proportion of tokens assigned to language expert model i; Pi can be used to represent the probability score of all tokens in a batch being routed to expert i; N can be used to characterize the number of experts. It can be used to characterize expert-level equilibrium loss.
[0109] In this embodiment, to enable multi-dialect-compatible text units to be processed by diverse groups of language expert models, a routing loss is introduced, thereby facilitating the transfer of knowledge data at the token level. To ensure that different language expert models within a group are adequately trained, an expert-level balancing loss is also incorporated, allowing text units to be more evenly distributed across different language expert models.
[0110] As an optional implementation, the method may further include: acquiring general knowledge data among multiple text unit sets corresponding to multiple natural language information; using a language expert model to convert the text unit sets into a query language under the database language, including: using a language expert model to convert the text unit sets into an initial query language under the database language; and migrating the general knowledge data to the initial query language to obtain the query language.
[0111] In this embodiment, the aforementioned general knowledge data can be a common language (or common dialect) among multiple text unit sets, information that can be shared in different dialects or languages, and can be related to the common parts of database models and query syntax, such as SQL keywords and structures, query logic and structures, and the processing of non-SQL elements. It should be noted that this is only an example and there are no specific restrictions on the type of general knowledge data.
[0112] Optionally, by using a language expert model, the set of text units can be converted into an initial query language under the database language, and general knowledge data can be migrated to the initial query language. By supplementing the initial query language with general knowledge data, a more accurate query language can be obtained.
[0113] For example, suppose the natural language information to be processed is "Which movies released in 2023 have a rating higher than 8 points?", then a set of text units ("movies", "release year", "rating") is extracted from the natural language information. The language routing model (also known as the dialect routing model) identifies the text unit set and its association with Cypher based on the text features in the set. Therefore, the text unit set can be assigned to the Cypher language expert model group. Using the language routing model, the top 5 language expert models in the Cypher language expert model group can be selected. These models can be used to process knowledge data related to Cypher grammar. Using the selected language expert models, the text unit set is converted into an initial query language in the database language. The resulting initial query language already covers Cypher's specific grammar, but may have grammatical or logical deficiencies, especially in low-resource language expert model groups where the initial query language may lack sufficient training. Furthermore, general knowledge data can be obtained among multiple text unit sets corresponding to multiple natural language information. By migrating general knowledge data from high-resource dialects (such as MySQL), the initial query language can be improved and supplemented, thereby obtaining a more accurate query language.
[0114] As an optional implementation method, obtaining general knowledge data among multiple text unit sets corresponding to multiple natural language information includes: calling a shared expert model to fuse multiple text unit sets to obtain general knowledge data, wherein the shared expert model is trained using general knowledge data samples among samples of different text unit sets, and the shared expert model and the language expert model are independent of each other.
[0115] In this embodiment, the aforementioned shared expert model can be a shared expert group, which can be visible to multiple text unit sets and can be used to perform sentence-level transfer of common knowledge data between multiple text unit sets. The shared expert model can be trained using common knowledge data samples between different text unit set samples.
[0116] Optionally, to address the data imbalance problem and facilitate the transfer of general knowledge data from high-resource dialects to low-resource dialects, a shared expert model is introduced. This shared expert model, independent of the language expert model, is used to capture general knowledge data across different dialects. The text unit sets of all input sentences are deterministically assigned to the shared expert model, thereby promoting cross-dialect information integration. In summary, by introducing a shared expert model, the transfer of general knowledge data from high-resource dialects to low-resource dialects can be accomplished, where both high-resource and low-resource dialects can serve as text unit sets.
[0117] Optionally, a shared expert model can be invoked. The shared expert model can be used to capture common knowledge data between different dialects. The tokens of all input sentences (i.e., natural language information) will be deterministically assigned to the shared expert model. Through the shared expert model, multiple sets of text units are fused to obtain knowledge data, thereby achieving the goal of promoting cross-dialect information integration.
[0118] Optionally, using only language expert model groups for each dialect cannot achieve the exchange of inherent information (i.e., common knowledge data) between different dialects. Multiple language expert model groups only obtain shared common knowledge data from their respective parameters, resulting in expert parameter redundancy. In this embodiment, a shared expert model is proposed specifically for capturing and integrating common knowledge data in different dialects, thereby making the transfer of common knowledge data more efficient and also alleviating the parameter redundancy problem of language expert models.
[0119] Optionally, a shared expert model can be used to integrate common knowledge data from multiple dialects at the sentence level. Regardless of the router model, tokens in all sentences can be deterministically assigned to the language expert model group within the shared expert model. The output of the shared expert model is as follows:
[0120]
[0121] Where M can be used to represent the number of language expert model groups, and N can be used to represent the number of shared expert models; It can be used to characterize the output of the i-th dialect expert model group. It can be used to characterize the output of the k-th shared expert model; Ns can be used to characterize the number of shared experts; H o It can be used to characterize the fusion of dialect expert model groups and shared expert outputs.
[0122] In this embodiment, by designing a shared expert group and dialect routing loss, it is possible to migrate general knowledge data from high-resource to low-resource areas, thereby effectively alleviating the data imbalance problem caused by low-resource dialects.
[0123] As an optional implementation method, a shared expert model is invoked to fuse multiple text unit sets to obtain general knowledge data, including: invoking a shared expert model to fuse multiple text unit sets at the sentence level to obtain general knowledge data.
[0124] In this embodiment, by invoking a shared expert model, multiple text unit sets can be integrated at the sentence level to obtain general knowledge data.
[0125] Optionally, shared expert models can be used at the sentence level to integrate text unit sets from different database dialects to facilitate the extraction and transfer of general knowledge data. Particularly when dealing with resource-imbalanced text unit sets, shared expert models can help transfer general knowledge data from text unit sets with abundant training data (i.e., high-resource dialects) to text unit sets with less data (i.e., low-resource dialects), thereby improving the performance of the latter.
[0126] For example, suppose we are processing a natural language query: "List all movies created in Neo4j in 2021". This query needs to be translated into Neo4j's Cypher query language. However, Neo4j's training dataset is relatively small, while MySQL's training dataset is very rich, containing a large number of examples related to date, filtering, and selection operations. Among these, text units containing date-related vocabulary (such as "2021" and "created") are likely to be routed to the expert model group for MySQL and PostgreSQL, as these text units have extensive experience and data in handling dates and times. The shared expert group can receive hidden states from multiple input sentences (i.e., natural language information) and attempt to learn common date processing and query generation logic from multiple natural language sources. For example, when the hidden state "list all movies created in Neo4j in 2021" reaches the shared expert model, the model can integrate common knowledge data on date operations from dialects such as MySQL and PostgreSQL. Specifically, the shared expert model can learn common knowledge data such as "2021" representing a date filter condition and "created" possibly involving some form of query operation. The shared expert model can use common knowledge data learned from high-resource dialects to enhance the query language generation capabilities of low-resource dialects. For example, the model can learn common patterns and grammatical structures for date filtering and then apply these patterns to Cypher query generation, even if Cypher uses different keywords and grammatical structures. Ultimately, the shared expert model can collaborate with the Neo4j language expert model group to jointly generate Cypher queries. The shared expert group provides general date processing and filtering logic, while the Neo4j language expert model group provides details specific to Cypher syntax. In generating the query language described above, the date filtering logic (general knowledge data) is learned from high-resource dialects, while the Cypher syntax (specific knowledge) is provided by the Neo4j language expert model group.
[0127] Through the above methods, shared expert models can transfer and integrate common knowledge data across different dialects, thereby improving the accuracy and robustness of query language generation. It should be noted that the method of calling a shared expert model to obtain common knowledge data described above is merely illustrative; any method of obtaining common knowledge data based on a shared expert model should be within the scope of protection of this application, and no specific limitations are imposed here.
[0128] In this embodiment, under the condition of resource imbalance, by integrating general knowledge data of multiple dialects at the sentence level, the general knowledge data can be effectively learned and utilized, while maintaining the accuracy of dialect-specific knowledge. This achieves the technical effect of improving the quality of query language generation and solves the technical problem of low quality of query language generation.
[0129] As an optional implementation, the general knowledge data is migrated to the initial query language to obtain the query language, including: calling the shared expert model and migrating the general knowledge data to the initial query language at the sentence level to obtain the query language.
[0130] In this embodiment, a shared expert model can be invoked. Using the shared expert model, sentence-level transfer of common knowledge data across multiple dialects can be performed, thereby converting the initial query language into a query language.
[0131] Optionally, shared expert models can capture and integrate common knowledge data from different database dialects to facilitate the migration of common knowledge data from high-resource dialects to low-resource dialects in the event of resource imbalance.
[0132] For example, in processing natural language queries, a shared expert model can apply general knowledge data (such as query structure and understanding of SQL keywords) to the initial query language (MySQL). In this way, if the MySQL data is limited, the shared expert model can utilize richer general knowledge data obtained from other dialects (such as PostgreSQL or Cypher) to help generate a more accurate query language.
[0133] Optionally, in the process of converting the initial query language into the query language, the shared expert model can not only process the input set of text units at the sentence level, but also incorporate general knowledge data across dialects into the initial query language to obtain the query language. For example, the shared expert model can understand general knowledge data for the "JOIN" operation, even though this general knowledge data may differ across different relational database dialects. This transfer of general knowledge data helps the language expert model team generate high-quality query information even in dialects with limited resources.
[0134] As an optional implementation, step S208 involves using a language expert model to convert the text unit set into a query language under the database language, including: using the language expert model to determine the grammatical structure of the text unit set, and using the grammatical structure to generate a query language under the database language.
[0135] In this embodiment, the aforementioned syntactic structure can be the syntax and structural rules followed when converting natural language information into a specific database query language (e.g., SQL, Cypher, or nGQL). It can include the basic syntactic elements of the query language, such as the correct use and arrangement of keywords, operators, table names, and field names, and can also include query construction logic, such as how to correctly represent database query operations like joins, filters, and aggregations. It should be noted that this is merely an illustrative example, and no specific limitations are placed on the type and content of the syntactic structure.
[0136] Alternatively, a language expert model can capture the grammatical structure specific to a set of text units to generate a query language associated with that set.
[0137] For example, language expert model groups can be used to process the grammatical features of a specific database language. Each language expert model group focuses on learning and generating queries in the corresponding database language, thereby isolating dialect-specific knowledge, reducing interference between different dialects, and more accurately generating the grammatical structure of text unit sets. After determining the grammatical structure of the text unit set, the query language in the corresponding database language can be generated using the grammatical structure.
[0138] As an optional implementation, the method may further include: adding the matrix to be trained to the weight matrix of the pre-trained model corresponding to the language expert model, wherein the pre-trained model is constructed by a low-rank adaptive model; training the matrix to be trained using knowledge data of the database language, while keeping the weight matrix of the pre-trained model unchanged, to obtain the language expert model in the target language expert model group.
[0139] In this embodiment, the matrix to be trained can be an additional small matrix or a trainable matrix. The low-rank adaptation model can be a LoRA model.
[0140] Optionally, by adding an additional training matrix to the weight matrix of the pre-trained model corresponding to the language expert model, the training matrix can be trained using the knowledge data of the database language, while keeping the original weights of the pre-trained model unchanged. This allows the trained language expert model to retain the ability to understand general knowledge data while learning the knowledge data of a specific set of text units.
[0141] Optionally, if the dialect model is trained separately by first constructing the data and then merging the MOEs, there will be a technical problem of high training cost. To solve the above problem, in this embodiment, a language expert model is constructed based on the LoRA model, so that the model can be trained directly to the end in a single stage. Since this method does not require separate training of the dialect model, it achieves the effect of reducing training cost.
[0142] Optionally, a pre-trained model is constructed through a low-rank adaptation model, a training matrix is obtained, the training matrix is added to the weight matrix of the pre-trained model, and the training matrix is trained using the knowledge data of the database language. This allows the constructed language expert model to learn the knowledge data of a specific dialect, while keeping the weight matrix of the pre-trained model unchanged, thus preventing the loss of knowledge data during the pre-training process.
[0143] Alternatively, the LoRA model can adapt the pre-trained model to learn new language features by attaching a small-scale trainable matrix to be trained, while retaining the general capabilities of the pre-trained model.
[0144] Since language expert models have already learned a large amount of general language knowledge during the pre-training phase, directly modifying the weight matrix of the language expert model when fine-tuning it to adapt to a specific task or dialect may lead to the loss of pre-trained knowledge, i.e., the so-called catastrophic forgetting phenomenon. Therefore, in this embodiment, a low-rank adaptation (LoRA) model is inserted into certain layers of the language expert model, that is, a small matrix is added to the pre-trained weight matrix. This allows the language expert model to maintain its mastery of the original knowledge data while learning new knowledge (e.g., the grammar of a specific database dialect). Furthermore, fine-tuning the weight matrix through a small matrix results in a significantly smaller number of parameters compared to directly fine-tuning the weight matrix of the pre-trained model, thereby improving data processing efficiency.
[0145] In this embodiment, text unit sets are obtained from multiple natural language information sets to be processed. Each text unit set includes language features in the natural language information that can be converted to a database language. The database language includes structured and unstructured database languages. A language routing model is used to assign the text unit sets to target language expert model groups within multiple language expert model groups. The language routing model is trained using text unit set samples, the labels of the corresponding database languages, and the corresponding language expert model groups. Different language expert model groups correspond to different database languages, and each language expert model group has learned the knowledge data of the corresponding database languages. At least one language expert model matching the text unit set is determined within the target language expert model group. The language expert model is then used to convert the text unit sets into query language under the database language, thereby improving the quality of generated query language and solving the technical problem of low generated query language quality.
[0146] This application also provides another method for generating query language, which can be applied to database management systems. Figure 3 This is a flowchart of another query language generation method according to an embodiment of this application, such as... Figure 3 As shown, the method may include the following steps:
[0147] Step S302: Obtain text unit sets from the multiple input natural language information respectively.
[0148] In the technical solution provided in step S302 of this application, the natural language information can be information input by a user through a terminal such as a computer, mobile phone, or tablet, and can be used to query the database. The set of text units can include dialect features in the natural language information that allow conversion to the database dialect, and can contain multiple text units. The dialect features can refer to syntax, keywords, functions, or data types unique to the query language of a specific database management system, and can be used to distinguish different database dialects. The database dialect can include structured database language and unstructured database language.
[0149] Optionally, multiple natural language information inputs can be obtained, and a set of text units can be extracted from the multiple natural language information. The set of text units may include words, phrases, sentences or higher-level semantic units. Multiple text units in the set of text units can be used to reflect the unique grammar, vocabulary or expression habits of a specific database dialect.
[0150] Optionally, text unit sets can serve as carriers of dialect features. For example, in database query generation, even simple keywords such as "SELECT," "FROM," and "WHERE" may have different usage and grammatical structures in different database dialects such as MySQL, PostgreSQL, or Cypher. These differences in usage and grammatical structure constitute dialect features. When processing the conversion from natural language information to query language, text unit sets (e.g., words or phrases) in the natural language information can be identified, and based on the dialect features of the database dialect, these text unit sets can be mapped to query structures specific to that dialect.
[0151] In this embodiment, the connection between dialect features and text unit sets is that text unit sets carry and embody dialect features in multi-dialect query generation tasks, while dialect expert models (such as MoMQ) generate query languages that conform to specific dialect grammar by identifying and processing text unit sets and applying the correct dialect features.
[0152] Step S304: Invoke the dialect routing model to assign the text unit set to the target dialect expert model group among multiple dialect expert model groups.
[0153] Among them, different dialect expert model groups correspond to different database dialects, and the dialect expert model groups have learned the query syntax knowledge data of the corresponding database dialects.
[0154] In the technical solution provided in step S304 of this application, a dialect routing model is trained using text unit set samples, the database dialect labels corresponding to the text unit set samples, and the dialect expert model groups corresponding to the text unit set samples. After obtaining the text unit set, the dialect routing model can be invoked to route the text unit set with dialect features to the target dialect expert model group among the multiple corresponding dialect expert model groups, thereby achieving the technical effect of correctly routing the text unit set and solving the technical problem of not being able to correctly route the text unit set. The aforementioned target dialect expert model group can be a dialect expert model group that matches the text unit set. The aforementioned dialect routing model can be a dialect router used to allocate the text unit set to the corresponding target dialect expert model group.
[0155] Optionally, the labels for the aforementioned database dialects can be vector labels, identifiers used to identify and distinguish different versions or types of database dialects, or used to determine which specific database query language format the natural language information should be converted into.
[0156] For example, when constructing the training dataset, each text unit set and its corresponding query pair are labeled with a database dialect. For instance, a training sample containing a text unit set of "query the names and ages of all employees" might have the database dialect label "MySQL" if the target SQL query is executed in a MySQL environment, and "PostgreSQL" if it's designed for a PostgreSQL environment. These labels can guide the dialect routing model to implement a multi-level routing strategy, ensuring that text units within a set can be routed to the appropriate target dialect expert model group for processing that specific text unit.
[0157] Step S306: Invoke the expert routing model and determine at least one dialect expert model that matches the text unit set in the target dialect expert model group. The expert routing model is trained using the text unit sample set and the labels of the corresponding dialect expert model.
[0158] In the technical solution provided in step S306 of this application, an expert routing model is trained using the text unit sample set and the labels of the corresponding dialect expert models. Using the expert routing model, at least one dialect expert model matching the text unit set can be determined from the target dialect expert model group. The aforementioned expert routing model can be an expert router, which can be used to route the text unit set to the corresponding dialect expert model.
[0159] Optionally, an expert routing model is used to determine which dialect expert models in the target dialect expert model group match the specific input token (i.e., the set of text units). The expert routing model can employ a sparse activation strategy, activating the top k dialect expert models for each text unit. Here, k is a hyperparameter that can be adjusted according to resource and task requirements. The expert routing model determines which dialect expert models are suitable for processing specific text units by calculating the affinity (i.e., weight) between each text unit and each dialect expert model. This avoids all dialect expert models processing all text units, thus reducing computational costs. Simultaneously, it ensures that the dialect expert models processing the token are specifically trained to solve related problems, thereby improving the accuracy and efficiency of generating query language.
[0160] In this embodiment, to prevent routing collapse, i.e., a few dialect expert models taking on too much work while other dialect expert models are hardly used, the expert routing model also incorporates expert balancing loss. Through expert balancing loss, it is ensured that each expert can obtain sufficient training data, avoiding parameter redundancy and model performance bottlenecks.
[0161] Optionally, a dialect routing model is used to identify the target dialect expert model group among multiple dialect expert model groups. The dialect routing model also utilizes dialect smoothing techniques to soften dialect labels, allowing some tokens to be routed to multiple dialect expert groups, thereby facilitating a more efficient transfer of general knowledge data between different dialects.
[0162] In summary, the expert routing model is used for efficient and even task allocation within a specific target dialect expert model group; the dialect routing model performs intelligent traffic scheduling between different dialect expert model groups, which not only isolates dialect-specific attributes but also promotes the sharing of general knowledge data. By utilizing both the expert routing model and the dialect routing model, the technical effect of improving the generation quality of query language is achieved, and the technical problem of low generation quality of query language is solved.
[0163] Step S308: Using a dialect expert model, the text unit set is converted into a query language in the database dialect.
[0164] In the technical solution provided in step S308 of this application, natural language information is assigned to a target dialect expert model group through a dialect routing model. This target dialect expert model group can be used to process knowledge related to a specific database dialect. Each dialect expert model group can contain multiple LoRA experts (i.e., dialect expert models). The expert routing model calculates the affinity of text units in the text unit set to each dialect expert model, and then selects the top k dialect expert models to process the text unit set. At the same time, expert balance loss can be used to ensure load balancing and avoid always selecting the same group of dialect expert models to process all text units. After determining the dialect expert model to process the specific text units, the selected dialect expert model can be used to convert the text unit set into a query language under the specific database dialect. For example, the MySQL dialect expert model can use MySQL syntax knowledge to convert the text unit set into an SQL query; the Cypher dialect expert model can generate a Cypher language query in neo4j from the text unit set.
[0165] In this embodiment, text unit sets are obtained from multiple input natural language information sources. Each text unit set includes dialect features in the natural language information that can be converted to a database dialect. Database dialects include structured and unstructured database languages. A dialect routing model is invoked to assign the text unit sets to target dialect expert model groups among multiple dialect expert model groups. The dialect routing model is trained using text unit set samples, labels of the corresponding database dialects, and the corresponding dialect expert model groups. Different dialect expert model groups correspond to different database dialects, and each dialect expert model group has learned the query syntax knowledge data of the corresponding database dialect. An expert routing model is invoked to determine at least one dialect expert model matching the text unit set from the target dialect expert model groups. This expert routing model is trained using text unit sample sets and labels of the corresponding dialect expert models. The dialect expert models are then used to convert the text unit sets into query language in the database dialect, thereby improving the quality of generated query language and solving the problem of low-quality generated query language.
[0166] According to embodiments of this application, from the perspective of human-computer interaction, a method for generating query language is also provided. Figure 4 This is a flowchart of another query language generation method according to an embodiment of this application, such as... Figure 4 As shown, the method may include the following steps:
[0167] Step S402: In response to the input operation applied to the operation interface, multiple natural language information to be processed is displayed on the operation interface. The natural language information includes a set of text units, which includes language features in the natural language information that can be converted to database language. The database language includes structured database language and unstructured database language.
[0168] In the technical solution provided in step S402 of this application, the above-mentioned operation interface can be a display interface, such as the display screen of a mobile terminal, the display interface of a computer, etc. It should be noted that this is only an example and there is no specific limitation on the type of operation interface.
[0169] Optionally, in response to an input operation, multiple pieces of natural language information to be processed can be acquired by the user through the input operation, and these multiple pieces of natural language information to be processed can be displayed on the operation interface. The aforementioned natural language information may include multiple text units, that is, the natural language information may include a set of text units. The set of text units may include language features in the natural language information that can be converted to the database language, such as the structure and logic between multiple text features. It should be noted that this is only an illustrative example, and no specific restrictions are placed on the type of speech features.
[0170] Step S404: In response to the generation operation applied to the operation interface, the query language of the natural language information under the corresponding database language is displayed on the operation interface. The query language under the database language is obtained by converting the text unit set using at least one language expert model that matches the text unit set in the natural language information. The language expert model comes from the target language expert model group. The target language expert model group is obtained by allocating the text unit set among multiple language expert model groups using a language routing model. The language routing model is trained using text unit set samples, the labels of the database language corresponding to the text unit set samples, and the language expert model group corresponding to the text unit set samples. Different language expert model groups correspond to different database languages, and the language expert model groups have learned the knowledge data of the corresponding database languages.
[0171] In the technical solution provided by step S404 of this application, the above-mentioned generation operation can be triggered by the user through the control on the touch operation interface, which is used to indicate the conversion of natural language information into query language. The conversion of natural language information into query language can be carried out according to steps S202 to S208. It should be noted that this is only an example and there is no specific limitation on the triggering method of the generation operation.
[0172] In this embodiment, in response to an input operation on the operation interface, multiple natural language information to be processed are displayed on the operation interface. The natural language information includes a set of text units, which includes language features in the natural language information that can be converted to the database language. In response to a generation operation on the operation interface, the query language of the natural language information in the corresponding database language is displayed on the operation interface. The query language in the database language is obtained by converting the text unit set using at least one language expert model that matches the text unit set in the natural language information. The language expert model comes from a target language expert model group, which is obtained by allocating the text unit set among multiple language expert model groups using a language routing model. The language routing model is trained using text unit set samples, the labels of the database language corresponding to the text unit set samples, and the language expert model groups corresponding to the text unit set samples. Different language expert model groups correspond to different database languages, and the language expert model groups have learned the knowledge data of the corresponding database languages. This achieves the technical effect of improving the generation quality of the query language and solves the technical problem of low generation quality of the query language.
[0173] This application also provides a method for generating query language. Figure 5 This is a flowchart of another query language generation method according to an embodiment of this application. For example... Figure 5 As shown, the method may include the following steps:
[0174] Step S502: By calling the first interface, text unit sets are obtained from multiple natural language information to be processed. The first interface includes a first parameter, the parameter value of which includes the text unit set. The text unit set includes language features in the natural language information that can be converted to database language. The database language includes structured database language and unstructured database language.
[0175] In the technical solution provided by step S502 of this application, a set of text units can be obtained from multiple natural language information to be processed by calling a first interface. The first interface may include a first parameter, the value of which can be a set of text units.
[0176] For example, a terminal device (i.e., a user) can pass a text unit set as the first parameter through the application programming interface (API) of a Software as a Service (SaaS) service provider, allowing the text unit set to be processed. The SaaS service provider's system will receive and process the text unit set. The first interface can be an API endpoint provided by the SaaS platform, which the user can call to send the text unit set, with the first parameter being used to pass the text unit set. In this way, the user can utilize the functionality provided by the SaaS platform to perform subsequent processing of the text unit set.
[0177] Step S504: Using the language routing model, the text unit set is assigned to the target language expert model group among multiple language expert model groups. The language routing model is trained using text unit set samples, the labels of the database language corresponding to the text unit set samples, and the language expert model group corresponding to the text unit set samples. Different language expert model groups correspond to different database languages, and the language expert model groups have learned the knowledge data of the corresponding database languages.
[0178] Step S506: In the target language expert model group, identify at least one language expert model that matches the text unit set.
[0179] Step S508: Using a language expert model, the text unit set is converted into a query language under the database language.
[0180] Step S510: Output the query language under the database language by calling the second interface, wherein the second interface includes a second parameter, and the parameter value of the second parameter includes the query language under the database language.
[0181] In the technical solution provided by step S510 of this application, the query language can be output by calling the second interface. The second interface may include a second parameter, and the parameter value of the second parameter can be the query language.
[0182] For example, the query language can be passed as the second parameter value through an application programming interface (API) to provide the query language to the end device. The SaaS service provider's system will transmit the query language to the end device and / or platform device through the interface. The second interface can be an API endpoint provided by the SaaS platform, which can be called to send the second parameter, which is used to transmit the query language.
[0183] Through steps S502 to S510, text unit sets are obtained from multiple natural language information to be processed by calling a first interface. The first interface includes a first parameter whose value includes the text unit set. The text unit set includes language features in the natural language information that can be converted to the database language. A language routing model is used to assign the text unit set to a target language expert model group among multiple language expert model groups. The language routing model is trained using text unit set samples, the database language labels corresponding to the text unit set samples, and the language expert model groups corresponding to the text unit set samples. Different language expert model groups correspond to different database languages, and the language expert model groups have learned the knowledge data of the corresponding database languages. At least one language expert model matching the text unit set is determined in the target language expert model group. The text unit set is converted into a query language under the database language using the language expert model. The query language under the database language is output by calling a second interface, where the second interface includes a second parameter whose value includes the query language under the database language. This achieves the technical effect of improving the quality of the generated query language and solves the technical problem of low quality in the generated query language.
[0184] According to the embodiments of this application, an embodiment of a query language generation system is also provided. It should be noted that the query language generation system of this embodiment can be used to execute the query language generation method of the embodiments of this application. Figure 6 This is a schematic diagram of a query language generation system according to an embodiment of this application, such as... Figure 6 As shown, the query language generation system 600 may include: a data input terminal 602, a language routing terminal 604, an expert routing terminal 606, a data conversion terminal 608, and a data output terminal 610.
[0185] The data input terminal 602 is used to obtain text unit sets from multiple natural language information to be processed, wherein the text unit sets include language features in the natural language information that can be converted to database languages, and the database languages include structured database languages and unstructured database languages.
[0186] In this embodiment, the data input terminal 602 can be used to obtain a set of text units from the natural language information to be processed.
[0187] The language routing endpoint 604 is used to route a set of text units to a target language expert model group among multiple language expert model groups using a language routing model. The language routing model is trained using text unit set samples, the labels of the database languages corresponding to the text unit set samples, and the language expert model groups corresponding to the text unit set samples. Different language expert model groups correspond to different database languages, and the language expert model groups have learned the knowledge data of the corresponding database languages.
[0188] In this embodiment, the language routing end 604 may include a language router, which may be a dialect routing end, and may be used to determine the target language expert model group that matches the text unit set, so as to allocate the text unit set to the corresponding query language.
[0189] Expert routing terminal 606 is used to determine at least one language expert model that matches the set of text units in the target language expert model group.
[0190] In this embodiment, the expert router 606 can be an expert router, which can be used to determine at least one language expert model in the target language expert model group that matches the text unit set, and send the text units in the text unit set to the corresponding language expert model.
[0191] Data conversion terminal 608 is used to convert a set of text units into a query language under the database language using a language expert model.
[0192] In this embodiment, the data conversion segment 608 may include at least one language expert model, which can be used to convert the text unit set to obtain the query language under the database language.
[0193] Data output terminal 610 is used to output the query language under the database language.
[0194] In this embodiment, a text unit set is obtained from multiple natural language information to be processed via data input terminal 602. The text unit set includes language features in the natural language information that can be converted to a database language. The database language includes structured and unstructured database languages. The text unit set is routed to a target language expert model group among multiple language expert model groups using a language routing terminal 604 and a language routing model. The language routing model is trained using text unit set samples, the labels of the corresponding database languages, and the corresponding language expert model groups. Different language expert model groups correspond to different database languages, and each language expert model group has learned the knowledge data of the corresponding database language. At least one language expert model matching the text unit set is determined from the target language expert model group via expert routing terminal 606. The text unit set is converted into a query language under the database language using a data conversion terminal 608 and a data output terminal 610. This improves the quality of the generated query language and solves the problem of low-quality generated query language.
[0195] Currently, with the advancement of natural language processing technology, especially the development of large language models, the ability of large language models to transform natural language into structured query language has been significantly improved. However, existing solutions are usually only optimized for specific database dialects and cannot achieve a unified database management system that works across multiple database dialects.
[0196] Traditional text-to-SQL (TTO) conversion typically uses an encoder-decoder architecture, which improves the efficiency of SQL conversion by enhancing the encoder's ability to understand questions and patterns. In recent years, with the rise of large language models (MLMs), these tasks have gradually shifted towards LLM-based methods. However, due to syntactic differences between different relational database dialects—such as the use of specific keywords in MySQL and PostgreSQL—limitations remain when dealing with multi-dialect query generation. Furthermore, these differences are more pronounced between relational and non-relational databases, manifesting in query logic. For example, the "SELECT" statement in MySQL differs from the "MATCH" statement in Cypher. Ignoring these dialectal differences can interfere with accurate query generation, leading to low-quality query language generation.
[0197] Meanwhile, due to the high cost of annotating natural language to database query language, and the limited data volume for most dialects, the similarity between natural language problems across dialects and databases represents a kind of transferable general knowledge data that is not fully utilized. Transferring this general knowledge data from resource-rich dialects to resource-poor dialects will help solve the problem of data imbalance. Therefore, in this embodiment, a multi-dialect database query language generation method based on hybrid experts is proposed. This method utilizes a novel framework of Mixture-of-Experts Enhanced Multi-Dialect Query Generation (MoMQ) to solve the problem of multi-dialect query generation across relational and non-relational databases. This overcomes the problems of grammatical differences between different database dialects and data imbalance, and improves the quality of query generation through a hybrid expert model, thereby achieving the technical effect of improving the quality of generated query language and solving the technical problem of low quality generated query language.
[0198] The following is a further introduction to an optimization method for a text image model under multi-image control conditions proposed in the embodiments of this application.
[0199] Figure 7 This is a schematic diagram of a MoMQ framework according to an embodiment of this application, as shown below. Figure 7 As shown, multiple natural language information sets to be processed are obtained, resulting in text unit sets (MySQL Tokens) 701 and 702 (Cypher Tokens). Using dialect router 703, text unit sets 701 and 702 are assigned to target language expert model groups 704 (MySQL Expert Group) and 705 (CypherExpert Group). Using expert routers 706 and 707, at least one dialect expert model matching text unit set 701 and at least one dialect expert model matching text unit 702 are determined within the target dialect expert model group. For example, two dialect expert models can be determined. It should be noted that this is only an example and the number of dialect expert models is not specifically limited.
[0200] In this embodiment, a shared expert group (708) may also be included. This shared expert group can be constructed from a low-rank adaptive model and can be used for migration processing of general knowledge data. Through an expert router (709), a set of text units can be transmitted to the shared expert group (708). Using the shared expert group (708), the general knowledge data is migrated to an initial query language to obtain the query language. The query language can be the output (709) of the MoE model.
[0201] Alternatively, the dialect expert model can be constructed from a low-rank adaptive model.
[0202] In this embodiment, a multi-dialect query generation framework based on expert hybrid (MoE) is proposed. This framework unifies the generation of query languages in relational and non-relational databases. Detailed MoE structures can be developed using multiple low-rank adaptation models. Simultaneously, pre-built pre-trained models (e.g., ...) can be frozen. Figure 7 The Attention, FFN Up, FFN Down MoE mechanisms are used to prevent the loss of pre-trained knowledge. Dedicated dialect expert models can be created for each dialect to isolate dialect-specific general knowledge data and reduce interference during query language generation.
[0203] Optionally, such as Figure 7 As shown, a dialect expert model can include a feed-forward network (FFN), a feed-forward network down with a mixture of experts (FFN Down MoE), a normalization layer (norm layer), and an attention mechanism.
[0204] Optionally, to address the imbalance in multi-dialect data, a shared expert group with multiple dialect visibility is proposed. This shared expert group enhances the transfer of common knowledge between high-resource and low-resource dialects. Furthermore, a multi-level routing strategy is proposed, including dialect routers and expert routers. The dialect router routes text unit sets to their respective dialect expert models; on the other hand, with the help of Dialect Router Loss, it can assign other text unit sets to all groups to facilitate token-level knowledge transfer. The expert router can be used to activate the top k experts in the dialect expert model where the input token resides. Expert Balance Loss can also be utilized to avoid load imbalances caused by known routing failures.
[0205] In this embodiment, the core of MoMQ lies in utilizing MoE, where MoE can contain dialect expert model groups and shared expert groups for each database dialect. Dialect expert model groups can specifically learn knowledge data for a particular database dialect and effectively isolate knowledge data from multiple dialects, reducing interference during query generation. Shared expert groups are visible to multiple dialects and can perform sentence-level transfer of common knowledge data across dialects. Furthermore, MoMQ introduces a multi-level routing structure, consisting of dialect routers and expert routers within the target dialect expert model group. Dialect routers can be used to route tokens with dialect characteristics to the corresponding dialect expert model group, and expert routers are used to activate the top-k dialect expert models within the group. Further, Dialect Router Loss can be used to allow tokens common to multiple dialects to be processed by diverse dialect expert model groups, thereby promoting token-level knowledge transfer. ExpertBalance Loss is used to ensure that different dialect expert models within a group can be fully trained.
[0206] In this embodiment, each database dialect has a dedicated group of language expert models to learn the dialect-specific knowledge data. By using the group of language expert models, full isolation of dialect-specific knowledge data can be achieved.
[0207] Optionally, each language expert model group can consist of multiple LoRA models (Modules) and a top-k expert router. The LoRA model can be used to adapt the pre-trained model to learn new task or dialect features, but it does not update the original weights of the pre-trained model. The expert router can be used to assign input tokens to appropriate language expert models. The aforementioned LoRA model can include fine-tuning the weights of the pre-trained model by introducing a low-rank matrix, thereby effectively reducing the number of parameters in the pre-trained model while maintaining or improving its performance. In LoRA, "LoRA Up" and "LoRA Down" can typically be used to characterize two phases of the pre-trained model: the LoRA fine-tuning phase (LoRAUp), in which the weights of the original neural network model can be fine-tuned, for example, by introducing a low-rank matrix (e.g., a small matrix) and multiplying this matrix by the original weights. The LoRA compression stage (LoRA Down) further reduces the number of model parameters. While the LoRA Up stage introduces a low-rank matrix to reduce the number of parameters, the pre-trained model still has a relatively large number of parameters. Therefore, the LoRA Down stage uses techniques such as knowledge distillation and pruning to further reduce the number of parameters, resulting in a more lightweight model. Through these two stages, LoRA Up and LoRA Down, a lightweight model with fewer parameters but similar performance can be obtained.
[0208] Optionally, the language expert model can train the training matrix by adding an additional training matrix to the weight matrix of the pre-trained model corresponding to the language expert model, using the knowledge data of the database language, while keeping the original weights of the pre-trained model unchanged. This allows the trained language expert model to retain the ability to understand general knowledge data while learning the knowledge data of a specific set of text units.
[0209] Optionally, the expert router can be used to calculate the weights between each token and multiple language expert models in the target language expert model group that match the text unit set, and select the K language expert models with the highest weights to process the text unit set.
[0210] Optionally, the output of the i-th language expert model as follows:
[0211]
[0212] in, It can be used to characterize the k-th LoRA expert in the i-th expert group. It can be used to characterize the weights from tokens to expert models; H can be used to represent the trainable matrix to be trained; H can be used to represent the hidden state of all input tokens; TopK can be used to represent the set of the top K highest scores among the token weights computed in all N language expert models. It can be used to represent the k-th gate value of a language expert model.
[0213] In this embodiment, a shared expert model (i.e., a shared expert group) is also proposed, which is visible to multiple dialects and helps to transfer general knowledge data from resource-rich dialects to resource-poor dialects.
[0214] Optionally, in order to address the data imbalance problem and facilitate the transfer of general knowledge data from high-resource dialects to low-resource dialects, a shared expert model is introduced. This shared expert model is independent of the language expert model and is used to capture general knowledge data between different dialects. The text unit set of all input sentences is deterministically assigned to the shared expert model, thereby promoting cross-dialect information integration.
[0215] Optionally, a shared expert model can be used to integrate common knowledge data from multiple dialects at the sentence level. Regardless of the router model, tokens in all sentences can be deterministically assigned to the language expert model group within the shared expert model. The output of the shared expert model is as follows:
[0216]
[0217] In this embodiment, guided by sentence-level dialect labels, the dialect router can make correct routing decisions, thereby correctly routing tokens of different dialects to the corresponding language expert model groups, so as to form complete isolation between different dialect expert groups.
[0218] Optionally, the language routing model can perform correct routing under the guidance of sentence-level dialect hard labels, thereby achieving complete isolation between different language expert model groups. However, there may be some similarities between different dialects; for example, "LIMIT" and "ORDER BY" are both valid tokens in relational and non-relational database dialects. Furthermore, different dialects have high similarity in natural language problem understanding and database pattern understanding. If these similar tokens have the opportunity to enter multiple dialect expert groups, especially from high-resource dialects to low-resource dialects, this will further promote token-level general knowledge transfer. Therefore, in this embodiment, a language routing model trained using routing loss is designed. The trained language routing model can be used to further reduce the occurrence of dialect isolation by replacing hard dialect labels with a smooth distribution. The smooth distribution allocates lower values to real dialects and allocates some value to other dialects. Under the constraints of DRL, tokens of specific dialects are excluded from having a higher probability of being routed to language routing models on the output weights of various language expert model groups. This allows similar tokens to have the opportunity to enter multiple language expert model groups, especially from resource-rich dialects to resource-poor dialects, thereby promoting more comprehensive dialect information exchange and knowledge data transfer.
[0219] In this embodiment, in order to solve the problem of unbalanced load that may occur during the routing process, which may lead to routing crashes, this embodiment introduces an expert-level balancing loss. By utilizing the expert-level balancing loss, text units can be more evenly distributed among different language expert models, preventing some language expert models from being overloaded while others are idle.
[0220] In this embodiment, MoMQ significantly outperforms baseline methods across multiple database dialects. Particularly in cases of imbalanced data, it improves accuracy by 4%–6%. Furthermore, MoMQ's robustness across different settings is also significantly enhanced.
[0221] Optionally, the MoMQ framework not only solves the task of generating multi-dialect queries, but also effectively handles the problem of data imbalance by introducing mechanisms such as hybrid expert models and shared expert models. This framework exhibits strong applicability and flexibility in multi-dialect environments.
[0222] In this embodiment, for each set of text units, there is a corresponding target dialect expert model group to process the set of text units. When new natural language information is received, the natural language query is dynamically input into the appropriate dialect expert model group according to the input natural language information to generate a more accurate and efficient query language.
[0223] For example, if a user enters natural language information about a MySQL database: "Query the names and ages of all students in the student table", the text unit set obtained from the natural language information is: "student table, name, and age". Based on the linguistic features of the text unit set, it can be determined that the text unit set is a question about the MySQL database. Furthermore, this text unit set can be assigned to the MySQL dialect expert model group. The MySQL dialect expert model group generates a complete SQL query language, such as select name, age from student table, based on the structure and syntax of the text unit set, and returns it to the user.
[0224] Using the above method, the system can identify the relevant database dialect based on the natural language information input by the user, and call the corresponding dialect expert model group for processing to improve the effect and accuracy of the generated query language. This achieves the goal of accurately converting natural language information into structured query language, making it easier for users to operate and manage the database.
[0225] In this embodiment, a dedicated group of language expert models is established for each dialect to isolate knowledge data specific to that dialect and reduce interference between different dialects. This group of language expert models can be used to process query language generation tasks related to its dialect, thereby better capturing the unique grammatical structure of that dialect.
[0226] In this embodiment, the above method achieves enhanced multi-dialect support, enabling effective query generation across various database dialects, including relational databases such as MySQL and PostgreSQL, and non-relational databases such as Neo4j's Cypher language and NebulaGraph's nGQL language. It should be noted that this is merely an illustrative example and does not impose specific limitations on the database type. Even under resource constraints, this method maintains high execution accuracy; for instance, it achieves higher execution accuracy than the baseline in the MySQL dialect, and similar performance is observed in other dialects.
[0227] In this embodiment, a language expert model group (e.g., dialect expert group) is provided for each database language (e.g., database dialect). The language expert model can be used to learn the knowledge data of the corresponding database language to isolate dialect-specific knowledge and reduce interference during generation. The text unit set corresponding to the natural language information is routed to the corresponding target language expert model group. A language expert model is selected from the target language expert model group to generate the query language. This effectively generates the query language across multiple database dialects, improves the quality of the generated query language, and thus achieves the technical effect of improving the quality of the generated query language, solving the technical problem of low quality of generated query language.
[0228] The method embodiments provided in this application can also be executed on mobile terminals, computer terminals, or similar computing devices. Figure 8 This is a hardware structure block diagram of a computer terminal (or mobile device) according to a query language generation method according to an embodiment of this application, such as... Figure 8 As shown, a computer terminal 80 (or mobile device) may include one or more processors 802 (shown as 802a, 802b, ..., 802n in the figure) 802 (processor 802 may include, but is not limited to, a microprocessor (MCU) or a field-programmable gate array (FPGA), etc.), a memory 804 for storing data, and a transmission device 806 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a Universal Serial Bus (USB) port (which may be included as one of the ports of a BUS bus), a network interface, a power supply, and / or a camera. Those skilled in the art will understand that... Figure 8 The structure shown is for illustrative purposes only and does not limit the structure of the aforementioned electronic device. For example, the computer terminal 80 may also include... Figure 8 The more or fewer components shown, or having the same Figure 8 The different configurations shown.
[0229] Figure 8 The hardware structure block diagram shown can serve as an exemplary block diagram not only for the aforementioned computer terminal 80 (or mobile device), but also as an exemplary block diagram for the aforementioned server.
[0230] The memory 804 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the data processing method in this embodiment. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory 804, thereby realizing the aforementioned data processing method. The memory 804 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 804 may further include memory remotely located relative to the processor, and these remote memories can be connected to the computer terminal 80 via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0231] The transmission device 806 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the communication provider of the computer terminal 80. In one example, the transmission device 806 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 806 may be a Radio Frequency (RF) module used for wireless communication with the Internet.
[0232] The display can be, for example, a touchscreen liquid crystal display (LCD), which allows users to interact with the user interface of a computer terminal 80 (or mobile device).
[0233] 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 used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation portals are provided for users to choose to authorize or refuse.
[0234] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.
[0235] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, they can also be implemented by hardware. Based on this 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 disk), and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods of the various embodiments of this application.
[0236] According to embodiments of this application, a method for implementing the above is also provided. Figure 2 The query language generation method shown is a query language generation device.
[0237] Figure 9 This is a schematic diagram of a query language generation apparatus according to an embodiment of this application, such as... Figure 9 As shown, the query language generation device 900 may include: a first acquisition unit 902, a first allocation unit 904, a first determination unit 906, and a first conversion unit 908.
[0238] The first acquisition unit 902 is used to acquire text unit sets from multiple natural language information to be processed, wherein the text unit sets include language features in the natural language information that can be converted to database languages, and the database languages include structured database languages and unstructured database languages.
[0239] The first allocation unit 904 is used to allocate a set of text units to a target language expert model group among multiple language expert model groups using a language routing model. The language routing model is trained using text unit set samples, the labels of the database languages corresponding to the text unit set samples, and the language expert model groups corresponding to the text unit set samples. Different language expert model groups correspond to different database languages, and the language expert model groups have learned the knowledge data of the corresponding database languages.
[0240] The first determining unit 906 is used to determine at least one language expert model that matches the text unit set in the target language expert model group.
[0241] The first conversion unit 908 is used to convert a set of text units into a query language under the database language using a language expert model.
[0242] It should be noted that the first acquisition unit 902, the first allocation unit 904, the first determination unit 906, and the first conversion unit 908 correspond to steps S202 to S208. The four units and their corresponding steps implement the same instances and application scenarios, but are not limited to the content disclosed in the above embodiments. It should also be noted that the above units can be hardware or software components stored in memory and processed by one or more processors. Furthermore, the above units can also run as part of a device in the computer terminal provided in the above embodiments.
[0243] According to an embodiment of this application, another method for implementing the above is also provided. Figure 3 The query language generation method shown is a query language generation device that can be applied to a database management system.
[0244] Figure 10 This is a schematic diagram of an apparatus for generating a query language according to an embodiment of this application, such as... Figure 10 As shown, the query language generation device 1000 may include: a second acquisition unit 1002, a second allocation unit 1004, a calling unit 1006, and a second conversion unit 1008.
[0245] The second acquisition unit 1002 is used to acquire a set of text units from multiple input natural language information, wherein the set of text units includes dialect features in the natural language information that can be converted to the database dialect, and the database dialect includes structured database language and unstructured database language.
[0246] The second allocation unit 1004 is used to call the dialect routing model to allocate the text unit set to the target dialect expert model group among multiple dialect expert model groups. The dialect routing model is trained using text unit set samples, the labels of the database dialects corresponding to the text unit set samples, and the dialect expert model groups corresponding to the text unit set samples. Different dialect expert model groups correspond to different database dialects, and the dialect expert model groups have learned the query syntax knowledge data of the corresponding database dialects.
[0247] Calling unit 1006 is used to call the expert routing model to determine at least one dialect expert model that matches the text unit set in the target dialect expert model group. The expert routing model is trained using the text unit sample set and the labels of the corresponding dialect expert model.
[0248] The second conversion unit 1008 is used to convert the text unit set into the query language of the database dialect using a dialect expert model.
[0249] It should be noted that the second acquisition unit 1002, the second allocation unit 1004, the calling unit 1006, and the second conversion unit 1008 mentioned above correspond to steps S302 to S308. The four units and their corresponding steps implement the same instances and application scenarios, but are not limited to the content disclosed in the above embodiments. It should also be noted that the aforementioned units can be hardware or software components stored in memory and processed by one or more processors. These units can also run as part of a device in the computer terminal provided in the above embodiments.
[0250] According to an embodiment of this application, another method for implementing the above is also provided. Figure 4 The query language generation method shown is a query language generation device.
[0251] Figure 11 This is a schematic diagram of an apparatus for generating a query language according to an embodiment of this application, such as... Figure 11 As shown, the query language generation device 1100 may include: a first display unit 1102 and a second display unit 1104.
[0252] The first display unit 1102 is used to respond to input operations on the operation interface and display multiple natural language information to be processed on the operation interface. The natural language information includes a set of text units, which includes language features in the natural language information that can be converted to a database language. The database language includes structured database language and unstructured database language.
[0253] The second display unit 1104 is used to respond to the generation operation applied to the operation interface and display the query language of the natural language information under the corresponding database language on the operation interface. The query language under the database language is obtained by converting the text unit set using at least one language expert model that matches the text unit set in the natural language information. The language expert model comes from the target language expert model group. The target language expert model group is obtained by allocating the text unit set among multiple language expert model groups using a language routing model. The language routing model uses text unit set samples, the labels of the database language corresponding to the text unit set samples, and the text unit set.
[0254] It should be noted that the first display unit 1102 and the second display unit 1104 mentioned above correspond to steps S402 to S404. The two units and the corresponding steps implement the same instances and application scenarios, but are not limited to the content disclosed in the above embodiments. It should be noted that the above units can be hardware components or software components stored in memory and processed by one or more processors. The above units can also be part of a device and run in the computer terminal provided in the above embodiments.
[0255] According to an embodiment of this application, another method for implementing the above is also provided. Figure 5 The query language generation method shown is a query language generation device.
[0256] Figure 12 This is a schematic diagram of an apparatus for generating a query language according to an embodiment of this application, such as... Figure 12 As shown, the query language generation device 1200 may include: a third acquisition unit 1202, a third allocation unit 1204, a determination unit 1206, a third conversion unit 1206, and an output unit 1210.
[0257] The third acquisition unit 1202 is used to acquire a set of text units from multiple natural language information to be processed by calling a first interface. The first interface includes a first parameter, the parameter value of which includes the set of text units. The set of text units includes language features in the natural language information that can be converted to a database language. The database language includes structured database language and unstructured database language.
[0258] The third allocation unit 1204 is used to allocate the text unit set to the target language expert model group among multiple language expert model groups using a language routing model. The language routing model is trained using text unit set samples, the labels of the database language corresponding to the text unit set samples, and the language expert model group corresponding to the text unit set samples. Different language expert model groups correspond to different database languages, and the language expert model groups have learned the knowledge data of the corresponding database languages.
[0259] The determination unit 1206 is used to determine at least one language expert model that matches the text unit set in the target language expert model group.
[0260] The third conversion unit 1206 is used to convert the text unit set into a query language under the database language using a language expert model.
[0261] Output unit 1210 is used to output the query language under the database language by calling the second interface, wherein the second interface includes a second parameter, and the parameter value of the second parameter includes the query language under the database language.
[0262] It should be noted that the third acquisition unit 1202, the third allocation unit 1204, the determination unit 1206, the third conversion unit 1206, and the output unit 1210 mentioned above correspond to steps S502 to S510. The five units and their corresponding steps implement the same instances and application scenarios, but are not limited to the content disclosed in the above embodiments. It should also be noted that the aforementioned units can be hardware or software components stored in memory and processed by one or more processors. These units can also be part of a device and run in the computer terminal provided in the above embodiments.
[0263] In the query language generation apparatus of this embodiment, a language expert model group (e.g., dialect expert group) is provided for each database language (e.g., database dialect). The language expert model can be used to learn the knowledge data of the corresponding database language to isolate dialect-specific knowledge and reduce interference during generation. The text unit set corresponding to the natural language information is routed to the corresponding target language expert model group. A language expert model is selected from the target language expert model group to generate the query language. This effectively generates query language among multiple database dialects, improves the quality of query language generation, and thus achieves the technical effect of improving the quality of query language generation, solving the technical problem of low quality of query language generation.
[0264] Embodiments of this application may provide an electronic device, which may be any one of a group of electronic devices. Optionally, in this embodiment, the aforementioned electronic device may also be replaced by a terminal device such as a mobile terminal.
[0265] Optionally, in this embodiment, the aforementioned electronic device may be located in at least one of a plurality of network devices in a computer network.
[0266] In this embodiment, the electronic device described above can execute the program code in the query language generation method.
[0267] Optionally, Figure 13 This is a structural block diagram of an electronic device according to an embodiment of this application. Figure 13 As shown, the electronic device A may include: one or more (only one is shown in the figure) processors 1302, memory 1304, memory controller, and peripheral interfaces, wherein the peripheral interfaces are connected to the radio frequency module, the audio module, and the display.
[0268] The memory can be used to store software programs and modules, such as the program instructions / modules corresponding to the methods and apparatus in the embodiments of this application. The processor executes various functional applications and data processing by running the software programs and modules stored in the memory, thereby implementing the methods in the above embodiments. The memory may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory may further include memory remotely located relative to the processor, and these remote memories can be connected to the terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0269] The processor can invoke information and applications stored in memory via a transmission device to perform the following steps: Obtaining text unit sets from multiple natural language information sets to be processed, wherein the text unit sets include language features in the natural language information that can be converted to a database language, and the database language includes structured and unstructured database languages; Assigning the text unit sets to target language expert model groups among multiple language expert model groups using a language routing model, wherein the language routing model is trained using text unit set samples, the labels of the database languages corresponding to the text unit set samples, and the language expert model groups corresponding to the text unit set samples, with different language expert model groups corresponding to different database languages, and the language expert model groups learning the knowledge data of the corresponding database languages; Determining at least one language expert model matching the text unit set in the target language expert model group; and using the language expert model to convert the text unit sets into query language under the database language.
[0270] Optionally, the processor may also execute program code that performs the following steps: calling the language routing model to determine the language expert model group corresponding to the language features among multiple language expert model groups as the target language expert model group, wherein the language routing model is trained using text unit set samples, the database language labels corresponding to the text unit set samples, and the language expert model group corresponding to the text unit set samples; and using the language routing model to route the text unit set to the target language expert model group.
[0271] Optionally, the processor may also execute program code for the following steps: obtaining routing loss, wherein the routing loss is used to allow multiple text units with a similarity greater than a similarity threshold to be routed to multiple language expert model groups; and training a language routing model using the routing loss, text unit set samples, the database language labels corresponding to the text unit set samples, and the language expert model groups corresponding to the text unit set samples.
[0272] Optionally, the processor may also execute program code that performs the following steps: invoking an expert routing model to determine a language expert model that matches the text unit set in the target language expert model group, wherein the expert routing model is trained using the text unit sample set and the labels of the corresponding language expert models.
[0273] Optionally, the processor may also execute program code that performs the following steps: calling the expert routing model to determine the weights between the text units in the text unit set and each language expert model in the target language expert model group, wherein the weights are used to represent the importance of the corresponding language expert model to the text units in the text unit set; and identifying the language expert models in the target language expert model group whose weights are greater than the weight threshold as the language expert models that match the text units in the text unit set.
[0274] Optionally, the processor may also execute program code for the following steps: obtaining the expert-level balance loss corresponding to the target language expert model group, wherein the expert-level balance loss is used to balance the load of different language expert models in the target language expert model group; using the expert-level balance loss, identifying the language expert models in the target language expert model group whose weights are greater than the weight threshold and whose loads meet the load threshold range as the language expert models that match the text units in the text unit set.
[0275] Optionally, the processor may also execute program code that performs the following steps: acquiring general knowledge data among multiple text unit sets corresponding to multiple natural language information; using a language expert model to convert the text unit sets into an initial query language under the database language; and migrating the general knowledge data to the initial query language to obtain the query language.
[0276] Optionally, the processor may also execute program code that calls a shared expert model to fuse multiple text unit sets to obtain general knowledge data, wherein the shared expert model is trained using general knowledge data samples from different text unit sets, and the shared expert model and the language expert model are independent of each other.
[0277] Optionally, the processor may also execute program code that calls a shared expert model to fuse multiple text unit sets at the sentence level to obtain general knowledge data.
[0278] Optionally, the processor may also execute program code that calls the shared expert model to migrate general knowledge data to the initial query language at the sentence level, thereby obtaining the query language.
[0279] Optionally, the processor may also execute program code that performs the following steps: using a language expert model to determine the grammatical structure of the text unit set, and using the grammatical structure to generate a query language under the database language.
[0280] Optionally, the processor may also execute program code for the following steps: adding the matrix to be trained to the weight matrix of the pre-trained model corresponding to the language expert model, wherein the pre-trained model is constructed by a low-rank adaptive model; training the matrix to be trained using knowledge data of the database language, while keeping the weight matrix of the pre-trained model unchanged, to obtain the language expert model in the target language expert model group.
[0281] The processor can invoke information and application programs stored in memory via a transmission device to perform the following steps: First, obtain text unit sets from multiple input natural language information sources, wherein the text unit sets include dialect features in the natural language information that allow conversion to the database dialect, and the database dialect includes structured database language and unstructured database language. Second, invoke a dialect routing model to assign the text unit sets to target dialect expert model groups among multiple dialect expert model groups, wherein the dialect routing model is trained using text unit set samples, labels of the database dialect corresponding to the text unit set samples, and the corresponding dialect expert model groups, with different dialect expert model groups corresponding to different database dialects, and the dialect expert model groups having learned the query syntax knowledge data of the corresponding database dialect. Third, invoke an expert routing model to determine at least one dialect expert model matching the text unit set from the target dialect expert model group, wherein the expert routing model is trained using a text unit sample set and the labels of the corresponding dialect expert model. Fourth, use the dialect expert model to convert the text unit sets into query language under the database dialect.
[0282] The processor can invoke information and application programs stored in memory via a transmission device to perform the following steps: In response to an input operation on the operating interface, display multiple natural language information items to be processed on the operating interface, wherein the natural language information includes a set of text units, the set of text units includes language features in the natural language information that can be converted to a database language, and the database language includes structured database language and unstructured database language; In response to a generation operation on the operating interface, display the query language of the natural language information in the corresponding database language on the operating interface, wherein the query language in the database language is obtained by converting the text unit set using at least one language expert model that matches the text unit set in the natural language information, the language expert model comes from a target language expert model group, the target language expert model group is obtained by allocating the text unit set among multiple language expert model groups using a language routing model, and the language routing model uses text unit set samples, the labels of the database language corresponding to the text unit set samples, and the text unit set.
[0283] The processor can invoke information and applications stored in memory via a transmission device to perform the following steps: Obtaining text unit sets from multiple natural language information sets to be processed by calling a first interface, wherein the first interface includes a first parameter, the value of which includes the text unit set, the text unit set including language features in the natural language information that can be converted to a database language, and the database language including structured and unstructured database languages; allocating the text unit sets to target language expert model groups among multiple language expert model groups using a language routing model, wherein the language routing model is trained using text unit set samples, labels of the database languages corresponding to the text unit set samples, and language expert model groups corresponding to the text unit set samples, different language expert model groups corresponding to different database languages, and the language expert model groups learning knowledge data of the corresponding database languages; determining at least one language expert model matching the text unit set in the target language expert model group; converting the text unit set into a query language under the database language using the language expert model; and outputting the query language under the database language by calling a second interface, wherein the second interface includes a second parameter, the value of which includes the query language under the database language.
[0284] In this embodiment, a language expert model group (e.g., dialect expert group) is provided for each database language (e.g., database dialect). The language expert model can be used to learn the knowledge data of the corresponding database language to isolate dialect-specific knowledge and reduce interference during generation. The text unit set corresponding to the natural language information is routed to the corresponding target language expert model group. A language expert model is selected from the target language expert model group to generate the query language. This effectively generates the query language across multiple database dialects, improves the quality of the generated query language, and thus achieves the technical effect of improving the quality of the generated query language, solving the technical problem of low quality of generated query language.
[0285] Those skilled in the art will understand that, Figure 13 The structure shown is for illustrative purposes only. Electronic devices can also be smartphones (such as Android phones, iOS phones, etc.), tablets, PDAs, and mobile internet devices (MIDs), etc. This diagram does not limit the structure of the aforementioned electronic devices. For example, electronic device A may include more or fewer components (such as network interfaces, display devices, etc.) than shown in the diagram, or may have a different configuration than shown in the diagram.
[0286] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing the hardware related to the terminal device. The program can be stored in a computer-readable storage medium, which may include: flash drive, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0287] Embodiments of this application also provide a computer-readable storage medium. Optionally, in this embodiment, the computer-readable storage medium includes a stored executable program, wherein, when the executable program runs, it controls the device where the storage medium is located to execute the program code executed by the method described in Embodiment 1 above. The specific execution process is as described above and will not be repeated here.
[0288] Optionally, in this embodiment, the computer-readable storage medium may be located in any one of the electronic devices in the group of electronic devices in the computer network, or in any one of the mobile terminals in the group of mobile terminals.
[0289] Embodiments of this application also provide a computer program product. Optionally, in this embodiment, the computer program product may include a computer program that, when executed by a processor, implements the methods provided in the embodiments described above.
[0290] Embodiments of this application also provide a computer program product. Optionally, the computer program product may include a non-volatile computer-readable storage medium, which can be used to store a computer program that, when executed by a processor, implements the method provided in the above embodiments.
[0291] Embodiments of this application also provide a computer program. Optionally, in this embodiment, when the computer program is executed by a processor, it implements the method provided in the above embodiments.
[0292] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0293] In the above embodiments of this application, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0294] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection of units or modules may be electrical or other forms.
[0295] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0296] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0297] If the integrated unit is implemented as 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 this application, in essence, or the part that contributes to the prior art, or all or part of the 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 cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard drive, magnetic disk, or optical disk.
[0298] The above are merely preferred embodiments of this application. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principles of this application, and these improvements and modifications should also be considered within the scope of protection of this application.
Claims
1. A method for generating a query language, characterized in that, include: Text unit sets are obtained from multiple natural language information to be processed, wherein the text unit sets include language features in the natural language information that can be converted to database languages, and the database languages include structured database languages and unstructured database languages; Using a language routing model, the text unit set is assigned to a target language expert model group among multiple language expert model groups. The language routing model is trained using text unit set samples, the labels of the database language corresponding to the text unit set samples, and the language expert model groups corresponding to the text unit set samples. Different language expert model groups correspond to different database languages, and the language expert model groups have learned the knowledge data of the corresponding database languages. In the target language expert model group, at least one language expert model that matches the text unit set is identified; Using the language expert model, the set of text units is converted into a query language under the database language.
2. The method according to claim 1, characterized in that, Using a language routing model, the set of text units is assigned to target language expert model groups among multiple language expert model groups, including: The language routing model is invoked to determine the language expert model group that corresponds to the language feature from among the multiple language expert model groups as the target language expert model group; Using the language routing model, the text unit set is routed to the target language expert model group.
3. The method according to claim 1, characterized in that, The method further includes: Obtain the routing loss, wherein the routing loss is used to allow multiple text units with a similarity greater than a similarity threshold to be routed to multiple groups of the language expert models; The language routing model is trained using the routing loss, the text unit set samples, the database language labels corresponding to the text unit set samples, and the language expert model group corresponding to the text unit set samples.
4. The method according to claim 1, characterized in that, In the target language expert model group, identifying at least one language expert model that matches the text unit set includes: The expert routing model is invoked to determine the language expert model that matches the text unit set in the target language expert model group. The expert routing model is trained using the text unit sample set and the labels of the corresponding language expert models.
5. The method according to claim 4, characterized in that, Invoking the expert routing model, and determining the language expert model that matches the text unit set from the target language expert model group, including: The expert routing model is invoked to determine the weights between the text units in the text unit set and each language expert model in the target language expert model group, wherein the weights are used to represent the importance of the corresponding language expert model to the text units in the text unit set; In the target language expert model group, the language expert model whose weight is greater than the weight threshold is identified as the language expert model that matches the text units in the text unit set.
6. The method according to claim 5, characterized in that, In the target language expert model group, the language expert models whose weights are greater than a weight threshold are identified as language expert models that match the text units in the text unit set, including: Obtain the expert-level balance loss corresponding to the target language expert model group, wherein the expert-level balance loss is used to balance the load of different language expert models in the target language expert model group; Using the expert-level balancing loss, the language expert models in the target language expert model group whose weights are greater than the weight threshold and whose loads are within the load threshold range are identified as language expert models that match the text units in the text unit set.
7. The method according to claim 1, characterized in that, The method further includes: Obtain general knowledge data among the multiple sets of text units corresponding to the multiple natural language information; Using the language expert model, the text unit set is converted into a query language under the database language, including: using the language expert model to convert the text unit set into an initial query language under the database language; and migrating the general knowledge data to the initial query language to obtain the query language.
8. The method according to claim 7, characterized in that, Acquiring general knowledge data among multiple sets of text units corresponding to multiple sets of natural language information, including: A shared expert model is invoked to fuse multiple text unit sets to obtain the general knowledge data. The shared expert model is trained using general knowledge data samples from different text unit sets, and the shared expert model is independent of the language expert model.
9. The method according to claim 8, characterized in that, By invoking a shared expert model, multiple sets of text units are fused to obtain the general knowledge data, including: The shared expert model is invoked to fuse multiple sets of text units at the sentence level to obtain the general knowledge data.
10. The method according to claim 9, characterized in that, The general knowledge data is migrated to the initial query language to obtain the query language, including: The shared expert model is invoked, and the general knowledge data is migrated to the initial query language according to the sentence level to obtain the query language.
11. The method according to claim 1, characterized in that, Using the language expert model, the text unit set is converted into a query language under the database language, including: Using the language expert model, the grammatical structure of the text unit set is determined, and the query language under the database language is generated using the grammatical structure.
12. The method according to any one of claims 1 to 11, characterized in that, The method further includes: The matrix to be trained is added to the weight matrix of the pre-trained model corresponding to the language expert model, wherein the pre-trained model is constructed by a low-rank adaptive model; The target language expert model is obtained by training the matrix to be trained using the knowledge data of the database language, while keeping the weight matrix of the pre-trained model unchanged.
13. A method for generating a query language, characterized in that, Applied to database management systems, including: Text unit sets are obtained from multiple input natural language information sources, wherein the text unit sets include dialect features in the natural language information that can be converted to database dialects, and the database dialects include structured database languages and unstructured database languages. The dialect routing model is invoked to assign the text unit set to a target dialect expert model group among multiple dialect expert model groups. The dialect routing model is trained using text unit set samples, the labels of the database dialects corresponding to the text unit set samples, and the dialect expert model groups corresponding to the text unit set samples. Different dialect expert model groups correspond to different database dialects, and the dialect expert model groups have learned the query syntax knowledge data of the corresponding database dialects. Invoke the expert routing model to determine at least one dialect expert model that matches the text unit set in the target dialect expert model group, wherein the expert routing model is trained using the text unit sample set and the labels of the corresponding dialect expert model; Using the dialect expert model, the set of text units is converted into a query language in the dialect of the database.
14. A method for generating a query language, characterized in that, include: In response to an input operation on the operation interface, multiple natural language information to be processed are displayed on the operation interface, wherein the natural language information includes a set of text units, the set of text units includes language features in the natural language information that can be converted to a database language, and the database language includes structured database language and unstructured database language; In response to a generation operation applied to the operation interface, the query language of the natural language information under the corresponding database language is displayed on the operation interface. The query language under the database language is obtained by converting the text unit set using at least one language expert model that matches the text unit set in the natural language information. The language expert model comes from a target language expert model group, which is obtained by allocating the text unit set among multiple language expert model groups using a language routing model. The language routing model is trained using text unit set samples, the labels of the database language corresponding to the text unit set samples, and the language expert model group corresponding to the text unit set samples. Different language expert model groups correspond to different database languages, and the language expert model groups have learned the knowledge data of the corresponding database languages.
15. A method for generating a query language, characterized in that, include: By calling a first interface, text unit sets are obtained from multiple natural language information to be processed. The first interface includes a first parameter, the parameter value of which includes the text unit set. The text unit set includes language features in the natural language information that can be converted to a database language. The database language includes structured database language and unstructured database language. Using a language routing model, the text unit set is assigned to a target language expert model group among multiple language expert model groups. The language routing model is trained using text unit set samples, the labels of the database language corresponding to the text unit set samples, and the language expert model groups corresponding to the text unit set samples. Different language expert model groups correspond to different database languages, and the language expert model groups have learned the knowledge data of the corresponding database languages. In the target language expert model group, at least one language expert model that matches the text unit set is identified; Using the language expert model, the set of text units is converted into a query language under the database language; The query language under the database language is output by calling the second interface, wherein the second interface includes a second parameter, and the parameter value of the second parameter includes the query language under the database language.
16. A query language generation system, characterized in that, include: The data input terminal is used to obtain text unit sets from multiple natural language information to be processed, wherein the text unit sets include language features in the natural language information that can be converted to a database language, and the database language includes structured database language and unstructured database language; The language routing end is used to route the text unit set to a target language expert model group among multiple language expert model groups using a language routing model. The language routing model is trained using text unit set samples, the labels of the database language corresponding to the text unit set samples, and the language expert model group corresponding to the text unit set samples. Different language expert model groups correspond to different database languages, and the language expert model groups have learned the knowledge data of the corresponding database languages. The expert routing end is used to determine at least one language expert model that matches the text unit set in the target language expert model group; The data conversion end is used to convert the set of text units into a query language under the database language using the language expert model. The data output terminal is used to output the query language under the database language.
17. An electronic device, characterized in that, include: Memory, which stores executable programs; A processor for running the program, wherein the program, when running, performs the method according to any one of claims 1 to 15.
18. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored executable program, wherein, when the executable program is executed, it controls the device on which the computer-readable storage medium is located to perform the method according to any one of claims 1 to 15.
19. A computer program product, characterized in that, It includes a computer program that, when executed by a processor, implements the method described in any one of claims 1 to 15.