Neural Graph Matching for Modification Similarity Applied to Electronic Document Comparison
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.
document comparison, graph matching, graph neural network, modification similarity, multi-modal
1 Introduction
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.

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:”.
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
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).

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 and width as a spatial graph where is set of nodes representing its k components and is the set of edges that denotes a relationship between them. Each node carries three or four types of information:
-
•
(Optional) Semantic property : A one-hot vector denoting the component class.
-
•
Text property : All the embedded text inside the component.
-
•
Geometric property : Captures the spatial location of the component in layout are encoded.
-
•
Visual property : Extracts the visual features from PDF code.
Let and be the geometrical centroid, width and height of the component , and , then the geometric feature is .
Define the edges features associated with edge using the pairwise geometric features between components and given below.
(1) |
Where and are the shifts between the components and constant normalises against the diagonal. In addition, the feature incorporates various geometric relations such as relative distance, aspect ratios and orientation . We explicitly include a containment feature taking into account the Intersection over Union (IoU) between components capturing the nesting of the layout components:
(2) |
The visual feature 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 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 in the graph hold both the semantic class label as well as the geometric property , text property and visual presentation of the layout component . where is the embedding layer that learns the several kinds of features and then projects the features into node feature . Similarly, the edge features are projected by . Next, the node features and the edge (relation) features are operated by graph convolutional networks and . The node and relational feature outputs of the GCN network are computed by , . The relation graph network operates on tuples , passing the information through the graph to learn the overall layout. Then obtain two set of features . Where and 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
(3) |
(4) |
where, and are attention weights learned with and parameters.
Finally, obtain a d-dimensional latent embedding that encodes the layout:
(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.
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.