HiPool: Modeling Long Documents Using Graph Neural Networks
Year: 2023

Abstract:
Encoding long sequences in Natural Language Processing (NLP) is a challenging problem. Though recent pretraining language models achieve satisfying performances in many NLP tasks, they are still restricted by a pre-defined maximum length, making them challenging to be extended to longer sequences. So some recent works utilize hierarchies to model long sequences. However, most of them apply sequential models for upper hierarchies, suffering from long dependency issues. In this paper, we alleviate these issues through a graph-based method. We first chunk the sequence with a fixed length to model the sentence-level information. We then leverage graphs to model intraand cross-sentence correlations with a new attention mechanism. Additionally, due to limited standard benchmarks for long document classification (LDC), we propose a new challenging benchmark, totaling six datasets with up to 53k samples and 4034 average tokens’ length. Evaluation shows our model surpasses competitive baselines by 2.6% in F1 score, and 4.8% on the longest sequence dataset. Our method is shown to outperform hierarchical sequential models with better performance and scalability, especially for longer sequences.

heading: 1 Introduction
text: Transformer-based models like BERT (Vaswani et al., 2017a) and RoBERTa (Zhuang et al., 2021) have achieved satisfying results in many Natural Language Processing (NLP) tasks thanks to largescale pretraining (Vaswani et al., 2017b). However, they usually have a fixed length limit, due to the quadratic complexity of the dense self-attention mechanism, making it challenging to encode long sequences.
One way to solve this problem is to adapt Transformers to accommodate longer inputs and optimize the attention from BERT (Feng et al., 2022; Jaszczur et al., 2021). BigBird (Zaheer et al., 2020) applies sparse attention that combines random,
global, and sliding window attention in a long sequence, reducing the quadratic dependency of full attention to linear. Similarly, Longformer (Beltagy et al., 2020) applies an efficient self-attention with dilated windows that scale linearly to the window length. Both models can take up to 4096 input tokens. Though it is possible to train even larger models for longer sequences, they are restricted by a pre-defined maximum length with poor scalability. More importantly, they fail to capture high-level structures, such as relations among sentences or paragraphs, which are essential to improving NLP system performance (Zhang et al., 2018; Zhu et al., 2019).
Another way is to apply a hierarchical structure to process adjustable input lengths with chunking representations for scalability on long sequences. Hi-Transformer (Wu et al., 2021) encodes both sentence-level and document-level representations using Transformers. ToBERT (Pappagari et al., 2019) applies a similar approach that stacks a sentence-level Transformer over a pretrained BERT model. While most of the existing work models upper-level hierarchy using sequential structures, such as multiple layers of LSTMs (Hochreiter and Schmidhuber, 1997) or Transformers, this may still bring the long dependency issue when the sequence gets longer. To alleviate this, we investigate graph modeling as a novel hierarchy for upper levels. Besides, we also consider inter-hierarchy relationships using a new attention mechanism.
Our key insight is to replace the sequence-based model with a hierarchical attentional graph for long documents. We first apply a basic pretrained language model, BERT or RoBERTa, to encode local representation on document chunks with a fixed length. The number of chunks could be extended for longer sequences for better scalability. Different from other works, we apply a graph neural network (GNN) (Zhou et al., 2018) to model the upper-level hierarchy to aggregate local sentence in-
161
formation. This is to alleviate the long dependency issue of the sequential model. Moreover, within such a graph structure, we propose a new heterogeneous attention mechanism to consider intra- and cross- sentence-level correlations.
Our contributions are two-fold: 1) We propose HiPool with multi-level hierarchies for long sequence tasks with a novel inter-hierarchy graph attention structure. Such heterogeneous graph attention is shown to outperform hierarchical sequential models with better performance and scalability, especially for longer sequences; 2) We benchmark the LDC (long document classification) task with better scaled and length-extended datasets. Evaluation shows that HiPool surpasses competitive baselines by 2.6% in F1 score, and 4.8% on the longest sequence dataset. Code is available at https: //github.com/IreneZihuiLi/HiPool.

heading: 2 Model
text: We introduce the HiPool (Hierarchical Pooling) model for long document classification, illustrated in Fig. 1. It consists of an overlapping sequence encoder, a HiPool graph encoder, and a linear layer. Overlapping Sequence Encoder. Given the input document S, we first chunk the document into a number of shorter pieces with a fixed length L, and we set the overlapping window size to be Lolp. Overlapping encoding makes it possible for a chunk to carry information from its adjacent chunks but not isolated, differentiating our model from other hierarchical ones. Then each chunk is encoded with a pretrained Transformer model, i.e., BERT or RoBERTa; we choose the CLS token representation as the input to our HiPool layer: X = BERT(S). HiPool Graph Encoder. We apply a graph neural network to encode incoming word-level information. Such a model has shown its potential in some NLP tasks (Li et al., 2022, 2021). We construct a graph, defined by G(V,E), where V is a set of nodes, and E is a set of node connections. There are two node types: n low-level nodes and m high-level nodes, and typically m < n. In our experiment, we set m = n/p, and p ≥ 0. The feedforward operation goes from low- to high-level nodes. In layer l, low-level nodes are inputs from the previous layer l − 1, while high-level nodes at layer l are computed based on low-level ones. Moreover, these high-level nodes will be the input to the next layer l + 1, becoming the low-level nodes in that layer. We consider X the low-level
Proposed Method Multi-level hierarchies for long sequence tasks with a novel inter-hierarchy graph attention structure. Heterogeneous graph attention is shown to outperform hierarchical sequential models with better performance and scalability, especially for longer sequences. Overlapping Sequ nce Encoder
● Pretrained model for fixed sequence length. ● Possible to be extended to longer input.
HiPool Graph Encoder ● Each layer and convolution
● Node clustering:
● Updating the nodes with information exchange
Linear Layer ● Cross entropy loss for training
HiPool model illustration. Figure 1: HiPool model illustration. It consists of a sequence encoder, HiPool graph encoder and a linear layer.
nodes in the first HiPool layer, as shown in the figure.
In each HiPool layer, given node representation H l and adjacency matrix Al at layer l, the task is to obtain H l+1:
H l+1 = HiPool(H l, Al). (1)
Inspired by DiffPool (Ying et al., 2018), we conduct a clustering method to aggregate information. We assign node clusters with a fixed pattern based on their position. For example, adjacent low-level neighbors should map to the same high-level clustering node. So we first define a clustering adjacency matrix Aself ∈ IRn×m that maps n nodes to m nodes, indicating the relations from low- to high- level nodes, marked as black arrows in the figure. Note that our approach allows overlapping, in which some nodes may belong to two clusters. We set the clustering sliding window to be 2p, with a stride to be p. In the figure, we show the case of p = 2. We denote interactions between low-level nodes by the adjacency matrix Al,1 and we model it using a chain graph, according to the natural order of the document.2
Then, the relations between high-level nodes Alhigh and their node representations H l high are computed: Alhigh = A T selfA lAself ,
H lhigh = AselfH l.
(2)
1We eliminated the subscript of Alow for simplicity, and this also makes Eq. 1 more generalized as other GNNs.
2We tested with a complete graph and BigBird attention structures but found little differences.
Besides, for each high-level node, to strengthen the connections across different clusters, we propose an attention mechanism to obtain crosssentence information. We propose a new edge type that connects external cluster low-level nodes to each high-level node, and the adjacency matrix is simply Across = 1−Aself , marked by green in the figure. We update H lhigh as the following:
Wscore = H l selfWatten(H l)T , Wscore = WscoreA T cross,
H lhigh ←WscoreH l +H lhigh, (3)
where Watten is trainable, and Wscore is a scoring matrix. We then apply a GNN to obtain H l+1. For example, a graph convolution network (GCN) (Kipf and Welling, 2016):
H l+1 = GCN(H lhigh, A l high). (4)
We run our experiments with two layers, and apply a sum aggregator to achieve document embeddings. More HiPool layers are also possible. Linear Layer. Finally, a linear layer is connected and cross-entropy loss is applied during training.

heading: 3 Experiments

heading: 3.1 LDC Benchmark
text: The LDC benchmark contains six datasets. We first choose four widely-used public datasets. Hyperpartisan (HYP) (Kiesel et al., 2019) and 20NewsGroups (20NG) (Lang, 1995) are both news text datasets with different scales. IMDB (Maas et al., 2011) is a movie review dataset for sentiment classification. ILDC (Malik et al., 2021) is a large corpus of legal cases annotated with binary court decisions (“accepted”and “rejected”). Limitation and new datasets. However, 20NewsGroups and IMDB cannot test the limit of models in encoding long documents since the average length of sentence is still relatively small; whereas Hyperpartisan only contains 645 examples and is thus prone to overfitting and not representative. ILDC is large and contains long texts, but it is mainly in the legal domain. Therefore, to enrich evaluation scenario, we select and propose two new benchmarks with longer documents based on an existing large-scale corpus, Amazon product reviews (He and McAuley, 2016), to conduct long document classification. Amazon-512 (A-512) contains all reviews that are longer than 512 words from the Electronics category; Amazon-2048 (A-2048)
contains 10,000 randomly sampled reviews that are longer than 2048 words from the Books category. We randomly split 8/1/1 as train/dev/test sets for both datasets. The proposed datasets enable us to draw statistically significant conclusions on model performance as sequence lengths increase, as demonstrated in in Table 1.

heading: 3.2 Evaluation
text: Hyperparameters. We list details in Appendix C. Baselines. We select four pretrained models: BERT (Devlin et al., 2019), RoBERTa (Zhuang et al., 2021), BigBird (Zaheer et al., 2020) and Longformer (Beltagy et al., 2020). We also compare with a hierarchical Transformer model ToBERT (Pappagari et al., 2019). Hi-Transformer (Wu et al., 2021) failed to be reproduced as there is no code available. We evaluate two variations of our HiPool method by changing the sequence encoder model: HiPool-BERT and HiPool-RoBERTa. We report the Micro-F1 score in Tab. 2. Main Results. Among the pretrained models, Longformer and BigBird perform better than BERT and RoBERTa. ToBERT can only surpass BERT as it is a hierarchical model that applies BERT as its text encoder. On average, HiPool-BERT improves significantly on BERT by 5.9% and on ToBERT by 3%. Compared to ToBERT, the superior performance of HiPool can be explained by the fact that sentence-level representations in ToBERT fails to capture cross-sentence information. HiPool surpasses baselines on A-512, A-2048 and ILDC that contain longer sequences. Notably, the best model, HiPool-RoBERTa, outperforms BigBird by 4.8% on ILDC. While our model applies a basic pretrained text encoder (the maximum length is 512), it can still surpass larger pretrained language models (i.e., the maximum length is 4096). Although HiPool is worse on HYP and IMDB, we note that HYP only has 65 examples in testing and is prone to overfitting. We further show that even in IMDB, HiPool still out-performs the best model for long
sequence in Appendix A. Hierarchy variations. To further compare sequential and graph hierarchy, we keep the word encoder and replace the HiPool graph encoder with the following sequential modules: Simple linear summation over low-level nodes; CNN applies a 1-dimension convolution; Trans is to apply a Transformer on top of low-level nodes. Besides, we also look at multiple graph settings: Aggr-mean is to use a mean aggregator to obtain the final document representation; Aggr-std is to use a feature-wise standard deviation aggregator; finally, Aggr-pcp applies Principal Neighbourhood Aggregation (PNA) (Corso et al., 2020). We report results on Amazon-2048 in Tab. 3, as it has the longest sequence on average. An observation is that applying aggregators are better than simpler structures, while keeping a graph is still a better choice. HiPool also considers attention in message passing, so it is doing even better. We also test other variations in Appendix B.

heading: 3.3 Ablation Study
text: Effect of input length. To better understand the effect of input length, in Fig. 2, we present an ablation study on the Amazon-2048 and ILDC, and compare three models: BigBird, Longformer, and HiPool. In general, the models benefit from longer input sequences in both datasets. Interestingly, when sequence is larger than 2048, Longformer and Bigbird could not improve and they are limited in maximum lengths. In contrast, as the input sequence gets longer, HiPool steadily improves,
showing its ability to encode long documents in a hierarchical structure. Model component. Next, we look at how each component of HiPool affects performance. As shown in Tab. 4, we first take the best model setting, HiPool-RoBERTa, and compare it with the following settings: 1) w/o RoBERTa is to replace RoBERTa with BERT, then the model becomes HiPool-BERT; 2) w/o HiPool is to remove the proposed HiPool module and replace with a simple CNN (Kim, 2014); 3) w/o Overlapping is to remove the overlapping word encoding. We could
see that removing the HiPool Layer leads to a significant drop, indicating the importance of the proposed method. Moreover, the HiPool framework can work with many pretrained language models, as we can see that applying RoBERTa improves BERT. A complete result table can be found in Appendix.

heading: 4 Conclusion
text: In this paper, we proposed a hierarchical framework for long document classification. The evaluation shows our model surpasses competitive baselines.

heading: 5 Limitations and Potential Risks
text: Limitations The model we proposed is specifically for classification, while it is possible to be extended to other NLP tasks by changing the highlevel task-specific layer. Besides, in the evaluation, we focused on English corpora. We plan to test on other languages in the future.
Potential Risks We make our code publicly available so that everyone can access our code. As the model is a classification model, it does not generate risky content. Users should also notice that the classification predictions may not be perfectly correct.

heading: 6 Acknowledgements
text: This paper is dedicated to the memory of Professor Dragomir Radev, who passed away while this paper was being peer-reviewed.

heading: B Graph Variations
text: We study other possible GNN types for hierarchy modeling. In Eq. 1, we replace the HiPool graph encoder with a GCN or GAT encoder. We apply two layers of the graph networks before the linear layer to compare fairly, and show results in Fig. 6. We notice that using GCN and GAT results in lower performance than that of HiPool. A possible reason is that they only focus on modeling the low-level nodes, ignoring a cross-sentence attention mechanism to strengthen high-level communication on long sequences like HiPool.

heading: C Hyperparameters, Experimental Settings
text: We run our experiments on 4 NVIDIA RTX A6000 GPUs, with the memory to be 48GB. We list hyperparameters for baselines and HiPool model in Tab. 7. For all datasets, we apply Adam optimizer (Kingma and Ba, 2014) for all experiments. For HiPool, we set the chunk length L = 300, and the overlapping length Lolp is L/2 = 150. We apply two layers of HiPool, reducing the number of nodes for each layer by p = 2. Among the baseline models, ToBERT (Pappagari et al., 2019) is adjustable for the maximum length, because it takes the maximum value in a batch during training. We evaluated F1 scores using scikit-learn: https://scikit-learn.org/stable/.

heading: D Frequently Asked Questions
text: • Q: Why do we call it a heterogeneous graph?
A: We use the term “heterogeneous”to distinguish the nodes from the graph. We wish to emphasize that the nodes are not the same, and they come from multiple levels and represent different information.
• Q: Are there other possible variations for modeling the hierarchy?
A: Yes, our HiPool model is a framework that applies a graph structure for high-level hierarchy, so it is possible to apply other GNN models. One can use Relational Graph Convolutional Networks (R-GCNs) (Schlichtkrull et al., 2018) to model the different relations for Aself and Across. Besides, some inductive methods like GraphSAGE (Hamilton et al., 2017) can also be applied to obtain node embeddings in the graph. We leave this topic as future work.
• Q: How does the aggregator work in Tab. 3.?
A: We replace the sum aggregator of our original HiPool with those mentioned aggregators. The applied PyTorch implementation: https://pytorch-geometric.readthedocs.io/en/ latest/modules/nn.html#aggregation-operators.
• Q: Why did not evaluate on the LRA (Long Range Arena) (Tay et al., 2021) benchmark?
A: LRA is more suitable for testing the efficiency of Transformer-based models and it consists of multiple types of long sequences. As we mentioned in the Introduction, our proposed model belongs to another category for long sequence encoding, not the efficiency transformer category that focuses on optimizing KQV attention.
ACL 2023 Responsible NLP Checklist

heading: A For every submission:

heading: 3 A1. Did you describe the limitations of your work?

heading: Appendix Section E

heading: 3 A2. Did you discuss any potential risks of your work?

heading: Appendix Section E

heading: 3 A3. Do the abstract and introduction summarize the paper’s main claims?
text: Section I
7 A4. Have you used AI writing assistants when working on this paper? Left blank.
B 3 Did you use or create scientific artifacts? Section 3

heading: 3 B1. Did you cite the creators of artifacts you used?
text: Section 3

heading: 3 B2. Did you discuss the license or terms for use and / or distribution of any artifacts?
text: Section 3

heading: 3 B3. Did you discuss if your use of existing artifact(s) was consistent with their intended use, provided
text: that it was specified? For the artifacts you create, do you specify intended use and whether that is compatible with the original access conditions (in particular, derivatives of data accessed for research purposes should not be used outside of research contexts)? Section 3

heading: 3 B4. Did you discuss the steps taken to check whether the data that was collected / used contains any
text: information that names or uniquely identifies individual people or offensive content, and the steps taken to protect / anonymize it? Section 3

heading: 3 B5. Did you provide documentation of the artifacts, e.g., coverage of domains, languages, and
text: linguistic phenomena, demographic groups represented, etc.? Section 3
3 B6. Did you report relevant statistics like the number of examples, details of train / test / dev splits, etc. for the data that you used / created? Even for commonly-used benchmark datasets, include the number of examples in train / validation / test splits, as these provide necessary context for a reader to understand experimental results. For example, small differences in accuracy on large test sets may be significant, while on small test sets they may not be. Section 3, Appendix A
C 3 Did you run computational experiments? Section 3

heading: 3 C1. Did you report the number of parameters in the models used, the total computational budget
text: (e.g., GPU hours), and computing infrastructure used? Appendix C, Section 3
The Responsible NLP Checklist used at ACL 2023 is adopted from NAACL 2022, with the addition of a question on AI writing assistance.

heading: 3 C2. Did you discuss the experimental setup, including hyperparameter search and best-found
text: hyperparameter values? Appendix C, Section 3

heading: 3 C3. Did you report descriptive statistics about your results (e.g., error bars around results, summary
text: statistics from sets of experiments), and is it transparent whether you are reporting the max, mean, etc. or just a single run? Appendix B, C, Section 3

heading: 3 C4. If you used existing packages (e.g., for preprocessing, for normalization, or for evaluation), did
text: you report the implementation, model, and parameter settings used (e.g., NLTK, Spacy, ROUGE, etc.)? Appendix C,D, Section 3
D 7 Did you use human annotators (e.g., crowdworkers) or research with human participants? Left blank.

heading: D1. Did you report the full text of instructions given to participants, including e.g., screenshots,
text: disclaimers of any risks to participants or annotators, etc.? No response.

heading: D2. Did you report information about how you recruited (e.g., crowdsourcing platform, students)
text: and paid participants, and discuss if such payment is adequate given the participants’ demographic (e.g., country of residence)? No response.

heading: D3. Did you discuss whether and how consent was obtained from people whose data you’re using/curating? For example, if you collected data via crowdsourcing, did your instructions to
text: crowdworkers explain how the data would be used? No response.

heading: D4. Was the data collection protocol approved (or determined exempt) by an ethics review board?

heading: No response.

heading: D5. Did you report the basic demographic and geographic characteristics of the annotator population that is the source of the data?
text: No response.

heading: Future Work
text: We leave this topic as future work. • Q: How does the aggregator work in Tab. 3. ?
A: We replace the sum aggregator of our original HiPool with those mentioned aggregators. The applied PyTorch implementation: https://pytorch-geometric. readthedocs. io/en/ latest/modules/nn. html#aggregation-operators. • Q: Why did not evaluate on the LRA (Long Range Arena) (Tay et al. , 2021) benchmark?
A: LRA is more suitable for testing the efficiency of Transformer-based models and it consists of multiple types of long sequences. As we mentioned in the Introduction, our proposed model belongs to another category for long sequence encoding, not the efficiency transformer category that focuses on optimizing KQV attention. ACL 2023 Responsible NLP Checklist