Generate Rap Lyrics - Fresh Machine Learning #4
Skills:
LLM Foundations70%
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
▶
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
What is Bitcoin?
Siraj Raval
5 Ways to Use Bitcoin
Siraj Raval
BTC Fever - Siraj [Music Video]
Siraj Raval
5 Reasons to Build Decentralized Apps
Siraj Raval
The Interplanetary File System
Siraj Raval
How to Build a Dapp in 3 min
Siraj Raval
Life Before Smartphones
Siraj Raval
4 Ways to Use Smart Contracts
Siraj Raval
3 Dapps You HAVE to See
Siraj Raval
Char's Life as a BitTorrent Engineer
Siraj Raval
4 Reasons AlphaGo is a Huge Deal
Siraj Raval
Build a Neural Net in 4 Minutes
Siraj Raval
Sentiment Analysis in 4 Minutes
Siraj Raval
The Hackathon Life
Siraj Raval
Your First ML App - Machine Learning for Hackers #1
Siraj Raval
Build an AI Composer - Machine Learning for Hackers #2
Siraj Raval
Build a Game AI - Machine Learning for Hackers #3
Siraj Raval
Build a Movie Recommender - Machine Learning for Hackers #4
Siraj Raval
Build an AI Artist - Machine Learning for Hackers #5
Siraj Raval
Build a Chatbot - ML for Hackers #6
Siraj Raval
Build an AI Reader - Machine Learning for Hackers #7
Siraj Raval
Build an AI Writer - Machine Learning for Hackers #8
Siraj Raval
Build a Chatbot w/ an API - ML for Hackers #9
Siraj Raval
One-Shot Learning - Fresh Machine Learning #1
Siraj Raval
Generative Adversarial Nets - Fresh Machine Learning #2
Siraj Raval
Tone Analysis - Fresh Machine Learning #3
Siraj Raval
Generate Rap Lyrics - Fresh Machine Learning #4
Siraj Raval
Build an Autoencoder in 5 Min - Fresh Machine Learning #5
Siraj Raval
Build a Self Driving Car in 5 Min - Fresh Machine Learning #6
Siraj Raval
Build an Antivirus in 5 Min - Fresh Machine Learning #7
Siraj Raval
TensorFlow in 5 Minutes (tutorial)
Siraj Raval
Build a Recurrent Neural Net in 5 Min
Siraj Raval
Build a Simulation in 5 Min
Siraj Raval
Build a TensorFlow Image Classifier in 5 Min
Siraj Raval
Tensorboard Explained in 5 Min
Siraj Raval
Generate Music in TensorFlow
Siraj Raval
Build a Game Bot (LIVE)
Siraj Raval
Deep Learning Frameworks Compared
Siraj Raval
Introduction - Learn Python for Data Science #1
Siraj Raval
Build a Neural Network (LIVE)
Siraj Raval
Twitter Sentiment Analysis - Learn Python for Data Science #2
Siraj Raval
Recommendation Systems - Learn Python for Data Science #3
Siraj Raval
Predicting Stock Prices - Learn Python for Data Science #4
Siraj Raval
Pong Neural Network (LIVE)
Siraj Raval
Deep Dream in TensorFlow - Learn Python for Data Science #5
Siraj Raval
Visualizing Data with D3.js (LIVE)
Siraj Raval
Genetic Algorithms - Learn Python for Data Science #6
Siraj Raval
Enter Siraj [Music Video]
Siraj Raval
Build a Web Scraper (LIVE)
Siraj Raval
Why is P vs NP Important?
Siraj Raval
How to Make a Neural Network (LIVE)
Siraj Raval
How to Make an Amazing Tensorflow Chatbot Easily
Siraj Raval
How to Make an Amazing Video Game Bot Easily
Siraj Raval
How to Make a Tensorflow Neural Network (LIVE)
Siraj Raval
How to Make a Simple Tensorflow Speech Recognizer
Siraj Raval
Joel Shor - Really Quick Questions with an Awesome Google Engineer
Siraj Raval
How to Make a Path Planning Algorithm Easily (LIVE)
Siraj Raval
The Best Way to Prepare a Dataset Easily
Siraj Raval
Catherine Olsson - Really Quick Questions with an OpenAI Engineer
Siraj Raval
How to Make a Tic Tac Toe Neural Network Easily (LIVE)
Siraj Raval
More on: LLM Foundations
View skill →Related Reads
📰
📰
📰
📰
Why Data Structures Still Matter When You're Doing Machine Learning
Dev.to · Ardhansu Das
Stop Feeding FX Bots Price Data Only: Add a Macro Risk Gate in Python
Dev.to · Robert Tidball
Human-in-the-Loop: Di Titik Mana Otomatisasi Harus Berhenti
Medium · Machine Learning
Three Python Concepts That Completely Changed How I Think About Programming
Medium · AI
🎓
Tutor Explanation
DeepCamp AI