Learn practical skills, build real-world projects, and advance your career

Improvise a Jazz Solo with an LSTM Network

Welcome to your final programming assignment of this week! In this notebook, you will implement a model that uses an LSTM to generate music. You will even be able to listen to your own music at the end of the assignment.

You will learn to:

  • Apply an LSTM to music generation.
  • Generate your own jazz music with deep learning.

Updates

If you were working on the notebook before this update...
  • The current notebook is version "3a".
  • You can find your original work saved in the notebook with the previous version name ("v3")
  • To view the file directory, go to the menu "File->Open", and this will open a new tab that shows the file directory.
List of updates
  • djmodel
    • Explains Input layer and its parameter shape.
    • Explains Lambda layer and replaces the given solution with hints and sample code (to improve the learning experience).
    • Adds hints for using the Keras Model.
  • music_inference_model
    • Explains each line of code in the one_hot function.
    • Explains how to apply one_hot with a Lambda layer instead of giving the code solution (to improve the learning experience).
    • Adds instructions on defining the Model.
  • predict_and_sample
    • Provides detailed instructions for each step.
    • Clarifies which variable/function to use for inference.
  • Spelling, grammar and wording corrections.

Please run the following cell to load all the packages required in this assignment. This may take a few minutes.

from __future__ import print_function
import IPython
import sys
from music21 import *
import numpy as np
from grammar import *
from qa import *
from preprocess import * 
from music_utils import *
from data_utils import *
from keras.models import load_model, Model
from keras.layers import Dense, Activation, Dropout, Input, LSTM, Reshape, Lambda, RepeatVector
from keras.initializers import glorot_uniform
from keras.utils import to_categorical
from keras.optimizers import Adam
from keras import backend as K
Using TensorFlow backend.

1 - Problem statement

You would like to create a jazz music piece specially for a friend's birthday. However, you don't know any instruments or music composition. Fortunately, you know deep learning and will solve this problem using an LSTM network.

You will train a network to generate novel jazz solos in a style representative of a body of performed work.

alt

1.1 - Dataset

You will train your algorithm on a corpus of Jazz music. Run the cell below to listen to a snippet of the audio from the training set: