This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

Neural Graph Matching for Modification Similarity Applied to Electronic Document Comparison

Po-Fang Hsu    Chiching Wei Po-Fang Hsu is with the Department of Advanced Document Technologies, Foxit Software Inc., 41841 Albrae Street. Fremont, CA, 94538 USA (e-mail: [email protected]).Chiching Wei (CTO) is with Foxit Software Inc., 41841 Albrae Street., Fremont, CA, 94538 USA (e-mail: [email protected]).
Abstract

This paper presents a novel neural graph matching approach applied to document comparison, which is a common task in legal and financial industries. In some cases, the most important differences are the addition or omission of words, sentences, clauses, or paragraphs. However, comparing document is a challenging task if the whole editing process is not recorded or traced. Under many temporal uncertainties, the potentiality of our approach is explored to approximate the accurate comparison to make sure which element blocks have a relation of edition with others. In the beginning, a document layout analysis that combines traditional and modern techniques to segment layout in blocks of various types is applied. Then this issue is transformed to a problem of layout graph matching with textual awareness. Graph matching is a long-studied problem with a broad range of applications. Different from previous works that focus on visual images or structural layout, we also bring textual features into our model to adapt this textually-rich domain. Specifically, based on the decodable electronic document, an encoder is introduced to deal with the visual presentation decoded from PDF. Additionally, since the modifications can cause the inconsistency of document layout analysis between modified documents and the blocks can be merged and split, Sinkhorn divergence is adopted in our graph neural approach, which tries to overcome both these issues with many-to-many block matching. This is demonstrated on two categories of layouts, legal agreement and scientific articles, collected from our real-case datasets.

{IEEEkeywords}

document comparison, graph matching, graph neural network, modification similarity, multi-modal

\IEEEpeerreviewmaketitle

1 Introduction

\IEEEPARstart

Document comparison, also known as redlining or blacklining, is a process of cross checking new versions of a document against previous copies in order to identify changes. These differences could include minor formatting modifications, such as font or spacing changes, or more significant grammatical changes. Document comparison is a common task in the legal and financial industries. In some cases, however, the most important differences may be the addition or omission of words, sentences, clauses, or paragraphs.

Traditionally, document comparison is generally processed through three stages. The first stage is document layout analysis, which analyzes document structures using primitive heuristics, statistical methods, or machine learning. Block-matching is then applied to match all of the blocks according to their modification similarity. Finally, edit distance can be used to evaluate the string similarity for matching all of the text in each block pair.

Refer to caption
Figure 1: Block Matching.

In the beginning, a document layout analysis process is applied that combines traditional and modern techniques to segment layout in blocks of various types. For example, a table should be classified into cells and another blocks can be paragraph, title, section, and so on. To perform a suitable comparing process, understanding the pairs of matched blocks should be compared is an indispensable step, such as in Fig.1. However, this is not an easy task if the whole editing process is not recorded or traced. Under many temporal uncertainties, to make sure which blocks have a relationship of edition with each other, the best solution is not existed. For example, we cannot determine definitely whether a paragraph ”123xxxx” is modified from paragraph ”xx123oo”, ”123xx”, or a completely new paragraph. Generally, the challenges can be classified into the following categories.

Semantic Inconsistency

One type of modification is semantic inconsistency of the component. After modifying, a paragraph block can become a list item or another type of layout. The context of the text, nearby blocks, and style of blocks should be considered.

Geometric Inconsistency

The position of the component that is changed is called Geometric Inconsistency. This means that a component is shifted by reading order. Additionally, a block can be split into multiple blocks, or merged with other blocks as shown in Fig. 2.

Text Ambiguity

Because of the modification, it is difficult to distinguish which blocks should be paired in some situation. For example, a list item block “c) Ambiguous Text:” should be paired with list item block “c) Text Ambiguity:” or the other near list item block “d) Ambiguous Text:”.

Refer to caption

Figure 2: Matching Cases.

An algorithm is designed to approximate the best solution. First, locate templates from two different versions with graph matching method. The graphs are then processed to find the most similar pairs in text level edited distance.

Graph matching – establishes correspondences between two graphs represented in terms of both local node structure and pair-wise relationships, whether they are visual, geometric, or topological. It is important in areas such as combinatorial optimization, machine learning, image analysis, or computer vision, and has applications in structure-from-motion, object tracking, 2d and 3d shape matching, image classification, social network analysis, autonomous driving, and more.

A novel two-stage neural approach, which overcomes both limitations. The first stage learns a representation for the layout in the page by combining both the text and visual information extracted from PDF code. This stage is able to largely generalize document format for acquiring all representation without expensive computing and storage features over visual renderings of the page. The second stage detects edited relatedness using a graph neural network. Unlike other traditional methods such as iterative closest point, which are limited to rigid displacements, graph matching naturally encodes structural information that can be used to model complex relationships and more diverse transformations.

2 Related Works

2.1 Document Comparison

Document comparison[7, 8], also known as redlining or blacklining, is a process of cross checking new versions of a document against previous copies in order to identify changes.

2.2 Document Layout Presentation

The recent work by Manandhar et al. [5] is the first to leverage GNNs to learn structural similarity of 2D graphical layouts, focusing on UI layouts with rectangular boundaries. The work employed a GCN-CNN architecture on a graph of UI layout images, also under an IoU-trained triplet network [20]. In addition, [10] learns the graph embeddings in a dependent manner. Through cross-graph information exchange, the embeddings are learned in the context of the anchor-positive (respectively, the anchor-negative) pair.

2.3 Graph Matching

Non-deep learning methods

The structural SVM based supervised learning method [16] incorporates earlier graph matching learning methods [1, 2, 3, 4]. Learning can also be fulfilled by unsupervised [3] and semi-supervised [17] mechanisms. In these earlier works, no neural network is adopted until the recent seminal work [6, 15].

Deep-learning methods

Deep learning is recently applied for graph matching on images [15], whereby convolutional neural network (CNN) is used to extract node features from images followed with spectral matching and CNN is learned using a regression-like node correspondence supervision. This work is improved by introducing GNN to encode structural [14] or geometric [19] information, with a combinatorial loss based on cross-entropy loss, and Sinkhorn network [18]. LayoutGMN [10] learns to predict structural similarity between two layouts with an attention-based graph matching network.

3 Our Approach

3.1 Decoding-Aware Visual Feature Presentation

Previous general approaches have need of the image examples for extracting and aligning the visual information. Indeed, image is a significant important feature in document representations. However, for the time being, it is a huge surge in document electronically, almost formats of electronic document render with the same encoding. As PDF, displaying the exact same content and layout no matter which operating system, device or software application it is viewed on. For PDF 1.4, the visual features are embedded as shown in Fig. 3; font style is shown in (Green), font size is shown in (Blue), color is shown in (Tan), position is shown in (Red) and text encode is shown in (Bold).

Refer to caption

Figure 3: PDF Code.
Refer to caption
Figure 4: Graph Encoder.

3.2 Graph Representation For Layout

A variety of visual and content-based features can be incorporated as the initial node features, such as the text, font, size, and type of a layout element or the image features in a document page. For modified learning in decodable electronic document tasks such as ours, we can only focus on content-based features. However, our work is not similar to [9, 10], the initial node features only contain semantic and geometric information of the layout elements. Since text and related features need to be considered, we simply apply Sentence-BERT[11] here to embed all of the text in the element. As shown in Fig. 4(a), which describes a document layout with height hh and width ww as a spatial graph G=(V,E)G=(V,E) where V={c1,,ci,,ck}V=\{c_{1},\cdots,c_{i},\cdots,c_{k}\} is set of nodes representing its k components and E={e1,,ei,,ek}E=\{e_{1},\cdots,e_{i},\cdots,e_{k}\} is the set of edges that denotes a relationship between them. Each node carries three or four types of information:

  • (Optional) Semantic property sis_{i}: A one-hot vector denoting the component class.

  • Text property tit_{i}: All the embedded text inside the component.

  • Geometric property gig_{i}: Captures the spatial location of the component in layout are encoded.

  • Visual property viv_{i}: Extracts the visual features from PDF code.

Let (xi,yi)(x_{i},y_{i}) and (wi,hi)(w_{i},h_{i}) be the geometrical centroid, width and height of the component c1c_{1}, and Ai=wihiA_{i}=\sqrt{w_{i}h_{i}}, then the geometric feature gig_{i} is [xiw,yih,wiw,hih,Aiwh][\frac{x_{i}}{w},\frac{y_{i}}{h},\frac{w_{i}}{w},\frac{h_{i}}{h},\frac{A_{i}}{wh}].

Define the edges features rijr_{ij} associated with edge eije_{ij} using the pairwise geometric features between components cic_{i} and cjc_{j} given below.

rij=[ϕij,wjwi,hjhi,1DΔx2+Δy2,ΔxAi,ΔyAi,θij]r_{ij}=[\phi_{ij},\frac{w_{j}}{w_{i}},\frac{h_{j}}{h_{i}},\frac{1}{D}\sqrt{\Delta x^{2}+\Delta y^{2}},\frac{\Delta x}{A_{i}},\frac{\Delta y}{A_{i}},\theta_{ij}] (1)

Where Δx=xj+xi\Delta x=x_{j}+x_{i} and Δy=yj+yi\Delta y=y_{j}+y_{i} are the shifts between the components and constant D=w2+h2D=\sqrt{w^{2}+h^{2}} normalises against the diagonal. In addition, the feature rijr_{ij} incorporates various geometric relations such as relative distance, aspect ratios and orientation θ=arctan2(ΔyΔx)[π,π]\theta=\arctan 2(\frac{\Delta y}{\Delta x})\in[-\pi,\pi]. We explicitly include a containment feature ψij\psi_{ij} taking into account the Intersection over Union (IoU) between components capturing the nesting of the layout components:

ψij=(M(ci)M(cj))(M(ci)M(cj)\psi_{ij}=\frac{(M(c_{i})\cap M(c_{j}))}{(M(c_{i})\cup M(c_{j})} (2)

The visual feature viv_{i} is a 3xN matrix of which N is the same as the length of the text of component, and the 3 types of features (Font-style, Size, and Color) are obtained from PDF code:

  • Font-style encodes typeface and font. For example, LiberationSans-Bold is encoded as below.

    LiberationSans \cdots\cdots Bold
    1 0 1
  • Size is the size of text.

  • Color is obtained by transforming color space to YCbCr with 4:2:0 chroma subsampling.

3.3 Layout Graph Encoder

As show in Fig. 4(c), the node features nin_{i} in the graph hold both the semantic class label sis_{i} as well as the geometric property gig_{i}, text property viv_{i} and visual presentation viv_{i} of the layout component cic_{i}. n0=En([Ec(Es(s0),Et(t0),Ev(v0))g0])n_{0}={E_{n}([E_{c}(E_{s}(s_{0}),E_{t}(t_{0}),E_{v}(v_{0}))g_{0}])} where EE is the embedding layer that learns the several kinds of features and then projects the features into node feature nin_{i}. Similarly, the edge features rijr_{ij} are projected by Er(rij)E_{r}(r_{ij}). Next, the node features and the edge (relation) features are operated by graph convolutional networks gn()g_{n}(\cdot) and gr()g_{r}(\cdot). The node and relational feature outputs of the GCN network are computed by xni=gn(ni)x_{n_{i}}=g_{n}(n_{i}) , xrij=gr([niEr(rij)nj])x_{r_{ij}}=g_{r}([n_{i}E_{r}(r_{ij})n_{j}]). The relation graph network grg_{r} operates on tuples ni,Er(rij)\langle n_{i},E_{r}(r_{ij}), njn_{j}\rangle passing the information through the graph to learn the overall layout. Then obtain two set of features Xn={xn1,xn2,,xnn},Xr={xr1,xr2,,xrn}X_{n}=\{x_{n_{1}},x_{n_{2}},\cdots,x_{n_{n}}\},X_{r}=\{x_{r_{1}},x_{r_{2}},\cdots,x_{r_{n}}\}. Where kk and kk^{{}^{\prime}} are the number of components (node features) and the total number of the relationship features which vary for different layout layouts. Next, the sets of features are passed through self-attention modules which learn to pool the node features and relational features given by

fnatt=i=1kanixni,fratt=i=1karixrif_{n}^{att}=\sum_{i=1}^{k}a_{n_{i}}x_{n_{i}},f_{r}^{att}=\sum_{i=1}^{k^{{}^{\prime}}}a_{r_{i}}x_{r_{i}} (3)
exp(wnxni)l=1nexp(wnTxnl),exp(wrxri)l=1kexp(wrTxrl)\frac{\exp(w_{n}^{\intercal}x_{n_{i}})}{\sum_{l=1}^{n}\exp(w_{n}^{T}x_{n_{l}})},\frac{\exp(w_{r}^{\intercal}x_{r_{i}})}{\sum_{l=1}^{k^{{}^{\prime}}}\exp(w_{r}^{T}x_{r_{l}})} (4)

where, ania_{n_{i}} and aria_{r_{i}} are attention weights learned with wnw_{n}^{\intercal} and wrw_{r}^{\intercal} parameters.

Finally, obtain a d-dimensional latent embedding that encodes the layout:

fe=Ee([fnatt,fratt])f_{e}=E_{e}([f_{n}^{att},f_{r}^{att}]) (5)

3.4 Layout Graph Matching Neural Network

We modify previous works [12, 13, 14] to implement our approach. The learning process of our matching neural network is shown in Alg. 1.

Algorithm 1 Iterative cross-graph node embedding
1:Block features {b1i(0),b2j(0)}iν1,jν2\{b_{1i}^{(0)},b_{2j}^{(0)}\}_{i\in\nu_{1},j\in\nu_{2}}; number of iterations K
2:embedding features {b1i(3),b2j(3)}iV1,jV2\{b_{1i}^{(3)},b_{2j}^{(3)}\}_{i\in V_{1},j\in V_{2}}
3:// first intra-graph aggregation
4:{bsi(1)}GConv1(As,{hsi(0)});\{b_{si}^{(1)}\}\leftarrow GConv_{1}(A_{s},\{h_{si}^{(0)}\});
5:// Initialize S^(0)\hat{S}^{(0)} as zero matrix
6:S^(0)0N×N\hat{S}^{(0)}\leftarrow 0^{N\times N};
7:for k{1K}k\leftarrow\{1...K\} do
8:     // cross-graph aggregation
9:     {h1i(2)}GConv(S^(k1){h1i(1)},{h2i(1)});\{h_{1i}^{(2)}\}\leftarrow GConv(\hat{S}^{(k-1)}\{h_{1i}^{(1)}\},\{h_{2i}^{(1)}\});
10:     {h1i(2)}GConv(S^(k1),{h2i(1)},{h1i(1)});\{h_{1i}^{(2)}\}\leftarrow GConv(\hat{S}^{(k-1)\top},\{h_{2i}^{(1)}\},\{h_{1i}^{(1)}\});
11:     // second intra-graph aggregation
12:     {hsi(3)}GConv(As,{hsi(2)});\{h_{si}(3)\}\leftarrow GConv(A_{s},\{h_{si}^{(2)}\});
13:     // correspondence prediction
14:     build M^\hat{M} from {h1i(3)},{h2i(3)};\{h_{1i}^{(3)}\},\{h_{2i}^{(3)}\};
15:     S^(k)Sinkhorn(M);\hat{S}^{(k)}\leftarrow Sinkhorn(M);
16:end for

4 Datasets

To the best of our knowledge, this work is the first to explore the topic of document comparison in visually-rich documents. Two kinds of layout datasets are collected and constructed: legal agreement and scientific articles. After data filtering, the size of the two datasets is 30 and 25 respectively. The component-level region bounding box is provided according to manual validation for the prediction of our Cascade Mask R-CNN[21] based document layout analysis detector. The corresponding transcript is annotated with the help of in-house workers, using a Web based annotation tool, Label Studio[22]. The annotation process was organized into two stages. In Stage 1, workers were shown a pair of document images with the annotation of layout segmentation and they revised the wrong annotation predicted from DLA predictor. Stage 2 aims to construct the matching relation between the components. Workers simply used the Relations tag provided by Label Studio to create label relations between regions.

5 Conclusions

A novel graph neural network is presented to solve both context similarity of components and structural matching between layout components. The main limitation of the current proposed framework is the requirement for strong a priori knowledge, which means that the framework is not so robust in revising the wrong input from document layout analysis. Another limitation of the current network is that it does not learn hierarchical graph representations which is desirable when dealing with cross-page comparison.

References

  • [1] L. Torresani, V. Kolmogorov, and C. Rother, “Feature correspondence via graph matching: Models and global optimization,” in Eur. Conf. Comput. Vis. Springer, 2008, pp. 596–609.
  • [2] T. Caetano, J. McAuley, L. Cheng, Q. Le, and A. J. Smola, “Learning graph matching,” Trans. Pattern Anal. Mach. Intell., vol. 31, no. 6, pp. 1048–1058, 2009.
  • [3] M. Leordeanu, R. Sukthankar, and M. Hebert, “Unsupervised learning for graph matching,” Int. J. Comput. Vis., vol. 96, no. 1, pp. 28–45, 2012.
  • [4] Andrei Zanfir, “Deep Learning of Graph Matching,” IEEE/CVF Conference on Computer Vision and Pattern Recognition, 2018.
  • [5] Dipu Manandhar, Dan Ruta, and John Collomosse, “Learning Structural Similarity of User Interface Layouts using Graph Networks,” ECCV, 2020.
  • [6] Minsu Cho, “Progressive Graph Matching: Making a Move of Graphs via Probabilistic Voting, CVPR.2012.
  • [7] Andrew Kao, “How to compare two PDF documents side by side,” https://www.foxitsoftware.com/blog/how-to-compare-two-pdf-documents-side-by-side/
  • [8] ADOBE ACROBAT, “Easily compare PDF files.,” https://acrobat.adobe.com/us/en/acrobat/how-to/compare-two-pdf-files.html
  • [9] Dipu Manandhar et al, “Learning Structural Similarity of User Interface Layouts using Graph Networks,” CVPR 2021.
  • [10] Akshay Gadi Patil et al, “LayoutGMN: Neural Graph Matching for Structural Layout,” CVPR 2021.
  • [11] Nils Reimers and Iryna Gurevych, “Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks,” ACL 2019.
  • [12] R Wang, J Yan, X Yang, “Learning combinatorial embedding networks for deep graph matching,” The IEEE International Conference on Computer Vision (ICCV), October 2019.
  • [13] Wang, J Yan, X Yang, “Combinatorial Learning of Robust Deep Graph Matching: an Embedding based Approach,” IEEE Transactions on Pattern Analysis and Machine Intelligence, 2020.
  • [14] R. Wang, J. Yan and X. Yang, “Neural Graph Matching Network: Learning Lawler’s Quadratic Assignment Problem with Extension to Hypergraph and Multiple-graph Matching,” TPAMI 2021
  • [15] A. Zanfir and C. Sminchisescu, “Deep learning of graph matching,” Comput. Vis. Pattern Recog., 2018, pp. 2684–2693.
  • [16] M. Cho, K. Alahari, and J. Ponce, “Learning graphs to match,” Int. Conf. Comput. Vis., 2013, pp. 25–32.
  • [17] M. Leordeanu, A. Zanfir, and C. Sminchisescu, “Semi-supervised learning and optimization for hypergraph matching,” Int. Conf. Comput. Vis. IEEE, 2011, pp. 2274–2281.
  • [18] R. Adams and R. Zemel, “Ranking via sinkhorn propagation,” arXiv:1106.1925, 2011.
  • [19] Z. Zhang and W. S. Lee, “Deep graphical feature learning for the feature matching problem,” Int. Conf. Comput. Vi., 2019, pp. 5087–5096.
  • [20] Elad Hoffer and Nir Ailon, “Deep metric learning using triplet network,” International Workshop on Similarity-Based Pattern Recognition, pages 84–92. Springer, 2015.
  • [21] Junlong Li et al., “DiT: Self-supervised Pre-training for Document Image Transformer,” arXiv 2022.
  • [22] Maxim Tkachenko et al., “Label Studio: Data labeling software,” 2020-2021.