9.12 Content-based Filtering| TensorFlow implementation of content-based filtering -[ML |Andrew Ng]
 In the practice lab, you'll see how to implement content-based filtering in TensorFlow. What I'd like to do in this video is just step through with you a few of the key concepts in the code that you get to play with. Let's take a look. Recall that our code has started with a user network as well as a movie network. And the way you can implement this in TensorFlow is very similar to how we had previously implemented a neural network with a set of dense layers. We're going to use a sequential model. We then, in this example, have two dense layers with the number of hidden units specified here. And then the final layer has 32 units and outputs 32 numbers. Then for the movie network, I'm going to call it the item network because the movies are the items here. This is what the code looks like. Once again, we have a couple of dense hidden layers followed by this layer, which outputs 32 numbers. And for the hidden layers, we'll use our default choice of activation function, which is the ReLU activation function. Next, we need to tell TensorFlow carers how to feed the user features or the item features, that is the movie features, to the two neural networks. This is the syntax for doing so. That extracts out the input features for the user and then feeds it to the user and then we had to find up here to compute VU, the vector for the user. And then one additional step that turns out to make this algorithm work a bit better is add this line here, which normalizes the vector VU to have length one. So this normalizes the length, also called the L2 norm, but basically the length of the vector VU to be equal to one. And then we do the same thing for the item network, for the movie network. This extracts out the item features and feeds it to the item neural network that we define up there. And this computes the movie vector VM. And then finally, this step also normalizes that vector to have length one. After having computed VU and VM, we then have to take the dot product between these two vectors. And this is the syntax for doing so. Carers has a special layer type. Notice we had here TF, carers layers dense. Here this is TF, carers layers dot. It turns out that there's a special carers layer that just takes a dot product between two numbers. And so we're going to use that to take the dot product between the vectors VU and VM. And this gives the output of the neural network. This gives the final prediction. Finally to tell Carers what are the inputs and outputs of the model, this line tells it that the overall model is a model with inputs being the user features and movie or the item features and the output is this output that we just defined up above. And the cost function that we use to train this model is going to be the mean squared error cost function. So these are the key code snippets for implementing content based filtering as a neural network. And you see the rest of the code in the practice lab. But hopefully you'll be able to play with that and see how all these code snippets fit together into a working TensorFlow implementation of a content based filtering algorithm. It turns out that there's one other step that I didn't talk about previously, but if you do this, which is normalize the length of the vector VU, that makes the algorithm work a bit better. And so TensorFlow has this L2 normalize function that normalizes the vector. It's also called normalizing the L2 norm of the vector, hence the name of the function. And so that's it. Thanks for sticking with me through all this material on recommender systems. It's an exciting technology and I hope you enjoy playing with these ideas in code in the practice lab for this week. And so that takes us to the last of these videos on recommender systems and to the end of the next to final week for this specialization. I look forward to seeing you next week as well. We'll talk about the exciting technology of reinforcement learning. Hope you have fun with the quizzes and with the practice labs and I look forward to seeing you next week.
[{"start": 0.0, "end": 7.28, "text": " In the practice lab, you'll see how to implement content-based filtering in TensorFlow."}, {"start": 7.28, "end": 11.94, "text": " What I'd like to do in this video is just step through with you a few of the key concepts"}, {"start": 11.94, "end": 14.42, "text": " in the code that you get to play with."}, {"start": 14.42, "end": 15.42, "text": " Let's take a look."}, {"start": 15.42, "end": 23.02, "text": " Recall that our code has started with a user network as well as a movie network."}, {"start": 23.02, "end": 29.86, "text": " And the way you can implement this in TensorFlow is very similar to how we had previously implemented"}, {"start": 29.86, "end": 34.44, "text": " a neural network with a set of dense layers."}, {"start": 34.44, "end": 36.519999999999996, "text": " We're going to use a sequential model."}, {"start": 36.519999999999996, "end": 41.36, "text": " We then, in this example, have two dense layers with the number of hidden units specified"}, {"start": 41.36, "end": 42.36, "text": " here."}, {"start": 42.36, "end": 47.44, "text": " And then the final layer has 32 units and outputs 32 numbers."}, {"start": 47.44, "end": 52.64, "text": " Then for the movie network, I'm going to call it the item network because the movies are"}, {"start": 52.64, "end": 54.019999999999996, "text": " the items here."}, {"start": 54.019999999999996, "end": 55.84, "text": " This is what the code looks like."}, {"start": 55.84, "end": 62.440000000000005, "text": " Once again, we have a couple of dense hidden layers followed by this layer, which outputs"}, {"start": 62.440000000000005, "end": 63.440000000000005, "text": " 32 numbers."}, {"start": 63.440000000000005, "end": 69.84, "text": " And for the hidden layers, we'll use our default choice of activation function, which is the"}, {"start": 69.84, "end": 72.60000000000001, "text": " ReLU activation function."}, {"start": 72.60000000000001, "end": 80.68, "text": " Next, we need to tell TensorFlow carers how to feed the user features or the item features,"}, {"start": 80.68, "end": 84.32000000000001, "text": " that is the movie features, to the two neural networks."}, {"start": 84.32, "end": 86.55999999999999, "text": " This is the syntax for doing so."}, {"start": 86.55999999999999, "end": 94.0, "text": " That extracts out the input features for the user and then feeds it to the user and then"}, {"start": 94.0, "end": 99.6, "text": " we had to find up here to compute VU, the vector for the user."}, {"start": 99.6, "end": 103.88, "text": " And then one additional step that turns out to make this algorithm work a bit better is"}, {"start": 103.88, "end": 109.72, "text": " add this line here, which normalizes the vector VU to have length one."}, {"start": 109.72, "end": 114.96, "text": " So this normalizes the length, also called the L2 norm, but basically the length of the"}, {"start": 114.96, "end": 117.88, "text": " vector VU to be equal to one."}, {"start": 117.88, "end": 122.48, "text": " And then we do the same thing for the item network, for the movie network."}, {"start": 122.48, "end": 129.82, "text": " This extracts out the item features and feeds it to the item neural network that we define"}, {"start": 129.82, "end": 131.1, "text": " up there."}, {"start": 131.1, "end": 136.32, "text": " And this computes the movie vector VM."}, {"start": 136.32, "end": 142.12, "text": " And then finally, this step also normalizes that vector to have length one."}, {"start": 142.12, "end": 149.72, "text": " After having computed VU and VM, we then have to take the dot product between these two"}, {"start": 149.72, "end": 150.72, "text": " vectors."}, {"start": 150.72, "end": 153.48, "text": " And this is the syntax for doing so."}, {"start": 153.48, "end": 156.92, "text": " Carers has a special layer type."}, {"start": 156.92, "end": 160.88, "text": " Notice we had here TF, carers layers dense."}, {"start": 160.88, "end": 163.98, "text": " Here this is TF, carers layers dot."}, {"start": 163.98, "end": 168.16, "text": " It turns out that there's a special carers layer that just takes a dot product between"}, {"start": 168.16, "end": 169.6, "text": " two numbers."}, {"start": 169.6, "end": 176.51999999999998, "text": " And so we're going to use that to take the dot product between the vectors VU and VM."}, {"start": 176.51999999999998, "end": 180.1, "text": " And this gives the output of the neural network."}, {"start": 180.1, "end": 183.44, "text": " This gives the final prediction."}, {"start": 183.44, "end": 188.72, "text": " Finally to tell Carers what are the inputs and outputs of the model, this line tells"}, {"start": 188.72, "end": 195.8, "text": " it that the overall model is a model with inputs being the user features and movie or"}, {"start": 195.8, "end": 201.72, "text": " the item features and the output is this output that we just defined up above."}, {"start": 201.72, "end": 207.12, "text": " And the cost function that we use to train this model is going to be the mean squared"}, {"start": 207.12, "end": 208.96, "text": " error cost function."}, {"start": 208.96, "end": 215.88, "text": " So these are the key code snippets for implementing content based filtering as a neural network."}, {"start": 215.88, "end": 220.24, "text": " And you see the rest of the code in the practice lab."}, {"start": 220.24, "end": 225.51999999999998, "text": " But hopefully you'll be able to play with that and see how all these code snippets fit"}, {"start": 225.51999999999998, "end": 231.48, "text": " together into a working TensorFlow implementation of a content based filtering algorithm."}, {"start": 231.48, "end": 235.16, "text": " It turns out that there's one other step that I didn't talk about previously, but if you"}, {"start": 235.16, "end": 240.94, "text": " do this, which is normalize the length of the vector VU, that makes the algorithm work"}, {"start": 240.94, "end": 242.26, "text": " a bit better."}, {"start": 242.26, "end": 248.95999999999998, "text": " And so TensorFlow has this L2 normalize function that normalizes the vector."}, {"start": 248.95999999999998, "end": 254.0, "text": " It's also called normalizing the L2 norm of the vector, hence the name of the function."}, {"start": 254.0, "end": 255.6, "text": " And so that's it."}, {"start": 255.6, "end": 260.28, "text": " Thanks for sticking with me through all this material on recommender systems."}, {"start": 260.28, "end": 265.08, "text": " It's an exciting technology and I hope you enjoy playing with these ideas in code in"}, {"start": 265.08, "end": 267.59999999999997, "text": " the practice lab for this week."}, {"start": 267.6, "end": 272.8, "text": " And so that takes us to the last of these videos on recommender systems and to the end"}, {"start": 272.8, "end": 277.28000000000003, "text": " of the next to final week for this specialization."}, {"start": 277.28000000000003, "end": 279.96000000000004, "text": " I look forward to seeing you next week as well."}, {"start": 279.96000000000004, "end": 283.72, "text": " We'll talk about the exciting technology of reinforcement learning."}, {"start": 283.72, "end": 287.24, "text": " Hope you have fun with the quizzes and with the practice labs and I look forward to seeing"}, {"start": 287.24, "end": 297.92, "text": " you next week."}]