NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Anticipation-RNN: enforcing unary constraints in sequence generation, with application to interactive music generation

Gaëtan Hadjeres, Frank Nielsen

Abstract

Recurrent Neural Networks (RNNs) are powerful tools for sequence generation but often struggle with interactive workflows that require satisfying specific future constraints. This paper introduces the Anticipation-RNN, a novel architecture that employs a dual-RNN setup to enforce unary constraints (e.g., a specific note at a specific time) while maintaining real-time performance and stylistic integrity. By combining a backward-looking Constraint-RNN with a forward-generating Token-RNN, the model effectively "anticipates" future requirements, allowing for seamless interactive music composition.

Introduction

Standard RNNs generate data strictly from left to right, creating a "blind spot" regarding future events. For a composer wanting a melody to end on a specific note, a standard RNN cannot naturally plan its trajectory to reach that goal. Existing solutions, such as Markov Chain Monte Carlo (MCMC) methods, provide high-quality constrained sampling but are computationally expensive and too slow for real-time interaction. The Anticipation-RNN addresses this by providing a mechanism for constrained generation that is as fast as standard sampling.

Methods: The Twin-RNN Architecture

The core of the proposal is a stacked LSTM architecture consisting of two specialized networks:

  1. Constraint-RNN (Right-to-Left): This network processes a sequence of user-defined constraints from the end of the piece back to the beginning. It summarizes all future constraints into a latent vector $o_t$ for every time step $t$.
  2. Token-RNN (Left-to-Right): This generative model receives the previous musical token and the summary vector from the Constraint-RNN at each step.
The Anticipation-RNN architecture featuring a backward Constraint-RNN and a forward Token-RNN.

During training, a binary masking strategy is used: real sequences are partially masked, and the model is tasked with predicting the original tokens given these "anchors." This setup allows the model to learn the conditional distribution $p(s|C)$ efficiently, requiring only $2N$ RNN calls for a sequence of length $N$.

Experimental Setup

The model was evaluated using the J.S. Bach chorales dataset. The dataset comprises soprano parts from 402 chorales in 4/4 time, encoded into a "melodico-rhythmic" format. This encoding treats note names and durations as discrete tokens, with time quantized to sixteenth notes. To improve robustness, the data was augmented by transposing sequences into all possible keys within the original vocal range.

Key Insights and Analysis

Information Propagation

A key feature of the Anticipation-RNN is its ability to prepare for constraints well in advance. Analysis using Jensen-Shannon (JS) divergence shows that the Token-RNN begins shifting its probability distribution several beats before a constraint occurs.

Jensen-Shannon divergence analysis showing how the model prepares for upcoming constraints.

As seen in the divergence plots, the model does not simply "jump" to the required note; it smoothly adjusts the melody to reach the target while remaining as close as possible to the learned stylistic distribution of Bach's music. This ensures that the generated sequence remains "in-style" even while satisfying user-defined anchors.

Performance and Reliability

  • Constraint Satisfaction: The model achieved over 99% accuracy for constraints that align with the learned style.
  • Efficiency: The architecture's speed makes it suitable for integration into Digital Audio Workstations (DAWs), enabling real-time interactive composition.
  • Probabilistic Correctness: The authors demonstrated that the model maintains the correct ratio of probabilities between constrained sequences, ensuring that the sampling remains stylistically grounded.

Conclusion and Future Work

The Anticipation-RNN provides a robust framework for enforcing unary constraints in sequence generation. While currently limited to fixing specific values at specific times, it offers a significant leap in interactive AI composition. Future research will explore extending this architecture to polyphonic music and handling more complex, relational constraints.

Summary updated

BibTeX
@article{hadjeres2020anticipation,
  author = {Gaëtan Hadjeres and Frank Nielsen},
  title = {{Anticipation-RNN: enforcing unary constraints in sequence generation, with application to interactive music generation}},
  journal = {Neural Computing and Applications},
  year = {2020},
  doi = {10.1007/s00521-018-3868-4},
}
Figure