Natural language query statement processing method and device, equipment and medium
The pipelined text generation model handles natural language query statements, which solves the problem of difficulty in training the NL2SQL model and low accuracy in statement generation, and realizes efficient and accurate SQL query statement generation.
Patent Information
- Application Number
- CN202411762859.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-03
- Publication Date
- 2025-04-25
AI Technical Summary
The existing NL2SQL model is difficult to train, and the accuracy of statement generation is not high.
By obtaining natural language query statements, determining their query type, matching the target column, and converting them into SQL query statements using the pipelined text generation model. The specific steps include inputting the natural language query statement and the target column into the first text generation model, obtaining the initial structured query statement, and then training the second text generation model of its input value, obtaining the target structured query statement.
The generation of structured query statements is simplified and the efficiency and accuracy of converting natural language query statements into SQL query statements is improved.
Smart Images

Figure CN119884164A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, device, equipment and medium for processing natural language query statements. Background Art
[0002] In real life, there are many databases that store information from all walks of life, such as school course selection information, grade information, company accounting information, and personnel turnover. Structured Query Language (SQL) is a database query language with great flexibility and powerful functions. For computer practitioners, it is also troublesome to write a large number of SQL statements with guaranteed accuracy for different databases and application scenarios.
[0003] Natural language to SQL (NL2SQL) is a technology that converts natural language query statements into SQL, allowing users to query data without having professional knowledge of databases, thereby lowering the threshold for using databases.
[0004] However, existing NL2SQL models often adopt an end-to-end structure. These models have complex structures, high requirements for training data, are difficult to build, have a large number of parameters, are difficult to train, and the accuracy of statement generation is difficult to meet application requirements. Summary of the invention
[0005] The embodiments of the present application provide a method, apparatus, device and medium for processing natural language query statements to solve the technical problems that the NL2SQL model is difficult to train and the accuracy of statement generation is low.
[0006] In a first aspect, an embodiment of the present application provides a method for processing a natural language query statement, the method comprising:
[0007] Obtaining a natural language query statement, where the natural language query statement is used to query data in a target table of a target database;
[0008] Determining a query type of the natural language query statement according to the difficulty of the natural language query statement;
[0009] Match the target columns of the query to natural language query statements of different query types;
[0010] Inputting the natural language query statement and the target column into a first text generation model to obtain an initial structured query statement, wherein the first text generation model is used to convert the natural language query statement into a corresponding structured query statement;
[0011] The initial structured query statement is input into a second text generation model trained with values to obtain a target structured query statement, and the second text generation model is used to fill in the values in the initial structured query statement.
[0012] Optionally, the matching of the target columns of the natural language query statements of different query types includes:
[0013] When the query type is a simple query, text matching is performed between the natural language query statement and each table in the target table;
[0014] The column with a score greater than a preset threshold is used as the target column.
[0015] Optionally, the matching of the target columns of the natural language query statements of different query types includes:
[0016] When the query type is a non-nested query, text matching is performed between the natural language query statement and each table in the target table;
[0017] The foreign key connected by the natural language query statement is used as the target column, and the connected foreign key is a column in other tables except the target table.
[0018] Optionally, the matching of the target columns of the natural language query statements of different query types includes:
[0019] When the query type is a nested query, text matching is performed between the query question and each table in the target table;
[0020] Use the foreign key connected by the natural language query statement as the relevant column;
[0021] The related columns are processed recursively to obtain the target column.
[0022] Optionally, the step of inputting the natural language query statement and the target column into a first text generation model to obtain an initial structured query statement includes:
[0023] Generate the initial structured query statement using predefined rules according to the first text generation model, wherein the predefined rules include a correspondence between a database schema structure and a generated query type; or
[0024] In the first text generation model, the encoder encodes the input natural language query statement into a vector of fixed length; the decoder in the first text generation model decodes the vector to obtain a structured query statement corresponding to the natural language query statement, and the second text generation model is trained using the teacher-student method.
[0025] Optionally, the method further comprises:
[0026] Encode sample questions using the trained text analysis model;
[0027] Use the fully connected layer to classify the sample database and sample table, and output the target database and target table.
[0028] Optionally, determining the type of the natural language query statement according to the difficulty of the natural language query statement includes:
[0029] According to the fields, grammatical structure and preset classification algorithm of the natural language query statement, the query type of the natural language query statement is classified into a simple query, a non-nested query or a nested query.
[0030] In a second aspect, an embodiment of the present application provides a natural language query statement processing device, the device comprising:
[0031] An acquisition module, used for acquiring a natural language query statement, wherein the natural language query statement is used for querying data in a target table of a target database;
[0032] A determination module, configured to determine a query type of the natural language query statement according to the difficulty of the natural language query statement;
[0033] A matching module, used to match the target columns of queries to natural language query statements of different query types;
[0034] A first model application module, configured to input the natural language query statement and the target column into a first text generation model to obtain an initial structured query statement, wherein the first text generation model is configured to convert the natural language query statement into a corresponding structured query statement;
[0035] The second model application module is used to input the initial structured query statement into a trained second text generation model to obtain a target structured query statement, and the second text generation model is used to fill in the values in the initial structured query statement.
[0036] In a third aspect, an embodiment of the present application provides an electronic device, comprising: a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned method for processing natural language query statements when executing the program.
[0037] In a fourth aspect, an embodiment of the present application provides a readable storage medium, which, when instructions in the readable storage medium are executed by a processor of an electronic device, enables the electronic device to execute the above-mentioned method for processing natural language query statements.
[0038] In summary, in the embodiment of the present application, firstly, a natural language query statement is obtained, and the natural language query statement is used to query data in the target table of the target database; secondly, the query type of the natural language query statement is determined according to the difficulty of the natural language query statement; thirdly, the target column of the query is matched for natural language query statements of different query types; then, the natural language query statement and the target column are input into the first text generation model to obtain an initial structured query statement, and the first text generation model is used to convert the natural language query statement into a corresponding structured query statement; finally, the initial structured query statement is input into the trained second text generation model to obtain a target structured query statement, and the second text generation model is used to fill in the value in the initial structured query statement. Through the above technical scheme, a pre-trained model is used in the process of converting the natural language query statement into an SQL query statement in an assembly line manner, which not only simplifies the generation of structured query statements, but also improves the efficiency and accuracy of converting natural language query statements into SQL query statements. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0040] Figure 1 It is a flowchart of a method for processing a natural language query statement provided in an embodiment of the present application;
[0041] Figure 2 It is a flowchart of the specific steps of a method for processing a natural language query statement provided in an embodiment of the present application;
[0042] Figure 3 is a flowchart of another method for processing natural language query statements provided by an embodiment of the present application;
[0043] Figure 4 It is a structural diagram of a natural language query statement processing device provided in an embodiment of the present application;
[0044] Figure 5 is a structural diagram of an electronic device provided in an embodiment of the present application;
[0045] Figure 6 It is a structural diagram of another electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0046] 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 part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0047] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0048] First, an application scenario involved in an embodiment of the present application is described.
[0049] SQL is a computer programming language for operating databases. It is used to store, read, query and modify data in relational databases. SQL language can be used to query data from the data tables contained in the database to obtain the required information.
[0050] Text-to-SQL (Text2SQL), as the name implies, converts text into SQL language, that is, converts natural language (NL) problems in the database field into SQL that can be executed in a relational database. Text-to-SQL is such a technology that converts natural language descriptions into SQL query statements. This technology can effectively assist technicians in querying massive databases and reduce the burden on developers.
[0051] Table question answering is a task that gives answers to natural language questions based on the content of the table. The task can be described as: input a table set T (containing one or more tables) and a question Q in natural language form, and output the correct answer A. The natural language query statement entered by the user and the data table to be queried are input into the deep learning model, and the model converts the natural language into SQL, queries the table to be queried and outputs the query results.
[0052] Exemplarily, the problem definition in the embodiment of the present application is: given a query question, a table name, and a column name, the model outputs the correct SQL statement, that is:
[0053] (Q, t, c) → R s
[0054] However, most current Text2SQL technologies use deep learning methods to map natural language to SQL templates, extract key information, form SQL, and complete database query tasks. In addition, existing Text-to-SQL models often adopt an end-to-end structure. These models have complex structures, high requirements for training data, are difficult to build, have a large number of parameters, are difficult to train, and the accuracy of sentence generation is difficult to meet application requirements.
[0055] In order to solve the above technical problems, the embodiment of the present application provides a method, device, equipment and medium for processing natural language query statements. First, a natural language query statement is obtained, and the natural language query statement is used to query data in a target table of a target database; secondly, the query type of the natural language query statement is determined according to the difficulty of the natural language query statement; thirdly, the target column of the query is matched for natural language query statements of different query types; then, the natural language query statement and the target column are input into a first text generation model to obtain an initial structured query statement, and the first text generation model is used to convert the natural language query statement into a corresponding structured query statement; finally, the initial structured query statement is input into a second text generation model trained with values to obtain a target structured query statement, and the second text generation model is used to fill in the values in the initial structured query statement. Through the above technical solution, a pre-trained model is used in the process of converting a natural language query statement into an SQL query statement in a pipeline manner, which not only simplifies the generation of structured query statements, but also improves the efficiency and accuracy of converting natural language query statements into SQL query statements.
[0056] The following is a detailed description of the method for processing natural language query statements provided in an embodiment of the present application.
[0057] Figure 1 is a flowchart of a method for processing a natural language query statement provided in an embodiment of the present application, see Figure 1 , the method for processing the natural language query statement may include:
[0058] Step 101: Obtain a natural language query statement.
[0059] In an embodiment of the present application, a natural language query statement is used to query data in a target table of a target database.
[0060] In some embodiments, step 101 may include: obtaining a natural language query sentence input by a user, wherein the natural language query sentence input by the user may be in voice form, text form, or any other natural language expression form, which is not specifically limited in this application.
[0061] Optionally, the natural language query statement includes a query command or a query question, for example, the natural language query statement is "query the profit of Company A in the first half of last year", and another natural language query statement is "which retail companies are there in YY community in XX city after 2013?".
[0062] Optionally, the natural language query statement is used to query data in a to-be-queried data table, wherein the to-be-queried data table may include one or more parent tables.
[0063] It should be noted that for a data table in a database, a column of a data table is called a field. A data table can be regarded as a set of fields. All true subsets of the field set are called sub-tables of this data table, and this data table is called the parent table to which these sub-tables belong. There is a corresponding relationship between the sub-table and the parent table, and a parent table can have one or more sub-tables. For example, if a data table A consists of M fields, then a data table B consisting of N fields selected from these M fields is called a sub-table of data table A, where M and N are positive integers greater than 1, and M is greater than N.
[0064] In one possible implementation, the data table to be queried may be input by a user, or the data table to be queried may be obtained by a computing device from a database, wherein the database may be stored locally on the computing device, or stored in a network server, or stored in a server cluster that provides cloud storage services, and this application does not make any specific limitations on this.
[0065] Step 102: Determine the query type of the natural language query statement according to the difficulty of the natural language query statement.
[0066] In the embodiment of the present application, the query types of the natural language query statements include simple queries, non-nested queries, and nested queries.
[0067] In some embodiments, step 102 may include: determining the query type of the natural language query statement according to the query fields, grammatical structure and a preset classification algorithm of the natural language query statement.
[0068] Optionally, determining the query type of a natural language query statement based on the query fields, grammatical structure and preset classification algorithm of the natural language query statement may also include: determining the number of query parent tables of the natural language query statement based on the query fields of the natural language query statement; determining whether the natural language query statement is a nested structure based on the grammatical structure of the natural language query statement; when the number of query parent tables of the natural language query statement is one, determining the query type of the natural language query statement as a simple query; when the number of query parent tables of the natural language query statement is multiple and the natural language query statement is a query of a non-nested structure, determining the query type of the natural language query statement as a non-nested query; when the number of query parent tables of the natural language query statement is multiple and the natural language query statement is a query of a nested structure, determining the query type of the natural language query statement as a nested query.
[0069] In a possible implementation, a classification symbol Token (CLS_Token) is used to represent the query type, and a fully connected layer is used to classify the natural language query statement.
[0070] Step 103: Match the target columns of the query to the natural language query statements of different query types.
[0071] In some embodiments, step 103 may include: using sequence tagging to match the target columns of queries to natural language query statements of different query types.
[0072] It should be noted that sequence labeling refers to labeling each element of a sequence, and each element is assigned a specific label. Generally speaking, a sequence refers to a sentence, and an element refers to a word in a sentence. The goal of the sequence labeling task is to determine the most appropriate label for each element in the sequence based on a given set of labels. Sequence labeling is a basic task in natural language processing. It has a wide range of applications in word segmentation, part-of-speech tagging, Chinese named entity recognition (NER) and relationship extraction. Among them, word segmentation is a basic task in Chinese natural language processing. By segmenting sentences, continuous text can be divided into independent words or phrases, providing a basis for subsequent tasks; part-of-speech tagging refers to labeling the grammatical attributes of each word in a sentence, such as nouns, verbs, adjectives, etc. Through part-of-speech tagging, the semantics of words can be more deeply understood; NER refers to identifying specific entities in the text, such as names of people, places, and organizations;; Relation extraction: Relation extraction refers to extracting the relationship between entities from the text, such as relationships between people and organizations.
[0073] Optionally, step 10 may also include: using a pre-trained NER model to match the target columns of the query to natural language query statements of different query types. In this way, the accuracy of the above natural language query statement processing method for related entity recognition in the NL2SQL field can be improved.
[0074] In a possible implementation, before step 103, the method for processing the above-mentioned natural language query statement may also include: using a pre-trained Robustly Optimized BERT (RoBERTa) model to encode the question, and then using a bidirectional long short-term memory (LSTM) model to sequence-label the question.
[0075] It should be noted that the RoBERTa model is an enhanced version of the BERT (Bidirectional Encoder Representation from Transformers) model, which improves pre-training performance by increasing the model size, using a larger batch size, more training data, dynamic masking, and improved text encoding. The next sentence prediction task is removed, a dynamic masking strategy is used, and a larger byte-level BPE vocabulary is adopted.
[0076] Step 104: input the natural language query statement and the target column into the first text generation model to obtain an initial structured query statement.
[0077] In an embodiment of the present application, the first text generation model is used to convert a natural language query statement into a corresponding structured query statement.
[0078] Optionally, the first text generation model may be a rule-based model or a sequence-to-sequence (Seq2Seq) model, wherein the rule-based model generates SQL query statements using predefined rules, while the Seq2Seq model generates SQL query statements using an encoder-decoder structure.
[0079] It should be noted that the Seq2Seq model is a neural network architecture that processes sequence data and is widely used in the field of natural language processing. It can convert one sequence into another sequence, and the lengths of the two sequences can be different, which makes the Seq2Seq model very suitable for tasks such as machine translation, text summarization, and dialogue systems. The Seq2Seq model usually consists of two parts: an encoder and a decoder. The encoder is responsible for reading the input sequence and converting it into a fixed-size internal state vector, which is considered to contain all the information of the input sequence. The decoder is responsible for converting this internal state vector into an output sequence.
[0080] Step 105: Input the initial structured query statement into the trained second text generation model to obtain a target structured query statement.
[0081] In the embodiment of the present application, the second text generation model is used to fill in the values in the initial structured query statement.
[0082] In some embodiments, the SQL statement outputted from step 104 is encoded using a pre-trained RoBERTa model, and a SQL query statement containing values is generated using a structured query statement to a structured query statement (SQL to SQL, sql2sql) method.
[0083] Exemplarily, during training, the value filling model is trained using a negative sampling method, where the decoder is provided with the correct output at each time step. During inference, the decoder labels the true generated values one by one, and uses a beam search algorithm to find the most likely label sequence. Among them, beam search is a restricted breadth-first search method that is often used in various natural language processing (NLP) generation tasks, such as machine translation, dialogue systems, and text summarization.
[0084] In summary, the method for processing natural language query statements in the embodiment of the present application is, first, to obtain natural language query statements, which are used to query data in the target table of the target database; secondly, to determine the query type of the natural language query statement according to the difficulty of the natural language query statement; thirdly, to match the target column of the query for natural language query statements of different query types; then, to input the natural language query statement and the target column into the first text generation model to obtain an initial structured query statement, and the first text generation model is used to convert the natural language query statement into a corresponding structured query statement; finally, to input the initial structured query statement into the trained second text generation model to obtain the target structured query statement, and the second text generation model is used to fill in the value in the initial structured query statement. Through the above technical scheme, a pre-trained model is used in the process of converting natural language query statements into SQL query statements in an assembly line manner, which not only simplifies the generation of structured query statements, but also improves the efficiency and accuracy of converting natural language query statements into SQL query statements.
[0085] Figure 2 is a flowchart of the specific steps of another method for processing natural language query statements provided by an embodiment of the present application, such as Figure 2 As shown, the method may include:
[0086] Step 201: Encode sample questions using the trained text analysis model.
[0087] In some embodiments, step 201 may include: encoding a sample question pair using a pre-trained RoBERTa model.
[0088] Step 202: Use the fully connected layer to classify the sample database and sample table, and output the target database and target table.
[0089] It can be understood that the purpose of this step is to determine the query table.
[0090] In a possible implementation, outputting the target database and the target table may include: outputting a to-be-queried data table and one or more parent tables included in the to-be-queried data table.
[0091] Step 203: Obtain a natural language query statement.
[0092] The method of this step has been described in the aforementioned step 101 and will not be repeated here.
[0093] Step 204: Classify the query type of the natural language query statement into a simple query, a non-nested query or a nested query according to the fields, the grammatical structure and the preset classification algorithm of the natural language query statement.
[0094] Optionally, step 204 may include:
[0095] Sub-step 2041: determining the number of query parent tables of the natural language query statement according to the query fields of the natural language query statement;
[0096] Sub-step 2042: determining whether the natural language query statement is a nested structure according to the grammatical structure of the natural language query statement;
[0097] Sub-step 2043: when the number of query parent tables of the natural language query statement is one, determining the query type of the natural language query statement as a simple query;
[0098] Sub-step 2044: when the number of query parent tables of the natural language query statement is multiple and the natural language query statement is a query of a non-nested structure, determining the query type of the natural language query statement as a non-nested query;
[0099] Sub-step 2045: When the number of query parent tables of the natural language query statement is multiple and the natural language query statement is a query of a nested structure, determine the query type of the natural language query statement as a nested query.
[0100] Step 205: Match the target columns of the query to the natural language query statements of different query types.
[0101] The method of this step has been described in the aforementioned step 103 and will not be repeated here.
[0102] In some embodiments, when the query type is a simple query, step 203 may include:
[0103] Sub-step A1: text matching the natural language query statement with each table in the target table;
[0104] Sub-step A2: taking the column whose score is greater than a preset threshold as the target column.
[0105] Exemplarily, sub-step A1 may include: performing text matching on the query question corresponding to the natural language query statement and each parent table in the target table to obtain the score of each child table in each parent table; correspondingly, sub-step A2 may include: taking the child table with a score greater than a preset threshold as the target column.
[0106] In the embodiment of the present application, the preset threshold can be set according to actual needs.
[0107] In some embodiments, when the query type is a non-nested query, step 203 may include:
[0108] Sub-step B1, performing text matching between the natural language query statement and each table in the target table;
[0109] Sub-step B2: Use the foreign key connected by the natural language query statement as the target column.
[0110] In the embodiment of the present application, the foreign key of the connection is a column in a table other than the target table.
[0111] It should be noted that a foreign key is a constraint used to ensure referential integrity between data tables. A foreign key is a combination of one or more fields whose values are based on the primary key of another table. By using foreign key constraints, you can ensure that the data referenced in the child table actually exists in the parent table, thereby maintaining data consistency and accuracy. The role of foreign keys includes maintaining referential integrity, establishing associations, and preventing data inconsistencies. Foreign keys also support cascading delete and update operations to ensure that records in the parent table exist in the child table. Foreign keys are also called foreign keywords.
[0112] Exemplarily, sub-step B2 may include: determining the foreign key of the query connection and outputting the related columns involved, and using the related columns as target columns.
[0113] In some embodiments, when the query type is a nested query, step 203 may include:
[0114] Sub-step S1, performing text matching between the query question and each table in the target table;
[0115] Sub-step S2: taking the foreign key connected by the natural language query statement as a related column;
[0116] Sub-step S3: recursively process the relevant columns to obtain the target column.
[0117] It is understandable that the basic idea of recursion is that a function calls itself. Recursion contains three elements: clarifying the function, determining the end condition, and finding an equivalent relation. Problems that are suitable for recursion usually have recursive relations or recursive data structures. When using recursion, pay attention to optimizations such as tail recursion and memoization.
[0118] Step 206: Input the natural language query statement and the target column into the first text generation model to obtain an initial structured query statement.
[0119] In an embodiment of the present application, the first text generation model is used to convert a natural language query statement into a corresponding structured query statement.
[0120] The method of this step has been described in the aforementioned step 104 and will not be repeated here.
[0121] Optionally, step 206 may include:
[0122] Step 2061: Generate an initial structured query statement using predefined rules according to the first text generation model.
[0123] In an embodiment of the present application, the predefined rules include a correspondence between the structure of the database schema and the generated query type.
[0124] In one possible implementation, the rule-based model generates SQL queries based on predefined rules that are designed based on the structure of the database schema and the types of queries that can be generated. For example, if the input text contains a question about the maximum value of a column, the rule-based model will generate a SQL query containing the MAX() function.
[0125] Optionally, step 206 may include:
[0126] Step 2062: The encoder in the first text generation model encodes the input natural language query statement into a vector of fixed length; the decoder in the first text generation model decodes the vector to obtain a structured query statement corresponding to the natural language query statement.
[0127] In an embodiment of the present application, the second text generation model is trained using a teacher-student method.
[0128] In one possible implementation, the Seq2Seq model generates SQL queries using an encoder-decoder structure. The encoder encodes the input text into a fixed-length vector, which is then decoded by the decoder to generate a SQL query. Both the encoder and decoder are implemented using LSTM networks. During training, the Seq2Seq model is trained using a teacher-student approach, where the decoder is fed the correct output at each time step. During inference, the decoder generates SQL queries token by token, using a beam search algorithm to find the most likely sequence of tokens.
[0129] Among them, step 2061 and step 2062 are in an "or" relationship.
[0130] Step 207: Input the initial structured query statement into the trained second text generation model to obtain a target structured query statement.
[0131] In the embodiment of the present application, the second text generation model is used to fill in the values in the initial structured query statement.
[0132] The method of this step has been described in the aforementioned step 105 and will not be repeated here.
[0133] To sum up, in the embodiments of the present application, a pipeline approach is adopted to use a pre-trained model in the process of converting natural language query statements into SQL query statements, which not only simplifies the generation of structured query statements, but also improves the efficiency and accuracy of converting natural language query statements into SQL query statements.
[0134] Figure 3 is a flowchart of another method for processing natural language query statements provided by this application, see Figure 3 , the method may include the following steps:
[0135] Step 301: Select a database and table.
[0136] Step 302: Select a query type.
[0137] The query types include simple statements, nested complex statements, and non-nested complex statements.
[0138] Step 303: Select a column.
[0139] Step 304: Generate a structured query statement.
[0140] Step 305: Fill in values for the structured query statement.
[0141] In summary, the method in the embodiment of the present application has the advantages of high accuracy and the ability to process complex query statements compared to the existing end-to-end method.
[0142] Figure 4 is a schematic diagram of the structure of a natural language query statement processing device provided in an embodiment of the present application. The natural language query statement processing device 30 may include:
[0143] An acquisition module 31 is used to acquire a natural language query statement, where the natural language query statement is used to query data in a target table of a target database;
[0144] A determination module 32, configured to determine a query type of the natural language query statement according to the difficulty of the natural language query statement;
[0145] A matching module 33, used for matching the target columns of queries to natural language query statements of different query types;
[0146] A first model application module 34, used to input the natural language query statement and the target column into a first text generation model to obtain an initial structured query statement, and the first text generation model is used to convert the natural language query statement into a corresponding structured query statement;
[0147] The second model application module 35 is used to input the initial structured query statement into the trained second text generation model to obtain a target structured query statement. The second text generation model is used to fill in the values in the initial structured query statement.
[0148] Optionally, the matching module 33 includes:
[0149] A first matching submodule, for performing text matching between a natural language query statement and each table in a target table when the query type is a simple query;
[0150] The first determination submodule is used to take a column with a score greater than a preset threshold as a target column.
[0151] Optionally, the matching module 33 includes:
[0152] A second matching submodule is used for performing text matching between the natural language query statement and each table in the target table when the query type is a non-nested query;
[0153] The second determination submodule is used to use the foreign key connected by the natural language query statement as the target column, and the connected foreign key is a column in other tables except the target table.
[0154] Optionally, the matching module 33 includes:
[0155] The third matching submodule is used for performing text matching between the query question and each table in the target table when the query type is a nested query;
[0156] A third determination submodule is used to use the foreign key connected by the natural language query statement as a related column;
[0157] The recursive processing submodule is used to recursively process the relevant columns to obtain the target column.
[0158] Optionally, the first model application module 34 includes:
[0159] A first model application submodule is used to generate an initial structured query statement using predefined rules according to the first text generation model, wherein the predefined rules include a correspondence between a database schema structure and a generated query type; or
[0160] The second model application submodule is used for the encoder in the first text generation model to encode the input natural language query statement into a vector of fixed length; the decoder in the first text generation model decodes the vector to obtain a structured query statement corresponding to the natural language query statement. The second text generation model is trained using the teacher-student method.
[0161] Optionally, the natural language query statement processing device 30 further includes:
[0162] The encoding module is used to encode sample questions using the trained text analysis model;
[0163] The classification module is used to classify the sample database and sample table using the fully connected layer, and output the target database and target table.
[0164] Optionally, the determination module 32 includes:
[0165] The classification submodule is used to classify the query type of the natural language query statement into simple query, non-nested query or nested query according to the fields, grammatical structure and preset classification algorithm of the natural language query statement.
[0166] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0167] See also Figure 5 , the electronic device 400 may include one or more of the following components: a processing component 402 , a memory 404 , a power component 406 , a multimedia component 408 , an audio component 410 , an input / output (I / O) interface 412 , a sensor component 414 , and a communication component 416 .
[0168] The processing component 402 generally controls the overall operation of the electronic device 400, such as operations associated with display, phone calls, data communications, camera operations, and recording operations. The processing component 402 may include one or more processors 420 to execute instructions to complete all or part of the steps of the above-mentioned method. In addition, the processing component 402 may include one or more modules to facilitate the interaction between the processing component 402 and other components. For example, the processing component 402 may include a multimedia module to facilitate the interaction between the multimedia component 408 and the processing component 402.
[0169] The memory 404 is used to store various types of data to support the operation of the electronic device 400. Examples of such data include instructions for any application or method operating on the electronic device 400, contact data, phone book data, messages, pictures, multimedia, etc. The memory 404 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0170] The power supply component 406 provides power to the various components of the electronic device 400. The power supply component 406 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device 400.
[0171] The multimedia component 408 includes an interface that provides an output interface between the electronic device 400 and the user. In some embodiments, the interface may include a liquid crystal display (LCD) and a touch panel (TP). If the interface includes a touch panel, the interface may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touch, slide, and gestures on the touch panel. The touch sensor may not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 408 includes a front camera and / or a rear camera. When the electronic device 400 is in an operating mode, such as a shooting mode or a multimedia mode, the front camera and / or the rear camera may receive external multimedia data. Each front camera and rear camera may be a fixed optical lens system or have a focal length and optical zoom capability.
[0172] The audio component 410 is used to output and / or input audio signals. For example, the audio component 410 includes a microphone (MIC), and when the electronic device 400 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode, the microphone is used to receive an external audio signal. The received audio signal can be further stored in the memory 404 or sent via the communication component 416. In some embodiments, the audio component 410 also includes a speaker for outputting audio signals.
[0173] The input / output I / O interface 412 provides an interface between the processing component 402 and the peripheral interface module, which may be a keyboard, a click wheel, buttons, etc. These buttons may include but are not limited to: a home button, a volume button, a start button, and a lock button.
[0174] The sensor assembly 414 includes one or more sensors for providing various aspects of status assessment for the electronic device 400. For example, the sensor assembly 414 can detect the open / closed state of the electronic device 400, the relative positioning of components, such as the display and keypad of the electronic device 400, and the sensor assembly 414 can also detect the position change of the electronic device 400 or a component of the electronic device 400, the presence or absence of user contact with the electronic device 400, the orientation or acceleration / deceleration of the electronic device 400, and the temperature change of the electronic device 400. The sensor assembly 414 may include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 414 may also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 414 may also include an accelerometer, a gyroscope sensor, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0175] The communication component 416 is used to facilitate wired or wireless communication between the electronic device 400 and other devices. The electronic device 400 can access a wireless network based on a communication standard, such as WiFi, a carrier network (such as 2G, 3G, 4G or 5G), or a combination thereof. In an exemplary embodiment, the communication component 416 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 416 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0176] In an exemplary embodiment, the electronic device 400 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors or other electronic components to implement a method for processing a natural language query statement provided in an embodiment of the present application.
[0177] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 404 including instructions, and the instructions can be executed by a processor 420 of an electronic device 400 to perform the above method. For example, the non-transitory storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0178] Figure 6is a block diagram of an electronic device 500 according to another embodiment of the present invention. For example, the electronic device 500 may be provided as a server. Figure 6 The electronic device 500 includes a processing component 522, which further includes one or more processors, and a memory resource represented by a memory 532 for storing instructions executable by the processing component 522, such as an application. The application stored in the memory 532 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 522 is configured to execute instructions to execute a method for processing a natural language query statement provided in an embodiment of the present application.
[0179] The electronic device 500 may also include a power supply component 526 configured to perform power management of the electronic device 500, a wired or wireless network interface 550 configured to connect the electronic device 500 to a network, and an input / output (I / O) interface 558. The electronic device 500 may operate based on an operating system stored in the memory 532, such as Windows Server TM, Mac OS X TM, Unix TM, Linux TM, Free BSD TM or the like.
[0180] In an embodiment of the present application, the memory 632 may be used to store software programs and various data. The memory 632 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, an application program or instructions required for at least one function (such as a sound playback function, an image playback function, etc.), etc. In addition, the memory 632 may include a volatile memory or a non-volatile memory, or the memory 632 may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDRSDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synchronous link dynamic random access memory (SLDRAM) and a direct memory bus random access memory (DRRAM). The memory 632 in the embodiment of the present application includes but is not limited to these and any other suitable types of memory.
[0181] The processor may include one or more processing units; optionally, the processor integrates an application processor and a modem processor, wherein the application processor mainly processes operations related to the operating system, user interface, and application programs, and the modem processor mainly processes wireless communication signals, such as a baseband processor. It is understandable that the modem processor may not be integrated into the processor.
[0182] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, each process of the above-mentioned image super-resolution reconstruction method embodiment is implemented, and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0183] The processor is the processor in the electronic device described in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.
[0184] An embodiment of the present application also provides a computer program product, which is stored in a storage medium. The program product is executed by at least one processor to implement the various processes of the super-resolution reconstruction method embodiment of the above-mentioned image, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0185] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the application disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present disclosure. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0186] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A method for processing natural language query statements, characterized in that: The method comprises: Obtaining a natural language query statement, where the natural language query statement is used to query data in a target table of a target database; Determining a query type of the natural language query statement according to the difficulty of the natural language query statement; Match the target columns of the query to natural language query statements of different query types; Inputting the natural language query statement and the target column into a first text generation model to obtain an initial structured query statement, wherein the first text generation model is used to convert the natural language query statement into a corresponding structured query statement; The initial structured query statement is input into a second text generation model trained with values to obtain a target structured query statement, and the second text generation model is used to fill in the values in the initial structured query statement.
2. The method according to claim 1, characterized in that The target columns for matching natural language query statements of different query types include: When the query type is a simple query, text matching is performed between the natural language query statement and each table in the target table; The column with a score greater than a preset threshold is used as the target column.
3. The method according to claim 1, characterized in that The target columns for matching natural language query statements of different query types include: When the query type is a non-nested query, text matching is performed between the natural language query statement and each table in the target table; The foreign key connected by the natural language query statement is used as the target column, and the connected foreign key is a column in other tables except the target table.
4. The method according to claim 1, characterized in that: The target columns for matching natural language query statements of different query types include: When the query type is a nested query, text matching is performed between the query question and each table in the target table; Use the foreign key connected by the natural language query statement as the relevant column; The related columns are processed recursively to obtain the target column.
5. The method according to claim 1, characterized in that The step of inputting the natural language query statement and the target column into a first text generation model to obtain an initial structured query statement includes: Generate the initial structured query statement using predefined rules according to the first text generation model, wherein the predefined rules include a correspondence between a database schema structure and a generated query type; or In the first text generation model, the encoder encodes the input natural language query statement into a vector of fixed length; the decoder in the first text generation model decodes the vector to obtain a structured query statement corresponding to the natural language query statement, and the second text generation model is trained using the teacher-student method.
6. The method according to claim 1, characterized in that The method further comprises: Encode sample questions using the trained text analysis model; Use the fully connected layer to classify the sample database and sample table, and output the target database and target table.
7. The method according to claim 1, characterized in that The determining the type of the natural language query statement according to the difficulty of the natural language query statement includes: According to the fields, grammatical structure and preset classification algorithm of the natural language query statement, the query type of the natural language query statement is classified into a simple query, a non-nested query or a nested query.
8. A natural language query statement processing device, characterized in that: The device comprises: An acquisition module, used for acquiring a natural language query statement, wherein the natural language query statement is used for querying data in a target table of a target database; A determination module, configured to determine a query type of the natural language query statement according to the difficulty of the natural language query statement; A matching module, used to match the target columns of queries to natural language query statements of different query types; A first model application module, configured to input the natural language query statement and the target column into a first text generation model to obtain an initial structured query statement, wherein the first text generation model is configured to convert the natural language query statement into a corresponding structured query statement; The second model application module is used to input the initial structured query statement into a trained second text generation model to obtain a target structured query statement, and the second text generation model is used to fill in the values in the initial structured query statement.
9. An electronic device, characterized in that: include: A processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method according to any one of claims 1 to 7 when executing the program.
10. A readable storage medium, characterized in that: When the instructions in the readable storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute any one of the methods described in claims 1 to 7.