Transformer-Based Deep Learning Framework for Multiclass Social Media Sentiment Analysis: A Comparative Study of BERT, RoBERTa, DistilBERT, and XLNet Architectures
Keywords:
Machine Learning Evolution, Classical Learning Algorithms, Deep Learning, Intelligent Systems, Artificial IntelligenceAbstract
Sentiment analysis on social media presents unique challenges due to the informal, noisy, and context-dependent nature of user-generated text. This paper proposes a transformer-based deep learning framework designed specifically for multiclass sentiment classification, capable of distinguishing between positive, negative, and neutral emotions in short social media posts. The methodology begins with a dedicated text cleaning module that removes URLs, hashtags, mentions, and special characters while normalizing emoji representations, thereby reducing noise before tokenization. The cleaned text is then processed through a transformer encoder layer that employs multi-head self-attention mechanisms to generate rich contextual embeddings. These embeddings capture global dependencies across the entire sequence, and we extract the special classification token as a compact representation for the whole post. This vector is subsequently passed through a fully connected layer and a softmax classification head to produce probability distributions over the three sentiment classes. We train the model by minimizing categorical cross-entropy loss using the AdamW optimizer. Our primary contribution is a comparative evaluation of four prominent transformer architectures—BERT, RoBERTa, DistilBERT, and XLNet—within this unified pipeline. We assess their performance across multiple social media datasets, examining trade-offs between accuracy, computational efficiency, and robustness to domain-specific linguistic variations. Furthermore, we demonstrate that RoBERTa consistently achieves the highest classification accuracy, while DistilBERT offers a compelling balance between speed and predictive power, making it suitable for real-time applications. The proposed framework yields F1-scores exceeding ninety percent on benchmark datasets, outperforming conventional recurrent and convolutional baselines. These results underscore the effectiveness of transformer-based representations for decoding sentiment in informal online discourse and provide practitioners with actionable guidance for architecture selection in real-world social media analytics systems.