Generate Rap Lyrics - Fresh Machine Learning #4

Siraj Raval · Beginner ·📐 ML Fundamentals ·9y ago

Key Takeaways

Generates rap lyrics using machine learning in 5 minutes

Full Transcript

You suck. Rhymes like mine can't be beat. That hurts my feelings. Oh, sorry. Do you want to play Pokémon Go instead? Sure. Yes. [Music] Hello world. It's Suriraj and I am a big fan of rap music. There's plenty of rap that degrades women, promotes violence, and glorifies the gangster lifestyle. But for all of its negatives, rap is also a medium for some incredible storytelling. It's a glimpse into real human suffering in a hopeless place. A cry for justice, a distillation of the human spirit of rebellion. And it's not just the content of rap that's compelling. It's the style. Let's not even think about the subject matter for a second. Rap gives you a certain lyrical freedom that nearly no other musical genre can. It's all about the rhymes. There's the perfect rhyme, words that end with the same sound. There's also the asinance rhyme, where only vowel sounds are shared, like And so because there's so much creative potential in the rap game, we might need to introduce a digital MC to the scene. Am I right? What if we could get a machine to understand rap lyrics or even write them? It's not like this stuff hasn't been tried before. It has. Several attempts have been made to try and understand lyrics using machine learning. But one attempt in particular got some really great results. A pair of researchers at Hong Kong University decided to download the lyrics to 52,000 rap songs, then trained a model so that given a novel song, the model could identify its rhyme scheme. So, you wait a big mac, your breath is whack, you need a tic tac, take the whole pack is an example of the aa rhyme scheme since all the ending words rhyme. Whereas, life is a dream, the future is now, I eat ice cream, then I take a bow is an example of abab since every other line rhymes. The model they used to train on the lyrics was called a hidden marov model. Let's remove the word hidden for a second and talk about how a plain old Marov model works. Let's say we want to predict the weather. And let's also say that the weather can only be one of three states, either sunny, cloudy, or rainy. For 100 days, we record the weather and record the transition between each day. Whenever we want to find the probability of the weather being a certain state after a given day, we can just tally the number of transitions of that type and divide the number of days by 100. That's how Marov models work. They help us predict the likelihood of a future state. Pretty useful, right? But what about a hidden Marov model? Well, suppose we can't directly observe the weather. So, we can't really calculate the transition probabilities. The model is hidden from us, but we can observe related phenomena like the number of people with umbrellas on a given day because Rihanna said so. So, using one of many techniques, we can still find ways to calculate the transition probabilities using these related variables. So hidden marov models are pretty cool and there are entire textbooks devoted to how they work. In fact, they can be used not just to classify lyrics but generate them as well. That same pair of researchers published a later paper. You know how during a cipher one MC challenges another with a verse? Then the opponent is supposed to spit back some sick rhymes. They trained an HMM to do this. The results were interesting, but let's just say their digital MC wasn't exactly the second coming of Tupac. Let's take a look at a fresh approach. A group of researchers published a paper just last month called Dope Learning, a computational approach to rap lyrics generation. Legendary. They used an algorithm called Rank SPM, which was partially powered by a deep neural network. And they fed it a data set of all the songs from the top 100 English-speaking rap artists. No idea how Lil Wayne got on that list. So, how does this algorithm work? Well, first they needed to extract features from their rap corpus to feed to their model. And they wanted features that represented three metrics. Rhyming, structural similarity, and semantic similarity. Of those three metrics, the semantic similarity was the one that required the use of a deep recurrent neural network. The neural net did what it does best. It found vector representations of words, lines, and groups of lines. Once the features were calculated, they were input into the rank SVM model. Rank SVM is a support vector machine, by the way, which is just a type of linear classifier. And the SVM eventually learned to predict the next line once it was trained on the input features. They also wanted to find a way to quantify how good their algorithm was compared to human MC's. And so they calculated something called rhyme density, which is the average length of the longest rhyme per word. Using rhyme density as a metric, they found that the algorithms generated lyrics had a 21% higher density than the most rhyme dense human artist on their list named Inspector Deck. Wait, who? Let's write our own rap lyrics generator using a hidden markup model in Python. We only need two dependencies here. Random, which helps generate random numbers, and RE, which helps deal with text formatting. Our highest level method is called test markup. In it, we'll initialize an empty array called raplive. Then add all of our lyrics to the rap library and return the rap generated from the rap library using the stop word that was input by the user. The generated rap will always start with the stop word. Let's take a look at the add to live function. It opens the lyrics file, then constructs an hmm. It iterates through every word and checks its record to see if it's a new word or sequence. If a word or sequence has appeared before, it won't re-record it. Then it changes each count to a percentage value or a transition probability. So once we've constructed our model, we can run the make wrap function. It'll take both the set of lyrics and the start word as the parameters. It'll continuously generate words via the marov next function for up to 50 words. The marov next function either returns a random word if the word is novel or finds a word from the model probabilistically. Let's test this out and see what it generates. I'll start off my rap with homie. Homie Grows Punani likely I'm toteen inspired enough. Basically boy coming period. Damn. So dope. Check out the links down below for more info and please subscribe for more ML videos. For now, I've got to go fix a malformed request. So thanks for watching.

Original Description

This episode of Fresh Machine Learning is about generating rap lyrics! Lyrical generation is possible using either Hidden Markov Models or deep learning. In this episode, I go through a few past examples of what's been done before, then dive into our own example that we can code in Python. Welcome to the machine MC revolution! The demo code for this video can be found here: https://github.com/llSourcell/Rap_Lyric_Generator I created a Slack channel for us, sign up here: https://wizards.herokuapp.com/ Try it out live here: http://deepbeat.org/ I introduce three papers in this video Unsupervised Rhyme Scheme Identification in Hip Hop Lyrics Using Hidden Markov Models: http://link.springer.com/chapter/10.1007%2F978-3-642-39593-2_3 Modeling Hip Hop Challenge-Response Lyrics as Machine Translation: http://www.illc.uva.nl/LaCo/CLS/papers/wu_hiphop_itg.pdf DopeLearning: A Computational Approach to Rap Lyrics Generation: http://arxiv.org/abs/1505.04771 More info about Hidden Markov Models: https://www.youtube.com/watch?v=TPRoLreU9lA https://www.quora.com/What-is-a-simple-explanation-of-the-Hidden-Markov-Model-algorithm http://www.developerstation.org/2011/11/hidden-markov-models-for-dummies.html I love you guys! Thanks for watching my videos, I do it for you. I left my awesome job at Twilio and I'm doing this full time now. I recently created a Patreon page. If you like my videos, feel free to help support my effort here!: https://www.patreon.com/user?ty=h&u=3191693 Much more to come so please subscribe, like, and comment. Follow me: Twitter: https://twitter.com/sirajraval Facebook: https://www.facebook.com/sirajology Instagram: https://www.instagram.com/sirajraval/ Instagram: https://www.instagram.com/sirajraval/ Signup for my newsletter for exciting updates in the field of AI: https://goo.gl/FZzJ5w Hit the Join button above to sign up to become a member of my channel for access to exclusive content! Join my AI community: http://chatgptschool.io/ Sign
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Siraj Raval · Siraj Raval · 27 of 60

1 What is Bitcoin?
What is Bitcoin?
Siraj Raval
2 5 Ways to Use Bitcoin
5 Ways to Use Bitcoin
Siraj Raval
3 BTC Fever - Siraj [Music Video]
BTC Fever - Siraj [Music Video]
Siraj Raval
4 5 Reasons to Build Decentralized Apps
5 Reasons to Build Decentralized Apps
Siraj Raval
5 The Interplanetary File System
The Interplanetary File System
Siraj Raval
6 How to Build a Dapp in 3 min
How to Build a Dapp in 3 min
Siraj Raval
7 Life Before Smartphones
Life Before Smartphones
Siraj Raval
8 4 Ways to Use Smart Contracts
4 Ways to Use Smart Contracts
Siraj Raval
9 3 Dapps You HAVE to See
3 Dapps You HAVE to See
Siraj Raval
10 Char's Life as a BitTorrent Engineer
Char's Life as a BitTorrent Engineer
Siraj Raval
11 4 Reasons AlphaGo is a Huge Deal
4 Reasons AlphaGo is a Huge Deal
Siraj Raval
12 Build a Neural Net in 4 Minutes
Build a Neural Net in 4 Minutes
Siraj Raval
13 Sentiment Analysis in 4 Minutes
Sentiment Analysis in 4 Minutes
Siraj Raval
14 The Hackathon Life
The Hackathon Life
Siraj Raval
15 Your First ML App - Machine Learning for Hackers #1
Your First ML App - Machine Learning for Hackers #1
Siraj Raval
16 Build an AI Composer - Machine Learning for Hackers #2
Build an AI Composer - Machine Learning for Hackers #2
Siraj Raval
17 Build a Game AI - Machine Learning for Hackers #3
Build a Game AI - Machine Learning for Hackers #3
Siraj Raval
18 Build a Movie Recommender - Machine Learning for Hackers #4
Build a Movie Recommender - Machine Learning for Hackers #4
Siraj Raval
19 Build an AI Artist - Machine Learning for Hackers #5
Build an AI Artist - Machine Learning for Hackers #5
Siraj Raval
20 Build a Chatbot - ML for Hackers #6
Build a Chatbot - ML for Hackers #6
Siraj Raval
21 Build an AI Reader - Machine Learning for Hackers #7
Build an AI Reader - Machine Learning for Hackers #7
Siraj Raval
22 Build an AI Writer - Machine Learning for Hackers #8
Build an AI Writer - Machine Learning for Hackers #8
Siraj Raval
23 Build a Chatbot w/ an API - ML for Hackers #9
Build a Chatbot w/ an API - ML for Hackers #9
Siraj Raval
24 One-Shot Learning - Fresh Machine Learning #1
One-Shot Learning - Fresh Machine Learning #1
Siraj Raval
25 Generative Adversarial Nets - Fresh Machine Learning #2
Generative Adversarial Nets - Fresh Machine Learning #2
Siraj Raval
26 Tone Analysis - Fresh Machine Learning #3
Tone Analysis - Fresh Machine Learning #3
Siraj Raval
Generate Rap Lyrics - Fresh Machine Learning #4
Generate Rap Lyrics - Fresh Machine Learning #4
Siraj Raval
28 Build an Autoencoder in 5 Min - Fresh Machine Learning #5
Build an Autoencoder in 5 Min - Fresh Machine Learning #5
Siraj Raval
29 Build a Self Driving Car in 5 Min - Fresh Machine Learning #6
Build a Self Driving Car in 5 Min - Fresh Machine Learning #6
Siraj Raval
30 Build an Antivirus in 5 Min - Fresh Machine Learning #7
Build an Antivirus in 5 Min - Fresh Machine Learning #7
Siraj Raval
31 TensorFlow in 5 Minutes (tutorial)
TensorFlow in 5 Minutes (tutorial)
Siraj Raval
32 Build a Recurrent Neural Net in 5 Min
Build a Recurrent Neural Net in 5 Min
Siraj Raval
33 Build a Simulation in 5 Min
Build a Simulation in 5 Min
Siraj Raval
34 Build a TensorFlow Image Classifier in 5 Min
Build a TensorFlow Image Classifier in 5 Min
Siraj Raval
35 Tensorboard Explained in 5 Min
Tensorboard Explained in 5 Min
Siraj Raval
36 Generate Music in TensorFlow
Generate Music in TensorFlow
Siraj Raval
37 Build a Game Bot (LIVE)
Build a Game Bot (LIVE)
Siraj Raval
38 Deep Learning Frameworks Compared
Deep Learning Frameworks Compared
Siraj Raval
39 Introduction - Learn Python for Data Science #1
Introduction - Learn Python for Data Science #1
Siraj Raval
40 Build a Neural Network (LIVE)
Build a Neural Network (LIVE)
Siraj Raval
41 Twitter Sentiment Analysis - Learn Python for Data Science #2
Twitter Sentiment Analysis - Learn Python for Data Science #2
Siraj Raval
42 Recommendation Systems - Learn Python for Data Science #3
Recommendation Systems - Learn Python for Data Science #3
Siraj Raval
43 Predicting Stock Prices - Learn Python for Data Science #4
Predicting Stock Prices - Learn Python for Data Science #4
Siraj Raval
44 Pong Neural Network (LIVE)
Pong Neural Network (LIVE)
Siraj Raval
45 Deep Dream in TensorFlow - Learn Python for Data Science #5
Deep Dream in TensorFlow - Learn Python for Data Science #5
Siraj Raval
46 Visualizing Data with D3.js (LIVE)
Visualizing Data with D3.js (LIVE)
Siraj Raval
47 Genetic Algorithms - Learn Python for Data Science #6
Genetic Algorithms - Learn Python for Data Science #6
Siraj Raval
48 Enter Siraj [Music Video]
Enter Siraj [Music Video]
Siraj Raval
49 Build a Web Scraper (LIVE)
Build a Web Scraper (LIVE)
Siraj Raval
50 Why is P vs NP Important?
Why is P vs NP Important?
Siraj Raval
51 How to Make a Neural Network (LIVE)
How to Make a Neural Network (LIVE)
Siraj Raval
52 How to Make an Amazing Tensorflow Chatbot Easily
How to Make an Amazing Tensorflow Chatbot Easily
Siraj Raval
53 How to Make an Amazing Video Game Bot Easily
How to Make an Amazing Video Game Bot Easily
Siraj Raval
54 How to Make a Tensorflow Neural Network (LIVE)
How to Make a Tensorflow Neural Network (LIVE)
Siraj Raval
55 How to Make a Simple Tensorflow Speech Recognizer
How to Make a Simple Tensorflow Speech Recognizer
Siraj Raval
56 Joel Shor - Really Quick Questions with an Awesome Google Engineer
Joel Shor - Really Quick Questions with an Awesome Google Engineer
Siraj Raval
57 How to Make a Path Planning Algorithm Easily (LIVE)
How to Make a Path Planning Algorithm Easily (LIVE)
Siraj Raval
58 The Best Way to Prepare a Dataset Easily
The Best Way to Prepare a Dataset Easily
Siraj Raval
59 Catherine Olsson - Really Quick Questions with an OpenAI Engineer
Catherine Olsson - Really Quick Questions with an OpenAI Engineer
Siraj Raval
60 How to Make a Tic Tac Toe Neural Network Easily (LIVE)
How to Make a Tic Tac Toe Neural Network Easily (LIVE)
Siraj Raval

Related Reads

📰
Why Data Structures Still Matter When You're Doing Machine Learning
Learn why data structures are crucial for machine learning performance and efficiency, beyond just interview prep
Dev.to · Ardhansu Das
📰
Stop Feeding FX Bots Price Data Only: Add a Macro Risk Gate in Python
Learn to add a macro risk gate to your FX bots in Python to avoid trading during high-risk events
Dev.to · Robert Tidball
📰
Human-in-the-Loop: Di Titik Mana Otomatisasi Harus Berhenti
Learn when to limit automation in machine learning systems to avoid risks, and why human-in-the-loop is crucial
Medium · Machine Learning
📰
Three Python Concepts That Completely Changed How I Think About Programming
Discover three Python concepts that transformed the author's programming approach and learn how to apply them to improve your own coding skills
Medium · AI
Up next
Dropout in Deep Learning
AnuTech-CH
Watch →