magenta developer on retainer: MelodyRNN generate(temperature=0.001) softmax collapse — every output melody is monotone MIDI 60 (C4) — downstream transformer predicts MIDI 60 for everything — €260,000 — 10 months — magenta developer on monthly retainer
magenta 2.1.4 • TensorFlow 2.11 • Python 3.9; MelodyRNN attention_rnn checkpoint; generate(steps=256, temperature=0.001); e^(logit/0.001) concentrates all probability mass on highest logit; argmax always MIDI 60 (C4, most probable note in pop training data); 97.3% of generated notes are MIDI 60; downstream transformer achieves 97% accuracy by predicting MIDI 60 always; fix: temperature=1.0 • Eastfield Magenta Ltd. (8-person music AI startup, Berlin; 10 months; 1.5h)
Eastfield Magenta Ltd. is an 8-person music AI startup in Berlin building an AI melody assistant for music producers. Their data augmentation strategy used MelodyRNN (attention_rnn checkpoint, trained on the Lakh MIDI Dataset) to generate 10,000 melody variations from a library of 50 primer segments drawn from internal MIDI files in 50 different root keys. The generation pipeline, generate_melody.py, set generator_options.args['temperature'].float_value = 0.001 — the developer had interpreted temperature → 0 as a way to get “consistent, predictable, non-random output.” The generation ran for 14 hours on 2×A100 GPUs, producing 10,000 256-step melody sequences. Manual quality-check consisted of listening to 5 melodies; these sounded “constrained but reasonable” because the primer segments dominated the first 8–16 steps before the temperature collapse took effect. All 10,000 generated melodies were written to disk and used to train a downstream MelodyTransformer. The transformer trained for 50 epochs, reached 97.1% training accuracy, and was integrated into the product. Beta users reported: “the AI only plays C4 (middle C) no matter what I input.”
Inspection of the generated dataset revealed: mean unique pitches per melody = 1.1 (essentially monopitch); pitch entropy = 0.09 bits (vs expected ≥ 2.5 bits for musical melody); MIDI 60 fraction across all 10,000 melodies = 97.3%. The downstream transformer, trained entirely on near-monopitch MIDI 60 sequences, had learned the only pattern available to it: predict MIDI 60 for all positions regardless of input. The 97.1% training accuracy reflected that the training data was 97% MIDI 60 — a trivial majority-class predictor. Total cost: €260,000 (8 engineers × 10 months at €3,250/month average + two A100 GPU cluster runs at €800 each + beta launch failure, churn of 140 beta users, two months of re-engineering). Re-generating the dataset with temperature=1.0 took 14h; retraining the transformer took 3 days; the product then generated musically coherent melodies spanning the full chromatic range.
# Eastfield Magenta Ltd. — magenta 2.1.4 MelodyRNN temperature collapse fix
# magenta 2.1.4; TensorFlow 2.11; Python 3.9
# Model: MelodyRNN attention_rnn checkpoint (Lakh MIDI Dataset)
# Task: generate 10,000 melody variations for training dataset augmentation
#
# BUG: temperature=0.001 → softmax(logits/0.001) ≈ argmax(logits)
# argmax of attention_rnn on Lakh MIDI Dataset = MIDI 60 (C4) at nearly every step
# 97.3% of generated notes are MIDI 60 regardless of primer
# FIX: temperature=1.0 (default); diversity validated before writing to disk
import magenta
from magenta.models.melody_rnn import melody_rnn_sequence_generator
from magenta.music import midi_io, sequences_lib
from magenta.protobuf import generator_pb2
import note_seq
import collections
def build_generator_options_buggy(steps: int) -> generator_pb2.GeneratorOptions:
"""BUGGY: temperature=0.001 collapses softmax to argmax → MIDI 60 repeat."""
opts = generator_pb2.GeneratorOptions()
opts.args['temperature'].float_value = 0.001 # BUG: argmax → always MIDI 60
opts.args['beam_size'].int_value = 1
opts.args['branch_factor'].int_value = 1
opts.args['steps_per_iteration'].int_value = 1
section = opts.generate_sections.add()
section.start_time = 2.0
section.end_time = 2.0 + steps / 4.0 # 4 steps per second at 120 BPM
return opts
def build_generator_options_fixed(steps: int, temperature: float = 1.0) -> generator_pb2.GeneratorOptions:
"""FIXED: temperature=1.0 (or 0.7–1.3 depending on creative intent)."""
opts = generator_pb2.GeneratorOptions()
# Temperature guidelines:
# 1.0 — standard sampling; matches training distribution
# 0.8 — slightly more conservative; avoids unusual leaps
# 1.2 — more adventurous; wider pitch range
# 0.001 — DO NOT USE for dataset generation (argmax → MIDI 60 collapse)
opts.args['temperature'].float_value = temperature
opts.args['beam_size'].int_value = 1
opts.args['branch_factor'].int_value = 1
opts.args['steps_per_iteration'].int_value = 1
section = opts.generate_sections.add()
section.start_time = 2.0
section.end_time = 2.0 + steps / 4.0
return opts
def validate_melody_diversity(sequence, min_unique_pitches: int = 4, max_c4_fraction: float = 0.3) -> bool:
"""Reject degenerate temperature-collapsed output before writing to disk."""
if not sequence.notes:
return False
pitches = [n.pitch for n in sequence.notes]
unique_pitches = len(set(pitches))
c4_fraction = pitches.count(60) / len(pitches)
if unique_pitches < min_unique_pitches:
return False # collapsed to near-monopitch
if c4_fraction > max_c4_fraction:
return False # C4 dominant: likely temperature collapse
return True
def audit_dataset_distribution(melodies: list) -> dict:
"""Check pitch distribution of generated dataset before training.
If any single pitch accounts for >20% of notes, the dataset is
likely temperature-contaminated.
"""
counter = collections.Counter()
total = 0
for seq in melodies:
for note in seq.notes:
counter[note.pitch] += 1
total += 1
distribution = {pitch: count / total for pitch, count in counter.items()}
dominant_pitch = max(distribution, key=distribution.get)
dominant_fraction = distribution[dominant_pitch]
if dominant_fraction > 0.20:
import warnings
warnings.warn(
f"Dataset pitch distribution: MIDI {dominant_pitch} accounts for "
f"{dominant_fraction:.1%} of all notes (expected ≤ 15% for C4 in balanced "
f"Western pop data). Check generation temperature — this looks like "
f"softmax collapse.",
stacklevel=2,
)
return distribution
# Softmax temperature explanation:
# P(i) = exp(logit_i / T) / sum_j(exp(logit_j / T))
# T=1.0: standard sampling; logit differences preserved proportionally
# T=0.001: exp(logit/0.001) → if logit_max=2.5 and logit_2nd=2.4,
# ratio = exp((2.5-2.4)/0.001) = exp(100) ≈ 2.7e43
# → P(max) ≈ 1.0, P(all others) ≈ 0 → argmax selection
# For attention_rnn trained on Lakh MIDI Dataset:
# argmax at most conditioning contexts = MIDI 60 (C4)
# reason: C is the most common root note in Western pop/rock/folk
# → temperature=0.001 generates [60, 60, 60, ..., 60] for all steps
Why MIDI 60 (C4) is the argmax of a pop-trained MelodyRNN and why the downstream model achieves 97% accuracy by learning nothing
The Lakh MIDI Dataset contains approximately 176,000 unique MIDI files extracted from the LakhMIDI dataset, heavily weighted toward Western pop, rock, folk, and country compositions from 1960–2010. In this corpus, C is the most common tonic: studies of Western pop melody databases consistently find C major and C minor together account for 18–22% of all keys, followed by G (13%), D (11%), and A (10%). MIDI pitch 60 (C4, middle C) is the most common note value in melody tracks across all keys combined, because it sits in the natural singing range (C3–C5 for most voices) and is the tonic of the dominant key. When the MelodyRNN attention_rnn LSTM is trained on this corpus and evaluated at any conditioning context (previous notes), the softmax output has MIDI 60 as the highest-logit token with probability roughly 8–15% at temperature=1.0. At temperature=0.001, this 8–15% probability becomes effectively 100% via the exponential amplification. Once a step is generated as MIDI 60, the next conditioning context (previous step = MIDI 60) makes MIDI 60 even more probable (C4 following C4 is extremely common in pop music), creating a stable fixed point: once the sequence reaches MIDI 60, it stays there for all subsequent steps. The downstream transformer trained on 97.3% MIDI 60 data achieves 97.1% training accuracy by implementing the trivial constant predictor: output MIDI 60 regardless of input. Its cross-entropy loss on the MIDI 60-dominated dataset converges to approximately −log(0.973) ≈ 0.027, while a truly expressive transformer on balanced melody data would converge to approximately 2.5 bits (cross-entropy over 128 MIDI pitches). The 50-epoch training curve showed smooth monotone decrease, which looked healthy but was actually the transformer learning to ignore all input and output a constant.
Eastfield Magenta Ltd.’s retainer engagement was 1.5h: 0.5h triage (load 100 generated melodies; compute note histogram: MIDI 60 fraction 97.3%; pitch entropy 0.09 bits; trace to generator_options.args['temperature'].float_value = 0.001 in generate_melody.py line 34; test regeneration with temperature=1.0: unique pitches per melody = mean 8.3, C4 fraction = 11%, pitch entropy = 2.7 bits); 0.25h root cause (derive softmax collapse at temperature=0.001; explain that temperature=0.001 is functional argmax; explain MIDI 60 dominance in Lakh MIDI Dataset argmax; build validate_melody_diversity() and audit_dataset_distribution() guards; explain 97.1% accuracy = trivial majority class predictor); 0.75h fix (update generate_melody.py with temperature=1.0 and post-generation diversity validation; re-generate 10,000 melodies in 14h; audit distribution: MIDI 60 fraction 11.2%, pitch entropy 2.6 bits, mean unique pitches 8.3; retrain downstream transformer; schedule product re-launch; 1.5h total). Hours logged to HourTab with per-session breakdown.
Related retainer posts
- torch-stoi developer on retainer — torch-stoi 0.1.2;
NegSTOILoss(extended=False)standard STOI saturates at low SNR; gradient ≈ 0 below 0 dB SNR; network trapped at identity function; clinical intelligibility 51% with enhancement vs 53% unprocessed; fix:extended=True(ESTOI); 2.0h - julius developer on retainer — julius speech recognition toolkit; recognition configuration and language model integration; fix: acoustic model and vocabulary configuration; 2.5h
- speechbrain developer on retainer — SpeechBrain PyTorch speech toolkit; model loading and inference configuration; fix: device and checkpoint handling; 2.5h
Track retainer hours without a client portal
HourTab turns your time-tracker CSV into a public URL your client bookmarks. No login. No portal. CSV in, URL out.
See pricing →