Video yükleniyor...

Video Yüklenemedi

Ana Sayfaya Dön

In my class, I teach the autoencoder by asking everyone to stand up. 🙆 Stretch your arms out wide. Imagine you are holding a heavy textbook (like Introduction to Algorithms by Prof. Cormen), the whole thing, every page. Now bring your hands slowly together until they almost touch your...

22,479 görüntüleme • 10 gün önce •via X (Twitter)

0 Yorum

Yorum bulunmuyor

Orijinal gönderinin yorumları burada görünecek

Benzer Videolar

[VAE] by Hand ✍️ A Variational Auto Encoder (VAE) learns the structure (mean and variance) of hidden features and generates new data from the learned structure. In contrast, GANs only learn to generate new data to fool a discriminator; they may not necessarily know the underlying structure of the data. The International Conference on Learning Representations (ICLR) this year announced its first ever "Test of Time Award" to recognizes the VAE paper, published 10 years ago. This exercise demonstrates how to calculate a VAE by hand. [1] Given: ↳ Three training examples X1, X2, X3 ↳ Copy training examples to the bottom ↳ The purpose is to train the network to reconstruct the training examples. ↳ Since each target is a training example itself, we use the Greek word "auto" which means "self." This crucial step is what makes an autoencoder "auto." [2] Encoder: Layer 1 + ReLU ↳ Multiply inputs with weights and biases ↳ Apply ReLU, crossing out negative values (-1 -> 0) [3] Encoder: Mean and Variance ↳ Multiply features with two sets of weights and biases ↳ 🟩 The first set predicts the means (𝜇) of latent distributions ↳ 🟪 The second set predicts the standard deviation (𝜎) of latent distributions [4] Reparameterization Trick: Random Offset ↳ Sample epsilon ε from the normal distribution with mean = 0 and variance = 1. ↳ The purpose is to randomly pick a offset away from the mean. ↳ Multiply the standard deviation values with epsilon values. ↳ The purpose is to scale the offset by the standard deviation. [5] Reparameterization Trick: Mean + Offset ↳ Add the sampled offset to predicted mean ↳ The result are new parameters or features 🟨 as inputs to the Decoder. [6] Decoder: Layer 1 + ReLU ↳ Multiply input features with weights and biases ↳ Apply ReLU, crossing out negative values. Here, -4 is crossed out. [7] Decoder: Layer 2 ↳ Multiply features with weights and biases ↳ The output is Decoder's attempt to reconstruct the input data X from reparameterized distributions described by 𝜇 and 𝜎. [8]-[10] KL Divergence Loss [8] Loss Gradient: Mean 𝜇 ↳ We want 𝜇 to approach 0. ↳ A lot of math called SGVB simplifies the calculation of loss gradients to simply 𝜇 [9,10] Loss Gradient: Stdev 𝜎 ↳ We want 𝜎 to approach 1. ↳ A lot of math simplifies the calculation to 𝜎 - (1/ 𝜎) [11] Reconstruction Loss ↳ We want the reconstructed data Y (dark 🟧) to be the same as the input data X. ↳ Some math involving Mean Square Error simplifies the calculation to Y - X.

Tom Yeh

48,432 görüntüleme • 2 yıl önce

Batch Normalization by hand ✍️ ~ 7 steps walkthrough below Batch normalization is common practice for improving training and achieving faster convergence. It sounds simple. But it is often misunderstood. 🤔 Does batch normalization involve trainable parameters, tunable hyper-parameters, or both? 🤔 Is batch normalization applied to inputs, features, weights, biases, or outputs? 🤔 How is batch normalization different from layer normalization? So I drew and calculated one entirely by hand. Goal: normalize a mini-batch of 4 examples to mean 0 and variance 1, then let the network scale it back. = 1. Given = A mini-batch of 4 training examples, each with 3 features. = 2. Linear layer = Let us multiply by the weights and add the biases. Batch norm sits after this, which answers the second question: what gets normalized is features, not inputs, weights or biases. = 3. ReLU = We apply the activation, and -2 becomes 0. Negative values are suppressed before any statistic is taken. = 4. Batch statistics = Let us compute the sum, mean, variance and standard deviation, one row at a time. A row is a feature and the four columns are the four examples, so every number here measures one feature against the rest of the batch. That is the "batch" in batch normalization, and it is exactly what layer normalization does not do. The statistics are rounded to whole numbers, which is what keeps the rest of the page doable in pen. = 5. Shift to mean 0 = We subtract the mean, in green. The four values in each feature now average to zero. = 6. Scale to variance 1 = Let us divide by the standard deviation, in orange. Each feature now has variance one, whatever scale it arrived at. = 7. Scale and shift = We multiply by a linear transformation and pass the result on. The diagonal and the last column are trainable, so having just forced every feature to mean 0 and variance 1, we hand the network the means to undo it. The outputs: Mean of each feature = [2, 1, 2] Std dev of each feature = [1, 1, 2] To the next layer = [2, -2, 2, 0], [-3, 3, 6, -3], [2, 0, 1, 2] The answers: 🤔 Both. The scale and shift are trainable, the statistics are not. Epsilon and the momentum on the running statistics are the hyper-parameters, and one mini-batch by hand needs neither. 🤔 Features, after the linear layer, not inputs, weights or biases. 🤔 Batch norm measures across the batch, one feature at a time. Layer norm measures across the features, one example at a time. 💾 Save this post!

Tom Yeh

20,638 görüntüleme • 19 gün önce

MLP in PyTorch by hand ✍️ ~ 7 steps walkthrough below Goal: fill in every blank in the PyTorch code to build a multi-layer perceptron. 1. Given Let us start with a code template on the left and the network it is supposed to build on the right. Every blank in the code can be worked out from the picture. 2. Linear layer We count: 3 features in, 4 features out. So the weight matrix is 4 by 3. There is an extra column for the biases, which means bias = T. 3. ReLU Let us apply the activation. ReLU crosses out the negatives, so -1 becomes 0. 4. Linear layer The input size is 4, because that is what the previous layer put out. The output size is 2. A 2 by 4 weight matrix, and this time no extra column, so bias = F. 5. ReLU We cross out the negatives again. 6. Linear layer Two features in, five out. A 5 by 2 weight matrix, with a bias column, so bias = T. 7. Sigmoid Let us finish. Sigmoid squashes the raw scores (3, 0, -2, 5, -5) into probabilities between 0 and 1. You have just implemented a three-layer deep neural network by hand. ✍️ == Story == Three years ago I gave this exercise to my students, to connect the code to the math. They found it odd. Every other AI course they were taking lived inside a Jupyter notebook, and here I was handing out paper. Three years later, my colleagues are the ones rushing to move their materials to paper. The exercise has not changed. Paper still asks the one thing a notebook lets you skip: do you actually understand what the code is doing? If you can tell me why the weight matrix is 4 by 3, and why bias is F on the second layer, you understand nn.Linear better than someone who has been copy-pasting it for a year. 💾 Save this post! #AIbyHand #PyTorch #DeepLearning

Tom Yeh

13,318 görüntüleme • 26 gün önce

Transformer by hand ✍️ ~ 6 steps walkthrough below Open the hood of a transformer and the parts list is overwhelming: embeddings, positional encoding, attention weighting, self-attention, cross-attention, multi-head attention, layer norm, skip connections, softmax, linear, Nx, shifted right, query, key, value, masking. Which of those actually make the car run? Two of them. Attention weighting and the feed-forward network. Everything else is an enhancement to make it run faster and longer, which is how we got from a car to a truck, and to the word "large" in large language model. So I drew and calculated those two parts entirely by hand. Goal: push five features through one transformer block, filling in every cell yourself. 1. Given Five positions of input features, arriving from the previous block. 2. Attention matrix Let us feed all five features to a query-key module (QK) and read back an attention weight matrix, A. The details of that module are a post of their own. 3. Attention weighting We multiply the input features by A to get the attention weighted features, Z. Still five positions. The effect is to combine features *across positions*, horizontally: X1 becomes X1 + X2, X2 becomes X2 + X3, and so on. 4. First layer Let us feed all five weighted features into the first layer of the FFN. Multiply by the weights and biases. This time the combining happens *across feature dimensions*, vertically, and each feature grows from 3 numbers to 4. Note that every position goes through the same weight matrix. That is what "position-wise" means. 5. ReLU We cross out the negatives. They become zeros. 6. Second layer Let us bring it back down: 4 dimensions to 3. The output feeds the next block, which has a completely separate set of parameters, and the whole thing runs again. You have just calculated a transformer block by hand. ✍️ The takeaway: the two parts are doing two different jobs, and neither one alone is enough. Attention mixes *across positions*, so a feature can see its neighbours. The FFN mixes *across feature dimensions*, so each position can think about itself. Horizontal, then vertical. Then that pattern repeats N times, each block with its own separate set of weights. That is the Nx from the list up top, and that is what makes the transformer run. 💾 Save this post! #AIbyHand #Transformers #DeepLearning

Tom Yeh

25,944 görüntüleme • 23 gün önce

[Backpropagation] by Hand✍️ [1] Forward Pass ↳ Given a multi layer perceptron (3 levels), an input vector X, predictions Y^{Pred} = [0.5, 0.5, 0], and ground truth label Y^{Target} = [0, 1, 0]. [2] Backpropagation ↳ Insert cells to hold our calculations. [3] Layer 3 - Softmax (blue) ↳ Calculate ∂L / ∂z3 directly using the simple equation: Y^{Pred} - Y^{Target} = [0.5, -0.5, 0]. ↳ This simple equation is the benefit of using Softmax and Cross Entropy Loss together. [4] Layer 3 - Weights (orange) & Biases (black) ↳ Calculate ∂L / ∂W3 and ∂L / ∂b3 by multiplying ∂L / ∂z3 and [ a2 | 1 ]. [5] Layer 2 - Activations (green) ↳ Calculate ∂L / ∂a2 by multiplying ∂L / ∂z3 and W3. [6] Layer 2 - ReLU (blue) ↳ Calculate ∂L / ∂z2 by multiplying ∂L / ∂a2 with 1 for positive values and 0 otherwise. [7] Layer 2 - Weights (orange) & Biases (black) ↳ Calculate ∂L / ∂W2 and ∂L / ∂b2 by multiplying ∂L / ∂z2 and [ a1 | 1 ]. [8] Layer 1 - Activations (green) ↳ Calculate ∂L / ∂a1 by multiplying ∂L / ∂z2 and W2. [9] Layer 1 - ReLU (blue) ↳ Calculate ∂L / ∂z1 by multiplying ∂L / ∂a1 with 1 for positive values and 0 otherwise. [10] Layer 1 - Weights (orange) & Biases (black) ↳ Calculate ∂L / ∂W1 and ∂L / ∂b1 by multiplying ∂L / ∂z1 and [ x | 1 ]. [11] Gradient Descent ↳ Update weights and biases (typically a learning rate is applied here). 💡 Matrix Multiplication is All You Need: Just like in the forward pass, backpropagation is all about matrix multiplications. You can definitely do everything by hand as I demonstrated in this exercise, albeit slow and imperfect. This is why GPU's ability to multiply matrices efficiently plays such an important role in the deep learning evolution. This is why NVIDIA is now close to $1 trillion in valuation. 💡Exploding Gradients: We can already see the gradients are getting larger as we back-propagate up, even in this simple 3-layer network. This motivates using methods like skip connections to handle exploding (or diminishing) gradients as in the ResNet. I did the calculations entirely by hand. Please let me know if you spot any error or have any questions!

Tom Yeh

64,645 görüntüleme • 2 yıl önce

Apparently, I saw this video online and I decided to share. What this worker is applying is called bitumen, or what many of us know as bituminous coating. Most people think a wall is a solid, impenetrable block, but in reality, it is more like a sponge. Concrete and blocks have microscopic pores that pull water from the earth through a process we call capillary action. This thick black substance is the shield that stops that water from climbing up into the house. It is not about making the wall look good because this part will be buried under the dirt forever. It is about creating a skin that water cannot breathe through. When do you need to do this? The need for this arises because the soil is a very aggressive environment. Water is not your only enemy.. The ground also contains salts and sulfates that want to eat away at the cement. If this moisture finds its way to the steel bars inside the columns, those bars will start to rust. And when steel rusts, it expands, and that expansion is what cracks the concrete from the inside out. This coating is the only thing standing between your foundation and that kind of slow destruction. Thats is why if you see wet patches at the bottom of your walls inside your house, it usually means someone skipped this step or did it poorly during construction. You can apply this anytime you are building parts of a structure that will stay in contact with the ground. It is common in areas where the water table is high or where the soil stays damp for most of the year. This is a one-shot opportunity. Once you backfill the soil, you can never go back to fix it without a lot of expense and a lot of digging. It is about having the foresight to protect the heart of the building while it is still exposed. Please don’t ignore this if you need to. If you ignore it now to save a bit of money, you will be funding the future decay of your own home. I hope this helps.

A.Y.O

75,399 görüntüleme • 3 ay önce

Universities and High Schools have not moved rapidly enough to guide students to have skills for the next decade. THEY HAVE FAILED. It is a massive crisis that can be averted by understanding what AI and Robotics will bring about. Solutions are knowing how to use these tools and new industries that will rise. But this situation is also on ALL OF US. No “job” is safe from founder to entry level in most industries. You and I, by what we do, will be “replaced” ultimately. What to do? AI and Robotics are tools, the next decade is owned by those who know how to use them expertly, but this is also temporary. We have to understand that what we do for “work” will change giving ultimately a greater value to those that are: Creative Flexible Always learning Willing to be wrong Love being human Love being alive Know history Covet wisdom Knowing all tech has downsides Building strong family and friends Realize many institutions have failed The first four are required for you to be able to live through this period with your sanity intact. The rest will allow you to thrive. There are no true careers at this point anymore. There are advocation and vocations which will either earn you money or give life meaning. We will learn that we are not “what we do”, just like we knew for 99% of human existence. Let that sink in. — You and I are far, far ahead of knowing this and we can do two things: 1) Laugh at the “clueless” 2) Help people understand with grace Go to Reddit if you are 1, in fact don’t follow me because you will not like this next decade and what I post. You are 2 and thank you. Even if you and I have not solved this issue, we can help people understand what is ahead and with determination and creativity bound together to solve it locally. Or human family has done this millions of times. The evidence is: you are here. The Neo Luddite movement has not even begun and it will potentially rip apart society even more than all the fashionable moment in the recent past has. These Luddites will have a good point with the wrong answers cooked up by dying academics that cling to labels, “virtues” and victim hood. It will be readymade for some governments to enter in as “big daddy” to “help us”. You will not like what they do, but you will only know when it is too late. It will include YOU “volunteering” to “leave” by 60, to “help out” CanadaPod style. “Brian, I’m 24 what do I do?”. I hope to do much more here to help. But I do know this: 1) Learn a trade or vocation because it’s valuable. It may also be free to low cost if you do it right. 2) Learn everything you can about USING AI and TRAINING YOUR AI. Your expertise will be in the top 1% for a decade. But not forever. 3) Understand Bitcoin and how it will rise while other things sink. This is a short list for now. We will know more moving forward. When you see videos like this posted below, know one thing: Many of these folks had no real family of mental and physical support. Maybe no parent or one parent. Maybe only a broke system to prepare them for—nothing. This was not their doing. Now it is not your “job” to help them, it is your survival to help them if that is what you need. See some day after the dust settles these 20 year olds will be 40 year olds and running YOUR world. And at some point you may need them more than you think you do. You will need them, as they need you now. THIS IS WHAT PAST WISDOM KNEW. The elders of the past never found the need to piss on the youth and hope for the best. THE YOUTH ARE OUR BEST, let us all find ways to change it, even if every aspect of “the system” wants us to berate them into the ground.

Brian Roemmele

37,681 görüntüleme • 11 ay önce

I have not seen enough about the decision from Mike Vrabel and Tim Kelly to go for 2 down by 8 last night. Here’s why I loved it: 1) NFL teams this season have been successful on 55% of two-point conversion attempts. The odds were in the Titans’ favor. 2) Will Levis was dealing in the 2nd half. 3) Titans still had all three timeouts and the two-minute warning. 4) Miami struggled to move the ball on offense all night. Their three scoring drives went for 12, 7, and 59 yards. 5) If successful on the two-point conversion, a stop on defense and a TD wins the game. If unsuccessful, you can still send it to OT. 6) Titans offense marched down the field, scored the TD to make it a one possession game and essentially told Miami, “we are going for two because we know you cannot stop us right now.” The odds are in your favor. It’s a good mathematical decision. You want to psych out an opposing offense? Give them the ball knowing they need to run the clock out, or you are going to have a chance to WIN the game, not send it to overtime. They saw what your offense just did to their defense. They saw your QB on the sideline screaming and hyping everyone up. Cutting the lead to six put WAY more pressure on the Dolphins offense. You want to hype up your defense? Put them back on the field knowing your offense just did their job. Put them back on the field knowing a stop and a TD wins it. At that point, they aren’t in the mindset of “we need a stop to have a chance to go to OT.” They are thinking, “let’s go out here, get a stop, and give our offense a chance to WIN.” There’s a fundamental difference in playing to WIN and playing NOT to LOSE. This was a decision by a coaching staff that was playing to WIN. Brilliant game by Vrabel and Kelly. Brilliant execution late in the game by the offense and the defense. Completely out-coached one of the best offensive minds in the game. #Titans

Jake!

36,853 görüntüleme • 2 yıl önce