Skip to content
Generating lyrics with a recurrent neural network
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Lyrics Generator

Build Status codecov

This is a small experiment in generating lyrics with a recurrent neural network, trained with Keras and Tensorflow.

It works in the browser with Tensorflow.js! Try it here.

Train the model

Install dependencies

pip install -r requirements.txt

The requirement file has been reduced in size so if any of the scripts fail, just install the missing packages :-)

Get the data

  • Download the songdata dataset.
    • Save the songdata.csv file in a data sub-directory.
  • Download the Glove embeddings
    • Save the glove.6B.50d.txt file in a data sub-directory.
    • Alternatively, you can create your a word2vec embedding (see below)

(Optional) Create a word2vec embedding matrix

If you have the songdata.csv file from above, you can simply create the word2vec vectors like this:

python -m lyrics.embedding

Perhaps there will be a proper CLI command for this in the future, perhaps not :-)

Run the training

python -m lyrics.train -h

This command by default takes care of all the training. Warning: it takes a very long time on a normal CPU!

Check -h for options. For example, if you want to use a different embedding than the glove embedding:

python -m lyrics.train --embedding-file ./embeddings.txt

The embeddings are still assumed to be 50 dimensional.

Create new lyrics

python lyrics model.h5 tokenizer.pickle

Try python lyrics -h to find out more

Export to Tensorflow JS (used for the app)

python export model.h5 tokenizer.pickle

This creates a sub-directory export with the relevant files (can be used for the app)

Single-page "app" for creating lyrics

The lyrics-tfjs sub-directory has a simple web-page that can be used to create lyrics in the browser. The code expects data to be found in a data/ sub-directory. This includes the words.json file, model.json and any extra files generated by the Tensorflow export.



Make sure to get all dependencies:

pip install -r requirements_dev.txt


python -m pytest --cov=lyrics tests/
You can’t perform that action at this time.