Loading video...

Video Failed to Load

Go Home

➡️ Machine Learning from Scratch, part 32: the convolutional neural network (CNN). An image is a grid of numbers. A filter is a tiny grid of numbers too, for example 3 by 3. It slides over the image, and at every position it multiplies its numbers with the pixels...

0 Comments

No comments available

Comments from the original post will appear here

Related Videos

➡️ Machine Learning from Scratch, part 37: softmax. Every neuron first adds up its inputs times their weights, then an activation function reshapes the result. Without activation functions, any number of layers would act like one single linear layer. Softmax is the special activation at the very end of a network that sorts things into classes. The last layer has one output neuron per class, and each one gives a raw score that can be any number, even negative. Softmax looks at all of them at once: it raises e to the power of each score, then divides by the sum. Now every output lies between 0 and 1, all outputs add up to exactly 1, and the class with the highest one is the prediction. Unlike an S curve on each neuron, softmax couples the whole layer: if one score rises, the other probabilities fall. Our own run, nothing downloaded. softmax.py (16 lines of numpy) makes 300 points in three classes and trains a small network with 2 inputs, 4 hidden neurons and 3 output neurons on 200 of them. On the 100 new points it gets 90 right. For the point (-1, 0) it says 95% class 1, 1% class 2 and 4% class 3. Honest notes: these percentages are the model's own confidence. On the test points our model is 94.9% sure on average but right only 90% of the time, so it is a bit too confident, which is common for neural networks. Our learning rate sits close to the edge of stability, so a tiny change in the start can move the last digit (we show our exact run). The 3D hills are the real probabilities of our trained network over the input plane. #machinelearning #coding #softmax #neuralnetwork #deeplearning

MachineLearningToGo

16,500 views • 1 month ago

➡️ Part 9 of learning ML code from scratch Six weights, one wrong answer, and not one of them knows it was at fault. Backpropagation is how they find out. Two questions guide the video: what even is backpropagation, and why do models need it? Step 1, the forward pass. Two numbers go into a tiny network, run through a hidden layer, and one number comes out. Ours says 0.700. We wanted 1.0, so square the difference and the loss is 0.09. That single number is how wrong the model is. Step 2, the question. Six weights produced that answer together. Which of them is to blame, and by how much? Step 3, the one idea. Change a single weight by a tiny amount and watch the error move. How much the error changes per unit of weight is the gradient of that weight. In the video you can see it happen: the weight wobbles and the error bar answers. Step 4, the shortcut. Every weight running into the same neuron starts from one shared number, the blame of that neuron. Multiply that blame by the value each weight carried and you have its gradient. One blame, computed once, and every weight into that neuron gets its own gradient from it. That is why backpropagation is fast enough to train anything at all. Step 5, backwards. The blame starts at the output and every layer hands its share to the layer in front of it, back through the same network the data came forward through. It goes layer by layer, and inside one layer every neuron is done together. Step 6, the update. The optimizer moves every weight against its own gradient, the whole weight matrix in one go, so no weight waits for its turn. All six gradients here are negative, so all six weights go up. After one step the answer reads 0.769. After sixty it reads 0.968 and the error is down to 0.001. The honest part: every gradient in the video was checked against the measured change of the error. Move that one weight, see what the error does, divide. Backprop and the measurement agree to nine decimal places, otherwise nothing would have rendered. #machinelearning #backpropagation #neuralnetworks #python #coding

MachineLearningToGo

212,200 views • 1 month ago

➡️ Machine Learning from Scratch, part 31: the transformer. A transformer turns every token into a list of numbers, adds its position, and then lets every token look at the others. That step is called attention: each token has a query (what am I looking for), a key (what do I contain) and a value (what I pass on). The better a query matches a key, the more of that value flows in. Real transformers repeat this in many layers with several attention heads each. The design comes from the 2017 Google paper "Attention Is All You Need" by Ashish Vaswani and colleagues, first used for translation. A large language model is a transformer trained to predict the next token, again and again, on a huge amount of text. Our own run, nothing downloaded. attention.py is one self-attention layer in 16 lines of numpy. Every word gets a query, a key and a value of 8 numbers, starting random, trained from scratch with hand-written backpropagation on 192 made-up sentences like "the dog ate the carrot because it was hungry". The task: find out which pet "it" means. On 64 new test sentences "it" puts 99.95 percent of its attention on the right word on average (the lowest single sentence gets 99.9 percent; the program prints this as 100%). Before training it was 10 percent, spread evenly. The cat sentence from the video is one of the test sentences. Honest notes: our task is easy on purpose. Every sentence has exactly one pet, so "it" only has to learn to look for pets, and it learns that within the first pass. Real sentences with two candidates need more context, which is what many layers are for. Our small version has no positions, no scaling, no mask, one head, and only "it" asks a question. Every word of the test sentences also appears in training; the combinations are new. The 3D space in the video shows the real keys of our model, projected to three axes (two of them stretched so you can see them). The stacked layers are a sketch. #machinelearning #ai #transformer #python #llm

MachineLearningToGo

81,200 views • 1 month ago

Backpropagation by hand ✍️ ~ 11 steps walkthrough below Backpropagation is the algorithm that actually trains a neural network, and it is where most people stop following along. It is not calculus you cannot do. It is matrix multiplication, working backward, one layer at a time. So I drew and calculated one entirely by hand. Goal: push the loss gradient back through a 3-layer network and land on a new value for every weight and bias. = 1. Given = A 3-layer perceptron, an input X, predictions Ypred = [0.5, 0.5, 0], and the truth Ytarget = [0, 1, 0]. = 2. Backprop gradient cells = Let us draw empty cells for every gradient we are about to compute. The shape of the answer comes first. = 3. Layer 3 softmax = We get dL/dz3 straight from Ypred minus Ytarget = [0.5, -0.5, 0]. No chain rule needed, and that shortcut is the whole reason softmax and cross-entropy are paired. = 4. Layer 3 weights and biases = Let us multiply dL/dz3 by [a2 | 1]. One multiplication gives the gradient for W3 and b3 together. = 5. Layer 2 activations = We multiply dL/dz3 by W3 to get dL/da2. The gradient moves back across a layer the same way the signal moved forward. = 6. Layer 2 ReLU = Let us pass it through the gate: keep the gradient where the activation was positive, zero it everywhere else. = 7. Layer 2 weights and biases = We multiply dL/dz2 by [a1 | 1]. The same figure as step 4, one layer up. = 8. Layer 1 activations = Let us multiply dL/dz2 by W2. = 9. Layer 1 ReLU = We apply the same gate again, now on a1. = 10. Layer 1 weights and biases = Let us multiply dL/dz1 by [x | 1], and every weight in the network now has a gradient. = 11. Update = We subtract, and the network has learned. In practice a learning rate scales this step. The gradients: dL/dz3 = [0.5, -0.5, 0] dL/da1 = [1, -2, 2, -1] dL/dz1 = [0, -2, 2, -1] The takeaway: matrix multiplication is all you need. Just like the forward pass, backpropagation is matrix multiplications end to end. You can do every one by hand, slowly and imperfectly, which is exactly why a GPU's ability to do them fast mattered so much to deep learning. 💾 Save this post!

Tom Yeh

964,224 views • 4 months ago

U-Net by hand ✍️ ~ 17 steps walkthrough below I consider U-Net as a key milestone in deep learning, the first image-to-image model that really worked! It came out of medical imaging, an unusual place, not from NeurIPS or CVPR or ACL. Now it is the backbone of diffusion models, which you see in almost all modern image generation models. I drew the network as a C so the matrix multiplication flows naturally down. Tilt your head to the right and it is a U again. 🤣 Goal: push a 3 x 16 image down to a 2 x 4 bottleneck and back out again, filling in every cell yourself. = 1. Given = An image of three channels, R, G and B, sixteen pixels wide, and every kernel the network will use. = 2. Convolution 1 = Let us slide the first kernel over the image. Each output is one multiply-and-add over a 2 x 3 window, and the result is the green feature map. = 3. Find the maxima = We circle the largest value in each 1 x 2 window. Circling first is worth the extra step: it is the pooling decision, made before anything is written down. = 4. Max pool 1 = Let us copy those maxima down. Sixteen columns become eight, and half the detail is gone for good. = 5. Convolution 2 = We convolve again with the second kernel, deeper into the contracting path. The feature map is blue now. = 6. Find the maxima again = Same move as step 3, on the blue map. = 7. Max pool 2 = Eight columns become four. = 8. The bottleneck = Let us convolve once more. This is the bottom of the U, a 2 x 4 block that is everything the network kept. = 9. Spread it out = We start back up. The transposed convolution writes each bottleneck value into a wider grid, leaving gaps between them. = 10. Transposed convolution 1 = Let us fill those gaps by convolving over the spread-out grid. Four columns become eight. = 11. The first skip = We copy the encoder's matching row straight across. This is the skip connection, and it is the whole reason a U-Net can recover detail that pooling threw away. = 12. Convolution with the skip = Let us convolve the upsampled features together with the copied ones. = 13. Spread it out again = Same as step 9, one level up. = 14. Transposed convolution 2 = Eight columns become sixteen, back to the width we started at. = 15. The second skip = The encoder's first feature map comes across, the one made before any pooling happened. = 16. Convolution and ReLU = We convolve, then cross out every negative and set it to zero. = 17. Output convolution = Let us apply the last kernel. Out comes R', G' and B', an image the same size as the one we started with. The outputs: R' = [3, 0, 7, 0, 7, 0, 17, 0, 3, 0, 9, 0, 2, 0, 6, 0] G' = [1, 20, 1, 10, 1, 12, 1, 19, 2, 5, 1, 11, 1, 3, 1, 7] B' = [4, 20, 8, 10, 8, 12, 18, 19, 5, 5, 10, 11, 3, 3, 7, 7] Congrats! You just calculated a U-Net by hand. 💾 Save this post!

Tom Yeh

17,722 views • 3 months ago

➡️ Machine Learning from Scratch, part 48: the Boltzmann machine. In 1985 Hinton, David Ackley and Terrence Sejnowski published how a Boltzmann machine learns, starting from the Hopfield network of part 47. Like the Hopfield network it prefers pictures with low energy, but it also has hidden units next to the visible pixels, and its units switch on by chance: the sigmoid turns the weighted sum into a probability. So the machine never settles and visits low energy pictures more often. We use the restricted version, with connections only between the two layers. The code (boltzmann.py, 16 lines of numpy) trains a restricted Boltzmann machine with 9 visible and 8 hidden units on all 14 bars-and-stripes pictures of 3 x 3 pixels, with contrastive divergence (one dream step per round, 5,000 rounds). Then 1,000 dreams start from pure noise and switch back and forth 100 times: 855 of them became one of the 14 pictures, from 3 times for the empty picture to 142 times for one with two bars. Sources: Nobel Prize in Physics 2024, press release of 8 October 2024 (Hopfield and Hinton, "for foundational discoveries and inventions that enable machine learning with artificial neural networks"); D. H. Ackley, G. E. Hinton, T. J. Sejnowski, "A Learning Algorithm for Boltzmann Machines", Cognitive Science, 1985; G. E. Hinton, "Training Products of Experts by Minimizing Contrastive Divergence", Neural Computation, 2002. Honest notes: the pictures do not come up equally often, because one dream step per round is only a shortcut for the real learning rule. When two of the 14 pictures are left out of training, our small machine does not dream them up; new examples of the same kind come from large machines trained on many examples. #machinelearning #ai #boltzmannmachine #neuralnetworks #nobelprize

MachineLearningToGo

14,700 views • 16 days ago

Dropout by hand ✍️ ~ 10 steps walkthrough below Dropout is the simplest trick in deep learning that actually works: during training you randomly switch neurons off, so the network cannot lean on any one of them. It is two lines of code and almost nobody has worked through what those lines do to the numbers. So I drew and calculated one entirely by hand. Goal: train one pass through a small network with two dropout layers, then run inference with dropout switched off. The network: Linear(2,4), ReLU, Dropout(0.5), Linear(4,3), ReLU, Dropout(0.33), Linear(3,2). = 1. Given = A training set of two examples, X1 and X2, and the weight matrices for all three linear layers. = 2. Draw the first random numbers = Let us draw 4 random numbers, one per neuron in the first hidden layer. Above 0.5 we keep (◯), below we drop (╳). Here that gives [◯, ╳, ◯, ╳]. = 3. Build the first dropout matrix = We turn that pattern into a diagonal matrix. The scaling factor is 1/(1-p) = 2, so a kept neuron gets 2 and a dropped one gets 0. Multiplying by it does both jobs at once: it deletes the 2nd and 4th neurons and doubles the two that survive. = 4. Draw the second random numbers = Let us do it again for the 3 neurons in the next layer, this time against p = 0.33. The result is [◯, ◯, ╳]. = 5. Build the second dropout matrix = We set the diagonal to 1.5 where kept and 0 where dropped. Only the 3rd neuron goes. = 6. Feed forward = Let us run the whole thing top to bottom: one matrix multiplication per layer, ReLU setting the negatives to zero, and the two dropout matrices doing their work in between. The outputs Y come out at the bottom. = 7. MSE loss gradients = We compare Y against the targets Y', subtract, and multiply each element by 2. That is the whole gradient of the mean squared error. = 8. Update the weights = Let us push those gradients back through the network and update the weights (marked in light red). = 9. Deactivate dropout = Training is over, so we set both dropout matrices to the identity. Every neuron is back, and nothing is scaled. = 10. Feed forward again = One more pass, this time on unseen data, to make the prediction. You have just trained and run a network with dropout by hand. ✍️ The outputs: Training outputs Y = [-6, 9; 13, 4] Loss gradients = [-4, 4; 6, -2] Inference outputs = [13, 13; 4, 3] 💾 Save this post! #AIbyHand #Dropout #DeepLearning #NeuralNetworks

Tom Yeh

14,442 views • 4 months ago

➡️ Machine Learning from Scratch, part 15: a recommender, the kind of algorithm that picks what your feed shows you. Our app is simulated: 300 people and 60 videos. Every person has a hidden taste, every video has a hidden style, and each person has watched only about 12 of the 60 videos. All the algorithm ever sees is who liked which of the videos they watched. How it learns: every person gets two numbers, and every video gets two numbers. Think of them as arrows on a map. For every video a person has seen, the two arrows turn into a chance of a like with the sigmoid from part 2. The algorithm compares that chance with what really happened and nudges both arrows a little. That is gradient descent from part 8, and the whole method is called matrix factorisation. The results, all measured on the videos nobody showed it: After 25 rounds it guesses 85.0% of the hidden likes right. After 3000 rounds it gets 87.8% right. The best any method could do here is 91.1%, because some likes are just random. For every person it recommends the three unseen videos with the strongest match, and 98% of them are videos the person really likes. A random unseen video gets a like 51% of the time. The first person on the list watched only 5 videos. From those five it guessed the other 55 and got 51 of them right. We ran the same program on 20 different simulated apps, and it always landed between 84 and 88%. Real apps use hundreds of numbers for every person and every video, plus signals like watch time and skips. The core idea stays the same: learn numbers for people and for videos, and match them. #machinelearning #ai #recommendersystem #python #coding

MachineLearningToGo

89,100 views • 1 month ago

➡️ Machine Learning from Scratch, part 47: the Hopfield network. In 1982 the physicist John Hopfield described a network that works as a memory, and 42 years later this work was part of the Nobel Prize in Physics. Each neuron is one pixel that is either on or off, and every neuron is connected to every other neuron, so 100 pixels need 4,950 connections. There are no layers: signals go back and forth until the network settles. Each neuron takes a weighted sum of its inputs and switches on if the sum is positive, off if it is negative. Storing a picture is simple: for every pair of pixels with the same colour the connection gets stronger, otherwise weaker. Every stored picture becomes a valley in the energy landscape, and no switch can ever raise the energy, so a noisy picture rolls downhill into the nearest stored memory. The code (hopfield.py, 16 lines of numpy, pictures in pics.txt) stores three 10 x 10 pictures, a heart, a house and a smiley, and flips 30 of the 100 pixels in each. After a single pass over all neurons all three come back exactly; the energy of the heart falls from -6.90 to -48.90, the energy of the stored heart. With 100 neurons and random patterns (10 flipped pixels, 20 runs) it recalls 5 patterns every time, 10 patterns in 94.5 % of the cases, 14 in 68 %, 20 in about one in four (24 %) and 30 in 1 %. Honest notes: the weights are kept as whole numbers (100 times the Hebb weight), so a sum of exactly zero switches the neuron on, as the rule says. The landscape in the video is a picture of the idea; the valley floors and the height of the rolling ball are the real energies from the run. #machinelearning #ai #coding #neuralnetworks #nobelprize

MachineLearningToGo

12,000 views • 17 days ago

Graph Convolutional Network by hand ✍️ ~ 12 steps walkthrough below Graph Convolutional Networks (GCNs), introduced by Thomas Kipf and Max Welling in 2017, are the tool for data shaped like a graph: social networks, recommendations, biological networks, drug discovery, molecular chemistry. I drew and calculated a simple GCN entirely by hand. Goal: run a two-layer GCN, then a small classifier, on a five-node graph, filling in every cell yourself. 1. Given A graph of five nodes, A to E, with edges between some of them. 2. Adjacency matrix (neighbors) Put a 1 wherever two nodes share an edge, in both directions. 3. Adjacency matrix (self) Add 1s down the diagonal, one self-loop per node. That is just adding the identity matrix. 4. Messages Multiply each node's embedding by the weights and biases, then ReLU. Negatives become 0. 5. Pooling Multiply the messages by the adjacency matrix. Each node gathers the messages of its neighbours and itself. 6. Visualize Node A pools [3,0,1] + [1,0,0] = [4,0,1]. 7. Second GCN layer Messages again: weights, biases, ReLU. 8. Pooling again Pool over each node and its neighbours, once more. 9. Visualize Node C pools [1,2,4] + [1,3,5] + [0,0,1] = [2,5,10]. 10. Fully connected layer Weights, biases, ReLU. This time there are no neighbours to pool, just the node itself. 11. Linear layer One more: weights and biases. 12. Sigmoid Squash each score to a probability (≥ 3 → 1, 0 → 0.5, ≤ -3 → 0). That is the classification for each node. You have just classified every node in the graph by hand. ✍️ The outputs: A: 0 (very unlikely) B: 1 (very likely) C: 1 (very likely) D: 1 (very likely) E: 0.5 (neutral) The takeaway: a GCN layer is two parts. The top part pools each node with its neighbours through the adjacency matrix. The bottom part is an MLP that transforms each node on its own. A transformer layer has the same two parts, with an attention matrix where the adjacency matrix was. Both matrices do one job, mixing across positions: attention over tokens, adjacency over nodes. In my class I call the GCN the transformer's little cousin: a bit more stubborn, because its attention is fixed by the graph rather than computed from Q, K, and V. Draw the two side by side and the resemblance is hard to miss. 💾 Save this post! #AIbyHand #GraphNeuralNetworks #DeepLearning

Tom Yeh

16,956 views • 4 months ago

➡️ Machine Learning from Scratch, part 38: cross entropy. Softmax (part 37) turns the raw scores of a network into one probability per class. Cross entropy is the loss function that scores how wrong those probabilities are, with one number. It looks only at the probability of the right class and takes minus its natural log. Right with 99 % costs 0.01. An unsure answer that gives the right class 40 % costs 0.92. If the network is 99 % sure of a wrong class, the right class gets 1 % and the cost jumps to 4.61. Training averages this cost over all examples and pushes the average down. Together with softmax, the push on every raw score is simply the predicted probability minus the truth, so the right class is pushed up, the wrong classes are pushed down, and a confident mistake gets the strongest push. With squared error through softmax, that push on a confident miss can be much weaker, which is one reason classifiers usually learn with cross entropy. Our own run, nothing downloaded. cross_entropy.py (16 lines of numpy) prints the three costs above, makes 300 points in three classes and trains the small network from part 37 (2 inputs, 4 hidden neurons, 3 output neurons) with cross entropy. The average loss falls from 1.01 to 0.13 in 1,000 steps. After training it gets 283 of the 300 points right, and the 17 it still gets wrong make up 73 % of the remaining loss. Honest notes: we train and measure on the same 300 points, so this is the training loss. On these easy points, the same network trained with squared error ends up about as accurate (284 of 300). The difference shows in the push on single confident mistakes: for our most confident miss at the start, 0.98 with cross entropy against 0.07 with squared error. The 3D surfaces show both losses over two raw scores of that real point, with the same 12 steps on each. #machinelearning #ai #crossentropy #neuralnetwork #deeplearning

MachineLearningToGo

11,400 views • 1 month ago

Discrete Fourier Transform by hand ✍️ ~ 12 steps walkthrough below Here is a little-known secret about the DFT and the inverse DFT: it is just matrix multiplication in both directions, one the transpose of the other, exactly like the forward pass and backpropagation I drew in other examples. Goal: recover which cosine waves a signal is made of, using nothing but multiplication and addition. = 1. Given = Three signals written as sums of cosines, and a fourth, X, that we do not know yet. = 2. Frequency matrix F = Let us write the coefficients as a matrix. Each signal is a row, each frequency a column, so A = cos(w) + 2cos(2w) becomes [1, 2, 0, 0]. = 3. Sample the waves = We read the four cosine waves at ten discrete time points. That word "discrete" is the whole difference between this and the continuous transform. = 4. Cosine matrix W = Let us write those samples as a matrix: each frequency a row, each time point a column. = 5. Frequency to time = We multiply F by W. That combines the four cosine waves in the proportions F specifies, and the result T is the three signals as they would look in time. = 6. Transpose = Let us stand each signal up as a column. = 7. Time to frequency = We multiply W by that transpose. Every cell is the dot product of one signal with one cosine wave, which measures how much of that wave the signal contains. Zero means none of it. = 8. Scale = Let us multiply by 2/n, with n = 10. The projections come out five times too large, and this is the correction. = 9. Transpose back = We turn it back around, and it is F again, exactly. That is the check: the transform recovered the coefficients we started from. = 10. Now solve for X = Let us run the same multiplication on the one signal whose recipe we never knew. = 11. Scale = We divide by 5 again. = 12. Transpose back = And X reads [0, 0, 3, 2], which says X = 3cos(3w) + 2cos(4w). Note: I originally drew this to show that the DFT is a special case of a convolution layer, its filters fixed to sine and cosine waves rather than learned. No wonder, then, that a convolution layer free to learn its own filters can be trained to process signals. 💾 Save this post!

Tom Yeh

13,644 views • 2 months ago

Discrete Fourier Transform by hand ✍️ ~ 12 steps walkthrough below Here is a little-known secret about the DFT and the inverse DFT: it is just matrix multiplication in both directions, one the transpose of the other, exactly like the forward pass and backpropagation I drew in other examples. Goal: recover which cosine waves a signal is made of, using nothing but multiplication and addition. = 1. Given = Three signals written as sums of cosines, and a fourth, X, that we do not know yet. = 2. Frequency matrix F = Let us write the coefficients as a matrix. Each signal is a row, each frequency a column, so A = cos(w) + 2cos(2w) becomes [1, 2, 0, 0]. = 3. Sample the waves = We read the four cosine waves at ten discrete time points. That word "discrete" is the whole difference between this and the continuous transform. = 4. Cosine matrix W = Let us write those samples as a matrix: each frequency a row, each time point a column. = 5. Frequency to time = We multiply F by W. That combines the four cosine waves in the proportions F specifies, and the result T is the three signals as they would look in time. = 6. Transpose = Let us stand each signal up as a column. = 7. Time to frequency = We multiply W by that transpose. Every cell is the dot product of one signal with one cosine wave, which measures how much of that wave the signal contains. Zero means none of it. = 8. Scale = Let us multiply by 2/n, with n = 10. The projections come out five times too large, and this is the correction. = 9. Transpose back = We turn it back around, and it is F again, exactly. That is the check: the transform recovered the coefficients we started from. = 10. Now solve for X = Let us run the same multiplication on the one signal whose recipe we never knew. = 11. Scale = We divide by 5 again. = 12. Transpose back = And X reads [0, 0, 3, 2], which says X = 3cos(3w) + 2cos(4w). Note: I originally drew this to show that the DFT is a special case of a convolution layer, its filters fixed to sine and cosine waves rather than learned. No wonder, then, that a convolution layer free to learn its own filters can be trained to process signals. 💾 Save this post!

Tom Yeh

25,684 views • 3 months ago

➡️ Machine Learning from Scratch, part 35: supervised vs unsupervised learning. In supervised learning every training example comes with the right answer, a label. The model guesses, a loss function measures how wrong the guess was, and training makes that error smaller step by step. In unsupervised learning there are no labels. The model still has a goal, but it is measured on the data itself. k-means is the classic example: place a few group centers, give every point to its nearest center, add up the squared distances, move each center to the middle of its points and repeat. That total never gets larger, and after a few rounds the groups stop changing. Our own run, nothing downloaded. learn.py (16 lines of numpy) makes 300 points in 2D from 3 true groups and learns them both ways. With labels (a nearest-middle classifier trained on 200 points) it gets 100 of 100 new points right. Without labels, k-means brings the total squared distance down from 2927 to 741, and its groups match the true ones for 298 of 300 points. Honest notes: our three groups are made up and well separated on purpose, so both methods do very well; real data is messier. The 298 counts each found group as the true group most of its points belong to (here that is a clean one-to-one match). k-means starts from far-apart points, because a random start can get stuck in a worse grouping. The algorithm cannot know what a group means, so a person still has to name it. #machinelearning #ai #supervisedlearning #coding #python

MachineLearningToGo

26,000 views • 1 month ago

ResNet by hand ✍️ ~ 10 steps walkthrough below "Deep Residual Learning for Image Recognition" (Kaiming He, CVPR 2016) is among the most cited papers in all of deep learning. Why does it matter so much? It fixed the exploding and vanishing gradients that kept deep networks from being deep, and made thousands of layers possible. How simple was the fix? An identity matrix. Goal: push three input vectors through a residual block, then through a transformer encoder block, filling in every cell yourself. = 1. Given = A mini batch of three input vectors, 3D, and the weights of the layers ahead. = 2. Linear layer = Let us multiply by the weights, add the bias, and apply ReLU so negatives become 0. Three feature vectors out. This is F(X). = 3. Concatenate = Now the trick. Stack an identity matrix beside the second layer's weights, and stack the input vectors under the features. Draw the lines between rows and columns: those are the skip connections. The identity is the residual. = 4. Linear layer + identity = We multiply the two stacked matrices. The identity carries X straight through while the weights transform it, so a single multiplication computes F(X) + X. Apply ReLU and hand it to the next block. Now watch the same trick inside a transformer, first in attention. = 5. Attention = Let us take three input vectors in 2D, compute the attention matrix, and multiply to get attention weighted vectors. = 6. Concatenate = We stack two identities this time, two residuals, which is how you get 1 + 1, and stack the input vectors with the attention weighted ones. = 7. Add = Multiply the stacked matrices. The identity adds attention to its own input, across the columns, which is how positions get combined. And again in the feed forward layer. = 8. First layer = Let us multiply by the feed forward weights and bias, then ReLU. Three feature vectors. = 9. Concatenate = Stack and link exactly as in step 3: the residual again. = 10. Second layer + identity = We multiply, apply ReLU, and pass the result to the next encoder block. This identity adds across the rows, combining features rather than positions. Takeaway: one simple "add" is what made really deep networks possible. 💾 Save this post!

Tom Yeh

18,332 views • 3 months ago

➡️ ML news part 1 An AI just fixed another AI by rewriting its weights directly, without any training. Machine Learning News, part 1: weight space programming. What is new, and why it matters. Until now, the weights of a neural network were set by training, and reading them took special tools built for that one job. A new report from researchers at MIT CSAIL shows that a general AI model, here GPT-6 Astra used as it is, can read and write those weights directly as plain lists of numbers. Test 1, reading. The model was given only the 17,253 weights of four small game playing networks (Breakout, Pong, Pac-Man, Freeway) and named the right game for all four. Test 2, writing. Without any data, loss or gradients, it wrote networks for three MinAtar games, and all three beat networks trained with PPO for 100 million steps. In Breakout it scored 517.4 points, against 25.3 after 500 million training steps. Test 3, repairing. The small open language model Qwen3.5-0.8B ran into its length limit on 93 percent of MATH-500 answers because it got stuck in loops. The model traced the loop to one direction written by the MLPs of layers 15 and 19 and removed it. That changed 131,072 weights, which is 0.016 percent of the model. MATH-500 went from 7.9 to 48.1 percent, IFEval from 21.0 to 62.3 percent, GSM8K from 13.8 to 67.1 percent, all with no training. The edit was chosen with a budget of 50 trial runs on practice problems, and the test sets were never seen. To be fair, the authors say the fix removed an obstacle and added no new ability, and on another small model it brought no improvement. This is an early report and not yet peer reviewed. Source: Takehi, Teoh, Zhang, Khattab (MIT CSAIL), "Sparks of Weight-Space Programming", blog post, November 2, 2026, (early report, not peer reviewed). Screenshots from the report are shown as quotes. Model names are given only to name the source. #machinelearning #ai #claude #neuralnetworks #llm

MachineLearningToGo

57,500 views • 13 days ago