{'fraction_non_alphanumeric': 0.03349632438545721, 'fraction_numerical': 0.013238865050061537, 'mean_word_length': 4.813962483078708, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
LGPMA: Complicated Table Structure Recognition with Local and Global Pyramid Mask Alignment

Table structure recognition is a challenging task due to the various structures and complicated cell spanning relations. Previous methods handled the problem starting from elements in different granularities (rows/columns, text regions), which somehow fell into the issues like lossy heuristic rules or neglect of empty cell division. Based on table structure characteristics, we find that obtaining the aligned bounding boxes of text region can effectively maintain the entire relevant range of different cells. However, the aligned bounding boxes are hard to be accurately predicted due to the visual ambiguities. In this paper, we aim to obtain more reliable aligned bounding boxes by fully utilizing the visual information from both text regions in proposed local features and cell relations in global features. Specifically, we propose the framework of Local and Global Pyramid Mask Alignment, which adopts the soft pyramid mask learning mechanism in both the local and global feature maps. It allows the predicted boundaries of bounding boxes to break through the limitation of original proposals. A pyramid mask re-scoring module is then integrated to compromise the local and global information and refine the predicted boundaries. Finally, we propose a robust table structure recovery pipeline to obtain the final structure, in which we also effectively solve the problems of empty cells locating and division. Experimental results show that the proposed method achieves competitive and even new state-of-the-art performance on several public benchmarks.


Introduction
Table is one of the rich-information data formats in many real documents like financial statements, scientific literature, purchasing lists, etc. Besides the text content, the table structure is vital for people to do the key information extraction. Thus, table structure recognition [10,21,34,30,5,4,39] becomes one of the important techniques in current document understanding systems. From the global perspective, early table structure recognition processes usually depend on the detection of the grid's boundaries [19,18]. However, these methods can not handle tables without grid boundaries, such as three-line tables. Though recent works [30,22,32,31] attempt to predict row/column regions or even invisible grid lines [33], they are limited to handle tables that cross span multiple rows/columns. The row/column splitting operation might also cut cells that contain text in multiple lines.
Another group of methods solves the above problems in a bottom-up way to firstly detect the text blocks' positions and then recover the bounding-boxes' relations by heuristic rules [38] or GNN(Graph Neural Networks) [29,14,2,24,26]. However, rules designed based on bounding boxes of text regions are vulnerable to handling complicated matching situations. GNN-based methods not only bring extra network cost but also depend on more expensive training cost such as the data volume. Another issue is that these methods are difficult to obtain the empty cells because they usually fall into the visual ambiguity problem with the cross-row/column cells. The prediction of empty cells directly affects the correctness of table structure, as illustrated in Figure 1(a). Moreover, how to split or merge these empty regions is still a challenging problem that cannot be neglected, because different division results will generate different editable areas when the image is transferred into digital format.
Notice that the structure of the table itself is a human-made rule-based data form. Under the situation that tables are without visual rotation or perspective transformation, if we could obtain all of the perfect aligned cell regions rather than the text regions [26], the structure inference will be easy and almost lossless, as illustrated in Figure 1(b). Nevertheless, acquiring such information is not easy. On the one hand, the annotations of text regions [5,2,39] are much easier to get than cell regions. On the other hand, the aligned boxes are difficult to be accurately learned since there is usually no visible texture of boundaries at the region's periphery. Multi-row/column cells are easy to be confused with the empty cell regions. For example, in Figure 1(c), the network usually falls into the situation that the predicted aligned boxes are not large enough and results in the wrong cell matching. Although [26] designs an alignment loss to assist the bounding boxes learning, it only considers the relative relations between boxes and fails to capture the cell's absolute coverage area.
In this paper, we aim to train the network to obtain more reliable aligned cell regions and solve the problems of empty cell generation and partition in one model. Observing that people perceive visual information from both local text region and global layout when they read, we propose a uniform table structure recognition framework to compromise the benefits from both local and global information, called LGPMA (Local and Global Pyramid Mask Alignment) Network. Specifically, the model simultaneously learns a local Mask-RCNN-based [6] aligned bounding boxes detection task and a global segmentation task. In both tasks, we adopt the pyramid soft mask supervision [17] to help obtain more accurate aligned bounding boxes. In LGPMA, the local branch (LPMA) acquires more reliable text region information through visible texture perceptron, while the global branch (GPMA) can learn more legible spatial information of cells' range or division. The two branches help the network learn better-fused features via jointly learning and effectively refine the detected aligned bounding boxes through a proposed mask re-scoring strategy. Based on the refined results, we design a robust and straightforward table structure recovery pipeline, which can effectively locate empty cells and precisely merge them according to the guidance of global segmentation.
The major contributions of this paper are as follows: (1) We propose a novel framework called LGPMA Network that compromises the visual features from both local and global perspectives. The model makes full use of the information from the local and global features through a proposed mask re-scoring strategy, which can obtain more reliable aligned cell regions. (2) We introduce a uniform table structure recovering pipeline, including cell matching, empty cell searching, and empty cell merging. Both non-empty cells and empty cells can be located and split efficaciously. (3) Extensive experiments show that our method achieves competitive and even state-of-the-art results on several popular benchmarks.

Related Works
Traditional table recognition researches mainly worked with hand-crafted features and heuristic rules [8,10,34,19,18,3]. These methods are mostly applied to simple table structures or specific data formats, such as PDFs. The early techniques about table detection and recognition can be found in the comprehensive survey [37]. With the great success of deep neural network in computer vision field, works began to focus on the image-based table with more general structures [21,30,24,9,13,36,23,14,33]. According to the basic components granularities, we roughly divide previous methods into two types: global-object-based methods and local-object-based methods.
Global-object-based methods mainly focus on the characteristics of global table components and mostly started from row/column or grid boundaries detection. Works of [30,31,32] firstly obtain the rows and columns regions using the detection or segmentation models and then intersect these two regions to obtain the grids of cells. [22] handles the table detection and table recognition tasks in an end-to-end manner by the table region mask learning and table's row/column mask learning. [33] detects the rows and columns by learning the interval areas' segmentation between rows/columns and then predicting the indicator to merge the separated cells.
There also exist some methods [13,39] that directly perceive the whole image information and output table structures as text sequence in an encoder-decoder framework. Although these methods look graceful and entirely avoid human being involved, the models are usually challenging to be trained and rely on a large amount of training data. Global-object-based methods usually have difficulties in handling various complicated table structures, such as cells spanning multiple rows/columns or containing text in multi-lines.
Local-object-based methods begin from the smallest fundamental element, cells. Given the cell-level text region annotation, the text detection task is relatively easy to finish by the general detection methods like Yolo [27], Faster R-CNN [28], etc. After that, a group of methods [36,23,38] tries to recover the cell relations based on some heuristic rules and algorithms. Another type of methods [11,2,14,24,26] treat the detected boxes as nodes in a graph and attempt to predict the relations based on techniques of Graph Neural Networks [29]. [14] predicts the relations between nodes in three classes (the horizontal connection, the vertical connection, no connection) using several features such as visual features, text positions, word embedding, etc. [2] adopts graph attention mechanism to enhance the predicting accuracy. [24] alleviates the problem of large graph nodes numbers by the pair sampling strategy. The above three works [14,2,24] also published new table datasets for this research area. Since there is no empty cell detected, local-object based-methods usually fall into empty cell ambiguity.
In this paper, we try to compromise the advantages of both global and local features. Based on the local detection results, we integrate the global information to refine the detected bounding boxes and provide a straightforward guide for empty cell division.

Overview
We propose the model LGPMA, whose overall workflow is shown in Figure 2. We adopt the pyramid mask learning mechanisms in both branches and use a mask re-scoring strategy to refine the predicted bounding boxes. Finally, the table structure can be uniformly recovered by a pipeline, including cell matching, empty cell searching, and empty cell merging.
The model is built based on the existing Mask-RCNN [6]. The bounding box branch directly learns the detection task of aligned bounding boxes for nonempty cells. The network simultaneously learns a Local Pyramid Mask Alignment (LPMA) task based on the local feature extracted by the RoI-Align operation and a Global Pyramid Mask Alignment (GPMA) task based on the global feature map.
In LPMA, in addition to the binary segmentation task that learns the text region mask, the network is also trained with the pyramid soft mask supervision in both horizontal and vertical directions.
In GPMA, the network learns a global pyramid mask for all aligned bounding boxes of non-empty cells. To obtain more information about empty cell splitting, the network also learns the global binary segmentation task that considers both non-empty and empty cells.
A pyramid mask re-scoring module is then adopted to refine the predicted pyramid labels. The accurate aligned bounding boxes can be obtained by the process of plane clustering. Finally, a uniform structure recovering pipeline containing cell matching, empty cell searching, empty cell merging is integrated to obtain the final table structure.

Aligned Bounding Box Detection
The difficulty of accurate text region matching mainly comes from the covered range gap between text regions and the real cell regions. Real cell regions may contain empty spaces for row/column alignment, especially for those cells crossing span multiple rows/columns. Inspired by [26,36], with the annotations of text regions and row/column indices, we can easily generate the aligned bounding box annotations according to the maximum box height/width in each row/column. The regions of aligned bounding boxes approximately equal to that of real cells. For the table images in print format and without visual rotation or perspective transformation, if we could obtain the aligned cell regions and assume there is no empty cell, it is easy to infer the cell relations according to the coordinate overlapping information in horizontal and vertical directions.
We adopt Mask-RCNN [6] as the base model. In the bounding box branch, the network is trained based on the aligned bounding box supervision. However, the aligned bounding box learning is not easy because cells are easy to be confused with empty regions. Motivated by the advanced pyramid mask text detector [17], we find that using the soft-label segmentation may break through the proposed bounding box's limitation and provide more accurate aligned bounding boxes. To fully utilize the visual features from both local texture and global layout, we propose to learn the pyramid mask alignment information in these two folds simultaneously.

Local Pyramid Mask Alignment
In the mask branch, the model is trained to learn both a binary segmentation task and a pyramid mask regression task, which we call Local Pyramid Mask Alignment (LPMA).
The binary segmentation task is the same as the original model, in which only the text region is labeled as 1 and others are labeled as 0. The detected mask regions can be used in the following text recognition task.
For the pyramid mask regression, we assign the pixels in the proposal bounding box regions with the soft-label in both horizontal and vertical directions, as shown in Figure 3. The middle point of text will have the largest regressed target 1. Specifically, we assume the proposed aligned bounding box has the shape of H × W . The top-left point and bottom right point of the text region are denoted as {(x 1 , y 1 ), (x 2 , y 2 )}, respectively, where 0≤x 1 <x 2 ≤ W and 0≤y 1 <y 2 ≤ H. Therefore, the target of the pyramid mask is in shape R 2×H×W ∈[0, 1], in which the two channels represent the target map of the horizontal mask and vertical mask, respectively. For every pixel (h, w), these two targets can be formed as: where 0≤w<W , 0≤h<H, and x mid = x1+x2 2 , y mid = y1+y2 2 . In this way, every pixel in the proposal region takes part in predicting the boundaries.

Global Pyramid Mask Alignment
Although LPMA allows the predicted mask to break through the proposal bounding boxes, the local region's receptive fields are limited. To determine the accurate coverage area of a cell, the global feature might also provide some visual clues. Inspired by [40,25], learning the offsets of each pixel from a global view could help locate more accurate boundaries. However, bounding boxes in celllevel might be varied in width-height ratios, which leads to the unbalance problem in regression learning. Therefore, we use the pyramid labels as the regressing targets for each pixel, named Global Pyramid Mask Alignment (GPMA).
Like LPMA, the GPMA learns two tasks simultaneously: a global segmentation task and a global pyramid mask regression task. In the global segmentation task, we directly segment all aligned cells, including non-empty and empty cells. The ground-truth of empty cells are generated according to the maximum height/width of the non-empty cells in the same row/column. Notice that only this task learns empty cell division information since empty cells don't have visible text texture that might influence the region proposal networks to some extent. We want the model to capture the most reasonable cell division pattern during the global boundary segmentation according to the human's reading habit, which is reflected by the manually labeled annotations. For the global pyramid mask regression, since only the text region could provide the information of distinct 'mountain top,' all non-empty cells will be assigned with the soft labels similar to LPMA. All of the ground-truths of aligned bounding boxes in GPMA will be shrunk by 5% to prevent boxes from overlapping.

Optimization
The proposed network is trained end-to-end with multiple optimization tasks. The global optimization can be written as: where L rpn , L cls , L box , L mask are the same losses with that of Mask-RCNN, which represent the region proposal network loss, the bounding box classification loss, the bounding boxes regression loss and the segmentation loss of mask in proposals, respectively. L seg is the global binary segmentation loss that is implemented in Dice coefficient loss [20], L LP M A and L GP M A are the pyramid label regression losses which are optimized by pixel-wise L1 loss. λ 1 , λ 2 , λ 3 are weighted parameters.

Inference
The inference process can be described in two stages. We first obtain the refined aligned bounding boxes according to the pyramid mask prediction and then generate the final table structure by the proposed structure recovery pipeline.
Aligned Bounding Box Refine. In addition to the benefits generated via joint training, the local and global features also exhibit various advantages in object perceiving [35]. In our setting, we find that local features predict more reliable text region masks, while global prediction can provide more credible long-distance visual information. To compromise both levels' merits, we propose a pyramid mask re-scoring strategy to compromise predictions from LPMA and GPMA. For any proposal region with local pyramid mask prediction, we add the information that comes from the global pyramid mask to adjust these scores. We use some dynamic weights to balance the impacts from LPMA and GPMA.
Specifically, for a predicted aligned bounding box B={(x 1 , y 1 ), (x 2 , y 2 )}, we firstly obtain the bounding box of the text region mask, denoted as B t ={(x 1 , y 1 ), (x 2 , y 2 )}. Then, we can find a matched connected region P ={p 1 ,p 2 ,...,p n } in the global segmentation map, where p=(x, y) represents a pixel. We use P o = {p|x 1 ≤ p.x ≤ x 2 , y 1 ≤ p.y ≤ y 2 , ∀p ∈ P } to represent the overlap region. Then the predicted pyramid label of point (x, y) ∈ P o can be re-scored as follows.
hor (x, y) ver (x, y) y 1 ≤ y ≤ y mid y−y2 where x mid = ver (x, y) are the local horizontal, global horizontal, local vertical and global vertical pyramid label prediction, respectively.
Next, for any proposal region, the horizontal and vertical pyramid mask labels (corresponding to the z-coordinate) can be used to fit two planes in the 3-dimensional space, respectively. All the four planes' intersection lines with the zero plane are the refined boundaries. For example, to refine the right boundary of the aligned box, we select all pixels that P r = {p|x mid ≤ p.x ≤ x 2 , p ∈ P o } with the refined pyramid mask prediction F (x, y) to fit the plane. If we formed the plane as ax + by + c − z = 0, using the least square method, the problem is equal to minimize the equation of: The parameters of a, b, c can be calculated by the matrix as follows:

R-1,2,3 R-1 R-2 R-2 R-3 R-3 R-3 R-3 R-3 R-4 R-4 R-4 R-4 R-4 R-
where ||.|| is the set size. Then we calculate the intersection line between the fitting plane with the plane of z = 0. Given that the bounding boxes are axisaligned, we calculate the refined x-coordinate as the average value: Similarly, we can obtain the other three refined boundaries. Notice that the refining process can optionally be conducted iteratively refer to [17]. Table Structure Recovery. Based on the refined aligned bounding boxes, the table structure recovery pipeline aims to obtain the final table structure, including three steps: cell matching, empty cell searching and empty cell merging, as illustrated in Figure 4.
Cell Matching. In the situation that all of the aligned bounding boxes are axis-aligned, the cells matching process is pretty simple but robust. Following the same naming convention with [14,2,24], the connecting relations can be divided into horizontal and vertical types. The main idea is that if two aligned bounding boxes has enough overlap in x/y-coordinate, we will match them in vertical/horizontal direction. Mathematically, for every two aligned bounding boxes, {(x 1 , y 1 ), (x 2 , y 2 )} and {(x 1 , y 1 ), (x 2 , y 2 )}, they will be horizontally connected if y 1 ≤ y1+y2 2 ≤y 2 or y 1 ≤ y 1 +y 2 2 ≤y 2 . Similarly, they will be vertically connected if ≤x 2 . Empty Cell Searching. After obtaining the relations between the detected aligned bounding boxes, we treat them as nodes in a graph, and the connected relations are edges. All of the nodes in the same row/column make up a complete subgraph. Inspired by [24], we adopt the algorithm of Maximum Clique Search [1] to find all maximum cliques in the graph. Take the row searching process as an example, every node that belongs to the same row will be in the same clique. For the cell that crosses span multiple rows, the corresponding node will appear multiple times in different cliques. After sorting these cliques by the average ycoordinate, we can easily label each node with its row index. Nodes that appear in multiple cliques will be labeled with multiple row indices. We can easily find those vacant positions, which are corresponding to the empty cells.
Empty Cell Merging. By now, we have obtained the empty cells at the smallest level (occupies 1 row and 1 column). To merge these cells more feasibly, we first assign the single empty cells with the aligned bounding box shape as the cell's maximum height/width in the same row/column. Thanks to the visual clues learned by the global segmentation task, we can design the simple merging strategy following the segmentation result. We compute the ratio of pixels that are predicted as 1 in the interval region for every two neighbor empty cells, as the red region illustrated in Figure 4. If the ratio is larger than the preset threshold, we will merge these two cells. As we can see, the empty regions' visual ambiguity always exists, and the segmentation task can hardly be learned perfectly. That is why many segmentation-based methods [24,23,22] struggle with complicated post-processing, such as fracture completion and threshold setting. The proposed method straightforwardly adopts the original visual clue provided by global segmentation and uses pixel voting to obtain a more reliable result.

Datasets
We evaluate our proposed framework on following popular benchmarks that contain the annotations of both text content bounding boxes and cell relations.
ICDAR 2013 [5]. This dataset contains 98 training samples and 156 testing samples that cropped from the PDF of government reports.
SciTSR [2]. This dataset contains 12,000 training images and 3,000 testing images cropped from PDF of scientific literature. Authors also select a subset of complicated samples that contains 2,885 training images and 716 testing images, called SciTSR-COMP.
PubTabNet [39]. It is a large-scale complicated table collection that contains 500,777 training images, 9,115 validating images and 9,138 testing images. This dataset contains a large amount of three-lines tables with multi-row/column cells, empty cells, etc.

Implementation Details
All experiments are implemented in Pytorch with 8×32 GB-Tesla-V100 GPUs. The deep features are extracted and aggregated through the backbone of ResNet-50 [7] with Feature Pyramid Network (FPN) [15]. The weights of the backbone  For all benchmarks, the model is trained by the SGD optimizer with batch-size=4, momentum=0.9, and weight-decay=1 × 10 −4 . The initial learning ratio of 1 × 10 −2 is divided by 10 every 5 epochs. The model's training on SciTSR and PubTabNet lasts for 12 epochs, and the fine-tuning process on ICDAR 2013 lasts for 25 epochs. We also randomly scale the longer side of the input images to the lengths in the range [480, 1080] for all training processes. In the testing phase, we set the longer side of the input image as 768. We empirically set all weight parameters as λ 1 =λ 2 =λ 3 =1.

Results on Table Structure Recognition Benchmarks
We first conduct experiments on the datasets of ICDAR 2013 and SciTSR, and the evaluation metric follows [5] (counting the micro-averaged correctness of neighboring relations). Notice that since ICDAR 2013 has very few samples, many previous works used different training or pre-training data. To be comparable to [2] and [26], our model is only trained by the training set of SciTSR. We also report the result of the model that is then fine-tuned on the training set of ICDAR2013, labeled by †. The results of DeepDeSRT on SciTSR come from [2]. The results are demonstrated in Table 1, from which we can see that the proposed LGP-TabNet vastly surpasses previous advances on these three benchmarks by 4.4%, 3.5%, 2.5%, respectively. Beside, LGPMA shows no performance decline on the complicated testing dataset SciTSR-COMP, which demonstrates its powerful ability to perceive spatial relations.
We also test our model in a more challenging benchmark of PubTabNet, whose results are demonstrated in Table 2. Since the corresponding evaluation metric of TEDS [39] considers both table structure and text content, we simply adopt an attention-based model [12] to recognize the text recognition. In the results, our method surpasses the previous SOTA by 1.6 in TEDS. We also report the results that only considers the table structure, denoted as TEDS-Struc. The performance gap between TEDS-Struc and TEDS mainly comes from the recognition error and annotation ambiguities.
Visualization Results. We demonstrate some of the visualization results in Figure 5, in which the green boxes denote the predicted non-empty boxes, and blue boxes are the recovered empty boxes. We can see that our model can predict cells' accurate boundaries, even for those cross span multiple rows/columns. Figure 6 demonstrates an example that is successfully predicted due to the correct refinement. We only show the LPMA and GPMA maps in the horizontal direction, where the LPMA map is generated by overlapping all proposals' local maps. In the initially proposed bounding boxes, some boxes do not have enough breadth, which would lead to wrong matching results. After refining by LPMA and GPMA, these boundaries can reach the more feasible positions. The empty cells can also be merged feasibly according to the predicted segmentation map during the table structure recovery.

Ablation Studies
We randomly select 60,000 training images and 1,000 validation images from PubTabNet to conduct the subsequent ablation studies.
Effectiveness of Aligned Bounding Box Detection. To verify the effectiveness of the designed modules, we conduct a group of ablation experiments, as shown in Table 3. Besides the TEDS-Struc metric, we also report the text region's detection results and aligned bounding boxes, where the detection IoU threshold is 0.7, and empty cells are ignored. From the results, we can easily find that both LPMA and GPMA can vastly enhance the aligned bounding box detection performance, which is also proportional to the performance of TEDS-Struc. Although these modules are designed for aligned bounding boxes, they also slightly enhance the performance of text region detection results. The performance gap between text region detection and aligned bounding box detection again demonstrates the latter task is much more difficult and challenging. We also evaluate the effectiveness of Alignment Loss (abbr. AL) proposed by [26]. Although solely adopting AL achieves better performance than the original Mask-RCNN, the performance is even lower than the best results of LGPMA when compromising all three modules. It means AL might bring adverse impact on LGPMA. Compared to AL, our proposed LGPMA can obtain more performance gain by 3.1% in aligned bounding box detection and 0.59 in TEDS-Struc. Table Structure Recovery. To verify the proposed table recovery pipeline's effectiveness, we conduct experiments to compare different empty cell merging strategies, as illustrated in Table 4. The evaluations contain the detection results that only consider empty cells, the detection results of all aligned bounding boxes, and TEDS-Struc. The strategy of using minimum cells means the direct results after Empty Cell Searching, and using maximum cells  means merging all neighboring empty cells with the same height/width. From the results, we can see that our strategy using the visual information from GPMA can correctly merge many empty cells and obtain the highest performances in both detection and TED-Struc metrics. Compared with Strategy of Minimum empty cells , the promotion of Empty Cell Merging by LGPMA on TEDS-Struc is relatively small. This is because the number of empty cells minority, and most of them in this dataset are labeled in the smallest shapes. Nevertheless, our proposed empty cell merging strategy is more robust to adapt to any possibility. Suppose the aligned bounding boxes of non-empty cells are detected perfectly, which equals the situation given ground-truths, as shown in the bottom part of Table 4. In this case, we can easily find that using the strategy of whether Minimum cells or the proposed LGPMA can almost achieve 100% accuracy in table structure recovery, and many errors come from the noisy labels. It demonstrates the robustness of our table structure recovery pipeline, and the performance mainly depends on the correctness of aligned bounding box detection.

Conclusion
In this paper, we present a novel framework for table structure recognition named LGPMA. We adopt the local and global pyramid mask learning to compromises advantages from both local texture and global layout information. In the inference stage, fusing the two levels' predictions via a mask re-scoring strategy, the network generates more reliable aligned bounding boxes. Finally, we propose a uniform table structure recovery pipeline to get the final results, which can also predict the feasible empty cell partition. Experimental results demonstrate our method has achieved the new state-of-the-art in three public benchmarks.