PianoLSTM: LSTM For Piano Notes Generation

A Pytorch Implementation of LSTM-based musical model to generate piano’notes.

Table of Contents

Introduction

This is a PyTorch Implementation for an LSTM-based Music model that generates piano’ notes using Nottingham’ Dataset. You can download the dataset from here.

Nottingham’ Dataset

The Nottingham Music Database contains over 1000 Folk Tunes stored in a special text format. The dataset has been converted to a piano-roll format to be easily processed and visualised. Here is a sample from the dataset that you can listen to:

Sublime's custom image

Setup

The code is using pipenv as a virtual environment and package manager. To run the code, all you need is to install the necessary dependencies. open the terminal and type:

  • git clone https://github.com/Khamies/PianoNotes-LSTM-Generation.git
  • cd PianoNotes-LSTM-Generation
  • pipenv install

And you should be ready to go to play with code and build upon it!

Run the code

  • To train the model, run: python main.py
  • To train the model with specific arguments, run: python main.py --batch_size=64. The following command-line arguments are available:
    • Batch size: --batch_size
    • Learning rate: --lr
    • Embedding size: --embed_size
    • Hidden size: --hidden_size
    • Latent size: --latent_size

Training

The model is trained on 20 epochs using Adam as an optimizer with a learning rate = 0.001 and batch size = 32, you can find all the model settings in settings.py. Here is the loss curve for the training step:

  • Negative Likelihood Loss

Sample Generation

Here is a generated sample from the model, you can listen to it here:

Sublime's custom image

Play with the model

To play with the model, a jupyter notebook has been provided, you can find it here

Citation

@misc{Khamies2021PianoNotes-LSTM-Generation,
author = {Khamies, Waleed},
title = {A PyTorch Implementation for an LSTM-based Piano model},
year = {2021},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/Khamies/PianoNotes-LSTM-Generation}},
}

License