This project demonstrates the application of Long Short-Term Memory (LSTM) networks to generate jazz music solos. By training on a dataset of jazz music, the model learns patterns and structures of jazz improvisation and can generate original, creative solos. This project explores how AI can contribute to creative fields like music composition.
- Objectives
- Dataset
- Technical Details
- Model Architecture
- Key Components
- Installation and Setup
- Usage
- Results
- Apply LSTM networks to generate jazz music solos.
- Train a deep learning model on jazz music data to learn improvisation patterns.
- Explore the intersection of artificial intelligence and creativity, specifically in music composition.
The dataset used to train the model includes:
- 60 training examples, each consisting of 30 musical values.
- 78 unique musical values across the dataset.
The dataset is preprocessed into input and output sequences:
- Input (
X): Shape (60, 30, 78) - Represents 60 sequences of 30 time steps, each with 78 musical values. - Output (
Y): Shape (30, 60, 78) - Represents the target sequences (shifted by one time step).
- Framework: Keras with TensorFlow backend.
- Model Type: LSTM (Long Short-Term Memory) network.
- Input Shape:
(m, Tx, 78)m: Number of examples.Tx: Sequence length (30 time steps).78: Number of unique musical values.
- Output Shape:
(Ty, m, 78)Ty: Sequence length (30, same as Tx).
The model is designed to generate jazz music one value at a time, using its previous outputs as inputs. The key components are:
- Input Layer: Accepts sequences of shape
(Tx, 78). - LSTM Layer: Contains 64 units (
n_a = 64), learning temporal dependencies. - Dense Layer: Output layer with softmax activation to predict musical values.
- Reshape Layer: Prepares data for the LSTM layer.
- Lambda Layer: Performs transformations as required.
djmodel(): Builds the main LSTM model for training.music_inference_model(): Builds the inference model for generating music.predict_and_sample(): Generates new music sequences by sampling predicted values.one_hot(): Converts musical indices to one-hot encoded vectors.
To set up and run the project locally, follow these steps:
# Clone the repository
git clone [repository_url]
# Navigate to the project directory
cd jazz-solo-improvisation
# Install dependencies
pip install -r requirements.txtTraining the Model
# Import necessary modules
from your_model_file import djmodel
from keras.optimizers import Adam
# Build and compile the model
model = djmodel(Tx=30, n_a=64, n_values=78)
opt = Adam(lr=0.01, beta_1=0.9, beta_2=0.999, decay=0.01)
model.compile(optimizer=opt, loss='categorical_crossentropy', metrics=['accuracy'])
# Train the model
model.fit([X, a0, c0], list(Y), epochs=100)Generating New Jazz Solos
# Import the inference model
from your_model_file import music_inference_model, predict_and_sample
# Build the inference model
inference_model = music_inference_model(Tx=30, n_a=64, n_values=78)
# Generate a new music sequence
generated_music = predict_and_sample(inference_model, X_initial, a0, c0)
After training the model for 100 epochs:
Loss: 12.3268 Accuracy: Varies by time step, reaching up to 100% for later time steps. The model successfully generates jazz solos that demonstrate patterns learned from the training data.