Proximal Policy Optimization (PPO) is a reinforcement learning algorithm that enables AI agents to modify their decision-making by using two neural networks—a policy network that outputs a probability distribution over possible actions given a state, and a value function network that outputs Q-values quantifying how good each action was. The algorithm works by collecting experience data (state, action, reward, action probability) during episodes, then computing advantages as the difference between actual future rewards and predicted Q-values. These advantages are used to calculate losses for both networks: the value function loss minimizes the squared advantage across the batch, while the policy loss uses clipped probability ratios multiplied by advantages to ensure stable updates. PPO balances effective policy improvements with cautious updates, making it suitable for training complex models like ChatGPT to produce safe, factual, and non-toxic responses.
Proximal Policy Optimization: RL Algorithm Explained | PPO Tutorial
Added:greetings fellow Learners now before we embark on our journey towards understanding proximal policy optimization I have a question for you how do you modify your decision making for a certain activity that you do or what does it take to modify your decision- making for a certain activity can you express this at all in words now this could be your decision- making on how you invest money or decision- making on your exercise routine or just any anything else share your thoughts in the comments down below and I would love to hear them in this video we're going to delve into a popular method that an AI uses to modify its decision making called proximal policy optimization this video is going to be divided into three passes where in the first pass we'll start by introducing some Concepts and definitions and as we go down into the later passes we'll dive into further details about the algorithm itself pay attention because I'm going to quiz you along the way so let's get to it the Poo algorithm makes use of two main architectures a policy Network and a value function Network they are both neural networks that take an input and return an output the policy network will take a stateus input and it will produce an action as output from an architecture standpoint the output layer this network has a number of neurons equal to the number of possible actions it can take and each neuron is a probability that an action is taken when the agent is in the input State the value function takes a state and an action as input and it will output a real number that quantifies how good was this decision this number is known as a q value from an architecture standpoint as was with the policy netor Network the output layer of this network has the number of neurons equal to the number of possible actions it can take and so technically this value function neural network will take in a state as input and for every action it is going to determine a q value and this will quantify how good was this specific output action for this specific State quiz time have you been paying attention let's quiz you to find out what is the primary function of the output layer in the policy network of this PO algorithm a it outputs Q values for the given State and action B it produces a probability distribution over possible actions given the input State C it calculates the advantage estimates for policy updates or D it generates random actions for exploration comment your answer down below and let's just have a discussion and if you think I deserve it and you love learning please consider hitting that like button now that's going to do for quiz time and pass one of our explanation but I'll be back so pay attention to help us out let's bring out Frank our lovely friend say hi Frank hello what a cutie now Frank is in this grid world and he needs to know how to get to that plus 10 reward spot now to do so he can take the actions of left right up or down and in this pass we're going to give an overview of how Frank can learn to navigate this world using po so let's talk about the overview of the training process Frank starts at some random State the state is passed into a policy Network the policy network will determine the probability of generating each action this is then a probability distribution and we sample from this to determine the actual next action Frank then takes that next action and will receive some reward we then stored the quadruple of the state action reward and action probability into a data store this information will be used ful when training the policy Network and the value function Network and we'll talk about this later we now repeat the sequence of steps for the episode or some fixed number of time steps within the episode now we have data stored in this episode as a batch and we can collect multiple batches if we choose but let's just stop over here thanks for the help Frank we'll take it from here and we're going to help you learn okay nice now let's talk about training the two networks take the batch of the state action reward and action probability now the state in action are used with the value function Network to give us a q value and like we said before this will quantify how good do we expect this action to be we then determine the total future reward for every time step using the data that we stored and this will quantify how good did we actually perform we take the difference between these two values and this difference is known as the advantage we use this advantage in order to compute a loss this loss is then back back propagated through the value function Network and so it learns we then use the same advantage and probabilities that we stored previously to determine the loss for the policy Network the loss is back propagated through the policy Network so its parameters are updated and then we repeat this process for all batches of data effectively the policy Network and the value function Network get better over time as they learn over time together and Frank learns to make better and better decisions so that he can get to that plus 10 reward square and this is an overview of the one iteration for proximal policy optimization quiz time I'm back back have you been paying attention let's quiz you to find out what is the main purpose of the Q values produced by the value function Network in po a to represent the probabilities of different actions given a state B to calculate the advantage estimates using policy updates C to generate probability distribution over possible actions or D to produce random actions for exploration comment your answer down below and let's have a discussion that'll do it for quiz time for now and also P two but keep paying attention because I will be back to quiz you so in past two we saw that the value function Network and the policy Network are trained together and the overview of the steps is basically we compute the LW loss for the value function Network we compute the loss for the policy Network we update both networks together and repeat and then Frank becomes better and better as a decision maker let's now take the overview of the process that we discussed in pass two but we're going to add a few more details specifically along the loss function calculation so let's start with the value function Network and generating its loss so we get the batch of data for the episode that we stored in past two for each time step we compute the actual future reward with the data gathered and this is done by taking the sum of discounted future rewards and then we can compute the expected future reward by passing the state into the value function neural network and it produces a q value for every action and then we look at the Q value for the specific action neuron in our Tuple so for every every time step we have two numbers we take the difference between these two numbers to get the advantage we Square the advantage for every time step and we can take the average of this across the batch this final number is a loss that we back propagate through the value function Network and so the neural network learns and at the same time all of this happens we are also training the policy Network so let's see how that's going now if we write it in mathematical form the policy Network loss looks like this very cumbersome but let's explain what's going on first we'll get the batch of data that we stored next pass the batch of states to the policy Network to get the probabilities of actions in each case we only consider the probability of the action taken when we gathered the data we then divide two numbers that is a probability for the specific action that we have now divided by the probability we collected previously and this is a probability ratio we'll multiply this ratio with the advantage computed in this time step and so for every time step in the episode we have a number let's keep this number aside and hold on to this Frank for me okay okay nice next we take the probability ratio and we'll clip it to ensure that we're not changing the network too much we multiply this by the advantage and so now for every time step we have two values we'll take the minimum of these values and then when we take the average of the values across the batch we'll get a single number this single number is our loss that is back propagated through the policy Network so this is quite a bit of steps but overall the loss function strikes a balance between making effective policy updates to improve per performance and making cautious policy updates to improve stability and effectively the value function Network and the policy Network are trained together and that is po quiz time this is going to be a fun one have you been paying attention let's quiz you to find out what is the primary purpose of computing the advantage in the loss function for the value function Network a to determine the ratio of probabilities between the old and new policies B to calculate the expected future rewards and guide updates to the value function C to click the probability ratio and ensure stable policy updates or D to compute the loss for the policy Network during training comment your answer down below and let's just have a discussion and once again if you do think I deserve this and you haven't done so yet please consider hitting that like button thank you so much and that will do it for quiz time for this video but before we go let's get a [Music] summary proximal policy optimization algorithm is used to learn a policy directly now the PO algorithm makes use of two architectures a policy Network and a value function Network the polic Network predicts a probability distribution of actions whereas the value function Network predicts Q values for every action taken from a state the PO algorithm involves training a policy Network and the value function Network iteratively and together and just as a new tidbit here but this algorithm is actually used by chat GPT and other large language models today to ensure that the responses that they give are safe factual and non-toxic now that's all we have for today and if you like this video please do consider giving it a like and if you want to look at some similar videos here check out this video on deep Q networks and just caution I'm going to be quizzing you a lot in this video too so if you like all that stuff please do check it out and I will see you in the next one bye-bye
Up Next

Train a Humanoid to Walk: Stable Baselines3 & Soft Actor-Critic
@johnnycode
16.5K views•2023-07-20

Building Real-Time ML Pipelines with Feature Stores and MLOps Frameworks
@ODSCAI
5.1K views•2022-02-20

Q-Learning Explained: A Guide to Reinforcement Learning Basics
@CodeEmporium
82.4K views•2023-11-07

Neural Networks Explained: Math, Layers, and Learning Fundamentals
@3blue1brown
21.9M views•2017-10-05
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Artificial Intelligence
![doc V. Lisý: Introduction to Artificial Intelligence (BE4B36ZUI) — 05 [18. 3. 2025, LS 24/25]](https://i.ytimg.com/vi/zKFE0LsdN9c/maxresdefault.jpg)






































