Computer Science
Computer Science-2021.gz:143358
Computer Science
959798da7d1bccab9fa3884b7a02c55c6880ebaf
Hierarchy-Aware T5 with Path-Adaptive Mask Mechanism for Hierarchical Text Classification

Hierarchical Text Classification (HTC), which aims to predict text labels organized in hierarchical space, is a significant task lacking in investigation in natural language processing. Existing methods usually encode the entire hierarchical structure and fail to construct a robust label-dependent model, making it hard to make accurate predictions on sparse lower-level labels and achieving low Macro-F1. In this paper, we propose a novel PAMM-HiA-T5 model for HTC: a hierarchy-aware T5 model with path-adaptive mask mechanism that not only builds the knowledge of upper-level labels into low-level ones but also introduces path dependency information in label prediction. Specifically, we generate a multi-level sequential label structure to exploit hierarchical dependency across different levels with Breadth-First Search (BFS) and T5 model. To further improve label dependency prediction within each path, we then propose an original path-adaptive mask mechanism (PAMM) to identify the label's path information, eliminating sources of noises from other paths. Comprehensive experiments on three benchmark datasets show that our novel PAMM-HiA-T5 model greatly outperforms all state-of-the-art HTC approaches especially in Macro-F1. The ablation studies show that the improvements mainly come from our innovative approach instead of T5.


Introduction
Hierarchical text classification (HTC), where text labels are predicted within a hierarchical structure, is a challenging task that has not yet received due attention within the field of multi-label classification. HTC methods have been extensively applied in industry domains, e.g., news article classification (Sandhaus 2008), product classification in Ecommerce (Yu et al. 2018), bidding strategy in paid search marketing (Agrawal et al. 2013).
In HTC tasks, labels at lower-level are inevitably sparse due to the hierarchical structure. Many studies (Hayete and Bienkowska 2005;Barbedo and Lopes 2006;Xiao et al. 2007;Johnson and Zhang 2015) completely or partially neglect such hierarchical structure and fail to accurately predict those lower-level labels, achieving low Macro-F1 score. Existing studies (Peng et al. 2021;Wu, Xiong, and Wang 2019) have proved that introducing structure information : the dynamic labeling process focuses on ancestor labels already generated on the current path. "Music" label is determined by "Arts" and "Features", while "Football" label is ruled by "Sports", "News".
can boost the predictive power on low-level labels and thus improve the overall task performance. A number of studies (Cesa-Bianchi, Gentile, and Zaniboni 2006;Shimura, Li, and Fukumoto 2018;Wehrmann, Cerri, and Barros 2018;Banerjee et al. 2019) propose to construct multi-level classifiers that are trained independently and predicted sequentially, where only local maximum is achieved and propagation of error negatively impacts model prediction. Some studies design an end-to-end model that introduces various strategies (such as Tree-LSTM/GCN , graph-CNN (Peng et al. 2018) and hierarchical fine-tuning based CNN (Shimura, Li, and Fukumoto 2018)) to encode the overall hierarchy information (as depicted in Figure 1 (a)) and predict all labels simultaneously and independently with sigmoid function, where label dependency across different levels (as depicted in Figure 1 (b)) is not captured in a more principled way and unnecessary noises are introduced. Although one recent study (Mao et al. 2019) develops labeldependent models with reinforcement learning, it still fails to address label dependency within each path (as depicted in Figure 1 (c)) and fails to fully integrate labels and text information. This paper seeks to close the gap by proposing the PAMM-HiA-T5. We are not only the first to capture lowerlevel label dependency on upper-level ones with generation model, but also the first to identify hierarchical dependency within the specific path. In each step of prediction phase, our model predicts next label based on the text sequence and labels previously generated on current path. As illustrated in Figure 1(c), our model sequentially predicts "Features", "News", "Arts", "Sports", "Music", "Football" labels. In the process where label "Music" is generated, our model pays more attention on "Features" and "Arts" labels on its own path instead of "News" and "Sports" labels on another path.
Our PAMM-HiA-T5 method follows a two-step design. Hierarchy-aware T5 (HiA-T5), a variant of T5 that is fully aware of the level dependency. We firstly use Breadth-First Search (BFS) to flatten hierarchical labels into multilevel sequential label structure, transforming the hierarchy to sequence. T5 model is applied to map the text sequence to label sequence, where the text sequence and upper-level labels generated earlier are then integrated in order to determine the next label. As such, we are able to fully exploit label dependency across different levels.
Path-adaptive mask mechanism (PAMM), a mechanism to exploit the label correlation within each path and eliminate the noise of other paths. We propose the pathadaptive mask mechanism to separate the sources of noises from different paths. Regularization is introduced in the training phase to encourage the model to pay more attention to ancestor labels on current path while penalizing those on other paths, according to both the text sequence and labels generated.
This study makes the following major contributions: • We propose a novel HiA-T5 model, a multi-level sequential label generative model to exploit label dependency across different levels. The mapping relationship between text sequence and label sequence is examined in each step of prediction. • We propose an original PAMM to identify the label's path information, separating the sources of noises from different paths to further improve prediction accuracy. • Experiments on various datasets show that our PAMM-HiA-T5 model achieves significantly and consistently better performance than state-of-the-art models. Boosting Micro-F1 score by 2.29% and achieving substantial 4.68% improvement in Macro-F1 score, we establish new state-of-art results on RCV1-V2. The ablation studies show that the improvements mainly come from our innovative approach instead of T5.

Related Work
Hierarchical text classification (HTC) is a critical task with numerous applications (Qu et al. 2012;Agrawal et al. 2013;Zhang et al. 2019;Peng et al. 2016). By methods of hierarchical information modeling, HTC approaches can be categorized into flat, local and global approaches (Silla and Freitas 2011). Flat approaches (Hayete and Bienkowska 2005;Barbedo and Lopes 2006;Xiao et al. 2007;Johnson and Zhang 2015) completely or partially ignore the label hierarchy and each label is independently predicted. Some of them simply ignore the invaluable hierarchical information and achieve poor performance. Some others predict leaf nodes first and then mechanically add their ancestor labels, which is only applicable where different paths in the label hierarchy share the same length.
Local approaches (Koller and Sahami 1997;Cesa-Bianchi, Gentile, and Zaniboni 2006;Shimura, Li, and Fukumoto 2018;Wehrmann, Cerri, and Barros 2018;Banerjee et al. 2019) construct multiple local classifiers so that the misclassification at a certain level is propagated downwards the hierarchy, easily leading to the exposure of bias (Silla and Freitas 2011). Specifically, Liu et al. (2005) proposes a top-down variant of SVM for HTC. Peng et al. (2018) uses deep graph convolutional neural networks with hierarchical regularization. Wehrmann, Cerri, and Barros (2018) utilizes a multi-label neural network architecture with local and global optimization. To address the lower-level labels sparsity problem, Shimura, Li, and Fukumoto (2018) takes advantage of a CNN-based model with the fine-tuning method. Banerjee et al. (2019) proposes to transfer the parameters of parent classifiers to initialize child classifiers for HTC task.
Global approaches (Gopal and Yang 2013;Mao et al. 2019;Wu, Xiong, and Wang 2019;Zhou et al. 2020;Peng et al. 2021), where the entire structural information is encoded and all labels are simultaneously predicted, has become recent mainstream due to its better performance. Gopal and Yang (2013) utilizes regularization to modify the SVM. Neural network architectures are also applied in global approaches. Mao et al. (2019) handles HTC task with reinforcement-learning-based label assignment method. Wu, Xiong, and Wang (2019) uses meta-learning to model the label interaction for multi-label classification. Zhou et al. (2020) utilizes the Bi-TreeLSTM and GCN to model hierarchical relationship and makes flat predictions for hierarchical labels. Peng et al. (2021) combines CNN, RNN, GCN, and CapsNet to model hierarchical labels. Although recent researchers have managed to introduce hierarchical information in different fashions, most of them still regard flat multilabel classification as the backbone of HTC where all labels are predicted simultaneously and independently. Their exploitation of hierarchical structure is far from insufficient.

Problem Definition
For HTC, we define the overall label hierarchy as a treelike structure, denoted by T = (L, E), where L = {l 1 , l 2 , . . . , l K } refers to the set of all label nodes in the corpus and K is the total number of them. E refers to the set of edges indicating the nodes' parent-child relations. Formally, we denote text objects as X = {X 1 , X 2 , . . . , X N } and their labels as Each text object is represented by a text sequence X i = [x 1 , x 2 , . . . , x J ], where x j is a word and J is the number of words in the text object. Meanwhile, each text object X i is mapped to a original label set L i = {l 1 , l 2 , . . . , l k , 1 ≤ k < K} that contains multiple labels. We then define a set of special symbols S = { , /, EOS} to identify special hierarchical relationships in the hierarchy.
All labels L in the corpus constitute the overall label hierarchy T . The original label set L i = {l 1 , l 2 , . . . , l k , 0 ≤ k < K} of any text object X i constitute an partial label hierarchy T i and T i ⊂ T . We aim to train a model to predict corresponding label set L i for each text object X i , where the label set L i are constrained by the hierarchy T i .

Background
The T5 model consists of an encoder-decoder architecture, which mainly includes the Multi-head Attention Mechanism, the Feed-Forward Network and so on (Raffel et al. 2020), as depicted in the Figure 2. Attention is calculated as: where Q, K, V ∈ R n×d model and the length of sequence is n. The attention score matrix Score ∈ R n×n is applied to the matrix V to calculate the weighted sum and obtain the final attention result. The results upon independently executing attention mechanism on H heads are concatenated to get Multi-head Attention.
where the projections matrices The Feed-Forward Network consists of two linear transformations with a nonlinear activation function in between.
T5 encoder is composed of a stack of "encoder blocks" and we define the number of blocks as B. Each block contains a self-attention sublayer and a feed-forward sublayer. The input sequence of encoder is mapped to the embedding Q encoder , K encoder , V encoder ∈ R n×d model , which are then passed into the encoder.
Encoder(Q encoder , K encoder , V encoder ) =stack(Block Encoder (Q encoder , K encoder , V encoder )) The structure of the decoder looks similar to that of the encoder, except that it has an additional encoder-decoder attention sublayer that attends to the output of the encoder stack, following each casual self-attention sublayer. In the end, we obtain the decoder output denoted as O decoder .
Hierarchy-Aware T5 with Path-Adaptive Mask Mechanism As depicted in Figure 3, we propose a PAMM-HiA-T5 model for HTC: a Hierarchy-Aware T5 model with Path-Adaptive Mask Mechanism. PAMM-HiA-T5 consisits of the HiA-T5 for level-dependent label generation and the PAMM for path-specific label generation.

Hierarchy-Aware T5
Level-dependent HiA-T5 The major shortcoming of previous HTC methods is the inadequate application of hierarchy information. In contrast, HiA-T5 exploits label dependency across different levels of the hierarchy with Breadth-First Search (BFS) and multi-head attention mechanism. HiA-T5 firstly explore the label hierarchy T i with Breadth-First Search (Cormen et al. 2001) to flatten the label set L i = {l 1 , l 2 , l 3 , l 4 , l 5 } into multi-level sequential label M L i = [l 1 , , l 3 , /, l 2 , , l 4 , /, l 5 , EOS], transforming the hierarchy to multi-level label sequence, as illustrated in Figure 4 (a). In this process, ' ' between labels denotes intralevel relationship, while '/' signifies inter-level relationship.
On one hand, the text sequence X i = [x 1 , x 2 , . . . , x J ] is mapped to embedding sequence Q text , K text , V text ∈ R n×d model , which are then passed into T5 encoder: The output encoder representation for semantic features of varied granularities is O text . On the other hand, the multi-level label sequence M L i = [l 1 , , l 3 , /, l 2 , , l 4 , /, l 5 , EOS] is mapped to embeddings sequence Q label , K label , V label ∈ R n×d model , which are passed into T5 decoder together: Specifically, HiA-T5 fully explores the label dependency across different levels through the self-attention mechanism. With the help of the intra-level separator ' ' and the inter-level separator '/', the causal decoder self-attention mechanism fully excavates the intra-level parallel and mutually exclusive relationship, as well as the inter-level dependent and appurtenant relationship. The output representation of the decoder causal self-attention mechanism incorporating level dependency information is A label = M ultiHead(Q label , K label , V label ).
So far, we have obtained the text representation O text highlighting the semantic features of texts with different granularities and the label representation A label incorporating label dependency across different levels. The output representation of the encoder-decoder attention mechanism integrating these two is A cross = M ultiHead(A label , O text , O text ), which is a sufficient crossover information for following prediction.
Loss of HiA-T5 We have obtained the final decoder block output of HiA-T5 O hierarchy , which fully integrates the label hierarchy information and the text semantic information of different granularities. Then O hierarchy is passed into a fully connected layer with a softmax output, which is also the final result of HiA-T5 denoted as P red. P red is the result of n timesteps and P red ∈ R n×K .
where W 3 ∈ R d model ×K , b 3 ∈ R K . In addition, any multilevel label sequence M L i is transformed into T ruth ∈ R n×K , which is composed of one-hot vectors corresponding to all labels. Therefore, the cross-entropy loss of HIA-T5 expressed is as follows: Loss HiA−T 5 = crossentropy(T ruth, P red)

Path-Adaptive Mask Mechanism
PAMM is the regularization designed in the training phase to encourage the model to pay more attention to ancestor labels on current path while penalizing those on other paths. We first obtain the path-adaptive mask matrix containing hierarchy information. Then path-adaptive mask loss is obtained according to operations on the path-adaptive mask matrix and the causal attention score matrix.

Path-Adaptive Mask Matrix
Now the text sequence X i = [x 1 , x 2 , . . . , x J ] is taken as input, which is fed into HiA-T5 for training, and its corresponding multi-level label sequence M L i is taken as output.
According to the T5 structure of Figure 2, the sequence M L i is first passed into causal attention sub-layer of decoder. Within this sub-layer, and according to formula (2), we get causal attention score matrix Score corresponding to the sequence M L i , as depicted in Figure 5 (a).
Then we define the path-adaptive dynamic mask matrix M , which can mask different parts of the label sequence at different decoding timestep i. The matrix M is obtained from the hierarchical structure of the label sequence corresponding to each text object. Specifically, the shape of the matrix M is same as the causal attention score matrix Score. Mask matrix M is also a lower triangular matrix and M = {m i,j } ∈ R n×n , which is only composed of 0 or 1 as shown below. m n,1 m n,2 · · · m n,n−1 m n,n     I i represents the input of the attention mechanism at the timestep i, and I i ∈ L∪S. If I i ∈ L, we define ancestor(I i ) as label I i 's ancestor labels and the special symbol immediately following it. Then we define the following formula to fill the matrix M based on the parent-child relationship contained in each path of label hierarchy. The i-th input timestep of the causal attention mechanism corresponds to the i-th row of matrix M , which contains i elements: m i,1 , m i,2 , . . . , m i,i . In the i-th row of matrix M , inputs I 1 , I 2 , . . . , I i of different timesteps corresponds to elements m i,1 , m i,2 , . . . , m i,i respectively.
Note that, in the i-th (1 ≤ i ≤ n) row of the matrix M , we first determine the value of the diagonal element m i,i , then determine the other elements m i,j (1 ≤ j < i) before m i,i , and the formula is as follows: Path-Adaptive Mask Loss With text sequence and labels previously generated in hand, we now introduce regularization and apply the path-adaptive dynamic mask matrix M , such that HiA-T5 decoder learns the weight of the attention matrix and pays more attention on the label's current path. Having obtained the multi-level label sequence M L i of a certain training sample, we use it as the input of causal selfattention of HiA-T5's decoder. According to the definition above, we get its path-adaptive mask matrix M , as depicted in Figure 4 (b). Furthermore, we get a new attention score matrix Score new as depicted in Figure 5 (b) by multiplying attention score matrix Score and the mask matrix M element-wise: We define C as the index set of ancestor(I i ). At any decoding timestep i, our goal is to make the sum of the attention scores j∈C s i,j of current path's labels as close to 1 as possible. Corresponding to attention scores matrix Score new of decoder's causal attention, that is, to make the sum of elements of each row in the matrix close to 1 as much as possible. According to the definition section, suppose Score is the causal attention score matrix corresponding to the h-th head of b-th decoder "blocks", where 1 ≤ h ≤ H, 1 ≤ b ≤ B. The path-adaptive mask loss is defined as: (16) Therefore, the loss generated by the path adaptive mask mechanism is added to the loss of HiA-T5 as total loss for training. The total loss function Loss is obtained as below, where ρ is the coefficient of path-adaptive mask loss item.

Experiments Experiment Setup
Datasets We conduct extensive experiments on three public datasets, including RCV1-V2 (Lewis et al. 2004), NY-Times(NYT) (Sandhaus 2008) and Web-of-Science(WOS) (Kowsari et al. 2017). RCV1-V2 and NYT are both news categorization dataset while WOS is about scientific literature categorization. Labels of these datasets are organized into a tree-like structure. Relevant information of datasets is summarized in Table 1 and Table 2.
We split RCV1-V2 in the benchmark dataset split manner and take a small portion of the training set as validation set. For NYT and WOS, we randomly split data into training, validation and test sets.   Table 2: Statistics of the average number of each label's occurrence at each level: level i denotes the level in the label hierarchy. In general, lower-level labels are more sparse.

Evaluation Metrics
We use standard evaluation metrics, including Micro-F1 and Macro-F1 (Gopal and Yang 2013;Peng et al. 2018;Huang et al. 2019), to measure the performance of all HTC methods. Micro-F1 equally weights all samples, while Macro-F1 gives equal weight to each label. As such, Micro-F1 gives more weight to frequent labels, while Macro-F1 equally weights all labels and is more sensitive to lower-level labels which are hard to predict. As shown in Table 2, the labels of most samples are screwed towards upper levels, in which case Macro-F1 is more sensitive to scattered lower-level labels.

Experimental Settings
The backbone pre-trained model we adopt is T5-base (Raffel et al. 2020). T5-base contains a total of about 220M parameters, including 12 layers of transformer, and each layer has 768 hidden dimensions, 3072 intermediate sizes and 12 attention heads. T5 is fine-tuned on relevant datasets before we perform following experiments. For the reproducibility of results, we set random seeds before experiments. Tokenizer from T5 is utilized to preprocess the text. For T5, the maximum length of token inputs of encoder is set as 300, and the maximum length of token outputs of decoder is set as 60. When the T5 model is fine-tuned, Adam optimizer is employed in a mini-batch size of 10 with learning rate 3 × 10 −4 , and model converges after 3 epochs. The search range of coefficient ρ is {0.1,1,10,100,200}, and we set it to 100 according results of validation set. The model with the best performance on the validation set is selected for evaluating the test set. In the inference phase, greedy search is adopted. The experiments are conducted on GeForce RTX 2080 Ti GPU and CentOS with Pytorch Lightning framework.

Performance Comparison
Experimental results on RCV1-V2 benchmark dataset are shown in Table 3, and our proposed PAMM-HIA-T5 outperforms all state-of-the-art results of flat, local and global approaches by a large margin, both in Micro-F1 and Macro-F1. This demonstrates the strong power of PAMM-HiA-T5 in solving HTC problems. PAMM-HIA-T5 achieve the performance of 86.25% Micro-F1 score and 68.03% Macro-F1 score, which outperforms state-of-the-art model by 4.68% of Macro-F1 and 2.29% of Micro-F1 on RCV1-V2. The greater improvement on Macro-F1 shows that PAMM-HiA-T5 has greater capability in predicting sparse lower-level labels, which results from the fact that our model utilizes the knowledge of upper-level labels in predicting lowerlevel ones by modeling hierarchical dependency. It can be shown from Table 2 that the samples' labels are unevenly distributed across levels. The labels of most samples are screwed towards upper levels. As level grows, sample labels become more sparse. This explains the reason why our model achieves greater boost in Macro-F1 than Micro-F1. Experiment results on WOS and NYT datasets are shown in Table 4, and we obtain consistent conclusion as from RCV1-V2: the level-dependency modeling and the pathadaptive mask mechanism bring significant performance improvement. On NYT dataset, we obtain the best performance of 77.89% Micro-F1 and 65.13% Macro-F1, improving Micro-F1 by 2.92% and Macro-F1 by 4.30% compared with the result reported in latest state-of-the-art HTC approach ). On WOS dataset, we still outperform the result reported in latest state-of-the-art HTC approach , although the improvement is minor due to its simple hierarchical structure and fewer lower-level labels. Local TD-SVM** (Liu et al. 2005) 80.10 50.70 HR-DGCNN-3 (Peng et al. 2018) 76.18 43.34 HMCN (Wehrmann, Cerri, and Barros 2018) 80.80 54.60 HFT(M) (Shimura, Li, and Fukumoto 2018) 80.29 51.40 Htrans (Banerjee et al. 2019) 80.51 58.49 Global HR-SVM* 1 (Gopal and Yang 2013) 72.75 38.58 SGM 2  77.30 47.49 HE-AGCRCNN (Peng et al. 2021) 77.80 51.30 HiLAP-RL (Mao et al. 2019) 83.30 60.10 HiAGM  83.96 63.35 PAMM-HiA-T5 86.25 68.03 Table 3: Performance comparison on RCV1-V2. * denotes the results reported in (Peng et al. 2018) and * * denotes the results reported in (Mao et al. 2019) on the similar dataset split. In this table, SVM (Noble 2006) implements standard multi-label classification in a way of one-vs-the-rest(OVR). Leaf-SVM predicts leaf nodes first and then mechanically add their ancestor labels. TextCNN (Kim 2014), HAN (Yang et al. 2016) and bow-CNN (Johnson and Zhang 2015) are modified as flat baselines for HTC by (Mao et al. 2019). This is the case for   than that in Micro-F1. This result illustrates the effectiveness of capturing level dependency by introducing upper-level label knowledge to assist lower-level label prediction.
Our ablation studies show that the improvements are mainly due to the strategy and the mechanism we proposed rather than the T5 itself. Experiments on RCV1-V2 show that PAMM-HiA-T5 outperforms the sota model by 4.68% in Macro-F1 and 2.29% in Micro-F1. But T5 only contributes 0.97% of the growth in Micro-F1, and it doesn't even exceed the sota model in Macro-F1.
In addition, Figure 6 demonstrates that the gap between HiA-T5 and T5 gets bigger as the level deepens. This illustrates that as the level grows, label prediction becomes more and more difficult, and the introduction of upper-level label knowledge by HiA-T5 becomes more and more valuable. Ablation Study on Path-adaptive Mask Mechanism We compare the performance of PAMM-HiA-T5 with the HiA-T5, and the ablation results are shown in the last two rows of Table 5. PAMM-HiA-T5 improves Macro-F1 by 2.87% and Micro-F1 by 0.26% compared with HiA-T5. This indicates that PAMM significantly improves the performance of HiA-T5 in more challenging multi-path scenarios by capturing precise path dependencies. With the assistance of PAMM, PAMM-HiA-T5 further improves the overall performance of HTC task especially in Macro-F1 by exploiting label dependency within each path and eliminating the noise from other paths. As shown in Figure 7, the heat map of the causal selfattention score in PAMM-HiA-T5's encoder proves the effectiveness of PAMM, where the attention score is mainly distributed on the path of the label current being decoded.  Figure 7: Causal self-attention score's heat map corresponding to a random sample. We use symbols instead of original labels for ease of display. Note that the score of each label is the average of its tokens' attention score for a cleaner view.

Analysis of Label Consistency
Label inconsistency, where one label is predicted positive but its ancestors are not, is a serious problem in many HTC approaches, due to the fact that they focus on flat multi-label classification and make independent predictions for all labels. It is worth mentioning that PAMM-HIA-T5 has outstanding classification performance while maintaining an ultra-low label inconsistency rate of 0.31%, as shown in Table 6. This is because PAMM-HiA-T5 fully leverages the constraints of upper-level labels generated earlier to predict the most accurate lower-level labels.

Conclusion
This paper aims to improve HTC task performance by exhaustively exploring level and path dependency within the hierarchical structure. We have devised an innovative PAMM-HiA-T5 methodology in order to capture lowerlevel label dependency on upper-level ones with generation model and to identify hierarchical dependency within the specific path. In the first place, we generate a multilevel sequential label structure to exploit level-dependency with Breadth-First Search (BFS) and T5 model. To further capture label dependency within each path, we then propose an original path-adaptive mask mechanism (PAMM) to identify the label's path information, eliminating sources of noises from other paths. Comprehensive experiments on three benchmark datasets show that our novel PAMM-HiA-T5 model establishes new state-of-the-art results, achieving significant Macro-F1 improvement by 4.68% and Micro-F1 improvement by 2.29%. The ablation studies show that the improvements mainly come from our original approach instead of T5.