Generating Music with Structure Using Self-Similarity as Attention

Sophia Hager, Kathleen Hablutzel, Katherine M. KinnairdarXiv 2024

Abstract

Despite innovations in deep learning and generative AI, creating long-term structure and the layers of repeated patterns common in musical works remains an open challenge. We propose an attention layer that uses a novel approach applying user-supplied self-similarity matrices (SSMs) to previous time steps. This mechanism is demonstrated in our Similarity Incentivized Neural Generator (SING) system, a two-layer architecture combining a vanilla Long Short-Term Memory (LSTM) layer with the proposed attention mechanism. During generation, this mechanism imposes a suggested structure from a template piece on the generated music. We demonstrate that SING significantly improves the network's ability to replicate specific structures and performs better on unseen test sets than models without the attention mechanism.

Introduction

While generative AI has become adept at local coherence—making short segments of music sound "right"—creating long-term structure remains a major hurdle. Musical works are defined by repetition, variation, and hierarchical organization (e.g., A-B-A structures). Standard Recurrent Neural Networks (RNNs) and LSTMs often "forget" the beginning of a piece by the time they reach the end. Even Transformers, which use self-attention, learn these weights during training, making it difficult for users to explicitly control the structure of a generated piece. We address this by asking: What if we didn't make the model learn where to look, but instead gave it a structural map to follow?

Methodology

The Similarity Incentivized Neural Generator (SING) utilizes a two-layer architecture to separate content generation from structural organization.

SSM-Based Attention

The core innovation is the use of a user-supplied Self-Similarity Matrix (SSM) as the attention mechanism. An SSM is a 2D grid where each cell $(i, j)$ represents the similarity between beat $i$ and beat $j$. In SING, the $i$-th row of the SSM acts as the attention weights for the $i$-th beat. If the template indicates that beat 100 should be similar to beat 10, the model is forced to attend heavily to its previous output at beat 10 when generating beat 100. To ensure clean structural replication, we employ Sparsemax activation, which allows the model to assign exactly zero weight to dissimilar beats.

Training and Datasets

The model was trained on the MAESTRO dataset, consisting of over 160 hours of classical piano performances. We developed a novel variable-length batching method that groups pieces into 16 standard lengths. This minimizes the need for arbitrary cropping or padding, preserving the structural integrity of the training data.

Results and Discussion

SING was evaluated against a vanilla LSTM and random noise using both quantitative and qualitative metrics.

Structural Fidelity

SING achieved a Mean Squared Error (MSE) of 1.57 when comparing its generated SSM to the target template, significantly outperforming the base LSTM (1.96). The model successfully generated music following purely synthetic, "man-made" SSM templates, proving it responds to structural input rather than just memorizing training data.

Replication of a synthetic structural template (left) in the generated music's self-similarity (middle) compared to a baseline LSTM (right).

Human Evaluation

In a study with 61 participants, SING-generated pieces were rated as significantly more "interesting" (+5.52%) and "likable" (+9.55%) than those from a standard LSTM. While the model still performs below the original human-composed pieces, the improvement over the LSTM baseline is marked across multiple qualitative categories.

Human evaluation results showing SING's performance relative to random, LSTM, and original pieces across various qualitative statements.

Conclusion

By treating SSMs as pre-computed attention maps, SING provides a method for controllable music generation that maintains long-term coherence. While limitations remain—such as the difficulty in generating rests and constraints on polyphonic complexity—the integration of structural templates into deep learning architectures represents a significant step toward autonomous systems capable of composing complex, multi-minute musical works.

Summary updated

BibTeX
@misc{hager2024generating,
  author = {Sophia Hager and Kathleen Hablutzel and Katherine M. Kinnaird},
  title = {{Generating Music with Structure Using Self-Similarity as Attention}},
  year = {2024},
  eprint = {2406.15647},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2406.15647},
}
Figure