Restricted Boltzmann Machine

Kirill Eremenko
A free video tutorial from Kirill Eremenko
Data Scientist
4.5 instructor rating • 46 courses • 1,890,600 students

Learn more from the full course

Deep Learning A-Z™: Hands-On Artificial Neural Networks

Learn to create Deep Learning Algorithms in Python from two Machine Learning & Data Science experts. Templates included.

22:15:27 of on-demand video • Updated September 2021

  • Understand the intuition behind Artificial Neural Networks
  • Apply Artificial Neural Networks in practice
  • Understand the intuition behind Convolutional Neural Networks
  • Apply Convolutional Neural Networks in practice
  • Understand the intuition behind Recurrent Neural Networks
  • Apply Recurrent Neural Networks in practice
  • Understand the intuition behind Self-Organizing Maps
  • Apply Self-Organizing Maps in practice
  • Understand the intuition behind Boltzmann Machines
  • Apply Boltzmann Machines in practice
  • Understand the intuition behind AutoEncoders
  • Apply AutoEncoders in practice
English Instructor: Hello and welcome back to the course on deep learning. In today's tutorial we're going to talk about the restricted Boltzmann machine and we're going to see how it learns, and how it is applied in practice. Gonna be a very interesting tutorial, let's get started. So here we've got the standard Boltzmann machine or the full Boltzmann machine where as you remember, we've got all of these intra connections. Every single node connects to every single other node and while in theory this is a great model and it's probably you can solve lots of different problems, in practice it's very hard to implement in fact, at some point we'll run into a roadblock because we cannot, simply cannot compute a full Boltzmann machine and the reason for that is as you increase number of nodes, the number of connections between them grows exponentially. So therefore, a different type of architecture was proposed which is called the restricted Boltzmann machine and this is what it looks like. So here we've got exactly the same concept with the simple restriction that hidden nodes cannot connect to each other and visible nodes cannot connect to each other. Other than that, everything's the same. We've got connections which are undirected meaning that they happen in both ways both from visible nodes to hidden nodes and from hidden nodes to visible nodes. And that's the architecture of the restricted Boltzmann machine. And now we're going to talk about how it is, how it works, how it's trained and then how it's applied in practice. So let's get straight into it. We're going to look at an example with movies because you can use a restricted Boltzmann machine to build a recommender system and that's exactly what you're going to be doing in the practical tutorials we've had learned. And this is going to help us build an intuitive understanding of the restricted Boltzmann machine and also it's going to help you when you're walking through the practical tutorials. So let's say our restricted Boltzmann machine is going or our recommender system is going to be working on six movies. Of course, in reality, there's going to be lots and lots more movies as you'll see in the practical tutorials. There'll be many more movies but in our example, we're just going to work with six for simplicity's sake and the way it's going to work is that we're going to, well let's rewind a little bit. As you remember, a Boltzmann machine is a generative type of model so it always constantly generates or is capable of generating these states, these different states of our system and then in training through feeding it training data and through a process called contrastive divergence which we'll discuss further down in this section. We help the Boltzmann machine to become very, become a representation of our specific system rather being a recommender system for any kind of possible impossible movies or any kind of recommender possible impossible recommender system. We make it become more and more like the recommender system that is associated with our specific set of movies that we are feeding into this system and with our specific training data. And so through that process, what this restricted Boltzmann machine is going to learn is it's going to understand how to allocate its hidden nodes to certain features. And this process is very very similar to what we discussed in the convolutionary neural networks. So for example, through the training process, the restricted Boltzmann machine might identify that genres are, genres of movies are important features for instance, genre A, B, C, D and E and the important thing to understand here is that it doesn't know that these are genres, it's just identifying certain features. We'll talk about this just in a second. Let's just, to start off with, to get us more comfortable with this concept, well let's kind of make it obvious that it doesn't have to be genres, for example, it could identify that genre A and B are important for the recommender system but then other important features include an actor, maybe Kevin Costner, an award maybe an Oscar, a director, Robert Zemeckis. So, it will identify that these are important features and so what does that mean? Right? You're probably, right now the main question that you might have in your head right now is, what, what does that even mean when it's identified that a feature is important? Well let's go through this, during the training process, we're feeding in lots and lots of rows to the restricted Boltzmann machine and for example, these rows could look something like this where we've got movies as columns and then the users as rows. And here we've got the ratings or the feedback that each user has left for the movie whether they liked it, that's a one or they didn't like it, a zero and also the empty cells are totally fine as well because that just means that person hasn't watched that movie. And, through this process as we're feeding in this data to this restricted Boltzmann machine what it is able to do is it's able to understand better our system and it is better to adjust itself to be a better representation of our system, and understand and reflect better reflect all of the intra connectivity that is, that might be present here because ultimately, people have biases, people have preferences, people have tastes and that is what is reflected in the datas. If somebody liked Movie two and three and didn't like Movie one just means that that's what's their preferences. Somebody else might have liked movie you one and might have not liked Movie two and might have liked that Movie three. So basically the data is talking about the preferences of people, their tastes and their, how they prefer to view movies or how they're biased towards different movies and that's what the restricted Boltzmann machine is trying to explain. And for instance it can or not explaining, that's what it's trying to model. And for instance, it could pick up from our example here that Movies three, four and six have very, usually have similar ratings. Not all the time but very often when somebody likes Movie three, four, they will probably like Movie six or when somebody likes Movie six and four or six and three, they'll probably like Movie four. Six and three, they'll like Movie four or if they don't like Movie three and four, they're unlikely to like Movie six. It's not always, so here we've got an example of somebody didn't like Movie three, didn't like Movie four, they can be examples where it doesn't follow that rule but it's those are going to be kind of more of an exception from the rule rather than a common. And this is just a very simplified example. But then what the restricted Boltzmann machine would do, it would identify this in the training and it would assign a node to look out for that feature. And even without knowing what that feature is because as you can see all the input it's getting are ones and zeros, it's not getting the genre of the movies, it's not getting the list of actors, it's not getting the awards that the movie won, won. It's only getting just these ones and zeros. But even from these similarities, it can establish that there probably is some feature that these movies have in common that is making people like them. So people who like these movies like that, not just they like that movie, they like that feature and therefore any other movie with that feature, will, is more, is highly likely to be enjoyed by those people and in our understanding, as humans that feature might be genre. And this is again, this is very similar to what we had with convolutional neural networks. We might not have a descriptive term for that feature but just for simplicity's sake we're gonna say that it's Genre A or it could be Actor X and that way it'll be easier for us and to understand what's going on. But that's in essence what the restricted Boltzmann machine is doing through this input it is, and through the training process it is better and better understanding what's features these movies might have in common or if they are features that these movies might have in common and it's assigning its hidden nodes or the weights are being assigned in such a way that the hidden nodes are becoming reflective of those specific features. So that's how the training of the RBM happens. Now let's have a look at something more fun. Let's have a look at how this would play out in action. So now that we've trained up our machine, our restricted Boltzmann machine. We know that it is able to pick out these certain features and based on what it's previously seen about thousands of our users and their ratings and now we're going to look at specific features so let's say we're, it's picked out drama as a feature, action DiCaprio, Leonardo DiCaprio as the actor in a movie, Oscar, whether or not the movie has won an Oscar and Quentin Tarantino, whether or not he was a director of the movie. And again these are just for our benefit. In reality, the restricted Boltzmann machine has no idea whether (laughs) the director's name is Tarantino or not. It's just picking out a feature. This is our explanation of that feature for intuitive purposes and now we're going to look at a couple of movies. So the machine is trained up on lots and lots of rows and now we're going to input a new row into this restricted Boltzmann machine into this recommender system and we're going to see how it's going to go about giving us the prediction whether or not a person will like certain movies. This is the fun part. This is the actual application of the RBM. So let's start. We've got movies The Matrix, the Fight Club, Forrest Gump, Pulp Fiction, Titanic and The Departed. And I tried to pick movies which are quite commonly seen, so hopefully you've seen all of these or at least most of these movies, if not it doesn't really matter, it will still go through there. You'll still be able to follow along with the examples totally fine. The Oscar here represents whether or not a movie won an Oscar just so that we, there's no questions about that. And the Oscar here we're talking about is the Best Picture Oscar. So an Oscar is an Academy Award and there's lots of different Academy Awards, for instance, they can, that is pretty much synonymous terms is done with lots of different types of Oscars. You could get an Oscar for being the best actor, you could get an Oscar for the best sound effects in your movie or the best visual effects. Well, this specific Oscar we're talking about is the Best Picture and there's only one of those per year. Yeah, so these the movies that we're looking at. And now let's see this person that we're trying to make a recommendation for, what have they seen, what they haven't seen, what they've rated and how they've rated it. So they've seen The Matrix, they didn't like The matrix, they put a zero, so one is like, zero is dislike. Fight Club, they haven't seen the Fight Club. Forrest Gump, they've seen Forrest Gump and they like the movie. Pulp Fiction, they've seen Pulp Fiction but they didn't like the movie. Titanic they've seen and they've liked it and The Departed, they haven't seen that movie and now we want to make a recommendation for this person, will they like Fight Club or not? will they like The Departed or not? So how does the restricted Boltzmann machine go about this now. Now we're finally getting to the to the essence, we're finally getting to the applications, so this is gonna be, it's gonna be interesting. All right, so we're gonna go through this step by step and we're going to assess which of these nodes are going to activate for this specific user. So the Boltzmann machine is trained up, it already knows about features and similarities. Now it's going to try to assess which of these features are going to activate and think very, it could be useful to think of it as in the convolutional neural network analogy. In there, we would feed in a picture into our convolutional neural network and it would, certain features would highlight. Certain features would light up if they're present in that picture. Same thing here we're feeding in a row into our restricted Boltzmann machine and certain features are going to light up if they are present in this user's tastes and preferences and likes and biases. That's the kind of very intuitive, what's happening in the background, that's very intuitive explanation of what's happening in the background. So let's go through this, I'm gonna go with so we're gonna start with Drama. So in terms of Drama, which movies here are Drama? We know that Matrix is not Drama, Fight Club is not Drama, Forrest Gump is Drama. It's actually, I looked it up, it's actually comedy and then it's Drama. We don't have comedy here. So it's for all in our purposes it's Drama. Pulp Fiction is not Drama. Titanic is Drama and The Departed is Drama, but we don't have data for The Departed, right? So this Boltzmann machine can only learn from these two. Right, it can only say, all right so this person liked Forest Gump and this person liked the Titanic and based on that this node is gonna light up and it's going to, we're gonna light it up symbolically in green meaning that it's activated and it's, that means this person likes Drama, Drama movies. Next, Action and you can see that the Action movies we have here are The Matrix, Fight Club and Pulp Fiction and Departed. We have four Action movies but out of them we only have data for The Matrix and Pulp Fiction and both of these, this person didn't like. So it's gonna light up in red. DiCaprio. So out of all of these movies, Leonardo DiCaprio is present in Titanic and The Departed and based on this, just this one, that one movie the DiCaprio node is going to light up green. Oscar. So we've got three Oscar movies. We only have data for Forrest Gump and Titanic and based on those, that person liked both. The node is gonna just light up green. And finally Tarantino the only movie with Tarantino as the director here is Pulp Fiction, out of all of them and that person did not like Tarantino that movie and therefore this node is gonna light up red. So there we go, that's the first pass. Everything from our visible nodes goes into our hidden nodes and our hidden nodes now we know which ones are activated. And now, the backward pass happens. Now what happens is the Boltzmann machine is going to try to reconstruct our input. It's going to, I'm gonna show this by flashing them. So basically that's exactly what happens in the process whether you're training and we didn't mention this during a training process, and, but this is what happens during training as well. So during training and during this is and is in essence a test. What the Boltzmann machine does is it accept values into the hidden nodes and then it tries to reconstruct your inputs based on those hidden nodes if during training if the reconstruction is incorrect then everything is adjusted the weights are adjusted and then we reconstruct again and again again but now it's a test so we're actually inputting a certain row and we want to get our predictions. So basically, there is not gonna be any adjusting of weights. We're just going to see how the Boltzmann machine basically reconstructs these rows. And moreover, we're not going to care about the movies that we already have ratings for, that's what the training part of the Boltzmann machine is for. Here we're only going to care about the movies where we don't have ratings and we're gonna use the values that reconstructs as predictions. So once again from here Boltzmann machine is going to be reconstructing these input values based on what it's learned. And so let's let's go. How is it going to reconstruct Fight Club? Well, Fight Club is going to look at all of the nodes and find out based on what it learned from the training it's going to really know which nodes actually connect to Fight Club. Is it a Drama movie? No, it's not. Is it an Action movie? Yes, it is. So that's not always going to light up. Is it, does it have DiCaprio in it? No, it doesn't. Did this movie win an Oscar? It hasn't. And is Tarantino director of this movie? No, he's not. That's in our understanding because we know these things. In the Boltzmann machine's understanding it will be like, does this, is this node connected to this node? No. Is this node connected to this node? Yes. Is this node connected to this node? No. This node to this no. This to this, no. So it wouldn't know these words but it would know these connections, it would know these associations based on the weights that it had determined during training and based on this one connection, we know this one lit up in red and therefore Fight Club is going to be a movie that this person is not going to like. Then next one. So now we're going to talk about The Departed. So the recommendation here is no. Now let's talk about The Departed. Again it's gonna go through its nodes, it's gonna know the connections. Right? Just by the weights from which should had established during training is going to know these connections and it will know here that The Departed is connected to this node, is connected to these nodes, connected to this node, connected this node, it's not connected to this node. The weight here is low or very insignificant and in our terms in human language why is that? Well because this node is responsible for Drama movies, it's a Drama movie. This node is responsible for Action movies, it's an Action movie. This node is responsible for DiCaprio movies, it does have DiCaprio in it. This movie is now is responsible for Oscar movies, it does have, it did have an Oscar, did win an Oscar and therefore based on this, we can see this node votes yes, yes, yes, this no, votes no so the answer in simplistic terms is, yes, you are going to most likely enjoy that movie or that user is going to enjoy that movie. So there we go, that's how the restricted Boltzmann machine works. I hope you enjoyed this breakdown of the training and the application of the RBM and I can't wait to see you in the next tutorial. Until then, enjoy deep learning.