Build an AI Composer - Machine Learning for Hackers #2
Key Takeaways
The video demonstrates how to build an AI composer using TensorFlow and Python, training a neural network to compose British folk music in just 10 lines of code. The process involves collecting a dataset of folk songs, building and training a model, and testing the model to generate new songs.
Full Transcript
[Music] I actually didn't play anything you just heard AI generated music hello world welcome to rology in this episode we're going to train a neural network to compose music all by itself machine generated music the technical term for this is music language modeling and it has a long history of research behind it marov models and restricted boltzman machines which kind of sounds like something out of halflife or Bioshock hold on babe I've got to go save the world using the restricted Bolton Machine music is how we communicate our emotions and Passions and it's completely based on mathematical relationships octaves chords scales Keys all of it is math at the lowest level music is a series of sound waves that create pockets of air pressure and the pitch we hear depends on the frequency of changes in this air pressure sheet music is The annotation we've created to help us map these sounds into a repeatable set of instructions so if machine learning is all about feeding data into models Define patterns and make predictions could we use it to feed in music data to predict new songs absolutely we're going to build an app that learns how to compose British folk music by training on a British folk data set I was going to go with American but I didn't think it'd be age appropriate there's too much sax and violins get it we'll be using tensorflow the sickest machine learning library ever to do this in just 10 lines of python we're going to follow our tried and true four-step machine learning methodology to do this collect the data set build a model train the model and test the model to start off we want to collect our data set so let's import the URL live module which is going to let us download the file from the web once we import it we can call the URL retrieve method to do just that we'll set the parameters to a link in the data dat set and the name will call the downloaded file we're using the Nottingham data set for this demo which is a collection of a thousand British folk songs in MIDI format midi format is perfect for us since it encodes all the note and time information exactly how it would be written in music annotation it comes in a zip file we want to unzip it as well we can do this programmatically using the zip file module we'll extract the data from the zip and place it in the data directory Okay so we've got our data it's time to create the model but before we do that we need to think about how we want to represent our input data there are two things happening there's the main tune or Melody and then there the supporting notes are harmony let's represent each as a vector and to make things easier we'll make two assumptions the first is that the melody is monophonic that means only one note is played at each time step the second is that the harmony at each time step can be classified into a chord class so that's two different vectors one for Melody and one for harmony we'll then combine them into one big vector and use that as our input we can just import our ml helper class and then call the create model method to do this music plays out over a period of time it's a sequence of notes so we need to use a sequence learning model it has to accept a sequence of notes as an input and output a new sequence of notes plain old neuron Nets can't do this they accept fixed size inputs like an image or a number we need a special kind of neural network a recurrent neural network those can deal with sequences since data doesn't just flow one way it Loops this allows the network to have a kind of short-term memory unlike Donald Trump but wait we want our Network to not just remember the most recent music it's heard but all the music it's heard like a piece of music can have multiple themes in different parts of it hopeful sad cheery and if Network remembers only the most recent part which was cheery it's just going to compose cheery stuff we need a special type of recurrent neural network called a long shortterm memory Network this type of network can remember things from way back in the sequence of data and it uses everything it remembers to generate new sequences our model will generate the sequences and chord mapping file to a file in the data folder this is a serialized by stream representation of our music that we can input directly into our model to train by the way every machine learning model has a set of water called hyper parameters these are the parameters that we human set for how our model operates like knobs on a control panel how many layers do we want how many iterations for training how many neurons you can just use an existing model with pre-tuned hyperparameters to build something awesome so now we're ready to train our model we can just call the train model method of our neuronet class to do this this will get the network to start collecting the input data piece by piece it took me about 2 hours to train this on my 2013 MacBook Pro but you don't have to wait until it's completely done to training to test it out just wait until you see the best law so far encountered saving model message once you see that you can type in RNN sample into terminal with the config file flag and point it to the newly generated config file in your model's folder that will generate a new song using the newly trained model you've just created to generate music we just sample the melody and Harmony at each time step and plug it into our trained model the model will then predict what the next notes will be the collection of all the predicted notes is our newly generated song there's some improvements that could be made for sure the time signature is is kind of sporadic and in terms of long-term structure there seems to be a lack of repeated themes and phrases the solution may well be more data and more computing power it usually is when it comes to machine learning with deep neuron Nets machine learning can help us learn the fundamental nature of how Music Works in ways that we haven't even thought about links with more info below check them out and please subscribe for more machine learning videos for now I've got to go fix a runtime error so thanks for watching
Original Description
This video will get you up and running with your first AI composer in just 10 lines of Python. The app can compose british folk songs after training on an existing folk dataset.
The code for this video is here:
https://github.com/llSourcell/AI_Composer
I created a Slack channel for us, sign up here:
https://wizards.herokuapp.com/
This is 'a' way to generate music, it's not necessarily the absolute best way. Another attempt I really like is this one since it can generate not just monophonic music, but polyphonic music as well:
http://www.hexahedria.com/2015/08/03/composing-music-with-recurrent-neural-networks/
Tensorflow install instructions here:
https://www.tensorflow.org/versions/r0.8/get_started/os_setup.html#pip-installation
In a future video, I'll discuss how to easily use cloud GPU computing. Likely using www.fomoro.com
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 up for my AI Sports betting Bot, WagerGPT! (500 spots available): https://www.wagergpt.xyz
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Siraj Raval · Siraj Raval · 16 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
▶
17
18
19
20
21
22
23
24
25
26
27
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 AI Lessons
⚡
⚡
⚡
⚡
Want to get started with deep learning
Reddit r/deeplearning
Building a Deepfake Detector From Scratch — What Nobody Tells You
Medium · Deep Learning
Unfolding the Meandering Path: High-Dimensional Invariance and the Flat 2D Plane of Neural…
Medium · Deep Learning
Implementing Neural Style Transfer from Scratch: The Project That Started It All
Medium · Deep Learning
🎓
Tutor Explanation
DeepCamp AI