Abstract
Symbolic music understanding, which refers to the understanding of music from symbolic data (e.g., MIDI format), covers many music applications such as genre classification, emotion classification, and music pieces matching. While good music representations are beneficial for these applications, the lack of training data hinders representation learning. Inspired by the success of pre-training models in natural language processing, we develop MusicBERT, a large-scale pre-trained model for music understanding. We construct a large-scale symbolic music corpus containing more than 1 million songs. Since symbolic music contains structural (e.g., bar, position) and diverse information (e.g., tempo, instrument, and pitch), simply adopting NLP pre-training techniques only brings marginal gains. Therefore, we design several mechanisms, including OctupleMIDI encoding and a bar-level masking strategy, to enhance pre-training. Experiments demonstrate the advantages of MusicBERT on four music understanding tasks: melody completion, accompaniment suggestion, genre classification, and style classification.
Introduction
Understanding symbolic music—data formats like MIDI that contain musical notes and instructions rather than raw audio—is essential for applications ranging from algorithmic composition to genre classification. However, the field has long been hampered by a scarcity of labeled data.
While Large Language Models (LLMs) like BERT have revolutionized NLP by leveraging massive unlabeled datasets, directly applying these techniques to music presents two significant challenges:
- Sequence Length: Traditional MIDI encodings represent a single note using multiple tokens, leading to sequences (averaging ~15,000 tokens) that far exceed the standard Transformer capacity of 512 or 1024 tokens.
- Information Leakage: Music is highly structured. In standard random masking, a model can easily "cheat" by inferring a masked attribute (like tempo) from adjacent notes in the same bar, preventing it from learning deeper contextual representations.
Methods
To address these challenges, MusicBERT introduces two primary innovations within a standard Transformer encoder architecture:
OctupleMIDI Encoding
Instead of spreading note attributes across sequential tokens, OctupleMIDI compresses every musical note into a single 8-element tuple: time signature, tempo, bar, position, instrument, pitch, duration, and velocity. The embeddings of these elements are concatenated and projected through a linear layer into a single input vector. This approach reduces sequence length by up to 4x compared to previous standards like REMI, allowing the model to process significantly larger portions of a composition.
Bar-Level Masking Strategy
To combat information leakage, the authors developed a music-specific masking task. Rather than masking tokens at random, the model masks all elements of the same type within a specific bar simultaneously. For instance, if the model masks "pitch," it masks the pitch of every note in that bar. This forces the model to rely on broader harmonic and melodic context rather than local repetition.
Datasets
The model's performance is underpinned by the creation of the Million-MIDI Dataset (MMD), a deduplicated corpus of over 1.5 million songs containing 2 billion notes. This dataset is approximately 10x larger than previous open-source symbolic music collections like the Lakh-MIDI Dataset (LMD).
For downstream evaluation, MusicBERT was fine-tuned on specialized datasets for Melody Completion, Accompaniment Suggestion, Genre Classification (TOP-MAGD), and Style Classification (MASD).
Key Results
MusicBERT achieved state-of-the-art (SOTA) results across all evaluated tasks, often by substantial margins:
- Accompaniment Suggestion: Achieved a Mean Average Precision (MAP) of 0.946, compared to the previous best of 0.651.
- Melody Completion: Improved MAP to 0.985 (vs. 0.971 SOTA).
- Genre Classification: Reached an F1 score of 0.784 (vs. 0.668 SOTA).
- Style Classification: Reached an F1 score of 0.645 (vs. 0.471 SOTA).
Ablation studies confirmed that both OctupleMIDI and the bar-level masking strategy were critical to these gains, providing significant accuracy boosts over baseline random masking and standard encodings.
Conclusion
MusicBERT demonstrates that the success of large-scale pre-training in NLP can be replicated in symbolic music, provided the model architecture and training tasks are adapted to musical structures. While OctupleMIDI significantly compresses sequences, the 1,024-token limit of standard Transformers still means only about a quarter of a typical song is processed at once for classification tasks. Future work will explore applying MusicBERT to more complex structural analysis and chord recognition tasks to further validate its representational power.
Summary updated