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
Variational Autoencoder by hand โ๏ธ ~ 11 steps walkthrough below
A VAE learns the structure of your data, the mean and variance of its hidden features, and then generates new data from that structure.
A GAN only learns to fool a discriminator. It can make convincing fakes without ever knowing what the data is really made of. That is the difference, and it is the whole reason VAEs matter.
In 2024 ICLR gave its first ever Test of Time Award to the VAE paper, "Auto-Encoding Variational Bayes" by Diederik Kingma and Max Welling, ten years on.
How does it work?
Goal: encode three inputs into a distribution, sample from it, decode it back, and read every loss gradient off the page.
= 1. Given =
Three training examples X1, X2, X3, copied to the bottom as their own targets. Reconstructing your own input is what puts the "auto", meaning self, in autoencoder.
= 2. Encoder, layer 1 =
Let us multiply the inputs by weights and biases, then apply ReLU, crossing out every negative.
= 3. Mean and standard deviation =
We multiply the features by two more weight sets. The first predicts the means ฮผ of the latent distributions, the second their standard deviations ฯ.
= 4. A random offset =
Let us sample ฮต from a standard normal, mean 0 and variance 1, and multiply it by ฯ. This is a random step away from the mean, scaled by how uncertain each feature is.
= 5. Mean plus offset =
We add the offset back onto ฮผ, and these become the decoder's inputs. Keeping the randomness out in ฮต is the reparameterization trick: it lets gradients flow straight through the sampling.
= 6. Decoder, layer 1 =
Let us multiply by weights and biases and apply ReLU again. Here -4 is crossed out.
= 7. Decoder, layer 2 =
We multiply once more. The output Y is the decoder's attempt to rebuild X from the sampled distribution.
= 8. Gradient for the mean =
Let us push ฮผ toward 0. A lot of math, the SGVB estimator, collapses the KL gradient to simply ฮผ itself.
= 9. Gradient for the standard deviation =
We want ฯ to approach 1.
= 10. And its formula =
That same math simplifies the gradient to ฯ minus 1/ฯ.
= 11. Reconstruction gradient =
We want the reconstruction Y to match the input X. Mean squared error simplifies its gradient to Y minus X.
Takeaway: the two gradients you just calculated each sit at the heart of a modern method, so one VAE teaches you both. The KL divergence is the penalty RLHF like GRPO uses to keep a fine-tuned model from drifting off its base. The reconstruction loss, plain mean squared error, is exactly what trains a diffusion model to denoise. Draw one VAE by hand and you have quietly learned the core of both.
๐พ Save this post!
Can you solve these agentic AI math problems by hand โ๏ธ? Getting a bit harder now. Download PDF: https://t.co/x3OfQrzJQV
Problems 11 to 15:
11. Comparing three calls: same total tokens, three different bills
12. The average call: size a sample, then scale it to the day
13. The system prompt: the tokens you re-send on every single call
14. The system prompt tax: what repeating those instructions costs
15. Calls in a budget: cost one call, then divide
Download, print, solve, and learn. โ๏ธ
~ Prof. Tom Yeh
Full Fine-Tuning vs LoRA by hand โ๏ธ interactive diagram. Open https://t.co/OpDkeUgLJw
Here's some T/F questions to test your knowledge:
[ ] Growing the batch size grows the number of trainable parameters
[ ] Both rows produce an output of the same shape
[ ] LoRA's ฮW is a smaller matrix than a full fine-tune's
[ ] Raising the rank leaves full fine-tuning's count untouched
[ ] A high enough rank makes LoRA cost more than a full fine-tune
Check your answers by dragging the diagram.
~ Prof. Tom Yeh
Answers: F, T, F, T, T
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!
LSTM by hand โ๏ธ ~ 15 steps walkthrough below
Since Hochreiter and Schmidhuber introduced them in 1997, LSTMs were the most effective way to handle long sequences, right up until the Transformer wave. They are a recurrent network: they read one input at a time and carry a memory forward. Lately recurrence is back in fashion (Mamba), because attention does not scale to hundreds of thousands of tokens.
So I drew and calculated one entirely by hand.
Goal: run an LSTM cell over a sequence of three inputs, filling in every gate and memory cell yourself.
1. Given
Three inputs X1, X2, X3, and four weight matrices: forget, input, candidate, and output.
2. Initialize
Let us set the previous hidden state h0 and the memory cell C0 to their start values.
3. Linear transform
We multiply the four weight matrices by the stack of the current input, the previous hidden state, and a 1.
4. The gates
Let us squash three of those results with sigmoid, giving the forget, input, and output gates, each between 0 and 1.
5. Update the memory
We forget part of the old memory (C0 times the forget gate) and add the new (the candidate times the input gate). That is the new memory C1.
6. Candidate output
Let us apply tanh to the new memory.
7. Update the hidden state
We multiply that candidate by the output gate. The result is h1.
8. Process X2
Copy h1 and C1 forward, then repeat the whole cell: linear transform, the gates, update memory to C2, output gate to h2.
9. Process X3
Once more. Copy h2 and C2 forward, repeat, and read off h3, the final hidden state.
Now you can show off to your friends that you calculated an LSTM by hand. โ๏ธ๐
๐พ Save this post!
#AIbyHand #LSTM #DeepLearning
Sora's Diffusion Transformer by hand โ๏ธ ~ 14 steps walkthrough below
Remember back in 2024 when Sora from OpenAI caused quite a sensation? This year, OpenAI shut it down. But the idea behind it, the Diffusion Transformer (DiT) that combines diffusion with a transformer, has led to the revolution in video generation models as we know them today.
Fancy tech names eventually die, but the foundational idea carries on.
So, how does DiT work?
Goal: generate a video conditioned by a text prompt and a diffusion step.
= 1. Given =
A training video, the prompt "sora is sky", and diffusion step t = 3.
= 2. Video to patches =
Divide all pixels in all frames into 4 spacetime patches. A patch spans space and time, which is how a video becomes a sequence.
= 3. Visual encoder =
Multiply the patches by weights and biases, then ReLU: one latent vector per patch. Here 4 numbers (2x2x1) become 2. In the paper, 196,608 become 4,096.
= 4. Add noise =
Sample noise scaled by the diffusion step t and add it to the latent features. You ruin the video on purpose so the model can be asked to guess what you ruined it with, the same trick as hiding a word from an LLM.
= 5. Encode conditions =
Encode "sora is sky" as [0,1,-1], encode t = 3 as [1,1], concatenate into one 5D column.
= 6. Estimate scale and shift =
Multiply that vector by weights and biases to get a scale [2,-1] and a shift [-1,5].
= 7. Apply scale and shift =
Scale the noised latent, then shift it. This is adaptive layer norm, the only place the prompt and the timestep touch the video. Conditioning is two arithmetic operations, not a separate model.
= 8. Self-attention =
Feed the conditioned latent to a query-key function to get a self-attention matrix. Value is omitted for simplicity.
= 9. Attention pooling =
Multiply the conditioned latent by the attention matrix. Patches now mix across space and time, which keeps frame 4 consistent with frame 1.
= 10. Pointwise FFN =
Multiply the attention-weighted features by weights and biases to get the predicted noise.
= 11. MSE loss gradients =
Take the difference between the predicted noise and the sampled noise from step 4. It kicks off backpropagation through every learnable parameter (red borders); encoder and decoder stay frozen (blue borders).
= 12. Denoise =
Subtract the predicted noise from the noised latent for the noise-free latent.
= 13. Visual decoder =
Multiply by weights and biases, then ReLU, back to patch size.
= 14. Patches to video =
Rearrange the patches into a sequence of frames.
Takeaway: DiT is a transformer that predicts noise. The video enters as latent patches, never pixels; the prompt and timestep enter only as a scale and a shift. Steps 4 and 11 are training, 12 to 14 are generation, the rest is the block you stack dozens of times.
๐พ Save this post!
Variational Autoencoder by hand โ๏ธ ~ 11 steps walkthrough below
A VAE learns the structure of your data, the mean and variance of its hidden features, and then generates new data from that structure.
A GAN only learns to fool a discriminator. It can make convincing fakes without ever knowing what the data is really made of. That is the difference, and it is the whole reason VAEs matter.
In 2024 ICLR gave its first ever Test of Time Award to the VAE paper, "Auto-Encoding Variational Bayes" by Diederik Kingma and Max Welling, ten years on.
How does it work?
Goal: encode three inputs into a distribution, sample from it, decode it back, and read every loss gradient off the page.
= 1. Given =
Three training examples X1, X2, X3, copied to the bottom as their own targets. Reconstructing your own input is what puts the "auto", meaning self, in autoencoder.
= 2. Encoder, layer 1 =
Let us multiply the inputs by weights and biases, then apply ReLU, crossing out every negative.
= 3. Mean and standard deviation =
We multiply the features by two more weight sets. The first predicts the means ฮผ of the latent distributions, the second their standard deviations ฯ.
= 4. A random offset =
Let us sample ฮต from a standard normal, mean 0 and variance 1, and multiply it by ฯ. This is a random step away from the mean, scaled by how uncertain each feature is.
= 5. Mean plus offset =
We add the offset back onto ฮผ, and these become the decoder's inputs. Keeping the randomness out in ฮต is the reparameterization trick: it lets gradients flow straight through the sampling.
= 6. Decoder, layer 1 =
Let us multiply by weights and biases and apply ReLU again. Here -4 is crossed out.
= 7. Decoder, layer 2 =
We multiply once more. The output Y is the decoder's attempt to rebuild X from the sampled distribution.
= 8. Gradient for the mean =
Let us push ฮผ toward 0. A lot of math, the SGVB estimator, collapses the KL gradient to simply ฮผ itself.
= 9. Gradient for the standard deviation =
We want ฯ to approach 1.
= 10. And its formula =
That same math simplifies the gradient to ฯ minus 1/ฯ.
= 11. Reconstruction gradient =
We want the reconstruction Y to match the input X. Mean squared error simplifies its gradient to Y minus X.
Takeaway: the two gradients you just calculated each sit at the heart of a modern method, so one VAE teaches you both. The KL divergence is the penalty RLHF like GRPO uses to keep a fine-tuned model from drifting off its base. The reconstruction loss, plain mean squared error, is exactly what trains a diffusion model to denoise. Draw one VAE by hand and you have quietly learned the core of both.
๐พ Save this post!
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
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!
Switch Transformer by hand โ๏ธ ~ 13 steps walkthrough below
The Switch Transformer, by Fedus, Zoph, and Shazeer in 2022, is one of the papers that made sparse Mixture of Experts practical at scale. Today, frontier models use MoE to pack enormous parameter counts while activating only a small slice per token: GPT-4, Claude, DeepSeek-V3, and Kimi all follow this pattern. If you want to understand how those models can be huge to store yet still cheap to run, this paper is a good place to start.
How does it work?
Goal: run five input features through attention, route each one to a single best expert, and read the output off the page.
= 1. Given =
Input features X1-X5 arrive from the previous block.
= 2. Attention matrix =
Feed all five features to a query-key attention module to get an attention weight matrix A.
= 3. Pooling =
Multiply the input features by A to get attention-weighted features Z1-Z5. The effect is to combine features across positions.
= 4. Visualize pooling =
Z4 is X4 + X5 because the fourth column of A is [0,0,0,1,1].
= 5. Gate values =
Multiply the weighted features by the switch matrix. Each gate value says how well expert A, B, or C can probably handle the feature.
= 6. Top expert =
Pick the row with the highest gate value. Sparse means only the top expert is selected, not all of them.
= 7. Routing =
Route each Z to its best expert. Every expert has a fixed capacity of 2, so one feature may overflow.
= 8. Expert A, linear =
Apply the linear layer to the features routed to Expert A. The effect is to combine features across feature dimensions.
= 9. Expert A, aggregate =
Send the combined feature to the corresponding output column.
= 10. Expert B, linear =
Apply the linear layer, as in step 8.
= 11. Expert B, aggregate =
Send the result to the corresponding output column, as in step 9.
= 12. Expert C, linear =
Apply the linear layer, as in step 8.
= 13. Expert C, aggregate =
Send the result to the output column. Since one feature exceeded Expert C's capacity, it passes through as-is.
Takeaway: a Switch Transformer keeps attention unchanged, then replaces the dense feed-forward network with a sparse set of experts. Most of the parameters sit in the experts, but only a small fraction are used for any one input. That is how GPT-4, Claude, DeepSeek-V3, and Kimi can be enormous to store and still cheap to run.
๐พ Save this post!
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 neck. The bottle "neck."
The final exam is tomorrow and you are allowed one cheat sheet: whatever you can scribble on your palm. All nine hundred pages have to survive the squeeze. That is the encoder.
Now imagine you sit in the exam. Push your arms back out to where they started. You try to rebuild the textbook from your palm notes. That is the decoder.
Of course you cannot get every page back. What you get back is what mattered enough to write down, and the gap between the two is the loss the network is trying to shrink.
I call it AI by Arms ๐. It gets a laugh, and then it gets remembered.
Goal: squeeze four numbers down to two, then rebuild the original four from them.
1. Given
Let us start with four training examples: X1, X2, X3, X4.
2. Auto (copy to targets)
We copy the training examples straight into the targets. That is the whole trick behind the name: "auto" is Greek for "self", and the data is its own label.
3. Encoder, layer 1
Let us multiply the inputs by the weights, add the biases, and apply ReLU. Negative values get crossed out and become zero.
4. Encoder, layer 2 (the bottleneck)
We do it again, and now the four dimensions have become two. This layer is called the bottleneck, because everything has to fit through it.
5. Decoder, layer 1
Let us go back the other way: multiply, add, ReLU. This time there are no negatives to cross out.
6. Decoder, layer 2
We multiply once more and get the outputs Y. This is the decoder's attempt to rebuild the four original numbers from the two it was given.
7. MSE loss gradients
Let us compare Y with the targets Y'. The gradient is 2 x (Y - Y'): subtract, then double. Those gradients kick off backpropagation, and the weights start to learn.
Your entire education is all about encoding and decoding!
New chapter! Context problems. Who can solve these by hand โ๏ธ? Download PDF: https://t.co/9kw8kCOdIz
The first five:
1. Mark the context: the window as cells you can count
2. What fills the window: the system prompt, the user, the model's reply
3. Turn by turn: every turn is the same block, and most of it is the reply
4. Will it fit? Number a new message into what's left, and see it run out
5. Turns until full: how many rounds before there is no room
Previously, I shared Chapter 1: Token Problems 1 ~ 20
https://t.co/cBKCeRf6oq
https://t.co/Uv5TufAwiT
https://t.co/x3OfQrzJQV
https://t.co/FVI5BKPsjO
Why am I designing these math problems?
AI is making people (including me) think less. It's just too easy to ask AI a few questions
about a new concept and start to believe I get it. We used to practice on a coding problem,
but now AI writes the code, and solving it technically is not the same as knowing anything.
So I recast each concept as a simple math problem you have to work with pen and paper.
Using our hands is one way to motivate ourselves to start thinking again. โ๏ธ
If you solve them by hand, leave a comment to let me know. I will give you a shout out in my next post.
Download, print, solve, and learn. โ๏ธ
~ Prof. Tom Yeh
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!
AI by Hand โ๏ธ Yantra Jnana Award ~ Yantra Jnana means "Machine Knowledge" in Sanskrit. I learned this from Prof. Narendra Karamangala. Today is Indiaโs Teachers' Day. We are pleased to announce this award to recognize extraordinary work teaching AI in an Indian language, by hand, without relying on expensive technologies.
Please share this announcement with people you know who may be interested in this award!
To enter the award, record a video of you teaching AI by hand in one of the following languages:
Hindi
Punjabi
Marathi
Gujarati
Kannada
Tamil
Telugu
Malayalam
We know there are a lot more languages in India. But please allow us to start with this initial round of 8 languages, which I believe have the most number of native speakers. If this round is well-received, we will definitely give more awards for cover other languages in the future.
Read more about the award: https://t.co/JIEbKigac3
Full Fine-Tuning vs LoRA by hand โ๏ธ interactive diagram. Open https://t.co/OpDkeUgLJw
Here's some T/F questions to test your knowledge:
[ ] Growing the batch size grows the number of trainable parameters
[ ] Both rows produce an output of the same shape
[ ] LoRA's ฮW is a smaller matrix than a full fine-tune's
[ ] Raising the rank leaves full fine-tuning's count untouched
[ ] A high enough rank makes LoRA cost more than a full fine-tune
Check your answers by dragging the diagram.
~ Prof. Tom Yeh