Table knowledge storage method, device, medium and equipment in intelligent question-answering scenario

By determining the table area and semantic information to determine the table header based on the position rules of the table header in RAG intelligent question and answer, the problem of the loss of table structure information in the traditional method is solved, the accurate parsing and storage of the table content is achieved, and the model's knowledge of the table is improved. understanding ability and question-answering effect.

CN118332065BActive Publication Date: 2024-09-06金现代信息产业股份有限公司
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
CN202410756087.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-13
Publication Date
2024-09-06
Estimated Expiration
2044-06-13

AI Technical Summary

Technical Problem

In RAG intelligent question answering, the traditional method parses the table content in the document into ordinary text, resulting in the loss of table structure information and the inability to accurately understand the table content, which in turn affects the model's question and answer effect on table knowledge.

Method used

By determining the table area based on the position rules of the table header, and using semantic information to determine the header, the table is converted into a key-value pair form that is easy to understand by the large language model. There is no need to rely on the color, filling and other attributes of the table when storing, and it can adapt to multiple rows or multiple List header situation.

Benefits of technology

It improves the model's ability to understand table knowledge, significantly improves the Q&A effect on complex tables, and ensures accurate parsing and storage of table contents.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118332065B
    Figure CN118332065B
Patent Text Reader

Abstract

The present invention belongs to the field of deep learning technology, and provides a table knowledge storage method, device, medium and equipment in an intelligent question and answer scenario. The present invention determines the table area based on the position rule of the table header, and determines the table header according to semantic information. The correct header can be obtained for the header area of ​​multiple rows or columns without relying on the color, fill and other attributes of the table. It is only based on the table structure and cell text content. The table can be converted into a format that is easy for a large language model to understand through the header for storage. Complex merged cell tables can be unified into standard tables, which can be used to extract specific cell content, etc., which can improve the model's understanding of table knowledge and significantly increase the question and answer effect of complex tables.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the field of deep learning technology, and in particular to a table knowledge storage method, device, medium and equipment in an intelligent question and answer scenario. Background Art

[0002] The statements in this section merely provide background information related to the present invention and do not necessarily constitute prior art.

[0003] In RAG intelligent question answering, local private knowledge needs to be parsed and stored, such as Word, PDF, Excel, etc. The traditional approach is to divide the text content into multiple text blocks according to a certain division strategy, and then store them in vector form. The table content in the document is also parsed as ordinary text, which loses the structural information of the table itself, may cause the order of the text content to be confused, and make the large language model unable to understand the table content.

[0004] Therefore, it is necessary to parse the table structure in the document into a key-value pair format that is easy for the large language model to understand, where the key is the table header content. Common table parsing generally determines the table header through cell attributes (such as font color, cell fill, etc.) or directly considers the first row of content to be the table header. However, the table in the document generally has no additional attributes and cells can be merged. There may be a situation where the table header spans multiple rows or columns. When parsing the table into a key-value pair, the key-value pair content will be incorrect, and then the model will misunderstand it, and the question and answer of table knowledge cannot get the correct result. Summary of the invention

[0005] In order to solve at least one technical problem existing in the above-mentioned background technology, the present invention provides a table knowledge parsing and storage method and system in a RAG intelligent question and answer scenario, which determines the table area based on the position rule of the table header, and determines the table header according to semantic information. The correct header can be obtained for the header area of ​​multiple rows or columns without relying on the color, fill and other attributes of the table; the table can be converted into a format that is easy for a large language model to understand and stored through the header.

[0006] In order to achieve the above object, the present invention adopts the following technical solution:

[0007] A first aspect of the present invention provides a table knowledge storage method in an intelligent question-answering scenario, comprising the following steps:

[0008] Obtain text and table information from knowledge documents in different formats;

[0009] Determine the header area based on the table information and the position pattern of the header formed in the table;

[0010] The text information of the determined table header area is spliced, and the trained text classification model is used to classify the spliced ​​content to determine the category to which the table belongs, and then the detailed area of ​​the table header is determined;

[0011] According to the determined detailed area of ​​the table header, the rest of the table is merged or split based on the table header to obtain table content with no cell merging and the same number of columns and rows in each row and column;

[0012] The text content of the header cell is used as the field name, and the text content of the cell in the corresponding column or row is used as the value. The table content is converted into a key-value pair, and a row or column in the original table is compiled into a set of key-value pair strings, which are vectorized and stored in the vector library.

[0013] Furthermore, after acquiring text information and table information in knowledge documents of different formats, the method further includes converting the table information into a unified storage format and defining a storage format based on rows and columns.

[0014] Furthermore, the position rules for forming the table header in the table include:

[0015] The first rule: the table header is located in the front row or front column of the table, that is, at the top or side starting area of ​​the table;

[0016] The second rule: the table header is the first few rows or columns, or there is no header, and there is no situation where the top or side starting area of ​​the table is all headers;

[0017] The third rule: The actual number of columns or rows in the header should be equal to the number of columns or rows in the table;

[0018] Fourth rule: In a multi-row header area, the number of cells in each row must be more than the row above it, and in a multi-column header area, the number of cells in each column must be more than the column to its left;

[0019] The fifth rule: If the number of cells in the non-header area row or column is greater than the actual number of cells in the header, the corresponding row where the number of cells in the non-header area is greater than the actual number of cells in the header is merged up and down or the column is merged horizontally, and there must be a row or column with the same number of cells as the row or column where the number of cells in the non-header area is greater than the actual number of cells in the header;

[0020] The sixth rule: There are adjacent rows or columns that are merged up and down, and both are headers, or neither is a header;

[0021] The seventh rule: In a multi-row header area, there are no two adjacent cells that are neither merged horizontally nor merged vertically; in a multi-column header area, there are no two adjacent cells that are neither merged vertically nor merged horizontally.

[0022] Further, the determining of the header area based on the table information and the position rule of forming the header in the table includes:

[0023] According to the first rule and the sixth rule, starting from the first row or the first column of the table stored in the row or column format, traverse the cells in each row or each column, and count whether there are upper and lower merge marks in the cells of each row or each column; if there are, the upper and lower adjacent rows or columns are grouped according to the marks, and if not, a single row or column is grouped;

[0024] According to the fourth rule, the maximum number of cells in each row or column in each group is used as the number of cells in each group, and the grouping results are traversed from top to bottom. When the number of cells in the current group is less than or equal to the number of cells in the previous group, the process stops, and the current group and all the groups above are used as the header row to be selected;

[0025] According to the seventh rule, traverse the groups in the header row or column selection area from bottom to top, and check whether there is a situation in each group where the same column or row is horizontally merged but not merged up and down; if so, discard the group and continue traversing; if not, stop traversing and use the rows or columns included in the current group and all groups as the header row area or column area;

[0026] The area obtained by merging the header row area and the header column area is the header area.

[0027] Furthermore, the step of splicing the determined text information in the header area includes:

[0028] Merge the rows in the header row area into one row, and concatenate the text contents of each cell with a preset symbol to obtain the first string;

[0029] Merge the columns in the header column area into one column, and use the preset symbol to concatenate the text content of each cell to obtain the second string.

[0030] The first character string and the second character string are concatenated using a preset symbol to obtain a final character string.

[0031] Furthermore, when training the text classification model, according to the second rule, the table is divided into three categories: multi-row header table, multi-column header table, and no-header table. Among them, the first column of the multi-row header table belongs to the same field, and the text information has similar meaning; the first row of the multi-column header table belongs to the same field, and the text has similar meaning; the no-header table has no header, and the first row and the first column have different meanings.

[0032] Furthermore, the method for determining the detailed area of ​​the header is:

[0033] If the table type is a multi-row header table, the header row area is the final header area, and the row obtained by merging the header rows is the header;

[0034] If the table type is a multi-column header table, the header column area is the final header area, and the column obtained by merging the header columns is the header;

[0035] If the table type is a table without a header, the text content in the table is treated as ordinary text and not as a table.

[0036] A second aspect of the present invention provides a table knowledge storage device in an intelligent question-answering scenario, comprising:

[0037] A data acquisition module, which is used to acquire text information and table information in knowledge documents of different formats;

[0038] A preliminary region determination module, which is used to determine the header region based on the table information and the position regularity of the header formed in the table;

[0039] The detailed area determination module splices the text information of the determined table header area, uses the trained text classification model to classify the spliced ​​content, determines the category to which the table belongs, and then determines the detailed area of ​​the table header;

[0040] A content parsing module is used to merge or split cells in the rest of the table based on the determined detailed area of ​​the table header and the table header as a reference, so as to obtain table content in which cells are not merged and the number of columns in each row and the number of rows in each column are the same;

[0041] The knowledge storage module is used to convert the table content into a key-value pair using the text content of the header cell as the field name and the text content of the cell in the corresponding column or row as the value, and to compile a row or column in the original table into a set of key-value pair strings, which are then vectorized and stored in the vector library.

[0042] A third aspect of the present invention provides a computer-readable storage medium.

[0043] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the table knowledge storage method in the intelligent question and answer scenario as described in the first aspect.

[0044] A fourth aspect of the present invention provides a computer device.

[0045] A computer device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps in the table knowledge storage method in the intelligent question and answer scenario described in the first aspect are implemented.

[0046] Compared with the prior art, the beneficial effects of the present invention are: the present invention determines the table area based on the position rule of the table header, and determines the table header according to the semantic information. The correct header can be obtained for the header area of ​​multiple rows or columns, without relying on the color, fill and other attributes of the table, only based on the table structure and cell text content. The table can be converted into a format that is easy for a large language model to understand and store through the header. Complex merged cell tables can be unified into standard tables, which can be used to extract specific cell content, etc., which can enhance the model's ability to understand table knowledge and significantly increase the question and answer effect on complex tables.

[0047] Advantages of additional aspects of the present invention will be given in part in the following description, and in part will become obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.

[0049] Figure 1 It is a flow chart of a table knowledge parsing and storage method in a RAG intelligent question-answering scenario provided by an embodiment of the present invention;

[0050] Figure 2 It is a schematic diagram of a table in a situation provided by an embodiment of the present invention; DETAILED DESCRIPTION

[0051] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.

[0052] It should be noted that the following detailed descriptions are all illustrative and intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present invention belongs.

[0053] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit exemplary embodiments according to the present invention. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.

[0054] Explanation of terms

[0055] 1. RAG: Retrieval-Augmented Generation, full name Retrieval-Augmented Generation, is a natural language processing technology that combines information retrieval (Retrieval) and text generation (Generation). It aims to assist large language models (such as the GPT series) in generating more accurate and richer text content by retrieving relevant information from external knowledge sources, thereby improving the performance and efficiency of the model in processing complex tasks.

[0056] 2. Large Language Model: A large language model (LLM) is a deep learning model trained with a large amount of text data that can generate natural language text or understand the meaning of language text. It has the ability to understand, generate and process natural language and can perform at a very high level in various tasks. Large language models can handle a variety of natural language tasks, such as text classification, question and answer, dialogue, etc., and are an important path to artificial intelligence.

[0057] 3. Embedding model: A deep learning language model that can convert text into a vector of digital representation.

[0058] 4. Apache POI: Apache POI is an open source toolkit (jar package) provided by the Apache organization. It provides an API for Java programs to implement reading and writing functions for Microsoft Office format files (such as Excel, Word, PowerPoint, Visio, etc.).

[0059] 5. OCR: Optical Character Recognition, which is the abbreviation of optical character recognition. This is a technology that converts text content into editable and searchable electronic documents by scanning and analyzing images or printed text.

[0060] Embodiment 1

[0061] like Figure 1 As shown, this embodiment provides a table knowledge storage method in an intelligent question-answering scenario, including the following steps:

[0062] Step 1: Obtain text information and table information from knowledge documents in different formats;

[0063] Step 2: Convert the table information into a unified storage format and define the storage format based on rows and columns;

[0064] Step 3: Determine the header area according to the position rule of the header in the table;

[0065] Step 4: Splice the text content of the determined table header area, use the pre-trained language model to classify the spliced ​​content, determine the category to which the table belongs, and then determine the detailed area of ​​the table header;

[0066] Step 5: Based on the determined detailed area of ​​the table header, take the table header as the basis, merge or split the cells in the rest of the table, and obtain the table content with no cell merging and the same number of columns and rows in each row and column;

[0067] Step 6: Use the text content of the header cell as the field name and the text content of the cell in the corresponding column or row as the value to convert the table content into a key-value pair. Compile a row or column in the original table into a set of key-value pair strings, which are vectorized and stored in the vector library.

[0068] Through the above technical solution, the table area is determined based on the regularity of the table header position, and the table header is determined based on the semantic information. The correct header can be obtained for the header area of ​​multiple rows or columns without relying on the table's color, fill and other attributes. The table can be converted into a format that is easy for the large language model to understand and store through the header.

[0069] In step 1, the knowledge document formats that RAG intelligent question answering supports parsing include Word documents, PDF documents, Excel documents, image documents, etc.

[0070] Among them, the method for obtaining table information in a Word document is:

[0071] Word documents are mainly in doc and docx formats, where doc is a binary file format and docx is based on the xml file format. It is essentially a compressed package containing multiple xml files. The main content of docx is in the document.xml file. The docx file format is easy to parse and obtain.

[0072] doc format files can be converted to docx for parsing through LibreOffice, or they can be directly parsed through the Apache POI open source project.

[0073] In the xml file, the table part is stored in <w:tbl>In the tag, <w:tr>For table row labels, <w:tc>It is the cell label. At the same time, cell merging and cell text content can also be obtained through the corresponding labels, which will not be listed one by one.

[0074] Among them, the method for obtaining table information in a PDF document is:

[0075] PDF documents are divided into two types, parsable and scanned. Scanned PDF is converted to image processing through the PDF processing library, and parsable PDF obtains the lines and text block content through the PDF processing library, and then obtains the rows, columns, cells and the entire table area through the intersecting lines, and obtains the text block in the cell area as the cell text content, and determines the cell merging status through the rows or columns spanned by the cell.

[0076] It should be noted that this method has been implemented in the PDF processing library and can be used directly.

[0077] Among them, the method for obtaining table information in Excel document is:

[0078] Excel documents are divided into two formats: xls and xlsx. Both can be parsed through the Excel processing library to obtain table rows, columns, cells and merge status.

[0079] Among them, the method for obtaining table information in the image is: the image obtains the table structure through the table recognition model, and recognizes the text information through the OCR model; some table recognition models can also recognize the unit text content while obtaining the table structure.

[0080] Other types of documents can obtain table information through the corresponding document parsing library.

[0081] In step 2, the table information is converted into a unified storage format, and a storage format based on rows and columns is defined, including:

[0082] Step 201: In order to facilitate subsequent processing, the table information parsed from different document formats needs to be converted into a unified storage format. Here, a unified storage format is defined, including the following structure:

[0083] Cell: The basic unit of a table. i The cells are represented by Cell i .

[0084] Row: A row is a collection of ordered cells of the same height and horizontal direction in a table. i The row is represented as Row i .

[0085] Column: A set of ordered cells at the same horizontal position and different heights in a table form a column. i The columns are represented as Column i .

[0086] When cells are merged horizontally, mark CMS at the start of the merged cell to indicate the start of the horizontal merge, mark CMC at the middle cell of the merge to indicate the continuation of the horizontal merge, and mark CME at the end of the merged cell to indicate the end of the merged object. When cells are merged vertically, mark RMS at the start of the merged cell to indicate the start of the vertical merge, mark RMC in the middle of the vertical merged cell to indicate the continuation of the merge, and mark RME at the end of the vertical merged cell to indicate the end of the merge.

[0087] Step 202: Two storage formats are defined on top of the unified storage format, which are based on rows and columns respectively, to facilitate subsequent operations.

[0088] Row-based format

[0089] Remove the column structure in the unified storage format. When cells are merged up and down, the cells are not omitted. When cells are merged horizontally, remove the redundant merged cells and only keep the merged cells. At the same time, remove the horizontal merge mark to indicate which columns the cells occupy, such as Cell j-k Represented as spanning j Column to k Columns in the table i Line j The cells are represented by Row i ( Cell j ).

[0090] Column-based format

[0091] Remove the row structure in the unified storage format. When cells are merged horizontally, the cells are not omitted. When cells are merged up and down, remove the redundant merged cells and only keep the merged cells. At the same time, remove the upper and lower merge marks to indicate which columns the cells occupy, such as Cell j-k Represented as spanning j Column to k Column. i Ledi j Cells are represented as Column i ( Cell j ).

[0092] for Figure 2 The three saving formats are simplified as follows:

[0093] 1) Unified storage format

[0094] [Cell1(CMS),Cell2(CMC),Cell3(CME),Cell4(RMS)];

[0095] [Cell1,Cell2,Cell3,Cell4(RMC)];

[0096] [Cell1(CMS,RMS),Cell2(CME,RMS),Cell3,Cell4(RME)];

[0097] [Cell1(CMS,RME),Cell2(CME,RME),Cell3,Cell4];

[0098] 2) Row-based format

[0099] Row1(Cell 1-3 ,Cell4(RMS));

[0100] Row2(Cell1,Cell2,Cell3,Cell4(RMC));

[0101] Row3(Cell 1-2 (RMS), Cell3, Cell4 (RME));

[0102] Row4(Cell 1-2 (RME), Cell3, Cell4);

[0103] 3) Column-based format

[0104] Column1(Cell1(CMS),Cell2,Cell 3-4 (CMS));

[0105] Column2(Cell1(CMC),Cell2, Cell 3-4 (CME));

[0106] Column3(Cell1(CME),Cell2,Cell3,Cell4);

[0107] Column4(Cell 1-3 ,Cell4);

[0108] The table storage format described above can be implemented in a variety of ways, which are not listed one by one in this embodiment.

[0109] After conversion to a unified format, the unified format is converted into a row-based format and a column-based format for saving.

[0110] Among them, in step 3, according to the position rule of forming the header in the table, the area of ​​the header is determined, and then the text and table structure information in the area are spliced ​​as the input of the table classification, including:

[0111] The position rules for forming the table header in the table include:

[0112] The first rule: The header is located in the front row or front column of the table, that is, at the top or side starting area of ​​the table.

[0113] The essence of a table header is to classify the properties of the table contents. For the simplest table (without cell merging), the prior art usually uses the first row as the table header. The content of each field in the header represents the attribute category of the column content. However, there is also a habit or other consideration to use the first column as the header.

[0114] However, when the table content is complex and contains multi-level attributes, a single-row header is difficult to achieve the desired presentation effect. In this case, multiple rows (or columns) will be used as headers for more detailed division and description.

[0115] For example, for a table that records vehicle-related information, in simple terms, vehicle types can be divided into motor vehicles and non-motor vehicles, and motor vehicles can be divided into cars, motorcycles, etc. Therefore, the original vehicle type field may be divided again, that is, at least two rows will be used.

[0116] The situation with multiple columns is the same as that with multiple rows, but no matter how detailed the division is, the header always starts from the top or side of the table.

[0117] The second rule: the table header consists of several rows or columns, or there is no header. There is no situation where the top or side starting area of ​​the table is all headers.

[0118] The main function of the table header is to identify the data content of each column (or row) in the table, so that users can quickly understand the meaning and structure of the data.

[0119] Some tables do not have a centralized header, such as a resume table, which has no obvious header. At the same time, if the first few rows and columns are used as header data, there is no clear mark to distinguish different parts of the data.

[0120] The third rule: The actual number of columns (or rows) in the table header should be equal to the number of columns (or rows) in the table.

[0121] The actual number of columns (or rows) of the table header refers to the number of cells contained when the table header is merged into one row (or column). The actual number of rows (or columns) of the table refers to the number of rows (or columns) of the table after excluding cell merging and splitting. When there are cell merging in the table, the number of cells in some rows may be greater than the actual number of columns in the table, and the number of cells in some columns may be greater than the actual number of rows in the table.

[0122] In order to identify the data content of each column (or row) in the table, each column (or each row) must have a header field.

[0123] Fourth rule: In a multi-row header area, the number of cells in the upper and lower rows will not be the same, and the number of cells in each row must be more than the row above it; in a multi-column header area, the number of cells in the left and right columns will not be the same, and the number of cells in each column must be more than the column to the left. This ensures that the header can be gradually refined and completely cover the column information of the table.

[0124] The header area occupies multiple rows (or columns) in order to divide the table data more finely, so the number of cells can only increase.

[0125] The fifth rule: If the number of cells in the non-header area row (or column) is greater than the actual number of cells in the header, the corresponding rows where the number of cells in the non-header area is greater than the actual number of cells in the header are merged up and down (or columns are merged horizontally), and there must be a row (or column) with the same number of cells as the row or column where the number of cells in the non-header area is greater than the actual number of cells in the header.

[0126] When the number of cells in the rows (or columns) of the non-header area is greater than the number of cells in the rows (or columns) of the header, it indicates that two of the cells are obtained by splitting the cells in the corresponding column (or row) of the header, and one of the two split cells must be merged up and down.

[0127] The purpose of splitting is still to further divide the attribute of a cell value. For example, under the table header "Field Motor Vehicle Type", there are values ​​such as "Car", "Motorcycle", and "Trailer". If "Car" needs to be further divided, the "Car" cell can be split and "Passenger Car", "Truck", etc. can be added on the right.

[0128] The sixth rule: There are adjacent rows (or columns) merged up and down, either they are all headers, or they are not headers.

[0129] The seventh rule: In a multi-row header area, there are no two adjacent cells that are neither merged horizontally nor merged vertically; in a multi-column header area, there are no two adjacent cells that are neither merged vertically nor merged horizontally.

[0130] It should be noted that the above summary rules cannot completely cover all tabular situations. They contain some reasonable assumptions that can solve the vast majority of tabular situations.

[0131] At the same time, it should be noted that the third rule takes effect in step 5, where "the number of columns in each row is the same, and the number of rows in each column is the same" means that the number of rows and columns in the non-header area is kept consistent with the header as the number of rows and columns of the table.

[0132] The fifth rule works in step 302, but because the seventh rule covers the situation described by the fifth rule, the existence of "a row (or column) with the same number of cells" indicates that "the same column has the same horizontal merge situation but no vertical merge situation".

[0133] The step of determining the area of ​​the header according to the position rule of the header in the table includes:

[0134] Step 301: According to the first rule and the sixth rule, starting from the first row of the table stored in the row-based format, traverse the cells in each row and count whether there are upper and lower merge marks in the cells of each row; if there are, group the upper and lower adjacent rows according to the RMS, RMC, and RME marks. S i ( Row m ,…, Row n ), if it does not exist, a single line is considered as a group.

[0135] Step 302: According to the fourth rule, take the maximum number of cells in each row in each group as the number of cells in each group, traverse the grouping results from top to bottom, stop when the number of cells in the current group is less than or equal to the number of cells in the previous group, and use all groups above the current group as the header row selection area. Step 303: According to the seventh rule, traverse the groups in the header row selection area from bottom to top, and check whether there is a situation in each group where the horizontal merge of the same column is consistent but there is no upper and lower merge; if so, abandon the group and continue traversal; if not, stop traversal and use the rows included in the current group and all groups above as the header row area.

[0136] The specific method is: get the result of the corresponding row of the group in the unified storage format, traverse each column, and check whether there are two adjacent cells with neither horizontal merge mark nor upper and lower merge mark. If there is, it means that the group is not a table header and is discarded.

[0137] Step 304: According to the first rule and the sixth rule, starting from the first column of the table stored in the column-based format, traverse the cells in each column and count whether there is a horizontal merge mark in the cells of each column. If there is, the upper and lower adjacent rows are grouped according to the CMS, CMC, and CME marks. Si ( Columnm ,…, Columnn ), if it does not exist, a single column is considered as a group.

[0138] Step 305: According to the fourth rule, the maximum number of cells in each column of each group is used as the number of cells in each group, and the grouping results are traversed from top to bottom. When the number of cells in the current group is less than or equal to the number of cells in the previous group, stop, and use all groups to the left of the current group as the header column to be selected.

[0139] Step 306: According to the seventh rule, traverse the groups in the header column selection area from bottom to top, and check whether there is a row in each group that has the same vertical merging situation but no horizontal merging. If there is, discard the group and continue traversing; if not, stop traversing and use the columns included in the current group and all groups on the left as the header column area.

[0140] The specific method is: get the result of the corresponding column of the group in the unified storage format, traverse each row, and check whether there are two adjacent cells with neither horizontal merge mark nor upper and lower merge mark. If there are, it means that the group is not a table header.

[0141] Step 307: The area obtained by merging the header row area and the header column area is the header area.

[0142] Among them, in step 4, the text content of the determined header area is spliced, including:

[0143] Merge the rows in the header row area into one row, and use the preset symbols to concatenate the text contents of each cell to obtain a string S 1. The specific method is as follows:

[0144] 1) Merge the rows within a group;

[0145] For groups in the header row area S i First, take the first row as the parent row and the next row as the child row. For the cells in the child row i , whose text content is Text i , get the corresponding cell in the parent row (i-n)~(i+n) Corresponding text content Text (i-n)~(i+n) , if Text (i-n)~(i+n) Not entirely in Text i In the Text (i-n)~(i+n) Add as a prefix to Text i Before, update to Text (i-n)~(i+n) (Text i ); and use the child row as the new parent row and the next row as the new child row; if there is no next row, use the parent row as the merged row within the group.

[0146] 2) Merge groups;

[0147] The rows after merging the groups are taken as new groups, and are still merged according to the above method to finally obtain a row of content.

[0148] 3) Splice cell contents;

[0149] Use a preset symbol to splice the text in each cell, such as a tab, |, #, etc. There is no restriction on the selection of the preset symbol, as long as it can express the splicing meaning and can be distinguished from the text content of the cell.

[0150] Merge the columns in the header column area into one column, and use the preset symbols to concatenate the text content of each cell to obtain a string S 2. The specific method is the same as the steps for merging the header row area, just change the rows to columns.

[0151] Will S 1 and S 2 Use the preset symbols to concatenate to get the final string.

[0152] In step 4, a pre-trained language model is used to classify the concatenated content, determine the category to which the table belongs, and then determine the detailed area of ​​the header, including:

[0153] According to the second rule, tables are divided into three categories: multi-row header tables, multi-column header tables, and no header tables.

[0154] Among them, the first column of the multi-row header table belongs to the same field, and the text information has similar meaning; the first row of the multi-column header table belongs to the same field, and the text has similar meaning; the headerless table has no header, and the first row and the first column have different meanings.

[0155] The final strings S obtained from the three category tables have obvious semantic differences, which can be distinguished by training text classification models (such as BERT, LSTM, etc.) to determine the final table category.

[0156] If the table category is a multi-row header table, the header row area is the final header area, and the row obtained by merging the header rows is the header; if the table category is a multi-column header table, the header column area is the final header area, and the column obtained by merging the header columns is the header; if the table category is a table without a header, the text content in the table is treated as ordinary text and not as a table. In step 5, based on the determined header detailed area, the rest of the table is merged or split based on the header to obtain a table content with no merged cells and the same number of columns in each row and the same number of rows in each column, specifically including:

[0157] For a table with multiple rows of headers, the columns occupied by the cells in the header are used as the final columns of the table, including:

[0158] For the header cell i , non-header area cell i No processing; non-header area cells (i-1)~i , split into Cell i-1 、Cell i ; Non-header area cell (i-1)~(i+1) , split into Cell i-1 、Cell i 、Cell i+1 .

[0159] The text content of each cell after splitting is the same as the text content of the cell before splitting. j~(j+1) , non-header area cell j~(j+1) No processing is done; non-header area cells j 、Cell (j+1) Merge into Cell j~(j+1) ; Non-header area cell (j-1)~j 、Cell (j+1)~(j+2) Split and merge into Cell j-1 、Cell j~(j+1) 、Cell j+2 ;

[0160] The text content of the merged cell is the result of sequentially concatenating the text of all cells involved in the merge.

[0161] For a table with multiple header columns, the rows occupied by each cell in the header are used as the final rows of the table. The logic of cell merging and splitting is the same as that of a table with multiple header columns.

[0162] In step 6, the header cell field is used as the key, the cell content of each column (or row) is used as the value, and each row (or column) is a set of key-value pairs, which are converted into strings and vectorized using the embedding model, and then stored in the vector library. At the same time, the id of the string in the vector library and the string content are stored in the database for subsequent retrieval and use.

[0163] This embodiment provides a table knowledge storage device in an intelligent question-answering scenario, including:

[0164] A data acquisition module, which is used to acquire text information and table information in knowledge documents of different formats;

[0165] A preliminary region determination module, which is used to determine the header region based on the table information and the position regularity of the header formed in the table;

[0166] The detailed area determination module splices the text information of the determined table header area, uses the trained text classification model to classify the spliced ​​content, determines the category to which the table belongs, and then determines the detailed area of ​​the table header;

[0167] A content parsing module is used to merge or split cells in the rest of the table based on the determined detailed area of ​​the table header and the table header as a reference, so as to obtain table content in which cells are not merged and the number of columns in each row and the number of rows in each column are the same;

[0168] The knowledge storage module is used to convert the table content into a key-value pair using the text content of the header cell as the field name and the text content of the cell in the corresponding column or row as the value, and to compile a row or column in the original table into a set of key-value pair strings, which are then vectorized and stored in the vector library.

[0169] Embodiment 3

[0170] This embodiment provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the steps in the table knowledge storage method in the intelligent question and answer scenario described in Example 1 are implemented.

[0171] Embodiment 4

[0172] This embodiment provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the steps in the table knowledge storage method in the intelligent question and answer scenario described in Embodiment 1 are implemented.

[0173] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.< / w:tc> < / w:tr> < / w:tbl>

Claims

1. A table knowledge storage method in an intelligent question-answering scenario, characterized in that: The steps include: Obtain text and table information from knowledge documents in different formats; Convert table information into a unified storage format and define the storage format based on rows and columns; Based on the table information and the position rule of forming the table header in the table, the table header area is determined, wherein the position rule of forming the table header in the table includes: The first rule: the table header is located in the front row or front column of the table, that is, at the top or side starting area of ​​the table; The second rule: the table header is the first few rows or columns, or there is no header, and there is no situation where the top or side starting area of ​​the table is all headers; The third rule: The actual number of columns or rows in the header should be equal to the number of columns or rows in the table; Fourth rule: In a multi-row header area, the number of cells in each row must be more than the row above it, and in a multi-column header area, the number of cells in each column must be more than the column to its left; The fifth rule: If the number of cells in the non-header area row or column is greater than the actual number of cells in the header, the corresponding row where the number of cells in the non-header area is greater than the actual number of cells in the header is merged up and down or the column is merged horizontally, and there must be a row or column with the same number of cells as the row or column where the number of cells in the non-header area is greater than the actual number of cells in the header; The sixth rule: There are adjacent rows or columns that are merged up and down, and both are headers, or neither is a header; The seventh rule: In the multi-row header area, there are no two adjacent cells that are neither merged horizontally nor merged vertically; in the multi-column header area, there are no two adjacent cells that are neither merged vertically nor merged horizontally; The determining of the header area based on the table information and the position rule of the header formed in the table includes: According to the first rule and the sixth rule, starting from the first row or the first column of the table stored in the row or column format, traverse the cells in each row or each column, and count whether there are upper and lower merge marks in the cells of each row or each column; if there are, the upper and lower adjacent rows or columns are grouped according to the marks, and if not, a single row or column is grouped; According to the fourth rule, the maximum number of cells in each row or column in each group is used as the number of cells in each group, and the grouping results are traversed from top to bottom. When the number of cells in the current group is less than or equal to the number of cells in the previous group, the process stops, and the current group and all the groups above are used as the header row to be selected; According to the seventh rule, the groups in the header row or column selection area are traversed from bottom to top, and it is checked whether there is a situation in each group where the horizontal merging of the same column or the same row is consistent but not merged up and down; if so, the group is discarded and the traversal continues; if not, the traversal is stopped, and the rows or columns included in the current group and all groups are used as the header row area or column area; the area after merging the header row area and the header column area is the header area; the text information of the determined header area is spliced, and the trained text classification model is used to classify the spliced ​​content to determine the category to which the table belongs, and then determine the header detailed area; According to the determined detailed area of ​​the table header, the rest of the table is merged or split based on the table header to obtain table content with no cell merging and the same number of columns and rows in each row and column; The text content of the header cell is used as the field name, and the text content of the cell in the corresponding column or row is used as the value. The table content is converted into a key-value pair, and a row or column in the original table is compiled into a set of key-value pair strings, which are vectorized and stored in the vector library.

2. The table knowledge storage method in the intelligent question-answering scenario according to claim 1, characterized in that: The step of splicing the determined text information in the header area includes: Merge the rows in the header row area into one row, and concatenate the text contents of each cell with a preset symbol to obtain the first string; Merge the columns in the header column area into one column, and use the preset symbol to concatenate the text content of each cell to obtain the second string. The first character string and the second character string are concatenated using a preset symbol to obtain a final character string.

3. The table knowledge storage method in the intelligent question-answering scenario according to claim 1, characterized in that: When training the text classification model, according to the second rule, the tables are divided into three categories: multi-row header tables, multi-column header tables, and no-header tables. The first column of a multi-row header table belongs to the same field, and the text information has similar meanings; the first row of a multi-column header table belongs to the same field, and the text has similar meanings; a no-header table has no header, and the first row and the first column have different meanings.

4. The table knowledge storage method in the intelligent question-answering scenario according to claim 3, characterized in that: The method for determining the detailed area of ​​the header is: If the table type is a multi-row header table, the header row area is the final header area, and the row obtained by merging the header rows is the header; If the table type is a multi-column header table, the header column area is the final header area, and the column obtained by merging the header columns is the header; If the table type is a table without a header, the text content in the table is treated as ordinary text and not as a table.

5. A table knowledge storage device in an intelligent question-answering scenario, characterized in that: include: A data acquisition module, which is used to acquire text information and table information in knowledge documents of different formats; The preliminary area determination module is used to determine the header area based on the table information and the position rule of the header formed in the table, wherein the position rule of the header formed in the table includes: The first rule: the table header is located in the front row or front column of the table, that is, at the top or side starting area of ​​the table; The second rule: the table header is the first few rows or columns, or there is no header, and there is no situation where the top or side starting area of ​​the table is all headers; The third rule: The actual number of columns or rows in the header should be equal to the number of columns or rows in the table; Fourth rule: In a multi-row header area, the number of cells in each row must be more than the row above it, and in a multi-column header area, the number of cells in each column must be more than the column to its left; The fifth rule: If the number of cells in the non-header area row or column is greater than the actual number of cells in the header, the corresponding row where the number of cells in the non-header area is greater than the actual number of cells in the header is merged up and down or the column is merged horizontally, and there must be a row or column with the same number of cells as the row or column where the number of cells in the non-header area is greater than the actual number of cells in the header; The sixth rule: There are adjacent rows or columns that are merged up and down, and both are headers, or neither is a header; The seventh rule: In the multi-row header area, there are no two adjacent cells that are neither merged horizontally nor merged vertically; in the multi-column header area, there are no two adjacent cells that are neither merged vertically nor merged horizontally; The determining of the header area based on the table information and the position rule of the header formed in the table includes: According to the first rule and the sixth rule, starting from the first row or the first column of the table stored in the row or column format, traverse the cells in each row or each column, and count whether there are upper and lower merge marks in the cells of each row or each column; if there are, the upper and lower adjacent rows or columns are grouped according to the marks, and if not, a single row or column is grouped; According to the fourth rule, the maximum number of cells in each row or column in each group is used as the number of cells in each group, and the grouping results are traversed from top to bottom. When the number of cells in the current group is less than or equal to the number of cells in the previous group, the process stops, and the current group and all the groups above are used as the header row to be selected; According to the seventh rule, traverse the groups in the header row or column selection area from bottom to top, and check whether there is a situation in each group where the same column or row is horizontally merged but not merged up and down; if so, discard the group and continue traversing; if not, stop traversing, and use the rows or columns included in the current group and all groups as the header row area or column area; the area after merging the header row area and the header column area is the header area; The detailed area determination module splices the text information of the determined table header area, uses the trained text classification model to classify the spliced ​​content, determines the category to which the table belongs, and then determines the detailed area of ​​the table header; A content parsing module is used to merge or split cells in the rest of the table based on the determined detailed area of ​​the table header and the table header as a reference, so as to obtain table content in which cells are not merged and the number of columns in each row and the number of rows in each column are the same; The knowledge storage module is used to convert the table content into a key-value pair using the text content of the header cell as the field name and the text content of the cell in the corresponding column or row as the value, and to compile a row or column in the original table into a set of key-value pair strings, which are then vectorized and stored in the vector library.

6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps in the table knowledge storage method in the intelligent question and answer scenario as described in any one of claims 1 to 4 are implemented.

7. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps in the table knowledge storage method in the intelligent question and answer scenario as described in any one of claims 1-4 are implemented.

Citation Information

Patent Citations

  • Table identification method and device, equipment and medium

    CN111695553A

  • Method for converting table information extracted from PDF document into structured knowledge

    CN113326797A

  • Table information extraction method and device, electronic equipment and storage medium

    CN113901214A

  • Table analysis method and device, computer equipment and storage medium

    CN114677695A

  • PDF sideline missing table content identification method and system

    CN116246289A