Natural language database query method and system based on self-training normal form model
Through the natural language query database method based on the self-training paradigm model, the problems of low accuracy of cross-domain data prediction and high difficulty of data query are solved, and an efficient and accurate data query process is realized.
Patent Information
- Application Number
- CN202510114181.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-24
- Publication Date
- 2025-03-04
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The prior art has low accuracy in cross-domain data prediction and requires a large amount of training data and professionals to convert and clean data, resulting in high difficulty and low efficiency in data query.
The natural language query database method based on the self-trained paradigm model is adopted. By preparing tabular data sets in different fields, building a paradigm model and self-training, a self-trained paradigm model is generated, and the natural language input model is directly used to convert the information of the statement to generate a database query statement.
It achieves high prediction accuracy when dealing with data in other fields, and does not require database professionals to convert and clean data, and directly input natural language to the model to generate query statements, reducing the difficulty of data query and improving efficiency.
Smart Images

Figure CN119557390A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data processing, and in particular relates to a natural language query database method and system based on a self-training paradigm model. Background Art
[0002] With the rapid development of information technology, big data and artificial intelligence technologies are widely used in more and more occasions. Data resources in all walks of life are growing and accumulating at an unprecedented rate. How to mine useful content from these big data has gradually become a widely concerned issue. Among them, there are many forms of application of big language models in various fields, one of which is natural language to database query language. There are currently many technical paths from natural language to query statements, such as using qualified big language models to prompt engineering to obtain answers, using special Text2SQL language models for conversion, and fine-tuning big language models according to databases. However, a large amount of data is generated in business production. These data are generally stored in the database in the form of tables. It is difficult for non-technical personnel to view the information of these data. At the same time, the current application scenarios of artificial intelligence models are limited, and there are two problems:
[0003] 1. After training with data from a certain field, only the data from that field can be used for prediction. This trained model cannot achieve the expected prediction accuracy when dealing with data from other fields.
[0004] 2. If you want to train a model in a field to achieve the expected prediction accuracy, a large amount of training data is currently required. When collecting a large amount of training data, users are generally asked to ask a large number of questions, and then database professionals convert these questions into corresponding query statements, which are then cleaned and organized by database professionals to finally obtain the required large amount of training data. This process increases the difficulty of data query and reduces efficiency. Summary of the invention
[0005] In view of the above-mentioned deficiencies in the prior art, the present application provides a natural language query database method and system based on a self-training paradigm model.
[0006] In the first aspect, the present application proposes a natural language query database method based on a self-training paradigm model, comprising the following steps:
[0007] Prepare tabular data sets in different medical fields, and divide the tabular data sets corresponding to each medical field into equal training sets and optimized training sets according to the amount of data;
[0008] Constructing a paradigm model, copying and initializing the network structure and weight matrix of the paradigm model, inputting the training set into the copied network structure and weight matrix for separate training, recording the gradient of each training, accumulating the gradient to obtain the accumulated gradient corresponding to the training set, and self-training the paradigm model based on the accumulated gradient and the optimized training set to obtain a self-training paradigm model;
[0009] Inputting a natural language example question into the self-training paradigm model to obtain sentence conversion information;
[0010] A database query statement is generated according to the statement conversion information in combination with predefined rules to query the target table data in the database, and the query result is sent to the front end for display to the user.
[0011] In some optional implementations of some embodiments, the construction paradigm model includes: a hidden layer, a self-att layer, a FeedFroward layer, and a LayerNorm layer;
[0012] Among them, the calculation logic of the hidden layer is:
[0013]
[0014] Where t is the input training data, W is the weight matrix of the hidden layer, T represents the transpose operation of the matrix, and the final output x is the vector representation output obtained through the hidden layer;
[0015] The hidden layer calculation result is then divided into three parts: calculated by the self-att layer; calculated by the FeedFroward layer; and added with the calculation results of the FeedFroward layer and the self-att layer. The formula is expressed as:
[0016] y=LayerNorm(x+MLP(x)+Attention(x))
[0017] Among them, Attention represents the self-att layer, MLP represents the FeedFroward layer, and y represents the final output result.
[0018] In some optional implementations of some embodiments, the output hidden layer calculation result is then divided into three parts: calculated by the self-att layer; calculated by the FeedFroward layer; and added to the calculation results of the FeedFroward layer and the self-att layer, including:
[0019] Calculation of self-att layer:
[0020]
[0021] in, , , Represent three different weight matrices, represents transpose, q, k, and v represent the output results of the three linear calculation layers respectively. Next, matrix operations are performed on q, k, and v:
[0022]
[0023] Among them, d is a hyperparameter, set to 64, att_output is the output result calculated by the self-att layer;
[0024] The operation logic of the FeedForward layer is:
[0025]
[0026] in, is the weight matrix of the FeedForward layer, and f is the output of the current calculation:
[0027]
[0028] Among them, e is the natural constant e, It is the output result of the FeedForward layer;
[0029] The calculation process of LayerNorm is:
[0030]
[0031] Among them, μ is the mean, is the variance, is the weight matrix of the LayerNorm layer, is the final result of the LayerNorm layer. Represents the i-th value of att_output.
[0032] In some optional implementations of some embodiments, copying and initializing the network structure and weight matrix of the paradigm model, inputting the training set into the copied network structure and weight matrix for separate training, recording the gradient of each training, and accumulating the gradient to obtain the accumulated gradient corresponding to the training set, includes:
[0033] Initialize the weight matrix of the paradigm model, and copy the network structure of the paradigm model and the initialized weight matrix;
[0034] The training sets in the copied network structure and weight matrix are trained separately. During training, each training set is divided into different training tasks, and then the gradients obtained from each training task are accumulated to obtain accumulated gradients. At this time, only the accumulated gradients are recorded, and the initial weights in the training process are not updated.
[0035] In some optional implementations of some embodiments, the self-training the paradigm model based on the accumulated gradient and the optimized training set to obtain the self-training paradigm model includes:
[0036] The following formula is used to optimize the weight matrix corresponding to the initial weights for weight training:
[0037]
[0038] in, represents the previously initialized weight matrix, lr represents the learning rate, which is a hyperparameter, and t2 represents the cumulative gradient obtained after training with the training set. Intermediate weight matrix;
[0039] With the intermediate weight matrix As a basis, Based on this, training is performed using the optimized training set:
[0040]
[0041] Among them, t3 represents the optimized training set;
[0042] After training, the final copyright weight matrix is obtained , using the final copyright matrix The paradigm model is fine-tuned with small samples to finally obtain a self-training paradigm model.
[0043] In some optional implementations of some embodiments, inputting a natural language example question into the self-training paradigm model to obtain sentence conversion information includes:
[0044] Constructing a natural language example question based on the field name and field content of any table in the table data set;
[0045] Inputting a natural language example question into the self-training paradigm model to obtain sentence conversion information, wherein the sentence conversion information includes first sentence conversion information, second sentence conversion information, third sentence conversion information, fourth sentence conversion information, and fifth sentence conversion information;
[0046] The first sentence conversion information is used to determine which columns of the target table data the answer to the natural language example question needs to be found from;
[0047] The second statement conversion information is used to determine the content of each column in the target table data as a query condition;
[0048] The third statement conversion information is used to determine the AND or OR logic between the query conditions;
[0049] The fourth statement conversion information is used to determine the statistical function to be applied;
[0050] The fifth statement conversion information is used to determine the judgment logic to be applied.
[0051] In some optional implementations of some embodiments, generating a database query statement according to the statement conversion information in combination with a predefined rule to query the target table data in the database, and sending the query result to the front end for display to the user, includes:
[0052] The predefined rules generate the database query statement generation rule: database query statement = Select + slot + from + name of the current data table + where + condition;
[0053] The slot is filled with the content of the fourth statement conversion information extracted by the model, and the condition is supplemented with the content of the fifth statement conversion information extracted by the model. There is at least one condition. When there are multiple conditions, the content of the third statement conversion information extracted by the model is used for connection, and the name of the current data table is obtained through the first statement conversion information.
[0054] The database is queried according to the assembled database query statement, and the query results are sent to the front end for display to the user.
[0055] In the second aspect, the present application proposes a natural language query database system based on a self-training paradigm model, including a data preparation module, a model training module, a model extraction module and a sentence conversion module;
[0056] The data preparation module is used to prepare tabular data sets in different medical fields, and divide the tabular data sets corresponding to each medical field into training sets and optimized training sets of equal size according to the data volume;
[0057] The model training module is used to construct a paradigm model, copy and initialize the network structure and weight matrix of the paradigm model, input the training set into the copied network structure and weight matrix for separate training, record the gradient of each training, accumulate the gradient to obtain the accumulated gradient corresponding to the training set, and self-train the paradigm model based on the accumulated gradient and the optimized training set to obtain a self-training paradigm model;
[0058] The model extraction module is used to input the natural language example question into the self-training paradigm model to obtain sentence conversion information;
[0059] The statement conversion module is used to generate a database query statement according to the statement conversion information combined with predefined rules to query the target table data in the database, and the query result is sent to the front end for display to the user.
[0060] In a third aspect, the present application proposes an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.
[0061] In a fourth aspect, the present application proposes a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.
[0062] Beneficial effects of the present invention:
[0063] The paradigm model obtained through self-training of this method can ensure the accuracy of prediction when dealing with data in other fields; there is no need for database professionals to convert these questions into corresponding query statements, clean or organize them, and the natural language can be directly input into the model to extract sentence conversion information, and the corresponding SQL statements can be generated according to the sentence conversion information and spliced according to the rule template. The SQL statements are used to query in the database and the query results are returned to the user, reducing the difficulty of data query and improving efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] Figure 1 It is the overall flow chart of the present invention.
[0065] Figure 2 This is the software module schematic diagram of this device.
[0066] Figure 3 This is the hardware module schematic of this device. DETAILED DESCRIPTION
[0067] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments described herein; on the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0068] In the first aspect, the present application proposes a natural language query database method based on a self-training paradigm model, such as Figure 1 As shown, the following steps are included:
[0069] S100: preparing tabular data sets in different medical fields, and dividing the tabular data sets corresponding to each medical field into a training set and an optimized training set of equal size according to the data volume;
[0070] Among them, prepare tabular data sets data1, data2, data3, data4, data5, data6, data7, data8, data9, and data10 in different medical fields; the data set corresponding to each field has a total of 30 data items, of which 10 are used as training sets, 10 are used as validation sets, and 10 are used as optimized training sets for further training;
[0071] S200: construct a paradigm model, copy and initialize the network structure and weight matrix of the paradigm model, input the training set into the copied network structure and weight matrix for separate training, record the gradient of each training, accumulate the gradient to obtain the accumulated gradient corresponding to the training set, and self-train the paradigm model based on the accumulated gradient and the optimized training set to obtain a self-training paradigm model;
[0072] In some optional implementations of some embodiments, the construction paradigm model includes: a hidden layer, a self-att layer, a FeedFroward layer and a LayerNorm layer, such as Figure 2 As shown;
[0073] Among them, the calculation logic of the hidden layer is:
[0074]
[0075] Where t is the input training data, W is the weight matrix of the hidden layer, T represents the transpose operation of the matrix, and the final output x is the vector representation output obtained through the hidden layer;
[0076] The hidden layer calculation result is then divided into three parts: calculated by the self-att layer; calculated by the FeedFroward layer; and added with the calculation results of the FeedFroward layer and the self-att layer. The formula is expressed as:
[0077] y=LayerNorm(x+MLP(x)+Attention(x))
[0078] Among them, Attention represents the self-att layer, MLP represents the FeedFroward layer, and y represents the final output result.
[0079] In some optional implementations of some embodiments, the output hidden layer calculation result is then divided into three parts: calculated by the self-att layer; calculated by the FeedFroward layer; and added to the calculation results of the FeedFroward layer and the self-att layer, including:
[0080] Calculation of self-att layer:
[0081]
[0082] in, , , Represent three different weight matrices, represents transpose, q, k, and v represent the output results of the three linear calculation layers respectively. Next, matrix operations are performed on q, k, and v:
[0083]
[0084] Among them, d is a hyperparameter, set to 64, att_output is the output result calculated by the self-att layer;
[0085] The operation logic of the FeedForward layer is:
[0086]
[0087] in, is the weight matrix of the FeedForward layer, and f is the output of the current calculation:
[0088]
[0089] Among them, e is the natural constant e, It is the output result of the FeedForward layer;
[0090] The calculation process of LayerNorm is:
[0091]
[0092] Among them, μ is the mean, is the variance, is the weight matrix of the LayerNorm layer, is the final result of the LayerNorm layer. Represents the i-th value of att_output.
[0093] In some optional implementations of some embodiments, copying and initializing the network structure and weight matrix of the paradigm model, inputting the training set into the copied network structure and weight matrix for separate training, recording the gradient of each training, and accumulating the gradient to obtain the accumulated gradient corresponding to the training set, includes:
[0094] Initialize the weight matrix of the paradigm model, and copy the network structure of the paradigm model and the initialized weight matrix;
[0095] The training sets in the copied network structure and weight matrix are trained separately. During training, each training set is divided into different training tasks, and then the gradients obtained from each training task are accumulated to obtain accumulated gradients. At this time, only the accumulated gradients are recorded, and the initial weights in the training process are not updated.
[0096] In some optional implementations of some embodiments, the self-training the paradigm model based on the accumulated gradient and the optimized training set to obtain the self-training paradigm model includes:
[0097] The following formula is used to optimize the weight matrix corresponding to the initial weights for weight training:
[0098]
[0099] in, represents the previously initialized weight matrix, lr represents the learning rate, which is a hyperparameter, and t2 represents the cumulative gradient obtained after training with the training set. Intermediate weight matrix;
[0100] With the intermediate weight matrix As a basis, Based on this, training is performed using the optimized training set:
[0101]
[0102] Among them, t3 represents the optimized training set;
[0103] After training, the final copyright weight matrix is obtained , using the final copyright matrix Perform small sample fine-tuning training on the paradigm model. It contains all the weight matrices in the paradigm model, and finally obtains the self-training paradigm model.
[0104] Specifically, the self-training method is:
[0105] First, initialize the weight matrix of the model network, and copy the network structure and the initialized weight matrix. We first use the above 10 training sets as training tasks in the copied network structure and weight matrix for separate training. During training, the difference between our training and the general network training process is: here only 10 training tasks are used for separate training, and the gradients of the 10 training tasks are accumulated at the same time, but they are not updated to the copied weight matrix, but the accumulated gradient t2 recorded in this process is recorded.
[0106] After that, we use the following method to obtain the initialization weight matrix for further training based on the previously initialized weight matrix:
[0107]
[0108] in, is the previously initialized weight matrix, lr is the learning rate, is a hyperparameter, t2 is the cumulative gradient obtained after the 10 training tasks calculated in the previous step, and then, using the weight matrix W1 as the basis, Based on this, the 10 items defined at the beginning are used as the optimized training set for further training:
[0109]
[0110] After this step of training is completed, a final version of the weight matrix is obtained , and then directly use this weight for new tasks with new small sample data After a small sample fine-tuning training, It contains all the weight matrices in the paradigm model, and finally obtains the model trained by the self-training paradigm.
[0111] S300: Inputting a natural language example question into the self-training paradigm model to obtain sentence conversion information;
[0112] In some optional implementations of some embodiments, inputting a natural language example question into the self-training paradigm model to obtain sentence conversion information includes:
[0113] Constructing a natural language example question based on the field name and field content of any table in the table data set;
[0114] Inputting a natural language example question into the self-training paradigm model to obtain sentence conversion information, wherein the sentence conversion information includes first sentence conversion information, second sentence conversion information, third sentence conversion information, fourth sentence conversion information, and fifth sentence conversion information;
[0115] The first sentence conversion information is used to determine which columns of the target table data the answer to the natural language example question needs to be found from;
[0116] The second statement conversion information is used to determine the content of each column in the target table data as a query condition;
[0117] The third statement conversion information is used to determine the AND or OR logic between the query conditions;
[0118] The fourth statement conversion information is used to determine the statistical function to be applied;
[0119] The fifth statement conversion information is used to determine the judgment logic to be applied.
[0120] The data used is in a table structure, and the sample data is shown in Table 1:
[0121] Table 1
[0122] NCTId Condition InterventionName Brief Title PostDate NCT05863013 Lung Cancer, Nonsmall Cell|Quality of Life|Physical Disability|Surgery ADL-GlittreTest Application of the ADL-Glittre test before and after lung cancer surgery May 17,2023 NCT02034097 Cancer Foretinib | Erlotinib A study evaluating Foretinib in subjects with non-small cell lung cancer May 19, 2014
[0123] Among them, NCTId, Condition, Intervention Name, BriefTitle, and PostDate are the field names of the table data.
[0124] For these fields and their contents, relevant questions are constructed from the doctor's perspective, and the model converts the questions into query statements. Specifically, the trained model is called and the query statements are finally converted into the following five key information after calculation:
[0125] ① Which columns should be used to find the answer to the current question?
[0126] ② What specific contents in each column are used as query conditions?
[0127] ③ The AND or OR logic between query conditions (when the number of query conditions is greater than 1, determine which kind of logic and, or is between the conditions);
[0128] ④Which statistical functions are used (AVG, MAX, MIN, COUNT, SUM);
[0129] ⑤ Size, equal, fuzzy matching judgment logic (>, <, >=, <=, ==, !=, like);
[0130] Constructed questions, sample answers:
[0131] Question: "What are the relevant experiments on the performance of Foretinib in non-small cell lung cancer since 2014?"
[0132] Model prediction results:
[0133] {"A Study Evaluating Foretinib in Subjects with Non-Small Cell Lung Cancer":"==",
[0134] "2014":">=",
[0135] "cond_conn_op":"and",
[0136] "cond_op":">",
[0137] "agg":""}
[0138] S400: Generate a database query statement according to the statement conversion information and predefined rules to query the target table data in the database, and send the query result to the front end for display to the user.
[0139] In some optional implementations of some embodiments, generating a database query statement according to the statement conversion information in combination with a predefined rule to query the target table data in the database, and sending the query result to the front end for display to the user, includes:
[0140] The predefined rules generate the database query statement generation rule: database query statement = Select + slot + from + name of the current data table + where + condition;
[0141] The slot is filled with the content of the fourth statement conversion information extracted by the model, and the condition is supplemented with the content of the fifth statement conversion information extracted by the model. There is at least one condition. When there are multiple conditions, the content of the third statement conversion information extracted by the model is used for connection, and the name of the current data table is obtained through the first statement conversion information.
[0142] The database is queried according to the assembled database query statement, and the query results are sent to the front end for display to the user.
[0143] Among them, the complete database language is generated according to the following rules, and the defined rules are:
[0144] The database query template used is:
[0145] Select+slot 1+from+name of current data table+where+condition 1, condition 2......
[0146] Slot 1 is filled with the information in the result ④ extracted by the model, and conditions 1, 2, etc. correspond to the information in the result ⑤ extracted by the model. The conditions are connected using the AND or OR logic ③ between the query conditions extracted by the model. The query statement generated by the information in the sample question is:
[0147] SELECT * FROM your_table_name WHERE Brief_Title = 'A Study Evaluating Foretinib in Subjects with Non-Small Cell Lung Cancer' AND PostDate >= '2014-01-01';)
[0148] Specifically, the model prediction information has three fixed keys: "cond_conn_op", "cond_op" and "agg", and the remaining keys are the contents of the corresponding columns.
[0149] For example, "A study evaluating Foretinib in subjects with non-small cell lung cancer" is the content that should correspond to the "Brief Title" column according to the question, and "2014" is the content from the "PostDate" column. The corresponding values are the size and equality judgment logic of these values.
[0150] In the second aspect, the present application proposes a natural language query database system based on a self-training paradigm model, such as Figure 3 As shown, it includes a data preparation module, a model training module, a model extraction module and a sentence conversion module;
[0151] The data preparation module is used to prepare tabular data sets in different medical fields, and divide the tabular data sets corresponding to each medical field into training sets and optimized training sets of equal size according to the data volume;
[0152] The model training module is used to construct a paradigm model, copy and initialize the network structure and weight matrix of the paradigm model, input the training set into the copied network structure and weight matrix for separate training, record the gradient of each training, accumulate the gradient to obtain the accumulated gradient corresponding to the training set, and self-train the paradigm model based on the accumulated gradient and the optimized training set to obtain a self-training paradigm model;
[0153] The model extraction module is used to input the natural language example question into the self-training paradigm model to obtain sentence conversion information;
[0154] The statement conversion module is used to generate a database query statement according to the statement conversion information combined with predefined rules to query the target table data in the database, and the query result is sent to the front end for display to the user.
[0155] In a third aspect, the present application proposes an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.
[0156] In a fourth aspect, the present application proposes a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.
[0157] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0158] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0159] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this disclosure.
[0160] In the embodiments provided in the present disclosure, it should be understood that the disclosed apparatus / computer equipment and methods can be implemented in other ways. For example, the apparatus / computer equipment embodiments described above are merely schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation. Multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, indirect coupling or communication connection of the apparatus or unit, which may be electrical, mechanical or other forms.
[0161] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0162] In addition, each functional unit in each embodiment of the present disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0163] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present disclosure implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. The computer program may include computer program code, and the computer program code may be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying computer program code, recording medium, U disk, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electric carrier signals and telecommunication signals.
[0164] The above are only preferred implementations of the present invention. It should be pointed out that a number of modifications and improved technical solutions made by those skilled in the art without departing from the technical solution should also be deemed to fall within the scope of protection required by the claims.
Claims
1. A natural language query database method based on a self-training paradigm model, characterized in that: The following steps are involved: Prepare tabular data sets in different medical fields, and divide the tabular data sets corresponding to each medical field into equal training sets and optimized training sets according to the amount of data; Constructing a paradigm model, copying and initializing the network structure and weight matrix of the paradigm model, inputting the training set into the copied network structure and weight matrix for separate training, recording the gradient of each training, accumulating the gradient to obtain the accumulated gradient corresponding to the training set, and self-training the paradigm model based on the accumulated gradient and the optimized training set to obtain a self-training paradigm model; Inputting a natural language example question into the self-training paradigm model to obtain sentence conversion information; A database query statement is generated according to the statement conversion information in combination with predefined rules to query the target table data in the database, and the query result is sent to the front end for display to the user.
2. The method according to claim 1, characterized in that: The construction paradigm model includes: a hidden layer, a self-att layer, a FeedFroward layer and a LayerNorm layer; Among them, the calculation logic of the hidden layer is: Where t is the input training data, W is the weight matrix of the hidden layer, T represents the transpose operation of the matrix, and the final output x is the vector representation output obtained through the hidden layer; The hidden layer calculation result is then divided into three parts: calculated by the self-att layer; calculated by the FeedFroward layer; and added with the calculation results of the FeedFroward layer and the self-att layer. The formula is expressed as: y=LayerNorm(x+MLP(x)+Attention(x)) Among them, Attention represents the self-att layer, MLP represents the FeedFroward layer, and y represents the final output result.
3. The method according to claim 2, characterized in that: The output hidden layer calculation result is then divided into three parts: calculated by the self-att layer; calculated by the FeedFroward layer; Adding the calculation results of the FeedFroward layer and the self-att layer includes: Calculation of self-att layer: in, , , Represent three different weight matrices, represents transpose, q, k, and v represent the output results of the three linear calculation layers respectively. Next, matrix operations are performed on q, k, and v: Among them, d is a hyperparameter, set to 64, att_output is the output result calculated by the self-att layer; The operation logic of the FeedForward layer is: in, is the weight matrix of the FeedForward layer, and f is the output of the current calculation: Among them, e is the natural constant e, It is the output result of the FeedForward layer; The calculation process of LayerNorm is: Among them, μ is the mean, is the variance, is the weight matrix of the LayerNorm layer, is the final result of the LayerNorm layer. Represents the i-th value of att_output.
4. The method according to claim 3, characterized in that: The copying and initializing of the network structure and weight matrix of the paradigm model, inputting the training set into the copied network structure and weight matrix for separate training, recording the gradient of each training, and accumulating the gradient to obtain the accumulated gradient corresponding to the training set, includes: Initialize the weight matrix of the paradigm model, and copy the network structure of the paradigm model and the initialized weight matrix; The training sets in the copied network structure and weight matrix are trained separately. During training, each training set is divided into different training tasks, and then the gradients obtained from each training task are accumulated to obtain accumulated gradients. At this time, only the accumulated gradients are recorded, and the initial weights in the training process are not updated.
5. The method according to claim 4, characterized in that: The self-training of the paradigm model based on the accumulated gradient and the optimized training set to obtain the self-training paradigm model includes: The following formula is used to optimize the weight matrix corresponding to the initial weights for weight training: in, represents the previously initialized weight matrix, lr represents the learning rate, which is a hyperparameter, and t2 represents the cumulative gradient obtained after training with the training set. Intermediate weight matrix; With the intermediate weight matrix As a basis, Based on this, training is performed using the optimized training set: Among them, t3 represents the optimized training set; After training, the final copyright weight matrix is obtained , using the final copyright matrix The paradigm model is fine-tuned with small samples to finally obtain a self-training paradigm model.
6. The method according to claim 5, characterized in that: The step of inputting a natural language example question into the self-training paradigm model to obtain sentence conversion information includes: Constructing a natural language example question based on the field name and field content of any table in the table data set; Inputting a natural language example question into the self-training paradigm model to obtain sentence conversion information, wherein the sentence conversion information includes first sentence conversion information, second sentence conversion information, third sentence conversion information, fourth sentence conversion information, and fifth sentence conversion information; The first sentence conversion information is used to determine which columns of the target table data the answer to the natural language example question needs to be found from; The second statement conversion information is used to determine the content of each column in the target table data as a query condition; The third statement conversion information is used to determine the AND or OR logic between the query conditions; The fourth statement conversion information is used to determine the statistical function to be applied; The fifth statement conversion information is used to determine the judgment logic to be applied.
7. The method according to claim 6, characterized in that: The step of generating a database query statement based on the statement conversion information and predefined rules to query the target table data in the database, and sending the query result to the front end for display to the user, includes: The predefined rules generate the database query statement generation rule: database query statement = Select + slot + from + name of the current data table + where + condition; The slot is filled with the content of the fourth statement conversion information extracted by the model, and the condition is supplemented with the content of the fifth statement conversion information extracted by the model. There is at least one condition. When there are multiple conditions, the content of the third statement conversion information extracted by the model is used for connection, and the name of the current data table is obtained through the first statement conversion information. The database is queried according to the assembled database query statement, and the query results are sent to the front end for display to the user.
8. A natural language query database system based on a self-training paradigm model, characterized by: It includes data preparation module, model training module, model extraction module and sentence conversion module; The data preparation module is used to prepare tabular data sets in different medical fields, and divide the tabular data sets corresponding to each medical field into training sets and optimized training sets of equal size according to the data volume; The model training module is used to construct a paradigm model, copy and initialize the network structure and weight matrix of the paradigm model, input the training set into the copied network structure and weight matrix for separate training, record the gradient of each training, accumulate the gradient to obtain the accumulated gradient corresponding to the training set, and self-train the paradigm model based on the accumulated gradient and the optimized training set to obtain a self-training paradigm model; The model extraction module is used to input the natural language example question into the self-training paradigm model to obtain sentence conversion information; The statement conversion module is used to generate a database query statement according to the statement conversion information combined with predefined rules to query the target table data in the database, and the query result is sent to the front end for display to the user.
9. An electronic 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, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Language representation model training method and device
CN113011184A
Multi-round dialogue method and system for jointly optimizing reply enhancement and span prediction
CN116361437A
Structured query language generation method and device and structured query language verification method and device
CN117667991A
Multi-modal false news detection method based on multi-level fusion and attention mechanism
CN117688509A
Machine translation using neural network models
US20200034436A1
Cited By
Large model training method for query conversion, database query method, computer equipment and computer readable storage medium
CN120123367A
Large model training method for query conversion, database query method, computer device, and computer-readable storage medium
CN120123367B