Table question and answer method and device, medium and product
By automatically processing user questions and table information through NL2SQL and NLG models, the inefficiency and error-prone manual extraction of indicator information in bank credit business is solved, and efficient and accurate table question and answering is achieved.
Patent Information
- Application Number
- CN202510928937.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-07
- Publication Date
- 2025-10-17
AI Technical Summary
In banking credit business, existing technical personnel need to manually extract indicator information from complex reports, resulting in high development costs, low efficiency, prone to errors, and inconsistent understanding among different personnel.
The NL2SQL model converts user questions into SQL statements, and the NLG model generates answers to automatically extract and interpret table information.
It improves the efficiency and accuracy of form question and answer, reduces costs, and ensures the consistency and accuracy of results.
Smart Images

Figure CN120804262A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the technical field of computer technology, and particularly relate to a table question and answer method, device, medium and product. BACKGROUND
[0002] In bank credit business, a large number of index statistics, performance appraisal and other report related work are possessed by personnel at various levels. At present, a large amount of credit source table data is processed into various reports according to certain complex rules by technical personnel, and personnel at various levels obtain the required index information from various reports based on their own experience and professional knowledge. The above-mentioned method has two major drawbacks, one is that the development cost of report processing is high, which cannot meet the flexible and changeable business needs, and the other is that the manual reading of credit business report has low efficiency, is easy to make mistakes, and different personnel have different understanding of the report. SUMMARY
[0003] Embodiments of the present application provide a table question and answer method, device, medium and product to improve the efficiency and accuracy of table question and answer and reduce the cost of table question and answer.
[0004] According to an aspect of the present application, a table question and answer method is provided, comprising:
[0005] obtaining identification information of a user input question and a target table;
[0006] generating an input text according to the user input question and the identification information of the target table;
[0007] inputting the input text into an NL2SQL model to obtain a target SQL statement;
[0008] executing the target SQL statement to obtain an execution result;
[0009] inputting the execution result and the user input question into an NLG model to obtain an output answer corresponding to the user input question.
[0010] According to another aspect of the present application, an electronic device is provided, comprising:
[0011] at least one processor; and
[0012] a memory in communication connection with the at least one processor; wherein
[0013] the memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to execute the table question and answer method according to any one of the embodiments of the present application.
[0014] According to another aspect of the present application, there is provided a computer readable storage medium storing computer instructions for causing a processor to implement the table question and answer method according to any of the embodiments of the present application when executed.
[0015] According to another aspect of the present application, there is provided a computer program product, which, when executed by a processor, implements the table question and answer method according to any of the embodiments of the present application.
[0016] The embodiments of the present application can obtain the user input question and the identification information of the target table, generate input text according to the user input question and the identification information of the target table, input the input text into an NL2SQL model to obtain a target SQL statement, execute the target SQL statement to obtain an execution result, and input the execution result and the user input question into an NLG model to obtain an output answer corresponding to the user input question, thereby solving the problems of high cost, low efficiency and easy error in obtaining required index information from various reports based on the experience and professional knowledge of business personnel, improving the table question and answer efficiency and accuracy, and reducing the table question and answer cost.
[0017] It should be understood that the content described in this part is not intended to identify key or important features of the embodiments of the present application, nor to limit the scope of the present application. Other features of the present application will become apparent from the following description. BRIEF DESCRIPTION OF DRAWINGS
[0018] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments. It should be understood that the following drawings only show some of the embodiments of the present application, and therefore should not be regarded as limiting the scope. For those skilled in the art, other related drawings can also be obtained without creative labor.
[0019] Figure 1 is a flow chart of a table question and answer method in the embodiments of the present application;
[0020] Figure 2 is a schematic diagram of injecting noise into a first word sequence in the embodiments of the present application;
[0021] Figure 3 is a structural schematic diagram of a table question and answer device in the embodiments of the present application;
[0022] Figure 4 is a structural schematic diagram of an electronic device in the embodiments of the present application. DETAILED DESCRIPTION
[0023] In the following, the technical solutions in the embodiments of the present application will be described clearly and completely in conjunction with the accompanying drawings of the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all the other embodiments obtained by a person of ordinary skill in the art without creative effort should belong to the scope of protection of the present application.
[0024] It should be noted that the terms "first", "second" and the like in the description and claims of the present application and the above-mentioned accompanying drawings are used to distinguish similar objects, and do not necessarily indicate a specific order or sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device including a series of steps or units need not be limited to those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0025] It can be understood that, before using the technical solutions disclosed in the embodiments of the present application, the type, scope of use, use scenario and the like of the personal information involved in the present application should be informed to the user and the authorization of the user should be obtained in accordance with relevant laws and regulations.
[0026] Embodiment one
[0027] Figure 1 A flowchart of a table question and answer method provided by the embodiments of the present application, the present embodiment can be applicable to the case of table question and answer, and the method can be executed by a table question and answer device in the embodiments of the present application. The device can be realized in the form of software and / or hardware, as shown in the figure, and the method specifically includes the following steps: Figure 1
[0028] S110, obtaining the identification information of the target table and the user input question.
[0029] In the present embodiment, the target table can be a credit table. The identification information of the target table can be the name of the target table, or the storage address of the target table. The identification information of the target table can be obtained in the following ways: the pre-stored identification information of the target table, the identification information of the target table corresponding to the key information in the user input question, or the identification information of the target table input by the user at the same time of inputting the question. The present embodiment does not limit the above.
[0030] In this embodiment, the user input question can be a user input question related to the credit table. The user input question is a user input natural language.
[0031] S120, generating an input text according to the user input question and the identification information of the target table.
[0032] In this embodiment, the format of the input text is a word sequence.
[0033] In this embodiment, the way of generating the input text according to the user input question and the identification information of the target table can be: determining the target table based on the identification information of the target table. Adding column names in the target table to column marks, splicing to obtain a table word sequence, splicing each word in the user input question to obtain a user input question word sequence, splicing the table word sequence and the user input question word sequence to obtain the input text, and the table word sequence and the user input question word sequence are spliced by a separator.
[0034] S130, inputting the input text into the NL2SQL model to obtain a target SQL statement.
[0035] In this embodiment, the NL2SQL model is obtained by iteratively training a BART model based on a training sample set.
[0036] Optionally, the training process of the NL2SQL model comprises:
[0037] Obtaining a credit table question and answer historical data set, wherein the credit table question and answer historical data set comprises a table, a question and a query statement corresponding to the question.
[0038] In this embodiment, the credit table question and answer historical data set covers a large number of professional terms, key indicators and question and answer preferences in the field, and is more focused on the credit field than the general table question and answer data set. It can make the model learn the semantic knowledge in the field, and can improve the generalization ability of the NL2SQL model and the NLG model in the target field.
[0039] In this embodiment, the question is a business question, and the table is a business table. It should be noted that in order to adapt to the characteristics of business tables and business questions in the credit field, daily operation data (including real business tables and business questions) in the system are used as data sources and are labeled to form query statements and answers corresponding to the questions. The annotation is shown in Table 1, for example:
[0040] Table 1
[0041]
[0042]
[0043] For example, the user raises a business question: "What is the daily average balance of financing of branch a on March 1, 2025?", after processing by the NL2SQL model provided by the embodiment of the application, the output query statement is "SELECT DAILY_AVG_BALANCE FROM FINAN_BUSI_PERFROMANCE WHERE ORG_NAME = 'a' AND DATA_DATE = '20250301'", after executing the above SQL statement, the execution result "c" is obtained, finally, after processing by the NLG model, the final output answer is "On March 1, 2025, the daily average balance of financing of branch a is c yuan".
[0044] After adding column labels to all column names in the table, splicing is performed to obtain a first word sequence.
[0045] Splicing each word in the question obtains a second word sequence.
[0046] In this embodiment, the question Q = {q1, … q |Q|} represents a word sequence, the table S = {c1, … c |S|} is composed of a group of table columns, where each column c i = {c1, … c |ci|} is a word sequence, Y = {y1, … y |Y|} represents the original SQL sequence at the token level, and A = {a1, … a |A|} represents the word sequence of the final answer.
[0047] In a specific example, in order to process the natural language question Q and the table schema S using the BART model, it needs to be formatted and preprocessed. For the table S, a special mark (<col i >) is added before each column name in the table, i is the i-th column in the table. All columns in the table are connected together to obtain the representation sequence of the table, and then it is connected with the natural language question sequence Q to form the input I of the model. For example: <col1>mechanism <col2>point balance <col3>Daily balance <col4>Data date <sep>What is the average daily balance of the branch's financing on March 1, 2025?
[0048] The first word sequence and the second word sequence are processed to obtain a target word sequence.
[0049] In this embodiment, the manner in which the first word sequence and the second word sequence are processed to obtain a target word sequence can be that the first word sequence and the second word sequence are spliced to obtain a target word sequence, and the first word sequence and the second word sequence are spliced by a separator. It can also be that noise is injected into the first word sequence to obtain a first word sequence after noise injection, and the first word sequence after noise injection and the second word sequence are spliced to obtain a target word sequence, wherein injecting noise into the first word sequence includes at least one of the following: adjusting the connection order of a column of a table in the first word sequence; deleting at least one column of a table in the first word sequence; and adding a column of a table in the first word sequence. Or it can be that noise is injected into the second word sequence to obtain a second word sequence after noise injection, and the first word sequence and the second word sequence after noise injection are spliced to obtain a target word sequence, wherein injecting noise into the second word sequence includes adjusting the order of entities in the second word sequence to obtain a second word sequence after noise injection, and the entities include at least one word.
[0050] The query statement is processed to obtain a query statement sequence.
[0051] In this embodiment, the manner in which the query statement is processed to obtain a query statement sequence can be that the column name and value in the query statement are added with a target mark and then spliced to obtain a query statement sequence. It can also be that the query statement is modified according to the first word sequence after noise injection to obtain a modified query statement, and the column name and value in the modified query statement are added with a target mark and then spliced to obtain a query statement sequence. It can also be that noise is injected into the query statement to obtain a query statement after noise injection, and the column name and value in the query statement after noise injection are added with a target mark and then spliced to obtain a query statement sequence, wherein injecting noise into the query statement includes adjusting the order of entities in the query statement to obtain a query statement after noise injection.
[0052] According to the target word sequence and the query statement sequence, a training sample set is generated.
[0053] In the embodiment, the training sample set can be generated according to the target word sequence and the query sentence sequence in the following manner: taking the target word sequence as an input sample, taking the query sentence sequence as an output corresponding to the input sample, obtaining a first sample set, taking the query sentence sequence as an input, taking the target word sequence as an output corresponding to the input sample, obtaining a second sample set, and generating the training sample set according to the first sample set and the second sample set.
[0054] The BART model is trained based on the training sample set to obtain an NL2SQL model.
[0055] In the embodiment, the BART model can be trained based on the training sample set to obtain an NL2SQL model in the following manner: generating a target vocabulary set according to all column names of the table, a corpus, and keywords in a structured query language; and training the BART model based on the training sample set and the target vocabulary set to obtain the NL2SQL model.
[0056] In the embodiment, the pre-training language model (Bidirectional and Auto-Regressive Transformers, BART) model is a pre-training language model combining the advantages of an auto-encoder and an auto-regressive model. The BART is based on a Transformer architecture and mainly consists of two parts: a first encoder (Encoder) that adopts a bidirectional Transformer to capture bidirectional context information of a text, and a first decoder (Decoder) that adopts an auto-regressive Transformer to generate a text in sequence.
[0057] Optionally, the BART model comprises the first encoder and the first decoder.
[0058] The BART model is trained based on the training sample set to obtain an NL2SQL model, including:
[0059] The target vocabulary set is generated according to all column names of the table, a corpus, and keywords in a structured query language.
[0060] In the embodiment, the keywords in the structured query language can be SQL keywords, which are core components of SQL syntax and are used to define the structure and behavior of a query. For example, the keywords in the structured query language can be SELECT, WHERE, MAX, and the like.
[0061] In the embodiment, based on the BART model, the NL2SQL task is modeled as a sequence-to-sequence (S2S) generation task, and an autoregressive generation method is used to predict the tokens in the target SQL sequence one by one. In the training process, various pattern enhancement methods are introduced, and the model is trained to recover the original sequence from the noise input or predict the damaged output, which is trained together with the S2S task.
[0062] It should be noted that in the process of generating the query sentence sequence, the words can be selected from the target vocabulary set, or the words can be directed to the target word sequence.
[0063] The target word sequence in the training sample set is input into the first encoder to obtain a hidden state sequence corresponding to the target word sequence.
[0064] In the embodiment, for each input sequence I, it is first encoded into a hidden state H using a Transformer: H = Encoder (E), where E = Embedding (I).
[0065] The hidden state sequence corresponding to the target word sequence and the target vocabulary set are input into the first decoder to obtain a predicted query sentence sequence.
[0066] In the embodiment, the hidden state sequence corresponding to the target word sequence and the target vocabulary set are input into the first decoder to obtain the predicted query sentence sequence in the following manner:
[0067] The query sentence sequence in the training sample set is input into the first encoder to obtain a hidden state sequence corresponding to the query sentence sequence;
[0068] The hidden state sequence corresponding to the query sentence sequence and the target vocabulary set are input into the first decoder to obtain a predicted word sequence;
[0069] According to the difference between the predicted query sentence sequence and the query sentence sequence, and the difference between the predicted word sequence and the target word sequence, the parameters of the BART model are trained to obtain an NL2SQL model.
[0070] Optionally, inputting the hidden state sequence corresponding to the target word sequence and the target vocabulary set into the first decoder to obtain the predicted query sentence sequence comprises:
[0071] Obtain an attention score between each hidden state in the hidden state sequence and each word in the target vocabulary set;
[0072] Obtain an attention score between each hidden state in the hidden state sequence and the hidden state sequence;
[0073] determine a mixture score according to the attention score between each hidden state in the hidden state sequence and each word in the target vocabulary set and the attention score between each hidden state in the hidden state sequence and the hidden state sequence;
[0074] determine an attention weight matrix according to the mixture score;
[0075] determine a predicted query sentence sequence according to the attention weight matrix.
[0076] In this embodiment, in the BART decoder, the Transformer is used to generate the hidden state h t at step t based on the previously generated sequence and the encoding output. t The attention score between each word in the target vocabulary set V is calculated as follows:
[0077]
[0078] where W1 is the weight matrix of the BART decoder (trainable), d k is a scaling factor.
[0079] At the same time, the attention score between the hidden state h t and the hidden state sequence H is calculated as follows:
[0080]
[0081] where |input| is the length of the input sequence, and W2 is the weight matrix of the BART decoder (trainable). scores vocab and scores source are directly connected to obtain the mixture score:
[0082] scores hybrid = {s1,..., si, i1,..., ii}; |V| |input|
[0083] Finally, the final probability distribution P is calculated as follows:
[0084] P = softmax(scores hybrid );
[0085] P can be used for loss function optimization during training and generation of the next token during inference, respectively.
[0086] Optionally, the first word sequence and the second word sequence are processed to obtain a target word sequence, including at least one of the following:
[0087] The first word sequence and the second word sequence are spliced to obtain a target word sequence, and the first word sequence and the second word sequence are spliced by a separator.
[0088] In the embodiment, the separator can be <sep>.
[0089] Noise is injected into the first word sequence to obtain a first word sequence after the noise is injected, and the first word sequence after the noise is injected and the second word sequence are spliced to obtain a target word sequence, wherein the noise injection into the first word sequence includes at least one of the following: adjusting the connection order of columns of a table in the first word sequence; deleting at least one column of a table in the first word sequence; and adding columns to a table in the first word sequence.
[0090] In this embodiment, multiple pattern enhancement methods are introduced during the training process of the NL2SQL model. The model is trained to recover the original sequence from the noisy input or predict the damaged output, and is trained together with the NL2SQL task.
[0091] In this embodiment, a method of increasing the columns of the table in the first word sequence may be: adding columns in other tables to the table in the first word sequence.
[0092] In this embodiment, three noise injection operations are performed to destroy the table S in the first word sequence:
[0093] 1. Rearrange: Rearrange the connection order of table columns during table formatting;
[0094] 2. Column deletion: For each table column, use P drop The probability of deleting columns;
[0095] 3. Column addition: with probability P add Extract a column from another table in the training database and insert it into the table S in the first word sequence.
[0096] In a specific example, Figure 2 As shown, the rearrangement method can be: <col0>and <col2>interchangeable. The manner of column deletion can be: deletion <col0>,Will <col0>The columns are replaced by <unk>Tag. The column added can be in the form of: adding <col4>.
[0097] In all three operations, the order of the special separator markers remains unchanged, so the corresponding anonymous entities in the SQL query should be updated synchronously. If a column entity mentioned in the SQL query is deleted, we replace the corresponding column marker in the SQL with a special <unk>The label is added to make up for the lack of schema information. Through this modification of the schema and SQL sequence, the model needs to identify the schema column that is truly related to the natural language question, thereby obtaining better generalization ability.
[0098] Noise is injected into the second word sequence to obtain a second word sequence after noise injection. The first word sequence and the second sequence after noise injection are spliced to obtain a target sequence. Injecting noise into the second word sequence includes adjusting the order of entities in the second word sequence to obtain a second word sequence after noise injection, and the entities include at least one word.
[0099] In one specific example, the question is: What is the financing daily balance of branch a on March 1, 2025? The order of the entities "branch a" and "financing daily balance" in the question is adjusted, and the adjusted question is: What is the financing daily balance of a branch on March 1, 2025?
[0100] In this embodiment, the manner of obtaining the entity in the first word sequence can be: performing entity recognition on the first word sequence to obtain the entity in the first word sequence.
[0101] In this embodiment, a plurality of schema enhancement methods are introduced into the NL2SQL model as additional training tasks of the model, and the model is trained to recover the original sequence from the noise or predict the output, so as to give the model the ability to distinguish similar fields and improve the robustness of the model.
[0102] Optionally, the query sentence is processed to obtain a query sentence sequence, including at least one of the following:
[0103] The column name and value in the query sentence are added with target labels and spliced to obtain the query sentence sequence.
[0104] In this embodiment, the target label includes a first label and a column label in a table.
[0105] In one specific example, after adding the target label to the column name and value in the query sentence, the manner of splicing to obtain the query sentence sequence can be: adding a first label "| " to the left and right of the column name and value in the SQL query sentence; replacing the column name with the corresponding column label in the table <coli>; add spaces between punctuation and words.
[0106] In one specific example, the input to the BART model is:
[0107] <col0>ORG <col1>TIME PT BLC <col2>DAILY_A_VG_BLC <col3>DATA_DATE… <sep>What is the average daily balance of the financing of the branch on March 1, 2025?
[0108] The output of the BART model is: SELECT <col2>| FROM | table | WHERE | <col0>| = | a column | AND <col3>| = | 20250301 |.
[0109] It should be noted that the input / output formatting process can improve the consistency between the model input and output, and help identify the table columns.
[0110] According to the first word sequence after injecting noise, the query statement is modified to obtain a modified query statement, the column name and value in the modified query statement are added with a target mark, and then spliced to obtain a query statement sequence.
[0111] The query statement is injected with noise to obtain a query statement after injecting noise, the column name and value in the query statement after injecting noise are added with a target mark, and then spliced to obtain a query statement sequence, wherein injecting noise into the query statement comprises: adjusting the order of the entities in the query statement to obtain a query statement after injecting noise.
[0112] For example, the query statement is: SELECT| <col2>| FROM | table | WHERE | <col0>| = | a column | AND <col3>| = | 20250301 |, the query statement after injecting noise is: SELECT <col2>| FROM | table | WHERE | <col0>| = | 20250301 | AND | <col3>| = |a row|.
[0113] In the embodiment, when the order of the entities in the reordered query statement is reordered, the table S is kept unchanged, the enhanced method can train the model to capture the internal relationship between different entities, thereby helping the alignment of natural language questions and tables, and enhancing the effect of the model.
[0114] In the embodiment of the application, a plurality of mode enhancement methods are introduced into the NL2SQL model as additional training tasks of the model, and the model is trained in a self-supervised manner to reconstruct the query sequence in a correct entity order, so as to train the model to capture the internal relationship between different entities and help improve the accuracy and robustness of the model.
[0115] In a specific example, X = {(Qi, Si, Yi)}, wherein Qi is a natural language question corresponding to the i-th sample. Si is a table corresponding to the i-th sample. Yi is a target SQL statement corresponding to the i-th sample. For each training sample (Qi, Si, Yi), initialize the source sequence and the target sequence: assign the natural language question Qi to the source sequence Tsrc (source), and assign the target SQL statement Yi to the target sequence Ttgt (target). Perform an erosion operation (deletion, addition or rearrangement) on the target sequence Ttgt and the table Si, and modify the Ttgt target sequence accordingly (for example, if a column in the table is discarded, the corresponding column in the SQL statement is replaced with <unk>The reordering operation (Shuffle) is performed with probability Pshuffle (i.e., there is a probability of reordering), and the source and target sequences are swapped with probability Pswap. That is, the natural language question that was originally the source sequence can become the target SQL statement, and the target SQL statement that was originally the target sequence can become the natural language question. The target sequence is re-ordered (Shuffle) by randomly shuffling the order of the entities in the sequence (e.g., column names, values, etc.). The type of the target sequence Ttgt is determined by the function SeqType: if the target sequence is of the SQL statement type (i.e., Ttype = SQL), then the prefix Tprefix = <2sql> is set, and if the target sequence is of the natural language type, i.e., NL, the prefix Tprefix = <2nl> is set. The final source sequence is constructed: Tsrc = Tprefix + Tsrc + Si, i.e., the prefix, the current source sequence, and the schema sequence are concatenated. The model is trained using this source sequence Tsrc and the target sequence Ttgt.
[0116] It should be noted that the swap operation is to enable the model to handle bidirectional tasks: both generating SQL from natural language and generating natural language from SQL (i.e., reconstruction). When swapping occurs, the original target SQL becomes the source, and the original source (natural language question) becomes the target. The new target (i.e., the original natural language question) is then re-ordered, and the model is required to recover the original natural language question (i.e., a self-supervised task). If no swapping occurs, then the target sequence is still SQL, and we re-order the SQL, and the model is required to recover the original SQL (self-supervised task). The prefix <2sql> and <2nl> tell the model what type of sequence to generate.
[0117] Tsrc is the input sequence in training, which can be composed of either a natural language question (Q) or a SQL statement (Y), depending on whether swapping occurs, and is finally augmented with a prefix and a table. Ttgt is the target sequence in training, which can be either the original SQL (Y) or natural language question (Q), or modified by the reordering operation. Si is the table, which can be modified by the eroding operation. Ttype is the type of the target sequence (SQL or NL), which is used to determine the prefix. Tprefix is a special token that indicates the type of task the model is required to perform (generate SQL or generate natural language).
[0118] Training objective: The model needs to predict the target sequence Ttgt (which can be SQL or natural language, which can be reordered or modified by the erosion operation) according to the input sequence Tsrc (which contains the prefix, original or reordered sequence and schema). In this way, the model learns: 1. Main task: text-to-SQL generation (or SQL-to-text generation when swapping occurs). 2. Self-supervised task: recover the reordered sequence (natural language or SQL). 3. Robustness to schema changes: through the erosion operation, the model learns to handle noise in the schema (such as missing columns, additional columns, etc.).
[0119] S140, executing the target SQL statement to obtain an execution result.
[0120] In this embodiment, after generating the SQL, the SQL statement executor is used to execute the query in the table to obtain the query target value of the user, but the obtained result is still a table, which is not conducive to reading by the user, and therefore, an NLG model needs to be additionally constructed for the table question and answer task.
[0121] S150, inputting the execution result and the user input question into the NLG model to obtain an output answer corresponding to the user input question.
[0122] Optionally, the credit table question and answer dataset further includes an execution result of the query statement and an output answer corresponding to the question.
[0123] The training process of the NLG model includes:
[0124] Inputting the execution result of the query statement and the question into the T5 model to obtain a predicted output answer.
[0125] Training the T5 model according to the difference between the predicted output answer and the output answer corresponding to the question to obtain the NLG model.
[0126] In the embodiment of the application, the T5 model is used to construct the NLG model, and the model is fine-tuned based on the constructed credit field characteristic dataset, so that the model has stronger generalization capability for special jargon in the field, thereby improving the model effect.
[0127] The result set (which is still a structured table) obtained after the SQL statement executor executes the SQL statement is serialized into a vector representation R. After being concatenated with the question Q and converted into a word embedding, it is used as the input of the T5 model. The encoder is composed of multiple layers of Transformer encoders. The decoder generates an output sequence Y according to the output of the encoder, and the decoding process is autoregressive, that is, it is generated word by word. The initial input of the decoder is a special token <s>. For the t-th time step, the decoder generates a probability distribution over the next word based on the current input and the encoder output: p(y t |y <t , H) = softmax(Decoder(y <t , H)), the most probable word y t is selected from the probability distribution and y t is used as input for the next time step until the decoder outputs an end-of-sequence token< / s> or reaches the maximum sequence length.
[0128] In this embodiment, from the perspective of task decomposition, table question answering mainly includes two core steps, one is to convert the user's question into a SQL statement, that is, the NL2SQL technology, so as to extract the answer from the table; the second is to feed back the extracted answer to the user in the form of natural language, that is, the NLG technology. Based on the above two points, first, based on a large amount of real table data in the credit field, question data, annotated corresponding SQL query statements and question answers, a high-quality, large-scale supervised credit table question answering data set is formed, which covers a large number of professional terms and key indicators in the field, so as to improve the generalization ability of the NL2SQL model and the NLG model in the target field; secondly, in the NL2SQL model, a variety of mode enhancement methods are introduced as additional training tasks of the model, and the model is trained to recover the original sequence or predict the output from the noise, so as to give the model the ability to distinguish similar fields and improve the robustness of the model.
[0129] Embodiment two
[0130] Figure 3 A structural schematic diagram of a table question answering device provided by the embodiment of the present application. The embodiment can be applicable to the case of table question answering. The device can be realized in the form of software and / or hardware. The device can be integrated in any device providing table question answering function, such as a computer, a server, a mobile phone, a tablet computer, a smart speaker, etc. Figure 3 As shown in the figure, the table question answering device specifically comprises an acquisition module 310, an input text generation module 320, a target SQL statement determination module 330, an execution module 340 and an output answer determination module 350.
[0131] The acquisition module is configured to acquire the user input question and the identification information of the target table.
[0132] The input text generation module is configured to generate an input text according to the user input question and the identification information of the target table.
[0133] The target SQL statement determination module is configured to input the input text into an NL2SQL model to obtain a target SQL statement.
[0134] The execution module is configured to execute the target SQL statement to obtain an execution result.
[0135] The output answer determination module is configured to input the execution result and the user input question into an NLG model to obtain an output answer corresponding to the user input question.
[0136] The above product can execute the method provided by any embodiment of the present application, and has the corresponding function modules and beneficial effects of the execution method.
[0137] Embodiment three
[0138] Figure 4 A structural diagram of an electronic device 10 that can be used to implement embodiments of the present application is shown. The electronic device is intended to represent various forms of digital computers, such as laptops, desktops, tablets, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular telephones, smartphones, wearable devices (e.g., headsets, glasses, watches, etc.), and other similar computing devices. The components shown here, their connections and relationships, and their functions, are meant to be examples only, and are not meant to limit implementations of the present application described and / or claimed in this document.
[0139] As shown, Figure 4 The electronic device 10 includes at least one processor 11, and a memory, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., communicatively connected to the at least one processor 11, where the memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes according to the computer programs stored in the read-only memory (ROM) 12 or loaded from the storage unit 18 into the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0140] Various components in the electronic device 10 are connected to the I / O interface 15, including an input unit 16, such as a keyboard, a mouse, etc., an output unit 17, such as various types of displays, speakers, etc., a storage unit 18, such as a magnetic disk, an optical disk, etc., and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network, such as the Internet, and / or various telecommunication networks.
[0141] The processor 11 can be various general and / or special purpose processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 performs various methods and processes described above, such as the table question answering method.
[0142] In some embodiments, the table question answering method can be implemented as a computer program tangibly embodied in a computer readable storage medium, e.g., storage unit 18. In some embodiments, parts or all of the computer program can be loaded and / or installed onto electronic device 10 via, e.g., ROM 12 and / or communication unit 19. When the computer program is loaded onto RAM 13 and executed by processor 11, one or more steps of the table question answering method described above can be performed. Alternatively, in other embodiments, processor 11 can be configured to perform the table question answering method by other means, e.g., with the aid of firmware.
[0143] Various implementations of the systems and techniques described above can be realized in digital electronic circuitry, integrated circuitry, a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on a chip (SOC), a programmable logic device (PLD), a computer hardware, firmware, software, and / or combinations thereof. These various implementations can include implementation in one or more computer programs that are executable and / or interpretable on a programmable system including at least one programmable processor, which can be special or general purpose, coupled to receive data and instructions from, and to transmit data and instructions to, a storage system, at least one input device, and at least one output device.
[0144] Computer programs used to implement the methods of the present application can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine, such that the computer program, when executed by the processor of the machine, implements the functions / acts specified in the flowcharts and / or block diagrams. The computer program can be executed entirely on a machine, partially on a machine, partially on a machine as a stand-alone software package, partially on a machine and partially on a remote machine or entirely on a remote machine or server.
[0145] In the context of the present application, a computer-readable storage medium can be a tangible medium that can contain or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. A computer-readable storage medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium can be a machine-readable signal medium. More specific examples of a machine-readable storage medium will include one or more lines of a program of instructions in a transitory signal, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0146] To provide for interaction with a user, the systems and techniques described here can be implemented on an electronic device having a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the electronic device. Other kinds of devices can be used to provide for interaction with a user as well; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form, including acoustic, speech, or tactile input.
[0147] The systems and techniques described here can be implemented in a computing system that includes a back end component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front end component (e.g., a user computer having a graphical user interface or a Web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such back end, middleware, or front end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0148] The computing system can include clients and servers. A client and server are generally remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. Servers can be cloud servers, also known as cloud computing servers or cloud hosts, which are a host product in the cloud computing service system to solve the defects of great management difficulty and weak business scalability in traditional physical hosts and VPS services.
[0149] It should be understood that the various forms of flow shown above can be reordered, additional steps added, or steps deleted. For example, the steps described in the present application can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solutions of the present application can be achieved, which are not limited herein.
[0150] The embodiment of the present application further provides a computer program product comprising a computer program which, when executed by a processor, implements the table question and answer method according to any one of the embodiments of the present application.
[0151] The computer program product, in the implementation process, can be written in one or more programming languages or combinations thereof to implement computer program codes for performing the operations of the present application, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" language or similar programming languages. The program code can be executed entirely on a user computer, partially on a user computer, as an independent software package, partially on a user computer and partially on a remote computer, or entirely on a remote computer or server. In the case involving a remote computer, the remote computer can be connected to the user computer through any kind of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, through the Internet by using an Internet service provider).
[0152] The above detailed description does not constitute a limitation on the protection scope of the present application. Those skilled in the art should understand that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent replacements and improvements made within the spirit and principles of the present application shall be included in the protection scope of the present application.< / unk> < / sep> < / coli> < / unk> < / unk> < / sep> < / sep>
Claims
1. A table question-answering method, characterized in that: include: Get the identification information of the user input question and target form; Generate input text according to the user input question and identification information of the target form; Input the input text into the NL2SQL model to obtain a target SQL statement; Execute the target SQL statement and obtain the execution result; The execution result and the user input question are input into the NLG model to obtain an output answer corresponding to the user input question.
2. The method according to claim 1, characterized in that The training process of the NL2SQL model includes: Acquire a credit form question and answer history dataset, wherein the credit form question and answer history dataset includes: a form, questions, and query statements corresponding to the questions; Add column tags to all column names in the table and then concatenate them to obtain a first word sequence; Concatenate each word in the question to obtain a second word sequence; Processing the first word sequence and the second word sequence to obtain a target word sequence; Processing the query statement to obtain a query statement sequence; Generating a training sample set according to the target word sequence and the query sentence sequence; The BART model is trained based on the training sample set to obtain the NL2SQL model.
3. The method according to claim 2, characterized in that The BART model includes: a first encoder and a first decoder; The BART model is trained based on the training sample set to obtain the NL2SQL model, including: Generate a target vocabulary set based on all column names of the table, the corpus, and keywords in the structured query language; Inputting the target word sequence in the training sample set into the first encoder to obtain a hidden state sequence corresponding to the target word sequence; Inputting the hidden state sequence corresponding to the target word sequence and the target vocabulary set into a first decoder to obtain a predicted query sentence sequence; Inputting the query sentence sequence in the training sample set into the first encoder to obtain a hidden state sequence corresponding to the query sentence sequence; Inputting the hidden state sequence corresponding to the query sentence sequence and the target vocabulary set into a first decoder to obtain a predicted word sequence; According to the difference between the predicted query statement sequence and the query statement sequence, and the difference between the predicted word sequence and the target word sequence, the parameters of the BART model are trained to obtain the NL2SQL model.
4. The method according to claim 3, characterized in that Inputting the hidden state sequence corresponding to the target word sequence and the target vocabulary set into the first decoder to obtain a predicted query sentence sequence, including: Get the attention score between each hidden state in the hidden state sequence and each word in the target vocabulary set; Get the attention score between each hidden state and the hidden state sequence in the hidden state sequence; determining a mixing score based on an attention score between each hidden state in the hidden state sequence and each word in the target vocabulary set and an attention score between each hidden state in the hidden state sequence and the hidden state sequence; Determining an attention weight matrix based on the mixture score; Determine a predicted query statement sequence based on the attention weight matrix.
5. The method according to claim 2, characterized in that The first word sequence and the second word sequence are processed to obtain a target word sequence, including at least one of the following: splicing the first word sequence and the second word sequence to obtain a target word sequence, wherein the first word sequence and the second word sequence are spliced by a separator; Injecting noise into the first word sequence to obtain a first word sequence after the noise injection, and concatenating the first word sequence after the noise injection with the second word sequence to obtain a target word sequence, wherein injecting noise into the first word sequence includes at least one of the following: adjusting a connection order of columns of a table in the first word sequence; deleting at least one column of a table in the first word sequence; or adding a column to a table in the first word sequence; Noise is injected into the second word sequence to obtain a second word sequence after the noise is injected, and the first word sequence and the second word sequence after the noise is injected are spliced to obtain a target word sequence, wherein the noise is injected into the second word sequence includes: adjusting the order of entities in the second word sequence to obtain the second word sequence after the noise is injected, and the entity includes at least one word.
6. The method according to claim 2, characterized in that The query statement is processed to obtain a query statement sequence, including at least one of the following: After adding target tags to the column names and values in the query statement, they are concatenated to obtain a query statement sequence; Modifying the query statement according to the first word sequence after the noise is injected to obtain a modified query statement, adding target tags to column names and values in the modified query statement, and then splicing them to obtain a query statement sequence; Noise is injected into the query statement to obtain a query statement after noise injection, and target tags are added to column names and values in the query statement after noise injection, followed by splicing to obtain a query statement sequence, wherein injecting noise into the query statement includes: adjusting the order of entities in the query statement to obtain the query statement after noise injection.
7. The method according to claim 2, characterized in that The credit form question and answer dataset also includes: the execution results of the query statement and the output answers corresponding to the questions; The training process of the NLG model includes: Input the query statement execution result and question into the T5 model to obtain the predicted output answer; The T5 model is trained based on the difference between the predicted output answer and the output answer corresponding to the question to obtain an NLG model.
8. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor. The computer program is executed by the at least one processor to enable the at least one processor to perform the form question answering method according to any one of claims 1 to 7.
9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the form question and answer method according to any one of claims 1 to 7 when executed.
10. A computer program product, characterized in that The computer program product comprises a computer program, which, when executed by a processor, implements the form question and answer method according to any one of claims 1 to 7.