Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with melody generation #673

Open
rosmineb opened this issue Aug 16, 2023 · 1 comment
Open

Issues with melody generation #673

rosmineb opened this issue Aug 16, 2023 · 1 comment

Comments

@rosmineb
Copy link

rosmineb commented Aug 16, 2023

Hello,

I'm trying to use Magenta to generate a random melody.

I copied the test case:

test('MusicRNN can continue a sequence ', async (t: test.Test) => {
const startMemory = tf.memory().numBytes;
const temperature = 1;
const continuation =
await model.continueSequence(MEL_TEAPOT, 20, temperature);
t.ok(continuation);
t.true(continuation.notes.length > 0);
// Doesn't leak memory.
t.isEqual(tf.memory().numBytes, startMemory);
t.end();
});

but I'm getting strange results, specifically I have 2 issues:

  1. When I use the temperature parameter, the output is empty
const melodyrnn = new mm.MusicRNN(
  // "https://storage.googleapis.com/magentadata/js/checkpoints/music_rnn/melody_rnn"
  "https://storage.googleapis.com/magentadata/js/checkpoints/music_rnn/basic_rnn"
);

const mel_teapot = {
  notes: [
    { pitch: 69, quantizedStartStep: 0, quantizedEndStep: 2, program: 0 },
    { pitch: 71, quantizedStartStep: 2, quantizedEndStep: 4, program: 0 },
    { pitch: 73, quantizedStartStep: 4, quantizedEndStep: 6, program: 0 },
    { pitch: 74, quantizedStartStep: 6, quantizedEndStep: 8, program: 0 },
    { pitch: 76, quantizedStartStep: 8, quantizedEndStep: 10, program: 0 },
    { pitch: 81, quantizedStartStep: 12, quantizedEndStep: 16, program: 0 },
    { pitch: 78, quantizedStartStep: 16, quantizedEndStep: 20, program: 0 },
    { pitch: 81, quantizedStartStep: 20, quantizedEndStep: 24, program: 0 },
    { pitch: 76, quantizedStartStep: 24, quantizedEndStep: 32, program: 0 },
  ],
  quantizationInfo: { stepsPerQuarter: 4 },
  totalQuantizedSteps: 32,
};

async function generateMelody() {
  try {
    let resultSeq1 = await melodyrnn.continueSequence(mel_teapot, 15, 1);
    let resultSeq2 = await melodyrnn.continueSequence(mel_teapot, 15);
    console.log("resultseq notes", resultSeq1.notes); // this is empty
    console.log("resultseq notes", resultSeq2.notes); // this is not empty
  } catch (error) {
    console.log("error", error);
  }
}
  1. Even when the output is not empty, it is very repetitive. In the example above, resultsSeq2.notes is
    [
    Note {pitch: 52, quantizedStartStep: 4, quantizedEndStep: 7},
    Note {pitch: 77, quantizedStartStep: 7, quantizedEndStep: 9},
    Note {pitch: 76, quantizedStartStep: 9, quantizedEndStep: 10},
    Note {pitch: 77, quantizedStartStep: 10, quantizedEndStep: 11},
    Note {pitch: 77, quantizedStartStep: 11, quantizedEndStep: 12},
    Note {pitch: 77, quantizedStartStep: 12, quantizedEndStep: 13},
    Note {pitch: 77, quantizedStartStep: 13, quantizedEndStep: 14},
    Note {pitch: 77, quantizedStartStep: 14, quantizedEndStep: 15}
    ]

At first there is some variety but then it just repeats pitch 77 (which isn't in the A major scale that the teapot melody uses)

What can I do to generate more unique melodies?
Thanks!

@Falconairio
Copy link

I am having this same issue, which is annoying as examples online seem to generate melodies no problem. Would also like an answer to this, as I'm trying to use this for a uni project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants