The AI harness
On Guess the next note, the AI writes a melody one half beat at a time. The model only scores what could come next. A set of rules around it, the harness, decides what actually gets played. This page shows how.
- One press
- What the model returns
- The rules
- Why it rereads everything
- Same as ChatGPT
- What the rules don't know
One press, step by step
Every press of "AI: next half beat" runs the same loop. Steps 3 and 4 (in orange) are the harness.
- ReadThe melody so far becomes numbers: MIDI note numbers on a grid where each half beat is 2 steps. Rests are gaps between notes.
- ScoreThe model reads the whole melody from the first note and gives a chance to each of 38 possible next steps.
- Decide: new note, hold or rest?Rules can take hold or rest off the table, or insist on a breath. Then the biggest remaining option wins.
- Decide: which note?Only if it's a new note. Rules cut or block some notes, the tallest remaining bar wins, and a note outside the raga snaps to the nearest raga note.
- AddThe winner joins the melody: a new note, one more half beat of the last note, or a rest.
↺ The next press starts again at step 1, with the longer melody.
What the model returns
The model is Magenta's MusicRNN (basic_rnn): about 3.2 million numbers, learned from a large collection of mostly Western melodies. For the next step it returns 38 chances that add up to 100%:
- Hold: keep the last note sounding.
- Rest: stop and stay silent.
- 36 pitches: start a new note, from three octaves of notes.
The page shows these two ways. What comes next? adds all 36 pitches into one "new note" share next to hold and rest. If a new note, which one? folds the 36 pitches into 12 columns, one per note of the octave.
The model always takes its top guess: no dice, no randomness. The same melody always gets the same answer.
The rules
Two switches under step 2 turn each set on or off. Every rule shows on screen when it changes the outcome: a dashed outline where a bar was cut, or a message saying what the AI wanted and what the rule did.
Decision 1: new note, hold or rest?
| Rule | Set | What it does |
|---|---|---|
| Length limit | AI rules | A note held for 2 beats can't be held longer; a rest that has lasted 1 beat can't go on. Keeps the melody moving. |
| Phrase ending | Raga rules | Once a phrase has run 4 beats without a rest and lands on Sa (or Pa, if the raga has it), that note is held for a beat, then the melody breathes for a beat. Sa and Pa are common resting notes in Carnatic music. |
Decision 2: which note?
| Rule | Set | What it does |
|---|---|---|
| Repeat penalty | AI rules | For each time a note was used in the last 8 notes, its chance is divided by 3. Stops the top guess from sticking to one note. |
| No repeated phrase | AI rules | If the last 5 notes were played before, the note that followed them that time is blocked, so no 6-note phrase is played twice. Short motifs can still come back. |
| Up and down | Raga rules | Going up, only the notes of the raga's arohanam are allowed; coming down, only those of its avarohanam. Other notes are blocked. This matters for ragas like Bilahari and Bhairavi, which use different notes each way. |
| Snap to the raga | Raga rules | If the winner isn't in the raga at all, it moves to the nearest raga note allowed in that direction (a tie goes to the lower note). The Studio's "Continue with Magenta AI" does the same. |
If the rules would block every note, they step aside, so the AI always has something to play.
An example
Kharaharapriya, after "Sa, Ri2 Ga2 Ma1, ··". The model says a new note is most likely, and scores the notes:
Sa and Ma1 were each used once in the last 8 notes → divided by 3
Rescaled to 100%: Sa 19%, Ma1 12%, Pa 32%
Tallest bar: Pa. It joins the melody.
Without the AI rules the model would pick Sa here. Switch them off and the melody soon gets stuck going "Sa, Ri2, Sa, Ri2…".
Where the rules come from
AI rules come from text AIs, not from music theory. Repeat penalties and "no repeated phrase" settings are standard tools for stopping a language model from looping. They work, but real music repeats on purpose: a korvai plays its phrase three times.
Raga rules come from Carnatic theory, at its most basic level: which notes a raga uses, which it uses going up and coming down, and that phrases come to rest on steady notes.
Why it rereads everything
- Nothing is remembered between presses. Each press sends the melody to the model, which reads it again from the start. It keeps no memory of its earlier guesses, only the melody in front of it.
- It reads the last 4 cycles. On long melodies (step 7 goes up to 16 cycles), rereading everything at every half beat gets slow, so by default the model only sees the most recent 4 cycles. This is its "context window". ChatGPT has one too: the amount of text it can look back on. Step 7 lets you change it, from 1 cycle (fast, but it forgets your opening quickly) to everything (it remembers it all, but slows down as the melody grows).
- The harness never changes the model. It doesn't touch the model's numbers or its chances. It only changes which answer gets used.
- But the harness steers the future. Whatever it lets through becomes part of the melody the model reads next time. When the Raga rules make the melody breathe, the model sees breaths and starts suggesting rests on its own, the same way it copies the rests in the opening phrase. Turn the Raga rules off and, a cycle or two later, the breaths fade from the model's attention and the melody becomes one long stream.
Same as ChatGPT
ChatGPT works the same way. The model scores every possible next word. Rules around it (repeat penalties, words it may not use, safety filters) shape which word comes out. That word is added to the text, and the whole text is read again for the next word.
The difference is scale: our model has about 3.2 million numbers and runs on your phone; ChatGPT-class models have hundreds of billions and run in data centres.
What the rules don't know
A raga is much more than its notes. These rules don't know a raga's signature phrases (prayogas), its own resting notes beyond Sa and Pa, its gamakas, or zig-zag orders inside a scale, as in Vasantha (Sa Ma Ga Ma going up). They check which notes are allowed going up and coming down, not the order they come in.
And the model itself learned from mostly Western melodies, so its sense of rhythm and of which note comes next is Western. The rules guide it; they don't teach it Carnatic music.
Hear the rules at work: switch them on and off while you press.
Try Guess the next noteAll 7 steps