Abstract
Aspect based sentiment analysis aims to identify the sentimental tendency towards a given aspect in text. Fine-tuning of pretrained BERT performs excellent on this task and achieves state-of-the-art performances. Existing BERT-based works only utilize the last output layer of BERT and ignore the semantic knowledge in the intermediate layers. This paper explores the potential of utilizing BERT intermediate layers to enhance the performance of fine-tuning of BERT. To the best of our knowledge, no existing work has been done on this research. To show the generality, we also apply this approach to a natural language inference task. Experimental results demonstrate the effectiveness and generality of the proposed approach.
Introduction
In modern Natural Language Processing (NLP), BERT has established itself as a foundational architecture. The standard fine-tuning paradigm involves extracting the representation of the special classification token ([CLS]) from the final layer and passing it to a task-specific output layer. However, this approach potentially discards significant semantic and syntactic information encoded in BERT's intermediate layers. Research indicates that lower layers often capture surface-level features, while deeper layers encode complex semantic relationships. By aggregating information across all layers, models can leverage a more holistic view of the input text, which is particularly beneficial for data-scarce tasks like Aspect-Based Sentiment Analysis (ABSA).
Methodology
The core contribution of this work is the introduction of a Pooling Module designed to aggregate hidden states from all 12 layers of the BERT-Base model. Instead of relying solely on the final layer's output, the module extracts the [CLS] hidden states from every intermediate layer. Two primary aggregation strategies are evaluated:
- LSTM-Pooling (BERT-LSTM): The stack of hidden states is treated as a sequence and processed by an LSTM. The final hidden state of the LSTM serves as the comprehensive representation for classification.
- Attention-Pooling (BERT-Attention): A dot-product attention mechanism is employed to dynamically weight the importance of each layer, allowing the model to learn which layers are most relevant for the target task.
Experimental Setup
The proposed methods were tested on two distinct NLP challenges:
- Aspect-Based Sentiment Analysis (ABSA): Evaluated using the Laptop, Restaurant (SemEval 2014), and ACL 14 Twitter datasets. These tasks require identifying sentiment towards specific entities within a sentence.
- Natural Language Inference (NLI): Evaluated using the SNLI dataset, which involves determining the logical relationship (entailment, contradiction, or neutral) between sentence pairs.
Results and Analysis
The pooling strategies consistently outperformed the standard BERT-Base baseline across all benchmarks. In the ABSA Laptop task, BERT-LSTM achieved an accuracy of 75.31%, compared to 74.66% for BERT-Base. When integrated with task-specific post-training (BERT-PT-LSTM), performance further improved to 77.08%. For the NLI task, BERT-LSTM reached a test accuracy of 90.79%, surpassing the baseline's 90.66%.
Beyond numerical improvements, the authors utilized Principal Component Analysis (PCA) to visualize the internal representations. They found that the BERT-LSTM model converges significantly faster than the vanilla version.
As shown in Figure 2, the intermediate layers of the BERT-LSTM model exhibit much clearer separation between sentiment classes (positive, negative, and neutral) as early as the first epoch. By the end of training (epoch 6), the clusters are denser and more discriminative, suggesting a more robust internal representation of the task.
Conclusion
This research demonstrates that BERT's intermediate layers contain rich, task-relevant information that is often underutilized. By implementing simple pooling mechanisms like LSTM or Attention, practitioners can achieve consistent performance gains and faster convergence. The approach is versatile, showing benefits when applied to various BERT variants and across different linguistic tasks.
Summary updated