AI Crash Course: A fun and hands-on introduction to machine learning, reinforcement learning, deep learning, and artificial intelligence - podcast episode cover

AI Crash Course: A fun and hands-on introduction to machine learning, reinforcement learning, deep learning, and artificial intelligence

Jun 16, 202524 min
--:--
--:--
Download Metacast podcast app
Listen to this episode in Metacast mobile app
Don't just listen to podcasts. Learn from them with transcripts, summaries, and chapters for every episode. Skim, search, and bookmark insights. Learn more

Episode description

Offers a comprehensive AI Crash Course authored by Hadelin de Ponteves, with contributions from Jan Warchocki and Kirill Eremenko, and published by Packt Publishing. This hands-on introduction covers various Artificial Intelligence (AI) concepts, including reinforcement learning, deep learning, and artificial neural networks, with practical applications in Python. The book systematically explains core AI principles like Thompson Sampling for decision-making and Q-learning for optimal pathfinding, illustrating them through real-world scenarios such as e-commerce advertising and warehouse logistics. It further explores deep Q-learning for complex problems like self-driving cars and server temperature optimization, culminating in an application of deep convolutional Q-learning for AI in games like Snake. The text emphasizes intuition over pure mathematics and provides a general AI framework along with code examples accessible on GitHub, encouraging readers to practice and apply their newfound AI skills across diverse industries.

You can listen and download our episodes for free on more than 10 different platforms:
https://linktr.ee/cyber_security_summary

Get the Book now from Amazon:
https://www.amazon.com/Crash-Course-hands-introduction-reinforcement/dp/1838645357?&linkCode=ll1&tag=cvthunderx-20&linkId=fb128ffc1d4a587069c893167c98db0b&language=en_US&ref_=as_li_ss_tl


Discover our free courses in tech and cybersecurity, Start learning today:
https://linktr.ee/cybercode_academy

Transcript

Speaker 1

Welcome to the deep dive. We take source materials, unpack complex topics and basically give you the crucial insights and maybe some surprising facts along the way.

Speaker 2

Yeah, think of it as your shortcut to getting up to speed exactly.

Speaker 1

So today we're diving into some excerpts from a book AI Crash Course. We're looking specifically at chapters covering reinforcement learning, deep learning, and AI in general.

Speaker 2

Right, and this source it positions itself as a kind of all in one guide. It's built from online courses that were apparently quite successful, okay, and it really stresses getting the intuition first, then the math, and then you know, actually coding things.

Speaker 1

Up right, intuition first. So our mission here is to pull out those core ideas, help build that intuitive feel, and look at some of the well pretty exciting real world applications they talk about. The idea is to help you, the listener, understand how these AI models actually work and importantly, where they might be used.

Speaker 2

When the book sets a big stage, it talks about AI's potential impact across well almost every transport, education, security, jobs, entertainment.

Speaker 1

Even the environment, So a lot of potential there.

Speaker 2

Definitely. It frames these technologies as potentially transformative.

Speaker 1

Okay, let's unpack this. Where does our source material suggest we start when building an AI, especially in this reinforcement learning space.

Speaker 2

It starts with the absolute foundation. You have to define the AI's environment.

Speaker 1

The environment.

Speaker 2

Yeah, that's the world, the context the AI operates in. And it's got three really key parts. All right, what are those first up? States? States are basically the inputs the AI gets what it perceives.

Speaker 1

Like sensor readings for a self driving car.

Speaker 2

Maybe exactly, sensor reading speed, location, or for a simple robot in a maze, the state might just be which square is currently in It's the where am I? Or what's happening info?

Speaker 1

Okay, so state is what the AI knows about its situation. What's next?

Speaker 2

Next are the actions. These are the things the AI can do, the choices it can make.

Speaker 1

So for the car, turn left, accelerate, break.

Speaker 2

Yep, or for the maze robot move north south east west, those are its possible moves, its decisions makes sense.

Speaker 1

State action, and the third piece must be important.

Speaker 2

Critically important rewards. This is the feedback what the AI gets after it it takes an action in a certain state.

Speaker 1

Ah, the feedback loop.

Speaker 2

Precisely, it could be positive like reaching a goal, or negative like hitting a wall. This reward signal is what guides the AI. It tells it what's good and what's bad.

Speaker 1

So the whole game for the AI is to figure out how to act, which actions to take in which states to get the most reward possible over time.

Speaker 2

That's the core idea, maximize cumulative reward. It learns by essentially trial and error driven by those rewards. And the source makes this important distinction too, between training mode and inference.

Speaker 1

Mode, right. Training versus inference.

Speaker 2

Training is where it's learning, interacting, getting rewards, updating it to understanding. For instance, well at showtime, the trained AI uses what it learned to just do the task without learning anymore.

Speaker 1

Got it learn first, then perform. So with that framework state's actions rewards, what's like the first actual AI model the book introduces.

Speaker 2

It kicks off with the classic problem, actually the multi arm banded problem.

Speaker 1

Ah, the slot machines. I remember this.

Speaker 2

One, yeah, exactly, multiple slot machines bandits in a casino. Each pays out with a different probability, but you don't know those probabilities.

Speaker 1

So the question is, how do you play them to maximize your winnings over time without knowing which machine is actually best initially exactly.

Speaker 2

And the AI approach discussed is Thompson sampling.

Speaker 1

Thompson sampling. Okay, what's the intuition there?

Speaker 2

Sound statistical, it is, but the intuition is quite neat. You could just keep playing the machine that's paid out the most.

Speaker 1

So far, right, Yeah, seems logical.

Speaker 2

Exploit the winner, but that winner might just be on a lucky streak.

Speaker 1

Thompson sampling is smarter. It keeps track of wins and losses for each machine, okay, and uses that history to maintain a probability distribution for each machine's likely success rate, specifically a beta distribution.

Speaker 2

A beta distribution, so more wins on a machine means its distribution shifts towards predicting higher success Right.

Speaker 1

More wins, fewer losses, the distribution gets more confident that the machine is good. Now here's the clever bit. Each round, you don't just pick the machine with the highest average win rate so far.

Speaker 2

No, we then you take a random draw from each machine's beta distribution, and you play the machine whose random draw came out highest for that round.

Speaker 1

Random draw? Why random seems like you'd want the most likely winner.

Speaker 2

That randomness is key. It builds an exploration. A machine you haven't played much will have a wider, less certain distribution, so its random draws might sometimes be high, prompting you to try it out.

Speaker 1

Ah, so it forces you to explore the less known options, sometimes just in case they're actually better than the current favorite.

Speaker 2

Exactly. It naturally balance is exploring new things, exploration with sticking to what seems to work exploitation, and it does this just based on the observed wins and losses, without needing the true payout rates.

Speaker 1

That's really clever. Balancing exploration and exploitation is a classic problem. Does the book give a real world example?

Speaker 2

Yes, a great one. Online advertising, which adversion gets the most clicks or sign ups?

Speaker 1

Okay, so each AD variation is like a slot machine.

Speaker 2

Arm perfect analogy. You show different ads, oh actions, you track clicks or conversions rewards one for click, zero for no click. Thompson sampling figures out which ad performs best over.

Speaker 1

Time by showing ads somewhat randomly based on those beta distributions. Learning as it goes.

Speaker 2

Yep, it converges on the statistically best ad adapting as it gets more data maps directly from the casino problem.

Speaker 1

Pretty neat, very neat, Okay, So Thompson sampling helps pick the best single option. But many problems involve a sequence of actions to reach a.

Speaker 2

Goal, right, and that's where the source introduces Q learning. This is a really foundational reinforcement learning algorithm for sequential decisions.

Speaker 1

Q learning. What's the Q stand for?

Speaker 2

It stands for quality. Essentially, the core idea is the Q value.

Speaker 1

Okay, quality value. What does it represent?

Speaker 2

A Q value written q s is a number. It represents the expected total future reward you'll get if you take action A when you're in state S A and D. This is key you act optimally after that.

Speaker 1

Whoa Okay, So it's not just the immediate reward for taking action A, it's that plus the best possible rewards you could get from then on.

Speaker 2

Exactly. It's the long term value of taking that specific action in that specific state. The goal of Q learning is to learn these Q values for all possible state action pairs.

Speaker 1

So if you know all the Q values, you just pick the action with the highest Q value in your current state, and that's the best move.

Speaker 2

That's the idea for using it once it's learned. Yes, but how does it learn those values? You use something called a temporal difference or TD.

Speaker 1

Temporal difference sounds like difference over time.

Speaker 2

Kind of think of TD as measuring the surprise. It's the difference between the AI's current estimate of qs A and a better estimate it gets after actually taking action A, getting a reward R, and seeing the next state's prime.

Speaker 1

How does it get that better estimate?

Speaker 2

The better estimate is the immediate reward R plus the maximum Q value it could get from that next state's prim basically R plus max QS.

Speaker 1

Okay, so TD is actual reward plus best future value from next state minus my old estimate of current state action value.

Speaker 2

You've got it. A big positive TD means Wow, that action was way better than I thought. A negative TD means Oops, that was worse.

Speaker 1

And this TD error is used to update the original Q value estimate.

Speaker 2

Precisely using the Bellman equation, which is the mathematical rule for this update. It uses the TD error and a learning rate to nudge the Q value closer to that better estimate. It links the immediate reward to the future potential.

Speaker 1

So it learns iteratively. Can you walk through the training process generally? Sure.

Speaker 2

You start by initializing all all Q values, maybe to zero. Then you run many episodes. In each episode, maybe started a random state, pick a random valid action. See what reward you get in what state you land in?

Speaker 1

Okay?

Speaker 2

Then you calculate that TDR based on the reward and the max q value of the next state, and you update the Q value for the state action pair you just experienced, repeat, repeat, repeat.

Speaker 1

Lots of exploration and updating exactly.

Speaker 2

Over time, exploring the environment and propagating these rewards back via the TV updates, the Q values start to converge towards the true optimal values.

Speaker 1

And then once training is done, The inference process is.

Speaker 2

Simple, very simple. Put the AI in any state s it looks up the learned Q values for all possible actions A from that state. It picks the action with the highest Q value. That's its policy.

Speaker 1

Okay, that makes sense. It learns the map of values, then follows the path of highest value. The source gives a warehouse robot example, right.

Speaker 2

Yeah, a really clear one. Guiding a robot through a maze like a warehouse layout to get to a specific goal location, say location G.

Speaker 1

How does that map to states, actions rewards.

Speaker 2

The states are just the robot's current location ABC. The actions are moving to an adjacent connected location, simple enough, and the rewards are designed to get it to G. Maybe a small reward like plus one for any valid move between locations, zero reward if it tries to move through a wall and the goal. A big reward, say plus one thousand for reaching location G. That high value at the goal is the incentive.

Speaker 1

So during training, the robot wanders around, bumping into walls, maybe stumbling into G. Eventually right, and.

Speaker 2

When it gets rewards, especially that big one of G, the TD updates start propagating that value backwards along the paths leading to G.

Speaker 1

So actions that lead towards G gradually get higher Q.

Speaker 2

Values Exactly the Q values effectively learn the goodness of each move in terms of reaching.

Speaker 1

The goal and the sourt's also mentioned. You could add intermediate goals like forcing the robot to go through location K on the way to G.

Speaker 2

Yes, you just tweak the reward matrix give a medium sized reward, maybe five hundred specifically for the action of moving from jda K if that's the desired intermediate step.

Speaker 1

AH make that specific transition valuable.

Speaker 2

Or you could add a big negative reward main to five hundred for a transition you wanted to avoid, like going from jda F. You shape the desired path by manipulating the rewards for specific state action.

Speaker 1

Pairs, very flexible and in inference. The trained robot would then follow the path that accumulated the highest.

Speaker 2

Q values testing the example path mentioned E to I to JDAK than LHG. The robot figures that out just by following the highest Q value at each step, guided by the rewards you designed.

Speaker 1

Okay, Q learning seems powerful for these kinds of discrete state spased problems. But what about more complex stuff like dealing with messy continuous data or images.

Speaker 2

Exactly, that's the limit of basic Q learning tables. For more complex problems. The source brings in artificial neural networks an ns and deep learning. The artificial brains kind of yeah, inspired by biologic brains. The basic unit is the neuron. It gets inputs, multiplies them by weights, sums them.

Speaker 1

Up, and passes the result through an activation function like re lu the rectifier you mentioned right.

Speaker 2

That activation function adds nonlinearity, which is super important for learning complex patterns. These neurons are arranged in layers input, hidden layers, output information flows forward.

Speaker 1

Okay, and how do these networks learn you mentioned adjusting weights.

Speaker 2

They learn by trying to minimize error. For example, predicting house prices, the network makes a prediction you compare to the actual price.

Speaker 1

That difference is the loss error, and it tries to reduce that error.

Speaker 2

Yes, using optimization algorithms like gradient descent, it calculates how adjusting each weight would affect the error and nudges the weights in the direction that reduces the error. Or many many.

Speaker 1

Examples the book uses that house price prediction example. What's a really critical step when you feed data like house size, number of bedrooms, et cetera into an ann.

Speaker 2

Data prep is huge. Splitting into twenty two test sets is standard, But the crucial thing, especially for an n's is scaling the data.

Speaker 1

Scaling Why is that so vital?

Speaker 2

Imagine number of bedrooms maybe one to five versus square footage thousands. Without scaling, the network might overweight square footage just because the numbers are bigger. Even if bedrooms are just as important.

Speaker 1

Ah, the scale of the numbers dominates the learning.

Speaker 2

Exactly scaling methods like midmax scale are mentioned in the source bring all features into a similar range like zero to one. So the network learns based on the predictive power of each feature, not just its raw numerical size.

Speaker 1

Makes sense, leveling the playing field for the input features. Okay, so we have Q learning for sequences ANNs for complex data. What happens when you put them.

Speaker 2

Together, magic happens. That's deep Q learning or DQN. This is where things get really powerful for complex RL problems.

Speaker 1

Deep Q learning. So the deep comes from the deep learning neural network exactly.

Speaker 2

The an N acts as a function approximator for the Q function instead of a giant table storing queues A for every possible state in action, which is impossible for complex environments.

Speaker 1

Right the state space could be enormous or even continuous.

Speaker 2

The ANN takes the states as as input, and its output layer predicts the Q values for all possible actions A from that state.

Speaker 1

So the network learns to estimate the Q values on the fly based on the input state.

Speaker 2

Precisely. It generalizes. Now, when it comes to choosing an action during training, DQN doesn't always just pick the action with the highest predicted Q value. That would be pure exploitation.

Speaker 1

It needs exploration too, write like in Thompson sampling exactly.

Speaker 2

The source mentions common strategies like softmax or epsilon greedy exploration epsilon greedy.

Speaker 1

That's the one where, say ten percent of the time, it just picks a random action instead of the best one.

Speaker 2

Yeah, that's the idea with probability upslone explore randomly, otherwise exploit the best known action. Softmax assigns probabilities based on Q values, giving even weaker actions some chance. This exploration is crucial for discovering potentially better strategies the AI doesn't know about yet.

Speaker 1

Okay, so how does the DQN actually learn? How does the network get better at predicting Q values.

Speaker 2

It's similar to the q learning update, but uses the network The AI is in state a's picks an action A using epslong, greedy you or similar, observes the reward R and the next state's prime.

Speaker 1

Okay.

Speaker 2

It then uses the same neural network to predict the maximum Q value possible from that next state. Hell, it's prime. Let's call that max qs. It calculates the target Q value. Target equals R plus gamma max qsaighty gamma is a discount factor for future rewards, so.

Speaker 1

Reward plus the discounted best value from the next state that's the target right now.

Speaker 2

It compares this target value to the q value the network originally predicted for the action a it actually took in state. As the difference between the prediction and the target is the error, the temporal difference error again.

Speaker 1

And that error signal is used to update.

Speaker 2

The network exactly. The error is backpropagated through the ann adjusting the weights so that next time the network's prediction for q A will be closer to that target value. It learns to make better predictions through experience.

Speaker 1

And there is something about experience replay.

Speaker 2

Memory ah yes, crucial for stability. Instead of learning only from the very last thing that happened, the AI stores lots of past experiences state action reward next to state tipples in a big memory buffer. Okay, Then for learning updates, it samples random mini batches of these past experiences.

Speaker 1

From the buffer way random badges.

Speaker 2

It breaks the correlation between consecutive experiences. Learning step by step can be unstable because consecutive states are often very similar. Random sampling makes the training data more diverse and independent in each batch, which really helps stabilize the learning process for the deep neural network.

Speaker 1

Got it okay, DQN sounds really powerful. The source must have some cool applications. You mentioned virtual self driving.

Speaker 2

Car, Yeah, a great example in the book, they use a Kivi app a Python framework to simulate it. The input states for the AI are are things like the car's angle towards the goal, but also crucially sensor readings, what kind of sensors virtual sensors detecting sand basically obstacles or off road areas to the left, front and right. This gives the AI situational awareness.

Speaker 1

And the actions are simple driving controls.

Speaker 2

Basic steering adjustments.

Speaker 1

Yeah.

Speaker 2

The rewards are set up to encourage driving well, a penalty magnetive one for hitting sand borders, a smaller penalty need you a point two if it moves away from the goal, and a small reward plus point one from moving towards the goal.

Speaker 1

So the DQN learns to process those sensor inputs, predict Q values for steering actions, and chooses actions that avoid penalties and get rewards.

Speaker 2

Exactly, it learns through trial and error in the simulation to stay on the road, avoid sand and navigate towards the target, eventually making round trips. You use something like py torch or TensorFlow to build the an N park very cool.

Speaker 1

And the server cooling example that sounded really practical.

Speaker 2

Extremely practical, applying Dkewin to minimize energy costs into server environment.

Speaker 1

So the input states there are things affecting temperature right.

Speaker 2

Server's current temperature, maybe number of active users, data transmission rate, factors influencing heat load, and the actions discrete choices. The source example use things like cool by one point five degrees cools by point five degree C, do nothing, heat by one point five degree c, heat by one point five degree C. Five distinct actions.

Speaker 1

And the reward is the energy saved compared to a standard maybe thermostat based system exactly.

Speaker 2

The goal is purely energy efficiency. The DQAN trains by simulating temperature changes based on inputs and its actions, learning which sequence of cooling heating actions keeps the temperature within an acceptable range while using the least energy possible.

Speaker 1

And it uses a standard A and unset up.

Speaker 2

Yeah, the source mentions a typical structure maybe two hidden layers means squared error mc loss to measure how far off its temperature prediction? Is the atom optimizer to adjust weights and epsilon greedy exploration during training.

Speaker 1

And the result was significant, quite significant.

Speaker 2

Yeah, the source sited achieving up to eighty seven percent energy savings compared to the baseline. That's a huge real world win from applying URL.

Speaker 1

Wow. Okay, so DQN handles complex states, but what about visual states like images or game screens.

Speaker 2

Ah, Now we get to deep convolutional q learning DCQN. This brings in convolutional neural networks CNNs.

Speaker 1

CNNs. They're specialized for images, right exactly.

Speaker 2

They're designed to process grid like data and images are the prime example.

Speaker 1

How do they work sort of intuitively?

Speaker 2

Well, the first key step is convolution. You slide small filters across the image. Each filter is designed to detect a specific simple feature like a vertical edge, horizontal edge, a corner, maybe a certain texture or color patch. This produces feature maps.

Speaker 1

Okay, finding basic patterns, then.

Speaker 2

Codes pooling, often max pooling. It takes small regions of the feature map and just keep the maximum value. It's a way to downsample reduce the data size will keeping the most salient features detected. It makes the network more robust to small shifts or distortions.

Speaker 1

So extract features, then condense them right after several layers of convolution and pooling, you've extracted increasingly complex features.

Speaker 2

Then you flatten the final two D feature maps into a single long one.

Speaker 1

D vector okay, a feature vector, and.

Speaker 2

That vector is then fed into a standard fully connected ann like we discussed before for the final prediction or decision making in this case predicting Q values.

Speaker 1

And you mentioned CNNs can handle three D inputs. That's important for.

Speaker 2

For the next example. Yeah, playing the classic Snake game using dcqn.

Speaker 1

Ah Snake perfect visual task exactly.

Speaker 2

The state isn't just a single snapshot of the game screen. To understand movement, the AI needs context, So the state input is actually a stack of recent game frames.

Speaker 1

Like layering the last few frames together precisely.

Speaker 2

Think of it like a three D volume with height and a short time dimension. This allows the CNN to perceive motion and direction, not just static positions.

Speaker 1

That's clever, Okay. What are the actions for snake?

Speaker 2

Simple up, down, left, right for possible moves?

Speaker 1

What about impossible moves like if the snake is going right, it can immediately go left.

Speaker 2

Good? Point the AI might try to command left, the game engine ignores it. The snake continues right and promptly dies. The key is the AI takes the action left, observes the outcome death, gets a negative reward, and associates that negative reward with the attempted action left. In that specific state moving right next to self, it learns trying to go left here is bad.

Speaker 1

Ah okay, It learns the consequence of the attempted action, even if the game rules prevent it. What about the rewards.

Speaker 2

Simple and effective plus one for eating an apple, negative one for dying, hitting wall or self, and crucially, a small negative reward like negative point zero three for every single step that doesn't end the game.

Speaker 1

Or get an apple a living penalty. Why penalize it just for moving.

Speaker 2

To encourage efficiency. Without it, the snake could just wiggle around an empty space forever. Not dying is okay. Not getting apples as okay. That small penalty incentivizes it to find apples quickly, because eating an apple plus one is the main way to counteract the accumulating negative living penalty.

Speaker 1

Makes sense, drives it towards the objective efficiently. So the DCQN takes the stack frames, processes them through CNN layers to understand the visual state where's the snake, apple Wall's.

Speaker 2

Body, flattens those features, feeds them to an ANN, which outputs the Q values for up, down, left, right, and.

Speaker 1

It learns by taking actions with exploration, getting rewards, penalties, and updating the whole network CNN plus ANN via backpropagation using the TD.

Speaker 2

Error You've got it and the result mentioned the source. After training, the AI could consistently eat around ten to eleven apples per game, which is pretty decent for learning from scratch.

Speaker 1

That's really cool, So quite a journey there from the absolute basics of.

Speaker 2

RL state's actions reward Drew.

Speaker 1

Thompson sampling for simple choices, Q learning for basic sequences.

Speaker 2

Then bringing in the power of neural networks with DQN for complex.

Speaker 1

States handling things like driving and server cooling, and.

Speaker 2

Finally DCQN use and convolutional networks to actually see and play a game.

Speaker 1

Like Snake Yeah, across casinos, warehouses, cars, server rooms, video games. It's amazing how that core loop of interaction and reward applies.

Speaker 2

And the source really hammers home that idea of intuition first practice, continuous learning. It even mentions resources like opening EYEGM for getting hands on.

Speaker 1

Right because understanding is one thing, but actually building these things.

Speaker 2

That takes practice. And thinking back to that big picture of the book painted at the start, all those potential application areas.

Speaker 1

Yeah, it kind of brings it full circle. We've seen the build in blocks. Now you can think about where they might fit exactly.

Speaker 2

We pulled out the core ideas from these excerpts.

Speaker 1

So what's the big takeaway here for you listening?

Speaker 2

Well, I think it's that these complex AI systems, they often boil down to these understandable core principles, defining the problem clearly states actions rewards is maybe half.

Speaker 1

The battle, yeah, and then using these learning algorithms, often involving neural networks now to figure out the optimal strategy through interaction and feedback, whether it's beta distributions for ADS or CNNs for snake.

Speaker 2

The potential is just huge and it's evolving so fast.

Speaker 1

So as you think about what we've talked through, the MULTIIRN bandit, the warehouse robot, the self driving car simulation, the energy saving server, the gameplaying AI, maybe ask yourself, this, is there a problem or a task in your world, maybe work, maybe a hobby that you could perhaps frame in terms of states, actions and rewards.

Speaker 2

How would an AI learning just through trial and error and feedback approach solving it. It's a powerful way to think about automation and optimization.

Speaker 1

That idea of learning by doing, driven by feedback, it really is powerful.

Speaker 2

Definitely something them all over.

Speaker 1

Thanks for diving deep with us today.

Speaker 2

Yeah, great discussion.

Speaker 1

We'll see you on the next one.

Transcript source: Provided by creator in RSS feed: download file
For the best experience, listen in Metacast app for iOS or Android