Text to SQL conversion method and system based on large pre-trained model

Through the text-to-SQL conversion method based on a large pre-trained model, the problem of repeated input of SQL statements during complex queries is solved, efficient and accurate SQL conversion is achieved, and query efficiency and continuity are improved.

CN118503273BActive Publication Date: 2024-10-29SHENZHEN BORUI WORLD TECH CO LTD
View PDF 9 Cites 0 Cited by

Patent Information

Application Number
CN202410958937.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-17
Publication Date
2024-10-29
Estimated Expiration
2044-07-17

AI Technical Summary

Technical Problem

The existing technology is difficult to effectively handle the problem of repeated input of SQL statements during complex queries, resulting in low query efficiency and high error rates.

Method used

Adopting a text-to-SQL conversion method based on a large pre-training model, by obtaining the query text corpus and SQL statement encoding library, train the bidirectional pre-training model, identify interaction time samples, build a continuous query text corpus, and optimize the model to generate continuous SQL conversion statements .

Benefits of technology

It improves the accuracy and efficiency of SQL conversion, supports automatic conversion in continuous query scenarios, and reduces user input burden and error rate.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118503273B_ABST
    Figure CN118503273B_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of natural language processing, and provides a text-to-SQL conversion method and system based on a large pre-trained model. The method comprises: obtaining a query text corpus and an SQL statement encoding library; training a bidirectional pre-trained model based on the two corpora; identifying interaction time samples in the query text corpus, performing interaction continuity analysis, and obtaining a continuous query text corpus; optimizing and training the bidirectional pre-trained model with the corpus, and outputting a bidirectional optimized conversion model; inputting the user's real-time query text into the model for continuous SQL conversion, and obtaining a continuous SQL conversion statement. The present application solves the technical problem of repeated query operations caused by the recognition of SQL statements one by one, and realizes that SQL can be automatically and continuously converted through continuous output, thereby improving the accuracy and continuity of text-to-SQL conversion and better supporting the effect of continuous query.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, specifically to the field of natural language processing technology, and in particular to a text-to-SQL conversion method and system based on a large pre-trained model. Background Art

[0002] In today's increasingly complex information environment, database management systems (DBMS) have become an indispensable part of various applications. Among them, structured query language (SQL), as a standard language for interacting with databases, is widely used in operations such as querying, inserting, updating and deleting data. However, for many users, writing and understanding SQL statements can be a tedious and error-prone task. Traditional SQL generation methods usually rely on entering query requirements sentence by sentence and then converting them into corresponding SQL statements one by one. This method may be acceptable when processing simple queries, but when processing complex queries involving multiple consecutive, similar operations or processes, it is often necessary to repeatedly enter a large number of similar query conditions, which not only increases the workload, but may also lead to an increase in query error rates. Summary of the invention

[0003] The present application provides a text-to-SQL conversion method and system based on a large pre-trained model, aiming to solve the technical problem of repeated query operations caused by recognizing SQL statements one by one.

[0004] In view of the above problems, the present application provides a text-to-SQL conversion method and system based on a large pre-trained model.

[0005] The first aspect disclosed in the present application provides a text-to-SQL conversion method based on a large pre-trained model, the method comprising: obtaining a query text corpus and an SQL statement encoding library, wherein the SQL statement encoding library is mapped to the query text corpus encoding; training according to the query text corpus and the SQL statement encoding library to obtain a bidirectional pre-trained model, wherein the bidirectional pre-trained model comprises a text-SQL conversion pre-trained model and an SQL-text conversion pre-trained model, and the model parameters of the text-SQL conversion pre-trained model and the SQL-text conversion pre-trained model are shared; identifying interaction time samples of each text in the query text corpus, performing interaction continuity analysis according to the interaction time samples, and obtaining a continuous query text corpus; accessing the continuous query text corpus to train and optimize the bidirectional pre-trained model, and outputting a bidirectional optimized conversion model; obtaining a user's real-time query text, inputting the user's real-time query text into the bidirectional optimized conversion model for continuous SQL conversion, and obtaining a continuous SQL conversion statement.

[0006] Another aspect disclosed in the present application provides a text-to-SQL conversion system based on a large pre-trained model, the system comprising: a corpus and encoding library acquisition unit, the corpus and encoding library acquisition unit is used to acquire a query text corpus and an SQL statement encoding library, wherein the SQL statement encoding library is mapped to the query text corpus encoding; a model training unit, the model training unit is used to perform training according to the query text corpus and the SQL statement encoding library to acquire a bidirectional pre-trained model, wherein the bidirectional pre-trained model comprises a text-SQL conversion pre-trained model and an SQL-text conversion pre-trained model, the text-SQL conversion pre-trained model and the SQL-text conversion pre-trained model The model parameters of the conversion pre-trained model are shared; an interaction continuity analysis unit, which is used to identify the interaction time samples of each text in the query text corpus, perform interaction continuity analysis according to the interaction time samples, and obtain a continuous query text corpus; a training optimization unit, which is used to access the continuous query text corpus to perform training optimization on the bidirectional pre-trained model and output a bidirectional optimized conversion model; a continuous SQL conversion unit, which is used to obtain a user's real-time query text, input the user's real-time query text into the bidirectional optimized conversion model to perform continuous SQL conversion, and obtain a continuous SQL conversion statement.

[0007] One or more technical solutions provided in this application have at least the following technical effects or advantages:

[0008] The above-mentioned text-to-SQL conversion method based on a large pre-trained model first obtains and prepares two data sets, namely, a query text corpus and an SQL statement encoding library. There is an encoding mapping relationship between the two data sets, that is, each query text corresponds to the encoding of one or more SQL statements. Subsequently, the two data sets are used to train a bidirectional pre-trained model. This model includes two parts, one is a text-SQL conversion pre-trained model, which can convert the input query text into SQL statements; the other is an SQL-text conversion pre-trained model, which can convert SQL statements back into readable query texts. The two models share model parameters during the training process, so that they can learn from each other and improve the accuracy of the conversion. Afterwards, the interaction time samples of each text in the query text corpus, that is, the time interval between user queries, are analyzed. Through the analysis of this time interval, which queries occur continuously, thereby constructing a continuous query text corpus. Then, this continuous query text corpus is connected to the trained bidirectional pre-trained model to further train and optimize the model. This process can help the model better learn the correlation between continuous queries and improve the conversion performance in the continuous query scenario. Finally, when the real-time query text is input, the text is input into the trained bidirectional optimization conversion model, and the model will generate continuous SQL conversion statements based on the continuity and context information of the text. In this way, a series of related SQL statements can be directly obtained by inputting natural language queries, improving the efficiency and accuracy of queries.

[0009] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0011] Figure 1 The figure is a flowchart of a text-to-SQL conversion method based on a large pre-trained model in one embodiment.

[0012] Figure 2 The following is an architecture diagram of a text-to-SQL conversion system based on a large pre-trained model in one embodiment.

[0013] Explanation of the accompanying drawings: corpus and encoding library acquisition unit 1, model training unit 2, interactive continuity analysis unit 3, training optimization unit 4, continuity SQL conversion unit 5. DETAILED DESCRIPTION

[0014] The embodiments of the present application provide a text-to-SQL conversion method and system based on a large pre-trained model to solve the technical problem of repeated query operations caused by recognizing SQL statements one by one.

[0015] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0016] It should be noted that the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or server that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or modules that are not explicitly listed or inherent to these processes, methods, products or devices. Example

[0017] like Figure 1 As shown, the present application provides a text-to-SQL conversion method based on a large pre-trained model, the method comprising:

[0018] A query text corpus and an SQL statement encoding library are obtained, wherein the SQL statement encoding library is mapped to the query text corpus encoding.

[0019] With the rapid development of natural language processing technology, by training models, users can input query requirements in the form of natural language, and the model automatically converts them into corresponding SQL statements. However, most of the existing text-to-SQL conversions are still at the level of single-sentence conversion, that is, they can only process one independent query statement at a time, and cannot process multiple queries with continuous similarity. In practical applications, query operations in many scenarios have certain continuity and similarity. For example, in the process of data analysis, it is necessary to first query the basic situation of a data set, and then further filter or aggregate data based on the query results. These operations are logically continuous, and there are often similarities between query conditions. However, most of the existing query methods cannot support the continuous automatic conversion output of SQL, which will greatly prolong the query time and reduce the query efficiency.

[0020] In an embodiment of the present application, the system terminal first obtains two key data sets, namely, a query text corpus and an SQL statement encoding library. Among them, the query text corpus is a collection containing a large number of user query texts. These query texts may be collected from search engines, database query interfaces, chat robots or other query-related applications, and are used to provide natural language query samples required for training models. Each query in the query text corpus represents the user's intention to retrieve or query information. The SQL statement encoding library refers to a set of encodings of SQL statements corresponding to the query text corpus, and each SQL statement represents an instruction for retrieving, inserting, updating or deleting data in the database, and is used to provide a corresponding SQL statement representation for the query text as the target output of the model training. In these two databases, each query text has one or more corresponding SQL statement encodings in the SQL statement encoding library. Through such a matching mode, the system terminal can make the SQL statement encoding library and the query text corpus present an encoding mapping relationship, which provides basic data for subsequent model training.

[0021] Furthermore, the present application provides a method for obtaining a multi-class query text corpus, including:

[0022] Acquire a first authorized user of the user's real-time query text; classify the attributes of the continuous query text corpus according to the user attribute characteristics of the first authorized user; and acquire a multi-category query text corpus.

[0023] Preferably, in order to make the trained model more targeted and provide more personalized services, the system terminal first identifies the first-authority users with real-time query text acquisition authority. These users are part of the registered users and are authorized to input query texts in real time. Subsequently, the user attribute characteristics of these first-authority users are collected and analyzed, and these characteristics include the user's industry background, professional field, historical query records, preferences, etc. The analysis of user attribute characteristics helps the system terminal to understand the user's query needs and habits more deeply. Afterwards, the continuous query text corpus is attributed and classified according to these user attribute characteristics. This process is to carry out refined management and screening of the query text corpus, and divide it into multiple categories or subsets, each category or subset corresponds to a user group with similar attribute characteristics. Such a multi-class query text corpus is of great significance for subsequent data analysis, model training or personalized service provision, so as to better meet the personalized query needs of users.

[0024] Training is performed according to the query text corpus and the SQL statement encoding library to obtain a bidirectional pre-training model, wherein the bidirectional pre-training model includes a text-SQL conversion pre-training model and an SQL-text conversion pre-training model, and model parameters of the text-SQL conversion pre-training model and the SQL-text conversion pre-training model are shared.

[0025] In one embodiment, in order to build a model that can handle the conversion between query text and SQL statements, the system terminal uses the query text corpus and the SQL statement encoding library to train a bidirectional pre-training model. This model includes two main parts: a text-SQL conversion pre-training model and an SQL-text conversion pre-training model. The two models are interrelated, and their model parameters are shared, which means that they will influence and optimize each other during the learning process, and both models are built based on the Seq2Seq model framework. The task of the text-SQL conversion pre-training model is to convert the input query text into the corresponding SQL statement. During the training process, the text-SQL conversion pre-training model will learn the vocabulary, grammar and semantics in the query text, as well as the mapping relationship between them and the SQL statement. At the same time, the SQL-text conversion pre-training model is responsible for converting the input SQL statement into a readable query text. This SQL-text conversion pre-training model will also learn the structure, grammar and meaning of SQL statements, and understand the corresponding relationship between them and the query text. Since the parameters of the two models are shared, when one of the models learns new knowledge or patterns during the training process, this information will also be used by the other model. This bidirectional pre-training method enables the model to more comprehensively understand the relationship between query text and SQL statements, improving the accuracy and efficiency of conversion.

[0026] Furthermore, the present application provides training based on the query text corpus and the SQL statement encoding library to obtain a bidirectional pre-training model, including:

[0027] A Seq2Seq model framework is established, wherein the Seq2Seq model framework includes an encoder and a decoder, and the text-SQL conversion pre-trained model and the SQL-text conversion pre-trained model share the encoder and the decoder.

[0028] Preferably, when constructing a model for processing the conversion between query text and SQL statements, the system terminal adopts a Seq2Seq (Sequence-to-Sequence) model framework. The Seq2Seq model is a classic deep learning architecture suitable for processing problems with variable lengths of input sequences and output sequences. This model framework consists of two parts, namely an encoder and a decoder. Among them, the encoder is a bidirectional RNN encoder, which converts the input sequence into a fixed context vector. During the conversion process, each element of the input sequence is processed to generate forward and backward hidden states. The final context vector is the concatenation of the forward and backward hidden states of the last time step. The task of the decoder is to gradually generate an output sequence based on the context vector. At each time step, the decoder calculates the probability of each possible output given the current state and context vector through an internal learning function, and then selects the element with the maximum probability value from the calculated probability distribution. This element corresponds to a word or tag in the vocabulary, which will be used as the output of the current time step. Subsequently, the system terminal generates a text-SQL conversion pre-training model and an SQL-text conversion pre-training model based on the encoder and decoder training. The two models share the encoder and decoder parts of the same Seq2Seq model framework, that is, the same encoder and decoder are used to convert query text into SQL statements, or convert SQL statements into query text. Since the two pre-trained models share encoders and decoders, they can learn from each other during the training process and jointly optimize model parameters. This sharing method enables the model to better understand the conversion rules between query text and SQL statements, and improve the accuracy and efficiency of the conversion.

[0029] According to the encoder of the Seq2Seq model framework, the query text corpus and the SQL statement encoding library are trained to obtain a text-SQL conversion pre-trained model; according to the decoder of the Seq2Seq model framework, the query text corpus and the SQL statement encoding library are trained to obtain a SQL-text conversion pre-trained model; a cross loss function is introduced to optimize the loss of the text-SQL conversion pre-trained model and the SQL-text conversion pre-trained model, and a bidirectional pre-trained model is output.

[0030] Preferably, the system terminal first uses the encoder part in the Seq2Seq model framework to train the query text corpus. In each time step, the encoder reads each element in the query text corpus in turn, and gradually updates its internal state according to the state of the previous time step, that is, generates the internal environment of the forward and backward hidden states. As the encoder processes each word in the query text, its internal state gradually accumulates information about the entire query, so that the internal state is gradually improved. Through the above training process, the encoder can accurately convert the query text into a fixed-length context vector. Subsequently, the generated context vector is input into the shared decoder, and the shared decoder gradually calculates the SQL statement corresponding to each context vector through the internal learning function. By repeating the above process, the system terminal can obtain the text-SQL conversion pre-training model. Afterwards, the shared encoder is used to read each element in the SQL statement encoding library in turn, generate a fixed-length context vector, and then use the decoder to calculate the corresponding query text to obtain the SQL-text conversion pre-training model. This process is the same as the aforementioned acquisition of the text-SQL conversion pre-training model. Further, the system terminal introduces negative log-likelihood loss as a cross loss function. Negative log-likelihood loss is used to measure the difference between the predicted sequence, that is, the SQL statement or query text generated by the model and the real sequence. During the training process of the text-SQL conversion pre-training model, the system terminal extracts the probability distribution composed of the probability of each possible output when the decoder generates the SQL statement corresponding to each context vector, and then extracts the probability of the corresponding real SQL statement in the SQL statement encoding library from this probability distribution. Subsequently, the system terminal inputs these probabilities into the negative log-likelihood loss function, which calculates the loss value of each time step and calculates the mean to obtain the SQL loss value. After that, the back-propagation algorithm and gradient descent are used to update the parameters of the encoder to minimize the SQL loss value. Based on this loss value, the system terminal optimizes the learning function in the decoder. In each training process, the loss value optimization is repeated until the SQL loss value is lower than the loss threshold. Through this process, the SQL statements generated by the text-SQL conversion pre-training model can be closer to the actual situation. Then, the system terminal performs a loss optimization process similar to the above in the SQL-text conversion pre-training model training, and performs text loss values ​​on the query text generated by the SQL-text conversion pre-training model and the corresponding real query text in the query text corpus to optimize the encoder and decoder.Finally, the system terminal connects the trained and verified text-SQL conversion pre-trained model and SQL-text conversion pre-trained model in parallel to generate a bidirectional pre-trained model, and partitions and stores the parameters of the finally trained text-SQL conversion pre-trained model and SQL-text conversion pre-trained model in the encoder and decoder so as to quickly call these parameters and perform the corresponding conversion work.

[0031] Furthermore, the present application provides domain training optimization for the bidirectional pre-training model, including:

[0032] Connecting a domain conversion module, wherein the domain conversion module includes domain word vector conversion, domain word vector synonym conversion and domain sentence conversion; performing domain conversion on the query text corpus according to the domain conversion module, and outputting a text domain corpus; accessing the text domain corpus to perform domain training optimization on the bidirectional pre-training model.

[0033] Preferably, in order to make the bidirectional pre-training model more accurate, the system terminal is connected to the domain conversion module, which includes three key parts, namely domain word vector conversion, domain word vector synonym conversion and domain sentence conversion. These conversion steps are intended to convert the query text corpus from the original domain to the target domain, thereby generating a text domain corpus. In the domain word vector conversion stage, for each word or phrase in the corpus, the system terminal searches for its word vector representation in the original domain, and converts the word vector of the original domain into the word vector of the target domain according to the predefined domain word vector mapping relationship to ensure that these words have appropriate representation in the new domain. This domain word vector mapping relationship is set based on historical data and expert advice. In the domain word vector synonym conversion stage, for the query text that has been converted to the domain word vector, the system terminal identifies the vocabulary that needs to be converted to the synonym. For example, in the field of science and technology, batteries may be replaced by batteries or energy sources, while in the financial field, investment may be replaced by capital allocation or asset appreciation. This conversion helps to ensure that the text still maintains its original intention after conversion, but adapts to the new domain context. In the target domain, the synonyms or word vectors of similar concepts of these words are searched, and the most appropriate synonyms or word vectors of similar concepts are determined according to the context for replacement, and the word vector representation of the relevant words in the query text is updated. In the domain sentence conversion stage, the system terminal analyzes the sentence structure of the query text and identifies the parts that do not conform to the sentence structure of the target domain. According to the sentence expression habits of the target domain, the sentence structure of the query text is adjusted. This includes changing the order of sentences, adding or deleting certain words, changing the tone of sentences, etc., to generate query texts that conform to the sentence structure of the target domain. After the three stages are completed, the system terminal collects and outputs the processed query texts through the domain conversion module to generate a text domain corpus. The text in the corpus has been domain converted and adapted to the expression habits of the target domain. Once the domain conversion is completed, the system terminal connects the generated text domain corpus to the bidirectional pre-training model for domain training optimization. This optimization aims to enable the model to better understand the text data in the target domain and improve the performance of the model on related tasks. The training process is similar to the above. By converting the query text corpus to the target domain through the domain conversion module and using the generated text domain corpus to optimize the bidirectional pre-trained model, the performance of the model in a specific domain can be improved to ensure that the text maintains its original meaning while adapting to the new domain.

[0034] The interaction time samples of each text in the query text corpus are identified, and interaction continuity analysis is performed according to the interaction time samples to obtain a continuous query text corpus.

[0035] In one embodiment, in order to enable the bidirectional optimization conversion model to automatically and continuously convert, the system terminal extracts the submission time of each text from the query text corpus. These timestamps can be regarded as interaction time samples of the text because they record the moment of interaction. Subsequently, the system terminal calculates the time intervals between adjacent queries based on the identified interaction time samples, and evaluates the continuity between queries based on these time intervals to obtain the length of the time interval between adjacent texts. Afterwards, the query text corpus is divided according to the length of the time interval, and a continuous query text corpus is generated based on the division results. The queries in this corpus are arranged according to their interaction order in the original corpus, and the time interval between adjacent queries is short enough to meet the definition of continuity.

[0036] Furthermore, the present application provides an interaction continuity analysis based on the interaction time sample, including:

[0037] The query text corpus is analyzed according to the interaction time sample to obtain the time interval length between adjacent texts; the query text corpus is divided according to the time interval length between adjacent texts to obtain multiple groups of query text corpus partitions, wherein the time interval length between adjacent texts in each group of query text corpus partitions is less than or equal to a preset interval length; each group of query text corpus partitions is taken as a continuous query text corpus partition to obtain a continuous query text corpus.

[0038] Preferably, the system terminal obtains the interaction time samples of each text from the query text corpus, and these time samples represent the specific time when the text is submitted or interacted. Subsequently, these time samples are analyzed to calculate the time interval between adjacent texts. After that, the time interval between each adjacent text is compared with the preset time interval, and the time interval that is greater than the preset time interval is eliminated. These time intervals may be accidental situations caused by the user's operation. Among them, this preset time interval is set according to historical experience. Then, the system terminal generates multiple groups of query text corpus partitions according to the comparison results of the time interval. The texts in these partitions are arranged in the order in which they are in the query text corpus, and the time intervals between these texts meet the requirements of the preset time interval. Therefore, the system terminal regards each group as a continuous query text corpus partition. Finally, these continuous query text corpus partitions are combined to form a new corpus, that is, a continuous query text corpus. The texts in this corpus are classified based on their temporal continuity, which helps to conduct more detailed and accurate analysis later.

[0039] Furthermore, the present application provides a method for obtaining multiple groups of query text corpus partitions, further comprising:

[0040] If the time interval between adjacent texts is longer than the preset time interval, obtain the SQL adjacent statements corresponding to the adjacent texts; determine whether the SQL adjacent statements have execution continuity, and if the SQL adjacent statements have execution continuity, divide them into the query text corpus partition of the current group; if the SQL adjacent statements do not have execution continuity, obtain an interruption instruction, and divide them into the query text corpus partition of the newly created group according to the interruption instruction.

[0041] Optionally, when analyzing the query text corpus, the system terminal first creates a blank query text corpus partition and adds the first query text to this partition. When the time interval between the query text and the adjacent text is less than or equal to the preset time interval, the system terminal directly adds the adjacent text to the current partition. Otherwise, the system terminal checks the SQL statements corresponding to these texts. If these SQL adjacent statements are continuous in execution, that is, they are logically related to each other and may be part of the same task or operation, then these texts will still be divided into the query text corpus partition of the current group. This is because the user may increase the time interval due to network delays, network failures and other issues. However, if there is no execution continuity between adjacent SQL statements, it means that these statements may be generated by different tasks or operations, so the system terminal will receive an interrupt instruction at this time. This interrupt instruction indicates that the system terminal needs to create a new group to store the subsequent texts, so as to ensure that the texts of different tasks or operations are correctly distinguished. Subsequently, the system terminal checks all the generated partitions and removes the partition with only one query text. Through such processing, the query text corpus is divided into multiple groups of partitions more accurately, and the text in each partition is continuous in time and logic.

[0042] The continuous query text corpus is accessed to perform training optimization on the bidirectional pre-training model, and a bidirectional optimized conversion model is output.

[0043] In one embodiment, the system terminal uses the continuous query text corpus to map and match the SQL statement encoding library to generate a corresponding continuous SQL statement encoding library, and there are also multiple partitions in the continuous SQL statement encoding library, which correspond one to one with the partitions in the continuous query text corpus. Subsequently, the system terminal connects the continuous query text corpus and the continuous SQL statement encoding library to the bidirectional pre-training model. After that, the system terminal uses the continuous query text corpus and the continuous SQL statement encoding library to train and optimize the bidirectional pre-training model, and the training process is similar to the aforementioned training. Through continuous iteration and optimization, the bidirectional pre-training model will gradually learn the corresponding relationship between the continuous query text and the continuous SQL statement, so that the performance of the bidirectional pre-training model will be comprehensively improved, better adapting to and meeting the needs of users. When the training is completed, the system terminal obtains an optimized bidirectional conversion model, that is, a bidirectional optimized conversion model. This model not only inherits the advantages of the bidirectional pre-training model sentence by sentence recognition, but also obtains more domain knowledge and context information through the training of the continuous query text corpus, making it more accurate and efficient when processing continuous automatic conversion tasks.

[0044] The user's real-time query text is obtained, and the user's real-time query text is input into the bidirectional optimization conversion model for continuous SQL conversion to obtain a continuous SQL conversion statement.

[0045] In one embodiment, when a user performs a real-time query, the system terminal captures these real-time query texts. These query texts contain database query operations that the user wants to perform. In order to convert these query texts into valid SQL statements and execute them, the system terminal inputs the user's real-time query text into a bidirectional optimization conversion model. The bidirectional optimization conversion model calls the encoder of the internal text-SQL conversion model to encode the input user's real-time query text, and then decodes the encoding result through the transition probability prediction expression of the decoder to generate continuous SQL conversion statements. Among them, the transition probability prediction expression is a learning function that is gradually optimized after training. The continuous SQL conversion statement is a group of related SQL query statements generated after the natural language query text input by the user is processed by the bidirectional optimization conversion model. These statements are semantically coherent and can be executed step by step to fully realize the user's query intention. For example, when the natural language query text input by the user is to query the weather conditions on a certain day, the system terminal will predict the query direction to be performed next according to the user's query habits, such as the traffic conditions for travel, suitable clothing, etc., and then determine the SQL conversion statement with the probability that meets the expected expectation according to the prediction results. By converting the user's real-time query text into continuous SQL statements that can be executed in the database, users can use natural language to query without writing complex SQL statements, thereby improving the efficiency and convenience of queries.

[0046] Furthermore, the present application provides inputting the user's real-time query text into the bidirectional optimization conversion model for continuous SQL conversion, including:

[0047] An initial transition probability distribution is defined according to interaction time samples of each text, wherein the initial transition probability distribution is a transition probability that identifies a user's transition from a previous query statement to a next query statement; and a Markov chain is constructed according to the initial transition probability distribution.

[0048] Preferably, the system terminal calculates the probability of transferring from one query statement to another query statement based on the interaction time samples of each text, which is determined by searching the entire query text corpus, counting the number of occurrences of a word or sentence immediately following the query, and calculating the proportion of the number of occurrences of this word or sentence to the total number of occurrences. For example, under the same interaction time sample, if the query of weather is followed by the query of traffic, travel, and clothing, where traffic is queried 30 times, travel is queried 10 times, and clothing is queried 60 times, then the transition probability of transferring from weather to traffic is 0.3, the transition probability of transferring from weather to travel is 0.1, and the transition probability of transferring from weather to clothing is 0.6. By counting these transition probabilities, the system terminal defines an initial transition probability distribution. Subsequently, the system terminal regards each query statement of the user as a state and constructs a state set. For example, if the user's query statement includes weather, traffic, travel, and clothing, then the state set includes four states of weather, traffic, travel, and clothing. Afterwards, the initial transition probability distribution is used to construct a transition probability matrix. Each row of this matrix represents a state, and each column also represents a state. The elements in the matrix are the probabilities of transitioning from the row state to the column state. For example, when the probability of weather transitioning to traffic is 0.3, and the probability of transitioning to travel is 0.1, then the element in the weather row and the traffic column in the transition probability matrix is ​​0.3, and the element in the travel column is 0.1. Then, the system terminal associates each state in the state set with the corresponding row and column in the transition probability matrix. In this way, each state corresponds to a set of transition probabilities that describe the possibility of transitioning from that state to all other possible states. After the association is completed, the system terminal completes the construction of the Markov chain.

[0049] The Markov chain is used to perform transition probability prediction on the user's real-time query text to obtain multiple prediction sentences greater than a preset expectation, wherein the expression of the transition probability prediction includes:

[0050] ;

[0051] in, is the transition probability, Indicates at time The query text , Indicates at time The query text ; Output continuous SQL conversion statements based on the multiple prediction statements.

[0052] Preferably, the system terminal uses a Markov chain inside the decoder to predict the transition probability of the user's real-time query text converted by the encoder. The Markov chain calculates the specific probability of state transition by using the transition probability prediction expression and the corresponding relationship between the state set and the transition probability matrix, and screens out the state transition direction with a probability greater than the preset expectation, and then obtains the corresponding SQL statement from the SQL statement encoding library. The specific transition probability prediction expression is as follows:

[0053] ;

[0054] in, is a conditional probability, indicating that the query text at a given time t is Under the condition of , the query text at time t+1 is The probability of , which measures the possibility of transition from one query text to another. It means in time , the query text entered by the user is . It means that at time t+1, the query text that may be entered is . Refers to the query Transfer to Query The number of times. Representation query The total number of occurrences. After obtaining the SQL statements corresponding to each prediction result, the bidirectional optimization conversion model outputs these SQL statements and generates continuous SQL conversion statements. These continuous SQL conversion statements will be fed back to the user by the system terminal.

[0055] In summary, the embodiments of the present application have at least the following technical effects:

[0056] The embodiment of the present application establishes a mapping relationship between text and SQL by acquiring a query text corpus and a corresponding SQL statement encoding library. Subsequently, these corpora are used to train a bidirectional pre-training model, which not only includes a text-SQL conversion pre-training model, but also includes an SQL-text conversion pre-training model, and the two share model parameters. In order to further improve the accuracy of the model, by identifying the interactive time samples in the query text corpus, the query text with continuity is organized into a continuous query text corpus, and the pre-training model is trained and optimized with it to obtain a bidirectional optimization conversion model. When the user enters the real-time query text, it is input into the bidirectional optimization conversion model, and the Markov chain is used to predict the transition probability of the continuity of the query text to obtain multiple possible prediction statements. These prediction statements are not only based on the current query text, but also take into account the previous query history and possible subsequent queries, thereby generating continuous and user-intended SQL conversion statements. In addition, in order to process query texts in different fields, a field conversion module is introduced, and the query text is subjected to field adaptation processing by technical means such as field word vector conversion, synonym conversion and sentence conversion, so that it is more in line with the query habits and requirements of a specific field. At the same time, the influence of authorized users and user attribute characteristics is also considered, and the continuous query text corpus is classified according to the user's attributes and permissions to provide more personalized and accurate query services. These technical effects jointly solve the technical problem of repeated query operations caused by SQL statement recognition one by one, and realize continuous automatic conversion of SQL through continuous output, improve the accuracy and continuity of text-to-SQL conversion, and better support the effect of continuous query. Example

[0057] Based on the same inventive concept as the text-to-SQL conversion method based on a large pre-trained model in the aforementioned embodiment, Figure 2 As shown, the present application provides a text-to-SQL conversion system based on a large pre-trained model, the system comprising:

[0058] Corpus and encoding library acquisition unit 1: The corpus and encoding library acquisition unit 1 is used to acquire a query text corpus and an SQL statement encoding library, wherein the SQL statement encoding library is mapped to the query text corpus encoding;

[0059] Model training unit 2: the model training unit 2 is used to perform training according to the query text corpus and the SQL statement encoding library to obtain a bidirectional pre-training model, wherein the bidirectional pre-training model includes a text-SQL conversion pre-training model and an SQL-text conversion pre-training model, and the model parameters of the text-SQL conversion pre-training model and the SQL-text conversion pre-training model are shared;

[0060] Interaction continuity analysis unit 3: The interaction continuity analysis unit 3 is used to identify the interaction time samples of each text in the query text corpus, perform interaction continuity analysis according to the interaction time samples, and obtain a continuous query text corpus;

[0061] Training optimization unit 4: the training optimization unit 4 is used to access the continuous query text corpus to train and optimize the bidirectional pre-training model, and output a bidirectional optimized conversion model;

[0062] Continuous SQL conversion unit 5: The continuous SQL conversion unit 5 is used to obtain the user's real-time query text, input the user's real-time query text into the bidirectional optimization conversion model to perform continuous SQL conversion, and obtain a continuous SQL conversion statement.

[0063] Furthermore, the corpus and encoding library acquisition unit 1 is also used to perform the following method:

[0064] Acquire a first authorized user of the user's real-time query text; classify the attributes of the continuous query text corpus according to the user attribute characteristics of the first authorized user; and acquire a multi-category query text corpus.

[0065] Furthermore, the model training unit 2 is also used to perform the following method:

[0066] Connecting a domain conversion module, wherein the domain conversion module includes domain word vector conversion, domain word vector synonym conversion and domain sentence conversion; performing domain conversion on the query text corpus according to the domain conversion module, and outputting a text domain corpus; accessing the text domain corpus to perform domain training optimization on the bidirectional pre-training model.

[0067] Furthermore, the model training unit 2 is also used to perform the following method:

[0068] A Seq2Seq model framework is established, wherein the Seq2Seq model framework includes an encoder and a decoder, and the text-SQL conversion pre-trained model and the SQL-text conversion pre-trained model share the encoder and the decoder; according to the encoder of the Seq2Seq model framework, the query text corpus and the SQL statement encoding library are trained to obtain a text-SQL conversion pre-trained model; according to the decoder of the Seq2Seq model framework, the query text corpus and the SQL statement encoding library are trained to obtain a SQL-text conversion pre-trained model; a cross loss function is introduced to optimize the loss of the text-SQL conversion pre-trained model and the SQL-text conversion pre-trained model, and a bidirectional pre-trained model is output.

[0069] Furthermore, the interaction continuity analysis unit 3 is also used to perform the following method:

[0070] The query text corpus is analyzed according to the interaction time sample to obtain the time interval length between adjacent texts; the query text corpus is divided according to the time interval length between adjacent texts to obtain multiple groups of query text corpus partitions, wherein the time interval length between adjacent texts in each group of query text corpus partitions is less than or equal to a preset interval length; each group of query text corpus partitions is taken as a continuous query text corpus partition to obtain a continuous query text corpus.

[0071] Furthermore, the interaction continuity analysis unit 3 is also used to perform the following method:

[0072] Determine whether the SQL adjacent statements have execution continuity. If the SQL adjacent statements have execution continuity, divide them into the query text corpus partition of the current group; if the SQL adjacent statements do not have execution continuity, obtain an interruption instruction, and divide them into the query text corpus partition of the newly created group according to the interruption instruction.

[0073] Furthermore, the continuity SQL conversion unit 5 is also used to execute the following method:

[0074] According to the interaction time samples of each text, an initial transition probability distribution is defined, wherein the initial transition probability distribution is a transition probability that identifies the user's transition from the previous query statement to the next query statement; according to the initial transition probability distribution, a Markov chain is constructed; the Markov chain is used to perform transition probability prediction on the user's real-time query text to obtain multiple predicted statements greater than a preset expectation, wherein the expression of transition probability prediction includes:

[0075] ;

[0076] in, is the transition probability, Indicates at time The query text , Indicates at time The query text ; Output continuous SQL conversion statements based on the multiple prediction statements.

[0077] It should be noted that the above-mentioned sequence of the embodiments of the present application is only for description and does not represent the advantages and disadvantages of the embodiments. And the above-mentioned specific embodiments of this specification are described. The processes depicted in the accompanying drawings do not necessarily require the specific order and continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0078] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.

[0079] This specification and drawings are merely exemplary illustrations of the present application and are deemed to cover any and all modifications, variations, combinations or equivalents within the scope of the present application. Obviously, a person skilled in the art may make various modifications and variations to the present application without departing from the scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the present application and its equivalents, the present application intends to include these modifications and variations.

Claims

1. A text-to-SQL conversion method based on a large pre-trained model, characterized in that: The method comprises: Acquire a query text corpus and an SQL statement encoding library, wherein the SQL statement encoding library is mapped to the query text corpus encoding; Performing training according to the query text corpus and the SQL statement encoding library to obtain a bidirectional pre-training model, wherein the bidirectional pre-training model includes a text-SQL conversion pre-training model and an SQL-text conversion pre-training model, and model parameters of the text-SQL conversion pre-training model and the SQL-text conversion pre-training model are shared; Identifying interaction time samples of each text in the query text corpus, performing interaction continuity analysis based on the interaction time samples, and obtaining a continuous query text corpus; Accessing the continuous query text corpus to train and optimize the bidirectional pre-trained model, and outputting a bidirectional optimized conversion model; Acquire a user's real-time query text, input the user's real-time query text into the bidirectional optimization conversion model for continuous SQL conversion, and acquire a continuous SQL conversion statement; Training is performed according to the query text corpus and the SQL statement encoding library to obtain a bidirectional pre-training model, the method comprising: Establishing a Seq2Seq model framework, wherein the Seq2Seq model framework includes an encoder and a decoder, and the text-SQL conversion pre-trained model and the SQL-text conversion pre-trained model share the encoder and the decoder; According to the encoder of the Seq2Seq model framework, the query text corpus and the SQL statement encoding library are trained to obtain a text-SQL conversion pre-training model; According to the decoder of the Seq2Seq model framework, the query text corpus and the SQL statement encoding library are trained to obtain a SQL-text conversion pre-training model; Introducing a cross loss function, performing loss optimization on the text-SQL conversion pre-training model and the SQL-text conversion pre-training model, and outputting a bidirectional pre-training model; Performing an interaction continuity analysis according to the interaction time sample includes: Analyze the query text corpus according to the interaction time sample to obtain the time interval between adjacent texts; Dividing the query text corpus according to the time interval between adjacent texts to obtain multiple groups of query text corpus partitions, wherein the time interval between adjacent texts in each group of query text corpus partitions is less than or equal to a preset interval length; Taking each group of query text corpus partitions as a continuous query text corpus partition, and obtaining a continuous query text corpus; If the time interval between adjacent texts is longer than the preset time interval, obtaining SQL adjacent statements corresponding to the adjacent texts; Determine whether the adjacent SQL statements have execution continuity, and if the adjacent SQL statements have execution continuity, divide them into query text corpus partitions of the current group; If the adjacent SQL statements do not have execution continuity, an interruption instruction is obtained, and the query text corpus partitions are divided into newly created groups according to the interruption instruction; The user real-time query text is input into the bidirectional optimization conversion model for continuous SQL conversion, the method comprising: According to the interaction time samples of each text, an initial transition probability distribution is defined, wherein the initial transition probability distribution is a transition probability that identifies the user's transition from the previous query statement to the next query statement; Constructing a Markov chain according to the initialization transition probability distribution; The Markov chain is used to perform transition probability prediction on the user's real-time query text to obtain multiple prediction statements greater than a preset expectation, wherein the expression of the transition probability prediction includes: ; in, is the transition probability, Indicates at time The query text , Indicates at time The query text ; According to the multiple predicted statements, continuous SQL conversion statements are output.

2. The text-to-SQL conversion method based on a large pre-trained model as claimed in claim 1, characterized in that: The method further comprises: Connecting a domain conversion module, wherein the domain conversion module includes domain word vector conversion, domain word vector synonym conversion and domain sentence conversion; Performing domain conversion on the query text corpus according to the domain conversion module, and outputting a text domain corpus; The text domain corpus is accessed to perform domain training optimization on the bidirectional pre-training model.

3. The text-to-SQL conversion method based on a large pre-trained model as claimed in claim 1, characterized in that: The method further comprises: Acquire the first authorized user of the real-time query text of the user; According to the user attribute characteristics of the first authorized user; The attributes of the continuous query text corpus are classified according to the user attribute features to obtain a multi-category query text corpus.

4. A text-to-SQL conversion system based on a large pre-trained model, characterized by: The steps for implementing the text-to-SQL conversion method based on a large pre-trained model as described in any one of claims 1 to 3 include: Corpus and encoding library acquisition unit: acquires a query text corpus and an SQL statement encoding library, wherein the SQL statement encoding library is mapped to the query text corpus encoding; Model training unit: performing training according to the query text corpus and the SQL statement encoding library to obtain a bidirectional pre-training model, wherein the bidirectional pre-training model includes a text-SQL conversion pre-training model and an SQL-text conversion pre-training model, and model parameters of the text-SQL conversion pre-training model and the SQL-text conversion pre-training model are shared; An interaction continuity analysis unit: identifying interaction time samples of each text in the query text corpus, performing interaction continuity analysis according to the interaction time samples, and acquiring a continuous query text corpus; Training optimization unit: accessing the continuous query text corpus to train and optimize the bidirectional pre-training model, and outputting a bidirectional optimized conversion model; Continuous SQL conversion unit: obtains user real-time query text, inputs the user real-time query text into the bidirectional optimization conversion model for continuous SQL conversion, and obtains continuous SQL conversion statements.

Citation Information

Patent Citations

  • Training method and device of voice speech translation model

    CN109785824A

  • Training method, device and equipment of retrieval matching model, and storage medium

    CN112579870A

  • Method and device for generating SQL statement conversion model

    CN113051286A

  • Automatic reply method and device for user inquiry and electronic equipment

    CN113254619A

  • Intelligent class case retrieval method based on speech recognition and NL2SQL model

    CN114168885A