# Hierarchical Attention Networks for Document Classification

Hierarchical attention networks weight words and sentences to classify documents

Zichao Yang, Diyi Yang, Chris Dyer, Xiaodong He, Alex Smola, Eduard Hovy · Proceedings of the 2016 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies

- **Problem** Neural models that ignore document structure gain little over traditional methods on large datasets. They read the whole document as one flat sequence.
- **Method** Hierarchical Attention Network (HAN) encodes words into sentence vectors, then sentences into a document vector. A learned attention layer at each stage weights the important parts.
- **Results** HN-ATT scored 68.2 on Yelp 2013, compared to 65.1 for LSTM-GRNN, a flat baseline.

## Why flat document models fall short

Document classification long relied on sparse n-gram features fed into linear models or kernel methods. Later neural models such as CNNs and LSTMs learned text representations directly, without that hand-built sparse design. The LSTM baseline reads a whole document as one single sequence, and averages the hidden states of all words for classification.

On the large-scale sets used here, that flat design brings little edge over traditional methods. SVM+TextFeatures scored 59.8 on Yelp 2013, while CNN-word scored 59.7 on the same set. The authors trace this gap to missing structure, because a long review has parts that differ in how much they say about the label.

Figure 1's review shows the point: its first and third sentences carry most of the rating signal. Inside those sentences, a few words such as delicious drive the judgement, while most other words add little. The same word can change meaning with context, so a fixed list of important words won't capture the signal. The good example shows this: it can appear in a low-rated review because of a negation, such as not good.

That raises the question of whether the document's own hierarchy can tell the model where to look.

## Two levels of attention over words and sentences

The key idea is to encode a review in two stages that follow its structure: words into sentence vectors, then sentence vectors into one document vector. The Hierarchical Attention Network (HAN) adds a learned attention layer at each stage, so it can weight some words and sentences more than others. Both stages rest on GRU encoders, so the gated recurrent unit comes first.

A GRU tracks its state with a reset gate and an update gate, and it has no separate memory cell. The update gate decides how much past state is kept, using \\( z\_t = \\sigma(W\_z x\_t + U\_z h\_{t-1} + b\_z) \\). The reset gate \\( r\_t \\) controls how much of the past enters the candidate state, so a zero reset gate makes the candidate forget the previous state.

Each word is first mapped to a vector by the embedding matrix \\( W\_e \\), which is initialized from word2vec trained on the training and validation splits. A bidirectional GRU then reads each sentence forward and backward, and the two hidden states are concatenated into an annotation \\( h\_{it} \\). Because the annotation sees both directions, each word carries information about its surrounding sentence.

The authors use word embeddings directly, and they note that a GRU over characters could replace them in a more complete model.

Not every word matters equally to a sentence's meaning, so a word-level attention mechanism pools the annotations with learned weights. For each annotation, the model computes \\( u\_{it} = \\tanh(W\_w h\_{it} + b\_w) \\) and scores it as \\( u\_{it}^\\top u\_w \\). A softmax turns these scores into weights \\( \\alpha\_{it} \\), and the sentence vector is the weighted sum \\( s\_i = \\sum\_t \\alpha\_{it} h\_{it} \\).

The word context vector \\( u\_w \\) acts as one fixed query for the informative word across the corpus, and it is learned during training after random initialization.

The sentence vectors go through a second bidirectional GRU, which gives each sentence an annotation \\( h\_i \\) that depends on its neighboring sentences. A sentence-level attention layer scores each \\( h\_i \\) with \\( u\_i = \\tanh(W\_s h\_i + b\_s) \\), normalizes the scores with softmax into \\( \\alpha\_i \\), and takes \\( v = \\sum\_i \\alpha\_i h\_i \\).

The sentence-level context vector \\( u\_s \\) is initialized randomly and learned in the same way as \\( u\_w \\).

A softmax classifier maps the document vector to class probabilities, \\( p = \\mathrm{softmax}(W\_c v + b\_c) \\). Training minimizes the negative log likelihood of the correct labels, \\\[ \\mathcal{L} = -\\sum\_d \\log p\_{d,j} \\\] where \\( j \\) is the label of document \\( d \\). The GRU dimension is 50, so a bidirectional GRU gives 100-dimensional annotations, and the context vectors are also 100-dimensional.

Training uses stochastic gradient descent with momentum 0.9, and the learning rate is picked by grid search on the validation set, with mini-batches of 64 documents of similar length.

## Comparison against baselines on six datasets

The authors evaluate HAN on six large scale document classification datasets, splitting each into 80% training, 10% validation and 10% test. Yelp 2013 holds 335,018 documents, and the Yahoo answers task provides 140,000 training samples and 5000 testing samples. The Yahoo answers task has 10 classes, and the authors randomly take 10% of its training samples for validation.

They don't rerun the baselines, since those numbers come from earlier papers by Zhang et al. (2015) and Tang et al. (2015).

The main comparison pits HN-ATT against the hierarchical baseline LSTM-GRNN and the other systems listed in Table 2. HN-ATT beats LSTM-GRNN by 3.1% on Yelp 2013, and the authors say the gain holds regardless of data size. On IMDB, HN-ATT scores 49.4, a 4.1% gain over the previous best baseline. The authors report gains of 3.2%, 3.4%, 4.6% and 6.0% on Yelp 2014, Yelp 2015, Yahoo answers and Amazon reviews.

On Amazon reviews, HN-ATT scores 63.6 against 59.6 for CNN-char, so the 6.0% gain can't be checked from the table alone. On Yahoo answers, a topic task, HN-ATT reaches 75.8, versus 71.2 for both CNN-char and CNN-word. Across Table 2, HN-ATT has the top score in every dataset column.

The authors also test HN-AVE, which averages the word and sentence annotations, and HN-MAX, which uses max-pooling. HN-AVE works like attention with non-informative context vectors, because all-zero context vectors make the attention weights uniform. HN-ATT beats both HN-AVE and HN-MAX on every dataset, which the authors read as evidence for the learned global context vectors.

Hierarchy alone already helps, since HN-AVE outperforms CNN-word by 7.3% on Yelp 2013.

## Does attention track context in document classification

The authors test whether the word weights of the attention layer change with context, which the model's design assumes. To check this, they plot the distribution of attention weights for good and bad on the test split of Yelp 2013, shown in Figure 3(a) and Figure 4(a). The aggregate distribution shows that each word's attention weight spans a range from 0 to 1.

The authors read this as the model capturing diverse contexts and assigning context-dependent weights to the words.

The authors then condition the distributions on the rating of each review, with Figures 3(b) to 3(f) and Figure 4 covering ratings 1 to 5. For good, the weight concentrates on the low end in reviews rated 1, and the distribution moves upward as the rating increases. The paper reads this as good playing a more important role in reviews with higher ratings.

The authors conclude that their model captures the context-dependent word importance.

This evidence is a set of plotted distributions for two words on one test split, with no numeric test attached. The claim rests on how the distributions shift across rating groups rather than on a comparison with a model without attention. Figure 5 gives a qualitative view of the same idea, where the model ignores a sentence like i don't even like scallops.

## What the attention highlights in documents

The authors check the selection by drawing the hierarchical attention on several Yelp 2013 and Yahoo Answers documents. Each line in the figure is one sentence, and a long sentence can wrap over several lines. Red encodes the sentence weight and blue encodes the word weight, so a reader sees both levels at once. Word weights get divided by their sentence weight, so only important words in important sentences stand out.

The display then takes the square root of the sentence weight times the word weight, which keeps important words in unimportant sentences visible.

In the Yelp 2013 review with label 4, which means star 5, strong words such as delicious and a-m-a-z-i-n-g stand out. Sentences about cocktails, pasta and entree get disregarded, even though they contain many words. The first document also contains i don't even like scallops, which reads as negative when taken alone. The authors say the model reads that sentence in context and treats the review as positive, so it ignores the sentence.

The paper also names terrible among the strong-sentiment words the model selects, in a label 0 review that means star 1.

On Yahoo Answers, the model highlights zebra, strips, camouflage and predator in a label 1 document. Label 1 denotes Science and Mathematics, so the highlighted words match the science question. For a label 4 document, which denotes Computers and Internet, the model focuses on web, searches and browsers. The authors stress that this setting is multiclass with 10 classes, and that detection happens before the topic is selected.

## Limits of the evidence behind the HAN results

The authors take their baseline numbers from earlier papers, so they don't rerun those baselines under their own setup. Table 2 gives one score per cell, so the paper doesn't show how much those scores vary across runs. The Yahoo Answers data set has no validation split, so the authors randomly took 10% of its training samples for validation.

The Amazon reviews follow the same 10% validation rule, so two of the six data sets rely on that split choice.

HAN takes word embeddings directly as input, and the authors didn't test a character-level GRU for word vectors. They left that character-level GRU out for simplicity, so the paper doesn't show its effect on the results. The attention weight study covers only the words good and bad on the Yelp 2013 test split. They didn't run the same weight distribution analysis on Yahoo Answers or on the other data sets.

The visualizations show several documents from Yelp 2013 and Yahoo Answers, not a systematic sample of either data set.

The main comparison pits HN-ATT against HN-AVE, so only one attention variant faces the averaging baseline. HN-ATT improves over LSTM-GRNN by 3.1%, 3.4%, 3.5% and 4.1% on four sets, so the margins vary by data set. Every reported comparison uses the 80%, 10% and 10% split for training, validation and test, unless stated otherwise.

## Paper info

- **Authors**: Zichao Yang, Diyi Yang, Chris Dyer, Xiaodong He, Alex Smola, Eduard Hovy
- **Venue**: Proceedings of the 2016 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies · Published
- **Added**: 2026-11-12
- **DOI**: 10.18653/v1/n16-1174
- **Original paper terms**: [Check in the original ↗](https://aclanthology.org/N16-1174/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://aclanthology.org/N16-1174/) · [PDF ↗](https://aclanthology.org/N16-1174.pdf)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Zichao Yang, Diyi Yang, Chris Dyer, Xiaodong He, Alex Smola, Eduard Hovy (2016). Hierarchical Attention Networks for Document Classification. Proceedings of the 2016 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies. https://doi.org/10.18653/v1/n16-1174

**BibTeX**

```
@article{yang2016hierarchical,
  title = {{Hierarchical Attention Networks for Document Classification}},
  author = {Zichao Yang and Diyi Yang and Chris Dyer and Xiaodong He and Alex Smola and Eduard Hovy},
  year = {2016},
  journal = {Proceedings of the 2016 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies},
  doi = {10.18653/v1/n16-1174},
  url = {https://aclanthology.org/N16-1174/}
}
```

## Other paper commentary

- [LightGCN: Simplifying and Powering Graph Convolution Network for Recommendation](https://refivu.com/en/papers/ce104c95-75b4-4033-900a-57eef9818488-lightgcn-simplifying-and-powering-graph-convolution-network.md)
- [Unsupervised Domain Adaptation by Backpropagation](https://refivu.com/en/papers/5b06ce85-04aa-40bd-a8ba-094e15a092f1-unsupervised-domain-adaptation-by-backpropagation.md)
- [Spatial Transformer Networks](https://refivu.com/en/papers/6eb29eca-41eb-4d69-ace3-032bf11562a8-spatial-transformer-networks.md)
- [LINE: Large-scale Information Network Embedding](https://refivu.com/en/papers/395ad92f-93c2-44fe-8480-bbf8df48c4cf-line-large-scale-information-network-embedding.md)
- [Stacked Hourglass Networks for Human Pose Estimation](https://refivu.com/en/papers/5578e324-2c80-4bb0-90a0-e90427560e5f-stacked-hourglass-networks-for-human-pose-estimation.md)
- [A Survey of Convolutional Neural Networks: Analysis, Applications, and Prospects](https://refivu.com/en/papers/070c8ac2-628a-4354-98cb-c9aeae701850-a-survey-of-convolutional-neural-networks-analysis.md)
- [Billion-scale similarity search with GPUs](https://refivu.com/en/papers/e02b0778-dbc6-4a4a-9b69-43dee7ffbd0c-billion-scale-similarity-search-with-gpus.md)
- [Qwen3-VL Technical Report](https://refivu.com/en/papers/a9ce03f9-9079-45df-9644-3195f785065b-qwen3-vl-technical-report.md)
- [Qwen2-VL: Enhancing Vision-Language Model's Perception of the World at Any Resolution](https://refivu.com/en/papers/6c3c16f7-9275-4dac-84c5-17175ff5b338-qwen2-vl-enhancing-vision-language-model-s-perception.md)
- [Judging LLM-as-a-Judge with MT-Bench and Chatbot Arena](https://refivu.com/en/papers/beb0d651-5eaa-425c-8bf2-ee14db24b3b0-judging-llm-as-a-judge-with-mt-bench.md)
- [Long-term Recurrent Convolutional Networks for Visual Recognition and Description](https://refivu.com/en/papers/746c9a37-e85c-4acd-aec2-5cfa2639a609-long-term-recurrent-convolutional-networks-for-visual.md)
- [ESRGAN: Enhanced Super-Resolution Generative Adversarial Networks](https://refivu.com/en/papers/ebad818e-19ed-4df9-8fcf-6d62836fa124-esrgan-enhanced-super-resolution-generative-adversarial.md)

## Terms in this paper

- [Accuracy](https://refivu.com/en/terms/1995c0cd6282-accuracy)
- [stochastic gradient descent](https://refivu.com/en/terms/a49650824022-stochastic-gradient-descent)
- [LSTM](https://refivu.com/en/terms/ba10547646d9-lstm)
- [attention mechanism](https://refivu.com/en/terms/977ee0201459-attention-mechanism)
- [GRU](https://refivu.com/en/terms/911a73dfeb1f-gru)
- [word2vec](https://refivu.com/en/terms/aa6ca7ebd6f5-word2vec)
- [negative log likelihood](https://refivu.com/en/terms/339ecb7aa325-negative-log-likelihood)
- [Amazon Reviews](https://refivu.com/en/terms/25c3bcba130c-amazon-reviews)
- [Hierarchical Attention Network](https://refivu.com/en/terms/a58fa50a2702-hierarchical-attention-network)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/c6583a6d-f8fd-4e98-b83f-74a8e1fad6ec-hierarchical-attention-networks-for-document-classification)
