-: Hello and welcome to this Python tutorial.
All right, so we just made the brain
and now let's make the body.
So as you understood, the body is the part where we define
how the actions are gonna be played.
Like what happens for real human body, you know,
you have the brain that send the signals to the body
and then your body plays the action.
Well, here that's the same.
We have our signals coming from the brain.
We get the output signal with the forward function here.
You know, first what happens is that we get the images.
The images go into the eyes of the neural network
composed of the three convolutional layers,
and then with the fully connected layers,
we get the output signal from the brain,
which contains the Q values.
But then, this output signal should be forwarded
to the body and the body will play the action.
And so that's exactly the part
that we're gonna take care of right now.
We're gonna implement the way the body will play the action
and the way it will do it is with a Softmax method,
exactly like for the self-driving car.
I insist that the Softmax method is highly recommended
for playing in action with the body of the AI
and therefore, that's the one we're gonna go for.
But as opposed to the self-driving code,
we're gonna make a class.
And this class will, of course,
correspond to the body of the AI.
And therefore, let's start by introducing class here.
That's where we're gonna go.
Softmax body, like this.
I don't wanna call it Softmax only
because Softmax is a class of PyTorch from the nn.Module.
So it's dangerous to call it this way,
therefore I'm calling it Softmax body
and now, it's very clear that our CNN,
Convolutional Neural Network is the brain
and Softmax body is the body of the AI.
So Softmax body, and let's inherit from the nn.Module.
I don't think we're gonna use it,
but anyway we can still inherit from it.
You know, in case you want to improve
this Softmax body class
and wanna use some tools from the nn.Module,
while you will be able to do it with the nn.Module.
But at this point, I don't think
we'll be using any of the nn.Module.
So then colon, and let's go inside the body.
All right, so first as usual,
we're gonna start with our _init_ function
to define the variables of the future body objects
that is the bodies of the AI.
And actually, as for a human body,
a parameter that can define it is the temperature.
And actually that's gonna be the only temperature
so it's a simple body, but still,
using this temperature parameter will do a lot for us.
Okay? But before the temperature,
let's not forget the self for the objects for the bodies.
And now we can input the temperature T,
which is the same parameter
as the one we use for the self-driving car.
Okay? And then colon,
and let's define our variables.
So, since we inherit from the _init_ module,
we're gonna use the super() function again
and so, let's be efficient.
Let's copy this and let's paste that right here.
And of course, let's not forget
to replace CNN here by Softmax body.
There you go.
Now, I suppose that might become a reflex for you
to use the super() function at this stage.
And then, what we have to do is of course,
set our temperature variable with self.T
and that will be equal to the argument that will be input
when creating an object to Softmax body class.
I remind that whenever you create an object
of the Softmax body class,
you have to input the arguments
that are in the _init_ function, and therefore that is T.
And then, the variable of your object attached
to your object self.T will be equal to this T
which is the argument that you will input.
All right, and now that's it for the _init_ function
that's actually all we need.
So, I guess we're ready to move on
to the next function of the Softmax body class
and this is gonna be the last function.
There only two functions, the _init_ function
and the next one that will implement in the next tutorial
which will be the forward function and why forward?
That's because right now, we have to forward
the output signal from the brain.
That is, you know,
the Q values contained in the output neurons
of the output layer to the body which will play the action.
So we are forwarding the output signal from the brain
to the body that will play the action.
Move forward, go left, go right,
turn left, turn right, or shoot.
All right, so let's do that in the next tutorial
and until then, enjoy AI.