
Explore the shift from large-language models to computer vision and dive into vision transformers, patch and position encodings, and the segment anything model's image encoder, prompt encoder, and mask decoder.
Encode text with the DistilBert tokenizer from pretrained, adding CLS and SEP tokens, applying max length and padding, and inspect input IDs, attention mask, and token type IDs.
Learn how embeddings convert tokens into 768-dimensional vectors learned via backpropagation. See how Bert base and DistilBert base use pre-trained embedding layers to enable fine-tuning for specific tasks.
Explore how positional encodings provide sequence order in transformers, add to token embeddings, and differ from rnn inputs, using a concrete example with I am a robot and noting dimensions.
Explore custom color positional encodings using sine and cosine waves, showing how each embedding dimension maps to positions and repeats, with Plotly demonstrations.
Learn how to derive and apply positional encodings for transformers using sine for even indices and cosine for odd indices, then add them to embeddings to form transformer inputs.
Explore the attention mechanism at the heart of transformers, learning how query, key, and value matrices produce context-aware word representations through self-attention and attention scores.
Explore how the query matrix and query vectors compute attention scores by dot-product with key vectors, guiding how much each word attends to others in a sentence.
Visualize raw attention scores in two dimensions for the word river, showing high attention to river, bank, and flooded due to vector alignment, dot products, and self-attention.
While this topic will not be covered in detail in this course, it's useful to know that many deep learning architectures—particularly those involving attention mechanisms, such as in Transformers—apply normalization before the softmax function.
This normalization is typically done to scale the attention scores produced by the dot product of query and key vectors. By controlling the magnitude of these scores before applying softmax, the model avoids overly sharp probability distributions and promotes more stable training.
Explore how the output context vector aggregates token vectors via attention to capture the word’s context from the entire sequence for downstream tasks like classification and translation.
Explore when to use vision transformers versus convolutional neural networks, highlighting global self-attention, patch-based processing, and scenarios like large data sets, segmentation, and medical imaging.
Learn how SAM auto-prompt mode uses pre-learned object finder queries to drive prompt self-attention and cross attention over Vision Transformer embeddings for automatic mask generation.
Explore a simplified path from a 2x6 input image through a vision transformer, using patch embeddings with 2d positional encodings and a single head self-attention encoder, then review prompt self-attention.
Understand how vision transformers compute attention using queries, keys, and values, scale by dimension, apply stabilized softmax, and combine with values to produce context-aware patch representations, aided by residual connections.
Learn how decoder prompt self-attention in auto-prompt mode lets three prompts share information using query, key, and value vectors, producing updated embeddings for image cross attention.
Apply image to prompt cross attention by letting image tokens query the updated prompts to refine themselves. Strengthen true object patches and suppress background through two-way attention.
Explore how the IOU token and tiny prediction head assess mask quality in SAM, using mean pooling over prompts to rank and select the best, deduplicating overlaps.
Explore a very simple neural network with input x, hidden layer h, and weights w1 and w2, and learn how backpropagation and gradient descent adjust toward the true label.
Welcome to Math Behind LLMs, Transformers and Modern Computer Vision, a rigorous deep dive into the mathematical foundations powering today’s most advanced AI systems.
This course is designed for learners who want more than intuition. We derive and analyze the core equations behind Large Language Models, Vision Transformers, and modern image segmentation systems.
You will begin with tokenization and embedding mathematics, understanding how raw text becomes high-dimensional vector representations through algorithms like WordPiece. From there, we mathematically unpack the heart of transformer architectures: query, key, and value matrices, attention score computation, scaling behavior, and multi-head attention.
We examine attention masks, contextual encoding, and positional encodings — including the sine and cosine formulations that preserve sequence structure. You’ll build strong geometric intuition around vectors, dot products, cosine similarity, and dense embeddings.
The course then expands beyond language.
You’ll compare Convolutional Neural Networks with Vision Transformers, analyze quadratic attention operations, and walk through the complete Vision Transformer pipeline from patch embeddings to final predictions.
In an advanced section, we dissect the mathematics behind Meta’s Segment Anything Model (SAM). You will explore prompt encoders, self-attention, cross-attention between prompts and images, attention score computation in segmentation models, and how these systems are trained at scale.
By the end of this course, you won’t just understand how transformers work — you will understand why they work at the equation level across language and vision.
If you aim to build deep technical mastery and develop the mathematical intuition required for cutting-edge AI research and engineering, this course will elevate your expertise.