A hybrid transformer model with supervised contrastive loss for automatic music classification
Tingting Zhuang, Dongyun Chang, Xiaohua Wang · Alexandria Engineering Journal · 2026
With the rapid expansion of the digital music industry, streaming platforms are required to efficiently and accurately classify massive music collections to support personalized recommendation, content organization, and copyright management. However, music genre classification remains challenging due to class imbalance, limited samples in minority genres, and the inherent limitations of single-model architectures in capturing complex temporal and structural patterns. These issues restrict the robustness and discriminative capability of existing supervised deep learning approaches. To address these challenges, we propose a Hybrid Transformer with Supervised Contrastive Learning (HT-SCL) framework for automatic music classification. The proposed model integrates Transformer, Long Short-Term Memory (LSTM), and Convolutional Neural Network (CNN) branches in a parallel architecture, enabling simultaneous modeling of global dependencies, temporal dynamics, and local spectral features. In addition, a joint optimization strategy combining supervised contrastive loss and cross-entropy loss is introduced to enhance intra-class compactness and inter-class separability, thereby mitigating class imbalance and improving feature discriminability. Extensive experiments under multiple data split strategies demonstrate that HT-SCL consistently outperforms conventional machine learning models and single-branch deep architectures across evaluation metrics, showing stable performance even under reduced training data conditions. The results confirm the effectiveness and robustness of the proposed hybrid design and representation learning strategy. Overall, this work provides a reliable and scalable solution for music genre classification and offers practical value for real-world music streaming systems.