<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel><title>Vitor Sousa — Notebook</title><description>Short technical notes: derivations, code observations, and debugging lessons from working through machine-learning systems.</description><link>https://www.vitorsousa.com/</link><item><title>Benchmark Your Benchmark</title><link>https://www.vitorsousa.com/notebook/benchmark-your-benchmark/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/benchmark-your-benchmark/</guid><description>A number without variance isn&apos;t a result — and a benchmark without a correctness gate isn&apos;t a benchmark.</description><pubDate>Fri, 24 Jul 2026 00:00:00 GMT</pubDate><category>Debugging</category><category>benchmarking</category><category>measurement</category><category>testing</category></item><item><title>GELU / SwiGLU from Scratch</title><link>https://www.vitorsousa.com/notebook/gelu-swiglu/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/gelu-swiglu/</guid><description>Why it matters: The gate is a content-dependent multiplier on each hidden unit — the FFN learns which features to let through, not just how to mix them.</description><pubDate>Sat, 02 May 2026 00:00:00 GMT</pubDate><category>Code note</category><category>transformers</category><category>ffn</category><category>swiglu</category><category>gelu</category><category>from-scratch</category></item><item><title>Pre-Norm vs Post-Norm: Why It Matters</title><link>https://www.vitorsousa.com/notebook/pre-norm-vs-post-norm/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/pre-norm-vs-post-norm/</guid><description>Why it matters: In pre-norm the residual stream is never normalized, so every block has a clean identity gradient path back to the input — deep stacks (≥12 layers) train without…</description><pubDate>Sat, 02 May 2026 00:00:00 GMT</pubDate><category>Code note</category><category>transformers</category><category>normalization</category><category>architecture</category><category>from-scratch</category></item><item><title>RMSNorm vs LayerNorm — When and Why</title><link>https://www.vitorsousa.com/notebook/rmsnorm-vs-layernorm/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/rmsnorm-vs-layernorm/</guid><description>Why it matters: RMSNorm drops the mean-centering step and the bias, normalizing by the root-mean-square instead of the standard deviation — same gain term, fewer ops, ~7–15% low…</description><pubDate>Sat, 02 May 2026 00:00:00 GMT</pubDate><category>Code note</category><category>transformers</category><category>normalization</category><category>rmsnorm</category><category>layernorm</category><category>from-scratch</category></item><item><title>Scaled Dot-Product Attention in 20 Lines</title><link>https://www.vitorsousa.com/notebook/scaled-dot-product-attention/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/scaled-dot-product-attention/</guid><description>Why it matters: Without the √dk divisor, dot products grow with dimension and push softmax into its saturated tail — gradients vanish and training stalls past dk ≥ 64.</description><pubDate>Sat, 02 May 2026 00:00:00 GMT</pubDate><category>Code note</category><category>transformers</category><category>attention</category><category>from-scratch</category></item><item><title>RoPE: Rotary Position Embedding in 15 Lines</title><link>https://www.vitorsousa.com/notebook/rope-15-lines/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/rope-15-lines/</guid><description>Rotate Q and K by a position-dependent angle so attention scores depend only on relative distance — the real-valued cos/sin + rotate_half form used in Llama and in rlvr-from-scratch.</description><pubDate>Thu, 23 Apr 2026 00:00:00 GMT</pubDate><category>Code note</category><category>rope</category><category>positional-encoding</category><category>pytorch</category><category>transformer</category></item><item><title>Bias-Variance Decomposition</title><link>https://www.vitorsousa.com/notebook/bias-variance-decomposition/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/bias-variance-decomposition/</guid><description>Expected squared error splits into bias², variance, and irreducible noise.</description><pubDate>Tue, 21 Apr 2026 00:00:00 GMT</pubDate><category>Derivation</category><category>theory</category><category>regularization</category><category>generalization</category></item><item><title>Causal Mask as an Additive Tensor</title><link>https://www.vitorsousa.com/notebook/causal-mask-additive/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/causal-mask-additive/</guid><description>Additive 0.0/-inf masks compose; multiplicative masks don&apos;t.</description><pubDate>Tue, 21 Apr 2026 00:00:00 GMT</pubDate><category>Code note</category><category>attention</category><category>masking</category><category>pytorch</category></item><item><title>Chain Rule for Vectors</title><link>https://www.vitorsousa.com/notebook/chain-rule-vectors/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/chain-rule-vectors/</guid><description>Backprop is the vector chain rule applied right-to-left via VJPs.</description><pubDate>Tue, 21 Apr 2026 00:00:00 GMT</pubDate><category>Derivation</category><category>calculus</category><category>backprop</category><category>jacobian</category></item><item><title>Eigendecomposition: What It Buys You</title><link>https://www.vitorsousa.com/notebook/eigendecomposition/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/eigendecomposition/</guid><description>A = QΛQ⁻¹ diagonalizes repeated matrix action; spectral radius governs stability.</description><pubDate>Tue, 21 Apr 2026 00:00:00 GMT</pubDate><category>Derivation</category><category>linear-algebra</category><category>eigenvalues</category><category>dynamics</category></item><item><title>Einops for Tensor Reshaping</title><link>https://www.vitorsousa.com/notebook/einops-rearrange/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/einops-rearrange/</guid><description>Named dimensions at the call site — shape bugs drop to near zero.</description><pubDate>Tue, 21 Apr 2026 00:00:00 GMT</pubDate><category>Code note</category><category>einops</category><category>pytorch</category><category>tensors</category></item><item><title>He Initialization</title><link>https://www.vitorsousa.com/notebook/he-initialization/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/he-initialization/</guid><description>Variance-preserving init for ReLU-family activations; Xavier is for tanh/sigmoid.</description><pubDate>Tue, 21 Apr 2026 00:00:00 GMT</pubDate><category>Code note</category><category>initialization</category><category>relu</category><category>pytorch</category></item><item><title>Jensen&apos;s Inequality</title><link>https://www.vitorsousa.com/notebook/jensens-inequality/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/jensens-inequality/</guid><description>For concave f, E[f(X)] ≤ f(E[X]); the gap is exploited by ELBO.</description><pubDate>Tue, 21 Apr 2026 00:00:00 GMT</pubDate><category>Derivation</category><category>theory</category><category>elbo</category><category>variational-inference</category></item><item><title>KV-Cache in Five Lines</title><link>https://www.vitorsousa.com/notebook/kv-cache/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/kv-cache/</guid><description>Concatenate previous K/V to new K/V; per-step cost drops from O(T²) to O(T).</description><pubDate>Tue, 21 Apr 2026 00:00:00 GMT</pubDate><category>Code note</category><category>inference</category><category>attention</category><category>optimization</category></item><item><title>Maximum Likelihood = Minimum Cross-Entropy</title><link>https://www.vitorsousa.com/notebook/mle-equals-cross-entropy/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/mle-equals-cross-entropy/</guid><description>Minimizing cross-entropy is MLE for a categorical distribution.</description><pubDate>Tue, 21 Apr 2026 00:00:00 GMT</pubDate><category>Derivation</category><category>theory</category><category>cross-entropy</category><category>mle</category></item><item><title>RoPE Applies at d_k, Not d_model</title><link>https://www.vitorsousa.com/notebook/rope-at-dk-not-dmodel/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/rope-at-dk-not-dmodel/</guid><description>Rotate Q and K per-head, after the head split, to keep the relative-position property.</description><pubDate>Tue, 21 Apr 2026 00:00:00 GMT</pubDate><category>Code note</category><category>rope</category><category>positional-encoding</category><category>attention</category></item><item><title>Seed Everything for Reproducibility</title><link>https://www.vitorsousa.com/notebook/seed-everything/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/seed-everything/</guid><description>Same seed + same code → same loss curves; non-negotiable for debugging.</description><pubDate>Tue, 21 Apr 2026 00:00:00 GMT</pubDate><category>Code note</category><category>reproducibility</category><category>pytorch</category><category>debugging</category></item><item><title>Sinusoidal vs Learned vs Rotary</title><link>https://www.vitorsousa.com/notebook/sinusoidal-vs-learned-vs-rotary/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/sinusoidal-vs-learned-vs-rotary/</guid><description>RoPE wins because it encodes relative position as a first-class operation.</description><pubDate>Tue, 21 Apr 2026 00:00:00 GMT</pubDate><category>Code note</category><category>positional-encoding</category><category>rope</category><category>transformer</category></item><item><title>Softmax + Temperature</title><link>https://www.vitorsousa.com/notebook/softmax-temperature/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/softmax-temperature/</guid><description>τ → 0 is argmax, τ = 1 is softmax, τ → ∞ is uniform.</description><pubDate>Tue, 21 Apr 2026 00:00:00 GMT</pubDate><category>Derivation</category><category>softmax</category><category>sampling</category><category>distillation</category></item><item><title>Standardize vs Normalize</title><link>https://www.vitorsousa.com/notebook/standardize-vs-normalize/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/standardize-vs-normalize/</guid><description>Standardize for Gaussian-ish; normalize for bounded ranges; robust for outliers.</description><pubDate>Tue, 21 Apr 2026 00:00:00 GMT</pubDate><category>Code note</category><category>preprocessing</category><category>scaling</category><category>statistics</category></item><item><title>Stratified Split</title><link>https://www.vitorsousa.com/notebook/stratified-split/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/stratified-split/</guid><description>Preserve class ratios across train/test under imbalance with stratify=y.</description><pubDate>Tue, 21 Apr 2026 00:00:00 GMT</pubDate><category>Code note</category><category>sklearn</category><category>evaluation</category><category>class-imbalance</category></item><item><title>SVD in One Line</title><link>https://www.vitorsousa.com/notebook/svd/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/svd/</guid><description>Every matrix is rotate-scale-rotate; truncation gives best low-rank approximation.</description><pubDate>Tue, 21 Apr 2026 00:00:00 GMT</pubDate><category>Derivation</category><category>linear-algebra</category><category>svd</category><category>pca</category></item><item><title>uv — Fast Python Package Management</title><link>https://www.vitorsousa.com/notebook/uv-package-manager/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/uv-package-manager/</guid><description>10–100× faster than pip, lockfile built-in, replaces pip + venv + pip-tools.</description><pubDate>Tue, 21 Apr 2026 00:00:00 GMT</pubDate><category>Code note</category><category>python</category><category>uv</category><category>packaging</category></item><item><title>Why .contiguous() After transpose()</title><link>https://www.vitorsousa.com/notebook/contiguous-after-transpose/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/contiguous-after-transpose/</guid><description>view() needs contiguous memory; transpose() returns a non-contiguous view.</description><pubDate>Tue, 21 Apr 2026 00:00:00 GMT</pubDate><category>Debugging</category><category>pytorch</category><category>tensors</category><category>debugging</category></item><item><title>Bessel&apos;s Correction in Variance Calculation</title><link>https://www.vitorsousa.com/notebook/bessels-correction-variance/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/bessels-correction-variance/</guid><description>Use N-1 degrees of freedom for unbiased variance on samples instead of the population formula.</description><pubDate>Sun, 15 Dec 2024 00:00:00 GMT</pubDate><category>Code note</category><category>statistics</category><category>variance</category><category>python-tricks</category></item><item><title>Calculating Average Precision (AP) without Sklearn</title><link>https://www.vitorsousa.com/notebook/average-precision-manual/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/average-precision-manual/</guid><description>Interpolate precision and integrate the PR curve yourself when library helpers are unavailable.</description><pubDate>Sun, 15 Dec 2024 00:00:00 GMT</pubDate><category>Code note</category><category>evaluation</category><category>precision-recall</category><category>python-tricks</category></item><item><title>Representative Centroid Selection for Long-Context RAG</title><link>https://www.vitorsousa.com/notebook/centroid-kmeans-rag/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/centroid-kmeans-rag/</guid><description>Cluster embeddings and surface diverse centroids instead of near-duplicates for long-context prompts.</description><pubDate>Sun, 15 Dec 2024 00:00:00 GMT</pubDate><category>Code note</category><category>rag</category><category>retrieval</category><category>clustering</category></item><item><title>The Log-Sum-Exp Trick for Softmax</title><link>https://www.vitorsousa.com/notebook/log-sum-exp-softmax/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/log-sum-exp-softmax/</guid><description>Compute softmax in log-space to avoid overflow while keeping gradients stable.</description><pubDate>Sun, 15 Dec 2024 00:00:00 GMT</pubDate><category>Code note</category><category>numerical-stability</category><category>log-space</category><category>python-tricks</category></item><item><title>Vectorized Covariance Matrix Calculation</title><link>https://www.vitorsousa.com/notebook/vectorized-covariance/</link><guid isPermaLink="true">https://www.vitorsousa.com/notebook/vectorized-covariance/</guid><description>Leverage BLAS-backed matrix multiplication for fast covariance estimates on wide datasets.</description><pubDate>Sun, 15 Dec 2024 00:00:00 GMT</pubDate><category>Code note</category><category>numpy</category><category>performance</category><category>feature-engineering</category></item></channel></rss>