And it was just kind of well motivated.


Rethinking Attention with Performers (Paper Explained)

So people thought that must be the way to go.


But then of course, turned out that relu's are much easier, much more stable, give much


better results and so on.


Don't saturate all these cool things.


This here is kind of the it feels like the same thing because right now we're doing this


softmax thing in attention.


And it's very important because it normalizes the attention matrix, right?


It gives you kind of this thing that comes out as kind of a distribution over the inputs


and so on.


So it's well motivated.


And you may be able to see, but also as the sigmoid is, it's kind of has this exponential


thing in there.


And the favor algorithm is going to approximate this softmax thing, but it can be used to


approximate much more.


So maybe, you know, we're going to find that if we swap out these, the non linearity in


there, we might be able to build much better transformers, or whatever the model will be


called performers, I guess they already do this here with relu's in this very paper.


So the performer is going to be fully compatible with regular transformer, and with strong


theoretical guarantees, unbiased or nearly unbiased estimation of the attention matrix,


uniform conversion and low estimation variance.


So the difference of the performer here is going to be that there have been methods before


that decompose the attention matrix into low rank matrices.


But those either don't work, or they kind of rely on, on priors, like the, you're assuming


that your attention matrix has a certain structure.


If it doesn't, it sort of fails.


This method here is going to be an unbiased estimator.


And it's going to sort of converge to the attention matrix if you add more of these


random features.


Okay, they this is fed here, like provably not relying on any priors fully compatible


with regular transformers, which means that you can take a transformer checkpoint and


sort of plug it into this framework.


And then you just have to fine tune a little bit to sort of use the checkpoint of a regular


transformer, which is pretty cool, right?


So we'll go through the paper, it's quite a heavy paper, it's quite a math heavy paper,


we won't go through all of it.


I just kind of want you to get the idea of what these performers do, what the reasoning


behind it is, and how you might be able to kind of work with them or extend them where


it's where it's going from here.


As always, if you like content like this, don't hesitate to share it out and tell your


friends about it.


Alright, so the problem with attention, or the problem with transformers is that I've


done this a million times, and you can go look it up.


But if you want to map a sequence of layer L into a sequence, or a set or whatnot of


layer L plus one, and you need to compute these attention weights, right, so the attention


weights are going to be from each token here to each token in the next layer, you're going


to compute one of these weights.


Alright, so there is, there is this matrix is called a the attention matrix, and a is


going to be of size L by L. And that is a problem if you have long sequences, right,


you can already see this.


So the way that this a comes to be is that conceptually, the upper layer, like it's all


the same layer, but conceptually, the upper layer emits something that are called queries,


and the lower layer emit something that are called keys and values.


Now, the keys and the queries, they go together into matrices.


So it multiply the keys and the queries, then you run this through and this is the


problem you run this through a softmax non linearity to basically get a distribution


and then you multiply it by the values.


So the query key matrix, this attention matrix, it will tell you how to aggregate the values.


Alright, if it weren't for the softmax, so you can you can think if if these if these


the dimensions of the queries and keys and values, let's call it small d, then the dimensionality


here will be something like here you'd have L by D, here it have D by L for the transposed.


And then here you'd have L by D. So because you have to do the softmax, you have to compute


this first, which gives you this L by L, which is the terrible thing.


However, if you could, if you could, if somehow decompose the softmax operation, you could


first do keys and values, which will give you a D by D matrix.


And then you could multiply it by the Q matrix, right, which would be much, much, much more


easy if D is smaller than L, certainly wouldn't grow quadratically in L, it would just grow


linearly in in space and time.


So here, this is formulated out the attention mechanism right here.


The attention mechanism is made of queries, keys and values.


And it's given by this formula right here.


Now there is a bit of a technicality, I wasn't exactly correct in what a is.


So here, they, they say, they, I called this thing here a, okay, they are very specific


what they mean by a, by a, they simply mean the exponential function of the normalized


queries times keys.


And then to get the actual softmax, you have to normalize by here, so D, which is so you


see, the inverse is made here D is constructed from a and normalizes a, but the normalization


is of secondary importance.


The important part here is that this exponential cannot be easily decomposed, right?


It's not like you can decompose the inner multiplication into two exponentials or something,


otherwise, the problem would be solved.


So what is this paper doing?


This is exactly what I just said was impossible.


So you have this matrix a right here, and you multiplied by V. Yes, again, forget about


the normalization by now.


It will decompose a into the query, the q prime and k prime.


Now they are called prime because they are not the queries and the keys.


Because we've just said the queries and the keys, they go into the exponential.


So it's going to be that k, sorry, q prime times k prime transposed is going to be approximately


equal to exponential function of q times k, maybe normalized by square root of D. But


you can see that this here isn't decomposable.


And yet they decompose it.


And the question is how because there have been papers before that try to decompose the


attention matrix.


I think linformer maybe, and there is also the reformer, which uses LSH and so on.


So there have been a number of tricks, but they all don't perform as well, which this


paper also shows empirically.


And they all rely on certain assumptions of the attention matrix.


And they all are not unbiased estimators in general, this paper is going to be an unbiased


estimator.


And they do this via sort of a kernel framework.


So what they they first of all, they make this problem more general.


They say we have our attention matrix A, the ijth entry is going to be the query i, the


key j, and some some kernel function of that.


Okay.


In our case, this is going to be the right x of query times key, like this, sorry, the


other way around.


query transpose, transpose, query times key, the inner product of that.


However, you can think of any sort of kernel function.


Okay, so yeah, if I'm not going to try to explain more details into kernels, we had


a fantastic machine learning street talk.


So if you don't know about this, this is our podcast, machine learning street talk, where


Alex Stanlech explained kernels in great detail, and with very, very precise language, and


very understandable as well.


So what I'm going to say is that they allow you to do things like this.


So you can think of kernels as kind of connecting two things, they allow you, they represent


an inner product in some other space.


Okay, so the kernel function of two inputs right here will be equal to some some inner


product of the two inputs when pulled through this function phi right here.


And that's what we're going to use.


Now usually, usually, when you learn about kernels, you do it in this way, you say, we


would like to compute in this very high dimensional space.


But we can't, we can't do inner products, we can't map this function phi explicitly.


So we're going to instead use this kernel right here, this kernel function.


And that's going to be equal.


If you pick the right kernel function for the particular phi.


In this paper, we're going to do it the other way around.


Because we say, well, this thing here is this is the softmax function.


And that's just a beast, right?


We can't possibly compute that.


However, if we could find out what inner product that corresponds to, what other space, we


could just go to that other space and perform an inner product.


And this thing over here is linear, right?


This is a linear function.


This here is the nonlinear function, this is our softmax.


So you can see that by going in this way, by finding what is the higher or the the phi


function for the softmax kernel, we can construct all of this attention business in a linear


fashion.


And that's what this paper does.


What it allows you to do is it allows you to find these q and k q prime and k prime


matrices such that as over here, right, this is the kernel function.


And this here is linear.


And then you can simply first multiply k by v, or k prime by v.


And then you can multiply q by k.


And that will alleviate you of having this giant attention matrix.


So how do they do it?


If you again, if you know about random Fourier features, this is going to be very much or


very similar thing right here.


They're not going to explicitly construct the high dimensional space such that this


is exactly equal, but they're going to construct an approximation.


And the approximation, you can make arbitrarily good.


And you do that via the following you say, so here, you see, this is how do I have to


map something into this other dimensional space, where this whole softmax business is


just a linear operation.


So what you would do, ultimately, is you would take your queries, you would map it through


this phi.


Okay, and you would take your keys, and you would also map it through this phi.


And this will give you query prime, and this will give you key prime.


Right?


So and then in the higher down in the higher, lower, whatever dimensional space, you would


take the inner product.


And the inner product between the two is going to approximately be as if you had multiple


the inner product is going to be approximately as if you had taken the original q and k,


multiply them and put them through a softmax.


How do we do it?


So here we define what the function needs to look like, sit such that this holds the


function again, they go very general here, the function in general is going to look like


the following.


So you have one function here that's called h, that is a function of your input.


And it's in front, it's a deterministic function of your input.


And you also have a normalization factor.


So this is kind of it's kind of a factor in front of it, you see that here comes a vector.


So this is a vector, right, we are mapping this to a some dimensional space.


And this is the vector.


Now, it's a bit you have to pay a bit of attention.


So inside this vector, you have l different sub vectors, they're all concatenated after


each other.


Okay, so you have CC here, this, where the F, this is f one, and then f two, f three,


f four, and so on until f l.


Okay, so you have all these sub vectors.


It doesn't matter, ultimately, you just concatenate them all, but it's important to just keep


in mind, within each of these vectors.


Within each of these sub vectors, you always have the same repeated term, okay, you have


this w times your x.


So the inner product between w and x, you can see there's w one through w m or omega,


I think it's an omega.


And again, in the in each sub vector, you have this repeated.


So what are these omegas?


First of all, the omegas are random vectors drawn for from some distribution.


Now, in practicality, this is going to be a normal distribution, like this one here,


an isotropic normal distribution.


So and the other part here is what are the F's?


So the F's, f one through f l, are going to be functions, deterministic functions.


So in a an example they gave right here, f one is the sine function, f two is the cosine


function.


And then you have to specify h and h in this particular example is one, but it can be a


function of x here, it's just the identity.


Sorry, not the identity, the constant function one.


So let's break this a little down.


So we have x, and x is going to be a vector x, as I said, x is going to be like one of


the queries here, or one of the one of the keys here, one one of them, right, one column


or one row, however you conceptualize it.


And we wonder how do we want to map so x?


x is going to be some vector, okay, then this is an ugly vector.


Let's draw it like this, x is a vector.


Then what we're going to do is we're going to take a bunch of omegas.


Now it's important that the omegas are random.


So they come from this isotropic normal distribution, but they're going to remain the same throughout


the algorithm.


So this is a method to resample them.


But just conceptualize that at the beginning of the algorithm, you choose these omegas,


and then you fix them.


Okay, so the omegas are going to be also vectors, which are random, just a bunch of random vectors.


Okay, let's take three.


What you're going to do is you're going to compute the inner product between your x and


each of the omegas.


So inner product in your x and each of the omega.


So this gives you omega one x, omega two x, omega three x, the dinner product, this is


going to be this is this is going to be numbers.


And then you're going to have a collection of functions.


So these are going to be functions, maybe function one is going maybe here, the sine


function function two is going to be the cosine function.


Okay, now you're going to take each to make a table, you're going to take each of these


products you computed, and put them through each of the functions.


So this is going to be sine of w omega one x, cosine of omega one x, sine of omega two


x and so on.


Okay.


And then you're going to take this table, and you're going to flatten it to a big vector.


So sine omega one x, cosine, or no sine first, the ordering data doesn't matter, as long


as you always do it the same omega two x, and so on, right until you have here cosine


of omega three x.


So that's the vector they're constructing.


And these are those random features.


So this here is going to be the vector that you're constructing, what you do is basically


geometrically your x is like somewhere here.


And it's a bit hard to draw in low dimensional space because you don't get the intuition.


But this is if this is your x, you're going to choose a bunch of these omegas, these omegas


are going to be randomly sampled from a uniform Gaussian.


So this is omega one, maybe omega two, omega three, omega four, and you're going to compute


the inner product between between any of the two.


Okay, so you're going to be essentially computing the projections onto each other or the angle


however you want to conceptualize it, the angle of this to each of the two of the omegas.


And then you're going to make a features out of these angles, right.


So this will sort of tell you how your vector stands to each of these random features.


Now the reason I say it's difficult in low dimension is because now I have more omegas


than the dimensionality, which is two right here.


And this makes no sense, right?


As soon as I have two vectors that are not collinear in two dimensional space, I can


if I project x onto them, like like this, sorry, like if I project x onto both of them,


I already have x fully represented, right?


There's no need to have more of them.


However, if you are in super duper high dimensional space, and you don't you don't have as many


features, then you get some interesting approximation properties, namely, so this was an example,


right?


We don't always have the sine and the cosine here.


This is purely an example, you can only have one function, you see, like this f one, you


don't need two functions, you can have one, you can have many, okay.


And you can choose how many omegas you sample, that is a parameter.


So yeah, you have a couple of choices, I want to make it clear the choice of h.


So the choice of h, and f, they go hand in hand, the choice of h and the f's determine


what the phi function is, okay.


So the choice of hf determine which kernel function this phi function corresponds to,


if you construct it like this.


So by choosing the correct functions, you tell the function which kernel you would like


to approximate.


And then by sampling the omegas, the more omegas you sample, the more accurately you


approximate that kernel, and then you can give some approximation guarantees, as they


say.


So the softmax kernel is given by this thing here, which we've already seen, okay.


And now how do we approximate the softmax kernel?


And they show that right here, the softmax kernel is approximated by this thing right


here.


So it's a bit of a ugly formula, and it contains this Gaussian kernel, the Gauss kernel.


So they say, if we choose h equals to one, so just a constant factor, and this f1 and


f2 to the sine and cosine, and in if we choose d, the distribution to be a normal distribution,


isotropic around the mean, this is the Gaussian kernel.


And then we simply have to choose h differently, this factor in front to make it into the softmax


kernel.


So as long as we put this factor in front, you can see that this here represent, this


here represents an inner product, right?


So you have to kind of think of decomposition.


So if you put, you can see f1, the sine f2, the cosine, which is this makes it the Gaussian


kernel, and then this factor in front of it here, two for h, this makes it now the softmax


So if we choose h and f, like this, then when we map our queries and keys through, if we


map our queries and keys through the phi function, and then make the inner product between them,


okay, like here, that will approximate depending on how many omegas we've sampled better or


worse, they approximate the result as if we had multiplied them first, and then put them


through the softmax function.


Alright, so this, you can see how this becomes much easier, because we can independently


put them through the phi, okay.


And then it's just a linear operation, which allows us to do our trick where we multiply


k and v first, and then multiply by q instead of the other way around, which we're forced


to do when we apply the softmax.


This was a long, a long way to get here.


But I hope you're with this.


And this is, this is pretty straightforward, actually, so far.


Now renormalization, we can take care of that easily.


But there is a problem, and this is, they argue, this hasn't been proposed so far, because


it doesn't work like this.


So even though you approximate this kernel fairly well, it's a bad approximation.


And they say, here, there is however, a caveat here, the attention module from one constructs


for each token, a convex combination of value vectors with coefficients given as corresponding


green renormalized kernel scores.


That is why kernels producing non negative scores are used.


Applying random feature maps with potentially negative dimension values leads to unstable


behaviors, especially when kernel scores close to zero, which is the case for lots of entries


of a corresponding to not relevant tokens are approximated by estimators with large


variants in such regions.


This results in abnormal behaviors, e.g. negative diagonal value renormalizers, and consequently,


either completely prevents training or leads to sub optimal models.


So what they're saying is that when you use softmax, you always, always get positive values,


right?


So if I have a bunch of vectors, or a bunch of numbers, this is, you know, positive number,


negative number, very positive number, negative number, and I run it through a softmax, I


will get out a distribution, right, like this, or really big, sorry, the softmax will scale


that up, I will get out a positive district, like a kind of a histogram, okay.


And now I'm trying to approximate this by this formula right here.


And you can see these are these are vectors, which gives me sine and cosine coefficients,


and I linearly multiply two vectors together, which definitely means I can get negative


entries and so on.


So the renormalization then has to somehow maybe take care of that.


And it says especially, especially around zero, when the original softmax matrix would


have values close to zero, this approximation is really bad and has high variance.


And they also argue a lot of attention vectors are close to zero, because we know that attention


is sort of sparsify just by the fact of what how the softmax works, it exaggerates the


largest inner products, and it really dampens the low inner products, okay.


Actually I might not even have done this correctly here if it's, if it's very negative, I'm not


sure.


In any case, they say that's why this doesn't work because it has such high variance, it's


a good approximation, but has such high variance in the wrong places, around zero where most


values are.


So they call this the SM, the softmax approximation with m sampled features, trig because it uses


the sine and cosine functions.


And now they're trying to remedy this.


And for that, they propose a different decomposition, so a different approximation to the softmax


kernel.


And they say we can also decompose the softmax or approximate the softmax kernel with the


following formula.


And I look, I, I'm not going to, they have a proof for this.


But this is the formula.


You sample again, you sample these things, and then you perform this inner, this is the


inner product that approximates the softmax kernel, okay.


And this is further, you can reduce this to this thing right here.


So it's a deterministic matrix right here, this, which is given by that.


And it's this cos H, so cos H is the hyperbolic tangent, this can be this is so cos H of x


is e to the x plus e to the minus x divided by two.


Okay, so this function approximates the softmax.


And that's just something you'll have to take from their proof.


However, you can now see that this can be fairly easily represented as an inner product,


you already see it here, right?


This you simply, this is the part that comes from x, and this is the part that comes from


y.


And if you want to note this in our in our notation earlier, again, we use the distribution


that we sample the omega from is going to be a normal distribution.


And our functions are going to be this h function is the pre factor, it's simply going to be


the made up of the norm of x and put through the exponential function.


And then we have two options actually, right here.


I don't even know why they put the first one.


But the second option makes more sense.


And there's a bit of a more of a fact right here.


So you have two functions, there is x of u and negative x and x of negative u, as the


two function, you remember, this is where we had sine and cosine before.


Now we have x u and negative x, sorry, x of negative u.


And we can quickly check that this gives us the same thing.


So this h, these h functions, if we inner product them, that's going to be to give us


the this, what is that even lambda?


Is that a big lambda matrix right here.


And our vector, let's just say we sample one single omega, right?


So we have our x, we sample one single omega.


So x is going to give us a vector with two sub vectors, right, since we have two functions,


each sub vector is of length one.


So the first is going to be e to the omega x.


And the second entry is going to be e to the negative omega x.


If we put in y through the same or as instead of x and y, you can think of queries and keys,


that's going to be omega y e to the negative omega y.


If we now take the inner product, that is going to give us and I'm resolving the exponentials


already right here.


So that's going to give us e to the e to the w x plus y.


And here is going to give us plus e to the w, or sorry, the negative w x plus y.


And that's the, you know, there's a normalization factor.


That's why the square root of two is here, right?


So that comes in somewhere here to give us this normalization factor.


So this is exactly the hyperbolic cosine of omega times z and z is x plus y that they


say it somewhere.


Yeah, here.


Okay.


So, if we choose f one and f two to be this x view and x negative view, then we get if


we perform the inner product, we get out exactly this formula number seven right here.


So this is this.


And that is an approximation of the softmax kernel of the softmax function.


It's just a different approximation than before.


And the cool thing about this approximation is that the approximation itself only ever


has positive values.


So these vectors here, you can see the x, the vectors here, and there's of course, a


four a factor in front of this right here, which is going to be also an exponential.


These are all exponential.


So these are all going to be positive features, which is very, very nice.


And they also show this theoretically.


So here, this kind of funky graphic shows this, this is the ratio of the approximation


mistake, okay, the ratio of the approximation mistake of the of the original approximation


that we discussed, and this new positive approximation that we just built right now.


And you can see that in parts here, it's fairly similar.


So this I believe, so r is the ratio.


So it's fairly flat, right here, but there are parts where it just shoots up, right.


And in fact, they can prove that you can see this also right here.


So the error of the trig approximation that shoots up, while the positive approximation


just stays flat, or flatter in these regions, they can in fact prove that the the error


of the Yeah, so you see the error.


If the softmax values go to zero, so that's the problematic regions, the error of the


trigonomic approximation can go to infinity, while the error of the positive approximation


goes to zero, they have a number of theoretical results in here, I think that's one of the


main ones, the fact that the this approximation succeeds where the other approximation fails.


Really quickly, they also have this variant here, where they don't build a two vec, a


two vec or a vector of two sub vectors, but just one with just the exponential function.


And that is the same thing, because of course, if you sample w, you're going to have sorry,


omega, if you sample omega, you're going to have omega as much as negative omega, I believe,


and and thereby, in expectation, you're going to get this hyperbolic cosine again, I think


that's the reason why but this lower, this lower construction here gives you the hyperbolic


cosine.


Okay, so pretty cool, we simply use this approximation, we run our queries, right, this, their queries,


and our keys through this.


And again, we ideally use more omegas than just one, maybe a bunch, the more we use the


better, we obtain a linear function that approximates the softmax function, the more we sample,


the more it approximates, it's unbiased, and so on.


They have a bunch of variants of it.


So variant where you normalize the omegas, which gives you the regularized softmax kernel,


which is not a softmax anymore, but it's a regularized softmax, and they can approximate


this.


And pretty much the same way.


Except instead of a normal distribution, you use a uniform distribution right here.


And they have a bunch of other things, namely, one other improvement is that so far, we've


simply sampled these W's, okay, we sampled the W's from a normal distribution, like this


here.


They say we can improve even further, namely, we can strictly improve with this gives us


an estimator with strictly lower variance, if we make sure that the W's we sample are


exactly orthogonal.


So they're already approximately orthogonal if we sample them from a high dimensional


space.


But if we make sure that they are exactly orthogonal, sorry, then they are giving us


an even better approximation.


And you can do that by this procedure called the Gram Schmidt orthogonalization or Gram


Schmidt renormalization procedure.


That's a it's a pretty easy procedure.


And it doesn't mess with your unbiasedness.


Whenever D is an isotropic distribution, isotropic just means the same in every direction.


So like a standard Gaussian would fulfill or a uniform would fulfill this thing as long


as it's centered.


I think maybe even if it's not centered depends on how you renormalize.


I'm okay, this is irrelevant.


But if you if you make them exactly orthogonal, say this leads to the first theoretical results


showing that orthogonal random features can be applied to reduce the variance of the softmax


or Gaussian kernel estimators for any dimensionality D, rather than just asymptotically for large


enough D, as it is the case for previous methods, and leads to the first exponentially small


bounds on large deviations probabilities that are strictly smaller than for non orthogonal


methods.


Okay, so we're going to end up with a thing that's strictly smaller.


So bounds that are strictly smaller than if you don't use orthogonality.


It only thing it requires is that m is smaller or equal to D. So the number of omega u sample


is going to be smaller or equal to the dimensionality that the original space operates in, which


they say this will be the case in all our experiments.


Okay, and again, these are exponentially small bounds, which is pretty cool.


I guess for you, the end user, it matters that this works.


And if you use all of their tricks with the positivity and the orthogonality, so by the


way, this here is where they show that see the or orthogonal MSE, the mean squared error


is smaller than the original one minus some thing.


And as long as the something of course is greater than zero, you're going to have something


that's smaller.


Okay, they prove a bunch of other things again about this kind of this regularized sorry,


not regularized.


I forget it's the where do you divide by the norm.


In any case, they implement this in jacks.


Oh, great.


Wow, cool.


I have no opinion on jacks.


But they have the code released.


And I'll of course, link to it.


And here you can clearly see so this is a log log plot, where you have l the size of


the input, and the number of seconds that it takes to go forward and backward over here


in the model.


And you can see the x here, the x is the baseline, where you simply bypass the attention matrix,


you simply take the identity function and just return the value matrix.


And you can see that the performance, the performers, they scale fairly well with that


baseline.


And in fact, they scale at the same slope, which is the important part right here, you


can really see that this is linear slope where the transformers, which are the dashed lines,


they all curve upwards, which of course, is that that quadratic requirement.


The same in the backward pass, I don't know if they continue curving, I think it's also


a straight line in the log log plot, but the slope is two instead of one, like the linear,


like the linear models.


Again, the comparison is only important between the baseline and the lines that you're looking


at, if they have the same slope, they scale the same as you get higher.


Look at it, this is log l, right?


So this is these, these are now two to the 18th tokens.


And I believe this is done on one GPU.


Yes.


So an out of memory error on a v 100 GPU.


And this is pretty good.


This is pretty good news for everyone who wants to run the the performers in in kind


of a low resource environment low reason with low resource, I mean, like a deep learning


GPU instead of 1000 TPUs, which is pretty cool.


They they also show the that their method is better than the kind of so the orthogonality


is better than the IID features, and then of course, the positive IID features are better


than these original trigonometric decomposition.


And they show that this thing that you can take a transformer checkpoint, and you plug


it into the performer.


And you simply have to fine tune a little bit to get it to the performance that the


transformer was at, right?


This is, I believe this is the original training curve of the transformer.


So you know, it's not a fair comparison, because the performer starts from the checkpoint already.


At least that's how I interpret it.


It's not clearly written.


And they say, okay, over here, this trig thing works, this is the original approximation,


this even works.


However, if we do that on a bit more challenging, more longer sequences, data data set, then


you can see that the trig softmax, it just it just wax out.


That's this thing here.


And you actually need better these positive approximations.


That compared to the linformer here, which is pretty cool.


So the linformer, another, I've made a video about it, if you want to know about it, but


they also do random projections of the attention matrix.


But you can see that the linformer plateaus along with the performers, if you don't redraw


the random features.


So if you want in the performer, if you do it at the right time, you redraw these random


features, these omegas, you have to, you have to see where you can, you can't just arbitrarily


redraw them between computation steps, but at the end of like a computation step, you


can redraw for the next computation step.


And if you do that, and even better with the regularized or the the normalized features,


you get to the same level of performance that a standard transformer would get.


But of course, without the quadratic requirements.


And okay, lastly, as I said, they've already, they've already swapped out the they swapped


out this non linearity by a ReLU.


So here they construct performer ReLU, taking F equals ReLU in equation five, you remember


what F was, F was the sine and cosine when we had the first approximation and F was the


x x of u and x of minus u.


The second one, and as I said, the big improvement in deep learning came when we swapped sigmoids


for ReLUs.


And here they've already, they're already trying swapping now this because they say,


well, so we have a method that we can basically plug in anything we want.


So they plug in ReLU because it's you know, worked well, and this again, it works pretty


well.


So they compare again, also with the reformer here with the linformer, as you can see, and


of course, they beat everything.


Now whether or not this method is going to be the next thing, like the thing that everyone


uses is to be, we don't know.


It's fairly possible.


It's pretty cool.


And it appears to be theoretically solidly grounded, but you never know from the experiments


of the single paper.


The broader impact statement much respect, they just use it to tell you how awesome their


paper is.


Like there's no mention on on on any kind of ethical impact, which I believe like I'm


all for these kinds of broader impact statements, like just kind of okay, research on transformers


is going to be better because now people have access to it.


It's backward compatible.


That's pretty cool.


It's applicable to biology and medicine because we can take longer sequences.


It's all like, yeah, I like these kinds of broader impact statement.


The last thing here is that you might be so the only problem is if you want to do this


causal attention, that if you want to do like a generative model, like a GPT sort of model,


you have to do a bit of a trick.


And that is because your attention matrix isn't the full attention matrix.


So you can't just decompose it.


It's this lower triangular matrix right here.


But since you have linear decomposition of this thing, you can do these kind of prefix


sums.


Namely, you can compute simply so you you you can compute the key one times value one.


And then you can compute key two times value two plus key one times value one.


And you compute key three value three plus key to value two plus key one, sorry, value


one, and so on.


You compute these things and these are all these are all the big where the L goes away,


right?


So we do that first.


And then we simply have to come along and we take q q one, multiply by key one v one,


we take q two, multiply by this and this q three will multiply by this, this, and this.


And you see, that's how you get your causal attention.


So you simply keep track of these prefix sums right here.


And then when the next q comes along, simply multiplied by all of the things that are above


it in the prefix sum.


That's how you get your triangular matrix.


So even that is solved.


A thing that I believe the linformer wasn't able to do with its particular decomposition.


I might be I might be wrong here.


All right, they have a bunch of experiments on protein analysis and so on, which of course,


wasn't possible, I guess before because it was so so heavy.


They also have like image net 64, as you can see right here, which is an impossible data


set for a classic transformer.


As I said, they have code code is in jacks, which is like this is it it's ugly code.


Let's be honest, but it's code.


So that's fairly cool.


And I want to point out the right at the bottom here is actually where the stuff happens.


So you can see that just quickly, you have here keys and queries are where is it?


Exact.


So queries and keys are going to be constructed right here.


So query prime and key prime are going to be pulled through this feature creator, which


implements these these kernels.


So these can be either as we said, these X or the relu's or the sine cosine, whatnot,


then you're going to multiply the queries and the keys, which gives you yet this W matrix.


And all that we need to do now is normalize it.


Okay, so we renormalize by constructing this denominator right here.


And then there's a whole block for the unit directionality, which you can imagine is pretty


ugly.


But the renormalization we constructed we reciprocal means we take the inverse multiplied


by the W and return the result.


This should be translatable into your favorite whatnot, pytorch or TensorFlow.


Maybe it's already been done.


I haven't researched that particular thing.


In any case, I invite you to check out the paper, the code, play around with the functions


used here as long as you, you know, use fun, you don't even you don't need to know like


these papers, they always know which kind of kernels their functions correspond to.


But you know, in SVMs, people just went went nuts.


I just plug in some functions, see what happens.


Probably nothing good, but it's possible.


Alright, so there was it for the performer.


I hope you gained something from this kind of an understanding of how it works.


And I wish you the best.


PAIR AI Explorables | Is the problem in the data? Examples on Fairness, Diversity, and Bias.

Hello everyone, so maybe you've seen my last video about this topic, but every few months


the debate about bias in machine learning models is resurfacing. And this time a tweet


by Karim Karr is sort of in the middle of it. And he says four things to know about


race and gender bias in algorithms. First, the bias starts in the data. Second, the algorithms


don't create the bias, but they do transmit it. Third, there are a huge number of other


biases, race and gender bias are just the most obvious. And fourth, it's fixable. And


what followed was what I thought was a pretty sensible tweet or thread about bias in machine


learning and in statistics in general and what to do about it, namely the plea for understanding


your data better and other suggestions. Now there's a follow up tweet to this, that is here saying,


Oh, this thread is doing numbers. There are a few comments disagreeing with this thread.


One thing to keep in mind as you read them, as far as I can tell, they are misinterpreting


what I said, because they are using a different definition of bias. And I think this really


hits the nail on the head. Specifically, he got a lot of heat for saying the first thing


here, the bias starts in the data. Now every time you talk about these things, there are


a number of people coming out saying, it's not the data, the problem is not the data,


or the problem is not only the data. And I have to admit, I also had a little bit of


a wrong impression of what that actually means. And I think the solution is in recognizing


that people are using different definition of bias. And that leads to a situation where


people talking past each other. So in my last video, I've pointed out, there are many different


things that can go wrong with a machine learning pipeline and where bias can be introduced


and erase the plea to not confuse them. Because what people will do is they will point to


one problem and then suggest a solution that is relevant for a different problem. Now as


far as I understand it, when Kareem talks about the bias starts in the data and is transmitted


by models, what he means is statistical bias, which means that either the data set is sampled


in a wrong way and doesn't represent the world as it is, which I also discussed, or that


the model itself, the choices we make during training and the loss function in the choice


of architecture, lead to a situation where the model output does not represent the world.


This refers to statistical bias and statistical bias is in part necessary for us to build


models that do generalize well, but it can be a problem. And I think everyone acknowledges


that. But when people say the problem is not in the data, I think they usually mix up two


different things. The first thing they mix is what I'm showing right here. There are


problems with building the models itself that can amplify a bias in the data or if they


have really bad models even create bias that was not present in the data set. On the other


hand, I also pointed out that a lot of people actually have a problem not with the data


itself, but with reality. So the bias they're talking about is bias that already exists


in the world. And here the machine learning model is sort of viewed as a tool of social


engineering. And very often evidence for wrong loss functions are brought up to show that


there is bias that is not in the data, but then the fixes that are suggested for it are


targeted towards bias that is in reality. So my plea last time was, let's not confuse


the different things that go wrong and how we fix them is perfectly viable to talk about


changing reality to talk about using a machine learning model to influence reality. We all


know there are feedback loops and other influences that these AI systems have. And I think we


should then honestly come out and say, when we talk about de-biasing, what we actually


mean is we want to bias the machine learning model such that it outputs a world that we


want to have, and not the world that we actually have as a tool for social engineering. So


today, we're going to have a look at a thing that I wanted to have a look for for a while.


And those are these AI explorables, they're made by Google. And they're kind of cool interactive


things that give you a visual impression of what can go wrong with machine learning models.


Right now they have these in the fields of privacy, and also fairness and bias. So I


thought today we'd look at the ones in the fairness and bias section with special regard


to people saying the problem is not in the data. Now, if you actually look at who's making


these arguments, and who's making these explainables, there is a pretty big overlap between who


is making the explainables, and who is saying the problem is not in the data. So if there


is good evidence for the fact that the problem is not in the data, I expect that these explainables


will give us a bit of a hint about that. So my hypothesis as I go through this is going


to be yes, the problem is in the data, either because the data is sampled incorrectly, in


which case, we can simply focus on sampling a better data set, or in the other case, because


reality is not as we want it. And that is reflected in the data, in which case, we're


not de biasing, we are actively biasing, but I guess you can see for yourself. So the first


explorable deals with measuring fairness. And essentially, it's saying that, imagine


there is a disease, and if you had a perfect test for the disease, you would have no problem.


So all the people in red here are sick, whereas all the people in gray are well, and the perfect


test would be able to recognize all the sick people and not recognize all the well people


100% accuracy, not a problem. This is not the case in reality, though, usually we have


tests that aren't exactly perfect. So you'll always end up with people who are sick, but


not recognize the ones down here, and people who are not sick, but the test says they are


sick, I'm sorry, it's really hard, I have to draw off screen and hit the region that


I'm targeting. It's an experiment. Now, these tests usually don't just say you're sick,


or you're not sick, they usually give you a probability of being sick. Now, the question


is, where do you cut off? Do you say a person is sick when the test is 99%? Sure. Do you


say a person is sick when the test is 50%? Sure. And here is where you have to make a


choice. One choice is to never miss the disease, which means that as soon as my test says this


person might be sick, I already put them into the sick category, I won't ever miss anyone,


or I'll just miss really few people down here. But you can see I have a large swath of people


that aren't sick, but the test says they're sick just because I'm so conservative. On


the other hand, I could say, I just want to be really sure. So I only classify anyone


as sick, if the test is really sure. You can see now that very few people that aren't sick


end up in the positive group. However, you have a lot of people who are sick who are


not detected, because you simply don't trust the test unless it's really, really sure.


The aggressiveness gives you a handle on the threshold here. So full aggressiveness means


that as soon as the test says there's there might be something wrong, you classify a person


as sick. On the other hand of the spectrum, you just want to be really, really sure. And


you can see while you miss half the sick people, you don't make any errors on healthy people.


So how does this play into fairness? The fairness aspect comes in when we consider different


subgroups, they say things get even more complicated when we check if the model treats different


groups fairly, whatever we decide in terms of trade offs between these metrics, we probably


like them to be roughly even across different groups of people. If we're trying to evenly


allocate resources, having the model miss more cases in children than adults would be


bad. So on the right, you can see that now we split the population into children and


adults. And you can see some things going on here. Namely, in this fictitious world,


the base rates are different. This is known as the base rate problem. And you can see


that the disease seems to be more prevalent in children just from the fact that they are


children. And this results in kind of a weird situation with what we had before. See, wherever


you set the threshold, you're going to have a different proportion of adults and children


that you misdiagnose in one way or another. So on the bottom here, you see the recall,


which is right now equal for children and adults. But due to the different base rates,


the children have a much higher precision than the adults. So if, for example, there


was some kind of worldwide pandemic, and you're an adult, you might rightfully claim that


this is unfair, because just by how the threshold is set, you go to quarantine much more easily


than a child, even if you are healthy. So you might plead for raising up the threshold.


But again, that would not be fair to the children. And even if you allow for having different


thresholds for the different groups, due to the different base rates, you'll never be


able to bring both the precision and the recall to be equal for the different groups. Now


I've looked at all of the different numbers. And you can see right here, I've plotted precision


versus recall. For adults, it looks about like this. And for children, it looks about


like this. So you can see as these curves are never intersecting, you'll never manage


to find any threshold for either group that were both precision and recall match. In their


conclusion to this article is somehow you cannot satisfy every single notion of fairness


at the same time, which of course, I agree with. But you can clearly see that the reason


this whole phenomenon happens is because you have the different base rates, which draw


these two curves away from one another. But let's examine our hypothesis again, is the


problem here in the data? And I would argue, yes, absolutely. The problem is in reality.


And reality makes it such that children are more often sick. So reality is at the cause


for this problem. And this reality gets into the data. So very directly, at least in this


particular problem, the problem is in the data. The next explainable is called hidden


bias. And the situation is, let's pretend we're college admission officers trying to


predict the GPA students will have in college. This is not real data, this is simulated data.


So here we take a simple machine learning model and let it predict the college GPA.


So on the x axis, you see what we're trying to predict. And on the y axis is our model


trying to predict it. So the further away we are from the middle line, the worse we're


doing. And you can see here if our only input variable and that's what it says at the top


is the high school GPA, we're doing pretty badly, we can increase that performance by


providing the model with more data, you can see that the points shifted towards the line,


meaning we make less mistakes. Now they introduce the problem. They say if a sexist college


culture has historically led to lower grades for female students is here in purple, the


model will pick up on that correlation and predict lower grades for women. Training on


historical data bakes in historical biases. And they also say here the sexist culture


has improved, but the model learned from the past correlation still predicts higher grades


for men. So essentially saying in the past, women were subject to sexism, and therefore


had lower grades. However, this is no longer the case. And now the model trained on the


old data still makes that mistake. Notice that this falls pretty clearly into the skewed


sampling and out of date data category. So right off the bat, the problem is in the data.


So the first thing they point out here is that if we simply don't give the model access


to the variable gender, the problem might still persist, because the model will simply


find correlations between gender and then use that to predict. And honestly, how could


the model do any different in the world that it sees and the data that it has, the purple


dots are actually performing poorer. So the most accurate thing to do is to score them


lower. Again, the problem here is clearly in the data and we need to get more accurate


data that better reflects the real world as it is. We all agree that if we don't have


the correct data, our model is going to learn all the mistakes that are in the data set.


So conclusion one from this explainable is that just because you take out a protected


attribute from the model, it doesn't mean that you can fix bias because the model can


simply find other variables that are correlated, which is absolutely true. The next thing they're


saying is that as intuitive as it might seem to exclude a protected attribute from the


algorithm, it might even be beneficial to explicitly include a protected attribute.


So here they have a different machine learning model. This time, they still want to predict


the college GPA. However, their only input variable is the score that one alumni interviewer


gives to a student. Now it just so happens that this student has a personal bias against


people from low income households here in red. So here they say, in our toy model, students


grades don't depend on their income once they're in college. In other words, we have biased


inputs and unbiased outcomes. The opposite of the previous example where the inputs weren't


biased, but the toxic culture bias the outcomes. So we've completely switched frames right


now, we're basically relying on this one person to interview all the people. And it is the


case that, you know, when this person says, yes, the GPA is probably going to be good,


and vice versa. So we still have this linear relationship. However, that person has a personal


bias. So necessarily, this is going to influence our decisions in a bad way. And here they


argue that if we explicitly include the income, the model can compensate for this. So the


model can recognize that if there is a person from a low income household, it probably shouldn't


trust that assessment of the interviewer as much. So conclusion one was that if you have


biased target variables, like you have this out of date data, then even excluding the


protected attribute might not be enough to fix the bias. Conclusion two from this experiment,


however, says that if you have accurate targets, like here we have actual data from how well


people performed, then giving the model access to all the data may help. So it's not as easy


as simply telling the model, don't look at this one particular variable. But again, let's


look at it from the perspective of is the bias in the data. And clearly here in the


second example, the problem was only there when we only relied on that biased interviewer.


So again, the bias was in the data. And as soon as we acquired better data, more variables,


we fix the problem, either because the data was sampled incorrectly, or because reality


itself simply isn't as we want it. The third explainable is called measuring diversity.


This is the most strongly worded one of the three. And I think it makes it the most explicit,


which is something that I'm thankful for. So they say search ranking and recommendation


systems can help find useful documents in large data sets. However, these data sets


reflect the biases of the society in which they were created, and the systems risk re


entrenching those biases. For example, if someone is not a white man searches for CEO


pictures and sees a page of white men, they may feel that only white men can be CEOs.


So the argument is one that I also made in my video, and it is that if we implement these


systems, they will have an effect on society and that effect might be not what we want.


But it is important to remember that this is an entirely different problem from skewed


data sets or different loss functions. And when you click on the link that they cite,


you get to this article, the top jobs where women are outnumbered by men named john. And


it is an astounding display of the disparities that are present in some jobs. Now, while


it is a valid question to ask why that is, and what might be at the cause of these problems,


it's pretty clear that this is the state of the world. And any machine learning model


outputting this as a search result reflects the world accurately. And the problems with


these models aren't really that they don't reflect the world as is. But what the people


are criticizing is that the output is not what they would like it to be. And they have


their reasons. There are valid feedback loops. And the reason they give here is that they


may feel that only white men can be CEOs. My problems with these types of arguments


is that search engines quickly sees to be search engines and are much more like wish


engines. Like why use a search engine when I already know what I want to come out. But


I do appreciate the honesty. So now we are truly in the field of social engineering.


We're in the field of making the outputs of these models as we want. So here they have


a toy data set, you can see there are squares and these squares, they come in three different


colors, they come in two different sizes, and some of them have a circle and some of


them don't. So here the first task is to select green boxes such that the representation of


green boxes is 30%. Now given that there are three green boxes, you can just select the


three green boxes and make sure that you select 10 boxes in total and you'll meet that. Notice


that that has nothing to do with a search engine. Now, this is simply we have a target


of green boxes and we're trying to meet that target. We can of course do the same thing


with the number of dots and the sizes and it gets interesting once we have different


intersecting targets. So we want 30% of our subset to be green 35% to have a dot and 60%


to be small. And while you can almost solve this problem, the point they're making right


here is that now it suddenly becomes important what difference metric you choose. If you


choose the mean difference metric between your targets and the actual group you're choosing,


the result will be different from when you choose for example, the absolute difference.


And you can see this right here. So here they give you the best choices according to targets


that you set on the left and they show you where they rank in terms of the different


metrics. So the sequence that is best in terms of mean difference is only second best in


terms of max difference. And as you change around the sliders, you can see that this


changes and you can see how the rankings here become pretty wild. So they go into this question


of which measure is best. In a vacuum they say all of these ranking methods are defensible.


Ranking one requires knowledge of the data set and broader societal context. For example,


the doctors on the left have more variance along the shirt color attribute, but they're


less diverse by gender than the doctors on the right. With the shirt color and gender


targets we've picked, the two subsets have the same mean and max differences. However,


in most applications, it's more important to have a representative sample of socially


relevant characteristics like gender, rather than something less salient like color. So


the point is that if they pick the subset on the left, it might be quite diverse with


respect to white or blue colored shirts, but it might not be as diverse with respect to


gender. However, on the right side, you can see that everyone's wearing a white shirt.


However, genders are more equally represented. So I don't really get the jump here. We went


from the metric you choose makes a difference in how the subgroups are represented to which


attribute we choose makes the different attributes differently represented. And all of that has


not really a lot to do with search engines per se, because I still don't get why I wouldn't


want my search engine to just represent the world as it is. But pretty clearly, you can


see that if you are not satisfied with the representation of a particular shirt color


of a particular gender, or other protected attributes, what you're essentially saying


is that reality isn't as you want it, that reality comes into the data set, and then


the data set is not as you want it. So the problem is in the data. And they go one step


further and say that it's actually not as easy as simply including something like gender.


So here you have stock photos for construction workers that seem to be very balanced on gender.


But if you look at the feminine presenting individuals and other gender representations,


they're depicted as historic nostalgia, toys, clip art or passive. And I mean, these are


certainly valid problems. But this is not truly a wish machine and not a search machine


anymore. I think maybe a more accurate solution to this problem would just be to tell people


that just because a search engine outputs a bunch of results that is not that per script


of description of the world, it is rather a descriptive representation of the training


data, which might or might not reflect the world as it is, I think people are in general


a bit more competent than simply seeing a bunch of images on a website and thinking,


oh, I'm going to now make my life decisions in accordance with what I saw here when I


typed a construction worker into Google. So that was it on the pair AI explorables on


the topics of fairness. And every single time, we saw that the problem is clearly in the


data itself, or in the reality that then influences the data again, which is fine. But I think


when we talk about these things, we should be clear about what kind of bias we mean,


and then suggest solutions that are specifically for that kind of bias. Alright, that was it


Processing Megapixel Images with Deep Attention-Sampling Models

Hi there, today we're looking at processing megapixel images with deep attention sampling models by


Angelos Kataropoulos and Francois Fleuret. So this is another paper that I saw the talk of at ICML and


it's a pretty cool idea, it's pretty simple and apparently it works very well. So consider the


following image here of a street situation and ask yourself if a self-driving car sees this, what are


the kind of things it needs to be aware of? So of course one of the things it needs to be aware of is


like the road, the cars and so on but also what's encircled in red here, the street sign. And the


street sign especially is important because there's a number on it and you want to see what the number


is otherwise you won't be able to adjust your speed. So if this is now a really large image, so if the


camera is really good and the dimensions of this image are really large, then current machine


learning methods have a problem because current machine learning methods kind of go up to maybe


something like 200 by 200 pixels or the current image net models, some downsampling. So if this


is much larger than this, what current machine learning models would do is they would simply


downsample, like compress the size, just compress it a bit and so on. And by that, as you see here


on the right, if the original patch in the image you could, you know, you could cut it out and


enlarge it, it would look like this. If you compress the whole image, the same patch would now


look like this blurred. So in the bottom half, you'd be able to recognize the number in the top


half, you wouldn't. So a standard CNN might be able to recognize the road and the car still at the


lower resolution, but not the speed sign. What we want is a method that can selectively pay attention


to parts of the image that it finds interesting, and then look at those parts in full detail, while


basically deciding to discard other parts completely such as the sky here. So this paper is


one that does this and does so in a very efficient manner. So the basic premise is very simple.


All right, I'm going to show you on this on the same image. So what you do is first, you actually


compress the image. So this image will become a smaller image, right? So here, maybe this is 1000


by 2000, you compress it down to maybe 100 by 200. Still the same image, but compressed on here's


the road. Here's a bunch of trees. I'm very good at drawing trees. And here's this street sign. And


here is a car. And here is another car. Alright, so and there's a sky up here. So now what you do


is on this smaller version, you classify every location in it, I guess you could classify you


could sub sample, but you want to classify every single location on it on how interesting is it.


And what they do is they take this and just put it through what they call an attention network,


which is just this, it's just a neural network. In their case, it's a CNN that for each location


here for each blue location, outputs a function, a of a, and let's call it a x y at coordinates x


and y of this image x. Okay, I this is stupid notation. That's a of x to the image is x at


coordinates i j. Right? So all of these blue things here are i's and j's, different i's and j's. And


then does this gives you now if you normalize correctly, so if you normalize over all the A's


and i j, i j, if you normalize, this gives you a distribution over this image. So if we look at it


in like one D, this gives you like a distribution, not a continuous one, in this case, a discrete


one, how interesting is each patch. And at the end, if you have this distribution, so let's finish


here. What you want to do is you want to say, which are the most interesting locations. So this one's


pretty high, and these are very high. So that might correspond to over here that might correspond to


some location. So this location is very high. And these locations are very interesting. And only in


these locations, you take them out, and then only those you process and full resolution. So you


might have extracted, let's say four patches. So now you have four of these patches. And each of


them individually, you run through a second neural network, which is called another CNN, which is


called f the feature network. So the feature network will take a patch and output a vector of


features. Right, so it will feed those in and output the vector of features. And then what you


do is you simply your final output, which they call g. Let me colorize this. So g, which is


g is now the final output. Let's not call it g. Let's call it Oh, output is you sum over all the


patches you have extracted down here. So the patch number P over all your patches, and then you


the patch number P over all your patches, and you sum these features f of patch P, right, and P might


be at location i j. Let's put i j here. So i j in the extracted patches. And you weigh each feature


by how much attention it got at that location. Alright, so it looks more complicated than it is


what you do is you simply determine these features by using this neural network only at the position


where this neural network says are interesting, then you get the features from the interesting


positions. And you basically just weigh them by how much attention they they got in the attention


distribution. And that will be your final output of the network. And it makes intuitive sense, like


one network decides what is interesting, the other network decides, what are we going to do with the


interesting things in this in this image. And the cool thing about this is, you can basically decide


how many of these patches here, how many you want to extract, you can decide at what resolution you


want to process this image. And all of this are parameters that you set by how much time you have


for computation, and how much memory you have for your computation. So that's pretty cool, pretty


modular, you can scale up, we can scale down. And the another cool thing is the theoretical guarantees that they give. So basically here, they prove that the way they do it, especially by extracting the patch, especially if they have an unbiased, sorry, especially have if they have sampling without replacement, is that if they weigh the things correctly,


and if they do the things correctly, they show that this is actually an unbiased estimator of the true neural network. If you were to evaluate on the full image, basically on each patch in full resolution. So


only taking the ones where the attention focuses is an unbiased estimator. And not only is it an unbiased estimator, it is in fact, the estimator with the smallest variance. And that's what they prove here. So the minimum variance estimator. And this is, this is pretty, pretty interesting, pretty cool.


And works pretty well. They also show how to derive the gradient update when you train with this attention sampling. So now you train your neural, you train your machine learning system, not on the whole image, but only on a sub set of the image patches. But it still behaves in expectation as if you were to train on the entire image. So pretty neat. So here they show how this compares to


full CNN. In this case, we have the full CNN, where the picture is simply down sampled, and then classified. And this is what's called megapixel MNIST. So in megapixel MNIST, you have a large image, and you put three digits in there, they're the same, for example, 555, from the MNIST data set, you put two random digits, others like two, three, and you put


also a bunch of noise, noise patches somewhere. So the task is to recognize, which is the dominant digit here, in this case, it would be five, right, five, five, where was the other one five here. So if you give this to a regular CNN, you see, it does about this well, this is the training loss here, training loss, and this is the test loss.


And it takes this much time, right time per epoch here, and this much time to evaluate, sorry.


If you now use this attention sampling, and as I said, you can actually modulate how many patches you want to take. So as you go down, you take more patches, we would expect it to take more time is exactly what happens. You see, for example, down here in the test error, if you take five patches per image, it takes very little time.


But the error, I mean, the error is still better than the if you use the CNN, simply because you can now pay attention to details much more. As you use more patches, your test error drops, also your training loss, they drop. So using more patches will actually give you a better and better and better performing model.


But you sacrifice a little bit of time, but still not never as as slow as with the full with with the CNN. So even though it's a down sampled CNN, right, so that is very interesting and very cool that not only do they beat the baseline in terms of error, but also a lot in terms of speed.


If you look at what the model does, as it learns, here you see for a given image, this is always the same image from the data set. At the beginning, they have actually marked where the relevant three relevant digits are in the picture with the red circle.


So if you look at how over the training of this model, how this distribution evolves is pretty interesting. Yellow basically means high attention. So at the beginning, you have high attention everywhere in the image. Right.


And then, as you go on and on and on, you see, for example, here, it pays attention to all the locations, where basically where there is something in the image, right? This could be one of these three digits, but it could also be one of the digits that it's trying to, that is trying to distract the model, like the false digits or the noise patches.


And as you go more and more and more, it really learns to only pay attention to the relevant digits, and then classify those at full resolution. So this really shows the this this kind of attention distribution learns something very meaningful.


They do more experiments on two data sets. Namely, this is a histopathology data set right here, where the goal is, I think to recognize this epithelial cells, this type of cell.


And


you can see


that this here is the baseline. And this here is the new method. And the baseline basically, what it does is it does a similar thing, namely, it processes the image in patches, but it processes every single patch.


Maybe in succession, but it still processes every single patch where the attention sampling only processes the patches that the attention sampling distribution suggests.


And this other data set here is a street sign data set that you saw at the beginning, right here. And the the, again, I think this is the baseline. And this is the attention. So both learn to pay attention to the street signs. But the other data set is the street sign data set.


Again, I think this is the baseline. And this is the attention. So both learn to pay attention to the street signs. But again, the attention sampling much more efficient. So here, you see the baseline performance, the attention sampling performance is similar in terms of test error.


But if you look at how much time the baseline uses per sample, and how much memory and then compare this to the attention sampling, you see that they save at least an order of magnitude in time and memory.


And the same thing goes for the street sign data set, you see test error here. And then test error is similar for the attention sampling, but again, time memory, much, much lower.


So the attention sampling is faster, and is more memory efficient than the baseline. And that makes it makes it easy to process these megapixel images, even on here, they say process megapixel images in a single CPU or GPU.


And that really, I like this because it kind of brings the research back to, let's say regular people, or maybe universities that don't have as much money as large companies.


And so all in all, very cool paper, very neat experiments to have a lot in the appendix. Check it out where they show their attention distribution in these images. Their theoretical analysis is pretty easy to follow if you want to check that out.


Online Education - How I Make My Videos

Hi there! So a lot of people have been asking me how I make these videos and this is of course


Online Education - How I Make My Videos

relevant now that everyone's work from home and all the schools are converted into online schools.


Online Education - How I Make My Videos

All of a sudden a lot of people have to make these online education happen and I think this


Online Education - How I Make My Videos

style of video lends itself to online education. So I'll quickly go over the process of how to do


Online Education - How I Make My Videos

this and maybe also how to run a university class online. Right, so the process is pretty simple of


Online Education - How I Make My Videos

how I make my videos. This might not work for everyone but it works for me. I use the Microsoft


Online Education - How I Make My Videos

OneNote in order to scribble on papers basically. So the thing is in OneNote you have this insert


Online Education - How I Make My Videos

thing here and you can print out a PDF onto your notebook here, right. So the way this looks then


Online Education - How I Make My Videos

is you'll get the PDF in your notebook and you can scribble on it with this using this draw tab


Online Education - How I Make My Videos

here. You can choose a pen and scribble on it, you can highlight things and so on. And I do this


Online Education - How I Make My Videos

while I record the screen so that's pretty much all there's to it. You can then print out again


Online Education - How I Make My Videos

this notebook and you can distribute those annotated PDF if you want. Now I'm pretty sure


Online Education - How I Make My Videos

this is here inserted as some sort of as a an image so I don't know about the copy paste ability


Online Education - How I Make My Videos

of the resulting product but here you see this is a paper I actually made a video about and that's


Online Education - How I Make My Videos

basically all there's to it. It's OneNote, it's a free program from Microsoft. In order to do


Online Education - How I Make My Videos

the annotating I use a last or last last generation Microsoft Surface tablet that I got for cheap at


Online Education - How I Make My Videos

some point. It comes with a nice pen and touchscreen so you can basically zoom around and zip around


Online Education - How I Make My Videos

while you do these things. In order to record the screen I use this iSpring free cam software. It


Online Education - How I Make My Videos

might not be the best but it does work for me well and they have a cool Pro Edition if you need


Online Education - How I Make My Videos

more features. But it works really well for recording your screen. You can record parts


Online Education - How I Make My Videos

of your screen or the full screen you can record with sound. So I use a microphone and then I just


Online Education - How I Make My Videos

record the sound from that with the same tool and at the end you get a video file that you can


Online Education - How I Make My Videos

upload to YouTube. Easy as that. If I need to do some editing which is rarely because I am lazy


Online Education - How I Make My Videos

I use either iMovie from Apple which comes with an Apple operating system. So I have a MacBook that


Online Education - How I Make My Videos

I run iMovie on. iMovie is really easy to edit movies on. I don't know if there's anything on


Online Education - How I Make My Videos

Windows where it's that easy that comes pre-packaged but if I need to do more complicated things I use


Online Education - How I Make My Videos

Shotcut which is an open source editor. I believe that's available for all the platforms and you can


Online Education - How I Make My Videos

do fairly complicated things with Shotcut if you ever need to do that. But if I just need to stitch


Online Education - How I Make My Videos

like two or three things together I use iMovie. And that's pretty much it for making and recording


Online Education - How I Make My Videos

videos I believe. Yeah one note is that then in order to do a class from online not all people


Online Education - How I Make My Videos

will just be able to record a video and then upload. Some of the things you need to do actually


Online Education - How I Make My Videos

live. And a lot of people right now use Zoom for live basically teleconferencing but you can also


Online Education - How I Make My Videos

do this sort of presenter mode where you present and people can do questions. Of course you can do


Online Education - How I Make My Videos

this via YouTube streaming as well but then it's of course it's kind of public on YouTube or link


Online Education - How I Make My Videos

accessible with Zoom. I believe you have more control but of course Zoom is a proprietary


Online Education - How I Make My Videos

solution and with the free account you can only get so far. So they limit your meetings in length


Online Education - How I Make My Videos

if you have more than I believe three or four people. An alternative is Jitsi which is open


Online Education - How I Make My Videos

source video conferencing and the cool thing here is you can actually run your own server such that


Online Education - How I Make My Videos

you can truly have control over everything. In order to communicate with lots of people of course


Online Education - How I Make My Videos

people use Slack but again Slack is a proprietary service and an alternative to that would be


Online Education - How I Make My Videos

RocketChat again where you can run your own server and it is fairly similar to Slack. In order to


Online Education - How I Make My Videos

collaborate or share just general notes of course Google's suite of docs and sheets and so on is


Online Education - How I Make My Videos

excellent and for classes especially Piazza is a good place. You can sign up as a class, you can


Online Education - How I Make My Videos

have TA's sign up as TA's and you can have your students sign up as students and then the students


Online Education - How I Make My Videos

can ask questions and then other students or the TA's can answer those questions. Basically a bit


Online Education - How I Make My Videos

of a forum but you can also announce things there for your classes. It's pretty cool and it's really


Online Education - How I Make My Videos

geared towards online classes and it's free so I know a lot of universities are using that right


Online Education - How I Make My Videos

now so if you're looking for some sort of announcement or discussion board for your class


Online Education - How I Make My Videos

Piazza is definitely a good place to be. And lastly we sometimes have classes where students


Online Education - How I Make My Videos

have to submit projects and we actually use CMT for this because it's really neat where you can


Online Education - How I Make My Videos

you know set deadlines and everything students can upload and then you can assign reviewers to


Online Education - How I Make My Videos

those projects which in our case are us the TA's and you know you can have meta reviews and so on.


Online Education - How I Make My Videos

So CMT is actually very good maybe a bit of an overkill if you just run a single class but it


Online Education - How I Make My Videos

has lots and lots of features and of course the big conferences also use CMT so it's definitely


Online Education - How I Make My Videos

stress tested. Alright so that was it from for my videos or at least how I make them I just you


Online Education - How I Make My Videos

know print out the PDF sit down for half an hour and rant about it and that's pretty much it and


Online Education - How I Make My Videos

then you throw it on YouTube or distribute the file however you want. And with that I hope I


Online Education - How I Make My Videos


[ML News] OpenAI removes GPT-3 waitlist | GauGAN2 is amazing | NYC regulates AI hiring tools

GPT-3 is now free to access, NVIDIA releases Gauguin 2 and it's amazing, and out of Google


X comes Everyday Robots, which aims to make robots handle everyday tasks.


Welcome to ML News.


Hey YouTube!


Hey attention sores, what's up?


This video is sponsored by Weights and Biases.


Thank you so much to Weights and Biases for being a great sponsor.


If you don't know Weights and Biases, you should definitely check it out.


It is a one stop shop for all your machine learning needs.


It starts at tracking your experiments with a single line of code.


Everything is logged to the cloud, your environment is logged, your outputs are logged, your models


and data sets can be saved and iterated upon.


And it's with you from conception of your idea all the way to deployment and monitoring.


They have on prem solutions, they have cloud solutions, and it's completely free for personal


use and for academic use.


So please try out Weights and Biases.


Today I want to highlight their jobs offerings.


If you're looking for a job, please consider Weights and Biases.


As you can see right here, they have all kinds of job openings from business operations, customer


success, there's lots of engineering jobs, there's deep learning engineers, site reliability


engineer, just regular software engineer, product engineer infrastructure, there's deep learning


engineer for growth.


But even if you're not an engineer, you can go into marketing into people operations,


product managers, all kinds of things and look at that they just need salespeople.


So if you're good at selling, maybe this is your position.


As you can see, they have some jobs in North America, some are in Europe, but a lot of


jobs are actually remote.


So whether you enjoy remote work or onsite work, chances are Weights and Biases has something


for you.


As you know, as we've reported right here, Weights and Biases has just raised a giant


amount of money at a $1 billion valuation.


Make sure you get a slice of that pie apply for a job today.


Go to 1db.com go to resources, click on careers and find all their job offerings right now.


If you're not looking for a job, check out their products.


I'm sure you're gonna love it and thank you so much again to Weights and Biases for sponsoring


this video.


All right, let's get into it.


OpenAI's blog says the open AI API is now available with no waitlist.


That means that you can simply go sign up and you get access to the API.


The API includes things such as their language model GPT-3 and so on.


It includes things like the instruct models and these models are good at following things


like instructions and also the codecs models that generate code given a piece of natural


language a function to fill my bank account.


Well, I guess the model tells me that I actually need to make a deposit in order to fill my


bank account.


That's sad.


Of course, the flagship models are still the GPT models specifically GPT-3.


The largest version is called DaVinci the best idea ever is the best idea ever is the


idea that is most useful to the most people.


Thank you DaVinci is a utilitarian absolutely based.


So even if you've used GPT-3 before and if that was a while back, you might want to check


it out again because the documentation has involved there are a lot of examples open


AI themselves have figured out a lot more about how to prompt these models in order


to get good completions in order to actually make them do what you want them to do.


And there's a lot of useful stuff right here.


I've actually made a poll about this in the past and over 1000 of you have responded and


it turned out most of you didn't have access yet even though a large portion of you applied


early.


So to all of you who still don't have access, this should help you.


Now this doesn't come as a surprise as in recent times, we've seen a lot of competitors


to open AI simply giving people access to their API and not having them on a long waitlist.


So how much of this is well we finally figured it out and how much of it is please don't


go to our competition.


We don't know.


That being said, open AI still wants to have a very tight control over people that actually


use the API to build products.


They say our work also allows us to review applications before they go live, monitor


for misuse, support developers as their product scales and better understand the effects of


this technology.


Essentially, they want to avoid at all costs that you build a product that in any way reflects


negatively on open AI be that if the model makes some sort of a mistake or if the technology


is used for a use case that maybe isn't super PR friendly.


That is not good or bad.


It's just something you have to keep in mind when you go all in and build actually an application


on the basis of an API like this.


Media releases the second iteration of their Gao Gan model, which is a generative adversarial


network that doesn't just come up with stuff by itself but can be conditioned on certain


inputs.


Gao Gan one was already being used to condition the model on sketches as you see here, you


can give a bunch of segmentation maps and then the model would dynamically adapt and


generate a picture based on that.


Gao Gan two takes this a step further.


Now you can also condition on words, for example.


In fact, they have released a little web app.


And as you can see, you can condition on a segmentation map.


That's what we saw in Gao Gan one, you can condition on a sketch, you can condition on


a base image or on text and not only either or of these modalities, but you can mix them


all as you want.


There is a Reddit post by the user whiskey and some of the pictures that this user was


able to generate with simply text prompts, if I understand this correctly, are just stunning


by themselves.


So here is a winter mountain landscape near sunset.


Now interesting is what you can do.


This is a stream, given a text description, then you can have the web app generate a sketch


from that.


Now I'm in dark mode right here, but you can probably see the dark lines that are supposed


to be a sketch.


This is generated from that image.


And then based on the sketch, you can re render with a different text description or with


the same text description, but apply a certain style to it.


So there's a lot of possibilities with models like this, you can explore that in the web


app.


So as we've said, for example, we can tell the model to input text right here.


So input utilization text says all that's used is this text right here, I've put far


from home.


So I render this, which is the arrow on the right, you can see a certain image is generated.


If I put close to Earth, a different image is generated a road with trees in fall, that


works out pretty well.


So what I can do now is I can take that and copy it over to the left side, the left side


is kind of like the input area.


Before we copy, actually, let me just take kind of a pencil and just sketch a bunch of


things here.


So let me sketch some I have no I have a touchpad don't don't criticize me.


And then like a line here.


Okay, and we'll do like some squiggles here.


That is a beautiful sketch.


So now we can activate not only text but sketch.


So now we're looking for a road with trees and fall given this sketch.


Well, okay, I have to admit my sketch wasn't exactly something that the model could make


sense of.


So let me try again, just a few broad strokes right here, maybe one here and something harsh


here.


Still no, my sketching abilities might not be super good.


So let me try the segmentation map for the segmentation map, you want to take a brush


like this one, you want to activate the input utilization of segmentation.


And then here you can select a bunch of segmentation things.


So dirt, let's put some dirt here on the lower right hand corner, like this.


Let's also put a bunch of grass over here.


And how about a fence right here.


That is a fence fence goes here.


And then house, the house is supposed to be take this part right here.


I'm not sure how the model is going to make this into a house.


Let's just have the house be all of this and we generate.


Okay, if you have better drawing skills than me, feel free.


But what is cool is that let's say we generate this image again, right, we can then copy


that image over to the left to this input area.


And then we can use different variants.


For example, here, we can have the segmentation map computed from that image, or we can have


the sketch computed from that image.


So let's compute the segmentation map from that image automatically.


And we can turn off the visualization of the real image.


So we only have the segmentation map left, we can then use that segmentation map together


with the piece of text.


But now we're going to change the piece of text, how about a road with trees in spring.


So what we want is a similar image, but in spring, look at that.


So this is pretty cool.


It would have probably be even more accurate if we used the source image as an image, which


you can also do you can use a sketch, as I said, any combination of these things, this


web app is pretty cool.


And it can even apply custom styles to images and so on.


Now I don't want to bore you too much with this and my poor drawing skills, you go ahead


and try it out.


I'll link it in the description.


Everyday Robots is a new initiative company, I have no idea what the actual legal structure


of this is.


Yet I guess it is some sort of a company and the goal is to make robots do everyday tasks.


So instead of having robots like Boston Dynamics, where you have very specifically tailored


robots and they're often hard coded to do certain things.


So for example, if a Boston Dynamics robot stands back flip, this has been the result


of massive engineering effort.


These robots are supposed to be a little more as they themselves say boring yet live in


the real world.


So they are able to navigate around obstacles interact with real things.


The challenges here are massive, like how do you generalize to arbitrary settings and


environments and things are dynamic and a lot of things are happening.


So this is born out of Google X, which is one of their sort of incubators.


And if I understand correctly, these robots are already used in some of their internal


cafes here you see one cleaning off the tables.


Now even with something as simple as cleaning off the tables, you have to get to the table,


you have to see if the table is empty, you have to be able to move around the table and


wash it down correctly until everything is washed and so on.


Definitely not an easy task.


So there's a big website with a lot of scrolljacking animations, as you can see here, but it seems


like a pretty exciting initiative.


There's also a good article on wired about it with a lengthy description of what the


goal here is and what the capabilities of these robots are right now and where this


company wants to go.


One specialty seems to be that these robots learn relatively quickly.


For example, teaching them to open a door apparently took under 10 hours.


Now that seems like a lot but in real life reinforcement learning with actual robots


that need to do this safely and cannot simulate and so on.


This is actually a very, very short time.


And once the robots have acquired this knowledge, they can transmit it to all the other robots.


So only one of them technically has to learn it.


The company imagines that in the future, these robots will assist humans with tasks as you


can see here menial labor tasks such as cleaning off tables.


And of course, since they are robots, the advantages that they can, for example, go


into hazardous environments in general operate differently than humans.


They also say that in the future, it might be supernatural to interact with robots like


these even if it may seem a little bit dystopian or futuristic right now.


Google AI presents met net two, which is another weather forecasting model.


So we've already seen DeepMind going into now casting, which means predicting rain a


few minutes up to like two hours from now.


And MetNet one has done previously work predicting a few hours ahead, like six hours or so if


I understand correctly.


But now they've pushed this to 12 hours.


So the different categories of rain forecasting actually bring a lot different challenges


to them.


For example, to predict the weather for the next 14 days, you look at entirely different


things you look at like big patterns and you can make some sort of large scale forecasts,


you know, in the north, it's going to rain in the south, it's not going to rain.


However, that information is almost completely useless for something like now casting where


you want extremely local predictions that are very, very accurate in time.


And in this regime, where MetNet two is in the 12 hour region, you sort of have to fuse


both of them together, you have to look at very, very large areas.


So for example, here, the blue area, if I understand correctly, is the area that they


actually look at to make a prediction for the red area.


Now, this is a giant area, but they still make predictions on a super fine grained resolution.


I think the resolution here is a resolution of two kilometers.


So every two kilometers, they make a prediction 12 hours from now, will it rain or won't it


rain?


The challenges from MetNet one, which could only predict up to like six hours is that


in order to predict for a longer horizon, they have to take more context into account,


as you can see right here.


And surprisingly, one way to do it is to actually replace the attention layers of MetNet one


with convolutional layers, which are more computationally efficient.


However, since convolutional layers only care about their local neighborhoods, they actually


use dilated convolutions to dramatically increase the size of the receptive fields of convolutions


over just a few layers.


On their blog, you can see a few examples and comparisons of their method to other methods.


And they even have an investigation into what the model actually learns about weather using


interpretability tools.


All of this is really cool because weather prediction used to be done with very, very


compute intensive physics simulation, which took apparently about one hour in order to


make this same prediction that MetNet two makes in under one second.


So invite you to go check out the blog post if you want to learn more.


A cool project by Nathaniel Felicke on hackster.io is this tiny ml dog bark stopper.


This is a report on how to use things like Arduinos and speakers in order to detect when


a dog barks and when the dog barks to play an appropriate sound.


Apparently this dog has a bit of separation anxiety.


So whenever the owner leaves the house, the dog just kind of goes wild.


And this video is a description on how they've used a speaker that is coupled to an Arduino


that records sound that the dog makes classifies the dog sound into barking or not barking.


This is done converting the sound into spectrograms and then classifying those spectrograms and


then when a bark is detected, the speaker will play a pre recorded sound of the owner


such that the dog thinks that the owner is still there.


So I very much invite you to go check it out.


If you want to build something like this for yourself, I'm sure this is a very good basis


in order to do so.


The instructions are all there.


And if you're into the mixture of ml and actual real world hardware, a little bit into soldiering


and hacking, this might be for you.


Speaking of hardware and interacting with machine learning, this is an ambitious project


where the YouTube user stack smashing has used a video capture card combined with again,


I think an Arduino or a Raspberry Pi in order to get a ml model to drive Mario Kart.


Usually this is done in an emulator.


People have done this before learn to drive Mario Kart using machine learning.


However, this user does it on an actual console, which means that they read out the picture


that the console generates using a capture card, they feed that image into a neural network.


And then they use this Raspberry Pi in order to send the commands back to the console.


Now the system doesn't go as far as actually move a joystick on a controller, but they


do send the appropriate controller inputs to the console using sort of like a cut off


cable and then sending the inputs to the cable.


The project details how they've adapted the tensor cart project that is meant for an emulator


and brought it to essentially the real world Mario Kart with the console.


Machine learning part of the project isn't very complicated.


The user has done a bunch of manual runs recorded their controller inputs and then let the model