Latest / CyberSecurity Summary / AI and Machine Learning for Coders: A Programmer's Guide to Artificial Intelligence
Transcript
- 0:00Speaker 1: The world of AI and machine learning is just exploding,
- 0:03Speaker 1: isn't it. And if you're a coder looking in, you
- 0:04Speaker 1: might be thinking, Okay, how do I actually get started
- 0:06Speaker 1: here without needing a PhD.
- 0:09Speaker 2: That's a really common question and honestly, the tools available
- 0:12Speaker 2: now have made it much more accessible for developers to jump.
- 0:16Speaker 1: In absolutely, and that's really our mission for this deep dive.
- 0:19Speaker 1: We're digging into key parts of Lawrence Moroney's book AI
- 0:23Speaker 1: and Machine Learning for coders. We want to pull out
- 0:26Speaker 1: the most important bits for you.
- 0:28Speaker 2: Think of it as a practical starting point. We're aiming
- 0:30Speaker 2: to give you the essentials on deep learning, computer vision,
- 0:33Speaker 2: and LP, basically focusing on how you can use TensorFlow
- 0:38Speaker 2: to tackle these things.
- 0:39Speaker 1: Yeah, the perspective here is crucial. It's tailored for you,
- 0:42Speaker 1: the coder. It's about the tools you can grab now
- 0:44Speaker 1: and the problems you can start solving.
- 0:47Speaker 2: Right, just like the book intents equipping you to become
- 0:50Speaker 2: an mL developer by focusing on actually doing it, not
- 0:53Speaker 2: getting bogged down in just the theory or the super
- 0:56Speaker 2: complex math.
- 0:57Speaker 1: And people have really responded to that approachmon called it
- 1:00Speaker 1: the much needed practical starting point. Soufu mentioned how it
- 1:04Speaker 1: teaches the key building blocks so you can code AI
- 1:07Speaker 1: for PCs mobile the browser.
- 1:10Speaker 2: Yeah, Laurence Maroney's vision was clearly about empowering developers, and,
- 1:15Speaker 2: like Andrew En says in the foreword, great Adventures await you,
- 1:17Speaker 2: it's an exciting space.
- 1:19Speaker 1: Okay, So let's unpack this. Where does machine learning really
- 1:22Speaker 1: differ from say, traditional programming and what's the main platform.
- 1:26Speaker 3: We'll be talking about.
- 1:28Speaker 2: Well, the fundamental difference is a kind of flip in thinking.
- 1:31Speaker 2: In traditional programming, you write explicit rules, rules, act on data,
- 1:35Speaker 2: and you get answers.
- 1:36Speaker 1: Like coding a game like Breakout, specifically, write the logic
- 1:40Speaker 1: how the ball moves, what happens when it hits a brick, scoring, paddle, misses.
- 1:45Speaker 1: It's all defined rules exactly.
- 1:47Speaker 2: Or think about activity detection from a wearable. You might
- 1:50Speaker 2: write rules like okay, if speed is over x, it's running.
- 1:53Speaker 2: If it's between y and X, it's walking. You define
- 1:56Speaker 2: the logic based on the data.
- 1:57Speaker 1: But that approach hits the ceiling pretty quickly, right. What
- 2:01Speaker 1: if you wanted to detect something way more complex, like
- 2:03Speaker 1: golfing precisely?
- 2:05Speaker 2: How do you write rules for that? The mix of
- 2:08Speaker 2: swinging pausing walking, It gets incredibly hard, maybe even impossible,
- 2:14Speaker 2: to define robust rules that cover every single variation by hand.
- 2:18Speaker 1: So the old rules act on data to give answers.
- 2:21Speaker 1: Method breaks down and the rules are just too fuzzy
- 2:24Speaker 1: or complex to write yourself. And that's where mL comes in.
- 2:28Speaker 2: Right. With machine learning, you kind of flip it. You
- 2:30Speaker 2: provide the data and you provide the answers. We call
- 2:32Speaker 2: those labels. Then the machine learning algorithm figures out the
- 2:36Speaker 2: rules or patterns connecting the data to those answers.
- 2:39Speaker 3: Ah okay.
- 2:39Speaker 1: So for the activity example, you'd give it sensor data
- 2:42Speaker 1: from someone walking, running, biking, and golfing, and you'd label
- 2:45Speaker 1: those chunks of data this part is walking, this part
- 2:48Speaker 1: is golfing.
- 2:48Speaker 2: Yep. And the mL algorithm looks at all that labeled
- 2:51Speaker 2: sensor data maybe acceleration, rotation time, whatever, and it learns
- 2:55Speaker 2: the underlying patterns that distinguish golfing from the others. It
- 2:58Speaker 2: derives the complex rules you couldn't realistically right, that's the
- 3:01Speaker 2: core shift. It's pretty powerful, and.
- 3:03Speaker 1: The platform that's really designed to put this power into
- 3:06Speaker 1: coder's hands is TensorFlow.
- 3:08Speaker 2: TensorFlow, Yeah, it's this huge open source platform for building
- 3:11Speaker 2: and using mL models. Its real value, I think is
- 3:14Speaker 2: that it handles a lot of the underlying complexity. It
- 3:17Speaker 2: implements common algorithms, common patterns, so you.
- 3:20Speaker 1: The coder can focus more on the actual problem you're
- 3:23Speaker 1: trying to solve with mL, unless on say, implementing backpropagation from.
- 3:27Speaker 2: Scratch, exactly focus on the scenario. And TensorFlow is built
- 3:31Speaker 2: to be flexible. You can deploy the models you create
- 3:33Speaker 2: almost anywhere web cloud, mobile apps, on Android or iOS,
- 3:37Speaker 2: even tiny embedded systems.
- 3:39Speaker 1: And how do you typically work with it? Python, install idse.
- 3:42Speaker 2: All of the above. Really, you can pip install it
- 3:44Speaker 2: in Python, use it in IDEs like pischarm, or a
- 3:49Speaker 2: really popular way is using cloud environments like Google Collab
- 3:53Speaker 2: that gives you access to GPUs and TPUs without needing
- 3:56Speaker 2: the hardware yourself.
- 3:57Speaker 1: Okay, let's drill down. What does the simplest possible example
- 4:00Speaker 1: of this learning look like? Like the basic building.
- 4:03Speaker 2: Block, right, So imagine teaching a network a really simple
- 4:07Speaker 2: linear relationship like why equals two x one? You'd give
- 4:11Speaker 2: examples if x is one, why is one of x's two,
- 4:14Speaker 2: Why is three x's three, y is five? And so
- 4:16Speaker 2: on Okay, a tiny neural network, even one with just
- 4:19Speaker 2: a single neuron, can learn this. It does it by
- 4:22Speaker 2: adjusting two internal values, a weight it multiplies the input
- 4:27Speaker 2: x by, and a bias it adds.
- 4:29Speaker 1: So it's basically learning the two in the menx one
- 4:32Speaker 1: from our equation. Yeah, those learned numbers, the weight and bias,
- 4:35Speaker 1: those are the parameters.
- 4:35Speaker 2: Of the network exactly, And that's a really important distinction
- 4:38Speaker 2: for coders getting into mL. Parameters, weights and biases are
- 4:42Speaker 2: what the network learns from the data. They're different from hyper.
- 4:45Speaker 1: Parameters, right. Hyperarameters are the knobs you turn before training starts.
- 4:48Speaker 1: Aren't they things that control the learning process itself.
- 4:51Speaker 2: Yeah, things like the learning rate, how quickly it adjusts weights,
- 4:55Speaker 2: or the number of neurons you decide to put in
- 4:56Speaker 2: a layer, or how many epochs meaning how many times
- 4:59Speaker 2: it sees a whole data set. You experiment with these
- 5:02Speaker 2: to get better results. And neurons also usually have something
- 5:06Speaker 2: called an activation function. It's like a little function that
- 5:08Speaker 2: processes the neurons output. A common one is relute rectified
- 5:13Speaker 2: linear unit. It basically just passes the value through if
- 5:15Speaker 2: it's positive and outputs zero otherwise. This adds nonlinearity, which
- 5:20Speaker 2: is crucial for learning anything beyond simple lines.
- 5:22Speaker 1: Okay, makes sense. We've got the basic shift to learning
- 5:25Speaker 1: the platform, the simplest building block. Let's apply this to
- 5:28Speaker 1: a huge area. Yeah, computer vision making machines.
- 5:31Speaker 2: See so at its core and image is just a
- 5:35Speaker 2: grid of numbers, right pixels. A small gray scale image
- 5:38Speaker 2: like from the Fashion MNIS data set might be twenty
- 5:41Speaker 2: eight by twenty eight pixels. Each pixel has a value,
- 5:44Speaker 2: say zero to two fifty five for how bright it.
- 5:46Speaker 1: Is, and color images just have more numbers per pixel,
- 5:48Speaker 1: usually three for red, green, and blue.
- 5:50Speaker 2: Three channels.
- 5:51Speaker 3: Yeah.
- 5:51Speaker 2: Now if you try to feed those raw pixel values
- 5:54Speaker 2: directly into that simple single neural network we just talked about,
- 5:57Speaker 2: or even a basic multi layer network, well it would
- 5:59Speaker 2: really struggle because a simple network doesn't understand spatial structure.
- 6:04Speaker 2: It just sees a flat list of numbers. It might
- 6:06Speaker 2: learn to recognize, say a sneaker, if it's exactly like
- 6:10Speaker 2: the ones in the training data, same position, same angle.
- 6:13Speaker 1: Ah, but if you show it the sneaker slightly rotated,
- 6:16Speaker 1: or maybe a different type of sneaker, like a high heel, it.
- 6:19Speaker 2: Might completely fail. It hasn't learned the features that make
- 6:23Speaker 2: something a sneaker. It just memorized specific pixel patterns in
- 6:26Speaker 2: specific locations.
- 6:27Speaker 3: Okay, so that's the problem.
- 6:28Speaker 1: Convolutional neural networks or CNNs are designed.
- 6:31Speaker 2: To solve exactly. CNNs are built to automatically find and
- 6:35Speaker 2: learn hierarchical features in images, things like edges, textures, shapes, objects,
- 6:40Speaker 2: regardless of where they appear in the image.
- 6:43Speaker 3: How do they do that? What are the core ideas?
- 6:44Speaker 2: Two main operations, convolutions and pooling. Convolutions use small filters,
- 6:49Speaker 2: like maybe a three by three grade of weights that
- 6:52Speaker 2: slide across the image. Each filter is trained to detect
- 6:55Speaker 2: a specific local pattern, maybe a vertical edge or a
- 6:58Speaker 2: certain curve or text.
- 7:00Speaker 1: So the filter scans the image and produces a sort
- 7:03Speaker 1: of map showing where it found that.
- 7:04Speaker 2: Pattern precisely, and applying a filter reduces the image dimensions slightly.
- 7:10Speaker 2: A three x three filter on a twenty eight x
- 7:12Speaker 2: twenty eight image gives you a twenty six x twenty
- 7:15Speaker 2: six output map.
- 7:16Speaker 3: Okay, and pooling.
- 7:17Speaker 2: Pooling layers then reduce the size of these feature maps,
- 7:20Speaker 2: making the representation smaller and more manageable while keeping the
- 7:23Speaker 2: most important information. A common type is max pooling. You
- 7:27Speaker 2: might take a two x two area and just keep
- 7:29Speaker 2: the maximum value, throwing away the other three. This halves
- 7:32Speaker 2: the dimensions but keeps the strongest signal for that feature
- 7:35Speaker 2: in that region.
- 7:36Speaker 1: And by stacking these convolutions and pooling layers.
- 7:39Speaker 2: The network builds up understanding. Early layers find simple edges,
- 7:43Speaker 2: Middle layers combined edges into corners and textures. Deeper layers
- 7:46Speaker 2: combine those into parts of objects, and then whole objects.
- 7:49Speaker 2: The key thing for you as a coder is that
- 7:51Speaker 2: the CNN automates this feature extraction. You don't have to
- 7:54Speaker 2: hand code edge detectors anymore.
- 7:56Speaker 3: Right, Let's make it concrete.
- 7:58Speaker 1: The book uses a horse or human classifier.
- 8:00Speaker 3: Example.
- 8:00Speaker 2: Yeah, that data set uses bigger color images, maybe three
- 8:03Speaker 2: hundred by three hundred pixels with three color channels. So
- 8:06Speaker 2: the input shape is three hundred by three hundred by three.
- 8:08Speaker 1: And since it's just two classes horse or human, it's
- 8:12Speaker 1: binary classification. You can use just one neuron in the
- 8:15Speaker 1: final output layer.
- 8:16Speaker 2: You can, and you typically attach a Sigmoid activation function
- 8:19Speaker 2: to it. Sigmoid squashes any input value into a range
- 8:23Speaker 2: between zero and one, perfect for probability. You can interpret
- 8:26Speaker 2: the output as say, the probability that the image is
- 8:29Speaker 2: a human.
- 8:30Speaker 1: The source mentioned a specific failure case, though, where a
- 8:34Speaker 1: model trained on this data set saw a picture of
- 8:36Speaker 1: just like the top half of a person and classified
- 8:39Speaker 1: it as a horse. Why would that happen? It seems
- 8:42Speaker 1: like a common beginner frustration.
- 8:44Speaker 2: It often boils down to the training data and overfitting.
- 8:47Speaker 2: If your training set mostly contains full body pictures of
- 8:50Speaker 2: humans standing up and maybe horses in profile, the model
- 8:53Speaker 2: learns those specific views. When it sees something unusual, like
- 8:57Speaker 2: only the upper body of a person perhaps and oppose
- 8:59Speaker 2: it hasn't seen, it might lapt onto some features, maybe texture,
- 9:02Speaker 2: maybe background that it learned we're associated with horses in
- 9:05Speaker 2: the training data. It hasn't generalized the concept of human
- 9:08Speaker 2: well enough outside the examples it saw.
- 9:10Speaker 1: Okay, so this overfitting. Doing great on training data but
- 9:14Speaker 1: failing on new stuff. How do you fight that, especially
- 9:18Speaker 1: if you don't have tons of data?
- 9:19Speaker 2: Several really good techniques. One is image augmentation. It's clever.
- 9:23Speaker 2: During training, you don't just feed the network your original images.
- 9:26Speaker 2: You apply random transformations on the fly, maybe rotate the
- 9:30Speaker 2: image slightly, zoom in or out a bit shift. It
- 9:33Speaker 2: horizontally or vertically flip it.
- 9:35Speaker 1: Ah, so you're essentially creating slightly modified versions of your
- 9:38Speaker 1: existing images, making the data set seem bigger and more varied.
- 9:42Speaker 2: Exactly, the model learns that a horse is still a
- 9:44Speaker 2: horse even if it's tilted or slightly zoomed, it becomes
- 9:48Speaker 2: more robust. Tensorflow's image data generator makes this super easy
- 9:52Speaker 2: to set up.
- 9:52Speaker 3: What else?
- 9:53Speaker 2: Another huge one is transfer learning. This is incredibly powerful.
- 9:57Speaker 2: You might only have a few thousand horse and human images,
- 10:00Speaker 2: but other people have trained enormous models, like mobile net
- 10:03Speaker 2: or inception on millions of images covering say one thousand
- 10:08Speaker 2: different categories on the ImageNet data set. Those massive models
- 10:11Speaker 2: have already learned really really good general purpose feature extractors
- 10:15Speaker 2: in their early convolutional layers. They know how to detect edges, textures, shapes,
- 10:21Speaker 2: basic object parts, things useful for recognizing any image.
- 10:26Speaker 1: So with transfer learning, you take those pre trained layers.
- 10:29Speaker 2: Yep, you basically chop off the original final layers that
- 10:32Speaker 2: were specific to the one thousand image Neet classes. You
- 10:36Speaker 2: freeze the weights of the early layers so they don't change,
- 10:39Speaker 2: and you add your own new classification layers on top,
- 10:41Speaker 2: maybe just a couple of layers ending in that single
- 10:44Speaker 2: sigmoid neuron for your horse human tasks.
- 10:47Speaker 1: And you only train your new small layers using your
- 10:49Speaker 1: smaller data set.
- 10:50Speaker 2: Mostly yes, or sometimes you fine tune by unfreezing the
- 10:54Speaker 2: last few pre trained layers and training them a tiny
- 10:56Speaker 2: bit too. But the point is you're leveraging all the
- 10:59Speaker 2: knowledge learn from the giant data set for your specific problem.
- 11:03Speaker 2: It's a massive shortcut. TensorFlow Hub is a great place
- 11:06Speaker 2: to find these pre trained models.
- 11:08Speaker 3: That makes a lot of sense any other tricks for overfitting.
- 11:10Speaker 2: Dropout regularization is another common one. During training, For each
- 11:14Speaker 2: batch of data, you randomly drop out, meaning temporarily ignore
- 11:18Speaker 2: a certain percentage of the neurons in a layer.
- 11:20Speaker 3: Wait, you just turn them off?
- 11:21Speaker 2: Why It sounds weird, but it forces the network to
- 11:25Speaker 2: learn more robust and redundant representations. It prevents any single
- 11:29Speaker 2: neuron from becoming overly specialized or critical for making predictions
- 11:33Speaker 2: based on the training data. It encourages the network to
- 11:36Speaker 2: distribute the learning. You often see the training accuracy and
- 11:39Speaker 2: the validation accuracy performance on data held back from training
- 11:43Speaker 2: stay much closer together when you use dropout.
- 11:46Speaker 1: Okay, got it. So that's a good overview for images.
- 11:48Speaker 1: What about the other big area text, natural language processing?
- 11:52Speaker 1: How to machine start to understand language?
- 11:54Speaker 2: Well? Like images, text needs to be converted into numbers first.
- 11:58Speaker 2: The initial step is usually tokenization.
- 12:01Speaker 1: Breaking sentences down into words or maybe even parts of words,
- 12:04Speaker 1: and giving each unique piece a number ID like these
- 12:07Speaker 1: is one, cat is two, sat.
- 12:09Speaker 2: As three exactly. You build a vocabulary, a mapping from
- 12:13Speaker 2: words to integer tokens. Good tokenizers handle things like punctuation.
- 12:18Speaker 2: Maybe today just becomes the token for today, and crucially,
- 12:22Speaker 2: you need a plan for words that weren't in your
- 12:25Speaker 2: training vocabulary and out of vocabulary or OOV token.
- 12:28Speaker 1: Once you have tokens, you turn sentences into sequences of
- 12:32Speaker 1: these numbers. The cat sat might become the sequence one
- 12:35Speaker 1: two three, right.
- 12:36Speaker 2: And because neural networks usually need fixed size inputs, you
- 12:39Speaker 2: have to make all your sequences the same length. You
- 12:42Speaker 2: either pad shorter sequences, usually with zeros, or you trunk
- 12:45Speaker 2: paate longer ones.
- 12:46Speaker 3: How do you pick the length?
- 12:48Speaker 2: You typically look at the distribution of sentence links in
- 12:50Speaker 2: your data. Maybe ninety five percent of your sentences are
- 12:53Speaker 2: shorter than say eighty five words, so you might pick
- 12:56Speaker 2: eighty five as your max length to minimize padding while
- 12:58Speaker 2: capturing most sentences fully.
- 13:00Speaker 1: And sometimes you clean the text first, remove HTML maybe
- 13:03Speaker 1: common words.
- 13:04Speaker 2: Yeah, preprocessing is often important, removing HTML tags, maybe converting
- 13:09Speaker 2: to lowercase. Sometimes you remove stop words. Common words like
- 13:13Speaker 2: is is it is? The that might not carry a
- 13:16Speaker 2: much specific meaning for your task. So is it sunny
- 13:19Speaker 2: today might become tokens for just sonny today.
- 13:23Speaker 1: Okay, so we have sequences of numbers, Yeah, but just
- 13:26Speaker 1: assigning arbitrary IDs like one, two, three doesn't tell the
- 13:29Speaker 1: model anything about meaning. Right, Cat two isn't inherently related
- 13:33Speaker 1: to dog maybe fifty exactly.
- 13:35Speaker 2: That's where embttings come in. This is a really key
- 13:37Speaker 2: concept in NLP.
- 13:38Speaker 3: Right.
- 13:39Speaker 2: Embeddings represent words not just as single numbers, but as
- 13:42Speaker 2: vectors lists of numbers in a multi dimensional space. Think
- 13:46Speaker 2: of it like giving each word coordinates on a complex map, and.
- 13:49Speaker 1: The idea is that words with similar meanings end up
- 13:51Speaker 1: closer together.
- 13:52Speaker 3: On this map.
- 13:52Speaker 2: Precisely, king and queen might have similar vectors. Walking and
- 13:56Speaker 2: running might be close. The relationships between words are captured
- 13:59Speaker 2: by their relative positions in this embedding space.
- 14:02Speaker 1: The book uses a cool example with pride and prejudice
- 14:04Speaker 1: characters right, plotting them based on learned dimensions like gender
- 14:07Speaker 1: or nobility.
- 14:08Speaker 2: Yeah, that's a great way to visualize it. Mister Darcy
- 14:11Speaker 2: and Elizabeth Bennett might be positioned based on these learned
- 14:14Speaker 2: semantic features. The key is that the network learns these
- 14:18Speaker 2: vector representations. The dimensions aren't predefined. They emerge from how
- 14:23Speaker 2: words are used together in the training text.
- 14:26Speaker 1: So the network figures out that king is used in
- 14:29Speaker 1: similar contexts to queen, but maybe also related to man,
- 14:34Speaker 1: while queen is related to woman.
- 14:35Speaker 2: Right, and you can even optimize the number of dimensions
- 14:38Speaker 2: in your embedding vectors. A rule of thumb is maybe
- 14:41Speaker 2: the fourth root of your vocabulary size. So for a
- 14:44Speaker 2: few thousand words, maybe seven or eight dimensions is enough
- 14:47Speaker 2: instead of say sixteen or three two. It trains faster
- 14:50Speaker 2: without losing too much meaning.
- 14:52Speaker 1: But if you'd just average the embedding vectors for all
- 14:55Speaker 1: words in a sentence, you lose word order, don't you.
- 14:57Speaker 1: It becomes a bag of words.
- 14:58Speaker 2: That's a major limitation of simple embedding approaches. Word order
- 15:02Speaker 2: is critical in language. Dog bites man versus man bites
- 15:05Speaker 2: dog totally different meanings, same bag of words, So.
- 15:07Speaker 1: To handle sequence in context, we need something more sophisticated,
- 15:10Speaker 1: like we're current nural networks RNNs exactly.
- 15:13Speaker 2: RNNs are designed from the ground up for sequential data.
- 15:16Speaker 2: They have a kind of internal memory or state that
- 15:18Speaker 2: gets updated as they process each word or token in
- 15:21Speaker 2: a sequence. This state carries context from previous words forward.
- 15:26Speaker 1: But you mentioned simple RNNs can struggle with long sentences.
- 15:30Speaker 1: They might forget important context from the beginning.
- 15:33Speaker 2: Yeah, that's the venish ingradient problem. Essentially, the influence of
- 15:37Speaker 2: early words can fade out over long sequences. If you
- 15:39Speaker 2: have a sentence like I grew up in France, so
- 15:42Speaker 2: I speak fluent, the word France early on is key
- 15:45Speaker 2: to predicting French at the end. A simple RNN might
- 15:49Speaker 2: lose that connection.
- 15:50Speaker 1: Okay, and that's why lstm's long short term memory networks
- 15:53Speaker 1: were developed, right.
- 15:54Speaker 2: LSTMs are a special type of RNM. They have internal
- 15:57Speaker 2: mechanisms called gates that expl ilicitly control what information to remember,
- 16:02Speaker 2: what to forget, and what to output. This makes them
- 16:05Speaker 2: much much better at capturing long range dependencies and sequences.
- 16:09Speaker 1: And then there are bidirectional LSTMs. How do they improve things?
- 16:12Speaker 2: So a standard LSTM reads the sequence from start to end.
- 16:17Speaker 2: A bidirectional LSTM has two LSTMs. One reads forwards, the
- 16:21Speaker 2: other reads backwards. Then it combines their outputs at each step.
- 16:25Speaker 1: Ah, so it gets context from both.
- 16:27Speaker 2: Directions exactly for understanding language, this is often really powerful.
- 16:32Speaker 2: Think about sentiment analysis. Sometimes the keyword determining the sentiment
- 16:36Speaker 2: comes late in the sentence, or for predicting a missing word,
- 16:40Speaker 2: knowing the words that come after it is just as
- 16:43Speaker 2: important as knowing the words before it.
- 16:45Speaker 1: Like that I lived in country right Gaelic example. Seeing
- 16:48Speaker 1: Gaelic later helps figure out.
- 16:49Speaker 2: The country precisely. The backward pass provides that future context,
- 16:53Speaker 2: and you can feed pre trained embeddings like love vectors
- 16:56Speaker 2: into these LSTMs to give them a head start on
- 16:59Speaker 2: word meaning.
- 17:00Speaker 1: Okay, so we can use these models to understand text.
- 17:02Speaker 1: What about generating text? How does that work?
- 17:05Speaker 2: The core idea is pretty straightforward. Actually, you train a
- 17:08Speaker 2: model to predict the next word in a sequence given
- 17:11Speaker 2: the preceding words.
- 17:12Speaker 1: So if your training data has the sentence the quick
- 17:14Speaker 1: brown Fox, you'd create training examples like input the label
- 17:19Speaker 1: quick input, the quick label brown input, the quick brown
- 17:22Speaker 1: label Fox exactly.
- 17:24Speaker 2: You slide a window across your text corpus, creating these
- 17:27Speaker 2: input sequences and their corresponding next word labels. The labels
- 17:31Speaker 2: are usually one hot encoded a vector of zeros with
- 17:34Speaker 2: a single one at the index, corresponding to the correct
- 17:37Speaker 2: next word in your vocabulary, and the.
- 17:39Speaker 1: Model architecture would be similar embedding layer than maybe an
- 17:42Speaker 1: LSTM or bidirectional LSTM.
- 17:44Speaker 2: Yep, very common. Then to generate text, you start with
- 17:48Speaker 2: a seed text, maybe a word or a phrase. You
- 17:51Speaker 2: feed that seed sequence into your trained model. It outputs
- 17:55Speaker 2: a probability distribution over all the words in your vocabulary
- 17:58Speaker 2: for what the next word is most likely to be.
- 18:00Speaker 1: You pick a word based on those probabilities, maybe the
- 18:03Speaker 1: most likely one.
- 18:04Speaker 2: Usually yeah, or sometimes you sample from the distribution to
- 18:06Speaker 2: get more variety. Then you append that predicted word to
- 18:10Speaker 2: your seed text. Now you have a slightly longer sequence, and.
- 18:13Speaker 1: You feed that new sequence back into the model to
- 18:15Speaker 1: predict the next word and repeat.
- 18:17Speaker 2: That's the loop, keep feeding the growing sequence back in
- 18:20Speaker 2: predicting the next word, appending it.
- 18:22Speaker 1: The book had an example using song lyrics right starting
- 18:25Speaker 1: with in the town of a Lottie yeah.
- 18:28Speaker 2: And the model correctly predicted one which was the actual
- 18:31Speaker 2: next word in the song it was trained on, and
- 18:33Speaker 2: using different seeds like sweet, Jeremy sad Dublin produced other
- 18:37Speaker 2: plausible next words based on the patterns learned from the lyrics.
- 18:41Speaker 1: Though it's fair to say these simple generation models can
- 18:44Speaker 1: often start repeating themselves or outputting stuff that doesn't make
- 18:47Speaker 1: much sense after a while.
- 18:48Speaker 2: No, definitely, they can descend into gibberish quite quickly. Getting
- 18:52Speaker 2: coherent long form text generation is much harder. It often
- 18:56Speaker 2: involves more complex architectures, maybe stacking multiple LSTM, careful tuning
- 19:01Speaker 2: of hyper parameters, and more sophisticated sampling strategies. The generated
- 19:05Speaker 2: Shakespearean text in the book is an example of getting
- 19:08Speaker 2: something more structured, even if parts are nonsensical, Right.
- 19:11Speaker 1: Okay, images text? What about data where the sequence is
- 19:15Speaker 1: time itself, time series data like weather or stock prices.
- 19:20Speaker 2: Yeah, time series data is everywhere, weather forecasts, stock market trends,
- 19:24Speaker 2: sensor readings over time, even something like Moore's law tracking
- 19:28Speaker 2: transistor density. It's all data points ordered chronologically, and this.
- 19:33Speaker 1: Kind of data often has specific characteristics you need to understand.
- 19:36Speaker 2: Absolutely. There's often an overall trend is the value generally
- 19:42Speaker 2: increasing or decreasing over time. There's seasonality patterns that repeat
- 19:46Speaker 2: at regular intervals, think daily temperature cycles, weekly website traffic spikes,
- 19:52Speaker 2: yearly retail sales patterns. Okay, there's autocorrelation, meaning the value
- 19:56Speaker 2: at one point in time is correlated with values at
- 19:59Speaker 2: previous points, like if it's hot today, it's probably going
- 20:01Speaker 2: to be warmish tomorrow, or maybe a predictable decay after
- 20:05Speaker 2: some event, and.
- 20:05Speaker 1: Then there's always just random noise, right, fluctuations You can't
- 20:08Speaker 1: really predict exactly.
- 20:10Speaker 2: Understanding these components helps in modeling.
- 20:13Speaker 1: So how do you prep time series data for an
- 20:15Speaker 1: mL model? It's not exactly sentences.
- 20:18Speaker 2: The standard technique is windowing. You essentially turn the time
- 20:21Speaker 2: series prediction problem into a supervised learning problem.
- 20:24Speaker 3: How does that work?
- 20:25Speaker 2: You create fixed size input sequences or windows of past
- 20:30Speaker 2: data points. For example, a window might be the last
- 20:33Speaker 2: thirty days of temperature readings, and the corresponding label for
- 20:37Speaker 2: that window is typically the value you want to predict,
- 20:40Speaker 2: maybe the temperature reading for the next day, day thirty one.
- 20:43Speaker 1: Okay, So you slide this window across your entire time
- 20:46Speaker 1: series history, creating lots of input window next value pairs precisely.
- 20:51Speaker 2: That becomes your training data.
- 20:52Speaker 1: Set, and before you build a fancy mL model, you'd
- 20:55Speaker 1: probably want some simple baselines to compare against.
- 20:58Speaker 2: Definitely, you need to know if your MLMA model is
- 21:00Speaker 2: actually adding value. The simplest baseline is the nive forecast.
- 21:04Speaker 2: Just predict that the next value will be the same
- 21:06Speaker 2: as the last observed value, so predict tomorrow's temperature will
- 21:09Speaker 2: be the same as today's.
- 21:10Speaker 1: Or maybe a moving average averaging the values in the last.
- 21:13Speaker 2: Window right that smooths out noise, but often lags behind
- 21:16Speaker 2: trends and doesn't capture seasonality.
- 21:18Speaker 3: Well.
- 21:19Speaker 2: You calculate the error of these baselines maybe mean absolute
- 21:23Speaker 2: error MAE, and that gives you a target for your
- 21:26Speaker 2: mL model to beat.
- 21:27Speaker 1: What mL models work well here on this windowed data You.
- 21:30Speaker 2: Can try basic dense neural networks DNNs, but architectures that
- 21:35Speaker 2: understand sequences are often better. You can use one D convolutions,
- 21:40Speaker 2: similar to how two dcnns find spatial patterns and images.
- 21:44Speaker 2: One dcnns can find patterns across consecutive timesteps within your window.
- 21:48Speaker 2: You need to use causal padding, though, to make sure
- 21:50Speaker 2: the convolution only looks at past data, not future data
- 21:53Speaker 2: it shouldn't know about.
- 21:54Speaker 1: Makes sense, and RNNs LSTMs grus absolutely.
- 21:58Speaker 2: Since time series is inherently sequential, rn n's are a
- 22:00Speaker 2: natural fit. They can maintain state across the timesteps within
- 22:04Speaker 2: the window, potentially capturing complex temporal patterns and dependencies that
- 22:08Speaker 2: simple DNNs or even CNNs might miss.
- 22:11Speaker 1: So again, it's about experimenting with different window sizes, architectures,
- 22:14Speaker 1: hyper parameters to see what works best for your specific
- 22:17Speaker 1: time series.
- 22:18Speaker 2: Exactly, different data sets will respond better to different approaches.
- 22:21Speaker 1: Okay, so we've trained all these amazing models for vision
- 22:23Speaker 1: language time series. Now the crucial part for a coder,
- 22:28Speaker 1: how do you actually use them in an application deployment?
- 22:30Speaker 2: Right, if you want to run your model directly on
- 22:33Speaker 2: a user's device, like in a native mobile app on
- 22:36Speaker 2: Android or iOS, or maybe on an embedded system like
- 22:39Speaker 2: a Raspberry Pie, the main tool is tensorflowite.
- 22:43Speaker 1: T flight And why run it on the device on
- 22:46Speaker 1: the edge. Why not just call a server API.
- 22:48Speaker 2: Several big advantages late and see the prediction happens right
- 22:51Speaker 2: there instantly, no network delay, connectivity, it works even if
- 22:56Speaker 2: the device is offline, and privacy the user's data like
- 22:59Speaker 2: an image want to classify, doesn't have to leave their device,
- 23:02Speaker 2: which is huge nowadays.
- 23:04Speaker 1: Okay, that makes sense, So how does it work. Let's
- 23:06Speaker 1: take our simple Y for X one model again.
- 23:09Speaker 2: So you train your model as usual, probably in Python
- 23:11Speaker 2: using TensorFlow. You save the trained model. Then you use
- 23:15Speaker 2: a tool called the TF dot light dot T flight
- 23:17Speaker 2: converter to convert your saved TensorFlow model into a special
- 23:20Speaker 2: optimized dot T flight format.
- 23:22Speaker 3: So you get this lightweight dot T flight file.
- 23:24Speaker 2: Yep, it's usually much smaller then in your mobile app
- 23:27Speaker 2: code Jabacotlin for Android, Swift Objective, BAFF for iOS, or
- 23:31Speaker 2: your embedded system code like Python or C plus plus
- 23:33Speaker 2: on a PI. You use the t flight interpreter library.
- 23:36Speaker 2: You load that dot T flight file into the interpreter.
- 23:40Speaker 2: You prepare your input data, making sure it has the
- 23:42Speaker 2: exact shape and data type the model expects. For example,
- 23:46Speaker 2: that might be a float three two array containing ten
- 23:48Speaker 2: point zero with the shape of one one.
- 23:50Speaker 3: Gotta get the details right there absolutely.
- 23:52Speaker 2: Then you pass that input to the interpreter, invoke it,
- 23:55Speaker 2: run the prediction, and it gives you back the output tensor,
- 23:58Speaker 2: which would contain something like eighteen point ninety seven.
- 24:01Speaker 1: The prediction for why what about more complex things like
- 24:04Speaker 1: running an image classifier on mobile.
- 24:06Speaker 2: The core process is the same convert to dot t
- 24:09Speaker 2: flight use the interpreter. The trickier part is usually getting
- 24:12Speaker 2: the image data into the right format before feeding it
- 24:15Speaker 2: to the interpreter. How So, mobile platforms have their own
- 24:18Speaker 2: image formats, like androids bitmap or iOS's uiimage. Your CNN model, however,
- 24:23Speaker 2: probably expects input as a say, two to four by
- 24:27Speaker 2: two two four x three tensor of floating point numbers
- 24:30Speaker 2: normalized between zero one. So you need code to take
- 24:32Speaker 2: the native image, resize it, extract the pixel values, maybe
- 24:35Speaker 2: dealing with raw bite buffers and bit shifting for colors,
- 24:38Speaker 2: normalize them and arrange them into the correct tensor shape.
- 24:41Speaker 1: All right, There's some data wrangling involved, yeah, and some
- 24:43Speaker 1: platform specific setup for the interpreter itself in the app project.
- 24:47Speaker 2: Definitely. T flight also offers optimization, particularly quantization. During the
- 24:52Speaker 2: conversion process, you can tell it to convert the model's
- 24:54Speaker 2: weights from thirty two bit floats to say, eight bit integers,
- 24:59Speaker 2: and that makes the model much smaller, often a four
- 25:01Speaker 2: x reduction in file size, and it usually runs faster too,
- 25:04Speaker 2: maybe two three x speed up on mobile CPUs or
- 25:07Speaker 2: specialized hardware like edgetpus.
- 25:10Speaker 3: Is there catch?
- 25:11Speaker 2: There can be a small loss in accuracy because you're
- 25:13Speaker 2: reducing precision. You always need to test the quantized model
- 25:17Speaker 2: to see if the accuracy trade off is acceptable for
- 25:20Speaker 2: your specific application.
- 25:21Speaker 1: Okay, so t flight for native embedded What if you
- 25:24Speaker 1: want mL in the browser or for a no JS backend, then.
- 25:27Speaker 2: You're looking at pencerflow dot js. Tfs it lets you
- 25:31Speaker 2: define train and run mL models entirely in JavaScript.
- 25:34Speaker 1: You can actually train models in the browser.
- 25:36Speaker 2: You can you can define a model layer by layer,
- 25:39Speaker 2: similar to how you do it in Python. Using JavaScript APIs,
- 25:43Speaker 2: you'd use TFJS tensors for your data. Training often involves
- 25:47Speaker 2: a sinkle weight because it happens asynchronously in the browser.
- 25:50Speaker 2: You can build that Y two x one model or
- 25:52Speaker 2: even more complex things like image classifiers or models that
- 25:56Speaker 2: work on CSV data, all within javascripts.
- 25:59Speaker 3: That's pretty cool.
- 26:00Speaker 1: But maybe the biggest win for web deevs is using
- 26:02Speaker 1: models someone else has already trained.
- 26:04Speaker 2: Absolutely, that's the power of pre converted JavaScript models. Places
- 26:08Speaker 2: like TensorFlow, dot org and tfhub offer many sophisticated models
- 26:12Speaker 2: already converted to the TFGS format, so.
- 26:14Speaker 1: You can just load them and use them with minimal
- 26:16Speaker 1: code exactly.
- 26:17Speaker 2: There are models for toxicity detection and text image classification
- 26:21Speaker 2: using things like mobile net, where you can just pass
- 26:23Speaker 2: an mg tag pose detection with posnet that gives you
- 26:27Speaker 2: coordinates of body joints from an image or video. You
- 26:30Speaker 2: can integrate these powerful features into your web app pretty easily.
- 26:33Speaker 1: Just load the model script, write a few lines of
- 26:35Speaker 1: JavaScript to run inference.
- 26:36Speaker 2: Pretty much, and you can even do transfer learning in TFJS.
- 26:40Speaker 2: You can load a pre trained model like mobilenet, use
- 26:43Speaker 2: a function like model dot infer mmg embtting to grab
- 26:46Speaker 2: the internal feature embeddings for your own images, and then
- 26:49Speaker 2: use those embeddings as input to train a small new
- 26:53Speaker 2: TFJS model tailored to your specific classification task.
- 26:57Speaker 3: Nice.
- 26:58Speaker 1: Okay, one more deportment scenario. What if you need a dedicated,
- 27:02Speaker 1: scalable server for running predictions, maybe lots of users hitting
- 27:06Speaker 1: it at once.
- 27:07Speaker 2: For that kind of robust production environment, you'd use TensorFlow serving.
- 27:11Speaker 2: It's specifically designed to deploy TensorFlow models as a high
- 27:14Speaker 2: performance inference server.
- 27:15Speaker 3: What is it anal for you?
- 27:16Speaker 2: It's built for low latency and high throughput. Crucially, it
- 27:20Speaker 2: handles model versioning really well. You can deploy multiple versions
- 27:23Speaker 2: of the same model, say V one and a new
- 27:26Speaker 2: V two you just trained, and TensorFlow serving can manage
- 27:28Speaker 2: serving requests to either version or transition traffic smoothly, so you.
- 27:32Speaker 3: Can ab test models or roll out updates safely.
- 27:35Speaker 2: Exactly. It typically exposes APIs like rest or gRPC. Your
- 27:40Speaker 2: application sends an inference request with the data, TensorFlow Serving
- 27:44Speaker 2: loads the correct model version, often managed via configuration files,
- 27:49Speaker 2: runs the prediction efficiently and sends the result back. It's
- 27:53Speaker 2: built for reliable, scalable production use.
- 27:55Speaker 1: Okay, we've covered a ton of ground from the basic
- 27:58Speaker 1: concepts through vision, language, time series, and now all these
- 28:02Speaker 1: ways to deploy models. This really pulls together the practical
- 28:06Speaker 1: side from Roney's book.
- 28:07Speaker 2: Yeah, we started with that fundamental shift learning rules from
- 28:10Speaker 2: data instead of writing them, and saw how tensilflow provides
- 28:13Speaker 2: the platform for coders to do that.
- 28:14Speaker 1: Then we dove into computer vision CNN's dealing with data
- 28:18Speaker 1: limits using augmentation and transfer learning and.
- 28:20Speaker 2: NLP tokenizing embeddings to capture meaning and RNNs like lstm's
- 28:25Speaker 2: especially by directional ones to understand sequence and context even
- 28:28Speaker 2: for generating texts.
- 28:30Speaker 1: We touched on time series windowing data using CNN's and
- 28:33Speaker 1: RNNs for prediction.
- 28:34Speaker 2: And finally getting those models out there TFLight for devices,
- 28:37Speaker 2: TFGS for the Web, and tf serving for scalable back
- 28:40Speaker 2: end inference.
- 28:41Speaker 1: It really feels like these tools make AI and mL
- 28:45Speaker 1: much more practical for coders today. You don't need to
- 28:47Speaker 1: be a deep research scientist to start building things exactly.
- 28:51Speaker 2: The focus shifts to understanding the techniques when to use
- 28:55Speaker 2: a CNN versus an LSTM, how to prepare your data,
- 28:58Speaker 2: how to leverage pre train mode models, and applying them
- 29:01Speaker 2: to your problems, which leads.
- 29:02Speaker 3: To a final thought.
- 29:03Speaker 1: Maybe we talked about transfer learning using these powerful pre
- 29:06Speaker 1: train models, and also about running models right on the
- 29:09Speaker 1: device with t flight for speed and privacy. So thinking
- 29:13Speaker 1: about those capabilities combined, what kinds of really complex, maybe
- 29:18Speaker 1: even personalized, intelligent features could you start imagining for the
- 29:22Speaker 1: applications you build things that maybe seemed impossible just a
- 29:24Speaker 1: few years ago, but are now potentially within reach for
- 29:27Speaker 1: a code or using these tools