Natural language conversion method and device and computer equipment
By obtaining database structure information and extracting natural language condition information, generating structured input information and converting it into database statements, the conversion problem of Text2SQL technology in Chinese scenarios is solved, and efficient and accurate database query is achieved.
Patent Information
- Application Number
- CN202311867334.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-29
- Publication Date
- 2025-07-08
AI Technical Summary
In the Chinese scenario, the existing Text2SQL technology is difficult to understand the semantic expression of table names and column names in the database, resulting in failure of natural language conversion, especially in the case of using code items to represent values, which is difficult to accurately convert into SQL statements.
By obtaining the structure information of the database, extracting the conditional information in the user's natural language query statement, and generating structured input information, and finally converting it into a statement that is recognizable to the database, and semantic analysis and prediction are used for use of the BERT model.
It improves the conversion efficiency and accuracy of natural language to structured language, ensures the accuracy of database query results, and is suitable for database queries in English and Chinese scenarios.
Smart Images

Figure CN120277089A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application belong to the technical field of semantic recognition, and particularly relate to a natural language conversion method, device, and computer device. Background Art
[0002] Text2SQL is a technology that converts a user's natural language into executable SQL statements. By applying Text2SQL, it is convenient for the operating object to better understand the true thoughts contained in the user's natural language and execute accordingly. Exemplarily, for a database, a user can use natural language to express the idea of querying certain information in the database. By converting the user's natural language into SQL statements that the database can recognize, the database can find the corresponding information and feedback it to the user.
[0003] The development of deep learning technology has also promoted the development of Text2SQL technology, and Text2SQL technology has achieved good results in multiple fields and various scenarios. However, for Text2SQL in the Chinese scenario, there are many problems in the implementation process. For example, due to the database naming convention, it is easy to cause the table names and column names in the database to lose their true semantic expressions, making it difficult for the language model to understand the relationship between the natural language input by the user and the actual tables and columns in the database, resulting in the failure of natural language conversion. Another example is that in the database, some data is represented by code items for specific values. For example, in the database, the number 1 may represent male and the number 0 may represent female; or, the letter M represents male and the letter F represents female. Facing such data, it is difficult to accurately convert the natural language input by the user into the correct SQL statements that can reflect the true situation of the data by applying Text2SQL. Summary of the Invention
[0004] In view of this, the embodiments of the present application provide a natural language conversion method, device, and computer device, which can solve the problems existing in the prior art and efficiently and accurately convert the natural language input by the user into statements that the database can recognize.
[0005] The first aspect of the embodiments of the present application provides a natural language conversion method, including:
[0006] Obtain the structure information of the database, where the structure information is information that describes the data stored in the database in a structured language;
[0007] When receiving a query statement input by the user in natural language, extract the condition information included in the query statement;
[0008] Generate structured input information according to the structure information and the condition information;
[0009] Convert the structured input information into database statements recognizable by the database.
[0010] A second aspect of the embodiments of the present application provides a natural language conversion device, including:
[0011] An acquisition module, configured to acquire the structure information of the database, where the structure information is information describing the data stored in the database in a structured language;
[0012] An extraction module, configured to extract the condition information included in the query statement when receiving a query statement input by a user in natural language;
[0013] A generation module, configured to generate structured input information according to the structure information and the condition information;
[0014] A conversion module, configured to convert the structured input information into database statements recognizable by the database.
[0015] A third aspect of the embodiments of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the natural language conversion method described in the first aspect above is implemented.
[0016] A fourth aspect of the embodiments of the present application provides a computer-readable storage medium storing a computer program, and when the computer program is executed by a processor, the natural language conversion method described in the first aspect above is implemented.
[0017] A fifth aspect of the embodiments of the present application provides a computer program product, and when the computer program product runs on a computer, the computer is caused to execute the natural language conversion method described in the first aspect above.
[0018] Compared with the prior art, the embodiments of the present application have the following beneficial effects:
[0019] In the embodiments of the present application, after obtaining database structure information that describes the data stored in a database in a structured language, a computer device can, when receiving a query statement input by a user in natural language, extract the condition information included in the query statement, and then generate structured input information according to the database structure information and the condition information in the query statement. Since the structured input information is information that describes the user's query purpose in a structured language, the computer device can quickly convert the structured input information into a database statement recognizable by the database, improving the efficiency and accuracy of the conversion from natural language to structured language. On this basis, by applying the converted database statement to database queries, it also helps to quickly obtain accurate query results. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings in the following description are only some embodiments of the present application, and those of ordinary skill in the art can obtain other drawings based on these drawings without creative efforts.
[0021] Figure 1 is a schematic diagram of a natural language conversion method provided by an embodiment of the present application;
[0022] Figure 2 is a schematic diagram of another natural language conversion method provided by an embodiment of the present application;
[0023] Figure 3 is a schematic diagram of a method for extracting condition information provided by an embodiment of the present application;
[0024] Figure 4 is a schematic diagram of a natural language conversion process provided by an embodiment of the present application;
[0025] Figure 5 is a schematic diagram of a natural language conversion device provided by an embodiment of the present application;
[0026] Figure 6 is a schematic diagram of a computer device provided by an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0027] In the following description, specific details such as specific system structures and technologies are presented for the purpose of illustration rather than limitation, so as to thoroughly understand the embodiments of the present application. However, those skilled in the art should clearly understand that the present application can also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid unnecessary details from interfering with the description of the present application.
[0028] Generally, applying the Text2SQL technology can convert the user's natural language into executable SQL statements. However, in the Chinese scenario, it is difficult to obtain ideal results by directly applying the existing Text2SQL technology. The main problems include:
[0029] 1. Due to the naming conventions of databases, a large number of databases are named in English, or named with Chinese initials, etc. This results in the table names and column names in the database losing their semantic expressions directly, and it is impossible to determine the data stored in the database directly through the table names or column names. As a result, it is difficult for the language model to understand the specific relationship between the input natural language and the tables and columns in the database, and it is impossible to convert the input natural language based on the table names and column names in the database.
[0030] 2. In the actual usage process, users may ask questions about the specific values of certain columns in the database or data table. If the language model has not been trained to obtain the relationship between the questions and the data, it is difficult to determine the correct columns to be queried from the input natural language. Exemplarily, in the question about gender, if the user asks "How many men are there", if the language model has not learned the knowledge that there is a relationship between men and gender during the pre-training process, it is difficult for the language model to accurately associate the input natural language with the corresponding column, and it is also likely to lead to the failure of subsequent queries.
[0031] 3. In the actually used databases, there are usually cases where specific values are represented by code items. Taking gender as an example again, in the database, it may be that the number 1 represents male and the number 0 represents female, or the letter M represents male and the letter F represents female. If only considering the input natural language and the structure of the database, it is very difficult to convert the natural language into the correct SQL statements representing the value situation with code items.
[0032] Therefore, in view of the above problems, the embodiments of the present application provide a natural language conversion method. By applying this method, by extracting the conditional information contained in the natural language and on the basis of combining the structural information of the database, structured input information can be generated. Then, converting the above-structured input information into a language recognizable by the database can obtain a database statement that accurately expresses the true meaning of the user's natural language. This method can efficiently and accurately convert the natural language input by the user into a statement recognizable by the database, and is applicable not only to the database query process in the English scenario, but also to the database query process in the Chinese scenario.
[0033] The technical solution of the present application will be described below through specific embodiments.
[0034] Refer to Figure 1, showing a schematic diagram of a natural language conversion method provided by an embodiment of the present application, which may specifically include the following steps:
[0035] S101. Obtain the structure information of the database, where the structure information is information that describes the data stored in the database in a structured language.
[0036] This method can be applied to a computer device, that is, the execution subject of the embodiment of the present application is a computer device. By executing each step in the natural language conversion method provided by the embodiment of the present application, the computer device can convert the user's natural language into a language that can be recognized by the operating object. For example, convert natural language into SQL language. SQL language is a structured query language applied to databases. Using SQL language, data can be quickly queried in the database to obtain corresponding data records.
[0037] In a possible implementation manner of the embodiment of the present application, the computer device may be an electronic device such as a mobile phone, a tablet computer, or a desktop computer. The computer device can be communicatively connected to the database, and the user can obtain the data they want to query from the database by interacting with the computer device. That is, the computer device can provide an interaction interface for interacting with the user. For example, the interaction operation can be an operation of inputting a query statement in the form of natural language. The interaction operation of the user on the interaction interface can be received and processed by the computer device, and the processed interaction operation can be transmitted to the database, and the database executes the operation corresponding to the interaction operation. For example, the database queries a certain type of data and returns the corresponding query result. The query result can be displayed to the user through the interaction interface of the computer device.
[0038] To achieve this purpose, the computer device can obtain the structure information of the database, and the structure information can be information that describes the data stored in the database in a structured language.
[0039] Exemplarily, the database stores the basic information of students in each grade, including the age, gender, grade of each student, etc. The structure information of the database obtained by describing these basic information in a structured language can be expressed as:
[0040] Table_name|age: age, gender: gender ({1: male, 0: female}), column3: grade ([‘first grade’, ’second grade’, ’third grade’, ’fourth grade’, ’fifth grade’, ’sixth grade’])
[0041] In the above example, Table_name can represent the name of a data table, and information such as the age, gender, and grade of students is recorded in this data table. Among them, the gender field in the data table uses the numbers 1 and 0 to distinguish between male and female, and the grades of all students include the first grade to the sixth grade.
[0042] In a possible implementation manner of the embodiments of the present application, the structure information of the database can be obtained by reading the field names and the stored data of each field in each data table in the database and then processing them. Alternatively, the structure information of the database can also be obtained by acquiring the description information of the database and analyzing the description information. The embodiments of the present application do not limit this. The above description information can be information that provides a general introduction to the data stored in the database.
[0043] S102. When receiving a query statement input by a user in natural language, extract the condition information included in the query statement.
[0044] In the embodiments of the present application, the query statement input by the user in natural language can be a statement input by the user when interacting with a computer device and hoping to query the database. Among them, the query statement can be a statement in text form or a statement in voice form.
[0045] Exemplarily, when the user interacts with the computer device, if the user hopes to query a certain type of data in the database, the user can directly enter the corresponding text in the interaction interface. For example, the user can enter the text "How many boys are there in total". Or, if the computer device is an electronic device with voice interaction function, the user can interact with the computer device by voice and speak out the corresponding query statement. For example, the user can say the sentence "How many boys are there in total", and the computer device can receive the corresponding voice information and convert the above voice information into text form through the voice-to-text function. Through any one of the above two interaction methods, the computer can obtain the query statement input by the user in natural language, that is, the query statement "How many boys are there in total" in the above example.
[0046] When receiving a query statement input by a user in natural language, the computer device can extract the condition information included in the query statement, and the condition information can be information representing the main features of the data to be queried.
[0047] In a possible implementation manner of the embodiments of the present application, the computer device can perform semantic analysis on the query statement to identify the potential conditions included in the query statement.
[0048] Alternatively, the computer device can also combine the structural information of the database and determine the potential conditions included in the query statement by matching the query statement with the structural information. The embodiments of the present application do not limit this. Exemplarily, for the above query statement "How many boys are there in total", by matching this query statement with the structural information in the foregoing example, it can be found that "boys" in the query statement matches "male" in the structural information, and "male" in the database is a specific value under the field "gender". Therefore, it can be considered that the conditional information in the query statement is to query students with the gender of male. That is, the conditional information can be expressed as: gender = 1.
[0049] S103. Generate structured input information according to the structural information and the conditional information.
[0050] In the embodiments of the present application, the structured input information can be an input information represented in a structured language. This input information is obtained after processing the query statement input by the user in natural language and can be recognized according to a certain data structure.
[0051] In a possible implementation manner of the embodiments of the present application, the structural information of the database and the conditional information in the query statement can be processed to generate structured input information. Exemplarily, since the structural information of the database is an information that describes the data stored in the database in a structured language, it is itself a kind of structured information. Therefore, based on the structural information of the database, content that can represent the corresponding conditional information in the query statement can be added to this structural information to generate structured input information. For example, the conditional information in the query statement can be added to the structural information of the database, or alternatively, the content representing the data with this type of condition in the structural information can be replaced with the conditional information in the query statement to obtain the structured input information.
[0052] In the foregoing example, the data content in the structural information of the database that represents the condition of having gender is the part {1: male, 0: female}. Therefore, after replacing it with the conditional information in the query statement, the obtained structured input information is:
[0053] Table_name|age: age, gender: gender (gender = 1), column3: grade ([‘first grade’, ’second grade’, ’third grade’, ’fourth grade’, ’fifth grade’, ’sixth grade’])
[0054] It should be noted that the above representation is only an example of a possible form of the structured input information. In actual applications, it can be processed according to actual needs. For example, irrelevant information can be deleted to avoid the influence of irrelevant information on subsequent recognition; the original query statement can also be spliced into the structured input information to establish the association relationship between the original query statement and the finally generated structured input information. The embodiments of the present application do not limit this.
[0055] S104. Convert the structured input information into a database statement recognizable by the database.
[0056] In the embodiments of the present application, since the structured input information is information with a certain structure obtained by processing the query statement input by the user, the Text2SQL technology can be applied to convert the structured input information into a database statement recognizable by the database, such as an SQL statement.
[0057] In the embodiments of the present application, after obtaining the database structure information that describes the data stored in the database in a structured language, when the computer device receives a query statement input by the user in natural language, it can extract the condition information included in the query statement, and then generate structured input information according to the database structure information and the condition information in the query statement. Since this structured input information is information that describes the user's query purpose in a structured language, the computer device can quickly convert the structured input information into a database statement recognizable by the database, improving the efficiency and accuracy of the conversion from natural language to structured language. On this basis, by applying the converted database statement to database queries, it also helps to quickly obtain accurate query results.
[0058] Refer to Figure 2 , which shows a schematic diagram of another natural language conversion method provided by the embodiments of the present application, and specifically may include the following steps:
[0059] S201. Obtain the table structure description information of multiple data tables stored in the database.
[0060] Generally, the database may include multiple data tables. Different data may be stored in each data table, and the table structure description information may also be included in each data table.
[0061] The table structure description information may refer to the information that generally describes the data stored in the data tables in the database. In a possible implementation manner of the embodiments of the present application, the table structure description information may exist independently. Exemplarily, the table structure description information may include the data table name, the column names of each column of data included in the data table, and the value range of each column of data, etc. Each data table may have a copy of the table structure description information respectively; or, multiple data tables may share a copy of the table structure description information. When storing data into the data table, the table structure description information can be updated synchronously.
[0062] In another possible implementation manner of the embodiments of the present application, the table structure description information may also be a kind of information that needs to be obtained through real-time analysis of the data stored in the data table. Therefore, when obtaining the table structure description information, the computer device can read the column names of each column of data in each data table and determine the data values corresponding to the column names. The above column names and their corresponding data values together constitute the table structure description information of each data table.
[0063] S202. Generate the structure information of the database according to the table structure description information of each data table, where the structure information is the information that describes the data stored in the database in a structured language.
[0064] The purpose of obtaining the table structure description information of each data table is to generate the database structure information that describes the data stored in the database in a structured language.
[0065] Therefore, after obtaining the table structure description information, according to the table structure description information of each data table, the attribute information of each column of data in each data table can be determined. The attribute information may be the information indicating the specific meaning of the data stored in this column. For example, age, gender, grade, etc. Then, the computer device can determine the attribute values of each column of data corresponding to each attribute information. According to the attribute information and its corresponding attribute values of multiple columns of data in each data table, the structure information of the database is generated. The above determination of the attribute values of each column of data corresponding to each attribute information is to determine the specific data stored in each column. For example, what ages are included in the "age" column, and what grades are specifically included in the "grade" column.
[0066] In some cases, it is possible that the data values corresponding to a certain column in the data table are represented by code items. Then, when generating the database structure information, it is also necessary to determine the code items of each column of data corresponding to each attribute information and the meaning of the code item. For example, in the column representing "gender", the number 1 represents male, and the number 0 represents female; or, the letter M represents male, and the letter F represents female.
[0067] The above S201 and S202 can be regarded as the collation of database information. By taking into account the description information of each data table in the database, the problem of missing semantic information caused by different naming methods in Chinese databases can be solved. After collating the database information, a representation of the structural information of the database can be:
[0068] Table_name|age: age, gender: gender ({1: male, 0: female}), column3: grade (['first grade','second grade', 'third grade', 'fourth grade', 'fifth grade','sixth grade'])
[0069] Table2_name|......
[0070] Table3_name|......
[0071] As can be seen above, each data table has a piece of information represented in structured language. This information includes the name of the data table (such as Table_name, Table2_name, etc.), the column names of each column in the table (such as age, gender, etc.), and the semantic interpretation of the column name (such as the age column represents age, and the gender column represents gender). In addition, for the case where there is a limited value range in each column of data, the specific value range of the corresponding column can also be included in this information (such as from the first grade to the sixth grade in column3). If the value of a certain column is represented in the form of code items, the above information also includes the code items and the corresponding explanations (such as under the gender column, the code 1 represents male gender, and the code 0 represents female gender).
[0072] S203. When receiving a query statement input by the user in natural language, extract the conditional information contained in the query statement.
[0073] In the embodiment of the present application, when receiving a query statement input by the user in natural language, semantic analysis can be performed on the query statement to extract the potential conditional information contained in the query statement. This conditional information is also a kind of information that can reflect the user's query purpose.
[0074] In a possible implementation manner of the embodiment of the present application, the structural information of the database can be predicted according to the query statement to determine whether there is target information associated with the query statement in the structural information. If there is target information associated with the current query statement in the database structural information, the computer device can determine the conditional information contained in the query statement according to the target information.
[0075] In a possible implementation manner of the embodiment of the present application, a pre-trained model can be used to predict the structure information and confirm whether the structure information contains the target information associated with the query statement. The above model can be trained based on the BERT model.
[0076] In the embodiment of the present application, the training of the BERT model can include a pre-training stage and a fine-tuning stage. Among them, in the pre-training stage, a large number of samples can be used to train the BERT model, so that the BERT model can learn relevant language knowledge. For example, through pre-training, the BERT model can make a certain degree of preliminary judgment on whether there is a correlation between the query statement and the database structure information. On this basis, the pre-trained BERT model can be fine-tuned so that the BERT model can better predict the query statement and the database structure information. Specifically, in the fine-tuning stage, the training task can be customized. The input data in the fine-tuning stage can be data with annotation information, that is, if there is a correlation between the query statement and the corresponding database structure information in the sample, one or more of the relevant items can be labeled as 1, and other items are labeled as 0. Using the annotated database structure information and the corresponding query statement to input into the pre-trained BERT model for fine-tuning can make the fine-tuned BERT model have a better prediction effect.
[0077] The above BERT model is only a possible model structure for implementing the method in the embodiment of the present application. According to different actual requirements, other structured models can also be used to predict the splicing information. Before using other structured models for prediction, they can also be pre-trained and fine-tuned, and the relevant methods can refer to the above introduction of the BERT model and will not be elaborated here.
[0078] As Figure 3 shown, it is a schematic diagram of extracting conditional information provided by the embodiment of the present application. As Figure 3 shown, first, the query statement can be spliced with the structure information of the database. For example, splicing the query statement "How many boys are there in total" in the foregoing example with the structure information of the database, the following information is obtained:
[0079] How many boys are there in total|Table_name|age: age, gender: gender ({1: male, 0: female}), column3: grade ([‘first grade’, ’second grade’, ’third grade’, ’fourth grade’, ’fifth grade’, ’sixth grade’])
[0080] The above information can be input into the BERT model for semantic analysis. Specifically, the BERT model can predict the structure information of the database based on the query statement. If, after prediction, a certain item in the structure information has no direct relationship with the above query statement, the prediction result can be output as 0; if a certain item in the structure information has a direct relationship, the BERT model can output the prediction result as 1. For example, in Figure 3 after prediction, the items such as gender: gender ({1: male, 0: female}) in the structure information are related to the query statement, so the corresponding output result of the model is 1, and the output results of other items are 0.
[0081] By looping through all the data tables in the database, the final condition can be obtained. For example Figure 3 the condition information of "gender = 1" shown in
[0082] In a possible implementation manner of the embodiment of the present application, the function of extracting the above condition information implemented by the computer device can be implemented by the evidence generation module on the computer device. Correspondingly, the condition information extracted by the evidence generation module from the query statement can also be regarded as the specific evidence generated by the evidence generation module. Applying this evidence, the query statement and the database structure information can be accurately identified, so as to obtain the structured input information.
[0083] S204. Concatenate the query statement and the structure information to obtain the to-be-processed input information.
[0084] Exemplarily, the to-be-processed input information can be:
[0085] How many boys are there | Table_name | age: age, gender: gender ({1: male, 0: female}), column3: grade ([‘first grade’, ’second grade’, ’third grade’, ’fourth grade’, ’fifth grade’, ’sixth grade’])
[0086] S205. Replace the target information associated with the condition information in the to-be-processed input information with the condition information to obtain the structured input information.
[0087] By using the predicted condition information to replace the target information associated with it in the to-be-processed input information, a standard input structure can be obtained. For example, the condition information in the above example is "gender = 1", and the target information associated with it is gender: gender ({1: male, 0: female}). By using the condition information to replace the target information, the structured input information obtained is:
[0088] How many boys are there in total|Table_name|age: age, gender = 1, column3: grade (['Grade 1', 'Grade 2', 'Grade 3', 'Grade 4', 'Grade 5', 'Grade 6'])
[0089] In a possible implementation manner of the embodiment of the present application, in order to reduce the influence of non - related information on subsequent processing, after obtaining the structured input information, the redundant information therein can also be deleted, and only the name of the data table, the column names and their explanations, and the conditions related to the query statement included in the column names are retained. Therefore, the structured input information in the above example can be expressed as after being trimmed:
[0090] How many boys are there in total|Table_name|age: age, gender: gender (gender = 1), column3: grade|Table2_name|......
[0091] S206. Convert the structured input information into a database statement recognizable by the database.
[0092] In the embodiment of the present application, the statement recognizable by the database can be an SQL statement. By applying the Text2SQL technology, the structured input information can be converted into an SQL statement.
[0093] It should be noted that the magnitudes of the sequence numbers of the steps in the above embodiments do not mean the order of execution is prior or posterior. The execution order of each process should be determined according to its function and internal logic, and should not constitute any limitation to the implementation process of the embodiment of the present application.
[0094] For the sake of easy understanding, the following introduces the natural language conversion method provided by the embodiment of the present application in combination with a specific example.
[0095] As Figure 4 shown, it is a schematic diagram of a natural language conversion process provided by the embodiment of the present application. According to the conversion process Figure 4 shown, the computer device can interact with the user and receive the query statement input by the user in natural language. For example, the query statement is "How many boys are there in total"? The above query statement can be input by the user in text form in the interaction interface of the computer device and transmitted to the computer device, or can be transmitted to the computer device in the form of voice information by the user through the audio acquisition module provided by the computer device. If the query statement is transmitted in the form of voice information, the computer device can convert the received voice information into text form.
[0096] The evidence generation module in the computer device can be used to handle the received query statements. It should be noted that naming the module for processing query statements in the computer device as the evidence generation module above is only an example, and the name of this module can be determined according to actual needs. The embodiments of this application do not limit this.
[0097] As Figure 4 shown, on the one hand, the evidence generation module can interact with the database to obtain the structure information of the database. On the other hand, the evidence generation module can receive the query statement input by the user and process it.
[0098] Among them, the evidence generation module can sort out the structure information of the database according to the specific data stored in the database. Specifically, the evidence generation module can process each data table stored in the database one by one, taking into account the description information of each column in each data table. The description information of each column represents the specific meaning of the data in that column and has a relatively complete semantic representation. Secondly, the evidence generation module can also take into account the specific value range of each column of data to obtain a value list for each column of data. If the value of a certain column is represented by a code item, the evidence generation module also needs to determine the code item of the value of that column and the specific meaning of each code item.
[0099] By sorting out the database information, a possible representation of the structure information of the database can be obtained as:
[0100] Table_name|age: age, gender: gender ({1: male, 0: female}), column3: grade ([‘first grade’, ’second grade’, ’third grade’, ’fourth grade’, ’fifth grade’, ’sixth grade’])
[0101] The key to the evidence generation module's processing of the query statement input by the user lies in how to extract the potential conditional information contained in the natural language. For example, in the natural language “How many boys are there in the whole grade”, since in the database, 1 represents male and 0 represents female, the condition contained in this natural language should be “gender = 1”, that is, the number of people with a value of 1 in the “gender” column.
[0102] In the embodiments of this application, a model pre-trained based on BERT can be used for semantic analysis to obtain the corresponding conditional information.
[0103] Specifically, the evidence generation module can splice the query statement with the structure information of the database to obtain the following information:
[0104] How many male students are there in the whole grade|Table_name|age: age, gender: gender ({1: male, 0: female}), column3: grade (['first grade','second grade', 'third grade', 'fourth grade', 'fifth grade','sixth grade'])
[0105] The above information can be input into the model for prediction, and the prediction result is the condition required by the evidence generation module. After looping through all the data tables, all the conditions can be obtained, that is, all the condition outputs of the evidence generation module. For example, all the condition outputs can be "gender = 1".
[0106] Then, the evidence generation module can combine all the generated conditions with the database structure information and the query statement input in natural language form to obtain a standard input structure as follows:
[0107] How many male students are there in the whole grade|Table_name|age: age, gender: gender (gender = 1), column3: grade (['first grade','second grade', 'third grade', 'fourth grade', 'fifth grade','sixth grade'])
[0108] By deleting the redundant information and only retaining the data table name, column names and their explanations, and the information of the conditions related to the natural language input contained in the column names. The simplified standard structured input information can be expressed as:
[0109] How many male students are there in the whole grade|Table_name|age: age, gender: gender (gender = 1), column3: grade|Table2_name|......
[0110] The above structured input information can be regarded as a kind of information containing relevant evidence generated by the evidence generation module.
[0111] Such as Figure 4 As shown, inputting the structured input information containing evidence into the Text2SQL model can further help the model obtain the correct SQL statement.
[0112] Referring to Figure 5 , a schematic diagram of a natural language conversion device provided by an embodiment of the present application is shown, which may specifically include an acquisition module 501, an extraction module 502, a generation module 503, and a conversion module 504, wherein:
[0113] The acquisition module 501 is used to acquire the structure information of the database, and the structure information is information that describes the data stored in the database in a structured language;
[0114] An extraction module 502, configured to extract conditional information included in the query statement when receiving a query statement input by a user in natural language;
[0115] A generation module 503, configured to generate structured input information according to the structure information and the conditional information;
[0116] A conversion module 504, configured to convert the structured input information into a database statement recognizable by the database.
[0117] In a possible implementation manner of the embodiment of the present application, the obtaining module 501 may specifically be configured to:
[0118] Obtain table structure description information of multiple data tables stored in the database;
[0119] Generate structure information of the database according to the table structure description information of each data table.
[0120] In a possible implementation manner of the embodiment of the present application, the obtaining module 501 may further be configured to:
[0121] Read column names of each column of data in each data table;
[0122] Determine data values corresponding to the column names, and the column names and their corresponding data values constitute the table structure description information.
[0123] In another possible implementation manner of the embodiment of the present application, the obtaining module 501 may further be configured to:
[0124] Determine attribute information of each column of data in each data table according to the table structure description information of each data table;
[0125] Determine attribute values of each column of data corresponding to the attribute information;
[0126] Generate structure information of the database according to the attribute information of multiple columns of data in each data table and their corresponding attribute values.
[0127] In the embodiment of the present application, the obtaining module 501 may further be configured to:
[0128] Determine code items of each column of data corresponding to the attribute information and meanings of the code items.
[0129] In a possible implementation manner of the embodiment of the present application, the extraction module 502 may specifically be configured to:
[0130] Predict the structural information according to the query statement to determine whether there is target information associated with the query statement in the structural information;
[0131] If there is target information associated with the query statement in the structural information, determine the conditional information included in the query statement according to the target information.
[0132] In a possible implementation manner of the embodiment of the present application, the generating module 503 may specifically be configured to:
[0133] Concatenate the query statement and the structural information to obtain the to-be-processed input information;
[0134] Replace the target information associated with the conditional information in the to-be-processed input information with the conditional information to obtain the structured input information.
[0135] A natural language conversion device provided by an embodiment of the present application. By applying this device, each step in the foregoing method embodiments can be implemented.
[0136] For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple. For related parts, refer to the description in the method embodiment part.
[0137] Refer to Figure 6 , which shows a schematic diagram of a computer device provided by an embodiment of the present application. As Figure 6 shown, the computer device 600 in the embodiment of the present application includes: a processor 610, a memory 620, and a computer program 621 stored in the memory 620 and executable on the processor 610. When the processor 610 executes the computer program 621, the steps in each of the foregoing embodiments of the natural language conversion method are implemented, such as Figure 1 the steps S101 to S104 shown. Alternatively, when the processor 610 executes the computer program 621, the functions of each module / unit in each of the foregoing device embodiments are implemented, such as Figure 5 the functions of the modules 501 to 504 shown.
[0138] Exemplarily, the computer program 621 may be divided into one or more modules / units. The one or more modules / units are stored in the memory 620 and executed by the processor 610 to complete the present application. The one or more modules / units may be a series of computer program instruction segments capable of performing specific functions, and these instruction segments may be used to describe the execution process of the computer program 621 in the computer device 600. For example, the computer program 621 may be divided into an acquisition module, an extraction module, a generation module, and a conversion module. The specific functions of each module are as follows:
[0139] An acquisition module, configured to acquire structure information of a database, where the structure information is information that describes data stored in the database in a structured language;
[0140] An extraction module, configured to extract condition information included in the query statement when receiving a query statement input by a user in natural language;
[0141] A generation module, configured to generate structured input information according to the structure information and the condition information;
[0142] A conversion module, configured to convert the structured input information into a database statement recognizable by the database.
[0143] The computer device 600 may be an electronic device capable of implementing each step in the foregoing method embodiments. The computer device 600 may be a desktop computer, a cloud server, or the like. The computer device 600 may include, but is not limited to, a processor 610 and a memory 620. Those skilled in the art can understand that Figure 6 This is only an example of the computer device 600 and does not constitute a limitation on the computer device 600. It may include more or fewer components than shown in the figure, or combine some components, or different components. For example, the computer device 600 may further include input / output devices, network access devices, buses, etc.
[0144] The processor 610 may be a central processing unit (CPU), or may also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0145] The memory 620 may be an internal storage unit of the computer device 600, such as the hard disk or memory of the computer device 600. The memory 620 may also be an external storage device of the computer device 600, such as a plug-in hard disk equipped on the computer device 600, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, and so on. Further, the memory 620 may also include both the internal storage unit and the external storage device of the computer device 600. The memory 620 is used to store the computer program 621 and other programs and data required by the computer device 600. The memory 620 may also be used to temporarily store the data that has been output or will be output.
[0146] An embodiment of the present application also discloses a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the natural language conversion method described in each of the foregoing embodiments is implemented.
[0147] An embodiment of the present application also discloses a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, the natural language conversion method described in each of the foregoing embodiments is implemented.
[0148] An embodiment of the present application also discloses a computer program product. When the computer program product runs on a computer, the computer is caused to execute the natural language conversion method described in each of the foregoing embodiments.
[0149] The foregoing embodiments are only used to illustrate the technical solutions of the present application, rather than to limit the same. Although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacement on some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of each embodiment of the present application, and shall all be included in the protection scope of the present application.
Claims
1. A natural language conversion method, characterized in that including: Obtain the structure information of the database, where the structure information is information that describes the data stored in the database in a structured language; When receiving a query statement input by the user in natural language, extract the condition information included in the query statement; Generate structured input information according to the structure information and the condition information; Convert the structured input information into a database statement recognizable by the database.
2. The method according to claim 1, characterized in that, The obtaining the structure information of the database includes: Obtain the table structure description information of multiple data tables stored in the database; Generate the structure information of the database according to the table structure description information of each data table.
3. The method according to claim 2, wherein The obtaining the table structure description information of multiple data tables stored in the database includes: Read the column names of each column of data in each data table; Determine the data values corresponding to the column names, and the column names and their corresponding data values constitute the table structure description information.
4. The method according to claim 2, wherein The generating the structure information of the database according to the table structure description information of each data table includes: Determine the attribute information of each column of data in each data table according to the table structure description information of each data table; Determine the attribute values of each column of data corresponding to the attribute information; Generate the structure information of the database according to the attribute information of multiple columns of data in each data table and their corresponding attribute values.
5. The method according to claim 4, wherein The determining the attribute values of each column of data corresponding to the attribute information includes: Determine the code items of each column of data corresponding to the attribute information and the meanings of the code items.
6. The method according to any one of claims 1 to 5, characterized in that The extracting the condition information included in the query statement includes: According to the query statement, predict the structure information to determine whether there is target information associated with the query statement in the structure information; If there is target information associated with the query statement in the structure information, determine the condition information included in the query statement according to the target information.
7. The method according to claim 6, characterized in that The generating structured input information according to the structure information and the condition information includes: Concatenate the query statement and the structure information to obtain the input information to be processed; Replace the target information associated with the condition information in the input information to be processed with the condition information to obtain the structured input information.
8. A natural language conversion device, characterized in that, including: An obtaining module for obtaining the structure information of the database, where the structure information is information that describes the data stored in the database in a structured language; An extracting module for extracting the condition information included in the query statement when receiving a query statement input by the user in natural language; A generating module for generating structured input information according to the structure information and the condition information; A converting module for converting the structured input information into a database statement recognizable by the database.
9. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the natural language conversion method according to any one of claims 1-7.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the natural language conversion method according to any one of claims 1-7.