Look at these faces. Now imagine we have 10,000 sams and 10,000 lizbits. Who is this? If you have half a brain, you guess right. Let's see how the model does here. I, this is Lizbit. This is Sam. This is also Sam. EZ. You did pretty good model. Good job. EZ. But really, I couldn't get my friends to take 10,000 selfies. It's more like three to four selfies. Now look at this face. Who is this? Again, if you have half a brain, you guess right. Let's see how the model did here though. I, this is Sam. EZ. This is someone outside the data set. EZ. Oh. All right, this is Sam. For sure. Lock it. All right. Okay. I'm out. This is done. This is so dumb. It's dumb. I'm out. I'm out. Am I dumb? Yes, you are. Clearly the model didn't do that well. But what if I only had one example for each of them? You know the drill. Who is this? Ha, but you didn't expect that. But it doesn't matter. You just don't know who it is. You just don't recognize the face. And that's the correct answer. I'm going to save the model from embarrassment and just let you know that it didn't really perform that well. That was hard. There are several key takeaways from these three exercises. Humans learn fast. We only need to see a face once or maybe a couple of times in order to know that we either recognize a face or we just don't. This is the idea behind one shot learning and few shot learning. And the second takeaway is that well machines need a lot of data. Sometimes even two faces with 10,000 training examples isn't enough. The reason for such a discrepancy is prior knowledge. When I showed you the three cases, we went in there with the knowledge of the world. You know how humans look. You know how to tell them apart. You know the different races of humans. You know how to identify humans wearing different pieces of clothing and so on. But a machine is going into this with no prior knowledge. It knows nothing. But if we do give some prior knowledge to our systems, how do you think it would fare? Well, it depends on that prior knowledge. Now prior knowledge can come in many forms, but I'll stick to three types based on a blog post so that it's just consistent. Prior knowledge about similarity prior knowledge about learning and prior knowledge about data. Humans are so knowledgeable that we can make use of all these three before presented with a new task. But in this video, we are going to shift focus only to the first. That is prior knowledge based on similarity. And we can tackle the others maybe in a separate video. But before we continue, this video is sponsored partially by Kite. They provide a code completion service for machine learning code. It integrates super well with your editors and even Jupyter notebooks. So click the link in the description to try Kite for free. Now back to the video. So we are here now looking to train a model to recognize faces. It takes an image and it returns a person's name. Probably it's the result of like a softmax operation. But what role would prior knowledge on similarity play here? The way that we define the model now, there are two major disadvantages. The first is that we need way too many examples to learn the parameters of the model. And two is that, well, if we need the model to recognize a new face, we would need to add a node to the softmax layer to represent this new class. And then, since we modified the network architecture, we would need to train the network again. Now to solve for both of these disadvantages, we transform the problem that the model is solving. Instead of providing an image and telling the network to figure out who it is, we can give the network two images and tell the network to determine if the images are of the same person or of different people. To this model, we can then inject prior knowledge while training. I'll definitely get into this prior shortly, but the point I'm trying to make here is to show you how this new setup overcomes both disadvantages of the traditional approach. The model takes in pairs of images from your data set. So it's really easy to create these pairs from a small set of images, combining them every which way. So we don't need as many training images. Also, let's say that we add a new face to the model that it's never seen before. We no longer need to modify the network architecture. It's just a binary classification problem. Great. So now that we know that this new approach can decrease training data and is scalable, let's get into the details about this model and this prior. Am I getting all this? Now, the model isn't just a single network. It's a parafidentical networks that converge into this node called a similarity function. And it terminates at a sigmoin neuron that outputs if the faces are similar or different. Since we're dealing with a parafidentical networks, this setup is called a Xiaomi's network, because Xiaomi's is twins. In this case, the networks are convolutional neural networks since we're dealing with image inputs. The output of these networks, though, aren't a typical softmax function. They are embeddings. These are basically vectors that form a compressed representation of the image. You'd implement this by using a typical neural network for classification, but then you remove the last softmax layer. Let's say that the output of the embedding of each network is a 64-dimensional vector. Each of these vectors represents the input image. Now, we pass it into the similarity function. This will compute the square difference between the vectors. It will be small if they are similar and this number will be large if they are different. We can convert this to a probability value by squishing it into a sigmoin function. If the output is below a certain threshold, they're different. If above that's a threshold, then they're similar. This function that determines a similarity isn't learned by the network. It is prior knowledge. The network just knows how to determine if two embeddings are similar even before looking at the first image. Hence, it's prior knowledge. Let's take a really quick look at the math and what's being predicted and what the loss is. Let's start with the images. They are i and j. Each of these networks are convolutional neural networks, the same network, which is represented by f. The embeddings that are produced are ff i and ff j. Because, remember, neural networks are just functions. So you're just passing in an image to a function and its output will be the embedding. Hence, it's represented as ff i and ff j. These are 64-dimensional vectors. The similarity function takes these two numbers and computes the vector difference. This is another 64-dimensional vector. I'm just taking squared terms, but you can also just take the raw absolute values. The similarity function then takes the sum of all the values in this vector to give us a number. Hence, the sigma where the k is iterating over every neuron. And it iterates from 1 to 64 because there are 64 numbers or 64 neurons. Now, in the network, we pass this number to the sigmoid function. It has an edge-weight w and a bias b. So the final output would look like this. A typical sigmoid function. Why hat here represents the probability of being similar? If above a certain threshold, they are similar. If the lowest are in threshold, they are different. So now this is great for inference like during the time of testing. But to make this network learn, it is done by back propagation. And the loss is the same as that of like the binary cost entropy loss with the sigmoid. Why and why hat should be close to each other? The network will tune its parameters to minimize this loss. So how is this using production? Honestly, a single example per person for a face recognizer is pretty tough. Particularly since the input is just raw pixels. And the network has to kind of learn just from very, very small, raw amounts of data. So it can take a few examples per person to have even a reasonable face recognizer. But for problems with more complex input features, few shot learning or even one shot learning becomes more possible. There are a bunch of coding examples online where they do something with a language data set to detect similar characters in an alphabet. And I'll actually add these resources in the description below. I'm not looking to explain the code here since the blog posts themselves do the explanation quite a bit of justice. So check those out. Hope you all enjoyed this video. And until next time. Bye bye. Bye. Bye.