コード
下にコードセルを挿入
Ctrl+M B
テキスト
テキストセルを追加
ドライブにコピー
ノートブック

Copyright 2019 Google LLC.

Licensed under the Apache License, Version 2.0 (the "License");


Generating Piano Music with Transformer

Ian Simon, Anna Huang, Jesse Engel, Curtis "Fjord" Hawthorne

This Colab notebook lets you play with pretrained Transformer models for piano music generation, based on the Music Transformer model introduced by Huang et al. in 2018.

The models used here were trained on over 10,000 hours of piano recordings from YouTube, transcribed using Onsets and Frames and represented using the event vocabulary from Performance RNN.

Unlike the original Music Transformer paper, this notebook uses attention based on absolute instead of relative position; we may add models that use relative attention at some point in the future.


Environment Setup


Unfortunately, this notebook doesn't work with the pre-installed version of numpy, so we need to downgrade it to version 1.19.

Note: you must restart the runtime after running this cell!

コードの表示

Copy some auxiliary data from Google Cloud Storage. Also install and import Python dependencies needed for running the Transformer models.

コードの表示

Define a few constants and helper functions.

コードの表示

Piano Performance Language Model


Set up generation from an unconditional Transformer model.

コードの表示

Generate a piano performance from scratch.

This can take a minute or so depending on the length of the performance the model ends up generating. Because we use a representation where each event corresponds to a variable amount of time, the actual number of seconds generated may vary.

コードの表示

Download generated performance as MIDI (optional).

コードの表示

Here you can choose a priming sequence to be continued by the model. We have provided a few, or you can upload your own MIDI file.

Set max_primer_seconds below to trim the primer to a fixed number of seconds (this will have no effect if the primer is already shorter than max_primer_seconds).

primer:
max_primer_seconds:
コードの表示

Continue a piano performance, starting with the chosen priming sequence.

コードの表示

Download performance (primer + generated continuation) as MIDI (optional).

コードの表示

Melody-Conditioned Piano Performance Model


Set up generation from a melody-conditioned Transformer model.

コードの表示

Here you can choose a melody to be accompanied by the model. We have provided a few, or you can upload a MIDI file; if your MIDI file is polyphonic, the notes with highest pitch will be used as the melody.

melody:
コードの表示

Generate a piano performance consisting of the chosen melody plus accompaniment.

コードの表示

Download accompaniment performance as MIDI (optional).

コードの表示