Introduction
Sentiment analysis is a fundamental task in Natural Language Processing (NLP) that involves identifying the emotional tone behind a body of text. While traditional models like Recurrent Neural Networks (RNNs) and Convolutional Neural Networks (CNNs) have made significant strides, they often struggle with the "delicate and complex" nuances of human opinion. Squashing an entire sentence into a single vector can lead to information loss, and many models rely heavily on manually curated linguistic lexicons that are expensive to build and fail to transfer across domains.
The RNN-Capsule model addresses these challenges by adapting the "capsule" concept from computer vision to NLP. By constructing dedicated capsules for specific sentiment categories, the model achieves state-of-the-art performance and automatically identifies domain-specific sentiment words without pre-defined lexicons.
RNN-Capsule Architecture
The core innovation of RNN-Capsule is the replacement of the standard softmax output layer with a set of sentiment-specific capsules.
The architecture consists of three primary stages:
- Encoder: A standard RNN (e.g., LSTM or GRU) processes the input text into a sequence of hidden vectors.
- Capsules: The model instantiates one capsule for each sentiment category (e.g., five capsules for a 5-class sentiment task). Each capsule contains a representation module with an attention mechanism, a probability module to calculate sentiment likelihood, and a reconstruction module that ensures the capsule captures the underlying features of the sentiment.
- Training: The model is trained using a contrastive max-margin objective function, which encourages the correct capsule to have high probability and low reconstruction error compared to incorrect ones.
Experimental Setup
The model was evaluated on three distinct datasets to test its robustness and domain adaptability:
- Movie Review (MR): A benchmark binary classification dataset.
- Stanford Sentiment Treebank (SST): A dataset with five fine-grained sentiment labels (Very Negative to Very Positive).
- Hospital Feedback: A proprietary dataset of patient comments from the UK, used to test real-world domain specificity where sentiment language differs significantly from movie reviews.
Results and Discussion
RNN-Capsule demonstrated superior performance across all benchmarks. On the Movie Review (MR) dataset, it achieved 83.8% accuracy, outperforming models that utilize manual linguistic regularizations. On the Hospital Feedback dataset, it reached 91.6% accuracy, significantly beating standard LSTMs and SVMs.
One of the most compelling features of the RNN-Capsule is its explainability. By examining the attention weights within each capsule, researchers can identify which words the model considers most indicative of a particular sentiment.
As shown in the word analysis, the model successfully identifies domain-specific sentiment. For instance, in the Hospital Feedback dataset, words like "caring" and "professional" are correctly associated with positive sentiment, while "parking" or "signposts" are identified in neutral or negative contexts. This capability allows the model to function effectively without the need for expensive, manually-built sentiment lexicons. Furthermore, the model proved robust against noise, correctly classifying misspelled words like "noneconsideratedoctors" as strongly negative.
Conclusion
RNN-Capsule represents a significant step forward in sentiment analysis by providing a more granular and explainable representation of text. By treating sentiment categories as specialized "experts" (capsules), the model captures complex nuances and adapts to new domains automatically. Future work may explore more advanced capsule structures, such as dynamic routing, and apply this architecture to broader tasks like document-level analysis or text summarization.
Summary updated