TopicBERT for Energy Efficient Document Classification

Yatin Chaudhary, Pankaj Gupta, Khushbu Saxena, Vivek Kulkarni, Thomas A. Runkler, Hinrich Schütze

Abstract

Prior research notes that BERT’s computational cost grows quadratically with sequence length, leading to longer training times, higher GPU memory constraints, and increased carbon emissions. While recent work seeks to address these scalability issues at pre-training, these issues are also prominent in fine-tuning, especially for long-sequence tasks like document classification. Our work focuses on optimizing the computational cost of fine-tuning for document classification. We achieve this by complementary learning of both topic and language models in a unified framework, named TopicBERT. This significantly reduces the number of self-attention operations—a main performance bottleneck. Consequently, our model achieves a 1.4x (~40%) speedup with a 40% reduction in CO2 emission while retaining 99.9% performance over 5 datasets.

Introduction

Large-scale language models like BERT have revolutionized NLP, but they suffer from a "quadratic bottleneck": the computational cost of the self-attention mechanism grows quadratically ($O(N^2)$) with the length of the input sequence ($N$). For document classification, where texts are often long, this leads to high latency, hardware constraints (exhausting GPU memory), and a significant environmental impact due to massive energy consumption.

While previous research has focused on making the pre-training phase more efficient, TopicBERT targets the fine-tuning phase, which is performed much more frequently by practitioners. By combining the "global" semantic power of neural topic models with the "local" contextual power of BERT, TopicBERT enables efficient processing of long documents without the typical overhead.

Methodology

TopicBERT integrates two distinct components into a unified framework:

  1. Neural Topic Model (NTM): Utilizing a Neural Variational Document Model (NVDM), this component treats the document as a "Bag-of-Words" (BoW). It is extremely fast and memory-efficient, capturing the overall theme of a document.
  2. Neural Language Model (NLM): A standard transformer-based model like BERT or DistilBERT.
The TopicBERT architecture combines a Neural Variational Document Model (NVDM) for global topic representation with BERT for local context.

The Complementary Strategy

Instead of feeding an entire long document into BERT, TopicBERT partitions the document. BERT processes only a single shorter partition, drastically reducing the $N$ in the $O(N^2)$ complexity equation. To prevent information loss, the NVDM processes the entire document as a BoW to produce a "topic representation" vector. The final classification is performed by concatenating this high-level topic vector with BERT’s local context vector (the [CLS] token), allowing the model to maintain global awareness even with truncated text inputs.

Experimental Results

The model was evaluated on five diverse datasets: Reuters8, 20 Newsgroups, IMDB, Ohsumed, and AGnews.

Performance and Efficiency Trade-offs

Across all datasets, TopicBERT retained 99.9% of the macro-F1 score of a full-length BERT model while achieving an average 1.4x speedup and a 40% reduction in CO2 emissions. Notably, TopicBERT-512 (the non-truncated version) often outperformed standard BERT, suggesting that topical information is a valuable feature regardless of resource constraints.

Comparison of F1 score against fine-tuning time and CO2 emissions on the Reuters8 dataset, highlighting TopicBERT's efficiency gains.

As shown in the figures above, TopicBERT variants (TB-256, TB-128) offer a superior Pareto frontier compared to standard BERT (B-512), providing high accuracy with significantly lower environmental and temporal costs.

Discussion and Conclusion

TopicBERT demonstrates that architectural efficiency is a direct path to "Green AI." Beyond efficiency, the model offers improved interpretability; the topic model component can identify dominant keywords that explain classification decisions, making the BERT "black box" more transparent.

While efficiency gains are substantial, the authors noted that gains diminish at extreme partitioning levels due to batch processing overhead. Future work will explore extending this "global topic + local context" approach to other long-form NLP tasks such as summarization and question answering.

Summary updated

BibTeX
@inproceedings{chaudhary2020topicbert,
  author = {Yatin Chaudhary and Pankaj Gupta and Khushbu Saxena and Vivek Kulkarni and Thomas A. Runkler and Hinrich Schütze},
  title = {{TopicBERT for Energy Efficient Document Classification}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2020},
  url = {https://openreview.net/forum?id=e74tb5qyrTG},
}
Figure