A multitask mode linking method, system, electronic device, and storage medium
Patent Information
- Application Number
- CN202511382286.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-25
- Publication Date
- 2026-10-30
- Estimated Expiration
- 2045-09-25
AI Technical Summary
但是,在处理复杂查询任务时,采用这种方式容易出现模式链接不准确、遗漏关键信息等问题,导致生成的SQL语句不准确;并且,还缺乏对大语言模型的深入利用,不仅难以适应不同领域的多样化需求,还容易出现对长文具和多表多列查询的执行准确度低的问题
[0055]本申请提供一种多任务模式链接方法、系统、电子设备及存储介质,利用当前自然语言问题、数据库信息、特征领域的领域信息和训练数据集对语言模型进行第一阶段微调,得到目标大语言模型;利用数据库信息和领域信息构建知识库;利用知识库和预先构建的多任务学习的损失函数对目标大语言模型进行第二阶段微调,得到多任务学习模型;利用目标大语言模型对当前自然语言问题进行初步模式链接,得到初步模式链接结果;其中,初步链接结果包括当前自然语言问题匹配的第一数据库表及其字段结构;利用多任务学习模型对当前自然语言问题、检索内容和数据库信息进行深度模式链接,得到深度模式链接结果;其中,深度模式链接结果包括当前自然语言问题匹配的第二数据库表及其字段结构;将初始模式链接结果和深度模式链接结果进行整合,得到最终模式链接结果,并利用最终模式链接结果生成相应的SQL语句。本申请提供的技术方案,通过两阶段微调,使得到的目标大语言模型和多任务学习模型能够更准确地理解自然语言问题,从而为后续生成更准确的模式链接结果和SQL语句奠定基础;并且,在第二阶段微调中,多任务学习框架(多任务学习的损失函数)使得到多任务学习模型能够适应不同类型的自然语言到SQL的转换任务,提高了模型的泛化能力;最后利用目标大语言模型对当前自然语言问题进行初步模式链接,和利用多任务学习模型对当前自然语言问题、检索内容和数据库信息进行深度模式链接,以便利用得到的两次链接得到的结果生成最终的SQL语句,不仅能够实现复杂查询任务的处理,以避免出现模式链接不准确、遗漏关键信息等问题,从而提供生成的SQL语句的准确性,还能够深入利用大语言模型,以适应不同领域的多样化需求,避免出现对长问句和多表多列查询的执行准确度低的问题。
Smart Images

Figure CN121166725B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and more specifically, to a multi-tasking mode linking method, system, electronic device, and storage medium. Background Technology
[0002] In today's data-driven era, database systems have become the core business support platform for various industries, widely used in finance, healthcare, education, retail, and other fields. With the continuous increase in data volume, efficiently and conveniently retrieving the required information from databases has become a significant challenge. Currently, databases can be queried using SQL statements; however, for non-professionals, learning and using SQL statements is a huge hurdle.
[0003] In existing technologies, non-programming professionals can use Text2SQL technology to interact with database systems through natural language without needing to understand complex SQL syntax. However, when handling complex query tasks, this approach is prone to problems such as inaccurate schema links and missing key information, leading to inaccurate generated SQL statements. Furthermore, it lacks in-depth utilization of large language models, making it difficult to adapt to diverse needs across different domains and prone to low accuracy in executing long queries and queries involving multiple tables and columns. Summary of the Invention
[0004] In view of this, the present invention provides a multi-task mode linking method, system, electronic device and storage medium to improve the accuracy and generalization ability of mode linking, as well as to efficiently and accurately convert natural language problems into SQL statements, so as to adapt to the data query needs of different fields and improve the corresponding execution accuracy.
[0005] The first aspect of this application provides a multi-task mode linking method, the method comprising:
[0006] The language model is fine-tuned in the first stage using current natural language problems, database information, domain information of feature domains, and training datasets to obtain the target large language model.
[0007] A knowledge base is constructed using the database information and the domain information;
[0008] The target large language model is fine-tuned in the second stage using the current natural language problem, the knowledge base, and the pre-built multi-task learning loss function to obtain the multi-task learning model;
[0009] The target large language model is used to perform preliminary pattern linking on the current natural language problem to obtain preliminary pattern linking results; wherein, the preliminary linking results include the first database table matched by the current natural language problem and its field structure;
[0010] The multi-task learning model is used to perform deep pattern linking on the current natural language question, the search content, and the database information to obtain deep pattern linking results; wherein, the deep pattern linking results include a second database table matched by the current natural language question and its field structure;
[0011] The initial pattern linking result and the deep pattern linking result are integrated to obtain the final pattern linking result, and the corresponding SQL statement is generated using the final pattern linking result.
[0012] Optionally, the step of using the current natural language problem, database information, domain information of the feature domain, and training dataset to perform a first-stage fine-tuning of the language model to obtain a large language model after the first-stage fine-tuning includes:
[0013] Obtain database information and perform structured processing on the database information to obtain structured target database information, wherein the target database information includes multiple database tables and their field structures;
[0014] Acquire domain information for a specific domain, and map the various knowledge points within that domain information to multiple database tables and their field structures to obtain multiple mapping relationships. Each mapping relationship includes knowledge, a database table, and its field structure.
[0015] Obtain a training dataset, and select multiple natural language questions from the training dataset based on the current natural language question, and use each natural language question as a training sample;
[0016] Construct an instruction dataset based on pre-set instructions, training samples, and mapping relationships;
[0017] The large language model is fine-tuned in the first stage using the instruction dataset to obtain the target large language model.
[0018] Optionally, the step of constructing a knowledge base using the database information and the domain information, and retrieving search content matching the current natural language question from the knowledge base, includes:
[0019] The database information is structured to obtain structured target database information. The domain information is then processed to obtain multiple domain knowledge fragments. The target database information includes multiple database tables and their field structures. The domain knowledge fragments include knowledge and their descriptions.
[0020] Each of the aforementioned domain knowledge fragments and each of the aforementioned database tables and their field structures are sliced to obtain multiple text blocks; wherein, each text block includes the knowledge and its description and the database tables and their field structures;
[0021] Each text block is vectorized to obtain a vector corresponding to each text block;
[0022] The vectors of each text block are clustered to obtain multiple clusters, and each cluster is compressed to complete a two-level index for each text block, thereby constructing an index for each text block;
[0023] The index of each text block and its matching metadata pointer are concatenated to obtain multiple prompt fragments; wherein, the metadata pointer includes knowledge, database tables and their field structures;
[0024] Generate a corresponding knowledge base based on each of the aforementioned prompt fragments.
[0025] Optionally, the second-stage fine-tuning of the target large language model using the current natural language problem, the knowledge base, and a pre-built multi-task learning loss function to obtain a multi-task learning model includes:
[0026] The knowledge base is retrieved using retrieval enhancement generation technology based on the current natural language question to obtain corresponding retrieval content, wherein the retrieval content includes prompt fragments that match the current natural language question;
[0027] The target large language model is fine-tuned in the second stage using prompt fragments that match the current natural language problem and a pre-built loss function for multi-task learning, resulting in a multi-task learning model.
[0028] Optionally, the step of integrating the initial pattern linking result and the deep pattern linking result to obtain the final pattern linking result, and using the final pattern linking result to generate the corresponding SQL statement, includes:
[0029] The initial pattern linking results and the deep pattern linking results are merged to obtain a pattern linking result set;
[0030] The pattern link result set is validated based on the database information using a pre-built validation function to obtain the validated pattern link result set.
[0031] The verified pattern linking result set is optimized using a pre-built optimization function based on the database information to obtain the final pattern linking result.
[0032] The initial SQL statement is generated using the large language model based on the final pattern linking result, and the initial SQL statement is modified using the database information to obtain the final SQL statement.
[0033] A second aspect of this application provides a multi-task mode linking system, the system comprising:
[0034] The first-stage fine-tuning unit is used to perform the first-stage fine-tuning of the language model using the current natural language problem, database information, domain information of the feature domain, and training dataset to obtain the target large language model.
[0035] A knowledge base construction unit is used to construct a knowledge base using the database information and the domain information;
[0036] The second-stage fine-tuning unit is used to perform second-stage fine-tuning on the target large language model using the current natural language problem, the knowledge base, and the pre-built multi-task learning loss function to obtain a multi-task learning model.
[0037] An initial pattern linking unit is used to perform preliminary pattern linking on the current natural language problem using the target large language model to obtain preliminary pattern linking results; wherein, the preliminary linking results include a first database table matched by the current natural language problem and its field structure;
[0038] The deep pattern linking unit is used to perform deep pattern linking on the current natural language question, the search content, and the database information using the multi-task learning model to obtain a deep pattern linking result; wherein, the deep pattern linking result includes a second database table matched by the current natural language question and its field structure;
[0039] The integration and SQL statement generation unit is used to integrate the initial pattern linking result and the deep pattern linking result to obtain the final pattern linking result, and to generate the corresponding SQL statement using the final pattern linking result.
[0040] Optionally, the unit for fine-tuning in the first stage is specifically used for:
[0041] Obtain database information and perform structured processing on the database information to obtain structured target database information, wherein the target database information includes multiple database tables and their field structures;
[0042] Acquire domain information for a specific field, and map the various knowledge points within that domain information to multiple database tables and their field structures to obtain multiple mapping relationships. Each mapping relationship includes knowledge, a database table, and its field structure.
[0043] Obtain a training dataset, and select multiple natural language questions from the training dataset based on the current natural language question, and use each natural language question as a training sample;
[0044] Construct an instruction dataset based on the pre-set instructions, training samples, and mapping relationships;
[0045] The large language model is fine-tuned in the first stage using the instruction dataset to obtain the target large language model.
[0046] Optionally, the knowledge base construction unit is specifically used for:
[0047] The database information is structured to obtain structured target database information. The domain information is then processed to obtain multiple domain knowledge fragments. The target database information includes multiple database tables and their field structures. The domain knowledge fragments include knowledge and their descriptions.
[0048] Each of the aforementioned domain knowledge fragments and each of the aforementioned database tables and their field structures are sliced to obtain multiple text blocks; wherein, each text block includes the knowledge and its description and the database tables and their field structures;
[0049] Each text block is vectorized to obtain a vector corresponding to each text block;
[0050] The vectors of each text block are clustered to obtain multiple clusters, and each cluster is compressed to complete a two-level index for each text block, thereby constructing an index for each text block;
[0051] The index of each text block and its matching metadata pointer are concatenated to obtain multiple prompt fragments; wherein, the metadata pointer includes knowledge, database tables and their field structures;
[0052] Generate a corresponding knowledge base based on each of the aforementioned prompt fragments.
[0053] A third aspect of this application provides an electronic device, including: a processor and a memory, the processor and the memory being connected via a bus; wherein, the processor is used to call and execute a program stored in the memory; the memory is used to store the program, the program being used to implement a method for constructing a three-dimensional model as provided in the first aspect of this application.
[0054] The fourth aspect of this application provides a computer-readable storage medium storing computer-executable instructions for performing a method for constructing a three-dimensional model as provided in the first aspect of this application.
[0055] This application provides a multi-task pattern linking method, system, electronic device, and storage medium. The method involves: first-stage fine-tuning of a language model using the current natural language question, database information, domain information of the feature domain, and training dataset to obtain a target large language model; constructing a knowledge base using the database information and domain information; second-stage fine-tuning of the target large language model using the knowledge base and a pre-built multi-task learning loss function to obtain a multi-task learning model; preliminary pattern linking of the current natural language question using the target large language model to obtain preliminary pattern linking results, including a first database table matching the current natural language question and its field structure; deep pattern linking of the current natural language question, retrieval content, and database information using the multi-task learning model to obtain deep pattern linking results, including a second database table matching the current natural language question and its field structure; integrating the initial and deep pattern linking results to obtain a final pattern linking result, and generating corresponding SQL statements using the final pattern linking result. The technical solution provided in this application, through two-stage fine-tuning, enables the target large language model and multi-task learning model to more accurately understand natural language problems, thus laying the foundation for generating more accurate pattern linking results and SQL statements. Furthermore, in the second-stage fine-tuning, the multi-task learning framework (the loss function of multi-task learning) allows the multi-task learning model to adapt to different types of natural language to SQL conversion tasks, improving the model's generalization ability. Finally, the target large language model performs preliminary pattern linking on the current natural language problem, and the multi-task learning model performs deep pattern linking on the current natural language problem, retrieval content, and database information. The results of these two linking operations are then used to generate the final SQL statement. This not only enables the processing of complex query tasks, avoiding problems such as inaccurate pattern linking and missing key information, thus improving the accuracy of the generated SQL statement, but also allows for in-depth utilization of the large language model to adapt to diverse needs in different domains, avoiding low accuracy in executing long questions and multi-table, multi-column queries. Attached Figure Description
[0056] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.
[0057] Figure 1 A flowchart illustrating a multi-task mode linking method provided in an embodiment of this application;
[0058] Figure 2This is a schematic diagram of the structure of a multi-task mode linking system provided in an embodiment of the present invention;
[0059] Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0060] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0061] In this application, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes the element.
[0062] See Figure 1 The flowchart of the multi-task mode linking method of this application is shown. The multi-task mode linking method specifically includes the following steps:
[0063] S101: The language model is fine-tuned in the first stage using the current natural language problem, database information, domain information of the feature domain, and training dataset to obtain the target large language model.
[0064] In the specific execution step S101, the current natural language problem, database information, and domain knowledge of a specific field can be obtained. Based on the database information and domain information, multiple mapping relationships are established. Each mapping relationship includes business terms, database tables, and their field structures. A pre-built training dataset and pre-set instructions are obtained so that a corresponding instruction dataset can be constructed based on the current natural language problem, the mapping relationships, the training dataset, and the instructions. The instruction dataset is then used to perform the first stage of fine-tuning on the large language model to be trained, resulting in the target large language model.
[0065] It should be noted that the current natural language question can be the natural language question that the user is currently inputting.
[0066] Optionally, the process of fine-tuning the language model in the first stage using the current natural language problem, database information, domain information of the feature domain, and training dataset to obtain the large language model after the first stage of fine-tuning can be as follows: Obtain database information and perform structured processing on the database information to obtain structured target database information, where the target database information includes multiple database tables and their field structures; obtain domain information of a specific domain and map each piece of knowledge within the domain information of the specific domain to multiple database tables and their field structures to obtain multiple mapping relationships, where each mapping relationship includes knowledge, database tables, and their field structures; obtain the training dataset and select multiple natural language problems from the training dataset based on the current natural language problem, and use each natural language problem as a training sample; construct an instruction dataset according to pre-set instructions, training samples, and mapping relationships; and use the instruction dataset to fine-tune the large language model in the first stage to obtain the target large language model.
[0067] In some embodiments, after obtaining the database information, in order to intuitively describe the database tables and their field structures, the database information can be processed into structured information to obtain structured target database information, wherein the structured target database information includes multiple database tables and their field structures.
[0068] It should be noted that the structured representation of the database table and its field structure can be a database table (column 1, column 2, column 3).
[0069] For example, for a database in the field of communications, the database information of the database is processed in a structured manner, and the resulting database tables and their field structures can be as follows: BaseStations(id (base station ID), location (location), status (status)), SignalStrengths(station_id (base station ID), strength (signal strength), timestamp (timestamp)), UserTraffic(userid (user ID), traffic (traffic), timestamp (timestamp)).
[0070] In some embodiments, after obtaining domain information in a specific field (such as communications, finance, etc.), domain knowledge can be sorted out to extract business terms, data coding relationships, and other knowledge within the specific field from the domain information; and the sorted knowledge can be mapped to each database table and its field structure to form a correspondence between the knowledge and the database interface (database table and its field structure), thus obtaining multiple mapping relationships.
[0071] For example, in the field of communications, business terms (knowledge) such as "base station," "signal strength," and "user traffic" can be extracted from relevant domain information. These extracted business terms can then be mapped to various database tables and their field structures, resulting in the following mapping relationships:
[0072] Base Station: Table BaseStations, columns id, locations, status;
[0073] Signal strength: Table SignalStrengths, columns station_id, strength, timestamp;
[0074] User Traffic: Table UserTraffic, columns userid, traffic, timestamp.
[0075] It should be noted that by sorting out knowledge such as business terminology and data coding relationships in specific fields, the model can be better adapted to the data query needs of specific fields.
[0076] In some embodiments, a corresponding training dataset can be pre-constructed, wherein the training dataset may include multiple natural language problems accumulated in history; some natural language problems are randomly selected from the training dataset, and the similarity calculation method of Euclidean distance is used to calculate the similarity between each natural language problem in the selected natural language problems and the current natural language problem, as shown in formula (1); finally, according to the similarity, each natural language problem in the selected natural language problems is sorted from large to small, and the k natural language problems most similar to the current natural language problem are selected from the sorted sequence as training samples, that is, the first k natural language problems are selected from the sorted sequence as training samples.
[0077] (1)
[0078] in, Let the vector represent the current natural language problem. For vectors in natural language problems, This represents the Euclidean distance, which is the similarity between two problems.
[0079] It should be noted that the various natural language problems accumulated over time can be natural language problems related to various business operations, such as customer inquiries about phone bills.
[0080] In some embodiments, a series of instructions can be pre-built, that is, a corresponding instruction dataset can be pre-built; wherein, the instructions included in the instruction dataset may be, for example, "extract keywords from the question", "identify entities in the question", "match keywords in the question with database tables and columns", etc.
[0081] For example, for a natural language problem (training sample) "Query the signal strength record of base station id 1", the instruction could be "Extract base station id" or "Matching table". In List".
[0082] In some embodiments, for each instruction, corresponding information (keywords or entities) is extracted from the training samples using the instruction, and the information extracted from the training samples is matched with database tables and columns in the mapping relationship. Finally, the instruction and the information extracted by the instruction and its matched database tables and columns are used to generate corresponding instruction data, so as to generate corresponding instruction datasets using the generated instruction data.
[0083] In this embodiment, after obtaining the instruction dataset, the large language model can be fine-tuned in the first stage using the instruction dataset. The large language model can better understand and follow the instructions in the instruction dataset, thereby improving the parsing ability of the target large language model for natural language problems. The first stage fine-tuning process is shown in formula (2):
[0084] (2)
[0085] in, These are the original parameters of the large language model. These are the parameters of the target large language model obtained after the first stage of fine-tuning. It's the learning rate. It is a loss function. It is an instruction dataset.
[0086] S102: Build a knowledge base using database information and domain information.
[0087] In the specific execution step S102, multiple text blocks can be generated based on database information and domain information. The text blocks include knowledge and its description, as well as database tables and their field structures. Each text block is vectorized, and a corresponding index is constructed based on each vectorized text block. Based on the index of each text block and its matching metadata pointer, a corresponding prompt fragment is generated. Finally, a corresponding knowledge base is generated based on each prompt fragment, so as to retrieve the search content that matches the current natural language question from the knowledge base.
[0088] Optionally, the process of constructing a knowledge base using database information and domain information can be as follows: The database information is structured to obtain structured target database information; the domain information is processed to obtain multiple domain knowledge fragments; wherein, the target database information includes multiple database tables and their field structures; the domain knowledge fragments include knowledge and their descriptions; each domain knowledge fragment and each database table and its field structure are sliced to obtain multiple text blocks; wherein, each text block includes knowledge and its description, and database tables and their field structures; each text block is vectorized to obtain a corresponding vector; the vectors of each text block are clustered to obtain multiple clusters, and each cluster is compressed to complete a two-level index for each text block, thus constructing an index for each text block; the index of the vector of each text block and its matching metadata pointer are concatenated to obtain multiple prompt fragments; wherein, the metadata pointer includes knowledge, database tables and their field structures; and a corresponding knowledge base is generated based on each prompt fragment.
[0089] In practical applications, after obtaining database information and domain information, a process of database construction, slicing, vectorization, and indexing can be performed sequentially to build the corresponding knowledge base. As one implementation method of this application embodiment, the knowledge base construction process can be as follows:
[0090] Database creation: The database information is structured to obtain structured target database information (i.e., the corresponding database metadata), and the domain information is JSON-ized to obtain multiple domain knowledge fragments. The target database information includes multiple database tables and their field structures; the domain knowledge fragments include knowledge (term) and its description (columns), for example, {"term": "signal strength", "desc": "RSRP value, in dBm, -85~-95 is medium", "columns": ["SignalStrengths.strength"]} or {"term": "base station type", "desc": "macro station / micro station / indoor distribution", "columns": ["BaseStations.type"]};
[0091] Slicing: Based on the description in the domain knowledge fragment, determine the matching database table and its field structure, and slice the domain knowledge fragment and the matching database table and its field structure into corresponding text blocks according to "knowledge-description-column". The text blocks include knowledge and its description and database table and its field structure.
[0092] Vectorization: Using a vectorization model to convert text blocks into corresponding embedding vectors;
[0093] Indexing: (1) FAISS-IVF-PQ two-level index: The first-level coarse quantizer clusters the embedding vectors of each text block into multiple clusters; the second-level product quantizer compresses each cluster into the corresponding characters to obtain the index of the text block; the metadata pointer of the text block is generated based on the knowledge ID, table name and column name (database table and its field structure) of the knowledge in the text block; finally, the index of the text block and its matching metadata pointer are concatenated to obtain the prompt fragment corresponding to the text block, and the knowledge base is generated based on each prompt fragment. Among them, the prompt fragment includes the index of the text block, knowledge ID, database table and its field structure.
[0094] S103: The target large language model is fine-tuned in the second stage using the current natural language problem, knowledge base and pre-built multi-task learning loss function to obtain the multi-task learning model.
[0095] In the specific execution step S103, the search content matching the current natural language question is retrieved from the knowledge base, and the target large language model is fine-tuned in the second stage using the search content and the pre-built multi-task learning loss function to obtain the multi-task learning model.
[0096] Optionally, the process of fine-tuning the target large language model in the second stage using the current natural language question, the knowledge base, and a pre-built multi-task learning loss function to obtain the multi-task learning model can be as follows: using retrieval enhancement generation technology to retrieve the knowledge base based on the current natural language question to obtain the corresponding retrieval content, wherein the retrieval content includes a prompt fragment matching the current natural language question; and using the prompt fragment matching the current natural language question and the pre-built multi-task learning loss function to fine-tune the target large language model in the second stage to obtain the multi-task learning model.
[0097] It should be noted that by utilizing Retrieval Enhanced Generation (RAG) technology, combined with database information and domain knowledge, the model can more accurately understand natural language questions and generate more accurate pattern linking results. Compared with existing technologies, this method can better handle complex query tasks and improve the quality of generated query statements.
[0098] In some embodiments, in order to enable the multi-task learning model obtained from the second-stage fine-tuning to deeply understand natural language problems, the retrieval enhancement generation technique can be used to retrieve the knowledge base based on the current natural language problem to obtain the corresponding retrieval content. This allows the target large language model to be fine-tuned in the second stage using the retrieval content and the pre-built loss function of multi-task learning, thus obtaining the multi-task learning model and enabling it to deeply understand natural language problems. The method of using the retrieval enhancement generation technique to retrieve the corresponding retrieval content from the knowledge base based on the current natural language problem can be as shown in formula (3):
[0099] (3)
[0100] in, This is a current problem in natural language processing. It is a knowledge base. This refers to the relevant information retrieved (the search results).
[0101] In some embodiments, multi-task learning tasks can be designed so that the multi-task learning model obtained after the second-stage fine-tuning can handle multiple tasks simultaneously, such as keyword extraction, entity recognition, and pattern linking. The multi-task learning model obtained in this way can not only better understand natural language problems but also be optimized across multiple tasks, improving overall performance. The pre-constructed loss function for multi-task learning can be shown in formula (4):
[0102] (4)
[0103] in, It is the task weight. This is the loss from the keyword extraction task. This is a loss in the entity recognition task. It is a loss of pattern linking tasks. For pre-built loss functions for multi-task learning.
[0104] It's worth noting that in the second stage of fine-tuning, multi-task learning tasks were designed to enable the model to handle multiple tasks simultaneously, such as keyword extraction, entity recognition, and pattern linking. In this way, the model not only better understands natural language problems but also optimizes across multiple tasks, improving overall performance.
[0105] It should also be noted that through two-stage fine-tuning, the large language model's instruction-following ability and task-specific capabilities are significantly improved, thus better handling the natural language to SQL conversion task. Compared with existing technologies, this method can more effectively utilize the potential of the large language model, improving the accuracy and generalization ability of pattern linking.
[0106] In some embodiments, after retrieving a prompt fragment (retrieval content) that matches the current natural language problem, the target large language model obtained in the first stage of fine-tuning can be fine-tuned again based on the retrieved retrieval content and the pre-built multi-task learning loss function (second stage fine-tuning), which can further improve the model's ability and generalization ability on specific tasks. The process of second stage fine-tuning of the target large language model can be shown in formula (5):
[0107] (5)
[0108] in, For the parameters of the multi-task learning model, The parameters of the target large language model, For pre-set parameters, For multi-task learning loss function, For the search results.
[0109] S104: Use the target large language model to perform preliminary pattern linking on the current natural language problem to obtain preliminary pattern linking results; wherein, the preliminary linking results include the first database table matching the current natural language problem and its field structure.
[0110] In the specific execution step S104, after the first stage of fine-tuning, the target large language model obtained after the first stage of fine-tuning can be used to perform preliminary pattern linking on the current natural language problem, so as to identify and filter the first database table and its field structure corresponding to the current natural language problem in the target database information, that is, to obtain the initial linking result. The preliminary pattern linking process can be shown as formula (6):
[0111] (6)
[0112] in, It is database information. For current natural language problems, This is the initial pattern linking result.
[0113] S105: Utilize a multi-task learning model to perform deep pattern linking on the current natural language question, retrieval content, and database information to obtain deep pattern linking results; wherein, the deep pattern linking results include the second database table matched with the current natural language question and its field structure.
[0114] In the specific execution of step S105, after the second-stage fine-tuning, the multi-task learning model after the second-stage fine-tuning can be used to perform deep pattern linking on the current natural language question, retrieval content, and database information. This can further optimize the results of the initial pattern linking and ensure the accuracy and comprehensiveness of the pattern linking. Among them, the deep pattern linking results include the second database table matching the current natural language question and its field structure. The deep pattern linking process can be shown in formula (7):
[0115] (7)
[0116] in, For deep mode linking results, For current natural language problems, For the search content, This is database information.
[0117] S106: Integrate the initial pattern linking result and the deep pattern linking result to obtain the final pattern linking result, and use the final pattern linking result to generate the corresponding SQL statement.
[0118] In the specific execution step S106, after obtaining the initial pattern linking result and the deep pattern linking result, the initial pattern linking result and the deep pattern linking result can be integrated to obtain a pattern linking result set. The pattern linking result set is then verified and optimized to obtain the final pattern linking result. An initial SQL statement is generated based on the final pattern linking result, and the initial SQL statement is then modified to obtain the SQL statement.
[0119] Optionally, the process of integrating the initial schema linking results and the deep schema linking results to obtain the final schema linking results, and then using the final schema linking results to generate the corresponding SQL statements, can be as follows: Merge the initial schema linking results and the deep schema linking results to obtain a schema linking result set; validate the schema linking result set based on database information using a pre-built validation function to obtain a validated schema linking result set; optimize the validated schema linking result set based on database information using a pre-built optimization function to obtain the final schema linking results; generate the initial SQL statement using a large language model based on the final schema linking results, and modify the initial SQL statement using database information to obtain the SQL statement.
[0120] In some embodiments, the results of preliminary pattern linking and deep pattern linking are merged to form a comprehensive pattern linking result set; specifically, during the merging process, in order to ensure that the correspondence between each database table and its columns (field structure) is accurately recorded and to avoid duplication and omission, the merging process can be as shown in formula (8):
[0121] (8)
[0122] in, The union operation represents the set operation. For the result set of the pattern link, This is the result of linking the initial pattern. This is the result of deep mode linking.
[0123] In some embodiments, the merged schema link result set is validated to check for errors or omissions. Specifically, the validation process includes, but is not limited to, checking the accuracy of database table names and column names (names of database tables and their field structures), and verifying whether the relationships between tables and columns conform to the database structure. The validation process can be as shown in formula (9):
[0124] (9)
[0125] in, It is a verification function. It is the result set of the verified pattern link. For database information, This is the result set of the pattern linking.
[0126] In some embodiments, the schema linking result set is optimized based on the verification results, and the verified schema linking results are optimized. Optimization includes correcting incorrect table or column names, supplementing missing information, and adjusting the relationships between tables and columns. The optimized schema linking results will serve as the basis for subsequent SQL generation. The optimization process can be illustrated as shown in formula (10):
[0127] (10)
[0128] in, It is an optimization function. It is the optimized pattern linking result set, i.e., the final pattern linking result; The result set of the validated pattern link, This is database information.
[0129] In some embodiments, a large language model is used to generate an initial SQL query statement based on the final schema linking result, wherein the initial SQL statement generation process can be as shown in formula (11):
[0130] (11)
[0131] in, For the final pattern linking result, This is the initial SQL statement.
[0132] In some embodiments, the generated initial SQL statement is checked and corrected, such as correcting syntax errors and optimizing query logic, until an executable and satisfactory SQL statement is generated or the maximum number of corrections is reached:
[0133] (12)
[0134] in, This is the initial SQL statement. For database information, This is an SQL statement.
[0135] It should be noted that adding validation and optimization to the schema linking result set not only improves the accuracy and reliability of the schema linking but also ensures the accuracy and executability of the generated SQL queries, reducing the number of errors and corrections, and improving the efficiency of the entire process. Compared with existing technologies, this method can more effectively detect and correct errors in schema linking, improving the quality of the final generated SQL queries.
[0136] This application provides a multi-task pattern linking method. First, a language model is fine-tuned using the current natural language question, database information, domain information of the feature domain, and training dataset to obtain a target large language model. A knowledge base is constructed using the database information and domain information. Second, the target large language model is fine-tuned using the current natural language question, the knowledge base, and a pre-built multi-task learning loss function to obtain a multi-task learning model. The target large language model is used to perform preliminary pattern linking on the current natural language question to obtain preliminary pattern linking results, including a first database table matching the current natural language question and its field structure. Third, the multi-task learning model is used to perform deep pattern linking on the current natural language question, the search content, and the database information to obtain deep pattern linking results, including a second database table matching the current natural language question and its field structure. Finally, the initial and deep pattern linking results are integrated to obtain a final pattern linking result, and the final pattern linking result is used to generate corresponding SQL statements. The technical solution provided in this application, through two-stage fine-tuning, enables the target large language model and multi-task learning model to more accurately understand natural language problems, thus laying the foundation for generating more accurate pattern linking results and SQL statements. Furthermore, in the second-stage fine-tuning, the multi-task learning framework (the loss function of multi-task learning) allows the multi-task learning model to adapt to different types of natural language to SQL conversion tasks, improving the model's generalization ability. Finally, the target large language model performs preliminary pattern linking on the current natural language problem, and the multi-task learning model performs deep pattern linking on the current natural language problem, retrieval content, and database information. The results from these two linking operations are then used to generate the final SQL statement. This not only enables the processing of complex query tasks, avoiding problems such as inaccurate pattern linking and missing key information, thus improving the accuracy of the generated SQL statement, but also allows for in-depth utilization of the large language model to adapt to diverse needs in different domains, avoiding low accuracy in long queries and queries involving multiple tables and columns.
[0137] Based on the multi-task mode linking method provided in the above embodiments of this application, correspondingly, the embodiments of this application also provide a multi-task mode linking system, such as... Figure 2 As shown, the system includes:
[0138] The first-stage fine-tuning unit 21 is used to perform the first-stage fine-tuning of the language model using the current natural language problem, database information, domain information of the feature domain, and training dataset to obtain the target large language model.
[0139] Knowledge base construction unit 22 is used to construct a knowledge base using database information and domain information;
[0140] The second-stage fine-tuning unit 23 is used to fine-tune the target large language model in the second stage using the current natural language problem, knowledge base and pre-built multi-task learning loss function to obtain the multi-task learning model.
[0141] The initial pattern linking unit 24 is used to perform preliminary pattern linking on the current natural language problem using the target large language model to obtain preliminary pattern linking results; wherein, the preliminary linking results include the first database table matched by the current natural language problem and its field structure;
[0142] The deep pattern linking unit 25 is used to perform deep pattern linking on the current natural language question, the retrieved content and the database information using a multi-task learning model to obtain the deep pattern linking result; wherein, the deep pattern linking result includes the second database table matched by the current natural language question and its field structure;
[0143] The integration and SQL statement generation unit 26 is used to integrate the initial pattern linking result and the deep pattern linking result to obtain the final pattern linking result, and to generate the corresponding SQL statement using the final pattern linking result.
[0144] The specific principles and execution processes of each unit in the multi-task mode linking system disclosed in the above embodiments of this application are the same as those of the multi-task mode linking method disclosed in the above embodiments of this application. Please refer to the corresponding parts of the multi-task mode linking method disclosed in the above embodiments of this application, and they will not be repeated here.
[0145] This application provides a multi-task pattern linking system. The system first fine-tunes a language model using the current natural language question, database information, domain information of the feature domain, and training dataset to obtain a target large language model. It then constructs a knowledge base using the database and domain information. Next, it fine-tunes the target large language model using the knowledge base and a pre-built multi-task learning loss function to obtain a multi-task learning model. Finally, it performs preliminary pattern linking on the current natural language question using the target large language model, obtaining preliminary pattern linking results. These preliminary results include a first database table matching the current natural language question and its field structure. The system then performs deep pattern linking on the current natural language question, retrieval content, and database information using the multi-task learning model, obtaining deep pattern linking results. These deep pattern linking results include a second database table matching the current natural language question and its field structure. Finally, it integrates the initial and deep pattern linking results to obtain a final pattern linking result, and uses this final pattern linking result to generate corresponding SQL statements. The technical solution provided in this application, through two-stage fine-tuning, enables the target large language model and multi-task learning model to more accurately understand natural language problems, thus laying the foundation for generating more accurate pattern linking results and SQL statements. Furthermore, in the second-stage fine-tuning, the multi-task learning framework (the loss function of multi-task learning) allows the multi-task learning model to adapt to different types of natural language to SQL conversion tasks, improving the model's generalization ability. Finally, the target large language model performs preliminary pattern linking on the current natural language problem, and the multi-task learning model performs deep pattern linking on the current natural language problem, retrieval content, and database information. The results of these two linking operations are then used to generate the final SQL statement. This not only enables the processing of complex query tasks, avoiding problems such as inaccurate pattern linking and missing key information, thus improving the accuracy of the generated SQL statement, but also allows for in-depth utilization of the large language model to adapt to diverse needs in different domains, avoiding low accuracy in executing long questions and multi-table, multi-column queries.
[0146] Optional, the first-stage fine-tuning unit is specifically used for:
[0147] Obtain database information and perform structured processing on the database information to obtain structured target database information, which includes multiple database tables and their field structures.
[0148] Acquire domain information for a specific domain, and map the various knowledge points within that domain information to multiple database tables and their field structures to obtain multiple mapping relationships. Each mapping relationship includes knowledge, a database table, and its field structure.
[0149] Obtain the training dataset, and select multiple natural language questions from the training dataset based on the current natural language question, and use each natural language question as a training sample;
[0150] Construct an instruction dataset based on pre-set instructions, training samples, and mapping relationships;
[0151] The large language model is fine-tuned in the first stage using the instruction dataset to obtain the target large language model.
[0152] Optional, knowledge base building unit, specifically used for:
[0153] The database information is structured to obtain structured target database information, and the domain information is processed to obtain multiple domain knowledge fragments. The target database information includes multiple database tables and their field structures; the domain knowledge fragments include knowledge and their descriptions.
[0154] The knowledge fragments from various fields are sliced with the database tables and their field structures to obtain multiple text blocks; each text block includes the knowledge and its description, as well as the database tables and their field structures.
[0155] Each text block is vectorized to obtain the vector corresponding to each text block;
[0156] The vectors of each text block are clustered to obtain multiple clusters, and each cluster is compressed to complete a two-level index for each text block, so as to construct the index of each text block;
[0157] The index of each text block and its matching metadata pointer are concatenated to obtain multiple prompt fragments; the metadata pointers include knowledge, database tables and their field structures.
[0158] Generate a corresponding knowledge base based on each prompt segment.
[0159] Optional, the second-stage fine-tuning unit is specifically used for:
[0160] The knowledge base is retrieved using retrieval enhancement generation technology based on the current natural language question to obtain corresponding retrieval content, which includes prompt fragments that match the current natural language question.
[0161] The target large language model is fine-tuned in the second stage using prompt fragments matched with the current natural language problem and a pre-built loss function for multi-task learning, resulting in a multi-task learning model.
[0162] Optionally, integration with the SQL statement generation unit, specifically used for:
[0163] The initial pattern linking results and the deep pattern linking results are merged to obtain the pattern linking result set;
[0164] The pattern link result set is validated based on database information using a pre-built validation function to obtain the validated pattern link result set.
[0165] The validated pattern linking result set is optimized based on database information using a pre-built optimization function to obtain the final pattern linking result.
[0166] The initial SQL statement is generated based on the final schema linking result using a large language model, and then the initial SQL statement is modified using database information to obtain the final SQL statement.
[0167] This application also provides a storage medium storing program instructions that, when loaded and executed by a processor, implement any of the above-described multitasking mode linking method embodiments.
[0168] This application also provides an electronic device, such as Figure 3 As shown, the device includes a processor 301 and a memory 302, which are connected via a bus; the memory stores program instructions; the processor calls the program instructions in the memory to execute any of the above-described multitasking mode linking method embodiments.
[0169] The processor mentioned in this article can be the terminal's CPU, an integrated MCU within the terminal, or a combination of a CPU and an MCU. Furthermore, the processor contains a kernel that retrieves the corresponding program from memory; one or more kernels can be configured.
[0170] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0171] The various embodiments in this specification are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for system or system embodiments, since they are basically similar to method embodiments, the description is relatively simple, and relevant parts can be referred to the descriptions in the method embodiments. The systems and system embodiments described above are merely illustrative. 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 modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0172] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0173] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
[0174] The above are merely preferred embodiments of the present invention. It should be noted that those skilled in the art can make various improvements and modifications without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A multi-task mode linking method, characterized in that, The method includes: The language model is fine-tuned in the first stage using current natural language problems, database information, domain information of feature domains, and training datasets to obtain the target large language model; wherein, the training dataset includes multiple natural language problems accumulated in history; A knowledge base is constructed using the database information and the domain information; The knowledge base is retrieved using retrieval enhancement generation technology based on the current natural language question to obtain corresponding retrieval content, wherein the retrieval content includes prompt fragments that match the current natural language question; The target large language model is fine-tuned in the second stage using a prompt fragment matched with the current natural language problem and a pre-built loss function for multi-task learning, to obtain a multi-task learning model. The target large language model is used to perform preliminary pattern linking on the current natural language problem to obtain preliminary pattern linking results; wherein, the preliminary pattern linking results include the first database table matched by the current natural language problem and its field structure; The multi-task learning model is used to perform deep pattern linking on the current natural language question, the search content, and the database information to obtain deep pattern linking results; wherein, the deep pattern linking results include a second database table matched by the current natural language question and its field structure; The preliminary pattern linking result and the deep pattern linking result are integrated to obtain the final pattern linking result, and the corresponding SQL statement is generated using the final pattern linking result.
2. The method according to claim 1, characterized in that, The process of fine-tuning the language model using current natural language problems, database information, domain information of the feature domain, and training datasets to obtain a large language model after the first stage of fine-tuning includes: Obtain database information and perform structured processing on the database information to obtain structured target database information, wherein the target database information includes multiple database tables and their field structures; Acquire domain information for a specific domain, and map the various knowledge points within that domain information to multiple database tables and their field structures to obtain multiple mapping relationships. Each mapping relationship includes knowledge, a database table, and its field structure. Obtain a training dataset, and select multiple natural language questions from the training dataset based on the current natural language question, and use each natural language question as a training sample; Construct an instruction dataset based on the pre-set instructions, training samples, and mapping relationships; The large language model is fine-tuned in the first stage using the instruction dataset to obtain the target large language model.
3. The method according to claim 2, characterized in that, The step of constructing a knowledge base using the database information and the domain information, and retrieving search content matching the current natural language problem from the knowledge base, includes: The database information is structured to obtain structured target database information. The domain information is then processed to obtain multiple domain knowledge fragments. The target database information includes multiple database tables and their field structures. The domain knowledge fragments include knowledge and their descriptions. Each of the aforementioned domain knowledge fragments and each of the aforementioned database tables and their field structures are sliced to obtain multiple text blocks; wherein, each text block includes the knowledge and its description and the database tables and their field structures; Each text block is vectorized to obtain a vector corresponding to each text block; The vectors of each text block are clustered to obtain multiple clusters, and each cluster is compressed to complete a two-level index for each text block, thereby constructing an index for each text block; The index of each text block and its matching metadata pointer are concatenated to obtain multiple prompt fragments; wherein, the metadata pointer includes knowledge, database tables and their field structures; A corresponding knowledge base is generated based on each of the aforementioned prompt fragments.
4. The method according to claim 1, characterized in that, The process of integrating the preliminary pattern linking result and the deep pattern linking result to obtain the final pattern linking result, and using the final pattern linking result to generate the corresponding SQL statement, includes: The preliminary pattern linking results and the deep pattern linking results are merged to obtain a pattern linking result set; The pattern link result set is validated based on the database information using a pre-built validation function to obtain the validated pattern link result set. The verified pattern linking result set is optimized using a pre-built optimization function based on the database information to obtain the final pattern linking result. The initial SQL statement is generated using the large language model based on the final pattern linking result, and the initial SQL statement is modified using the database information to obtain the final SQL statement.
5. A multi-task mode linking system, characterized in that, The system includes: The first-stage fine-tuning unit is used to perform first-stage fine-tuning of the language model using the current natural language problem, database information, domain information of the feature domain, and training dataset to obtain the target large language model; wherein, the training dataset includes multiple natural language problems accumulated in history; A knowledge base construction unit is used to construct a knowledge base using the database information and the domain information; The second-stage fine-tuning unit is used to perform second-stage fine-tuning on the target large language model using the current natural language problem, the knowledge base, and the pre-built multi-task learning loss function to obtain a multi-task learning model. An initial pattern linking unit is used to perform preliminary pattern linking on the current natural language problem using the target large language model to obtain preliminary pattern linking results; wherein, the preliminary pattern linking results include a first database table matched by the current natural language problem and its field structure; The deep pattern linking unit is used to perform deep pattern linking on the current natural language question, the search content, and the database information using the multi-task learning model to obtain a deep pattern linking result; wherein, the deep pattern linking result includes a second database table matched by the current natural language question and its field structure; The integration and SQL statement generation unit is used to integrate the preliminary pattern linking result and the deep pattern linking result to obtain the final pattern linking result, and to generate the corresponding SQL statement using the final pattern linking result. The second-stage fine-tuning unit is specifically used for: The knowledge base is retrieved using retrieval enhancement generation technology based on the current natural language question to obtain corresponding retrieval content, which includes prompt fragments that match the current natural language question. The target large language model is fine-tuned in the second stage using prompt fragments matched with the current natural language problem and a pre-built loss function for multi-task learning, resulting in a multi-task learning model.
6. The system according to claim 5, characterized in that, The first-stage fine-tuning unit is specifically used for: Obtain database information and perform structured processing on the database information to obtain structured target database information, wherein the target database information includes multiple database tables and their field structures; Acquire domain information for a specific domain, and map the various knowledge points within that domain information to multiple database tables and their field structures to obtain multiple mapping relationships. Each mapping relationship includes knowledge, a database table, and its field structure. Obtain a training dataset, and select multiple natural language questions from the training dataset based on the current natural language question, and use each natural language question as a training sample; Construct an instruction dataset based on the pre-set instructions, training samples, and mapping relationships; The large language model is fine-tuned in the first stage using the instruction dataset to obtain the target large language model.
7. The system according to claim 6, characterized in that, The knowledge base construction unit is specifically used for: The database information is structured to obtain structured target database information. The domain information is then processed to obtain multiple domain knowledge fragments. The target database information includes multiple database tables and their field structures. The domain knowledge fragments include knowledge and their descriptions. Each of the aforementioned domain knowledge fragments and each of the aforementioned database tables and their field structures are sliced to obtain multiple text blocks; wherein, each text block includes the knowledge and its description and the database tables and their field structures; Each text block is vectorized to obtain a vector corresponding to each text block; The vectors of each text block are clustered to obtain multiple clusters, and each cluster is compressed to complete a two-level index for each text block, thereby constructing an index for each text block; The index of each text block and its matching metadata pointer are concatenated to obtain multiple prompt fragments; wherein, the metadata pointer includes knowledge, database tables and their field structures; A corresponding knowledge base is generated based on each of the aforementioned prompt fragments.
8. An electronic device, characterized in that, include: A processor and a memory are connected via a bus; wherein the processor is used to call and execute a program stored in the memory; The memory is used to store a program for implementing a multi-tasking mode linking method as described in any one of claims 1-4.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions for performing a multitasking mode linking method as described in any one of claims 1-4.
Citation Information
Patent Citations
Knowledge retrieval enhancement-based characteristic agricultural product standardized file content generation method
CN118779407A
Chinese scene-oriented Text2SQL prompt project optimization method
CN120011509A
