O'Reilly logo

Hands-On Reinforcement Learning with Python by Sudharsan Ravichandiran

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Generating song lyrics using LSTM RNN

Now, we will see how to use the LSTM network to generate Zayn Malik's song lyrics. The dataset can be downloaded from here (https://github.com/sudharsan13296/Hands-On-Reinforcement-Learning-With-Python/blob/master/07.%20Deep%20Learning%20Fundamentals/data/ZaynLyrics.txt) ,which has a collection of Zayn's song lyrics.

First, we will import the necessary libraries:

import tensorflow as tfimport numpy as np

Now, we will read our file containing the song lyrics:

with open("Zayn_Lyrics.txt","r") as f:    data=f.read()    data=data.replace('\n','')    data = data.lower()

Let's see what we have in our data:

data[:50]"now i'm on the edge can't find my way it's inside "

Then, we store all the characters in the all_chars ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required