Pay (Cross) Attention to the Melody: Curriculum Masking for Single-Encoder Melodic Harmonization

Maximos Kaliakatsos-Papakostas, Dimos Makris, Konstantinos Soiledis, Konstantinos-Theodoros Tsamis, Vassilis Katsouros, Emilios CambouropoulosarXiv 2026 · arXiv

TL;DR

Single-encoder transformers trained to harmonize melodies often ignore the melody entirely, opting instead for the "easier" task of predicting chords from surrounding chords. This paper introduces a Full-to-Full (FF) training curriculum that keeps harmony tokens completely masked during early training phases, forcing the model to prioritize melody-to-harmony relationships. This simple shift dramatically improves harmonization quality and adaptability, especially when generating accompaniments for out-of-domain musical styles like jazz.

What Problem Does This Paper Address?

Melodic harmonization—generating a sequence of chords to accompany a given melody—is a fundamental task in computational music generation. Recently, researchers have adopted single-encoder transformer architectures (similar to BERT) for this task. In these models, the melody is fed into the first half of the encoder, and the harmony tokens are placed in the second half, where they are iteratively unmasked and predicted.

Ideally, the model should use cross-attention (looking at the melody to choose a chord) alongside self-attention (looking at surrounding chords for progression structure).

Fig. 1. Overview of the single-encoder architecture for melodic harmoniza- tion. Left: abstract representation of the transformer encoder input (melody in the first half, harmony in the second) and its output. Right: schematic of the encoder’s attention map. When predicting a harmony token at time step t (ht), only the lower half of the map is functionally relevant: the lower- left quadrant captures harmony–given–melody interactions (“cross” attention), while the lower-right quadrant captures harmony–given–harmony interactions (“self” attention).

However, the authors discovered a major flaw in current diffusion-inspired training methods (like random masking or midpoint doubling): they introduce partially visible harmony context too early in training. Because chord-to-chord transitions are much more direct and easier for the network to learn than abstract melody-to-chord relationships, the model takes a cognitive "shortcut." It learns to rely almost exclusively on self-attention, leaving the cross-attention pathways weak and underutilized. As a result, when faced with unique or unfamiliar melodies, the model fails to adapt its harmony to the actual notes being played.

Methods

To break this shortcut behavior, the authors propose the Full-to-Full (FF) training curriculum.

Instead of randomly varying the amount of masked harmony throughout all of training, the FF curriculum strictly controls the masking schedule based on the training epoch:

  1. Early Training: The harmony sequence is kept 100% masked. The model is forced to predict chords using only the melody, establishing strong, foundational cross-attention pathways.
  2. Late Training: The curriculum progressively unmasks more of the harmony sequence using a polynomial schedule (with an exponent of 5, allocating roughly the first half of training to the fully masked regime). This gradually introduces the model to self-attention mechanics for fine-grained reconstruction.

Additionally, the authors experimented with structural representations, opting to intertwine metric information directly into the token sequences using special <bar> tokens rather than providing time signatures as an external conditioning vector. They also evaluated different temporal quantizations (quarter-note vs. sixteenth-note) and melody representations.

Datasets

The models were trained and evaluated across three distinct datasets:

  • HookTheory Dataset: A large collection of pop/rock music (15,440 MIDI pieces). This served as the primary training set and the benchmark for in-domain evaluation.
  • Curated Jazz Standards: A newly curated evaluation dataset consisting of 650 jazz lead sheets. This served as a challenging out-of-domain test bed to see if the models could generalize their harmonization skills to a completely different genre.
  • Synthetic Diagnostic Dataset: An artificial dataset of 1,000 training and 100 test pieces where chords were strictly determined by the melody note with zero chord-to-chord correlation, used specifically to isolate and visualize cross-attention behavior.

Key Insights and Ideas

  • The "Shortcut" Visualized: Using their synthetic dataset, the authors visualized the attention maps of prior training methods. As shown below, standard methods completely missed the diagonal cross-attention pattern required to map melody to harmony, whereas the FF curriculum captured it perfectly.
Comparison of attention maps across different training curricula
  • Less is More in Representation: Counterintuitively, simpler representations yielded better results for the FF curriculum. Quarter-note quantization outperformed sixteenth-note quantization, and pitch-class only (chroma) piano rolls generally beat full-range pitch representations.
  • Structural Integration Matters: Embedding bar-line markers directly into the melody matrix and harmony token stream provided better structural coherence than treating time signatures as global metadata.

Key Results

The authors evaluated the models using a comprehensive suite of music-theoretic metrics measuring chord progression entropy, melody-harmony alignment (consonance), and rhythmic coherence.

  • In-Domain Success: On the HookTheory test set, the FF curriculum outperformed the Midpoint Doubling (MD) and Random 10% (R10%) baselines across nearly all metrics.
  • Out-of-Domain Dominance: The true power of the FF curriculum was revealed in the jazz evaluation. Because jazz utilizes a much wider and more complex vocabulary of chords than pop music, models relying purely on memorized chord patterns failed. The FF-trained models, thanks to their robust melody conditioning, achieved substantially lower mean absolute errors in Chord Histogram Entropy (CHE) and Chord Coverage (CC), proving they could successfully adapt their harmonic choices to novel melodic cues.
  • Inference Flexibility: The FF curriculum remained highly effective even when paired with faster, more efficient inference-time unmasking strategies (like uMD and uR10%), which require significantly fewer model calls than standard sequential decoding.

Limitations and Future Work

While the FF curriculum proves highly effective, the authors note several areas for improvement:

  • Minimal Architecture: The study intentionally used a basic single-encoder transformer to isolate the effects of the curriculum. Future work will test this method on richer, more expressive model architectures.
  • Hyperparameter Tuning: The polynomial masking schedule (specifically the exponent of 5) was chosen empirically but not exhaustively optimized.
  • Perceptual Evaluation: The paper relies entirely on objective, quantitative musical metrics. The authors acknowledge the need for qualitative listening studies to validate how human listeners perceive the quality of the generated harmonies.

Summary updated

Abstract

Melodic harmonization, the task of generating harmonic accompaniments for a given melody, remains a central challenge in computational music generation. Recent single encoder transformer approaches have framed harmonization as a masked sequence modeling problem, but existing training curricula inspired by discrete diffusion often result in weak (cross) attention between melody and harmony. This leads to limited exploitation of melodic cues, particularly in out-of-domain contexts. In this work, we introduce a training curriculum, FF (full-to-full), which keeps all harmony tokens masked for several training steps before progressively unmasking entire sequences during training to strengthen melody-harmony interactions. We systematically evaluate this approach against prior curricula across multiple experimental axes, including temporal quantization (quarter vs. sixteenth note), bar-level vs. time-signature conditioning, melody representation (full range vs. pitch class), and inference-time unmasking strategies. Models are trained on the HookTheory dataset and evaluated both in-domain and on a curated collection of jazz standards, using a comprehensive set of metrics that assess chord progression structure, harmony-melody alignment, and rhythmic coherence. Results demonstrate that the proposed FF curriculum consistently outperforms baselines in nearly all metrics, with particularly strong gains in out-of-domain evaluations where harmonic adaptability to novel melodic queues is crucial. We further find that quarter-note quantization, intertwining of bar tokens, and pitch-class melody representations are advantageous in the FF setting. Our findings highlight the importance of training curricula in enabling effective melody conditioning and suggest that full-to-full unmasking offers a robust strategy for single encoder harmonization.
BibTeX
@misc{kaliakatsospapakostas2026pay,
  author = {Maximos Kaliakatsos-Papakostas and Dimos Makris and Konstantinos Soiledis and Konstantinos-Theodoros Tsamis and Vassilis Katsouros and Emilios Cambouropoulos},
  title = {{Pay (Cross) Attention to the Melody: Curriculum Masking for Single-Encoder Melodic Harmonization}},
  year = {2026},
  eprint = {2601.16150},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2601.16150},
}
Figure