惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
U
Unit 42
IT之家
IT之家
Y
Y Combinator Blog
T
Tailwind CSS Blog
B
Blog
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
Jina AI
Jina AI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
I
InfoQ
J
Java Code Geeks
F
Fortinet All Blogs
T
The Blog of Author Tim Ferriss
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
H
Hackread – Cybersecurity News, Data Breaches, AI and More
人人都是产品经理
人人都是产品经理
腾讯CDC
Hugging Face - Blog
Hugging Face - Blog
GbyAI
GbyAI
博客园 - 司徒正美
The GitHub Blog
The GitHub Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LangChain Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
I Built a Neural Network You Can Watch Train — Forward Pa...
Amar Gul · 2026-06-21 · via DEV Community

Amar Gul

Every neural-network tutorial I tried threw equations at me before I ever saw what was actually happening. I wanted the reverse: watch the activations flow forward, watch the loss bars shrink, watch backprop push gradients right-to-left across the layers.

So I built it. Here's a neural network that trains itself in front of you 👇

What you're actually seeing

  • Forward pass — particles flow left → right as activations propagate through the layers.
  • Loss — bars drop each epoch, and the output neurons glow red → gold → green as the error shrinks.
  • Backpropagation — particles flow right → left, the gradient returning toward the input.
  • 9 epochs, deterministically timed so every run is identical.

No training data is harmed in the making of this animation — it's a faithful visual model of the phases, built for intuition, not for crunching MNIST.

The stack

  • React for the phase state machine: idle → forward → loss → backward → done
  • Framer Motion for the particle and node animations
  • Web Audio API for synthesized sound (no audio files), tied to the dot movement
  • A small drift-corrected timing loop so the whole run lands on a fixed wall-clock budget

Three things that were trickier than expected

1. Animate particles with CSS transforms, not SVG attributes

My first version animated each particle's cx/cy. It worked but stuttered. Switching to Framer Motion's x/y (which compile to GPU-friendly CSS transforms) made it buttery:

<motion.circle
  r={4}
  cx={0} cy={0}
  initial={{ x: x1, y: y1, opacity: 0, scale: 0 }}
  animate={{ x: [x1, x2], y: [y1, y2], opacity: [0, 1, 1, 0] }}
  transition={{ duration: 0.65, ease: "easeInOut" }}
/>

2. Backprop has to flow backward

Sounds obvious, but my first pass spawned the backprop particles in the same direction as the forward pass. The fix was just swapping the source/target layer so the dots travel from the deeper layer back toward the input:

// Forward: layer l-1 → l   (left → right)
spawnParticles(l - 1, l, FORWARD_COLOR);

// Backprop: layer l → l-1  (right → left)
spawnParticles(l, l - 1, BACKWARD_COLOR);

Tiny change, huge difference in how "correct" it reads.

3. Make the network show it's learning

Loss bars are fine, but I wanted the network itself to react. So the output nodes are colored by the current loss — the same thresholds as the bars, so the legend stays consistent:

function lossColor(loss) {
  if (loss < 0.15) return GREEN;   // basically trained
  if (loss < 0.40) return GOLD;
  return RED;                       // high error
}

Early epochs glow red; by the end they settle into green. You see the network heal.

Bonus: deterministic timing (so I could record it)

setInterval drift made every recording a slightly different length. I anchored a start timestamp and held each epoch to a fixed budget, correcting drift as it goes:

function waitUntil(targetMs) {
  const remaining = targetMs - (Date.now() - runStart);
  return sleep(Math.max(remaining, 0));
}
// ...end of each epoch:
await waitUntil((epoch + 1) * EPOCH_BUDGET_MS);

Now every run lands on the same total time regardless of frame jitter.

What I learned

  • Animation isn't decoration — putting the direction of data flow on screen taught me backprop better than any equation did.
  • Browsers block the Web Audio API until a user gesture, so "start" had to be a real click.
  • Deterministic timing is underrated: it made the thing recordable and the code simpler.

I'm animating a whole set of these — sorting, Dijkstra, hash tables, binary trees. What algorithm should I visualize next? Drop it in the comments 👇