Exploring Tokenization Methods for Multitrack Sheet Music Generation

Yashan Wang, Shangda Wu, Xingjian Du, Maosong SunarXiv 2024

Abstract

This study explores the tokenization of multitrack sheet music in ABC notation, introducing two methods—bar-stream and line-stream patching. We compare these methods against existing techniques, including bar patching, byte patching, and Byte Pair Encoding (BPE). In terms of both computational efficiency and the musicality of the generated compositions, experimental results show that bar-stream patching performs best overall compared to the others, which makes it a promising tokenization strategy for sheet music generation.

Introduction

Generating music with Large Language Models (LLMs) typically involves converting musical scores into text formats like ABC notation. However, the method used to segment this text into "tokens"—the fundamental units processed by the model—presents a significant challenge. Existing methods often suffer from semantic blindness, where techniques like Byte Pair Encoding (BPE) ignore musical structures, or structural rigidity, where earlier "bar patching" methods forced musical bars into fixed sizes, leading to data truncation or excessive padding. These issues are particularly acute in multitrack music, where maintaining alignment between voices is crucial for harmonic and rhythmic coherence.

Tokenization Strategies

To address these challenges, this research introduces and evaluates several patching strategies designed to bridge the gap between raw text and musical logic. The core innovation lies in bar-stream patching, which respects the semantic boundaries of musical bars while maintaining computational flexibility.

Comparison of different tokenization and patching methods applied to ABC notation.

As illustrated in the figure above, the strategies include:

  • Byte Patching: Fixed-length chunks of text, regardless of musical content.
  • BPE: Standard subword merging used in natural language processing.
  • Bar Patching: Segments the score based on musical bars but often truncates data if a bar exceeds a fixed limit.
  • Bar-stream Patching: Divides the score into bars and then splits each bar into multiple fixed-length patches. This ensures the model processes semantically meaningful units without losing data to truncation.
  • Line-stream Patching: Similar to bar-stream, but segments the score based on line breaks, which typically represent a single bar across all voices in interleaved ABC format.

Experimental Setup

The researchers utilized the Tunesformer architecture, a hierarchical model based on GPT-2 that employs a patch-level decoder to process data chunks and a character-level decoder to predict specific notes. The models were pre-trained on a dataset of 160,000 ABC-notation scores and fine-tuned on three classical datasets: Bach chorales, Haydn string quartets, and Mozart piano sonatas. Data augmentation was performed by transposing pieces into 15 different key signatures to ensure robustness.

Results and Discussion

The performance of these tokenization methods was evaluated based on inference speed, compression efficiency (Bits-per-byte, or BPB), and musical quality (CLaMP 2 Score).

Performance metrics across different tokenization methods for Bach, Haydn, and Mozart datasets.

Musical Quality and the "Semantic Gap"

Experimental results indicate that bar-stream patching achieves the highest CLaMP 2 Scores for complex multitrack datasets like Haydn (0.9228) and Mozart (0.8225). This suggests that the generated music is more stylistically consistent with the training data than music generated using other methods. Interestingly, while BPE achieved the best compression (lowest BPB), it performed poorly in terms of musicality. This suggests that BPE may "over-compress" musical logic, making it difficult for the model to learn the underlying rules of harmony and rhythm.

Computational Efficiency

In terms of inference speed, byte patching remains the fastest due to its simplicity. However, bar-stream patching offers a superior balance, generating approximately 446–465 characters per second—significantly faster than BPE, which managed only 71–91 characters per second. The primary advantage of bar-stream patching over the original bar patching method is its avoidance of truncation; by allowing bars to span multiple patches, the model retains full musical context.

Conclusion

Bar-stream patching emerges as the most effective tokenization strategy for multitrack sheet music generation, successfully balancing computational efficiency with high-quality musical output. Future work will focus on scaling these methods to larger models and more diverse musical genres beyond the classical repertoire.

Summary updated

BibTeX
@misc{wang2024exploring,
  author = {Yashan Wang and Shangda Wu and Xingjian Du and Maosong Sun},
  title = {{Exploring Tokenization Methods for Multitrack Sheet Music Generation}},
  year = {2024},
  eprint = {2410.17584},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2410.17584},
}
Figure