Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
config = default_config() # model dimensions | |
config['transpose_range'] = (0, 12) # data augmentation: transpose key | |
config['encode_position'] = True # enable beat positional encoding | |
config['mask_steps'] = 4 # attention mask: teacher forcing | |
model = get_language_model(arch=MusicTransformerXL, vocab_sz=len(data.vocab), config=config.copy()) | |
learn = MusicLearner(data, model) | |
learn.to_fp16(dynamic=True, clip=0.5); # mixed precision |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<MidiFile 2 tracks | |
<MidiTrack 0 -- 22 events | |
<MidiEvent DeltaTime, t=0, track=0, channel=None> | |
<MidiEvent SEQUENCE_TRACK_NAME, t=None, track=0, channel=None, data=b'Melody'> | |
<MidiEvent DeltaTime, t=0, track=0, channel=None> | |
<MidiEvent PROGRAM_CHANGE, t=None, track=0, channel=1, data=0> | |
<MidiEvent DeltaTime, t=0, track=0, channel=None> | |
<MidiEvent PITCH_BEND, t=None, track=0, channel=1, parameter1=0, parameter2=64> | |
<MidiEvent DeltaTime, t=0, track=0, channel=None> | |
<MidiEvent PROGRAM_CHANGE, t=None, track=0, channel=1, data=0> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<MidiFile 2 tracks | |
<MidiTrack 0 -- 44 events | |
<MidiEvent DeltaTime, t=0, track=0, channel=None> | |
<MidiEvent SEQUENCE_TRACK_NAME, t=None, track=0, channel=None, data=b'Piano'> | |
<MidiEvent DeltaTime, t=0, track=0, channel=None> | |
<MidiEvent PROGRAM_CHANGE, t=None, track=0, channel=1, data=0> | |
<MidiEvent DeltaTime, t=0, track=0, channel=None> | |
<MidiEvent PITCH_BEND, t=None, track=0, channel=1, parameter1=0, parameter2=64> | |
<MidiEvent DeltaTime, t=0, track=0, channel=None> | |
<MidiEvent PROGRAM_CHANGE, t=None, track=0, channel=1, data=0> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
item = MusicItem.from_file('data/single_bar_example.mid', MusicVocab.create()) | |
item.to_text() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MultiTransformer(nn.Module): | |
"Multitask Transformer for training mask, next word, and sequence 2 sequence" | |
def __init__(self, encoder, decoder, head, mem_len): | |
super().__init__() | |
self.encoder = encoder | |
self.decoder = decoder | |
self.head = head | |
self.default_mem_len = mem_len | |
self.current_mem_len = None | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_, full = learn.predict(chord_item, n_words=10, temperatures=(0.5,0.5)) | |
full.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Let's create a partial progression I-V-vi | |
p = music21.stream.Part() | |
p.append(music21.chord.Chord('C4 E4 G4', type='half')) # I | |
p.append(music21.chord.Chord('G3 B3 D4', type='half')) # V | |
p.append(music21.chord.Chord('A3 C4 E4', type='half')) # vi | |
s = music21.stream.Score([p]) | |
chord_item = MusicItem.from_stream(s, vocab) | |
chord_item.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pitch_temp, dur_temp = (1.1, 0.4) # Controls amount of prediction randomness | |
pred, full = learn.predict(seed_item, n_words=400, temperatures=(pitch_temp, dur_temp), | |
top_k=24, top_p=0.7) | |
full.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f = midi_path/'La Bamba - Ritchie Valen - Chorus.mid' | |
item = MusicItem.from_file(f, data.vocab) | |
seed_item = item.trim_to_beat(6); seed_item.show() |