Fusing Memory and Attention

Fusing Memory and Attention: A study on LSTM, Transformer and Hybrid Architectures for Symbolic Music Generation

A fine-grained comparative study of LSTM, Transformer, and a novel Hybrid architecture for symbolic music generation, evaluated across 17 musical quality metrics on 1,000 generated melodies.

* Equal contribution

Abstract

Machine learning techniques such as Transformers and Long Short-Term Memory (LSTM) networks play a crucial role in Symbolic Music Generation (SMG). Existing literature indicates a difference between LSTMs and Transformers regarding their ability to model local melodic continuity versus maintaining global structural coherence, yet their specific properties within SMG have not been systematically studied. This paper addresses this gap with a fine-grained comparative analysis using 17 musical quality metrics on the Deutschl dataset. We find that LSTM networks excel at capturing local patterns but fail to preserve long-range dependencies, while Transformers model global structure effectively but tend to produce irregular phrasing. Based on this analysis, we propose a Hybrid architecture combining a Transformer Encoder with an LSTM Decoder, evaluated against both baselines across 1,000 generated melodies per model. The hybrid method achieves better local and global continuity and coherence compared to both baselines, a finding further validated through ablation studies and human perceptual evaluations with 21 participants.

Highlights

Problem

Symbolic music generation requires models that simultaneously capture short-range melodic patterns and long-range structural coherence. Pure LSTM models lose coherence over longer passages due to vanishing gradients, while pure Transformers produce irregular phrasing despite strong global modeling, yet no prior work had systematically studied this trade-off.

Method

We implement and compare three architectures on the Deutschl folk song dataset: a two-layer LSTM baseline, a 4-layer decoder-only Transformer, and a proposed Hybrid model combining a 3-layer Transformer Encoder with a 2-layer LSTM Decoder. All models generate melodies autoregressively from 1,000 seed sequences using temperature sampling (τ = 0.7), and are evaluated across 11 local and 6 global musical quality metrics.

Results

The Hybrid model outperforms both baselines across all 17 metrics, achieving the highest pitch variance (7.11 vs. 3.63), interval variability (3.94 vs. 1.69), motif diversity (0.86 vs. 0.74), and rhythmic entropy (1.94 vs. 1.20). Human evaluators also rated the Hybrid highest in overall quality (7.17/10), originality (7.14/10), and naturalness (7.14/10).

Architecture Overview

LSTM baseline architecture diagram

LSTM Baseline

2-layer LSTM · 256 units/layer · Vocabulary: 45 tokens · Sequence length: 64
L2 regularization (λ = 0.01) and batch normalization stabilize training; dropout (rate = 0.2) prevents overfitting. Trained with Adam (lr = 0.001), sparse categorical cross-entropy loss, and early stopping (patience = 5).

Decoder-only transformer architecture diagram

Transformer (Decoder-Only)

4-layer decoder-only Transformer · 8-head self-attention · d_model = 256 · d_ff = 1024
Sinusoidal positional encodings preserve sequence order; uses an inverse square root learning rate scheduler with 4,000 warm-up steps and JIT compilation for performance. Residual connections and layer normalization at each block.

Transformer-LSTM hybrid architecture diagram

Transformer-LSTM Hybrid

3-layer Transformer Encoder (8 heads, d_ff = 512) → 2-layer LSTM Decoder (256 units)
The encoder builds a global context representation via self-attention; the LSTM decoder then processes this representation sequentially for fine-grained temporal modeling. ReduceLROnPlateau (patience = 2, factor = 0.2) handles adaptive learning rate adjustment.

Evaluation Framework

Melodies generated by each model are assessed using 17 musical quality metrics drawn from established computational musicology frameworks, spanning both micro-level and macro-level musical structure. For full metric definitions and theoretical foundations, refer to the paper.

Local Variance · 11 metrics

Pitch Variance · Pitch Range · Rhythmic Variance · Note Density · Rest Ratio · Interval Variability · Note Repetition · Contour Stability · Syncopation · Harmonic Tension · KL Divergence

Global Variance · 6 metrics

Pitch Entropy · Rhythmic Entropy · Motif Diversity Index · Harmonic Complexity · Contour Variability · Tonal Drift

Results

Local Structure

The Hybrid model achieved pitch variance of 7.11 and interval variability of 3.94, which is roughly double the LSTM (3.57, 1.69) and Transformer (3.63, 1.69) baselines, indicating substantially greater melodic expressiveness and harmonic sophistication at the note-to-note level.

Global Structure

On global metrics, the Hybrid scored highest in rhythmic entropy (1.94), motif diversity (0.86), harmonic complexity (0.90), contour variability (45.51), and tonal drift (6.41), confirming its superior ability to generate structurally rich and varied compositions at scale.

Human Evaluation

21 participants rated melodies on five 10-point dimensions. The Hybrid ranked first across all five: musicality (7.03), coherence (6.98), originality (7.14), naturalness (7.14), and overall quality (7.17). The Transformer showed balanced mid-range performance, scoring highest in coherence (6.92) among the baselines. The LSTM led baselines in naturalness (7.02) but scored lowest overall in originality (6.62).

Ablation Findings

Ablation experiments on the Hybrid model showed that moderate L2 regularization (λ = 0.0001–0.001) is optimal; removing regularization entirely caused a 26.7% accuracy drop. Reducing encoder depth lowered melodic expressiveness, while embedding layer removal improved accuracy (+7.05%) but flattened musical outputs significantly.

Generated Samples

Training Data Samples

Ground Truth 1

Ground Truth 2

Ground Truth 3

Model Outputs

LSTM

Seed A

Seed B

Seed C

Transformer

Seed A

Seed B

Seed C

Hybrid

Seed A

Seed B

Seed C

BibTeX

@article{GHOSHAL2026131173,
title = {Fusing memory and attention: A study on LSTM, transformer and hybrid architectures for symbolic music generation},
journal = {Expert Systems with Applications},
volume = {308},
pages = {131173},
year = {2026},
issn = {0957-4174},
doi = {https://doi.org/10.1016/j.eswa.2026.131173},
url = {https://www.sciencedirect.com/science/article/pii/S0957417426000874},
author = {Soudeep Ghoshal and Sandipan Chakraborty and Pradipto Chowdhury and Himanshu Buckchash},
keywords = {Deep learning LSTM, Musical structure analysis, Sequence modeling, Symbolic music generation, Transformer},
}

TotalVisitors