the it will judge whether or not some of the words are present right here and


Learning to summarize from human feedback (Paper Explained)

that's 100% due to the reward model I think not being trained on you know


sentences like what we've just seen because even the supervised baseline the


summaries are going to be pretty okay and the especially the human reference


summaries are going to be pretty okay for the most part they're going to


already be coherent they're going to be linguistically correct grammatically


correct and so on so it just never seen that space of data right if we scroll


back through the this giant mess right here this is already it's already the


paper basically so after implementing this particular reward you can see that


they now have a handle right here on how much the RL is supposed to go away from


the supervised baseline it if they simply constrain this to some reasonable


degree then the reinforcement learning seems to improve the seems to improve


the summaries okay so the results here are you've already seen I think the main


results in that they are pretty pretty good especially you can see this in they


also ask the humans to rate summaries in different kind of in different areas


then you can see that the reference summaries are always or most of the time


better than the supervised baseline and also the pre trained only models yet the


human feedback models they outperform the reference summaries which is you know


it's pretty cool because you'd think that humans would be sort of very good


at this stuff but the human feedback you can think of it as kind of emulating an


ensemble of humans so the reference summary is just a single human writing a


summary and the human feedback is optimizing a model that's kind of tries


to integrate all of the human summaries that exist from a particular of a


particular post of course it would be interesting to see of how diverse the


how diverse the summaries would be I believe they they have some experiment


where they sample with different temperatures but still maybe there's a


trade-off with diversity here that it always goes for the best one and they


make that do a lot of experiments I don't want to actually get into they


also transfer this to this news data set so simply trained on reddit but then


transfer it to the news data set which it works pretty well as you can see


right here so it works almost as well as a supervised baseline that was directly


trained on that data set and that's fairly fairly cool so I definitely think


that there is a a value and the criticism of rouge definitely is


warranted also the question of how we train with different things such as


summary where we can't even really formulate what we want like there's a


trade-off with length as well the incorporation of human feedback is very


valuable so the last part they do is understanding the reward model they ask


themselves what what does the reward model actually learn and this is where


I'm a little bit disappointed in here though this this is very valuable right


the fact that they show that if you let it go too far if you optimize only for


the reward model you fail they also do investigations into model size and how


much data you need and so on they change a little bit the things which I this


okay this this is pretty cool where they say we construct an additional


validation set by having lablers make minimal edits to summaries to improve


them our reward model our reward models prefer the edited summaries almost as


often as a separate set of human evaluators so the reward models can sort


of spot when summaries improve and so on they do a lot of validating that the


reward models are actually in line with human preferences however as we see if


you directly optimize for the reward model if you are allowed to go away from


the data manifold of valid summaries then anything can happen and that's the


danger with incorporating reinforcement learning right here you can also see


they're clearly better than humans so here are the these these curve that I


draw at the beginning for these reward models whereas the rouge as you can see


it just flattens out after a certain complexity what they don't investigate


what would be really interesting is just something that I would find interesting


is how much the reward model actually depends on the input post because it


seems like it seems like you could you know trade-off information in the input


post and coherence and so on by looking at what happens if you actually change


the input post does it matter a lot how much does it matter and so on so this it


would be fairly cool to look at especially given that we humans can


apparently look at these summaries and judge them fairly well by just looking


at the summaries of course we have no clue what the article said yeah all


right so here they discussed some limitations and they're of course very


very open about the limitations right here you know it's extremely skill


intensive time-consuming to produce good ones and expensive so yeah the last


thing here is the broader impact statement and they of course go through


the full trifecta of broader impact statements which again to repeat so you


have to you have to do this you have to so here is you and you you take you take


your hand and you go like you know that the Catholics go you touch here you


touch here you touch here or the shoulders here and here and you say the


magic words the magic words are technology good technology bad


technology biased okay so what you want to do is it's technology which is a


metaphor that broader impact statements they never actually deal with the exact


method in the paper they always go like up one layer or two and of course the


extreme is technology so you don't want to talk bad about your technique because


my god your technique isn't bad is it so you just go up and you say whatever


language models can be bad or good or machine learning can be better or


technology now first you say it's a it's good right so many potential positive


effects of aligning machine learning algorithms with the designers


preferences and again I think this is a bit overhyped this aligning because we


clearly see that the way they do it if you align too much it is misaligned


again ironically then bad so unfortunately our techniques also enable


malicious actors to more easily train models that cause societal harm yes


tick that's the technology bad part and you can see for instance one could use


human feedback to fine-tune a language model to be more persuasive and


manipulate humans beliefs so we are talking about language models we're not


talking about a summarization here in this particular case we're talking about


language models so that's the technology part and then technology bias so you can


pretty clearly predict that there's going to be a part that is something


like there you go however since the data set consists of user


submitted posts with minimal moderation they often contain content if offensive


relict harmful societal biases this means our models can generate biases or


offensive summaries as they have been trained to summarize such content at


least this is actually about you know summarization at least this is actually


about the model in question right here so props to that but if you ever write a


broader impact statement the the holy trifecta of broader impact statements


must apply and you're good right that was my thoughts for this paper a bit of


rambling look at the paper look at the appendix look at the code that they've


released I believe they've even released this small model they have a 1 billion


parameter model I don't want to promise too much but yeah they have a lot of


appendix a lot of experiments right there and check out open AI with that


Support Vector Machine Intro and Application  - Practical Machine Learning Tutorial with Python p.20

What is going on everybody welcome to another machine learning with Python


tutorial in this tutorial we're gonna be talking about another supervised machine


learning classifier and that is the support vector machine or SVM. Right out


of the gate you should think about what is support vector machine what does this


even mean well first of all machine probably just has some sort of relation


to like a system or something like this but then we have support what?


vector so that should tell us that we're gonna be dealing with vectors and in


vector space and then we see we have support and we're not really sure what


the heck that's supposed to mean but generally we're gonna probably guess


that it it goes together so we've got support vectors we're not really sure


what those are yet but we'll figure it out so we've got a support vector


machine we're looking probably for some support vectors and we are recognizing


that we're working in vector space. Okay so the support vector machine was


created by Vladimir Vapnik back in the 60s actually but when largely ignored


and overlooked until the 90s Vapnik was in the USSR at the time and then in the


90s he got moved over to the United States working with Bell Labs and in the


90s this is where it was shown that the support vector machine was better than


the neural network at like handwritten number recognition and stuff like this


and then basically the SVM became the most popular machine learning algorithm


for a while and it's still one of the most popular machine learning


algorithms. So first let's just talk about the really high-level intuition of


the support vector machine and then we'll show an actual example of us using


it and then we'll break it down to explain how it does what it does because


it turns out the support vector machine I would argue is probably one of the


most complex machine learning algorithms. So again we're in vector space so let's


draw some vector space and then the support vector machine is what's called


a binary classifier so it separates only into two groups at a time but it's


important to not confuse this with that a support vector machine can only


classify into two groups it just will separate two groups or basically


separate groups to really one at a time one from the rest I'll explain that more


when we dive in but for now just understand it it's a binary classifier


and what it wants to do is separate into two groups and these two groups are


denoted as positive or negative and generally they're going to be a positive


one or a negative one so let's say you got two groups of data so you've got


some positives so we'll draw positive positive positive and then you're going


to have some negatives so I'll draw a negative negative and a negative and the


objective of the SVM is to find the best separating hyperplane which is also


referred to as your decision boundary so the best separating hyperplane or


decision boundary that will separate this data so for now it's going to look


a lot like a line and I think that's why a lot of people can get confused because


the SVMs are are always depicted or usually depicted in two-dimensional


space at most three-dimensional space so the SVM is going to go it's going to run


and it's going to say hmm I found the best separating hyperplane and it is


like this okay and it would be a straight line if I could draw right


anyways so it's saying that's the best separate separating hyperplane and it's


going to say that is the best because the distance between that hyperplane and


the the associated data that it's separating is the greatest so if you were


to take a perpendicular bisector of the hyperplane and draw that to the closest


data points let's say you'd have like this this and this okay that that


distance is the greatest distance that you could come up with with a separating


hyperplane so for example another separating hyperplane might be this


right that's a separating hyperplane but the distance again the perpendicular


distance between those is this and like this right much smaller than our


greenish yellow counterparts okay so the support vector machine says that yellow


greenish line is the best separating hyperplane for our data now how we get


to that is another story but for now let's just remember that is the let's


say that's the best separating hyperplane once you acquire the best


separating hyperplane you can now take in unknown data so let's say you have an


unknown data point so unknown you because that you rests on the right hand


side of that separating hyperplane we're gonna say it's not unknown it's a


positive sample conversely if you had an unknown that was down here it's not


unknown it's on the left hand side of this hyperplane therefore it's actually


a negative sample so that is the intuition of the support vector machine


we just need to find the best separating hyperplane and then from there we can


classify new data points again I will just reiterate it's a binary classifier


and natively we want it to be against linear data so for example what is the


best separating hyperplane well turns out we we we can't do that right now


where is that hyperplane right it doesn't exist so in in theory you can't


have one but wouldn't it be nice if we could do like like that everything that


is on the left side of this line is a minus and everything that's on the right


side is a plus so I'll leave it to you to determine whether or not that's even


possible and we will answer that question I promise but for now let's


actually apply the support vector machine in a more simple example we're


going to be using the same example that we did before with the breast cancer


data set so let's go ahead and hop over there okay so now we're gonna do is we're


gonna take the same code we used back in part 14 with the k-nearest neighbors


algorithm if you don't have that go to the text version of this tutorial on


python programming net and you can just copy and paste it'll be right at the top


so here's the code this is the code we used with the k-nearest neighbors now


using the support vector machine super simple we're gonna import support vector


machine from sk learn and then we're gonna come down to the classifier and


we're not going to be using k-nearest neighbors we're gonna use SVM capital SVC


for support vector classifier and then we're gonna use empty parameters there


there are a lot of parameters that we can modify but in order to know what to


modify or what it's doing we need to break down the algorithm first so for


now we'll just use the defaults and let's go ahead and run it because that's


all we have to do super simple to change algorithms so there we go we ran it 92%


accuracy and then this is the classification that we just kind of made


up and it did it right let's run it one more time 92 seems kind of low there we


go 96 okay so that is the support vector machine in in practice again all we did


was just take the data replace some of the data with some outliers which later


now you'll see how different the support vector machine handles outliers as


opposed to the k-nearest neighbors what if we did not drop the ID column so


let's do that and then we're just not going to make a prediction so if we


don't drop the ID column we're relegated back to about 65% accuracy so it does


better than the k-nearest neighbors did when we left in the ID column but it


still has a huge impact so ID was just kind of a useless data column oh that


time we got 99% accuracy nice anyway so so that's that anyway so we drop the ID


column so it's useless and then our X's are just everything except for the class


our features are everything but the but the actual label itself the Y's are a


label we do the train test call the classifier train the classifier and then


test it okay simple enough so that is the theory and application of a support


vector machine now we're going to break it down so if you have any questions


comments concerns up to this point feel free to leave them below otherwise stay


DINO: Emerging Properties in Self-Supervised Vision Transformers (Facebook AI Research Explained)

Hello there, I hope you have all seen this. This is a new system by Facebook AI. And what you're


seeing here is a visualization of the attention maps of that neural network. In the middle is a


supervised baseline. And on the right is this new system called dyno. It's not as much a system as


it is a methodology for unsupervised pre training of visual transformers. And you can see that the


system has neither been trained to learn what a dog is, nor has it been trained to do any sort of


segmentation. Yet if you look at the attention maps, it clearly can track objects, it knows what


to pay attention to in the images. And it can do much more than that. So here you can see that it


can sort of track objects behind occlusions. So the ship goes behind the waves, the horse goes


behind the grass. And you can see in the attention map that these, this is well reflected. You can do


more than that, though, even so if you use this feature representation that this model gives you


for ImageNet, then as the model gets trained, and you represent ImageNet and its feature space,


it will cluster the same the images of the same class, it will cluster them together,


which is already pretty cool, because it has no labels at training time. But also it will cluster


similar classes with each other, which, you know, speaks to the, it kind of speaks to the fact that


this might be the next step in unsupervised representation learning for images. And


specifically, it appears that the features that come out of a network that is trained with dyno


are extremely valuable for the kinds of things we, you know, we are interested in when working


with natural images. So this is image retrieval and classification. So the system, let's just


switch over to the paper right here. The paper is called Emerging Properties in Self-Supervised


Vision Transformers. It presents a system called dyno. It's by Mathilde Caron, Hugo Touvron,


Ishan Misra, Hervé Jégo, Julia Marral, Piotr Bojanovski and Arnaud Joullin of Facebook AI


Research, Inria and Sorbonne University. You can see a bit more here in these pictures,


where again, this is the self attention. So the attention map from a vision transformer


that was trained with dyno and no supervision. Okay, and you can clearly see that in all the


cases, the attention falls on what you would consider as a human the relevant things in the


image. Now, I have my hypotheses, why this is the case, like completely without labels, and we'll


see about that. But the representations that come out of the systems are really useful. For example,


you can fine tune linear classifiers on top of these representations and that gives you


really good image classifiers. They do that with ImageNet. You can use these for image retrieval,


because similar images are clustered together. You can use even do zero shot classification


simply by doing a k-nearest neighbor classifier in that feature space. And yeah, here you can also do


some sort of proto image segmentation by looking at the attention maps. You don't even have to do


something special to visualize this like you have to do in CNNs. The attention map directly gives you


the sort of segmentation map or something pretty close to it. As an overview, this system dyno


is simply a they push the self supervised learning. And they specifically make the case that


self supervised and visual transformer, they go together really well. And they, as I said,


the dyno is called self distillation with no labels. So that is dyno. And yeah, they push


various kind of metrics in self supervised systems or, you know, then linear classifier


trained on top of them. For example, 80.1% top one on ImageNet in linear evaluation with the


visual transformer base. And a quick overview over the system is right here. So two things they say


are important next to all the other self supervised systems. First of all, they do they have a kind of


student teacher, that's the self distillation part. The teacher is a momentum teacher. And


it does this centering. And it also does sharpening in the softmax right here. And then


there is no contrastive learning, there's no negative samples that the sharpening and the


centering sort of take care of keeping the model from mode collapse or from collapsing. Also,


there's no batch norm. So if those things don't mean anything to you, maybe you stay tuned,


we'll discuss them in a bit more detail as we go through the paper. If you like paper


summaries like this and other content, for example, our cooking video, feel free to share


this out and tell your friends about it. By the way, the cooking video did terribly, I don't know


why. I guess, I guess my youtuber skills are just not not on par. But yeah, I don't know.


Yeah, if anyone has any ideas. Alright, let's dive in. So vision transformers are a new thing,


right? vision transformers. I've also made a video about vision transformers. They are


the easy, the simple application of the transformer architecture, which was prevalent in natural


language processing with the introduction of attention is all you need and follow up papers,


BERT, and so on, and applying this to images. And the concept is very simple. You have an image and


you divide this into patches. So you divide the image into patches. And then you simply unroll


that array sort of so you unroll that array. So you have patch, patch, patch, patch, and so on.


And then you simply consider this as a sequence, like a sentence like, Hello, my name is and so on.


You simply consider the sequence of patches as word embeddings. So there's like one, I think


there's one fully connected layer to actually get the word embedding, or the token embedding. And


then you put a transformer as you would in NLP. So there is a transformer here. And you do whatever


you do with a transformer. So usually, if you don't know, people prepend a special token, that


special token is usually called something where I'm going to draw this, that special token is


usually called CLS token. And that is also passed through the transformer. And the transformer in


its base configuration, it sort of keeps it keeps the length of the sequence the same, it's actually


not necessary to do this. But that's just how we do things. So for every input token, you'll get a


corresponding output token or output embedding or output signal, whatever you want to call it. And


such that none of the input tokens is, you know, kind of preferred, because every input token


sort of refers to some little patch here in the image. If you want to say something about the


entire image, you don't want to prefer any one of them. So what you do is you have this special


token, the CLS token, which is associated with no location in the image. And that's ultimately what


you use to classify the image or also here to do representation learning. So the representation


we're looking to get out is the final layer embedding of the CLS token. And that through


the transformer architecture had aggregated all the information or we hope so from all the visual


tokens in the image. So that's a visual transformer. Now, what do we do with it in this Dino


architecture? I've already shown you this picture, let's go a little bit deeper into that. So let's


get deeper into that. Self supervised learning naturally means you have no labels. And in this


case, you don't even have a negative sample mechanism or a contrastive learning mechanism.


So what you want to do is you want to train a model that sort of gives you sensible representations.


And that is easier said than done if you have no labels. Now, when you do contrastive learning,


the goal is that you have an image and you just take two patches from the image, let's say,


and you have another image and you take a patch from that. And now you have what's called your


what's called your anchor, this is your anchor. And then you have patch, patch A from the same


patch B. Now you present the model, all the three patches, and you tell it which one is the anchor,


and it needs to decide is the patch A or patch B from the same image, you can see how this objective


can give you sort of representation because the model learns what kind of stuff is likely to be


in the same image. This is not the case right here. We don't do contrastive learning, we don't


have negative samples, we only we take one image, and then we augment that image in different ways.


Now augmentations are a kind of a science by itself. I think they say they follow the paper


BYOL in terms of augmentations. I've also made a video on that. Essentially what you do


is you do various random perturbations of the image, you might flip it, you might apply some


color jitter, you might apply like some solarization, anything like this, anything you can do to make the


image different, but that you're relatively sure that you know it still looks like the same,


like you would still recognize it as the same image. So a part of these augmentations are also


crops. What I've shown you here are crops of the same image. They do something special right here.


When they have an image, they crop in two different ways. One they call I think global crops,


and these are crops which generally cover more than 50% of the image, whereas the other ones


they called local crops, and these are crops that cover less than 50% of the image. This is going to


be important in in one while. So these are global and these are local crops of the same image.


So they exactly and keep that in mind. And now we have to understand what's up with this


student and this teacher. So what we ideally want to do is we want to have


two different augmentations of the same image. So here you have an image and you can see we make


two different versions of that image. Now this could be two different crops and then we apply


two different color jitters, we apply two different random rotations and so on. We just want two


different versions of the same image. And our goal finally is going to be here you can see the loss


is that the representation we get out of it is the same. So we teach the network that look these two


things, they might look different, you know, but they are in fact the same. They are, you know,


from their crops, differently augmented, differently cropped, but from the same image. So the easiest


thing would be to just pass the two through the same network, but that it does not work. So if you


don't have negative samples, your main goal is to avoid what's called collapse. If the network just


maps everything to the same representation, then it always wins, right? It always is like, well,


you know, okay, the two things are the same because everything's the same. You don't want that. So a


trick is to have two different models. One you call the student and one you call the teacher.


And they're called student and teacher because from distillation. So in distillation,


what you usually have is you have a data set and then you train a big model, which is the teacher.


The teacher. And now what you want to do is you want to make, you want to make that model maybe


smaller, right? Such that it runs on a mobile phone. And that's then the student. And there


is a procedure where you take the data set, and you take the teacher model, and you sort of transfer


the knowledge from the teacher model to the student model while using you can use the data


set to do so. And that usually works better than training the student model from scratch.


It's very interesting why that even works. But this process is called distillation.


So that's why it's called teacher and student. However, in this case, it's kind of a self


distillation. So the teacher and the student, they're not big or small. They're the same


architectures. In fact, we only train the student. Okay. And the teacher is made from the student. So


here is where the terms break down a bit. Like, so in the distillation sense, the teacher is


the teacher in the distillation, but now it breaks down because the teacher is constructed


from the student. So we have a teacher, we train the student to predict the same thing as the


teacher does, like learning from the teacher. But then at the same time, after we have done after


we've updated the student, we then have we then build the teacher from the new student. And the


way we do this, you can see right here is by exponentially moving average. So we keep the


teacher model. And then as we update the student model, we simply update the teacher a little bit


into the direction of the student model. And there's also a schedule associated with this


exponentially moving average, like how much the exponential decay is, and so on. This seems all to


be loaded with hyper parameters. But again, the results are really cool. And it I guess it's yet


gonna turn out how sensitive to hyper parameters this whole setup is. They do make ablations, but


we'll see how other people with other data sets fare. All right, so we have the teacher


that is built from the student exponentially moving average. And we want to make the two


predict the same represents or the same output for different augmentations of the same image.


Okay, in fact, here you see it's even a bit more complicated. So this is the pseudocode.


So we want to augment the image, we get two different versions of the image, we push both


of these versions through the student and through the teacher. And then we want,


if you can track that, but T1 is the X1 that went through the teacher. That needs to be the same as


X2 that went through the student. And then the image X2 went through the teacher should be the


same as X1 going through the student. So we want to augment the image differently two times. Then


that gives us two different views of the same image, then we want to run them through the


both through the teacher and student. And then we want sort of everything to be consistent with


everything else. So we want the one augmentation in the one model to be consistent with another


augmentation through another model. Now, there are two more things here. The first one is these


centering, what's called centering. And that's what something the teacher does. And also something


they say in the text is that in the teacher, they only use the global cropping. Whereas in the


student, they use both the global and the local cropping. So the student uses both, and the teacher


only uses the global crops. So essentially, if the student gets a local crop, and the teacher gets a


global crop, the goal here is that both things predict the same representation. And that means


the student has somehow learned that, you know, whatever I see here is a little piece of whatever


the teacher has, even though it doesn't know I should reformulate this because it doesn't see


what the teacher has, right? So the student somehow has to from a very small subpatch,


it has to know it has to output something that it would that itself or the teacher, which is itself


averaged, would also output if it sees more context in the image. So you train the network


to for all of these crops and for all the different augmentations, output the same thing


without knowing what the other thing is. And I think that is the advantage to contrastive


representations, honestly, because in contrastive representation, in contrastive learning,


you sort of contrast with the negative samples. And here, it's really like you don't know anything


and you need to output something. And that needs to match whatever you yourself


would output if you saw a different part of the image. So you have no choice but to output,


you know, either the same thing all the time, which is prevented here, or to output


something that's on the image. And you can't just output something that's only in your patch,


right? Otherwise, another patch wouldn't show the same thing. Like if you if there's like there's


like a little tiny structure here, you would not output that because the other patches don't have


it. However, if there is something big in the image, right, like, you know, our traditional


cat right here, and you recognize that because you see a little cat ear, if you output a


representation for cat, and you know, since you would also do this for the other ear and for the


paws and so on, you, this whiskers, you then would, you then win, like your loss is small.


So you're intrinsically pushed towards outputting something that describes the image as a whole,


right? And that differentiates it from other images. So what what encourages you to be different,


that's this centering. And also, in the softmax, there is a there is a sharpening.


So first of all, the centering is simply what you do in the teacher, you keep a running average here.


Again, you can see that you can keep a running average of all the representations that the


teacher sees. You just you keep you keep that as a list or a running list, all the representations


that the teacher sees running average, and you simply subtract that from the logits down here.


That's that's centering. It's something like a normalization, but not really. What it does is it


it keeps the it keeps the logits sort of close in a range that's manageable and and has some


variance and so on. And, you know, within as a as a proxy, it also does that to the student because


the student is trained to be like the teacher. So centering is a bit like a normalization here.


And then the second thing is that there is a different parameter in the softmax as a temperature


parameter. So the softmax function is at the end, and that has a temperature. Where is it? Where


are you? This is the softmax function, you can see it has a temperature parameter, right? And


that temperature is much lower for the teacher than for the student. And they call this sharpening.


Now, why is there even a softmax? That's what I asked myself, like, if you think of a of what you


do with a representation, usually when you do something like a contrastive loss, you may just


do a contrastive loss or a self supervised loss on the representation itself, like you do cross


product or not cross product, inner product, or cross product, or cross product, or cross product.


Not cross product, inner product, or you do L2 distance between the representations or something.


Here, we do cross entropy. And the cross entropy after a softmax and the way I interpret this is


the following. A softmax is like, what you get out is a normalized distribution, right? However,


we have no class labels here. So what you do is you simply choose, you choose a number,


any number, right? This is you as an implementer of this algorithm, choose what dimension you want


to output here. Now, after the softmax, whatever you input is going to be a distribution over the


amount of things that you have input. So and you can interpret this as classes, right? There's class


zero, one, two, three, and so on. And you're going to get class zero is probability 10%,


class one, zero percent, class two, 40%, and so on. You don't know what it means. But you know,


you get this as an output. And the teacher having this sharpening, it will have a much more peaked


distribution. So for the same thing, it might have a distribution that's not as much class zero,


not as much class one, very much class two, right? This even goes off screen for you. Yeah,


very much class two, and so on. And since this is the, since the teacher is the target for the


student, you see here is a stop gradient. The student is sort of, this is a common, I guess,


I guess this is a common trick in distillation. Like the teacher is very sure. And that means


the student gets a better learning signal to match the teacher. So this sharpening of the teacher


gives these less noisy for the student. And also, I think it also helps prevent this.


I'm not sure. So they speak of sharpening and centering. And one, I think one they claim


furthers collapse, probably the sharpening. And one prevents it, which might be the centering.


I might mix them up. But you know, one sort of reduces the noise, but encourages,


I think the sharpening must reduce noise, but encourage collapse. And then the centering


counteracts that, counteracts the collapse. Yeah, probably. Though there is an argument to be made


that the sharpening might also counter collapse because, oh, yes, that's what they say. Now I


remember. So they say the sharp, so they say, naturally, this would then be biased towards


the uniform distribution with the centering, I believe, but the sharpening then counteracts


that again. It's in the text somewhere. I'm more interested in why this is even a softmax in the


first place. So I interpret this as you force the model to come up with an k-dimensional


classification problem by itself. And it has to choose by itself what the classes are, right?


So it has to somehow make representations that allow itself to come up with a classification


problem that it can solve. And I think that's pretty smart. You know, instead of giving it


a classification problem, you simply ask it to come up with one. Now this could go horribly wrong,


right? But apparently, if you do it like this, it goes well. So that's the dyno architecture. Again,


we augment image, we augment it in different ways. We put all the things through the student


and through the teacher. The teacher is an exponential moving average of the student.


That gives us different representations of different augmentations of the same image. We


require the representations to be the same in terms of their... So we take the representations,


we ship them through a classifier, through a softmax into a distribution. We require the


outputs to be the same of the student and the teacher. While the teacher has centering, which is


centering the logits by an exponential running average of all the representations it has ever


seen. And also it has a sharper softmax. All of this together, and yeah, the teacher has a stop


gradient, so it's we train the student. All of this together gives us a system that comes up with


good representations and does not collapse. Now, what does this buy us? It buys us what I've


essentially shown you at the beginning. And also it buys us k-nearest neighbor classification,


which are zero shot classifiers. Right now, I can pump this through the system, pump a data set


through the system. I can come with a new image and I can simply do k-nearest neighbor. I don't


even have to train the network anymore. I can come with a new data set. I can do image retrieval. I


can do linear classification on top of the representation. And all of this works much better


than previous systems, no matter the architecture. But it seems to work especially well with the


visual transformers down here. If you see this, for example, compared to the best Resnets. So


there's this 5% difference in linear evaluation, which, you know, this is 25% error. This is 20%


error on ImageNet. And there is even a bigger difference when you look at k-nearest neighbor


classification, which is the rightmost column. They do a lot of experiments, as I said, in image


retrieval, in copy detection, which is really interesting. That's, I think, where you want to


realize if someone has taken an image and made another image out of it. You know, and don't know


if that's such a good thing, given that the entire meme culture relies on it. If you look at the CLS


token, right, the CLS token is ultimately where the representation that you take comes out. If you


look at the attention heads of that, and you visualize the attention maps, it gives you this,


not only this segmentation map, but like, yeah, like not only does it tell you where to look,


but it even seems to be sort of segmenting the individual objects here in the horse. You can see


the horse, you can see the straps of the horse, you can see, sorry, this is a zebra. Yeah, you can see


in the trucks, you can see the roads, or the wheels are separate from the truck, and so on.


They do ablations, and they compare it with sort of supervised baselines. You can see this works


much better. And what I think is pretty cool is down here in the appendix somewhere, yeah,


they have more of these attention maps compared to supervised attention maps. And this, I mean,


that the comparison is very, very strong. Yeah, because, yeah, so compared to supervised, what I


think is happening that if you give the these things a supervised problem, they, you can see


they do pay attention, for example, here, they pay attention to whatever the cat's face or something


and the ears, you can see the cat shape. However, there is this thing, like there is the shortcut


learning, which is, I think, a data set problem, but also, a supervised system just stops kind of


learning once it has mastered the task, or it might try out various optimizations for the task


that you give it, right? And these optimizations, I think, are what pop up all over the place with


these little specs of attention that it also does. It might not make sense in this particular image,


but, you know, the same attention pattern or the same thing to pay attention to might make a lot


of sense in like three other images in the data set. So that's why that's there. Whereas, if you


do this unsupervised, there is no, there's no hyper optimization on a single task. There is no real,


like there is only, there's no, like, especially if you have also more images, which you can do in


unsupervised, right? You can also can't hyper optimize for individual samples and so on.


So that's one thing. And here is this complete map of ImageNet, I think. And maybe you can't read it,


but like here's Tractor and right next to it is like Harvester and Trasher. There's Minibus down


here. So all of these, like the vehicles are clustered together. There is kind of Butcher Shop


and Grocery Store right next to each other. This, you know, it appears to be really, really good


representations. Now, the question is why, right? That's the question. So this was the paper. I


encourage you to go read the experiment section and so on. It's very cool, cool ablations.


They show why exactly they use this loss and what happens without the momentum of the teacher and so


on. But what interests me is why does this give you such extraordinary representations in an


unsupervised fashion? And I am sort of, I have two hypotheses or two things that I think contribute


mostly to this. So if we look at the question of why, right? The first thing I think is the


augmentations. The augmentations have played a large role, not as much in NLP. In NLP, we do it


a little bit differently, but augmentations in computer vision and self supervised learning have


a central role, and it's really important that you have the correct ones, which is a thing they also


say right here, right? They really stress that this multi crop augmentation is quite important.


So augmentations seem to be central. And to me, augmentations are a bit like that's where you put


the human prior. That's where you tell the model what it should pay attention to and what it


shouldn't pay attention to, right? Because all the things you destroy with an augmentation, like you


make the color brighter, you tell the model color doesn't matter, right? Or brightness


variations don't matter. So by augmenting, you tell the model what it should and shouldn't, or


what it shouldn't pay attention to, essentially. So all the things that, it's the same if you have


a dataset of dogs and cats, right? And you tell it, this is a dog, this is a dog, this is a dog.


Essentially, you tell it, you shouldn't pay attention to what is different in these images,


you should only pay attention to what is the same. And the augmentations, that's kind of where


the knowledge goes in. So if we want to go towards fully, let's say fully autonomous,


self-supervised learning, that's what we need to get rid of. We need to get rid of the augmentations,


or we need to get rid of us designing augmentations for the domain. If we want this to be,


domain agnostic, and also if we want better image representations, because the probability


that we as humans exactly capture the correct augmentations is zero, right? We seem to capture


pretty good ones, but the probability we have the best ones is like zero. The second thing,


and this is a thing that's I think more hidden, is the dataset. And what I mean is how the dataset


is constructed. So these things are often trained on something like ImageNet dataset. And you can see


in these pictures, there always seems to be like an object of interest in these pictures, right?


Even if you train this from pictures in the wild, like you scrape pictures from Instagram or


whatever, the way people don't take pictures of random things. People, if you're, you know,


it would be pretty weird to have a picture and there's just like dirt road. Like it's just like


dirt road and here's like a bit of grass. And you post this on social media and you're like,


whoa, look at this. So by how you construct the dataset, even if you scrape it from the internet,


by how humanity takes pictures, you are implicitly telling the model what's important. So the model


learns, how should I say this, how you make the dataset speaks a lot about where your attention


goes. And that's what you feed the model, right? So these things, these self-supervised methods


in this way, they rely a lot on dataset construction. So we shouldn't expect to see


set construction. So we shouldn't expect this to transfer to domains where we get like random


IID data from the world because these things aren't IID. We tell the model pretty clearly


by the data we give it, what's important, what isn't. So that is a little bit of my opinion.


And I think that's correct, right? I think the model, if we have self-supervised learning,


the information should be taken from the dataset, right? So the model should look at the data and


say, now what seems to be, given how this dataset is, what seem to be the important things in there?


I'm more a fan of getting rid of the augmentations. So that's my opinion. If you want more experiments,


it's also faster and has less parameters and so on. But again, Dino is a method of self-supervised


learning where and their argument is that it combines naturally well with the vision transformer.


Image GPT: Generative Pretraining from Pixels (Paper Explained)

Okay, I'm sure many of you have already seen this because it was rather widely announced,


but the open AI team has announced a new model that produces pictures instead of text.


So as you can see right here, on the left, you'll always see like a half a picture. And on the right


is the ground truth. So they took this picture, they simply cut the bottom half right here. And


then they let the model sort of imagine what they cut away. And what it comes up with is pretty cool,


I have to say, like, look at the birds, like, this is just awesome. But the special thing about this


isn't that it simply completes pictures. The special thing about it is it does it one pixel by


pixel. So basically, it goes at this pixel right here and asks, Okay, what's that pixel? And then


what's that pixel? And then what's that pixel, and so on. So it is basically a like a language model,


but for pixels in that it goes over the images in order, basically like this,


or like always from left to right, left to right, left to right. And it has no clue of the spatial


relations between the pixels, it needs to learn that by itself, as opposed to a convolutional


neural network, which is specifically designed such that if you want to predict this pixel right


here, then it's specifically designed to say, okay, the most important information is probably


around that pixel. And then some like other important information is widely around that pixel.


So CNNs are built with this in mind. Whereas this model right here, which is also known as image GPT


isn't doesn't have any of that. It's simply a transformer model that goes over these pixels


one by one. And we'll see how that's done. There's some more examples right here. Particularly cool


is the cat. And you see that there is the beginning of this little white thing right here,


which is this card. And the completions of the model. Yes, very interesting. The model can of


course, as a language model can also sample by itself, just random images, you sample them once


through. And this is what it comes up with. So these are pretty good quality images for a model


for a model that just produces one pixel by one pixel. Now this idea of one pixel by pixel isn't


new. This has been around before. But the investigation here is basically how much can we


how far can we push these generative models for pre training? Hi, there. This is Janek from


post production. I've realized that I've forgotten to even read the name of the paper. So it's called


generative pre training from pixels by Mark Chen, Alec Radford, round child, Jeff Wu, he won't do


profile a diary wall, David Luan, and Ilya Satsuki. And since Henry AI labs has already


made a video on this, this video is going to be more of kind of a rumble rant about what I find


interesting about the paper and some thoughts about it rather than like a classic explanation.


I hope you still enjoy that. So what you saw on the right wasn't even the this isn't the final


result, the supposed result. This is simply the pre training task. It's fun to look at it. But the


actual object objective of the paper is the following. What if we train we pre train on a


large data set to generate what good images like these, or we to complete images like these. And


then we fine tune on a classification task. And the answer is here. They say, on c410, we achieve


sick the 96.3% accuracy with a linear probe outperforming a super wide supervised wide


resonant and a 99% accuracy with full fine tuning matching the top supervised pre trained models.


And even larger model trained on a mixture of image net and web images is competitive with


self supervised benchmarks on image net achieving 72 top one accuracy on a linear probe of our


features. So the goal here is that you have a data set that you want to try and like train a


classifier on. So usually you have a data set and the data set has images, and you put them through


like a convolutional neural network. And then you have to classify the image into one of I don't


know how many classes on c410. That's 10 classes on image and it's 1000. And the data set is these


images together with these labels. Now, the idea of pre training is that you some where have a


bigger data set that is sort of similar to the small data set. But yeah, it's similar enough such


that the network could learn something. So what you want to do first is you first want to take the


large data set, train this network right here. And then in a second step, fine tune the network


on this smaller data set. And you sort of hope that what you learn from the large data set right


here, transfers over a little bit of knowledge, you already have a little bit of knowledge,


and you can make better use of the data that you have right here. Now, the question is,


how do you do this pre training? And of course, this has a long tradition, well long for maybe


two or three years right now, in the language community, where people, they pre train these


large models, like we've just seen GPT-3, or BERT was one of them. They pre train these large


transformer models on text, and then to fine tune them on classification tasks for text. And that's


what this paper is doing right here. They pre train a transformer that is a GPT-2 scale model.


They pre train it on image generation. And then they fine tune it or transfer learn it to


classification tasks. And the point of the paper is to say that, like in text data, in text data,


we have made pretty good, pretty good experiences with doing this with pre training a generative


model and then fine tuning on a classification task. While so far in images, all we've ever done


is we've pre trained these pre training tasks usually is a classification task, or like a


self supervised task with a contrastive loss or something like this. What they're doing new is


the generative modeling in the as a pre training. And again, this isn't like entirely new, but they


show that if you throw a lot of computers at it, and lots of data and a big model, then that can


work equally well to the self supervised tasks. So their model, as I said, is pretty, pretty simple,


they take an image, and they unroll the image now, and fully unrolled image on, let's say ImageNet


has 224 squared pixels, and that times three, right, because you have three color channels. That's


too large, even for an open AI supercomputer. So what they do is first, they downscale the image.


So they downscale, it's not as drastic as here, where you just get a three by three image, but


they do downscale it to like a 32 by 32 or a 64 by 64. Then they unroll it, which simply means they


go through the image like this, and make a sequence out of it because their models are naturally


made for text sequences. They simply put the image into a text sequence, they further simplify


this by reducing the three color channels to a single one. So they have their own color representation.


And basically, yeah, they reduce the three color channels to one channel that simply indexes the


color in their color representation. And they say, it's still pretty good, it's pretty faithful.


So ultimately, they end up with like a 32 squared length representation of their image.


And then they do one of two things, they either do autoregressive generative pre training,


which is the sort of GPT-2 style pre training. And the, the idea here is that you always want


to predict the next pixel of a sequence. So you can see right here, that's the sequence that you,


sorry, that's the sequence that you input. And you always want to predict what is the next pixel.


And in this case, you've seen you see that we've already predicted everything. Here, we've already


predicted everything up to this red pixel. So you want to know what's this next pixel, this thing


right here. What's this going to be? And the diagram here basically shows you how the attention


flows. So every position in this transformer, and if you don't know what a transformer is,


I haven't made a video about attention is all you need, where these are explained. But briefly,


every position here can sort of send information can send information only if you have a very


detailed information, only in one direction as to so you train all of these in parallel. And when


you predict this pixel right here, you only want information from whatever was before that pixel,


otherwise, the model could cheat, right? Otherwise, the model could simply learn to copy over the


value. But the attention pattern here is simply to show you that this is autoregressive and it's in


order to predict the next pixel. And then from all of this, you want to predict the next pixel. And


then from all of this, you want to predict the next pixel. This is in contrast to this objective


here that comes from BERT. And I've also made a video on BERT. What you do in BERT is you simply


take that image and you cross the block out two of the pixels, or many of the pixels. And you simply


ask your network to reconstruct those pixels, okay. And now you can see the attention flows in


all direction BERT, the B stands actually for bi-directional. So this is the contrast to the


autoregressive pre-training framework. Now the these two things have been implied in text both.


The autoregressive is usually it's easier to actually make it produce something like we saw


producing these images, because you can always just predict the next pixel and then the next and


then the next and then the next. Whereas in BERT, it's a bit more unclear how you would produce


things in a consistent manner, because the predictions of these two pixels right here,


they are independent. It's one forward pass, and then both of these are predicted.


But other papers have tried to solve this like this, not XLNet. I forget, I forget its name,


it's something with an X. And yeah, but, but these are the two objectives they look at. And it turns


out they sort of trade off a bit, they work equally well, or a bit better and a bit worse,


depending on the task. So once they have done this, so they simply feed images, and you'll


notice that you don't need any labels for this. So what you'll do is simply input an image and then


simply take away half of it like this, and then predict that pixel. And then you want to predict


that pixel, and then you want to predict that pixel, right? That's all like you do with text


and in BERT, you simply input an image, cross out pixels, and then predict them. So you don't need


labels for this. And that's why you can do it with this big data set. And you can do it in an


unsupervised fashion. So you can just crawl the internet for for images, and just feed this in


into there. And it will sort of learn to produce these images. Now, the question is, if you produce


if you learn to produce these images, does that help you for classification? And there,


they have two methods of, of assessing this. The bottom one here is the fine tuning method,


where you simply so this is supposed to be the representation you learn in the different layers


of the network. So this is supposed to be this thing right here. What you'll do is you'll simply


fine tune. That means you on top of this representation, you add a classification head


that has two outputs cat or dog. And you train this entire network on your small data set that


we discussed before. So you train the entire network, all of the parameters, this is called


fine tuning. In contrast to that, what you can do is you can simply, and this is the easy way,


you can simply add this classification head with two outputs, and then only train this classification


head. And that is won't perform as well. But it gives you sort of a better idea of how good


that is the representation that this network right here learned. And on top of that, so if you spin


this idea further, you can actually go and do this at any intermediate layer right here. So you can


forward propagate until layer two right here. And then here, you add your classification head into


the two into the two classes, and you only train the classification head. That being said, you can


also do this with fine tuning. But in this case, this is called a linear probe. And it is often


used to assess how good the a representation in intermediate layers is, whereas what it actually


does is assessing how linearly classifiable a representation is, which isn't the same as how


useful or how informative, but it is one way to to assess these things. Okay. So these are the two


things they assess. Alright, so for as for data sets for c410, they use like c410 and c4100 as


data sets and the STL 10. And there you have to keep in mind the pre training is done on ImageNet


for those so that you pre train on ImageNet without the labels, and then you transfer learn or


learn or fine tune or or linear probe on these small data sets. Whereas later, we're going to


look at ImageNet in there, the pre training as I understand it is done on ImageNet itself, but also


a wider collection of a 100 million or so images from the web from the internet. Okay. So as you


can see right here, this is what happens if you do this linear probing. And you can see it works


pretty well. So you get like a 95 96% accuracy with linear probes. This is very powerful. So it's not


easy to get 96% on c410. I mean, current state of the art is like 99%. But still 96% is pretty good.


And this is the so the entire network, there is this big giant network that you input your image


into. And then there is this one linear layer that does the classification. And all of this right


here has not been trained with classification in mind, it simply has been trained to reproduce


images. It hasn't even been trained on c410. As far as I understand, it's been trained on ImageNet.


So the the this is to stress how cool or how significant this result is basically that just


a linear probe on top of that will give you such a good accuracy. And the second thing that is


obvious right here is this bottom axis is the layer. So this is the layer where they attach the


linear probe. And usually if you pre train a network with a classification task in mind,


so you pre train it with the labels, or maybe even without the labels in a self supervised way,


or something like this, usually, the last layer has the best representation for classification.


But here, the special thing is that the intermediate layers in the middle have the best


representation, you can see that the representation quality in terms of linear probing falls off as


they sort of it falls off as they go into higher layers. And this is consistent across the data


sets, as you can see, and the the idea here is or the way they interpret it is that if you have an


image right here, and the you've blocked part of it, so you've blocked this and this


wrong way around this. So you've generated everything. And now your task is to predict


the next pixel, right? So you're you train to predict this next pixel right here. And the idea


is that as you put the image through the network, what it will do is sort of since the first layers,


they're going to be, they're going to be similar to a CNN, they're going to be doing some low level


low level feature transformation thing, right? But also the last layers, they're going to really care


about what's the exact pixel that goes here, right? Since it's their job to to do that,


they're going to care what color does it need to have, you know, what exact luminosity and so on,


how does it fit in with the previous pixels and so on, where as so that's, that's also good. But


it's not just low level information and consistency with other pixels or something like this.


At some point, if you want to generate consistent images, and we saw that this model can generate


consistent images, at some point, there needs to be some kind of a notion of the global information


in the picture, right? Such because the images are consistent throughout. So there needs to be some


some notion of what is in that image as a whole. And that's the exact information that we need for


classification. And the only way that could actually be is here in the middle, since you know,


that's the place. So the hypothesis is that the these models somehow learn a higher level


representation of global information somewhere in the middle before they then specify that


information again, down to predict the actual pixel. And that's why the best representations


for classification are in the middle. So this is one of the this is actually the interesting


finding or one of the interesting findings of this paper. I mean, it's cool that they can


reach a good accuracy. But to recognize that maybe in these, these generative models,


they have some intermediate stage where they represent the global information. And that


will actually make the best representation. Okay, the second cool thing right here is that you can


see they have different sizes of models. So the IGP TL, I believe is something like 60 layers,


then this is like 48 layers, and this is 32 layers, we don't really so these are on the all


of on the scale of GPT two, either a little bigger or a little smaller. It's not like GPT three scale


where you need ginormous supercomputer, though they do do a lot of computation. But this still


sort of fits within hardware of a standard size and not like exascale. What's interesting right


here is that you can see the larger models, they reach a lower validation loss. So here is the


validation loss larger model if you train them on. So these checkpoints here are always after the


same amount of steps, the larger models do reach a lower validation loss right here, as you can see.


So this is the large, this is the medium, this is the small. And also, you can see that on this


axis, the linear probe accuracy. So this is whenever you go and you find the best intermediate


layer for linear probing, you probe it and you record the accuracy. So you can see a general


trend as your validation loss goes down, the linear probe accuracy goes up. So there is a connection,


like it is in text models. In text models, there's a connection of the perplexity of your language


model, and the quality that of the representation you get for downstream tasks. In this model,


it seems to be the exact same thing, there is a connection between reaching lower validation loss


and reaching a higher performance on classification. So that's one interesting


thing, the general trend to up to the upper right corner. The other interesting, and even arguably


even more interesting thing is that if you look at the same validation loss, so at this point,


all of these models have the same validation loss, yet still, the bigger model is better,


right, you can see right here, the bigger model outperforms the smaller model, even though they


have the same validation loss on the image modeling task. And this is also something that OpenAI in


their in their text papers has stressed that the larger models, they seem to be somehow more


capable of forming good representations, even, you know, even if they have the same loss. So


again, this, this could just be sort of a training data, remember better training data remembering


thing. And when I said that in GPT-3, I didn't actually mean explicit remembering of training


data, I meant kind of a fuzzy remembering of training data of I formulate that in the in the


comments, but I feel a lot of people have misunderstood me there. Here, I think it's a much


harder, harder to estimate what's going on. Also, since image pixels, humans don't have a super good


model on image pixels in their head, as we have about text, as you can see, if you then fine tune,


so for now, we've just do linear probing. If you fine tune these architectures, then you reach like


a 99% accuracy on C410, which is on par with the best models that we have. So G pipe is supervised,


pre trained on ImageNet, but also, I guess uses a bunch of data augmentation while these image GPT,


it uses minimal data augmentation, I think they simply random crop a little bit. And that's about


it. So they also experiment around with this BERT objective. So until now, this was all the,


this was all these autoregressive objective. And I feel the open AI people are a bit more of a fan


of the autoregressive objective, just given what they've done so far in their papers. And you can


see here comparison of the two objectives on C410. And on ImageNet, again, C410 is pre trained with


ImageNet. And ImageNet itself is pre trained with like a larger collection of images from the web,


all the pre training is done without labels. Now, the blue is what you can reach with a linear probe.


And the orange is then on top of that what you can reach by fine tuning, okay, so no linear probe,


but fine tuning, I have to say that the fine tuning is always done at the end. So even though


the linear probe, even though the linear probe can be attached anywhere in between, and it's often


useful to do that, as we saw, because the in between layers are the best, they say they tried


fine tuning also in from in between, but it always worked out best whenever you fine tune,


whenever you fine tune, you take actually the last layer. So that kind of gives you an idea that the


model is then it's sort of what seems to be important is this coming up with the higher level


representation. And then once you fine tune, you're probably able to push that representation


through to the end because of your training signal. But if you hadn't done the pre training,


you wouldn't even have that higher level representation. And then the signal, I guess,


is not strong enough to back propagate through the whole model, it would be very interesting


if they investigate if they do this linear probe analysis again, after they fine tune the model,


that and to see if then still it is the intermediate layers that have the best representation,


or if now the best representation in a linear probe sense shifted towards the end, I'm going to


guess it's shifted towards the end. But I sort of want to even see if the accuracy of the linear


probe in the middle, does it keep the same, right? So does the curve go like this, this is the linear


probe, when you simply pre train, right, this is linear probe accuracy. The question would be,


does it change to be like this? Or does it change to be like this? This is supposed to be the same


at the end. So basically, does it stay as good as it is, but simply get better at the end? Or does


the representation like in this curve, does the good representation now shift towards the end,


and leave the lower layer with even more capacity to do some low level stuff? Yeah,


maybe they've done this, I haven't seen it. So and as you can see, these BERT and auto


regressive objective, they sort of trade off. So the BERT, it tends to do poorly in the linear


probe setting, but then it catches up during fine tuning in CIFAR-10, almost being at the level of


the auto regressive and in ImageNet actually outperforming it. This darker thing here,


it simply means that you average across different maskings of BERT, because I guess even in


classification, it's not entirely clear how to get a signal out of BERT, because they don't do this


CLS vector with BERT, what they do for classification and linear probing, and that's


written up here, they simply take the they do an average pooling, I think they do an average pooling


of the of all the representations of the sequence. And the last thing that I've also forgotten,


there's a lot of stuff. When they fine tune, while fine tuning,


come on, while fine tuning, the classification loss yields reasonable downstream performance,


we find empirically that the joint objective, the generative objective and the classification


objective works even better. Okay, so even when you fine tune with this model, you have to keep


the generative modeling part, the generative loss around, and then it performs even more better,


more well, whatever that word is. So that's also something to think about. I think this this paper


right here, it kind of lays down a lot of cool things that you can think about. And it gives


rise to a lot of hypotheses of how does this stuff work? Why does this stuff work? I don't even think


that the numbers are the most important thing. It's mostly the fact of the effects. And what does it


mean? Okay, so this was my take on it. It was, it's more kind of a my rant of what I find special


about this paper than about the actual paper. You can look at the paper, their numbers are


pretty good on ImageNet, they do not reach the same like super duper performance as they do on


c410. And I guess that's probably because they have to downscale the ImageNet images way more


than they have to downscale the c410 images, because those are of course, only 32 by 32.


So because they have to downscale so much, they lose probably a lot of information.


And I would be interested to see if there is a way to involve convolutions in this,


in all of this. So to do the downscaling that in a learned manner with convolutions or something,


I'm sure this has all been done already. I'm just lazy to look it up. Yeah, so I invite you to look


at their blog post where they have these samples, they look pretty, pretty funny. And these full


samples up here look fairly, you know, fairly cool for what it's trained to do and that it has no


spatial awareness whatsoever. It simply uses learn position encodings. And yeah, check it out. That


Alright, hello everyone. Today we're going to look at this paper, Challenging Common Assumptions in the Unsupervised Learning of Disentangled Representations,


by Francesca Locotello and a bunch of other people at Google AI, ETH Zurich and MPI.


Full disclaimer, I know these people and I've talked to them about this work, so just so you know where I'm coming from.


It's a good paper and it's fairly short to explain, so let's go over it.


The main thing here is what's called disentanglement.


So disentanglement is kind of a property of data in unsupervised learning, or not data, of your model that you would like to have in unsupervised learning,


here especially in generative models.


So what they focus on is autoencoding here, and what that means is I have some data point, which could be an image.


Let's draw an image here.


And I compress this usually into a vector, and the vector has a couple of dimensions.


This is a representation of the data, and from this representation what I can do is I can produce an image again.


And if I train an autoencoder, I will enforce that my model.


So both of these are my model.


This is called an encoder, and this is called a decoder.


What they do is that the final image then looks like the original image.


This is an autoencoder, basically a compression algorithm that tries to find representations so that it can reconstruct the original image again.


Here we go a little further in that we use what's called variational autoencoders.


So all of these experiments here use variants of the variational autoencoder.


And what's a variational autoencoder?


Let's skip some here.


A variational autoencoder is the same thing as an autoencoder, except it's a probabilistic framework.


So what you do is here on the bottom you can see an equation that basically is the objective for a VAE.


And what it does is it says, okay, I have an image.


Let's say this is my image.


And I use an encoder like in an autoencoder.


And that gives me a representation.


But now I don't use this representation directly to decode, but this representation is simply the parameters from a bunch of distributions.


So here let's say I have four latent factors.


And the latent factors are basically the latent variables that describe this image.


So the images could be images of, let's say, cats.


And four latent factors could be the color of the fur of the cat, the size of the cat, the position in the image, and the, let's say, the general lighting of how bright the image is.


So these could be four latent factors that would explain best the image.


And from that, the image could be best reconstructed, let's say.


So the four latent factors we consider as probability distributions.


So what our encoder needs to do, our encoder needs to produce eight numbers in this case.


Eight numbers. Why? Because for each of these four distributions, we want a mean and a standard deviation.


So these eight numbers here, each one or each pair of numbers, one of them is going to be the mean and the other one is going to be the standard deviation of a distribution.


And then from these, we're going to construct a distribution.


Like so. OK, here's the mean, here's the standard deviation.


So the distribution somehow looks like this.


And then we're going to sample from this distribution.


So one sample could be here, one sample could be here, one sample could be here, here.


So of course, in the middle here, we're going to have more samples.


But so the whereas the autoencoder directly uses the encoding to reproduce the image, the variational autoencoder,


the what the output, what the encoder produces here is simply parameterization for a distribution.


And that distribution then is sampled.


So we're going to take one sample here.


So from each of these, so there's going to be multiple of those distributions because we have eight numbers.


We are going to produce four distributions in particular.


So we're going to sample four different numbers.


So we're going to sample a new vector with four, one, two, three, four.


Well, I didn't have eight at the beginning, but never mind.


So here this gives us four numbers, but these are samples.


So these are going to be different every time, even if we feed the same image.


And from this, the decoder is going to try to reproduce the image.


And then again, the images, the end image and the beginning image are going to be forced to be close to each other.


But also now, since this is a probabilistic framework, we also kind of need we need a different loss function.


For the autoencoder, you can simply penalize how far the images are in, let's say, L2 norm.


But here we have two distinct parts to the loss term.


So and everything is probabilistic. So let's walk through this here.


The first part of the so we have two parts of the loss term.


And here in particular, Q is you can see here it takes as an is it is the distribution of Z conditional on X and Z will always be our latent representation of the of the data.


And X will be the data itself, the data point.


So Q will take the data point and produce a Z.


And the Z specifically here, what's meant is this this thing here.


This is Z. Whereas this is this is X and this is also well, this is X tilde or something, whatever is produced by the decoder.


So basically, what we're going to do is we're going to punish the KL distance, which is a probabilistic distance measure.


We're going to. May measure the distance between the distribution of Z under X.


With the prior over Z, so P of Z here, this here is the prior distribution over Z.


And the prior distribution in VA is often to be taken as a Gaussian.


So. We'll say, all right, so the our our kind of default assumption on the Z variables is that they're that they're Gaussian here.


And we're going to force basically going to force the encoder to come up with encodings generally over the data set that are Gaussians that are conformal to our prior.


So here we say specific prior PZ.


I didn't mean to cross that out. Right.


So this second term enforces the the encoder to produce things that are Gaussian.


Specifically, if our prior is, let's say. Zero zero mean unit variance Gaussians, it's going to enforce that.


The first term here. Is different.


The first term makes the image that has been input to the variational encoder and the image that has been output close together.


Again, this is a probabilistic. Lost.


So what we're going to do here is we're going to take expectations.


So the KL distance is also an expectation, by the way.


We're going to take expectations over PX, which is the distribution of the data.


And also over Q and Q is again our encoding mechanism.


And we're simply going to punish the or we're going to maximize the log probability, which is equivalent to minimizing the negative log likelihood, which you might be familiar with of the data given the Z variables.


So this is an expectation over Q given X.


So what that means is basically we want the the probability. Of this original data point, we want.


Here we output X tilde. We we want this to be close to X here.


So what we can say is we want the probability that our model outputs X.


Which has been the original input, right, given this particular Z that it produced to be high.


As an expectation of Q. Of Z given X.


So is it the cryptic, but it means here I input X into Q.


I get out Z. And when I have the Z, what I produce here is what I produce.


The likelihood that X, the original image, these are the same is produced, should be high.


So that's a variational autoencoder. I simply encourage the latent representations to be close to my prior, which is often Gaussian.


And I encourage the output to be similar to the input, which I do by encouraging the likelihood that the output is the input.


All right, so cool. So what's that have to do with disentanglement?


Disentanglement is property that now I would like to have in my model, which is that these these things here or we can also focus on these things here.


However you want to view it or these things here, these latent things that my encoder outputs somehow give me information about data in a way that's disentangled.


What that means is I've already I've made an example that's already disentangled.


Where I said let's say we have images of a cat of cats and the fur color is going to be one variable and the color of the eyes of the cat is going to be another one.


And the position in the image is going to be another one.


So these are all fairly independent, right?


And so if I change some latent factor, I can change them pretty much independently. So here this could be the fur color.


I can change it pretty much independently and cat will just have a different fur and so on.


What would be non disentangled representations would be, let's say one encodes the fur of the cat.


And the other one encodes the species of cat because these are these are highly, let's say, entangled.


So the fur color is highly dependent on what species the cat is.


And it's not really so they kind of you can you can imagine it as these things being correlated, but it's slightly different.


And there are there's not an agreement on what disentanglement means really.


We just kind of imagine data is somehow entangled and we want to kind of pull out these disentangled factors.


So what they focus on here and the easiest the easiest measure here is the following.


I might want to have some space. All right.


So the easiest measure of disentanglement that is come up with here is the following.


It's an assumption. The assumption is let's say there's data X.


Right. We'll call it random variable. And we know we know we assume that this data is generated by a bunch of latent variables.


Z1, Z2, Z3, which are independent, which means that and the technical thing for this is that the P of Z,


which is all of them, can be factorized into P of Zi.


So they are independent and these kind of determine independently the data X.


Now, what does that disentanglement when my model has produced a disentangled representation means?


I now have a model, some model M, which is going to give me a representation of X.


And the representation, as we saw before, could be these things here.


That's the representation. Specifically what these people do is they say,


OK, the mean of the distribution that my encoder gives me, that's the representation of X.


Right. So this gives you a representation of X from which you then might want to reconstruct X over here.


So the important thing is when is the representation disentangled? The representation is disentangled in the easiest sense if the following holds.


When I change Zi, so I introduce a delta to Zi to any of these three,


that means that in the representation of X, which we're just going to say,


so if there's three dimensions of Zi, we just assume kind of we know that and we also make the representation three dimensional,


then exactly one factor in this is going to change.


So if I change one factor of the true underlying distribution, which is independently,


which all the latent factors are independent, then only one factor in my representation changes.


So if that's the case, then kind of I can be fairly sure that I've captured the true latent structure of the data.


Right. If one of the, if I change one of the Zi here, let's say I change Zi three and only then R3.


So I change Zi three, let's say I have access to the true underlying distribution.


I ask the world to give me a picture of a cat that where the fur color is different.


And then I put it, I get a data point and then I put it through my model.


I get a representation and only from the cat that I had before,


only one of the factors of my representation changes. Then I call it disentangled.


Then I can be fairly sure, okay, my representation, this dimension of my representation captures the fur color independently of the other factors.


All right. So that's disentanglement. And you notice it requires actually access here to the true distribution of how the data is generated by the world.


So this is something you generally don't have, but it's a technical notion. So you can certainly postulate it.


And it's a nice framework. And this paper basically proves that generally learning disentangled representation in that way is impossible.


If you don't have some, if you don't make some assumptions, some a priori assumptions on your data and your model.


So this is a theorem here and we see here P is any generative model which admits this factorization.


Right. That's what we talked about. The true underlying generative process is independent in its constituents.


That means there's a bunch of latent variables. They independently from each other produce a data point.


Right. X is the data observations. Then there exists an infinite family of bijective functions.


Right. Such that this and this and this and this. Okay.


What that means is so this thing here basically just means that the distributions agree.


So the overall distributions, let's say that it's not exactly that, but the posterior distributions, let's say the data looks the same.


Right. That what comes out of the process looks the same.


So there is there is functions that transform the latent distribution into some other distribution, but they look the same in cumulatively.


All right. And then this part here means you'll see the derivative of f i of u with respect to some u j, which you'll notice i and j are different.


And this means that basically the dimensions are entangled.


It means that if I take the derivative of one entry in the function output and I derive it by another entry, then I get a non-zero derivative,


which means that this u j influences f i, which basically means that I can produce, I can take the z,


I can transform it in so z is independent.


So it means the i-th dimension has no influence on the j-th dimension of the output.


And I can transform it into something where that's no longer the case, where the i-th and the j-th dimension very much kind of are entangled or covariate.


So this means I can take the z that that's kind of everything is independent. I can transform it into something where everything is dependent.


And they give a nice example here. So they say, let's say we have Gaussians in two dimensions.


So we have one Gaussian here and let me see if I can draw this one Gaussian here, right, in two dimensions.


They're completely independent.


What you'll find is that the kind of distribution overall has iso lines like this, right?


It gives you kind of a hump in the middle, two-dimensional, you can maybe imagine like a bit of a mountain in the middle.


All right, so this is what you, this is the kind of output distribution.


If you don't know about the underlying factors, you simply see the cumulative distribution, which would be the big P here.


All right, now we transform this into with F and F is simply a rotation by 45 degrees.


So two new axis, this and that. And again, our two Gaussians are going to be transformed of these.


Right. So these are not, these are not disentangled anymore.


Well, in the notion, I can't say it like this, but this is easiest to say. So these are kind of, now that it's rotated in terms of the original coordinate system, which would go like this.


These very much depend on each other, right?


The jth dimension, the ifth dimension depend on each other, because if I sample from one of the Gaussians, I need now basically two coordinates to describe where it is.


Or one isn't just, so if I sample from one Gaussian, I need both the coordinates.


But the cumulative distribution or the, that is still going to look exactly the same.


So it's again, so it's basically an isometric hump in every direction.


If I rotate that, it looks exactly the same. This is the P here.


But now the ifth dimension and the jth dimension very much influence each other.


And interestingly, if you now look at disentanglement, if I just have, if I now produce data x here, x1.


And here I produce data x2. And both go through my model and give me our representation of x1 and the representation of x2.


I have, without seeing the underlying structure, I have no idea which one of those two it comes from.


And thereby, I have zero chance, basically, it's a lucky guess which one it comes from.


And there's an infinite family. So I will never find the true underlying distribution here.


And thereby, I will never be able to satisfy this property that if one of the z changes, then only one of the factors of my representation will change.


Because if I say, oh, well, obviously, this is the case, then I'm going to make a different model.


And if I say, well, this is the case, I'm going to make a different model.


I don't know which one it is. I have to choose one and it could be the other one.


So I'm bound to be wrong in this case 50 percent of the time.


But if it's an infinite family, I'm bound to be wrong every time, basically.


So that's what the theorem basically says.


I can't decide on the true underlying distribution.


There's an infinite family that transforms it into it.


It transforms every distribution into some other distribution that has basically complete opposite properties of entanglement.


I need to choose one and I will never choose the right one because I'm not that lucky.


And thereby, I can't do representation learning that's disentangled.


All right. So that's the main claim of the paper.


And there is a lot of experiments here.


So what the paper also does is they do some new data sets and they test a lot of a lot of architectures.


Basically, they say just because it's theoretically impossible, it's not impractical because we can actually make these underlying assumptions.


Like we can make some assumptions on the data there and then we kind of can attempt to do disentanglement learning.


So they do these data sets and they test different VAEs architectures on it and they basically establish where more work should go.


So that's kind of the rest of the paper.


I encourage you to look at the rest of the paper.


I just wanted to give a quick introduction to VAEs and to disentangled representation learning.


Loading in your own data - Deep Learning basics with Python, TensorFlow and Keras p.2

What is going on everybody and welcome to part two of our deep learning with


Python, TensorFlow, and Keras tutorial. In this tutorial what we're going to be


talking about is how to load in an outside data set. The outside data set


we're going to use is this cats and dogs data set from Microsoft. It was for


initially a Kaggle challenge and the idea is to take pictures of cats and


dogs and then identify them by feeding them through a neural network and have


the neural network say whether or not that's a cat or a dog. So go ahead and


download that data set and then once you have that data set let me pull up an


example here. What you should see is like this. So you should get two directories


these two I've added these two things I've added in but what you should have


is cat and dog and then in here you should have some like images of cats and


dogs in this case bunch of dogs. So each one has like 12,500 samples so you


should have plenty of examples to teach a model what's a cat and what's a dog. So


go ahead and download those extract those and then we'll come over here and


we will get to work. So we're going to import first of all NumPy as np we're


going to import Metplotlibidontpyplot as plt we're going to import os we're


going to import cv2 and from and actually just cv2. If you don't have


NumPy pip install NumPy if you don't have Matplotlib pip install Matplotlib


and if you don't have cv2 you will need to do a pip install opencv-python.


Alright once we have those basically I'm gonna use matplotlib just to show


the image we're gonna use OS to iterate through directories and join paths cv2


to show or I'm sorry to do some image operations and then NumPy to do


various array operations. So the first thing we're gonna do is specify a data


directory my data is located in my X files under datasets and pet images then


we're gonna have categories the two categories we've got to deal with here


are dog and cat I can't leave those different and in fact we should probably


just double quote since we double quoted the other ones. So now what we want to do


is iterate through all of the our examples of dog and cat so the way we're


gonna do that is for category in categories what do we want to do well


we're gonna say path is os.path.join data dir and whatever that


category is so basically this just gets our us into our basically the path to


cats or dogs dir. Then we want to say is for image in os.list dir that path so


it'll just be a bunch of these images basically with it are named by just


number once we have that we can just iterate through all those images so the


images are we can convert them immediately to an array with cv2.mread and


we can read those with os.path.join and we're going to join path and image now


and that's the full path to that image then what we're going to do is we're


going to convert it to grayscale so we read in that image and then we say cv2


cv2.mread underscore grayscale so we're gonna convert it to grayscale


because one you know RGB data is three times the size of grayscale data and I


just don't think that color is that essential in this specific task and a


lot of identifying tasks it is but at least in the you know the difference


between a cat and a dog yes they have a lot of color but does the is the color


the differentiating factor between cats and dogs I don't think so if it was like


you know dog versus some reptile or something like that then yeah probably


you'd want to bring in color okay so once we've done that the next thing that


we want to do is like we can at least we can graph this and look at what we're


dealing with just to make sure it's what we expect so PLT dot M show image array


cmap equals gray again the only reason I'm using matplotlib here is because I


don't know how to do like inline in a Jupyter notebook with cv2 I'm sure


there's a way if somebody knows it go ahead and leave it below then I'm just


gonna throw a break here in a break just so we can look at this picture real


quick so as you can see it's a grayscale image of a dog no surprise there it's


kind of what we expected also our data this is what our data looks like image


array okay just a bunch of numbers now what if we didn't convert it to


grayscale so in this case you can see it's just a bunch of number you know


pixel values here in this 2d array what if we didn't do grayscale though and


what we just did this blue dog now no longer is it 2d because these are actual


RGB actually probably BGR I believe is how cv2 reads things and that's why this


is all why the dog is a blue in the photo anyway we're gonna we are gonna


keep grayscale though and just take a note you know like what how that


changes your your actual data so for example we could say imagery dot shape


for example there and it's a 398 by 500 which brings us to the next problem we


have which is you can even tell like some of the all these dogs are like


different shaped photos some are landscapes some are portraits some are


square and we really need everything to be normalized at all you know if at all


possible there are ways to have variable sized images to make


classifications on but in the interest of keeping things as simple as possible


we'd like to make everything the same shape so that's what we're gonna do next


now we have to decide on a shape so for example what if we say image size 50 so


maybe we're gonna try every image is a 50 by 50 so the way we would do that is


just new array equals cv2 resize and we resize the image array and then we do


image size image size and that's our new array and we really should look at it so


in show new array and then see map for the color map oh my gosh can we get this


please gray and then PLT dot show so I can still tell that's a dog but


eventually we can't right if I we do ten make it a ten by ten I can't tell that's


a dog I don't think anybody can we go with 20 still probably not maybe though


you might be able to get away with it at 30 it's still pretty hard but now you


can start to see like you know like the forearm or I guess the wrist you know


the area after the wrist the hand of a dog I guess I don't know anyways that's


usually longer in dogs so I could make this classification at this point but


you know at 50 I'm pretty comfortable but you do have to be careful because


this dog takes up quite a bit of the image whereas some of these might not


like for example I'm sure I can find one eventually this one's a pretty small he


blends into the bench quite a bit most of these are pretty pretty well done


actually but sometimes you know it won't it'll be smaller part of the image and


it'll be a little harder when we make it a small image look at this camo dog


anyway so keep that in mind I'm gonna I guess I'll stick with 50 we'll see how


that goes so once you decide on the size that you want to go with let's go ahead


and create our training data set so I'm gonna say training data equals an empty


list and then I'm gonna start this function that I'm gonna call create


training data and I'm gonna give myself I'm just gonna say pass I'm just gonna


give myself some space here there we go okay create training data and what we


want to do is now iterate through everything and build it the data set so


I'm just gonna take this copy and then come down here paste it in tab this over


now the next thing we need to do is we our neural network kind of like in our


MNIST data set right did we we have to map basically we've got the features as


numbers but our label our classification is not yet a number right we can't map


things to a string dog or a string cat right we need to map things to some sort


of numerical value so we're gonna say 0 is a dog 1 is a cat and the way we can


do that is we can just get the index value of dog and cat and make that index


value in that list the arbitrary classification it doesn't matter which


one is the one in which one is the zero it's just you have to convert to a


number so the way we're gonna do that is I'm just gonna say class underscore num