A table question and answer method based on a large language model and natural language processing

CN117743526BActive Publication Date: 2026-09-15COMPUTER INNOVATION TECH RES INST OF ZHEJIANG UNIV
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202311551970.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-11-21
Publication Date
2026-09-15
Estimated Expiration
2043-11-21

AI Technical Summary

Technical Problem

本发明设计了一种将表格数据信息输入到大语言模型并通过自然语言处理表格任务的方法,以解决现有方法大模型不能看到表格的整体信息,无法理解用户输入的自然语言,导致准确率低的问题

Benefits of technology

[0037] 1. Because the large language model of this invention sees the overall and complete information of the table, it has better fuzzy matching capabilities. It can find the column name with the closest meaning in the table information based on the user's input question. Even if the table content is in Chinese, the user can ask questions in English; it automatically completes the column names for the user and rejects inquiries unrelated to the table.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117743526B_ABST
    Figure CN117743526B_ABST
Patent Text Reader

Abstract

The application discloses a table question and answer method based on a large language model and natural language processing. The method comprises the following steps: extracting explicit information of original table data based on rules; extracting implicit information of the table according to a transformer model; inputting complete table information and natural language input of a user into the large language model, debugging a prompt of the large language model, and then generating python code; executing the python code to process a table task, generating a new table meeting a user query requirement, and returning a result. Since the large language model can see the whole and complete information of the table, the large language model has better fuzzy matching capability, meanwhile, the accuracy of processing the table task through the natural language processing is greatly improved, the method is more intelligent, and is closer to an actual use scene.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of table processing technology, and in particular relates to a method for extracting table content based on large language models and natural language processing. Background Technology

[0002] Much of the world's information is stored in tabular form, found online, in databases, or in documents. These include technical specifications for consumer products, financial and national development statistics, sporting event results, and more. Currently, finding answers to questions still requires manually searching these tables or using services that provide answers to specific questions (such as those about sporting event results). Accessing this information would be much easier if it could be queried using natural language.

[0003] Table-based question answering has a wide range of applications. The earliest methods include Natural Language Interface for Databases (NLIDB), a system that allows users to access information stored in a database by inputting requests in a natural language representation. These methods rely heavily on rules and templates, are highly constrained by natural language, have poor language understanding capabilities, and lack strong generalization ability. More recently, NL2SQL has become popular, with deep learning-based implementations showing significant improvement over NLIDB. However, current NL2SQL methods only input table header information into the model, meaning the model only understands a partial portion of the table, making it difficult to provide accurate answers to user questions, resulting in low accuracy in practical applications.

[0004] Previous methods often focused too much on the specific information in each cell when interpreting tables, neglecting the overall picture. There is an urgent need to enable models to grasp the global information of tables, improve the accuracy of table-based question answering, and better reflect real-world usage scenarios. Summary of the Invention

[0005] To address the problems existing in the background technology, the present invention aims to provide a table-based question-answering method based on a large language model and natural language processing. The present invention designs a method for inputting table data information into a large language model and performing table tasks through natural language processing, thereby solving the problem that existing methods cannot fully utilize the table's overall information and therefore cannot understand the user's input natural language, resulting in low accuracy.

[0006] The technical solution adopted in this invention is as follows, including the following steps:

[0007] Step S01: Extract explicit information from the original table data of the original table used for question and answer;

[0008] Step S02: Vectorize the original table data to obtain the implicit information of the original table data. The implicit information is the feature vector containing all the information of the original table data.

[0009] Step S03: Simultaneously input the explicit information, implicit information, and user questions from the original table data into the large language model, and generate Python code text in the large language model;

[0010] Step S04: Based on the original table data and Python code text, obtain the answer to the user's question by executing the Python code text query and provide it to the user.

[0011] The specific steps of S01 are as follows:

[0012] Step S0101: Classify the original table data according to the data type to extract continuous columns (numeric type), discrete columns (character type), and time series (time stamp) from the original table data;

[0013] Step S0102: Perform data preprocessing on the continuous and discrete columns to obtain the preprocessed continuous and discrete columns;

[0014] Step S0103: Extract explicit information from the preprocessed continuous and discrete columns, as well as the time series, of the original tabular data;

[0015] The explicit information of the original table data includes the minimum, median, and maximum values ​​of the continuous columns, the top ten data categories with the highest frequency in the discrete columns, and the start and end times in the discrete columns.

[0016] The specific steps of step S02 are as follows: inputting the original table into the transformer model, and the transformer model outputs a feature vector containing all the data information of the original table, i.e., implicit information;

[0017] The specific steps of step S03 are as follows:

[0018] Step S0301: First, combine the explicit and implicit information of the original table data to obtain the complete data information of the original table data;

[0019] Step S0302: Construct a training dataset using multiple user questions and their corresponding answers;

[0020] Step S0303: Input the complete data information of the original table data into the large language model to be trained, and then use the training dataset and prompt to train the large language model to obtain the trained large language model.

[0021] Step S0304: Based on the trained large language model, output the Python code text corresponding to the solution of the user's problem.

[0022] The specific steps of S04 are as follows:

[0023] Step S0401: Input the user question to be queried into the trained large language model. The large language model determines whether the user question is related to the original table:

[0024] If the user's problem is related to the original form, proceed to step S0402;

[0025] Otherwise, the large language model outputs "None" and displays this message to the user on the front-end page;

[0026] Step S0402: Use pyflakes to perform syntax validation on the generated Python code text:

[0027] If the generated Python code text has correct syntax, it indicates that the Python code text is executable code, and proceed to step S0403;

[0028] If the generated Python code text has a syntax error, return to step S03 to regenerate a new Python code text until the new Python code text passes the syntax check;

[0029] Step S0403: By executing the Python code text, the large language model obtains the answer corresponding to the user's question based on the user's question query, and generates a new table based on the question answer and returns the result.

[0030] The specific method of data preprocessing in step S0102 is as follows:

[0031] First, delete data in the continuous / discrete column where the missing percentage exceeds 50%; then fill the deleted data in the continuous / discrete column with fill values; for the discrete column, use the data category with the highest frequency in the discrete column as the fill value; for the continuous column, use the average value of the continuous column as the fill value.

[0032] In step S0303, the specific method for training the large language model is as follows: input the training dataset and prompt into the large language model, continuously adjust the prompt of the large language model, and when the output result of the large language model is consistent with the answer corresponding to the user question in the training dataset, take the prompt at this time as the final prompt of the large language model.

[0033] By explicitly and implicitly inputting tabular information into a large model, the large model gains a holistic understanding of the tabular information. Then, through interaction with the large model using natural language, Python code capable of processing tabular tasks is generated. This method includes: 1) extracting explicit information from the original tabular data based on rules; 2) extracting implicit information from the table using a transformer model; 3) generating Python code based on the tabular information and the user's natural language input into a large language model; and 4) executing the Python code to process the tabular task. This invention significantly improves the accuracy of processing tabular tasks using natural language because the large language model sees the overall and complete information of the table.

[0034] The technical solution of this invention can be summarized as follows:

[0035] First, explicit information from the original table data is extracted based on rules and experience. Then, the original table is input into the transformer model to obtain implicit vector information. Next, the explicit and implicit information from the original table, along with the user's query question, are input into the larger model to generate Python code. Finally, the original table data and the Python code generated by the larger model are combined to execute the Python code, generate a new table that meets the user's query requirements, and return the results.

[0036] The beneficial effects of this invention are as follows:

[0037] 1. Because the large language model of this invention sees the overall and complete information of the table, it has better fuzzy matching capabilities. It can find the column name with the closest meaning in the table information based on the user's input question. Even if the table content is in Chinese, the user can ask questions in English; it automatically completes the column names for the user and rejects inquiries unrelated to the table.

[0038] 2. The method of the present invention greatly improves the accuracy of table processing tasks through natural language processing, making it more intelligent and closer to real-world application scenarios. Attached Figure Description

[0039] Figure 1 This is a schematic diagram of the process of an embodiment of the present invention;

[0040] Figure 2 A diagram illustrating the extraction of explicit information from a table;

[0041] Figure 3 A diagram illustrating the extraction of implicit information from a table;

[0042] Figure 4 A diagram illustrating the process of generating Python code;

[0043] Figure 5 A diagram illustrating the refusal to answer by a large language model;

[0044] Figure 6 This is a diagram illustrating word matching for words with similar column names.

[0045] Figure 7 This is a diagram illustrating the matching of English and Chinese column names.

[0046] Figure 8 This is a diagram illustrating how to extract table information directly without using column names. Detailed Implementation

[0047] The present invention will be described in detail below with reference to specific implementation examples. These examples will help those skilled in the art to further understand the present invention, but do not limit the present invention in any way.

[0048] Embodiments of the present invention include the following steps, such as Figure 1 As shown:

[0049] Step S01: Extract explicit information from the original table data of the original table used for question answering based on rules and experience;

[0050] Step S02: Vectorize the original table data to obtain the implicit information of the original table data. The implicit information is the feature vector containing all the information of the original table data.

[0051] Step S03: Simultaneously input the explicit information, implicit information, and user questions from the original table data into the large language model, and generate Python code text in the large language model;

[0052] In practice, the user issues are specifically related to the user's natural language processing.

[0053] Step S04: Based on the original table data and Python code text, execute the Python code text to retrieve the answer to the user's question and provide it to the user.

[0054] Step S01 is as follows:

[0055] Step S0101: Classify the original table data according to the data type to extract continuous columns (numeric type), discrete columns (character type), and time series (time stamp) from the original table data;

[0056] Step S0102: Perform data preprocessing on the continuous column and the discrete column respectively to obtain the preprocessed continuous column and discrete column;

[0057] Step S0103: Extract explicit information from the preprocessed continuous and discrete columns, as well as the time series, of the original tabular data;

[0058] Explicit information about the original tabular data includes the minimum, median, and maximum values ​​of the continuous columns, the top ten most frequent data categories in the discrete columns, and the start and end times in the discrete columns.

[0059] In practice, the method for extracting explicit information from the original table data is as follows: Figure 2 As shown: For a preprocessed continuous column, extract the minimum, median, and maximum values ​​of the data in the continuous column; for a preprocessed discrete column, extract the top 10 most frequent categories of the data in the discrete column; for a time series, extract the start and end times of the time series.

[0060] Step S02 specifically involves: inputting the original table into the transformer model, and the transformer model outputting a feature vector containing all the data information of the original table, i.e., implicit information;

[0061] Unlike image and audio / video data, tabular data possesses permutation invariance, meaning that rearranging rows or columns does not affect the information contained within the table. The transformer model perfectly embodies this property; it is a model trained on massive amounts of tabular data that can extract representations of the entire tabular dataset. For example... Figure 3 As shown, the original table used for question answering is input into the transformer model to obtain a 512-dimensional feature vector that can represent the overall information of the original table.

[0062] Step S03 specifically includes:

[0063] Step S0301: First, combine the explicit and implicit information of the original table data to obtain the complete data information of the original table data;

[0064] Step S0302: Construct a training dataset using multiple user questions and their corresponding answers;

[0065] Step S0303: Input the complete data information of the original table data into the large language model to be trained, and then use the training dataset and prompt to train the large language model to obtain the trained large language model.

[0066] Step S0304: Based on the trained large language model, output the Python code text corresponding to the solution of the user's problem.

[0067] In specific implementation, such as Figure 4 As shown, the prompt, the complete data information of the original table data, and the user's question are input into the large language model. The large language model outputs Python code text that can solve the user's question.

[0068] Step S04 is as follows:

[0069] Step S0401: Input the user question to be queried into the trained large language model. The large language model determines whether the user question is related to the original table:

[0070] If the user's problem is related to the original form, proceed to step S0402;

[0071] Otherwise, the large language model outputs "None" and displays this message to the user on the front-end page. Figure 5 As shown;

[0072] Step S0402: Use pyflakes to perform syntax validation on the generated Python code text:

[0073] If the generated Python code text has correct syntax, it indicates that the Python code text is executable code, and proceed to step S0403;

[0074] If the generated Python code text has a syntax error, return to step S03 to regenerate a new Python code text until the new Python code text passes the syntax check;

[0075] Step S0403: By executing the Python code text, the large language model retrieves the answer to the user's question based on the query, and simultaneously generates a new table based on the question and answer, returning the results, such as... Figures 6-8 As shown.

[0076] The specific method of data preprocessing in step S0102 is as follows:

[0077] First, delete data in the continuous / discrete column where the missing percentage exceeds 50%; then fill the deleted data in the continuous / discrete column with fill values; for discrete columns, use the data category with the highest frequency in the discrete column as the fill value; for continuous columns, use the average value of the continuous column as the fill value.

[0078] In step S0303, the specific method for training the large language model using the training dataset and prompt is as follows: input the training dataset and prompt into the large language model, continuously adjust the prompt of the large language model, and when the output result of the large language model is consistent with the answer corresponding to the user question in the training dataset, take the prompt at this time as the final prompt of the large language model.

[0079] The capabilities of Large Language Models (LLMs) are not designed in advance; their limits need to be continuously explored. The A1 text prompt is one such exploration method, using text prompts to help the large language model better understand its task. Through continuous experimentation and testing, the most suitable prompt was determined.

[0080] The core technology of this invention is to input tabular data into a large language model and process the table data through natural language processing, which is closer to real-world application scenarios. Thanks to the large language model, which can display complete table information, its advantages over other methods are as follows:

[0081] 1. It can match synonyms, such as Figure 6 As shown, name --> full name;

[0082] 2. It can be written in both Chinese and English, such as Figure 7 As shown, age --> age;

[0083] 3. You can extract table information directly without using column names, such as... Figure 8 As shown, the large language model knows that Xiao Li is in the name column. Without inputting the table information into the large language model, this task cannot be completed.

[0084] Those skilled in the art can readily make various changes and modifications based on the provided textual description, drawings, and claims, without departing from the spirit and scope of the invention as defined by the claims. Any modifications or equivalent variations made to the above embodiments based on the technical concept and essence of the invention fall within the protection scope defined by the claims of this invention.

Claims

1. A table-based question-answering method based on a large language model and natural language processing, characterized in that, Includes the following steps: Step S01: Extract explicit information from the original table data of the original table used for question and answer; Step S02: Vectorize the original table data to obtain the implicit information of the original table data; Step S03: Simultaneously input the explicit information, implicit information, and user questions from the original table data into the large language model, and generate Python code text in the large language model; The specific steps of S03 are as follows: Step S0301: First, combine the explicit and implicit information of the original table data to obtain the complete data information of the original table data; Step S0302: Construct a training dataset using user questions and their corresponding answers; Step S0303: Input the complete data information of the original table data into the large language model to be trained, and then use the training dataset and prompt to train the large language model to obtain the trained large language model. Step S0304: Based on the trained large language model, output the Python code text that solves the user's problem; Step S04: Based on the original table data and Python code text, obtain the answer to the user's question by executing the Python code text query and provide it to the user.

2. The table-based question-answering method based on a large language model and natural language processing according to claim 1, characterized in that: The specific steps of S01 are as follows: Step S0101: Classify the original table data according to the data type to extract continuous columns, discrete columns and time series from the original table data; Step S0102: Perform data preprocessing on the continuous and discrete columns to obtain the preprocessed continuous and discrete columns; Step S0103: Extract explicit information from the preprocessed continuous and discrete columns, as well as the time series, of the original tabular data; The explicit information of the original table data includes the minimum, median, and maximum values ​​of the continuous columns, the top ten data categories with the highest frequency in the discrete columns, and the start and end times in the discrete columns.

3. The table-based question-answering method based on a large language model and natural language processing according to claim 1, characterized in that: Specifically, step S02 involves inputting the original table into the transformer model, and the transformer model outputting a feature vector containing all the data information from the original table.

4. The table-based question-answering method based on a large language model and natural language processing according to claim 1, characterized in that: The specific steps of S04 are as follows: Step S0401: Input the user question to be queried into the trained large language model. The large language model determines whether the user question is related to the original table: If the user's problem is related to the original form, proceed to step S0402; Otherwise, the large language model outputs "None" and displays this message to the user on the front-end page; Step S0402: Use pyflakes to perform syntax validation on the generated Python code text: If the generated Python code text has correct syntax, it indicates that the Python code text is executable code, and proceed to step S0403; If the generated Python code text has a syntax error, return to step S03 to regenerate a new Python code text until the new Python code text passes the syntax check; Step S0403: By executing the Python code text, the large language model obtains the answer corresponding to the user's question based on the user's question query, and generates a new table based on the question answer and returns the result.

5. The table-based question-answering method based on a large language model and natural language processing according to claim 2, characterized in that: The specific method of data preprocessing in step S0102 is as follows: First, delete data in the continuous / discrete column where the missing percentage exceeds 50%; then fill the deleted data in the continuous / discrete column with fill values; for the discrete column, use the data category with the highest frequency in the discrete column as the fill value; for the continuous column, use the average value of the continuous column as the fill value.

6. The table-based question-answering method based on a large language model and natural language processing according to claim 4, characterized in that: In step S0303, the specific method for training the large language model is as follows: input the training dataset and prompt into the large language model, continuously adjust the prompt of the large language model, and when the output result of the large language model is consistent with the answer corresponding to the user question in the training dataset, take the prompt at this time as the final prompt of the large language model.

Citation Information

Patent Citations

  • Model training method and device, table recognition method and device, electronic equipment and storage medium

    CN113673236A