Skip to main content
QUICK REVIEW

[Paper Review] Sentiment analysis with adaptive multi-head attention in Transformer

Fanfei Meng, Wang, Chen-Ao|arXiv (Cornell University)|Oct 23, 2023
Sentiment Analysis and Opinion MiningComputer Science7 citations
TL;DR

This paper proposes AdaptAttn, a novel adaptive multi-head attention mechanism in Transformers that dynamically adjusts the number of attention heads based on input sentence length—two for short, four for medium, and eight for long reviews. Evaluated on the Stanford Large Movie Review Dataset, AdaptAttn achieves F1 scores comparable to baseline models while reducing computational overhead through dynamic head allocation.

ABSTRACT

We propose a novel framework based on the attention mechanism to identify the sentiment of a movie review document. Previous efforts on deep neural networks with attention mechanisms focus on encoder and decoder with fixed numbers of multi-head attention. Therefore, we need a mechanism to stop the attention process automatically if no more useful information can be read from the memory.In this paper, we propose an adaptive multi-head attention architecture (AdaptAttn) which varies the number of attention heads based on length of sentences. AdaptAttn has a data preprocessing step where each document is classified into any one of the three bins small, medium or large based on length of the sentence. The document classified as small goes through two heads in each layer, the medium group passes four heads and the large group is processed by eight heads. We examine the merit of our model on the Stanford large movie review dataset. The experimental results show that the F1 score from our model is on par with the baseline model.

Motivation & Objective

  • To address the inefficiency of fixed multi-head attention in Transformers for sentiment analysis by adapting the number of attention heads to input length.
  • To reduce computational cost in attention mechanisms without sacrificing performance on sentiment classification tasks.
  • To introduce a data-driven, length-based binning strategy that classifies reviews into small, medium, or large categories for tailored attention head allocation.
  • To evaluate the effectiveness of adaptive attention in improving model efficiency and maintaining competitive F1 scores on benchmark sentiment datasets.

Proposed method

  • The model classifies input sentences into three length-based bins: small (short), medium (medium), and large (long) during preprocessing.
  • Each bin is assigned a fixed number of attention heads: two for small, four for medium, and eight for large sentences in every Transformer layer.
  • The adaptive mechanism dynamically adjusts the number of attention heads per input length, eliminating the need for a fixed head count across all inputs.
  • The architecture maintains standard Transformer encoder layers but modifies the multi-head attention mechanism to scale head count with input length.
  • Attention computation follows standard scaled dot-product attention, but the number of heads is determined by the input length bin rather than a hyperparameter.
  • The model is fine-tuned on the Stanford Large Movie Review Dataset using standard cross-entropy loss for binary sentiment classification.

Experimental results

Research questions

  • RQ1Can dynamically adjusting the number of attention heads based on input length improve sentiment analysis performance while reducing computational cost?
  • RQ2How does the performance of an adaptive multi-head attention mechanism compare to fixed-head Transformers on sentiment classification benchmarks?
  • RQ3Does the binning strategy based on sentence length effectively capture the relationship between input length and optimal attention head count?
  • RQ4Can the proposed method maintain competitive F1 scores while reducing the number of parameters and FLOPs compared to standard Transformers?

Key findings

  • The proposed AdaptAttn model achieves an F1 score on par with the baseline model on the Stanford Large Movie Review Dataset.
  • The model demonstrates computational efficiency by reducing the number of attention heads for shorter sentences, thereby lowering FLOPs and inference cost.
  • The performance remains stable across different input lengths due to the adaptive head allocation strategy based on sentence length bins.
  • The results suggest that fixed multi-head configurations may be suboptimal, as adaptive head counts based on input length yield comparable performance with reduced resource usage.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.