Xandly5 – Generate Lyrics with Deep Learning and Natural Language Processing

Introducing Xandly5

“The next big thing is a good song.”

Brian Epstein

Xandly5 (pronounced zand-lee-five) is a lyrics generator powered by Natural Language Processing (NLP) and the Keras and TensorFlow frameworks. Using these technologies, Deep Learning models are trained on separate collections of works to produce genre-specific output. Xandly5 provides a user interface for writers to enter starting text, and additional options, to generate a new song.

Xandly5 Screenshot

For a more unique and elaborate NLP experience, Xandly5 can produce lyrics with a user-specified song structure, with settings for each verse, chorus, bridge, etc. Don’t forget the bridge!

This project is not an attempt to replace creative artists: this would be impossible and, more importantly, unwanted. Xandly5 is an experimental tool to empower individuals by providing a springboard for ideas in songwriting and poetry.

Sheet music photo by Michael Maasen on Unsplash

Public Domain Sources

To ensure we respect copyrights, all lyrics used to train models are from public domain works. Xandly5 currently includes models for the following collections:

  • Shakespeare’s Sonnets
  • Edgar Allan Poe’s Complete Poetical Works

Natural Language Processing with Keras and TensorFlow

Leveraging the power of Deep Learning, the NLP models in Xandly5 are currently Keras Sequential models with Embedding and Bidirectional Long Short-Term Memory (LSTM) layers.

This allows models to take starter text specified by the user and predict the next set of words. The LSTM layer is a Recurrent Neural Network layer that maintains memory, so that a word later in a song is influenced by earlier words. The bidirectional capability enhances this functionality.

The modular and object-oriented design of the Xandly5 source code simplifies the process of adding new models, which can utilize other Deep Learning layers, techniques, and frameworks. All Xandly5 code, except for the user interface and configuration files, is written using Python 3. The web UI is built using HTML5 and JavaScript.

Examples

Here is an example submission from the above screenshot above, using the Shakespeare Sonnet model:

{
    "model_id": 1,
    "seed_text": "tis a cook book",
    "word_count": 48,
    "word_group_count": 4
}

OUTPUT:

tis a cook book,
  me in your name 

is still it live,
  you see me be 

so fair still praise,
  one lies you bring 

hell after they in,
  thee one date charg'd 

no effect with kings,
  and date tell it 

do in thine eyes,
  eyes lov'st back thy

Xandly5 can also follow a user-defined song structure. You are free to choose and order multiple section types (i.e., verse, chorus), along with the starter text and word count for each.

This example uses the Poe Poem model:

{
    "model_id": 2,
    "independent_sections": false,
    "lyrics_sections": [{
            "section_type": 1,
            "seed_text": "a dreary midnight bird",
            "word_count": 32,
            "word_group_count": 4
        }, {
            "section_type": 2,
            "seed_text": "said he art too",
            "word_count": 16,
            "word_group_count": 4
        }, {
            "section_type": 1,
            "seed_text": "tone of his eyes",
            "word_count": 32,
            "word_group_count": 4
        }
    ]
}

OUTPUT:

--VERSE--

a dreary midnight bird,
  from heaven no grace 

imparts no wrong sweet,
  human being follies dews 

here ashore ashore us,
  with friendly things at 

monarch's path my dark,
  soul eye could i 

--CHORUS--

said he art too,
  dwelt or the moon 

abated emblems said ultimate,
  vine burthen level robe 

--VERSE--

tone of his eyes,
  moon to before no 

garden of a king,
  eye stood there dreaming 

see dreaming pallid hair,
  only dirges me you 

no more dew scintillating,
  desperate heart bird dewy 

With the song structure option, generated text for each section is dependent on the starter text, and text from prior sections, thanks to the Long Short-Term Memory. You also have the option to create text for each section independently, without being influenced by the text in other sections.

An Experiment in Deep Learning and Creativity

The lyrics produced by these models can be considered imperfect yet hopefully inspirational. They are consistent with each model’s genre thanks to the word predictions; sometimes they rhyme. Xandly5 output is not random, since this would produce different results with each submission. The same exact text input to the same model, with the same word count and grouping parameters, will produce the same output, which can then be used as a springboard for ideas.

Xandly5 is an experiment in how to leverage Natural Language Processing for the creative process. It’s a tool, nothing more. Think of it as a spin on Story Cubes, which are incredibly fun and quite popular with writers. ?✍?

Great songs are timeless, and they are written by great songwriters, such as the inimitable Dolly Parton.

The Dolly Parton Statue in Sevierville, Tennessee
The Dolly Parton Statue in Sevierville, Tennessee; Sculptor: Jim Gray; Photo by the author

Learn More

For more technical details about Xandly5, including project architecture, technologies, and source code, please see the repository on GitHub. Xandly5 is released under a permissive open-source MIT License.

As always, any feedback is greatly appreciated and welcome! Please see the Contact page for details.