A Text-to-SQL method, system, and medium
By annotating database column name information in the Text-to-SQL model, using pre-trained model encoding and autoregressive decoding, and combining SQL syntax judgment and structure completion, the low accuracy of existing models in complex scenarios is solved, and more efficient SQL generation is achieved.
Patent Information
- Application Number
- CN202310502292.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-06
- Publication Date
- 2026-01-30
- Estimated Expiration
- 2043-05-06
AI Technical Summary
Existing Text-to-SQL models have low accuracy in handling complex application scenarios involving multiple tables, multiple domains, and multiple rounds. In particular, when the problem and database structure are long, it is difficult to meet the syntax rules, resulting in low generation accuracy.
By acquiring and labeling column name information in the database structure, encoding is performed using pre-trained models such as BART or T5. Combined with autoregressive decoding and SQL syntax judgment, words that satisfy grammatical relationships are retained, missing table names are filled in, a prefix tree is constructed for bundle search, and JOIN keywords are added, thereby reducing the learning difficulty of the model and improving the generation accuracy.
It improves the accuracy of Text-to-SQL generation tasks in complex scenarios, solves the problem of low generation accuracy of the model in multi-table, multi-domain, and multi-round application scenarios, and achieves more efficient SQL generation.
Smart Images

Figure CN116521711B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of database, in particular to a Text-to-SQL method, system and medium. BACKGROUND
[0002] Text-to-SQL generation task is a research direction in the field of natural language processing, and the Text-to-SQL generation task is specifically that a system generates a SQL statement consistent with the semantics of a question according to the question, and executes the statement in a database to obtain the corresponding result.
[0003] At present, most of the researches on Text-to-SQL are for end-to-end generation methods, such as SQL generation based on fixed templates (SQLova, M-SQL, etc.), SQL generation based on grammar and transition system (RAT-SQL, etc.), and SQL generation based on pre-training model and constraint decoding (PICARD, etc.). However, the existing model architecture applications have certain limitations, for example, they can only be limited to single table, single domain or single round of Text-to-SQL problems. Although the PICARD model in the prior art uses a Transformer to complete the Text-to-SQL generation task, the model structure is relatively complex and is difficult to apply to multi-table, multi-domain and multi-round application scenarios. Moreover, in a complex application scenario, when the question and the database structure are long, the Text-to-SQL has the problem of low accuracy. SUMMARY
[0004] The purpose of the present application is to solve the problem of low accuracy in Text-to-SQL due to the length of the question and the database structure, and to propose a Text-to-SQL method, system and medium.
[0005] The technical solution adopted by the present application to solve the above technical problems is:
[0006] A Text-to-SQL method, comprising the following steps:
[0007] Step one: obtaining a Text-to-SQL question and a database structure, converting the Text-to-SQL question and the database structure into linear text and then splicing to obtain input information;
[0008] Step two: finding a column name in the input information, and labeling category information after the column name;
[0009] Step three: encode the input information after marking the category information to obtain an encoding vector V, and based on the encoding vector V, use autoregressive decoding to obtain a result text;
[0010] Step four: obtain all words in the result text and the order of the words, and then for each word in the result text, sequentially determine whether the current word and the next word satisfy the SQL syntax relationship, if yes, retain the current word,
[0011] Step five: splice the words retained in step four into a target text, and based on the target text, count the table names in the target text except the FROM keyword, and compare the table names in the target text except the FROM keyword with the table names in the FROM keyword, and based on the comparison result, supplement the missing table names in the FROM keyword.
[0012] Further, the encoding of the input information after marking the category information specifically includes:
[0013] The pre-training model is a BART algorithm model or a T5 algorithm model.
[0014] Further, the specific steps of obtaining the result text based on the encoding vector V by using autoregressive decoding are:
[0015] In each round, the word with the largest weight is selected as the currently generated word through autoregressive decoding, and then the result text is obtained.
[0016] Further, the specific steps of obtaining the result text by using autoregressive decoding in each round to select the word with the largest weight as the currently generated word are:
[0017] Step 3.1: based on the encoding vector V, map the encoding vector V to a word vector through linear transformation, wherein the number of dimensions of the word vector is consistent with the number of corresponding words in the word table, and the numerical value on each dimension of the word vector represents the weight of the word corresponding to the dimension being selected, the word corresponding to the dimension with the largest weight is selected as the target word, the target word is encoded to obtain an encoding vector E, and then the encoding vector E and the encoding vector V are spliced and mapped to obtain a new encoding vector;
[0018] Step 3.2: replace the encoding vector V in step three with the new encoding vector, and repeat the above steps until a terminal symbol is generated, and determine the result text according to the target words determined in all rounds and the order of adjacent rounds.
[0019] Further, in the fourth step, if the current word and the next word do not satisfy the syntax relationship of the SQL, the weights corresponding to all the words in the current word round are sorted, and the current word is replaced by the word corresponding to the second largest weight in turn until the replaced word and the next word satisfy the syntax relationship of the SQL.
[0020] Further, the category information includes subsidiary relationship, foreign key relationship, table relationship, internal structure information, name linkage information, numerical value linkage information, and historical information.
[0021] Further, the category information after the column name is labeled, specifically: the subsidiary relationship after the column name is labeled as BL, the foreign key relationship after the column name is labeled as FK, the table relationship after the column name is labeled as FT, the internal structure information after the column name is labeled as TK, the name linkage information after the column name is labeled as SL, the numerical value linkage information after the column name is labeled as EL, and the historical information after the column name is labeled as HI.
[0022] A Text-to-SQL system, comprising: an input information acquisition module, a labeling module, an encoding module, a syntax judgment module, and a completion module;
[0023] The input information acquisition module is configured to acquire a Text-to-SQL question and a database structure, concatenate the Text-to-SQL question and the database structure after converting them into linear texts to obtain input information;
[0024] The labeling module is configured to find a column name in the input information and label category information after the column name;
[0025] The encoding module is configured to encode the input information after the category information is labeled to obtain an encoding vector V, and based on the encoding vector V, use autoregressive decoding to obtain a result text;
[0026] The syntax judgment module is configured to acquire all the words in the result text and the order of the words, and then judge whether the current word and the next word satisfy the syntax relationship of the SQL for each word in the result text in turn, and if so, retain the current word;
[0027] The completion module is configured to concatenate the retained words into a target text, and based on the target text, count the table names in the target text except the FROM keyword, compare the table names in the target text except the FROM keyword with the table names in the FROM keyword, and based on the comparison result, supplement the missing table names in the FROM keyword.
[0028] Further, the encoding module is configured to use autoregressive decoding based on the encoding vector V to obtain the result text, and the specific steps are:
[0029] The encoding module is configured to select, in each round, a word with the largest weight as a currently generated word through autoregressive decoding, thereby obtaining a result text.
[0030] A Text-to-SQL medium comprising a computer readable program configured to perform the steps of any one of claims 1 to 7.
[0031] The present application has the following advantages:
[0032] The present application addresses the problems of model memory information difficulty and weak information correspondence ability when the database structure is long. The present application retains words that meet the syntax rules by information marking and applying SQL syntax rules, sorts all weights corresponding to the current word in the current round for the words that do not meet the syntax rules, and replaces the current word with the words corresponding to the second largest weight in turn until the replaced word and the next word meet the syntax relationship of SQL. The replaced word is then retained. Finally, the text is spliced, thereby solving the problems of memory information difficulty and weak information correspondence ability. The present application ultimately solves the problem of low accuracy in Text-to-SQL due to the length and database structure of the prior art, thereby improving the accuracy of SQL generation. BRIEF DESCRIPTION OF DRAWINGS
[0033] Figure 1 The present application is a whole flowchart;
[0034] Figure 2 The present application is a structure diagram;
[0035] Figure 3 The present application is a process diagram for decoding SQL statements;
[0036] Figure 4 The present application is a SQL completion process diagram. DETAILED DESCRIPTION
[0037] It should be particularly noted that the various embodiments disclosed in the present application can be combined with each other without conflict.
[0038] Specific embodiment one: reference Figure 1 Specifically, the present embodiment is a Text-to-SQL method, characterized by the following steps:
[0039] Step one: obtain the Text-to-SQL question and the database structure, convert the Text-to-SQL question and the database structure into linear text, and splice them to obtain input information;
[0040] Step two: For the input information, the column name is obtained in the input information, and the category information is marked behind the column name;
[0041] Step three: The marked input information is encoded to obtain an encoding vector V, and through autoregressive decoding, the word with the maximum weight is selected in each round as the currently generated word, and then the result text is obtained;
[0042] Step four: For each word in the result text, it is sequentially determined whether the current word and the next word satisfy the syntax relationship of SQL, if yes, the current word is retained, otherwise, all weights in the current word corresponding round are sorted, and the word corresponding to the second largest weight is selected to replace the current word, and the replaced word is retained until the replaced word and the next word satisfy the syntax relationship of SQL. Here, an example is given. For example, the result text includes five words. First, it is determined whether the first word (assuming A) and the second word (assuming F) satisfy the syntax relationship of SQL. If yes, the first word is retained, and it is determined whether the second word and the third word satisfy the syntax relationship of SQL. If not, according to the autoregressive decoding process, the first word determines all weights obtained in the first round of autoregressive decoding process and the word corresponding to the maximum weight of each weight (in the autoregressive decoding process), such as the first word in the result text in the autoregressive decoding process. The weight of A is 0.4, the weight of B is 0.3, the weight of C is 0.2, and the weight of D is 0.1. Therefore, the word A corresponding to the weight 0.4 is selected as the first word.
[0043] When the current word and the next word do not satisfy the syntax relationship of SQL, here, an example is given for the first word in the result text. All weights in the first round of autoregressive decoding process are sorted, and the word corresponding to the second largest weight is selected according to the sorting, and it is determined whether the selected word and the next word satisfy the syntax relationship of SQL. If yes, the first word is replaced with the word corresponding to the second weight, otherwise, according to the sorting, the word is continuously selected to determine whether it satisfies the syntax relationship of SQL (A and F do not satisfy the syntax relationship of SQL, then it is determined whether B and F satisfy the syntax relationship of SQL, if yes, B is used as the current word, that is, B is retained, otherwise, it is continuously determined whether C and F satisfy the syntax relationship of SQL).
[0044] Step five: The words retained in step four are spliced into a target text, and based on the target text, the table names in the target text except the FROM keyword are counted, and the table names in the target text except the FROM keyword are compared with the table names in the FROM keyword. Based on the comparison result, the missing table names in the FROM keyword are supplemented, that is, the Text-to-SQL is completed.
[0045] To solve the limitations of existing Text-to-SQL methods in application scenarios, the present application proposes a structure-aware method for SQL generation. However, in complex application scenarios, the length of the problem and the database structure, the generation of SQL has the problem of low accuracy. To solve this problem and reduce the learning difficulty of the model, the present application additionally proposes a structure marking, a limited decoding, and a SQL completion mechanism.
[0046] The present application is applicable to the text-to-SQL generation task and can be divided into four parts: generating an input with structure marking, model coding, limited decoding, and generating SQL completion. The specific process is shown in Figure 1 The overall structure of the model is shown in Figure 2 .
[0047] Limited decoding
[0048] Because the input information is complex, the language model may generate SQL containing entities that do not exist in the database when predicting SQL. The present application solves this problem by constructing a prefix tree based on the database structure. Each node in the book corresponds to a character in the dictionary, and each node's child node corresponds to the allowed successor of the node. After obtaining the prefix tree, multiple candidate results for the current step are generated at each step of beam search, and each result is checked to see if it is a legal successor of the previous step. The prediction results that do not meet the requirements are filtered out. This process is repeated until the prediction result is the end symbol and is a legal successor.
[0049] For example, Figure 3 , this is the process of generating SQL statements by the model. In the second step of generation, among the four candidate successors of the generated SELECT keyword, according to the SQL syntax rules, the FROM keyword cannot directly follow the SELECT keyword, so it is eliminated, and the other three legal results are retained. Through limited decoding, we can significantly improve the proportion of legal SQL generated by the model.
[0050] SQL completion
[0051] Because the JOIN keyword is not explicitly mentioned in the question, the JOIN keyword is often omitted when generating the answer. To improve the accuracy of SQL generation, Text-to-SQL needs to have the ability to supplement the missing JOIN keyword based on the database structure. Specifically, this method first constructs a schema graph based on the database structure. Each node in the graph represents a table name or a column name, and each edge corresponds to a structural relationship, such as table-column inclusion relationship, table-table foreign key relationship, etc. Based on this schema graph, the model attempts to find tables and columns in the shortest path between existing tables and columns in a JOIN-lacking SQL.
[0052] For example, this is a SQL without JOIN keyword, the table MATCHES and column WINNER_id are not mentioned in the FROM clause. We infer these two information from their neighbors PLAYERS and RANKING. Since MATCHES is on the path of the join of these two tables, and WINNER_id is the primary key of MATCHES, in this way we can complete the full SQL statement. Figure 4
[0053] Specific embodiment two: this embodiment is a further description of specific embodiment one, the difference between this embodiment and specific embodiment one is that the input information after labeling the category information is encoded, specifically including:
[0054] The input information after labeling the category information is encoded by using a pre-trained model, and the pre-trained model is a BART algorithm model or a T5 algorithm model.
[0055] Model encoding
[0056] After labeling the structure mark, the constructed input is sent into a pre-trained model for encoding. The pre-trained language model can use BART, T5 and the like self-encoding language model, and after the encoding is completed, each character in the answer is generated step by step through the self-recursive way.
[0057] Specific embodiment three: this embodiment is a further description of specific embodiment one, the difference between this embodiment and specific embodiment one is that the specific steps of obtaining the result text based on the encoding vector V by using the self-recursive decoding are:
[0058] Through the self-recursive decoding, the word with the largest weight is selected as the current generated word in each round, and then the result text is obtained.
[0059] Specific embodiment four: this embodiment is a further description of specific embodiment three, the difference between this embodiment and specific embodiment three is that the specific steps of obtaining the result text by using the self-recursive decoding, and selecting the word with the largest weight as the current generated word in each round are:
[0060] Step 3.1: based on the encoding vector V, the encoding vector V is mapped to a word vector through linear transformation, wherein the number of dimensions of the word vector is consistent with the number of corresponding words in the word table, and the numerical value of each dimension of the word vector represents the weight of the word corresponding to the dimension selected, the word corresponding to the dimension with the largest weight is selected as the target word, the target word is encoded to obtain the encoding vector E, and then the encoding vector E and the encoding vector V are spliced and mapped to obtain a new encoding vector;
[0061] Step 3.2: Replace the encoding vector V in step three one with the new encoding vector, and repeat the above steps until the terminal symbol is generated, and according to the target word determined in all rounds, and the order of the results text of the adjacent round.
[0062] Specific implementation five: this implementation is a further description of the specific implementation one, the difference between this implementation and the specific implementation one is that in step four, if the current word and the next word do not satisfy the syntax relationship of SQL, then sort all the weights in the current word corresponding round, and replace the current word from the second largest weight corresponding word in turn, until the replaced word and the next word satisfy the syntax relationship of SQL, then keep the replaced word.
[0063] Specific implementation six: this implementation is a further description of the specific implementation one, the difference between this implementation and the specific implementation one is that the category information includes subsidiary relationship, foreign key relationship, table relationship, internal structure information, name link information, numerical link information and historical information.
[0064] Specific implementation seven: this implementation is a further description of the specific implementation six, the difference between this implementation and the specific implementation six is that the category information is marked after the column name, specifically: the subsidiary relationship after the column name is marked as BL, the foreign key relationship after the column name is marked as FK, the table relationship after the column name is marked as FT, the internal structure information after the column name is marked as TK, the name link information after the column name is marked as SL, the numerical link information after the column name is marked as EL, and the historical information after the column name is marked as HI.
[0065] Generating input with structure markers
[0066] Because the database contains complex internal and external key relationships, and the model is difficult to capture and remember these relationships. The basic input information includes the question and the database structure, in order to reduce the difficulty of the model to understand the input information, this method marks different markers in the input text to indicate different information. For example, if a column name is the foreign key of the table, it will be marked after it, such as <fk>The specific marking information is shown in Table 1.
[0067] Table 1
[0068]
[0069] Specific implementation eight: a Text-to-SQL system, comprising: an input information acquisition module, a marking module, an encoding module, a syntax judgment module and a completion module;
[0070] The input information acquisition module is configured to acquire a Text-to-SQL question and a database structure, splice the Text-to-SQL question and the database structure after being converted into linear text to obtain input information;
[0071] The marking module is configured to find a column name in the input information and mark category information after the column name;
[0072] The encoding module is configured to encode the input information after the category information to obtain an encoding vector V, and obtain a result text by using autoregressive decoding based on the encoding vector V;
[0073] The specific steps of obtaining the result text by using autoregressive decoding based on the encoding vector V are as follows:
[0074] In each round, the word with the largest weight is selected as the currently generated word by autoregressive decoding, and then the result text is obtained;
[0075] The syntax judgment module is configured to acquire all words in the result text and the order of the words, and then judge whether the current word and the next word satisfy the syntax relationship of SQL for each word in the result text in turn, if yes, the current word is reserved, otherwise, all weights in the current word corresponding round are sorted, and the current word is replaced by the words corresponding to the next largest weights in turn until the replaced word and the next word satisfy the syntax relationship of SQL, and then the replaced word is reserved;
[0076] The completion module is configured to splice the reserved words into a text, and based on the spliced text, count the table names in the text except the FROM keyword, compare the table names with the table names in the FROM keyword, and based on the comparison result, supplement the missing table names in the FROM keyword;
[0077] The category information includes subsidiary relationship, foreign key relationship, table relationship, internal structure information, name linkage information, numerical value linkage information and historical information.
[0078] The category information marked after the column name is specifically: the affiliation relationship is marked as BL, the foreign key relationship is marked as FK, the table relationship is marked as FT, the internal structure information is marked as TK, the name link information is marked as SL, the numerical link information is marked as EL, and the history information is marked as HI.
[0079] Specific embodiment nine: this embodiment is a further description of specific embodiment eight, and the difference between this embodiment and specific embodiment eight is that the specific steps of the encoding module are:
[0080] Step 1: encode the marked input information to obtain an encoding vector V;
[0081] Step 2: based on the encoding vector V, and through linear transformation, the encoding vector V is mapped to a word vector, wherein the number of dimensions of the word vector is consistent with the number of corresponding words in the word table, the value on each dimension of the word vector represents the weight of the word corresponding to the dimension being selected, then the word corresponding to the dimension with the maximum weight is selected as the target word, then the target word is encoded to obtain an encoding vector E, and then the encoding vector E and the encoding vector V are spliced and mapped to obtain a new encoding vector;
[0082] Step 3: replace the encoding vector V in step 1 with the obtained new encoding vector, and repeat the above steps until a terminal symbol is generated, and then determine the result text according to the target words determined in all rounds and the order of adjacent rounds.
[0083] The autoregressive process is as follows:
[0084] Step 1: encode the marked input information to obtain an encoding vector V;
[0085] Step 2: based on the encoding vector V, and through linear transformation, the encoding vector V is mapped to a word vector, wherein the number of dimensions of the word vector is consistent with the number of corresponding words in the word table, the value on each dimension of the word vector represents the weight of the word corresponding to the dimension being selected, then the word corresponding to the dimension with the maximum weight is selected as the target word, then the target word is encoded to obtain an encoding vector E, and then the encoding vector E and the encoding vector V are spliced and mapped to obtain a new encoding vector;
[0086] Step 3: replace the encoding vector V in step 1 with the obtained new encoding vector, and repeat the above steps until a terminal symbol is generated, and then determine the result text according to the target words determined in all rounds and the order of adjacent rounds.
[0087] Specific embodiment ten: a Text-to-SQL medium, the medium comprising a computer readable program, the computer readable program is used for executing the steps of any one of claims 1 to 7.
[0088] Those skilled in the art will appreciate that embodiments of the application can be readily used as a method, apparatus, or computer program product. Accordingly, the application can take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the application can take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROMs, optical storage devices, etc.) embodying computer readable program code thereon for use by or in connection with an instruction execution system. Program code embodied on one or more computer-usable storage media can be downloaded over a network
[0089] The present application is described in reference to the flowchart illustrations and / or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, embedded processing system or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart illustrations and / or block diagrams block or blocks. Figure 1 one or more functions specified in the flowchart illustrations and / or block diagrams block or blocks. Figure 1 one or more functions specified in the flowchart illustrations and / or block diagrams block or blocks.
[0090] These computer program instructions can also be stored in a computer- readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instructions which implement the flowchart illustrations and / or block diagrams block or blocks. Figure 1 one or more functions specified in the flowchart illustrations and / or block diagrams block or blocks. Figure 1 one or more functions specified in the flowchart illustrations and / or block diagrams block or blocks.
[0091] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the flowchart illustrations and / or block diagrams block or blocks. Figure 1 one or more functions specified in the flowchart illustrations and / or block diagrams block or blocks. Figure 1 one or more functions specified in the flowchart illustrations and / or block diagrams block or blocks.
[0092] While the preferred embodiments of the application have been described, additional variations and modifications can be made to these embodiments by those skilled in the art once they have the benefit of the present disclosure without departing from the spirit and scope of the application. Accordingly, it is intended that such additions and modifications be included within the scope of the application. It is the following claims, including any amendments thereto, which define the scope of the application.
[0093] Obviously, numerous modifications and variations of the present application are possible in light of the above teachings. It is therefore to be understood that within the scope of the appended claims and their equivalents, the application can be practiced otherwise than as specifically described.< / fk>
Claims
1. A Text-to-SQL method, characterized in that The method comprises the following steps: Step one: obtaining a Text-to-SQL question and a database structure, converting the Text-to-SQL question and the database structure into linear text, and splicing the linear text to obtain input information; Step two: searching for a column name in the input information, and labeling category information after the column name; Step three: encoding the input information after the category information is labeled to obtain an encoding vector V, and using autoregressive decoding based on the encoding vector V to obtain a result text; Step four: obtaining all words in the result text and the order of the words, and then judging whether a current word and a next word satisfy a SQL syntax relationship in sequence for each word in the result text, and if so, retaining the current word, Step five: splicing the words retained in step four into a target text, and comparing table names in the target text except a FROM keyword with table names in the FROM keyword, and based on a comparison result, supplementing missing table names in the FROM keyword; The specific steps of obtaining the result text by using autoregressive decoding based on the encoding vector V are as follows: In each round, a word with the largest weight is selected as a currently generated word through autoregressive decoding, and then the result text is obtained; The specific steps of obtaining the result text by using autoregressive decoding in each round are as follows: Step three one: based on the encoding vector V, the encoding vector V is mapped into a word vector through linear transformation, wherein the number of dimensions of the word vector is consistent with the number of corresponding words in a word table, and a value on each dimension of the word vector represents a weight of a word corresponding to the dimension, a word corresponding to a dimension with the largest weight is selected as a target word, the target word is encoded to obtain an encoding vector E, and then the encoding vector E and the encoding vector V are spliced and mapped to obtain a new encoding vector; Step three two: the new encoding vector is used to replace the encoding vector V in step three one, and the above steps are repeated until a terminal symbol is generated, and a result text is determined according to target words determined in all rounds and the order of adjacent rounds.
2. The Text-to-SQL method of claim 1, wherein, The encoding of the input information after the category information is labeled comprises the following steps: The input information after the category information is labeled is encoded by using a pre-training model, and the pre-training model is a BART algorithm model or a T5 algorithm model.
3. The Text-to-SQL method of claim 1, wherein, In step four, if the current word and the next word do not satisfy the SQL syntax relationship, all weights in the corresponding round of the current word are sorted, and the current word is replaced in sequence from a word corresponding to a second largest weight until the replaced word and the next word satisfy the SQL syntax relationship.
4. The Text-to-SQL method of claim 1, wherein, The category information comprises subsidiary relationship, foreign key relationship, table relationship, internal structure information, name linkage information, numerical value linkage information, and historical information.
5. The Text-to-SQL method of claim 4, wherein, The category information after the column name is marked, specifically: the dependent relationship after the column name is marked as BL, the foreign key relationship after the column name is marked as FK, the table relationship after the column name is marked as FT, the internal structure information after the column name is marked as TK, the name link information after the column name is marked as SL, the numerical link information after the column name is marked as EL, and the history information after the column name is marked as HI.
6. A Text-to-SQL system, characterized in that, Comprise: An input information acquisition module, a marking module, an encoding module, a syntax judgment module, and a completion module; The input information acquisition module is used to acquire a Text-to-SQL question and a database structure, and splice the Text-to-SQL question and the database structure after being converted into linear text to obtain input information; The marking module is used to find a column name in the input information, and mark category information after the column name; The encoding module is used to encode the input information after the category information is marked to obtain an encoding vector V, and obtain a result text by using autoregressive decoding based on the encoding vector V; The syntax judgment module is used to acquire all words and the order of the words in the result text, and then judge whether the current word and the next word satisfy the syntax relationship of SQL for each word in the result text in turn, and if yes, the current word is retained; The completion module is used to splice the retained words into a target text, and based on the target text, count the table names in the target text except the FROM keyword, compare the table names in the target text except the FROM keyword with the table names in the FROM keyword, and based on the comparison result, supplement the missing table names in the FROM keyword; The specific steps of obtaining the result text by using autoregressive decoding based on the encoding vector V are: In each round, the word with the largest weight is selected as the currently generated word by autoregressive decoding, and then the result text is obtained; The specific steps of obtaining the result text by autoregressive decoding and selecting the word with the largest weight as the currently generated word in each round are: Step three one: based on the encoding vector V, the encoding vector V is mapped into a word vector through linear transformation, wherein the number of dimensions of the word vector is consistent with the number of corresponding words in the word table, the numerical value on each dimension of the word vector represents the weight of the word corresponding to the dimension being selected, the word corresponding to the dimension with the largest weight is selected as the target word, the target word is encoded to obtain an encoding vector E, and then the encoding vector E and the encoding vector V are spliced and mapped to obtain a new encoding vector; Step three two: the new encoding vector replaces the encoding vector V in step three one, and the above steps are repeated until a terminal symbol is generated, and the result text is determined according to the target words determined in all rounds and the order of adjacent rounds.
7. A computer readable storage medium characterized by The medium comprises a computer readable program for executing the steps of any one of claims 1 to 5.
Citation Information
Patent Citations
SQL (Structured Query Language) conversion method and system based on language model coding and multi-task decoding
CN112988785A
Text-to-SQL generation method based on template retrieval
CN115203236A