Build an Autoencoder in 5 Min - Fresh Machine Learning #5

Siraj Raval · Beginner ·🛠️ AI Tools & Apps ·9y ago

Key Takeaways

Builds an autoencoder in 5 minutes

Full Transcript

is generating novel [Music] data hello world it's SJ and today we're going to learn about a special type of neural network called an autoencoder then we're going to implement our own autoencoder using tensorflow to generate handwritten digits an autoencoder is a simple type of neural network with only three layers it's got an input layer a hidden layer and an output layer just like your mom just kidding what makes an autoencoder special is that the output neurons are directly connected to the input neurons and the goal is to get the output values to match the input values so if I added an image of a dog to the input layer the output layer would then output that same image when we input that image it's a vector in N dimensional space which is sent to the hidden layer after some activation function is applied to it this reduces it to an M dimensional space so there are less Dimensions this process is called dimensionality reduction and it happens in every neural network so we can think of the first layer of the network as the encoder since it's compressing data and the last part as a decoder since it tries to reconstruct the original input from the smaller representations in the hidden layer so when do we use autoencoders all day all day well one use case is data compression kind of like creating a zip file for some data set that you can later unzip another is image search where you search Google using an image as your search query instead of text it's very likely that Google is using autoencoders to help fuel this use case whenever one of Google's Bots is crawling the web and finds an image it'll compress it using an autoencoder that would mean Google would have all of its indexed images compressed in the form of an easily searchable array whenever you search for a new image it'll compress it and find all the points nearest to it in the compression space since there is less noise then rank them according to their similarity there's also the one class classification use case that's when we only have a data set with a single class which is called the target class when we feed it to an autoencoder it'll learn to detect objects of that class when it receives an object that doesn't fit that class category it'll detect it as an anomaly whether it's a deadly virus or fraud attempt system downtime or someone who actually doesn't play Pokémon go that's right autoencoders are for you and if you want to train a deep Network you could use what's called a stacked autoencoder that is a set of autoencoders where the outputs of each layer are wire to the inputs of the successive layer once you train it on some data set you can use those weights to initialize your deep net instead of randomly initialized weights one of the more recent applications of Auto encoders is generating novel yet similar outputs to our puts like faces that look really similar but are different than the input faces for this we use a newer type of autoencoder called a variational auto encoder which learns a distribution around data so it can generate similar but different outputs there are lots of techniques that are used to prevent autoencoders from successfully reconstructing the input image like Den noising where the input is partially corrupted on purpose the idea is that if it can reconstruct an image despite it being corrupted it'll be a more robust decoder so let's build our own simple Auto encoder to learn to detect handwriting digits using tensorflow shall we first we'll import tensorflow the awesome machine learning library then nump the pythonic scientific Computing Library we'll also import our input data which is the collection of handwritten character images then we'll Define our autoencoder hyperparameters we know that each character image is 28x 28 pixels so we'll set the width to 28 then we'll initialize a variable that represents the number of input nodes we also want to have 500 nodes in the hidden layer I generally like to have 2/3 the number of nodes in my hidden layer as my input layer as a starting point one to purposfully corrupt our input data later so that our decoder gets even more robust in its reconstruction over time so let's set our corruption level to. 3 which isn't nearly as high as the US governments once we have these variables we'll use them to help us build nodes we'll start by creating a node for the input data then we'll create a node for the corruption mask which will help us reconstruct the original image we'll then want to create nodes for our hidden variables after we initialize our weights we'll initialize our hidden layer as well as the prime values for each that tie the weights between the encoder decoder and result in an output value after that we Define our model via a function that takes in our variable parameters we'll make sure to get a corrupted version of our input data then create our neural net and compute the sigmoid function to create our hidden State then we'll create our reconstructed input and return that so our model will accept an input and return a reconstructed version of it despite the self-imposed data corruption so we can utilize this function by building a model graph with it which we'll call Z so now that we have our model we need to create a cost function which is what we want to minimize over time the more we minimize it the more accurate our output results will be then we want to create a training algorithm which we'll call train op and use the classic gradient descent algorithm to help train our model which takes the cost function as a parameter so it can continuously minimize when we train it before we start training our model we need to load our data so let's read from our local directory we'll set one hot to True which is a bit widest operation that will make computation faster then initialize the variables for images and labels for both our training and testing data finally we'll begin our training process by initializing a tensorflow session we'll initialize all of our variables first then begin our for Loop which will iterate 100 times for every image and label we will retrieve an input then create a mask using the binomial distribution of our input data and use that as a parameter to run our tensorflow session using the training algorithm we defined earlier we'll calculate a mask for the outer loop as well and print out the results as we go along let's take a look at the results we can see our score gets better and better over time with training and eventually our neural net is able to reconstruct and classify handwritten characters for more information check out the links down below and please subscribe because I'm just getting started for now I've got to go boost some gradients so thanks for watching

Original Description

This video is all about autoencoders! I start off explaining what an autoencoder is and how it works. Then I talk about some use cases for autoencoders and the special types of autoencoders we use for each of them. Finally, I programmatically go through an example of a simple autoencoder, followed by a demo. The code for this video is here: https://github.com/llSourcell/autoencoder_demo/tree/master I created a Slack channel for us, sign up here: https://wizards.herokuapp.com/ Autoencoder live demo in the browser: https://cs.stanford.edu/people/karpathy/convnetjs/demo/autoencoder.html and here are some great links to read up on autoencoders: http://ufldl.stanford.edu/tutorial/unsupervised/Autoencoders/ http://lazyprogrammer.me/a-tutorial-on-autoencoders/ https://blog.keras.io/building-autoencoders-in-keras.html https://www.quora.com/What-are-the-best-resources-for-learning-about-autoencoders-from-scratch 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 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 · 28 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
27 Generate Rap Lyrics - Fresh Machine Learning #4
Generate Rap Lyrics - Fresh Machine Learning #4
Siraj Raval
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

📰
How I use python to save hours every week
Learn how to use Python to automate tasks and save hours every week, with practical steps for beginners and experienced users alike.
Dev.to AI
📰
What Are AI Software Solutions and How Can They Transform Your Business?
Discover how AI software solutions can transform your business by automating tasks, enhancing decision-making, and driving innovation
Dev.to · upwork floating infotech
📰
AI Shorts generators you can actually edit (not a black box)
Learn to identify editable AI video generators and when to use black box solutions
Dev.to · Reel Mint
📰
I Wanted To Automate Website Testing Without Writing Hundreds Of Scripts. AI Changed The Approach.
Learn how AI-powered testing is revolutionizing website testing by shifting from script-based automation to goal-based testing, increasing efficiency and reducing manual effort
Medium · AI
Up next
Microsoft Bot Framework Web Chat Authentication with Microsoft Graph API Call using Auth Token in C#
Dewiride Technologies
Watch →