Shift before exponentiating
Subtract the maximum logit to stay stable when confidence gets extreme.
I'm Krishna Sharma, a Computer Science student and ML practitioner. I turn raw datasets into useful models and working products — from CNNs on MNIST to production APIs.
A compact implementation of the derivative that turns a classifier's confident mistake into a useful learning signal.
import numpy as npdefsoftmax(logits): shifted = logits - logits.max(axis=-1, keepdims=True) exp = np.exp(shifted) # numerical stabilityreturn exp / exp.sum(axis=-1, keepdims=True)defsoftmax_cross_entropy_backward(logits, target): probs = softmax(logits) grad = probs.copy() grad[np.arange(len(target)), target] -=1.0return grad / len(target) # dL / d(logits)logits = np.array([[2.4, 0.8, -0.2]])gradient = softmax_cross_entropy_backward(logits, [0])Subtract the maximum logit to stay stable when confidence gets extreme.
The elegant derivative: predicted distribution, adjusted at the target index.
Positive gradients lower excess confidence; the negative target gradient raises it.
Six bite-size derivations I actually use — from dot-product attention to the ELBO. Hover for intuition, drag sliders to see numbers move, and watch the gradients flow.
Each query attends to all keys. Temperature √dₖ prevents vanishing gradients when dₖ is large.
The backbone of your MNIST CNN — shared weights slide across the image.
Chain rule all the way down — one scalar loss, millions of gradients.
Vanilla SGD oscillates. Adam adapts per-parameter with momentum + RMS.
Variational inference — trade-off behind VAEs and diffusion.
Bias–variance trade-off: $\; \mathbb{E}[(y-\hat f)^2]=\text{Bias}^2+\text{Var}+\sigma^2$
# x: [B, T, d] — residual stream def transformer_block(x): y = LayerNorm(x) # y = (x-μ)/σ · γ + β a = MultiHeadAttention(y, y, y) # 8 heads · QKᵀ/√d x = x + Dropout(a) # residual y = LayerNorm(x) f = FFN(y) # W₂·GELU(W₁y + b₁) + b₂ return x + Dropout(f) # GELU: 0.5x(1+erf(x/√2)) ≈ x·sigmoid(1.702x) # FFN expands 4×: d → 4d → d (≈ 2/3 params)
I'm a fourth-year B.Tech Computer Science student graduating in 2027. My work sits between applied machine learning and software engineering: I like models that get deployed, not notebooks that get closed.
As a Software Development Intern at WritED Edutech, I built a React frontend and improved technical SEO for a JavaScript-rendered single-page app. Competitive programming keeps my foundations in algorithms, graphs, and dynamic programming sharp.
Right now I'm deepening ML theory while building small, complete, end-to-end projects — each one shippable, each one documented.
A convolutional neural network trained on MNIST, built from data loading to an inference pipeline with synthetic test cases and a structured README.
A reusable text-classification module using TF-IDF and scikit-learn to predict sentiment polarity, packaged with executed results instead of placeholder output.
A production-style backend service for shortening and redirecting URLs, built with FastAPI and PostgreSQL and containerized with Docker.
Built WritED Edutech's production React frontend, then audited technical SEO for a hash-routed SPA to improve crawlability and search visibility.
From Codeforces rounds to interview graphs — the handful of identities and bounds that keep showing up. No fluff, just the ones that solve problems.
Preview loads on click — saves bandwidth. open in new tab or download.