Manifold Mixup: Better Representations by Interpolating Hidden States
deep learning neural networks adversarial examples machine learning bengio classification smooth flat representations ai artificial intelligence supervised learning regluarization regularizer hidden representations overconfidence
Standard neural networks suffer from problems such as un-smooth classification boundaries and overconfidence. Manifold Mixup is an easy regularization technique that rectifies these problems. It works by interpolating hidden representations of different data points and then train them to predict equally interpolated labels.

https://arxiv.org/abs/1806.05236

Abstract:
Deep neural networks excel at learning the training data, but often provide incorrect and confident predictions when evaluated on slightly different test examples. This includes distribution shifts, outliers, and adversarial examples. To address these issues, we propose Manifold Mixup, a simple regularizer that encourages neural networks to predict less confidently on interpolations of hidden representations. Manifold Mixup leverages semantic interpolations as additional training signal, obtaining neural networks with smoother decision boundaries at multiple levels of representation. As a result, neural networks trained with Manifold Mixup learn class-representations with fewer directions of variance. We prove theory on why this flattening happens under ideal conditions, validate it on practical situations, and connect it to previous works on information theory and generalization. In spite of incurring no significant computation and being implemented in a few lines of code, Manifold Mixup improves strong baselines in supervised learning, robustness to single-step adversarial attacks, and test log-likelihood.

Authors:
Vikas Verma, Alex Lamb, Christopher Beckham, Amir Najafi, Ioannis Mitliagkas, Aaron Courville, David Lopez-Paz, Yoshua Bengio
 Hi there, today we're looking at manifold mixup, better representations by interpolating hidden states by Vikas Verma et al. A number of big names on this paper as you can see and I also saw this at ICML so I was intrigued by it. They propose manifold mixup which is sort of a regularizer of neural networks is specifically of supervised learning and it's actually a pretty simple concept and they kind of show that it has some nice properties and outperforms other regularizers. So what's the problem? The problem is that if you look at this spiral problem here which is often kind of used to to show properties of neural networks, what you have are blue points and the blue points are one class and the red points are another class. You see the two classes here are in this kind of spiral pattern. The data space is just two-dimensional. You see here this is one class, this is the other class. This is pretty difficult for a model to learn because of course the easy models would be like linear classifiers but there's no way to put a line through this such that one class is on one side mostly. So neural networks, if you train them, they will give you something like you see here. They will try to kind of bound the regions with the red points from the blue points but then there's some weird things like here is a weird thing, here is a weird thing. So you'd imagine a correct model would actually classify this area as blue but the neural network has no concept of let's say that the spiral should continue that thus it simply sees here's blue, here's blue, here's a bit of a gap in the training data. So in this case it assigns a red class to it. So this is one problem that the decision boundaries are rather squiggly and irregular and the second one if you look at the actual colors, full blue means very confident blue class, full red means very confident red class and in between you kind of see going into the the white so if you look very closely I can't actually zoom in more here. If you look very closely you'll see that the blue gets lighter and lighter until it reaches white and from here the red goes lighter and lighter until it reaches white and white means not confident, white means like 50-50. So you see the area of not confident is actually very small right. If you consider a point here is actually still very confident that it's a blue point and the area of non-confidence is very small even though maybe as as humans we would judge like a relatively large band in the middle to be not confident like if we get a point like this. And the third problem is that you can see in multiple locations like here or here or here that the decision boundary is very close to the data points unnecessarily close. So especially if you look here the decision boundary could be much more optimally placed probably something like this right given the training data but the neural networks because they only see training data they they have no basically no incentive to do this. Alright one might think of you know something like a support vector machine that actually has an incentive to to put the decision boundary away from the from the training data but the neural networks currently they're not SVMs they're basically logistic regressions and as such have no no incentive to do this. So this these are the problems the other problems are this is the input space. If you look at the hidden space so they build neural networks specifically they have like the 2d input and then that goes through a bunch of layers and then at one point there's a bottleneck layer with just two hidden nodes and then I guess that goes again and then it goes into a classifier. So in this bottleneck layer they analyze the hidden representations of the data points and in this case for this spiral data set what happens is so in red you see again the red classes in blue the blue class it's 2d so you can plot it what it does is it bunches up the hidden representations fairly fairly so it bunches them kind of up it spreads them out in directions here here here most are bunched up here and it does these kind of weird arrangements here with the pockets of those and of course the neural network is powerful enough such that it can actually you know separate all of this from each other but it's not ideal and the black dots they represent kind of points in between or points from the input space that are not part of the training data so they say they sample uniformly in the range of the input space you see that the black dots are all over the place right some are confident blue some are confident red some are like somewhere all right what you would expect from a good model is that if you input something that's kind of in between or not really sure not even part of the input distribution that it assigns like a low confidence to it that it says well I'm not sure about this this must be somewhere in the middle so just to jump in jump forward to the results what does manifold mixup do without knowing what it is in the same data set it gives you a picture like this you see the decision boundaries are much more smooth right the region of no confidence or of low confidence indicated by the light colors here is much larger and also the decision boundary here we had specifically this data point here you see the decision boundary is pushed away though you could argue about that particular point but the decision boundary is generally pushed away from the data points you also see no more kind of these squiggles here it doesn't happen in in here also if you look at the hidden representations the hidden representations now are spread out the classes are bunched up so not all the points are bunched up but the the points of individual classes are bunched up together and the randomly sampled points are in the middle as they should be you say only confident red is down here confident blue is up here and everything in between is on confident and third if you look at the singular value decompositions of the hidden player and that's kind of a measure of how spread out in the different dimensions a data set is you see that the manifold mix up here in green it concentrates or it it lowers the singular values of the kind of lower indexes so the first singular value is large which means that there is like a dominant direction in the in the data and this is done for each class separately as I understand it it puts a lot of weight on the first singular vector and then it pushes down the contributions of the other singular vector which means that the data set that is analyzed is is concentrated into fewer directions of variance this is layer one and here is layer three means so you see it happens in both that the manifold mix up compared to the baseline model does this so now you might ask what is manifold mix up it's actually pretty pretty simple concept all right here is another comparing it to other kind of regularization techniques and showing that none of them really does this so manifold mix up is this basically what you do is when you train a neural network you have input data and you take many batches of input data specifically you take two many batches X and Y and X prime Y prime right and then what you do is if I have the draw the neural network here so here is the inputs like a picture of a cat it goes through layers right and then what you do is you say at some particular you say stop stop right you take the representation out you and you do this with two different many batches so here is this is cat one and I'm down back here is cat two whatever or dog that's a cat you pass it in right here you take it out here you pass it through the network and you take it out so you now have two different forward paths of two different many batches and then you define a lambda and I guess they randomly sample a lambda in zero one right in the range of zero one so this is a mixing coefficient and then you mix you say lambda times hidden representation of batch one plus one minus lambda of hidden representation of batch two and that is what you pass through the rest of the network right so basically you forward propagate two different batches until a certain layer here then you mix them with a random coefficient and then you pass it through the rest and then the only thing you also have to do is then at the end if you think of the labels of these two things you want to mix the labels in the same fashion so you want to mix lambda times y of batch one plus one minus lambda of y of batch two and then this is your training signal for whatever comes out here right so it's it's um these are these are one hot labels so if it's class three it's zero zero one zero and if y2 is class five it's zero zero zero zero one and then you simply mix the two right and that becomes your training signal so in a practical example if let's just have a mini batch size of one so just one sample if this is cat and this is dog you would pass them forward right you would mix so in the hidden representation it would kind of become a cat dog maybe you do it 50 50 but then you would also mix the labels of cat and dog 50 50 and tell the network this is a mixture of 50% cat 50% dog and then you would train the network to predict that 50 50 coefficient so they do this the question is at which layer do you do this and they simply I think for each mini batch sample one hidden layer at random they might have some weighting or something but the way they describe it is they simply sample one layer for me per mini batch and then do the mixing there and then you can actually back prop through everything everything is differentiable this mixing is differentiable so you can back prop through any everything and there's even you know kind of an engineering trick to only use a single mini batch by mixing it with itself so that's that's pretty neat so this manifold mix up as you can see here is the that's kind of the description you mix the hidden representations with lambda and you mix the labels with the same lambda and that will become your actual training signal all right so they give some theory to it that it flattens representations and specifically they say under some conditions namely if the network is large enough so if the dimension of the hidden representation is of a certain size then if you optimize this manifold mix up like if you optimize over every lambda and over the entire training data set what you will end up is actually a linear function of the input this is not too surprising that if you because what you do is you mix linearly this mixture happens in a linear fashion so if you optimize for and you not only optimize for the training set but you optimize for every possible mixture of the training set linear mixture your minimization your minimizer function will actually become a linear function it's not surprising but they have a formal proof of this and they also have a proof that if certain assumptions are given then the minimizers if you apply the minimizers the hidden representations will actually fall on a low dimensional subspace which is also not surprising but it's kind of the theoretical analog to what they show with with the singular value distribution that it basically suppresses low singular values that means the data set is much more into a single direction the hidden representations sorry all right so this the theory part is you can you can read it if you if you want to it's yeah it's it's to the results are to be expected I would say from what they do and the last thing they give a pictorial example of why manifold mix up flattened representations so both of these things the fact that the minimizers will become linear functions and the fact that the singular value spectrum is more concentrated on the first singular value means basically that representations are flattened and here is a pictorial representation so in this case what happens if you if you basically have these four data points a 1a 2b 1 and b 2 where a 1 and a 2 are blue class and b 1 and b 2 are red class and if you now look at an interpolation point between the two so if you look at this interpolation point between a 1 and b 2 what happens is that in this case this should be 50 50 blue and red but if you now look at the points that it where it's not interpolated on this is very close to a 2 in this case it's probably should be more like 95 blue and 5 red do they say here well if you use manifold mix up to learn the network what you'll actually do is you say okay actually this hidden representation needs to be pushed outward and you will achieve something over here where any mixture of two points of the opposite class will actually give you a 50 50 so all the mid points here will give you a 50 50 mixture between the labels which basically means what you end up with is a line between this data and this data and it means that basically the network becomes more linear and the representations become more flat because flat is the optimal if your distributions are flat all the distances to the line are the same and this objective is optimized and this is basically my my kind of biggest problem with the method is that it it kind of mixes the input with a linear function where we know that that is kind of not the shape of the true data manifold the input manifolds as you can see here the input manifold here isn't linear or flat it's actually very very tangled and we know that neural networks as you continue in the layers will flatten those representations because ultimately at the end it needs to classify the data set linearly because the last layer is a softmax layer but the the idea that you could apply this to any layer seems a bit shady to me of course it works and they show it works and it's really nice that it works but applying this to low layers in neural networks seems a bit not principled to me so I think this is not the end of the story of this line of work and there is kind of more that can be done in a more principled fashion but in any case they show that this actually works in terms of performance on generalization on kind of standard data sets so they have results on CIFAR-10 and CIFAR-100 which are famous image data sets and they show that the hair regularizer outperforms others and they also show that they can withstand one step single step adversarial attacks more kind of better so they have a better performance against single step adversarial attacks after regularizing mostly again giving kind of an idea that the if you push if you push it if you have a two points this is X this is X X 1 X 2 there are different classes if you put the decision boundary really close to X 2 then an adversarial attack can simply move the point across the decision boundary with a very small step but if you actually have the decision boundary pushed away from both data points then the an adversarial attack must go a very long way to the decision boundary and thus if you limit the size of adversarial attacks which is what you usually do you can maybe not reach this decision boundary and thus you mitigate some of the problem so it's pretty cool I think yeah there's work to be done but I think this is pretty cool it's implemented pretty easy I've seen there's a lot of libraries already available with it in and yeah won't hurt to add this to your code make your network better and more robust all right that was it from me bye bye
 Hi there, today we're looking at manifold mixup, better representations by
 interpolating hidden states by Vikas Verma et al. A number of big names on
 this paper as you can see and I also saw this at ICML so I was intrigued by it.
 They propose manifold mixup which is sort of a regularizer of neural networks
 is specifically of supervised learning and it's actually a pretty simple concept
 and they kind of show that it has some nice properties and outperforms other
 regularizers. So what's the problem? The problem is that if you look at this
 spiral problem here which is often kind of used to to show properties of neural
 networks, what you have are blue points and the blue points are one class and
 the red points are another class. You see the two classes here are in this kind
 of spiral pattern. The data space is just two-dimensional. You see here
 this is one class, this is the other class. This is pretty difficult for a
 model to learn because of course the easy models would be like linear
 classifiers but there's no way to put a line through this such that one
 class is on one side mostly. So neural networks, if you train them, they will
 give you something like you see here. They will try to kind of bound the
 regions with the red points from the blue points but then there's
 some weird things like here is a weird thing, here is a weird thing. So you'd
 imagine a correct model would actually classify this area as blue but the
 neural network has no concept of let's say that the spiral should continue
 that thus it simply sees here's blue, here's blue, here's a bit of a gap in
 the training data. So in this case it assigns a red class to it. So this is
 one problem that the decision boundaries are rather squiggly and
 irregular and the second one if you look at the actual colors, full blue means
 very confident blue class, full red means very confident red class and in between
 you kind of see going into the the white so if you look very closely I can't
 actually zoom in more here. If you look very closely you'll see that the blue
 gets lighter and lighter until it reaches white and from here the red goes
 lighter and lighter until it reaches white and white means not confident,
 white means like 50-50. So you see the area of not confident is actually very
 small right. If you consider a point here is actually still very confident that
 it's a blue point and the area of non-confidence is very small even though
 maybe as as humans we would judge like a relatively large band in the middle to
 be not confident like if we get a point like this. And the third problem is that
 you can see in multiple locations like here or here or here that the decision
 boundary is very close to the data points unnecessarily close. So especially
 if you look here the decision boundary could be much more optimally placed
 probably something like this right given the training data but the neural
 networks because they only see training data they they have no basically no
 incentive to do this. Alright one might think of you know something like a
 support vector machine that actually has an incentive to to put the decision
 boundary away from the from the training data but the neural networks currently
 they're not SVMs they're basically logistic regressions and as such have
 no no incentive to do this. So this these are the problems the other problems are
 this is the input space. If you look at the hidden space so they build neural
 networks specifically they have like the 2d input and then that goes through a
 bunch of layers and then at one point there's a bottleneck layer with just two
 hidden nodes and then I guess that goes again and then it goes into a classifier.
 So in this bottleneck layer they analyze the hidden representations of the data
 points and in this case for this spiral data set what happens is so in red you
 see again the red classes in blue the blue class it's 2d so you can plot it
 what it does is it bunches up the hidden representations fairly fairly so it
 bunches them kind of up it spreads them out in directions here here here most
 are bunched up here and it does these kind of weird arrangements here with the
 pockets of those and of course the neural network is powerful enough such
 that it can actually you know separate all of this from each other but it's not
 ideal and the black dots they represent kind of points in between or points from
 the input space that are not part of the training data so they say they sample
 uniformly in the range of the input space you see that the black dots are
 all over the place right some are confident blue some are confident red
 some are like somewhere all right what you would expect from a good model is
 that if you input something that's kind of in between or not really sure not
 even part of the input distribution that it assigns like a low confidence to it
 that it says well I'm not sure about this this must be somewhere in the
 middle so just to jump in jump forward to the results what does manifold mixup
 do without knowing what it is in the same data set it gives you a picture like
 this you see the decision boundaries are much more smooth right the region of no
 confidence or of low confidence indicated by the light colors here is
 much larger and also the decision boundary here we had specifically this
 data point here you see the decision boundary is pushed away though you could
 argue about that particular point but the decision boundary is generally
 pushed away from the data points you also see no more kind of these squiggles
 here it doesn't happen in in here also if you look at the hidden representations
 the hidden representations now are spread out the classes are bunched up so
 not all the points are bunched up but the the points of individual classes are
 bunched up together and the randomly sampled points are in the middle as
 they should be you say only confident red is down here confident blue is up
 here and everything in between is on confident and third if you look at the
 singular value decompositions of the hidden player and that's kind of a
 measure of how spread out in the different dimensions a data set is you
 see that the manifold mix up here in green it concentrates or it it lowers
 the singular values of the kind of lower indexes so the first singular value is
 large which means that there is like a dominant direction in the in the data
 and this is done for each class separately as I understand it it puts a
 lot of weight on the first singular vector and then it pushes down the
 contributions of the other singular vector which means that the data set
 that is analyzed is is concentrated into fewer directions of variance this is
 layer one and here is layer three means so you see it happens in both that the
 manifold mix up compared to the baseline model does this so now you might ask
 what is manifold mix up it's actually pretty pretty simple concept all right
 here is another comparing it to other kind of regularization techniques and
 showing that none of them really does this so manifold mix up is this
 basically what you do is when you train a neural network you have input data
 and you take many batches of input data specifically you take two many batches X
 and Y and X prime Y prime right and then what you do is if I have the draw the
 neural network here so here is the inputs like a picture of a cat it goes
 through layers right and then what you do is you say at some particular you say
 stop stop right you take the representation out you and you do this
 with two different many batches so here is this is cat one and I'm down back
 here is cat two whatever or dog that's a cat you pass it in right here you take
 it out here you pass it through the network and you take it out so you now
 have two different forward paths of two different many batches and then you
 define a lambda and I guess they randomly sample a lambda in zero one
 right in the range of zero one so this is a mixing coefficient and then you
 mix you say lambda times hidden representation of batch one plus one
 minus lambda of hidden representation of batch two and that is what you pass
 through the rest of the network right so basically you forward propagate two
 different batches until a certain layer here then you mix them with a random
 coefficient and then you pass it through the rest and then the only thing you
 also have to do is then at the end if you think of the labels of these two
 things you want to mix the labels in the same fashion so you want to mix lambda
 times y of batch one plus one minus lambda of y of batch two and then this
 is your training signal for whatever comes out here right so it's it's um
 these are these are one hot labels so if it's class three it's zero zero one zero
 and if y2 is class five it's zero zero zero zero one and then you simply mix
 the two right and that becomes your training signal so in a practical
 example if let's just have a mini batch size of one so just one sample if this
 is cat and this is dog you would pass them forward right you would mix so in
 the hidden representation it would kind of become a cat dog maybe you do it 50
 50 but then you would also mix the labels of cat and dog 50 50 and tell the
 network this is a mixture of 50% cat 50% dog and then you would train the
 network to predict that 50 50 coefficient so they do this the question
 is at which layer do you do this and they simply I think for each mini batch
 sample one hidden layer at random they might have some weighting or something
 but the way they describe it is they simply sample one layer for me per mini
 batch and then do the mixing there and then you can actually back prop through
 everything everything is differentiable this mixing is differentiable so you
 can back prop through any everything and there's even you know kind of an
 engineering trick to only use a single mini batch by mixing it with itself so
 that's that's pretty neat so this manifold mix up as you can see here is
 the that's kind of the description you mix the hidden representations with
 lambda and you mix the labels with the same lambda and that will become your
 actual training signal all right so they give some theory to it that it flattens
 representations and specifically they say under some conditions namely if the
 network is large enough so if the dimension of the hidden representation
 is of a certain size then if you optimize this manifold mix up like if
 you optimize over every lambda and over the entire training data set what you
 will end up is actually a linear function of the input this is not
 too surprising that if you because what you do is you mix linearly this mixture
 happens in a linear fashion so if you optimize for and you not only optimize
 for the training set but you optimize for every possible mixture of the
 training set linear mixture your minimization your minimizer function
 will actually become a linear function it's not surprising but they have a
 formal proof of this and they also have a proof that if certain assumptions are
 given then the minimizers if you apply the minimizers the hidden representations
 will actually fall on a low dimensional subspace which is also not surprising
 but it's kind of the theoretical analog to what they show with with the singular
 value distribution that it basically suppresses low singular values that
 means the data set is much more into a single direction the hidden
 representations sorry all right so this the theory part is you can you can read
 it if you if you want to it's yeah it's it's to the results are to be expected I
 would say from what they do and the last thing they give a pictorial example of
 why manifold mix up flattened representations so both of these things
 the fact that the minimizers will become linear functions and the fact that the
 singular value spectrum is more concentrated on the first singular value
 means basically that representations are flattened and here is a pictorial
 representation so in this case what happens if you if you basically have
 these four data points a 1a 2b 1 and b 2 where a 1 and a 2 are blue class and b 1
 and b 2 are red class and if you now look at an interpolation point between
 the two so if you look at this interpolation point between a 1 and b 2
 what happens is that in this case this should be 50 50 blue and red but if you
 now look at the points that it where it's not interpolated on this is very
 close to a 2 in this case it's probably should be more like 95 blue and 5 red
 do they say here well if you use manifold mix up to learn the network what
 you'll actually do is you say okay actually this hidden representation
 needs to be pushed outward and you will achieve something over here where any
 mixture of two points of the opposite class will actually give you a 50 50 so
 all the mid points here will give you a 50 50 mixture between the labels which
 basically means what you end up with is a line between this data and this data
 and it means that basically the network becomes more linear and the
 representations become more flat because flat is the optimal if your
 distributions are flat all the distances to the line are the same and this
 objective is optimized and this is basically my my kind of biggest problem
 with the method is that it it kind of mixes the input with a linear function
 where we know that that is kind of not the shape of the true data manifold the
 input manifolds as you can see here the input manifold here isn't linear or flat
 it's actually very very tangled and we know that neural networks as you
 continue in the layers will flatten those representations because ultimately
 at the end it needs to classify the data set linearly because the last layer is a
 softmax layer but the the idea that you could apply this to any layer seems a
 bit shady to me of course it works and they show it works and it's really nice
 that it works but applying this to low layers in neural networks seems a bit
 not principled to me so I think this is not the end of the story of this line of
 work and there is kind of more that can be done in a more principled fashion but
 in any case they show that this actually works in terms of performance on
 generalization on kind of standard data sets so they have results on CIFAR-10
 and CIFAR-100 which are famous image data sets and they show that the
 hair regularizer outperforms others and they also show that they can withstand
 one step single step adversarial attacks more kind of better so they have a
 better performance against single step adversarial attacks after
 regularizing mostly again giving kind of an idea that the if you push if you
 push it if you have a two points this is X this is X X 1 X 2 there are different
 classes if you put the decision boundary really close to X 2 then an adversarial
 attack can simply move the point across the decision boundary with a very small
 step but if you actually have the decision boundary pushed away from both
 data points then the an adversarial attack must go a very long way to the
 decision boundary and thus if you limit the size of adversarial attacks which is
 what you usually do you can maybe not reach this decision boundary and thus
 you mitigate some of the problem so it's pretty cool I think yeah there's work to
 be done but I think this is pretty cool it's implemented pretty easy I've seen
 there's a lot of libraries already available with it in and yeah won't hurt
 to add this to your code make your network better and more robust all right
 that was it from me bye bye