Video summary
In this lesson, the focus shifts from the hard perceptron to a "softer" version capable of handling probabilistic outputs through gradient descent. The core concept introduced is the loss function, specifically binary cross-entropy, which quantifies how poorly the current weights perform on a given dataset by measuring the distance between the true label and the predicted probability. This loss is calculated as an average penalty across all data points, where the penalty depends on whether the prediction aligns with the actual class. If the model predicts correctly—meaning the inner product of weights and features has the right sign—the cost is zero; however, if the prediction is wrong, the cost increases proportionally to the magnitude of the error, encouraging the model to adjust its parameters to minimize this average badness.
To find the optimal weights that minimize this loss, the lecture draws an analogy between optimizing a mathematical function and physical motion, such as picking up a pencil without consciously controlling individual muscles. The goal is to descend down the "loss landscape" until reaching the lowest possible point, which represents the best set of weights. This process relies on calculus concepts like scalar fields, level curves, and directional derivatives. The gradient of the loss function at any specific point acts as a compass, pointing in the direction of the steepest ascent. Consequently, to minimize the loss, the algorithm must move in the opposite direction—the negative gradient—which corresponds to the path of steepest descent. This geometric interpretation explains why the update rule involves subtracting a scaled version of the gradient from the current weights.
The final part of the lesson derives the specific update rule for the soft perceptron, revealing that it is essentially logistic regression. By computing the partial derivatives of the cross-entropy loss with respect to each weight component, the instructor demonstrates that the weight update involves adding a term proportional to the difference between the true label and the predicted probability. Unlike the hard perceptron which only corrects errors when a point is misclassified, this softer approach updates weights continuously for every sample based on how confident the model is in its prediction. To make this computationally feasible for large datasets, the lesson introduces stochastic gradient descent, where the model updates its weights after processing just one sample at a time rather than waiting to compute gradients for the entire dataset. This iterative approach allows the system to learn efficiently from massive amounts of data, such as distinguishing spam emails, by treating each new piece of information as a step toward minimizing the overall loss.
Read the full video transcript
So welcome to class.
We made it. So we have today lesson
seven.
All right. So where did we left off last
time? We were introducing at the end of
the last lesson a loss function. A loss
function. It was this curly L for my
weights W given a specific data set.
This was given to me by the average
percent loss which is we can write like
this average this is a percent loss
of w for a specific x and y pair. What
does the loss tell me? The loss tell me
how bad my weights are for a given data
set in this case. And then the curly L
is just on average how bad my weight is
for each X and Y of my data set. This is
just the average. Then we said that my
loss in our soft perceptron was going to
be we ch make a choice in this case X
and Y is going to be the binary cross
entropy. So this is the cross entropy
between y and then my prediction y given
that y t is given to me by the sigmoid
of my weight multiplied by my feature
vector.
This thing here is going to be equal to
y log of y
minus 1 - y * log
of 1 - y t. So this is the binary cross
entropy. Okay.
And this is the the form the shape that
I I usually remember y 1 - y 1 - there
are the minuses such that the logs gives
me a positive value. But then the loss
is a function of my weights. And so
let's rewrite this one in terms of
weights x and y. So we can also write
this one. The loss is going to be equal
and I just use this identity for the Y
t. And so I have that the loss is going
to be Y times the solve plus
of the negative inner product between my
weight and the feature vector for my
specific X. And then I have class 1
minus y and I have soft class
of my
weight transpose my feature vector of x.
As you can see now I have both of these
are equivalent but the second expression
is using weight
the x and then the y. So this is
function of x wx and y in y entropy
measure the distance is a cost and
measure the distance between y and y t.
So that's why I have y and y t in the
expression. Remember how how is this
soft working? So in the case of y= one
we only have this part surviving.
And then if you have y equals z
then you have only this part here
surviving. And so the cross entropy is
you can think about it as the sum. I
don't like it. You can think about this
as having that curly like the curly
bracket and then you have the two
options for y= 1 and for y equals 0. You
understand right? It's a binary option
here. And so how does it work? So if I
write on my horizontal axis
this thing here. So first of all what is
this item here?
It's a matrix. It's a vector. It's a
scalar. What is it?
>> Scal
this guy here. Where am I pointing the
finger?
>> It's a vector right? So these two things
are maybe very large vectors like the
vector with many many many components.
But then as soon as I do the projection
here I'm projecting the feature vector
on the way. I just get a single scaler.
And so here I I show you with a single
axis the projection between weight and
then my feature. And so according to
whether I have the label equal one or
zero I will have two different shapes
right for this cross entropy. So here
I'm going to be plotting the cross
entropy y. So how does the soft be? So
plus is going to be basically positive
like like the bis sector for the
positive things and then basically zero
on the other side right where does it
cross the vertical axis
>> 7 and so this thing here is going to be
something like comes down this way and
then it's going to be zero here and then
it's going to be going going up. This is
for y equals z. And then the other case
we had that it's going to be just what
happens if you put a negative sign. You
just you just flip it on the vertical
axis, right? We I think we know this. So
this one still comes down this way. It's
going to be zero here and then it goes
down crosses 7 and it goes basically
down to zero. So what happens here?
Let's think about it. So let's consider
the case where y equal one. So if my
inner product
is positive I don't pay penalty right
this is how much you pay I don't it's a
cost right cost means how much you money
you spend so if I if it's very positive
my inner product if y equ= 1 my feature
is align with a weight vector and it's
very align then I pay nothing similarly
if y equals 0 and my product is very
negative meaning my f is opposite with W
then I also pay nothing which is
basically what we we're having in the
perceptronum case right if it's positive
if you're falling on the correct side of
decision boundary you don't pay anything
so if you're falling down here you don't
pay anything how about the other case if
my y equal one but my inner product is
negative I pay a price that is
proportional to how negative my inner
product is right you can see if it's
minus one the projection I pay one. If
it's minus2, I pay + two, right? And
therefore, you pay for having W and F
with a not acute angle. Similarly, for
the class Y equals zero, you're going to
start paying whenever your feature and
the weight are aligned.
You pay you pay proportional to how much
this inner product is. All right, this
is kind of review from last class. Then
we finish with a very nice uh plot which
I'm going to be trying to reproduce here
in a quick manner because I think I
failed to show you something. So here we
were trying to what we were trying to do
what why we were trying to choose
different weights last time
again
either maximize the likelihood that is
correct but then in this class we've
been using
minimizing the the loss right the loss
is telling us how bad the weights are so
we'd like to get good weights and so
there is like a scalar value which is
telling us about the goodness or badness
or spec a specific thing. Let me bring
back a friend of ours from 1948. Who am
I bringing back?
>> What?
>> Norbert.
>> Norbert. Yes. Let me bring back Norbert.
So you know you have readings right on
the on the Google Drive. Let's bring
back winner.
So like let's say now I supposed to pick
up my chalk, right? I I pick up a lead
pencil. To do this, I have moved some
muscles in my arm and whatever fingers
to grab the thing. However, for all of
us, but some a few expert anatomist, we
don't know which what these muscles are.
On the contrary, what we will is to pick
up the pencil, right? I can pick up my
chalk without any problem without
knowing what muscles I'm using. So once
we have determined on this our motion
proceeds in such a way that we may say
roughly that the amount by which the
pensy is not yet picked up is decreased
at each stage and so this somehow what
would like I'd like to connect this to
what we are trying to do here we have a
value that is telling us how much we
have to yet travel to get a very good
weight and then we try to decrease this
amount which is telling me oh you
haven't not yet got there. So I try to
decrease decrease decrease until I get
the lowmost loss which is going to be
basically telling me okay this is the
best weight you can get right so there
is some sort of analogy between this guy
here and what we are trying to do so
that's the first recall we we have that
that's why I we are trying to figure out
what's possible weight are going to be
good weights for different what
what did I show you last time so this
stuff how do you pick a
you need to determine
what data set you're interested in. So
different data sets will have different
optimal weights. And so what I show you
last time was here I was going to show
you the different uh losses or how much
you pay. Here I'm showing you just the
feature space. Be careful. This is
the inner product here. Since I cannot
draw in whatever number of space I
consider to have a single feature right.
So considering
my feature vector is simply one and then
f okay single scalar feature this is
from last time and this is going to be
the loss I pay for specific choice
choices of weights and then here
let's say I have different data sets. So
I have data set one,
data set one, then I have data set two.
Data set one was pretty nice. It had
the red points all on one side and then
the blue guys on the other side.
And so we were going to pay. So if these
are going to be the y= 1
and these are the y equals 0
let's say this is zero in this case we
don't want to care too much so if these
are the ones and I have positive f how
much should be the we be my weight
should be positive or negative if my if
this is the zero
posit because of that right we said that
the inner product has to be positive If
my f are positive, then I have to pick a
positive weight in this case, right? And
then we saw so if I pick a positive
weight, I'm going to be ending up with
something like this. So here we were
looking at two possible choices. One is
going to be this one where my W1 my my
weight is going to be equal one. So I
get exactly that one. And then in the
second case, so this is W the weight
equal one. And in the second case, I use
my weight equal two. What happens if you
put a y W equal two? You just speed up
this thing, right? We already we saw
that. I'm not explaining this. I'm just
reviewing the content from last lesson.
And so if I speed up this thing here, I
go twice as fast.
And so if you go twice as fast,
sure
the slow one was crossing
slowly. The fast one is crossing fast,
right?
So the slow one will make you pay for
the red guys, right? because it is a non
zero
non zero non zero lo or loss for these
points. The more you make it steep and
the more this guy will go down on the
other side. Right? This is what we saw
last time. Sweet. So where are we using
W?
W is used for
coming up with my
this guy. And this is what does this
represent?
This is representing what the predicted.
>> Yes. Okay, that's correct. Ya is a
prediction but is a number between 0 and
one which we interpret as
>> the probability of
y
>> y right? So this thing here we interpret
as the probability of y= 1 for that
specific x. Right? And so let's draw
this case here. So let's draw I'm going
to draw here the probability on this
line for y = 1. How do I draw this one?
Well, I just multiply
w * f.
And so if I check I choose this w2, I'm
going to be getting something that is
likely going to be one over here, zero
over here, and then in the middle is
going to be going
down and this is
my probability
this is what we have seen last time I
didn't draw this last part so today new
content is the fact that I drew the
probability
which is
using this specific choice of way right
this is with
with
wal
in the second case if I change my data
set there will be obviously a different
weight which is going to be optimal for
the different data set. So let's now
up the system here and I will get
some of the samples that are going to be
put on the wrong side. Right? So I will
have here a red guy and I will have here
a blue guy and then the rest is going to
be the same.
So we are still having the positive
class on the positive side. So which
should be the sign of my weight to
minimize
the cost?
>> Still positive, right? We haven't
changed the the positive the the sign of
the weight. But in this case, what
happens if I pick W equal to this guy
over here? If I will check how much this
guy pays,
this one pays a lot.
And this red one pay nothing. But what
happens if I choose W equal one? Well, I
pay much less. I pay this amount over
here.
Okay. And yes, the other one on the
right hand side will pay a bit more than
nothing. But the amount I decrease this
one is much larger than the sum of all
the amounts that this one are going to
be paying more, right? And so
how do we evaluate this curly in this
case over here? Here I just show you the
capital L.
>> How do I evaluate the curly L?
>> I take the average.
>> I take the average. Right? So I take the
the penalty the cost each of them pay
and then I compute the average cost.
Right? So there is a cost associated to
each of them. But the cost associated to
this one is so large that when I compute
the average, this one is make me pay so
much much so much more than I would pay
if I choose a smaller weight which is
going to be me making me pay now for the
other red guys but much less overall
than how much I would have pay for the
single bad case in the case I would have
chosen the W equal to. Okay, are we
follow? All right. And so how do I draw
now the probability
for again the same stuff right? So
probability y = 1
given x
with
w = 1
how how is going to change with respect
to the previous
soft right you can see that right so
it's going to be likely one over here
it's going to be likely zero over here
it's going to be likely 0.5 over here
and then This stuff will be like like
that, right? And so here you can see
that this one is much sharper. Right? If
this is the zero
I draw in a diagonal but you can see the
probability that we come up with it's
much smoother and so if there is some
confusion in my points then the overall
probability transition is going to be a
smoother one that is reflecting the
confusion around the decision boundary.
If the data is completely linear I will
just recover basically a vertical edge.
All right. So that was concluding the
lesson from last week.
Now are there better way to do this? How
do we call this? Okay, this is a joke.
This is called GSD.
You know what is GSD?
Yes. Graduate student descent. But
you're undergraduate. So it will be you
GSD.
>> Yeah. Whatever. Right. Okay. And
you figure out by the end of today's
lesson why this is a joke, right? for
the one that don't know. Okay, don't
worry. Okay, so is there a better way to
figure out which weight
to choose to minimize this average of
badnesses? Yes.
>> So what is this function over here? So
let's let's get some uh some
definitions. So assuming
a given
data set. So we are just looking at one
of these data sets. Let's take this like
let's let's let's stop it like let's fix
it. So assuming a given data set this
function
it's mapping
RN to
R plus
what what is the name of this thing? No
not the the loss. What is the the symbol
here? Do you know what is this notation?
>> Like when you find distance usually. No.
>> Right.
Are you familiar with the column sum set
arrow set?
>> It's a function.
>> This is a function. A function notation.
I'm defining the domain and the image of
a specific. Are you writing down notes?
No. Okay. I don't know how you're going
to be learning anything without writing
down. Anyway, so this is going to be a
non negative
scalar field.
What is a scalar field? It's basically a
like an ark, right? This is a scalar
field.
This is this is like a scalar field.
It's defined over a specific domain, but
then there is only one height. So this
like a it's a blanket on a specific
domain underneath. And this blanket is
actually only positive. We don't care
the rate of change.
of L
at W along
direction
is called
the directional
derivative.
Okay. So we have a specific so this guy
here where does you live? So u it's a
cursor is a unit vector. U
is a unit
vector that lives where
>> yeah.
All right. So it's just a direction. And
so the directional derivative it tells
me how much a scalar field changes in
that specific direction. Okay. This is
definition.
Okay, the directional derivative d u of
l e w0
is given to me by
the inner product between this weird
symbol here
and u okay and this thing here let's
find out what it is this item over here
which is called the gradient of l in W0
is going to be the Jacobian of L
in W
which is simply the collection of the
partial derivative
with respect to all
the parameters. Okay. So this guy over
here is called the gradient
of L in
Z. This thing here is called the
Jacobian.
And this is just the this is a partial
derivative, right? This is a partial
derivative.
You already seen this. Who hasn't seen
this before?
One, two, three, four. Okay. Have you
seen partial derivatives?
No. Have you seen derivatives? Yes.
Okay. So, how many? This is going to be
a function of multiple variables.
Usually in this case so far, we only had
a single W. Here we have multiple W's.
We have W1, W2, W3. So
the loss when I write loss of W this
means I'm talking about loss with
respect to the first component second
component
and n component there are multiple
component and so each of these item here
is the derivative of this function
considering it as a function of the
whatever component I show here. So this
is here is the der the derivative of my
loss function with respect to the second
value. All the other I consider just
constant like numbers. You don't you
don't care.
So just like w should be a vector right
w is yes is a location which I call it
w0. So let me put a zero on top so we
don't get confused.
>> I just mean like for the you so above to
the right. Yes, yes, yes, yes. Let me
put a zero on top so I don't get
>> so this is a vector I call it w0
and these are all the partial derivative
with respect to each component and then
it's going to be evaluated at the
specific location. This is a specific
location.
Sorry guys.
So this is a specific location.
We are looking at this napkin, right?
This kind of cloth. And then if I'm at a
specific point, which I call it W0, then
what is the rate of change in this
direction?
Well, I can just check a specific
direction. U is going to be one of the
directions I'm looking at. And I see how
much this function goes up and down.
Okay.
What w is
>> a specific location. So but how do we
choose?
>> No, it's arbitrary location. So let's
say I have in this case only two
dimensional. So n equals 2. So I have w1
here, w2 here. This location over here I
will call it my W0 which is a specific
W 1 and W 2 0. It's a specific point.
>> Okay.
>> These are gradient is computed at just
one point.
>> Correct. So the gradient
if I wouldn't put a zero will be the
function
>> is a gradient function. If I put the
actual zero is the gradient evaluated at
that point. It's a number. It's a it's a
it's a vector. Okay, it's a numerical
vector. This is going to be my my point
here. I may have my
something like that.
This is my surface.
And then I go up to the location on the
surface. And at this I in this location
I gonna check for example if this is
going to be my u hat. This is the
direction I'm looking at. And here I
like to see in this direction
how is this what is the the rate of
change of the function. It's going to be
up going down. So I can just check every
possible direction. I'm on some surface.
I can go in every direction and see oh
it's going to be going up or down. Okay.
I check this direction. It's going to be
going up and down.
Let me show you a picture so you can
actually I mean I draw the thing but let
me show you this going to be my
whatever surface and all along these red
lines the height doesn't change. Okay.
So either you play plot things in 3D or
you can actually plot them down on the
bottom side. You can see all the
locations where the height of this
function is constant.
But we were talking about these
gradients. Let me show you the gradients
in one sec. So this is going to be my
surface I'm talking about. This is going
to be my initial location, the W0. And
then I look at a specific direction.
That's my U direction. So in that U
direction, I go up on my on my surface
and I going to be checking what is the
rate of change in that specific
direction. This is the d directional
derivative of my surface my my scalar
field at this w location. Okay.
So here we are looking at this. So what
can I do now? I can change you and I
will be able to look at the rate of
change in possible different direction.
My question for you, what is the
direction where I have the largest rate
of change
in the direction of gradient? So what is
the meaning of this thing here?
So this is the inner product, right,
between two vectors.
>> This is how much is this stuff, right?
This is a scalar, right? This is scalar
value, right? It's the inner product of
two different things. So this is going
to be equal the magnitude of the first
times the magnitude of the second one
times
of the angle between the two. Okay. How
much is this guy here? The magnitude of
the unit vector.
>> Okay. Very good.
How much is the magnitude of this thing?
I don't know. is the magnitude of this
vector over here. Now I can change u I
can change the direction
which is the direction which gives me
the largest overall product of items.
The only thing I can change is gonna be
the angle here five right and so when is
when is the cosine maximum
>> zero
>> when the phi is zero right and therefore
whenever my direction u is aligned to
the direction of this item over here I
will have the maximum increase of this
function.
Okay. And so we have that this horrible
vector over here tells me two different
things. The first one tells me what what
is the direction
of maximum
>> maximum increase of the function. The
second thing that tells me which is the
magnitude is the actual maximum rate of
change. Right? So it tells you two
different things. The direction of
maximal maximum change and the amount of
maximum change. So let's write it down.
Okay. The gradient
of L in
W0 points
in the direction
of
maximum
increase
its magnitude its length.
tells us what
>> rate of change.
>> The maximum rate of change that function
has the maximum
rate of change.
Well, the maximum
directional derivative, right? Okay,
whatever we can write it down. Maximum
range of
change
of L in
so this is not definition but we kind of
understand right who's not understanding
okay don't be shy let me back up to the
picture I show you before so these are
again these red lines are the locations
where the height doesn't change so what
is the
rate of change along the red lines
>> the directional derivative if I point if
I am on one of these red circle circle
let's say I am at specific location
right can you see my mouse yeah I am at
specific location here the purple one
where okay where the the arrow is let's
let's assume we are at the arrow and
let's consider the directional
derivative with the direction being
tangent to the level curve. What is the
derivative?
What is the directional derivative for
the direction tangent of the level
curve?
>> 0
>> zero. Why?
>> Because we're not changing
>> because along the level curve the height
doesn't change by definition. Maybe I
didn't show you the definition. Do I
have the definition?
Yes, I have the definition. So the
definition of level curves that you
haven't seen before is of a function f
of in this case two variables are the
curves of equations whatever the height
is constant where a is a constant right
so the the curves where the height is
constant that's called a level curve
okay therefore if you compute the
directional derivative in that in the t
for a direction that is tangent to the
level curve is going to be zero now a
question for
What is going to be the direction of
steepest ascent?
Perpendicular to the level curve. Why?
See, I don't want you to answer because
you memorize something. This is not a
class where you're memorizing things.
Here we are trying to build some
understanding.
Don't get it wrong. Right? I'm trying to
to want to make you reason about this.
Why is this blue curve
the direction of steepest ascent
along the red line? We said the
derivative is
>> zero. Then I turn, I turn, I turn, I
turn, I turn, I get orthogonal to the
level curve. Then you have the maximum
in this case. I go I go I go I go again
when I am once again on the
zero right and then I go again again
again again again I get the direction of
steepest
descent oh what is the title of today's
class
>> oh so now we figure out how to find the
direction to go downhill. Why do we want
to go why do we want to go downhill?
because we want to minimize this damn
loss right of my weight. So, we're going
to be using the direction of steepest
descent. What is the steepest descent?
Well, if the gradient points in the
direction of maximum increase, this is
direction of maximum increase. I just
have it backward.
>> Are we all on board? Are we lost? No, we
understand. Yes. Question. Will the
graph always look like this? Is any
other shape possible?
>> That's the next slide. We have so much
time. Oh, okay. No, we don't have much
time. I want to just You don't know
what's coming, right? No, you don't
know. Okay. I don't know.
Okay. I'm improvising. There we go. This
is going to be our exercise for now. We
have to figure out which goes with
which, right? This is like primary
school
thing.
Okay. Which curve go? Which letter
curves go with which one? Right. So A,
where does A go? In first, second,
third, fourth, fifth, and sixth. Show me
with your Okay. You have fingers, right?
Your in your hands. Both all of you have
at least six fingers, right? You don't
Okay. Show me with your hand with where
A goes, right? Yeah, that's correct.
I don't know that this those are
correct. Those are not correct.
Okay, some of you are mostly correct.
Let's try number uh B, right? Where is B
going?
Okay, most of you are wrong. How about
C?
Where is C? Let me see. C. Yeah, C.
Yeah, now you're correct. You're correct
as well. You're correct. You're not
correct.
You're incorrect. What about you?
Where's he go? See?
>> Yeah, I know. You're supposed to show
them. my fingers. Anyway,
okay. Let's go here.
If you know this is six, right? You know
how to use, right? E R S.
All right. How about D?
Where is D? D. Yeah. Okay, very good.
High five. How about E?
Okay. And F. Well, it's the last one,
right? Okay. Very good. So, we
understood the the assignment. Amazing.
Yeah. So, if you are not really familiar
with these things, you haven't seen it
them before, there is the chapter 14 of
this book. You can find it wherever you
want to find it. Right. All right. One
more. This one. What happened here? What
am I showing you here? As you can see,
these are my gradients.
So, where is the maximum of this
function here?
>> Think about
what is maximum.
Yeah.
What does the what does this what does
this symbol mean here? Look what what
how do we call this in English or
length?
>> Pink. Pink. Pink. Just think. Yeah.
Yeah. Sure. Okay. One more one more
bonus thing. See, today we have a lot of
things.
>> Today also we have Wikipedia
the end.
So what's happening here? So as you see
the black curves are representing the
level curves. This one is going to be a
maximum. The yellow means very high
value. The blue means it's a minimum. We
are starting at specific random well
some locations and then all these blue
curves
are always always perpendicular
to the level curves. Okay. So at given
locations we are performing one step in
what direction?
>> Negative gradient.
>> The negative gradient. Right. So how do
we call this one? Let me actually write
it down because we didn't even call it.
Therefore, we will
be mice
add
one sample
at a time
such that we're going to have my weight
is going to be my weight minus
EA gradient
weight.
Okay.
is this procedure
in the so
okay
additionally for now So ita is called
learning
and for now
equal one. Same with beta where we don't
whenever we don't care about beta or ea
or whatever we just set it to one we're
going to forget about ea for and so just
pay attention the gradient is a vector.
Meanwhile, here we were looking at the
transpose gradient which is the
Jacobian, right? The Jacobian is the the
transpose of the of the gradient. So
this is the gradient is a column vector.
I subtract from my weight a proportion
like something proportional to the
negative gradient of my percent loss.
Okay, L is the percent of those
B per
although we are trying to minimize the
average of the Bness. It turns out that
the procedure that we're going to be
using for now is going to be just taking
each sample each like one sample I
compute one gradient I perform one step.
I take another sample, I comput another
gradient, I perform one other step and
so on and so on and so on. So this is
like iterative procedure. I do one step
at a time because otherwise the
alternative
it would be to take all the points,
compute all the gradients, average out
all those gradients, then one do one
step. It takes forever because every
single time you compute all the
gradients to do one step and it turns
out that if you have duplicate in your
data set, you're just wasting
computation. If I have the same email
twice
and the same label, I'm just computing
the same gradient twice. And is this
reasonable? Yes, it is very reasonable
because
if all these emails weren't going to be
kind of similar, it would be hopeless
for your system to be able to detect
spam and so if you pick one email, one
spam, two spam, 100,000 spam, most of
them will be looking like spam and so
you're just getting gradients that are
basically identical. And so if you just
want to compute the gradient for this
guy, you're just wasting computations.
Meanwhile, what we are going to be doing
is going to be for each email, I compute
my gradient, I update my weight. I take
the second email, I compute the
gradient, I apply the weight. Third
email, I compute the gradient, up the
yada yada. Okay. Yeah.
>> So, we're saying this approximates that.
So uh if we use for example L it will be
approximately equal to
>> this gradient here with respect like the
gradient of the capital L is a
stochastic approximation of the gradient
of the curly guy. The curly guy is the
average of all these gradients. But if I
have a data set of 100,000 emails I have
to comput 100,000 gradients to just
compute one gradient for the curve and
do one step. It takes forever. If your
data set is infinite, you're never
stepping in like let's say you're
training CHGPT on the internet. If you
want to read the whole internet before
doing a single step, you don't go
anywhere, right? Meanwhile, you just
should read one thing step one thing
step one thing step right more or less.
Other questions?
>> Yeah. Where do we start from?
>> Zero zero.
>> Yes. Don't worry. I I I make sure in the
next part we have
>> do we start next part? Of course I'm
going to start a new part but Okay. Do
you have other questions? No. Right.
Okay. So brace yourself for what's
coming
today. Should have been this the second
part should have been the main part but
then I had the different things with the
with the screens. I didn't plan we we
didn't have them before. Let's take a
picture.
All right. What was the last line I just
erased?
>> Stoastic gradient.
>> Okay. So, where are we starting?
>> We are going to compute a gradient of
our capital L. What was the first line
here? What is our L?
You forgot
>> average.
>> Capital L.
>> Average.
>> No, no, no, no. That's curly L.
>> Sure. Which per sample loss are we
using?
>> Entent entropy. So let's talk about
let's compute gradient
of the percent.
We need the fact that y is defined as my
sigma of
omega f
and which is going to be 1
+ x
of negative omega
f omega sorry w
minus one. Okay. And then we're going to
be computing now well we're going to be
reviewing what is the cross entropy
for
y = 1 and my y.
This is remember I just use the inner
product. I have simply the soft
plus which one?
the one right of the negative
w
okay
which is simply
correct right
sweet so what is the gradient for this
guy so instead of gradient let's go to
jacobians again it's all the same right
cares So I'm going to be computing
the partial of this guy here
of log.
>> Okay.
>> Derivative of function of functions is a
function of a function. Right? has a
multiplication inside
right. Okay. So what multiplied by?
>> Wip.
>> Yeah. I I just write what I think you
said.
>> And then what?
>> What's coming out? One more thing.
Right.
Okay,
now I just do some cleaning.
What is this?
Very
good.
>> Okay.
What is this
thing here?
This is one minus this thing, right?
So I can also write down here.
>> Wait a
ask where can we learn to take
derivatives of matrices and vectors? Is
there like a book?
>> You don't care. try just use it as a
don't worry just just pretend there is
it's not a it's not a vector you don't
you don't care I know like there is a
book there is Wikipedia there are many
sources there's a book the book I I use
for today's lesson but you don't care
okay so this guy here is the what
>> this thing Here is
>> this thing here is
>> yeah which is
>> this is the what what is this stuff
giving us? This is
>> so what is this thing here
yals?
>> Yeah exactly. Thank you.
Okay. So for the case where
y = 1,
we have that my weight
will be the weight minus
the gradient.
So minus
the gradient.
The gradient will be the transpose of
one thing
transpose advance one
>> this is the Jacobian this is the gra
>> no but like it's there it's minus one
minus y till the frpose
>> correct
>> but very you wrote just as f
>> that is correct from the previous
blackboard this is jacobian this is
transpose algebra
just notation just forget about the the
transpose doesn't matter so what
happened in this case we can also write
yes any question yeah
>> each row the joy matrix is a gradient
right that's why we're doing the
transpose thing right here
>> yeah so the the definition from previous
from previous board here we had that the
transpose
so this guy here the Transpose of this
one is the Jacobian of L which is the
row vector
of all the partial
okay so this is a column vector so they
are one oh I didn't write the
another notation for this one here is
the following
there you go my bad so this thing here
is k another notation for this jacobian
here which is going to be this thing
over my bad I didn't define that this
notation over here
what's happening
if I perform a prediction so this is
going to be again the probability of
y= z
if x
so you make a prediction
You have you assign the some belongness
of this specific X to the red class and
to the blue class. The email was a red
red one was plus one. So I will sum F to
my W to my weight proportionally to how
much I think it should be the blue
class. If I think it's not the blue
class, I don't sum anything. If I think
it's just a little bit the blue class,
then I sum just a little bit of F. If I
think it's really the blue class, then I
sum a lot my F. So this one allows me to
sum between zero to like is a multiplier
that goes from 0 to one, which is
allowing me to sum to my current weight,
the feature vector scaled by this
proportional value. Okay, this this
multiplier.
Okay, let's do the second one. Second
part is going to be basically identical.
I have the fire cell of my cross entropy
for the other class
with respect to the weight is going to
be what?
Well, we had to actually write down this
on the right. So, I didn't write the
definition. Let's write down here. So,
we have the cross entropy for this this
case.
This is going to be what? Soft plus of
the positive thing. Right? This is soft
plus
of the positive inner product
which is going to be 1 log
1 + x
of this thing here. Right?
So we take the derivative. It's going to
be identical but there is the minus not
without a minus minus. So we had x
w transpose f
/ 1 + x
w f*
frppose
I divide it and I get 1 / 1 + x
of negative
w F
* F transpose
which is going to be this is our sigmoid
right this is my sigmoid
of W of F
times my left transpose and we know this
one is again
my Y tild this guy here is my Y right
going to be again the probability the
same right as the probability
of
y = 1 given my x
and so for the second case what happens
if I have that with y = 0
we are going to be
updating my weight
as my weight minus this thing here right
minus
my weight times my
So in this case we were summing the
feature proportional to how much we are
giving the attribute to the other class.
In this class we were supposed to get
zero and so we're going to be
subtracting
the feature. Right? If I want to have
zero I have to lower the inner product.
How much do I lower proportional to the
this item over here? I have y equals z.
I have to lower my inner product. So I
subtract. I have y= 1. I want to add to
increment the inner product. Right? It's
very similar to what we were doing
before. Let me add some more things.
What is this thing over here?
Cool. Probability y - y tilda. Yeah.
Same thing there. It will be y - y
tilda.
Okay,
for both cases,
if I if I summarize, we have that we sum
to my wave factor
the difference between y and y tilda.
Finally, if I put together, we have the
given data set
and
a zero vector.
I pick
one email
label Y
compute
the feature
and use
the following
This is known
as
this
regression.
Although
a better name
logistic
classification
and the logistic comes from the sigma,
right?
Okay, so we kind of put all together
there is a few derivatives there which
we computed but then overall what is
this rule? This looks the same as
our
>> perception the same thing, right? But
the only difference well the only it's a
major difference. This thing is a number
between zero and one. Okay, but this you
do exactly the same thing. You just have
always this is no longer error
correcting algorithm because you're not
just correcting errors. You always have
a nonzero difference here. So you always
change in this way.
That was today's lesson.
Questions? No questions.