Data generation method, natural language processing method, model training method, and device and medium

By building target structured query statements and training natural language models, the problem of users' difficulty in converting natural language into SQL statements is solved, and the ability of non-professionals to efficiently query databases is realized.

WO2025149808A1PCT designated stage expired Publication Date: 2025-07-17CLOUD INTELLIGENCE ASSETS HOLDING (SINGAPORE) PTE LTD

Patent Information

Application Number
PCT/IB2024/062544
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2024-01-10
Filing Date
2024-12-12
Publication Date
2025-07-17

AI Technical Summary

Technical Problem

In the prior art, it is difficult for non-professionals or users who lack database knowledge to convert natural language into structured query language (SQL) statements for database query, resulting in low query efficiency and poor user experience.

Method used

By constructing a target structured query statement, the target natural language is generated using the pre-trained natural language model, and the training data is generated based on the matching degree between the target data table and the natural language, the second natural language model is trained to accurately identify the user's query intention and generate corresponding SQL statements.

Benefits of technology

It improves the accuracy and efficiency of users querying databases, supports non-professional personnel to realize database query needs in natural language, and enhances user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure IB2024062544_17072025_PF_FP_ABST
    Figure IB2024062544_17072025_PF_FP_ABST
Patent Text Reader

Abstract

The present disclosure relates to the technical field of artificial intelligence. Provided are a data generation method, a natural language processing method, a model training method, and a device and a medium. The data generation method comprises: on the basis of a target data table in a database, constructing a target structured query language, wherein the target structured query language is configured to query at least one piece of data in the target data table; using a first natural language model to generate a target natural language corresponding to the target structured query language; and on the basis of the matching degree between the target data table and the target natural language, and the target structured query language and the target natural language, generating training data for training a second natural language model, wherein the second natural language model is configured to process a received natural language to generate a corresponding structured query language. The training data generated in the present disclosure can make a trained natural language model more accurately identify a query intent in the natural language, and support a user to use the natural language to meet the requirement for database query.
Need to check novelty before this filing date? Find Prior Art

Description

[0001]Data Generation, Natural Language Processing, Model Training Method, Device, and Medium This disclosure claims priority to Chinese patent application number 202410038580.7, filed with the China Patent Office on January 10, 2024, entitled "Data Generation, Natural Language Processing, Model Training Method, Device, and Medium," the entire contents of which are incorporated herein by reference. Technical Field This disclosure relates to the field of artificial intelligence technology, and more particularly to a data generation method, a natural language processing method, a model training method, a data generation device, a natural language processing device, a model training device, an electronic device, a computer-readable storage medium, and a computer program product. Background In the current era of big data, massive amounts of data are stored in databases in the form of data tables. Database queries require a deep understanding of the syntax and database structure of Structured Query Language (SQL). For non-professionals or users lacking relevant knowledge, converting natural language into SQL statements and then performing database queries is quite difficult. SUMMARY OF THE INVENTION Embodiments of the present disclosure provide a data generation method, a natural language processing method, a model training method, a data generation device, a natural language processing device, a model training device, an electronic device, a computer-readable storage medium, and a computer program product to alleviate or resolve one or more technical problems existing in the prior art. In a first aspect, embodiments of the present disclosure provide a data generation method, comprising: constructing a target structured query language (SQL) structured query statement based on a target data table in a database, wherein the target structured query statement is used to query at least one item of data in the target data table; generating a target natural language corresponding to the target structured query statement using a trained first natural language model; and generating training data for training a second natural language model based on a match between the target data table and the target natural language, the target structured query statement, and the target natural language. The second natural language model is used to process received natural language to generate a corresponding structured query statement. In a second aspect, an embodiment of the present disclosure provides a natural language processing method, comprising: processing received natural language using a second natural language model to generate a structured query statement corresponding to the natural language; wherein the second natural language model is trained based on training data generated by the data generation method of the first aspect of the embodiment of the present disclosure.In a third aspect, embodiments of the present disclosure provide a model training method, comprising: constructing an initial natural language model; training the initial natural language model using training data generated by the data generation method of the first aspect of the present disclosure to obtain a second natural language model, wherein the second natural language model is configured to process received natural language and generate a corresponding structured query statement. In a fourth aspect, embodiments of the present disclosure provide a data generation device, comprising: a structured query statement construction module, configured to construct a target structured query language (SCL) structured query statement based on a target data table in a database, wherein the target structured query statement is used to query at least one item of data in the target data table; a natural language generation module, configured to generate a target natural language corresponding to the target structured query statement using the trained first natural language model; and a data generation module, configured to generate training data for training a second natural language model based on a match between the target data table and the target natural language, the target structured query statement, and the target natural language, wherein the second natural language model is configured to process the received natural language and generate a corresponding structured query statement. In a fifth aspect, embodiments of the present disclosure provide a natural language processing device, comprising: a generation module for processing received natural language using a second natural language model to generate a structured query statement corresponding to the natural language; wherein the second natural language model is trained based on training data generated by the data generation method of the first aspect; and a query module for querying a database based on the structured query statement to obtain query results corresponding to the natural language. In a sixth aspect, embodiments of the present disclosure provide a model training device, comprising: a model construction module for constructing an initial natural language model; and a training module for training the initial natural language model using the training data generated by the data generation method of the first aspect to obtain a second natural language model; wherein the second natural language model is used to process received natural language and generate a corresponding structured query statement. In a seventh aspect, embodiments of the present disclosure provide an electronic device, comprising a memory, a processor, and a computer program stored in the memory, wherein the processor implements any of the methods of the embodiments of the present disclosure when executing the computer program. In an eighth aspect, embodiments of the present disclosure provide a computer-readable storage medium, wherein the computer-readable storage medium stores the computer program, wherein the computer program implements any of the methods of the embodiments of the present disclosure when executed by the processor. In a ninth aspect, an embodiment of the present disclosure provides a computer program product, including a computer program, which implements any method of the embodiments of the present disclosure when executed by a processor.According to the data generation method provided by the embodiments of the present disclosure, a pre-trained natural language model can be used to generate a large amount of target natural language corresponding to the target structured query statement based on the target structured query statement as training data. Because the natural language generated by the natural language model can cover different descriptions of the same query intent, the natural language model trained using this training data can generate structured query statements that are more closely related to the query intent based on the user's natural language, thereby facilitating the computer system to obtain query results from the database. The technical solutions of the embodiments of the present disclosure can support non-professionals or users lacking database knowledge to complete database query requirements in natural language. The above description is only an overview of the technical solutions of the present disclosure. To better understand the technical means of the present disclosure, it can be implemented in accordance with the contents of the specification. To make the above and other purposes, features, and advantages of the present disclosure more readily understood, specific embodiments of the present disclosure are described below. BRIEF DESCRIPTION OF THE DRAWINGS In the drawings, unless otherwise specified, identical reference numerals throughout the multiple figures indicate identical or similar components or elements. The drawings are not necessarily drawn to scale. It should be understood that these drawings depict only some embodiments of the present disclosure and should not be construed as limiting the scope of the present disclosure. Figure 1 illustrates an exemplary system architecture according to an embodiment of the present disclosure; Figure 2 illustrates a timing diagram for generating and utilizing training data in an application scenario according to an embodiment of the present disclosure; Figure 3 illustrates a flow chart of a data generation method according to an embodiment of the present disclosure; Figure 4 illustrates a flow chart of a natural language processing method according to an embodiment of the present disclosure; Figure 5 illustrates an exemplary flow chart of a model training method according to an embodiment of the present disclosure; Figure 6 illustrates a schematic diagram of a data generation device according to an embodiment of the present disclosure; Figure 7 illustrates a schematic diagram of a natural language processing device according to an embodiment of the present disclosure; Figure 8 illustrates a schematic diagram of a model training device according to an embodiment of the present disclosure; and Figure 9 illustrates a block diagram of an electronic device for implementing an embodiment of the present disclosure. DETAILED DESCRIPTION OF THE EMBODIMENTS The following briefly describes certain exemplary embodiments. As will be appreciated by those skilled in the art, the described embodiments may be modified in various ways without departing from the spirit or scope of the present disclosure. Therefore, the drawings and description are to be regarded as illustrative in nature and not restrictive. To facilitate understanding of the technical solutions of the embodiments of the present disclosure, the following describes related technologies according to the embodiments of the present disclosure. The following related technologies, as optional solutions, may be combined in any manner with the technical solutions of the embodiments of the present disclosure and fall within the scope of protection of the embodiments of the present disclosure.The following terms will be used below: Natural Language to Structured Query Language (NL2SQL): This is a technology that converts natural language into Structured Query Language (SQL). Using NL2SQL, a user's natural language can be converted into semantic representations that a database or computer can understand and execute, thereby enabling interaction between natural language and the database. Natural Language Processing (NLP): This is referred to as a natural language model in the disclosed embodiments. A natural language model refers to a deep learning model trained using large amounts of text data that can generate natural language text or understand the meaning of language text. Natural language models can handle a variety of natural language tasks, such as text classification, question-answering, and conversation, and are an important technical means in the field of artificial intelligence technology. Generally speaking, NL2SQL technology can convert a user's natural language into SQL statements that the database can understand and recognize, thereby helping users interact with the database and query data in the database. NL2SQL generally includes an SQL generator and an SQL executor. The SQL generator takes as input a specific database and a natural language question targeting the database, and outputs a structured query statement (hereinafter referred to as an SQL statement) corresponding to the natural language question. The SQL executor generates and executes the SQL statement on the database, obtaining the corresponding query results. However, in current NL2SQL technology, the SQL statements generated by the SQL generator cannot fully and accurately match the user's actual query intent, especially for questions from users with a high degree of colloquialism. This often results in users having to modify and repeat the same question. Consequently, NL2SQL technology has low query efficiency and a poor user experience. In view of this, embodiments of the present disclosure provide a data generation method, a natural language processing method, and a model training method. These methods construct a target SQL statement for querying specific data in a database, utilize a natural language model to generate a target natural language corresponding to the target SQL statement, and then construct training data based on the target SQL statement and the target natural language to train the natural language model.This natural language model can process received user natural language, accurately identify the user's query intent, and generate corresponding SQL statements for data table queries. Because the natural language model can process and generate a large amount of natural language corresponding to the target SQL statement, the natural language in the constructed training data can cover as many different descriptions of the same question as possible, improving the hit rate of the user's true query intent. This, in turn, enables non-professionals or users lacking database knowledge to complete database query requirements using natural language. To facilitate understanding of the embodiments of the present disclosure, a brief description of the system architecture applicable to the present disclosure is first provided. Figure 1 shows an exemplary system architecture diagram of an embodiment of the present disclosure. As shown in Figure 1, the system architecture includes a data generation device 101, a natural language processing device 102, and a model training device 103. The data generation device 101 is used to construct a target SQL statement for querying specific data in a database, and uses the natural language model to generate target natural language corresponding to the target SQL statement, thereby constructing training data using the target SQL statement and the target natural language. Figure 2 shows a time sequence diagram of the generation and utilization of training data in an embodiment of the present disclosure. First, during the training data generation phase, initial data can be constructed based on the data in the database and a pre-trained natural language model. This initial data can include a target SQL statement and the target natural language corresponding to the target SQL statement. Specifically, the target SQL statement can be constructed using an SQL template. The SQL template reflects an assumption about the user's query. For example, SQL Template 1 assumes that the user is querying for specific data in a target data table in the database. It can obtain the location description of the specific data in the target data table. The location description can include the row and column names of the specific data. This location description is used as a constraint in conjunction with the SQL template to construct the target SQL statement. For another example, SQL Template 2 assumes that the user is querying for the data corresponding to the maximum value in a specific row of the target data table. The row name and maximum value of the specific row are used as constraints in conjunction with the SQL template to construct the target SQL statement. Subsequently, the target data table and target SQL statement are used as input, and the natural language model is used to output the target natural language corresponding to the target SQL statement. For a target SQL statement, the natural language model can predict and simulate multiple corresponding target natural languages. The target SQL statement and each target natural language can be constructed into a set of training data.Because the natural language model only references the target data table and the target SQL statement when predicting the target natural language corresponding to the target SQL statement, in practical applications, the actual query intent corresponding to the user's target natural language may not correspond to data in the target data table. Therefore, the constructed initial data needs to be screened. For example, the target natural language in the initial data can be input into the recall module, which then outputs a data table that may correspond to the query intent of the target natural language. The recall module can use the natural language model to perform vector extraction on the description information of each data table in the database and the input target natural language, obtaining description vectors for each data table and a target vector for the target natural language. The recall module then calculates the vector similarity between the target vector and each description vector and outputs the data table corresponding to the description vector with the highest similarity to the target vector as the data table with the highest degree of match to the target natural language. Furthermore, whether the query intent of the target natural language corresponds to data in the target data table can be determined by verifying whether the target data table is the data table with the highest degree of match to the target natural language, or whether the target data table is among the highly matched data tables output by the recall module. For example, if the target data table is the one with the highest degree of match for the target natural language, and the query intent in the target natural language corresponds to data in the target data table, the target natural language and the target SQL statement corresponding to the target natural language in the initial data can be used as positive training data. Conversely, if the recall module indicates that the query intent in the target natural language is less likely to correspond to data in the target data table, the initial data containing the target natural language can be deleted or used as negative training data. After screening the initial data, training data is obtained that can be used to train the required natural language model (for use in the SQL generator). The natural language model trained using this training data can process the received user's natural language and generate an SQL statement corresponding to the natural language, which can be used to query the database to obtain the user's desired query results. The model training device 103 is used to construct an initial natural language model and train the initial natural language model using the training data generated by the data generation device 101 to obtain a second natural language model.The natural language processing device 102 is configured to process received natural language using the second natural language model trained by the model training device 103, generating SQL statements corresponding to the natural language for querying the database. This allows users to input their query requirements into the natural language processing device 102 in natural language, thereby obtaining SQL statements that represent the user's query requirements and can be recognized and used by the database. For example, the data generation device 101, the natural language processing device 102, and the model training device 103 can be deployed on the same entity or multiple entities. The entity can be a physical server including an independent host, a virtual server hosted by a host cluster (such as a cloud server), or a client. The client can be hardware, such as an electronic device such as a mobile phone, a personal computer, a tablet computer, or a wearable device; it can also be an application (APP) or software module deployed on the electronic device. It should be noted that the application scenarios or application examples of the data generation method, natural language processing method, and model training method provided in the embodiments of the present disclosure are provided for ease of understanding, and the embodiments of the present disclosure do not specifically limit the application of the technical solutions. Furthermore, the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, storage, and display) involved in this disclosure are all authorized by the user or fully authorized by all parties. The collection, use, and processing of relevant data must comply with the relevant laws, regulations, and standards of the relevant countries and regions, and corresponding operation portals are provided for users to select, edit, authorize, or deny. The following detailed description of the technical solutions of this disclosure and how they address the aforementioned technical issues is provided using specific embodiments. The specific embodiments listed above may be combined with each other, and the same or similar concepts or processes may not be described in detail in certain embodiments. Figure 3 shows a flow chart of a data generation method 300 according to an embodiment of this disclosure. This data generation method 300 can be applied to a data generation device. As shown in FIG3 , the data generation method 300 may include: Step S301: constructing a target structured query statement based on a target data table in a database, wherein the target structured query statement is used to query at least one item of data in the target data table; wherein, in step S301, for the target data table in the database, it may be assumed that one or more items of data in the target data table are the user's query targets, and a target structured query statement that can be used to query the target data in the database is constructed based on the target data assumed to be the query targets.In one embodiment, step S301 constructs a target structured query statement based on a target data table in a database, including: determining target data in the target data table; determining target constraints based on the location description information of the target data in the target data table; and constructing the target structured query statement based on the target constraints and a preset structured query statement template. Specifically, after determining one or more data items in the target data table as target data, the location description information of the target data in the target data table can be obtained. The location description information can be understood as information that helps identify the target data in the target data table. For example, if the target data table describes the average temperature for different time periods within a week, the column information of the data indicates that the data refers to a specific day from Monday to Sunday, and the row information of the data indicates that the data refers to a specific time period of the day. Each data item in the data table represents the temperature for a specific time period within a week. Assuming the target data is the temperature on Tuesday, the location description information of the target data is "Tuesday" and "8:00am-9:00am." This location description information is used as a target constraint, and a target structured query statement is constructed using a preset structured query statement template. For example, the constructed target structured query statement may be "SELECT date, time period, temperature from table 1 where date = 'Tuesday' and time period = '8:00am-9:00am'." This target structured query statement queries the temperature between 8:00 and 9:00am on Tuesday morning from table 1. It is understandable that the number of target structured query statements that can be obtained by determining the target data using only the existing row and column information in the target data table as target constraint conditions is limited. Therefore, flexible constraint conditions can be added to the preset structured query statement template as a supplement to the target constraint conditions to enrich the target structured query statements that can be constructed. Taking the target data table as an example, which describes the average temperature at different times of the week, if the restriction added to the structured query statement template is a maximum value restriction, you can select only one column in the data table as the location description information. For example, if you still select the column containing Tuesday, the constructed target structured query statement can be "SELECT max temperature from table 1 where date = 'Tuesday'". This target structured query statement indicates that the highest temperature on Tuesday is queried from data table 1.The technical solutions of the embodiments of the present disclosure can fully utilize preset structured query statement templates to construct constraints on target data in a target data table, generating a large number of structured query statements for querying different data in the target data table. This facilitates the subsequent generation of sufficient training data to train a natural language processing model. Step S302: Generate a target natural language corresponding to the target structured query statement using a trained first natural language model. The first natural language model can be a pre-trained or industry-standard large-scale natural language model. Furthermore, the target structured query statement and target data table constructed in step S301 can be input into the first natural language model, and the first natural language model can be used to predict and output a target natural language corresponding to the target structured query statement. The first natural language model can output multiple target natural languages ​​for a single target structured query statement. These target natural languages ​​represent multiple natural language expressions that a user desires to perform on the target data table corresponding to the target structured query statement. Each target natural language and its corresponding target structured query statement can constitute a set of initial data for the target data table. In one embodiment, to further expand the amount of training data ultimately generated and ensure prediction coverage of users' natural language expressions, the target data table can be directly input into the first natural language model, causing the first natural language model to directly output content containing two fields, namely, the target structured query statement and the corresponding target natural language, as initial data. The aforementioned methods of obtaining initial data by using a structured query statement template in conjunction with the first natural language model and directly inputting the target data table into the first natural language model can be used independently or in combination. The specific configuration can be tailored to actual needs and is not limited in this disclosure. Using the technical solutions of the embodiments of this disclosure, after constructing a large number of target structured query statements for querying the target data table, the natural language model is used to predict the target natural language corresponding to the target structured query statements. Leveraging the predictive capabilities of the natural language model, a large amount of initial data can be obtained, fully covering potential natural language query expressions posed by users and ensuring effective training of the natural language model. Step S303: Generate training data for training a second natural language model based on the matching degree between the target data table and the target natural language, the target structured query statement, and the target natural language. The second natural language model is used to process the received natural language and generate a corresponding structured query statement.It is understood that in step S302, during the process of generating the target natural language based on the target structured query statement, the first natural language model predicts the target natural language that may correspond to the target structured query statement for querying target data in the target data table. In actual use, the database includes a vast number of data tables, and the actual query purpose of the previously predicted target natural language may not necessarily be for the target data table. Therefore, it is necessary to filter the previously obtained target structured query statement and target natural language. This filtering method can be performed by calculating the matching degree between the target data table and the target natural language to determine whether it meets the requirements. Specifically, in step S303, based on the matching degree between the target data table and the target natural language, the target structured query statement, and the target natural language, training data for training the second natural language model is generated. This can include: in response to the matching degree between the target data table and the target natural language meeting the preset requirements, using the target structured query statement and the target natural language as positive sample training data. The first preset requirement may be: the target data table's match with the target natural language is higher than the match with the target natural language of any other data table in the database; the second preset requirement may be: the target data table's match with the target natural language is higher than a preset value, and the number of other data tables in the database with a higher match with the target natural language than the target data table is less than a preset number. It is understood that the two preset requirements define different sets of positive sample training data. The first preset requirement requires that the trained natural language model output the structured query statement with the highest match for the user's natural language query, and query the database to ensure that the user can easily and directly obtain query results; the second preset requirement requires that the trained natural language model output at least one structured query statement with a high match for the user's natural language query, thereby ensuring that the query results obtained from the database cover the user's desired query content to the greatest extent possible. Optionally, data that does not meet the preset requirements can be deleted or used as negative training data to train the natural language model. The specific preset requirements for screening positive sample training data from the constructed target structured query statement and its corresponding target natural language can be set based on the actual functional requirements of the training model, and are not limited in this disclosure. In one embodiment, in order to support step S3O3 in determining the training data of the positive sample based on whether the matching degree between the target data table and the target natural language meets the preset requirements, the data generation method of the embodiment of the present disclosure further includes: calculating the matching degree between each data table in the database and the target natural language.Specifically, calculating the degree of match between each data table in the database and the target natural language includes: performing vector extraction on the target natural language to obtain a target vector corresponding to the target natural language; performing vector extraction on the description information of each data table to obtain a description vector corresponding to each data table; determining the similarity between the description vector and the target vector, and determining the degree of match between each data table and the target natural language based on the similarity. The description information of the data table may include table header information describing the data content and function of the data table. Vector extraction is the process of converting text into vectors. The description information of each data table can be subjected to feature extraction and encoding using a pre-trained natural language model to convert the data into a vector representation to obtain a description vector corresponding to each data table. Similarly, feature extraction and encoding can be performed on the target natural language to obtain a target vector corresponding to the target natural language. By calculating the similarity between each description vector and the target vector, the degree of match between the data table to which the description vector belongs and the target natural language can be determined. The greater the similarity, the higher the degree of match. Alternatively, the header information of certain data tables cannot fully describe the data content and requires specific data information. To improve the accuracy of the matching calculation, the entire data table can be vectorized to obtain a corresponding description vector. The specific configuration can be set based on actual needs. Alternatively, a deep learning optimization library can be used to fine-tune the pre-trained natural language model. This optimization reduces memory and video memory usage, improves training speed, provides efficient storage and data processing capabilities, and enhances the efficiency and feasibility of the training process. According to the technical solutions of the embodiments of the present disclosure, a sufficient amount of initial data containing target structured query statements and their corresponding target natural language for database queries is constructed using a pre-trained natural language model. This initial data is then filtered to obtain final training data. The natural language model trained with this training data can process received user natural language, accurately identify the user's query intent, and generate structured query statements corresponding to the natural language for use in database queries and obtaining query results. Because the natural language model can process and generate a large amount of natural language corresponding to the target structured query statement, the natural language in the constructed training data can cover as many different descriptions of the same query intent as possible, allowing non-professionals or users lacking database knowledge to express their query requirements in more natural language. Figure 4 shows a flowchart of a natural language processing method 400 according to an embodiment of the present disclosure. This natural language processing method 400 can be applied to a natural language processing device.As shown in Figure 4, the natural language processing method 400 may include: Step S401: Processing received natural language using a second natural language model to generate a structured query statement corresponding to the natural language; wherein the second natural language model is trained based on the training data generated by the data generation method 300; Step S402: Querying a database based on the structured query statement to obtain query results corresponding to the natural language. The natural language processing method of this embodiment can be applied to an SQL generator in NL2S QL technology, so that after receiving a user's natural language query, the SQL generator can accurately identify the user's query intent and generate a corresponding structured query statement, so that an SQL executor can execute the structured query statement to quickly determine the corresponding query results in the database. Because the training data used to train the second natural language model is generated using data generation method 300, a large number of correspondences between structured query statements and natural language are generated using the natural language model. The natural language in the constructed training data can cover as many different ways of describing the same question as possible, reducing the impact of overly colloquial user language on the accuracy of query results and improving the user experience. Figure 5 shows a flowchart of a natural language processing method 500 according to an embodiment of the present disclosure. This natural language processing method 500 can be applied to a natural language processing device. As shown in Figure 5, this natural language processing method 500 may include: Step S501: Constructing an initial natural language model; Step S502: Training the initial natural language model using the training data generated by data generation method 300 to obtain a second natural language model. The second natural language model is used to process received natural language and generate corresponding structured query statements. The initial natural language model can be created based on any model framework that includes a feature transformation network. Optional model architectures may include, but are not limited to, at least one of the T5 (Transfer Text-to-Text Transformer) and GPT (Generative Pre-Trained Transformer) frameworks. For example, taking the positive sample training data used in data generation method 300 as an example, the model input is the target natural language and various data tables in the database. The model output is a target structured query statement corresponding to the target natural language. The target structured query statement includes the table name of the target data table and restrictions on the target data.This allows the trained second natural language model to recognize and process the received user's natural language and accurately output a corresponding structured query statement. The output structured query statement can be used to identify a data table in the database that matches the user's query intent, and then, based on the constraints in the structured query statement, determine the data corresponding to the user's query intent within the data table as a query result. For example, the second natural language model can be a model in the SQL generator in NL2S QL technology, enabling the SQL generator to more accurately recognize natural language and generate a structured query statement that precisely describes the query intent, allowing the SQL executor to execute the structured query statement in the database and obtain the user's desired query result. Based on the technical solution of the embodiments of the present disclosure, the initial natural language model is trained using the training data generated by data generation method 300 to obtain a second natural language model. Due to the training data's broad coverage of different natural language descriptions of the same question, the second natural language model enables non-professionals or users lacking database knowledge to express their query requirements in a more natural language. Corresponding to the application scenarios and methods provided in the embodiments of the present disclosure, the embodiments of the present disclosure also provide a data generation device. As shown in FIG6 , the data generation device 600 may include: a structured query statement construction module 601, which constructs a target structured query statement based on a target data table in a database, wherein the target structured query statement is used to query at least one data item in the target data table; a natural language generation module 602, which generates target natural language corresponding to the target structured query statement using a trained first natural language model; and a data generation module 603, which generates training data for training a second natural language model based on the matching degree between the target data table and the target natural language, the target structured query statement, and the target natural language. The second natural language model is used to process received natural language and generate a corresponding structured query statement. In one embodiment, the data generation module 603 is configured to use the target structured query statement and the target natural language as positive training data in response to the matching degree between the target data table and the target natural language meeting a preset requirement. The preset requirement is: the matching degree between the target data table and the target natural language is higher than the matching degree between any other data table in the database and the target natural language; or, the matching degree between the target data table and the target natural language is higher than a preset value, and the number of other data tables in the database that have a higher matching degree with the target natural language than the target data table is less than a preset number.In one embodiment, the data generation device further includes a calculation module for calculating the degree of match between each data table in the database and the target natural language. In one embodiment, the calculation module is configured to perform vector extraction on the target natural language to obtain a target vector corresponding to the target natural language; perform vector extraction on the description information of each data table to obtain a description vector corresponding to each data table; determine the similarity between the description vector and the target vector, and determine the degree of match between each data table and the target natural language based on the similarity. In one embodiment, the structured query statement construction module 601 is configured to determine target data in the target data table; determine target constraints based on the location description information of the target data in the target data table; and construct a target structured query statement based on the target constraints and a preset structured query statement template. Corresponding to the application scenarios and methods provided in the embodiments of the present disclosure, the embodiments of the present disclosure also provide a natural language processing device. As shown in Figure 7 , the natural language processing device 700 may include: a generation module 701 for processing received natural language using a second natural language model to generate a structured query statement corresponding to the natural language; wherein the second natural language model is trained based on the training data generated by the data generation method 300; a query module 702 for querying a database based on the structured query statement to obtain query results corresponding to the natural language. Corresponding to the application scenarios and methods provided in the embodiments of the present disclosure, the embodiments of the present disclosure also provide a model training device. As shown in Figure 8 , the model training device 800 may include: a model construction module 801 for constructing an initial natural language model; a training module 802 for training the initial natural language model using the training data generated by the data generation method 300 to obtain a second natural language model; wherein the second natural language model is used to process the received natural language and generate the corresponding structured query statement. The functions of each module in each device of the embodiments of the present disclosure can be found in the corresponding description of the above-mentioned method, and they have corresponding beneficial effects, and are not further described here. Figure 9 is a block diagram of an electronic device for implementing the embodiments of the present disclosure. As shown in Figure 9, the electronic device includes a memory 901 and a processor 902. The memory 901 stores a computer program executable by the processor 902. When the processor 902 executes the computer program, the method described in the above embodiment is implemented. The memory 901 and the processor 902 may be one or more. The electronic device also includes a communication interface 903 for communicating with external devices and exchanging data.If the memory 901, processor 902, and communication interface 903 are implemented independently, the memory 901, processor 902, and communication interface 903 may be interconnected via a bus and communicate with each other. This bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, for example. This bus may be classified as an address bus, a data bus, a control bus, etc. For ease of illustration, FIG9 shows only one thick line, but this does not mean that there is only one bus or only one type of bus. Optionally, in a specific implementation, if the memory 901, processor 902, and communication interface 903 are integrated on a single chip, the memory 901, processor 902, and communication interface 903 may communicate with each other via an internal interface. The present embodiment provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the method provided in the present embodiment. Embodiments of the present disclosure provide a computer program product comprising a computer program. When executed by a processor, the program implements the methods provided in the embodiments of the present disclosure. Embodiments of the present disclosure also provide a chip comprising a processor configured to retrieve and execute instructions stored in a memory, thereby enabling a communication device equipped with the chip to perform the methods provided in the embodiments of the present disclosure. Embodiments of the present disclosure also provide a chip comprising an input interface, an output interface, a processor, and a memory. The input interface, the output interface, the processor, and the memory are connected via an internal connection path. The processor is configured to execute code in the memory. When the code is executed, the processor performs the methods provided in the embodiments of the present disclosure. It should be understood that the processor may be a CPU (Central Processing Unit), other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), FPGAs, other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, and the like. A general-purpose processor may be a microprocessor or any conventional processor.It is worth noting that the processor may be a processor supporting the Advanced RISC Machines (ARM) architecture. Furthermore, optionally, the aforementioned memory may include read-only memory and random access memory. The memory may be volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. Non-volatile memory may include read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory may include random access memory (RAM), which serves as an external cache. By way of example and not limitation, many forms of RAM may be used. For example, static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronized link dynamic random access memory (SLDRAM), and direct rambus random access memory (DR RAM). In the above embodiments, they can be implemented in whole or in part via software, hardware, firmware, or any combination thereof. When implemented using software, they can be implemented in whole or in part in the form of a computer program product. A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions according to the present disclosure are fully or partially generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. Computer instructions can be stored in or transferred from one computer-readable storage medium to another.Throughout this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples" indicate that a specific feature, structure, material, or characteristic described in conjunction with that embodiment or example is included in at least one embodiment or example of the present disclosure. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, those skilled in the art may combine and integrate different embodiments or examples, as well as features from different embodiments or examples, as long as they are not mutually inconsistent. Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features being referred to. Therefore, features specified as "first" or "second" may explicitly or implicitly include at least one of those features. Throughout this disclosure, "multiple" means two or more, unless otherwise specifically defined. Any process or method described in a flowchart or otherwise herein can be understood to represent a module, segment, or portion of code comprising one or more executable instructions for implementing a specific logical function or process step. Furthermore, the scope of the preferred embodiments of the present disclosure includes alternative implementations in which functions may be performed out of the order shown or discussed, including substantially simultaneously or in reverse order depending on the functions involved. The logic and / or steps described in a flowchart or otherwise herein, for example, can be considered a sequenced list of executable instructions for implementing the logical function and can be embodied in any computer-readable medium for use by an instruction execution system, apparatus, or device (e.g., a computer-based system, a system including a processor, or other system that can fetch and execute instructions from an instruction execution system, apparatus, or device), or in conjunction with such an instruction execution system, apparatus, or device. It should be understood that various aspects of the present disclosure may be implemented using hardware, software, firmware, or a combination thereof. In the aforementioned embodiments, multiple steps or methods may be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. All or part of the steps of the method in the above-described embodiment may be performed by instructing related hardware through a program. The program may be stored in a computer-readable storage medium. When executed, the program includes one or a combination of the steps of the method embodiment. Furthermore, the functional units in the various embodiments of the present disclosure may be integrated into a single processing module, each unit may exist physically separately, or two or more units may be integrated into a single module.The above-mentioned integrated modules can be implemented in either hardware or software functional modules. If implemented as software functional modules and sold or used as independent products, the integrated modules can also be stored in a computer-readable storage medium. This storage medium can be a read-only memory, a magnetic disk, or an optical disk. The above description is merely an exemplary embodiment of the present disclosure, but the scope of protection of the present disclosure is not limited thereto. Anyone skilled in the art can easily conceive of various variations and substitutions within the technical scope of the present disclosure, and such variations and substitutions are intended to be encompassed by the scope of protection of the present disclosure. Therefore, the scope of protection of the present disclosure shall be subject to the scope of protection of the claims.

Claims

Claims 1. A data generation method, comprising: Based on the target data table in the database, construct a target structured query statement, where the target structured query statement is used to query at least one piece of data in the target data table; use a first natural language model to generate the target natural language corresponding to the target structured query statement; generate training data for training a second natural language model according to the matching degree between the target data table and the target natural language, the target structured query statement, and the target natural language, where the second natural language model is used to process the received natural language and generate a corresponding structured query statement.

2. The method according to claim 1, wherein Generate training data for training a second natural language model according to the matching degree between the target data table and the target natural language, the target structured query statement, and the target natural language, including: in response to the matching degree between the target data table and the target natural language meeting a preset requirement, using the target structured query statement and the target natural language as positive sample training data.

3. The method according to claim 2, wherein The preset requirement is: the matching degree between the target data table and the target natural language is higher than the matching degree between any other data table in the database and the target natural language; or, the matching degree between the target data table and the target natural language is higher than a preset value, and the number of other data tables in the database with a matching degree higher than the target data table for the target natural language is less than a preset number.

4. The method according to claim 3, further comprising: Extract vectors from the target natural language to obtain the target vector corresponding to the target natural language; extract vectors from the description information of each data table to obtain the description vectors corresponding to each data table one by one; determine the similarity between the description vector and the target vector, and determine the matching degree between each data table and the target natural language according to the similarity.

5. The method according to any one of claims 1 to 4, wherein Based on the target data table in the database, construct a target structured query statement, including: determine target data in the target data table; determine target restriction conditions according to the position description information of the target data in the target data table; construct a target structured query statement according to the target restriction conditions and a preset structured query statement template.

6. A natural language processing method, comprising: Use a second natural language model to process the received natural language and generate a structured query statement corresponding to the natural language; where the second natural language model is trained based on the training data generated by the data generation method described in any one of claims 1 to 5; query in the database based on the structured query statement to obtain the query result corresponding to the natural language.

7. A model training method, comprising: Construct an initial natural language model; Training the initial natural language model with the training data generated by the data generation method according to any one of claims 1 to 6 to obtain a second natural language model, where the second natural language model is used to process the received natural language and generate a corresponding structured query statement.

8. A data generation device, comprising: A structured query statement construction module, configured to construct a target structured query language structured query statement based on a target data table in a database, where the target structured query statement is used to query at least one item of data in the target data table; a natural language generation module, configured to generate a target natural language corresponding to the target structured query statement by using a trained first natural language model; a data generation module, configured to generate training data for training a second natural language model according to the matching degree between the target data table and the target natural language, the target structured query statement, and the target natural language, where the second natural language model is used to process the received natural language and generate a corresponding structured query statement.

9. A natural language processing device, comprising: A generation module, configured to process the received natural language by using a second natural language model and generate a structured query statement corresponding to the natural language; where the second natural language model is trained with the training data generated by the data generation method according to any one of claims 1 to 6; a query module, configured to query in the database based on the structured query statement and obtain a query result corresponding to the natural language.

10. A model training device, comprising: A model construction module, configured to construct an initial natural language model; A training module, configured to train the initial natural language model with the training data generated by the data generation method according to any one of claims 1 to 6 to obtain a second natural language model, where the second natural language model is used to process the received natural language and generate a corresponding structured query statement.

11. An electronic device, including a memory, a processor, and a computer program stored on the memory, where the processor implements the method according to any one of claims 1 - 7 when executing the computer program.

12. A computer-readable storage medium, where a computer program is stored in the computer-readable storage medium, and the computer program implements the method according to any one of claims 1 - 7 when executed by a processor.

13. A computer program product, including a computer program, where the computer program implements the method according to any one of claims 1 - 7 when executed by a processor.

Citation Information

Patent Citations

  • A conversion method and device for a natural language and a structured query language

    CN109933602A

  • Language transformation model training method and device

    CN114168619A

  • Man-machine conversation method and device, equipment and storage medium

    CN114186016A

  • Database natural language query method and device, electronic equipment and storage medium

    CN114328823A

  • Data manufacturing frameworks for synthesizing synthetic training data to facilitate training a natural language to logical form model

    US20230186161A1

Cited By

  • Text2SQL (Structured Query Language) system oriented to actual power scene and control method thereof

    CN121501826A

  • Business data query method and device based on artificial intelligence large language model, computer equipment, readable storage medium and program product

    CN121705328A