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

推荐订阅源

Spread Privacy
Spread Privacy
P
Palo Alto Networks Blog
P
Proofpoint News Feed
AI
AI
Help Net Security
Help Net Security
S
Securelist
T
Troy Hunt's Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
Cisco Blogs
Scott Helme
Scott Helme
Hacker News - Newest:
Hacker News - Newest: "LLM"
Vercel News
Vercel News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
B
Blog
GbyAI
GbyAI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Proofpoint News Feed
S
Security Affairs
Cisco Talos Blog
Cisco Talos Blog
AWS News Blog
AWS News Blog
T
Tenable Blog
H
Help Net Security
NISL@THU
NISL@THU
F
Fortinet All Blogs
博客园_首页
G
GRAHAM CLULEY
L
LINUX DO - 最新话题
P
Privacy International News Feed
G
Google Developers Blog
博客园 - Franky
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Security Archives - TechRepublic
Security Archives - TechRepublic
The Register - Security
The Register - Security
L
LangChain Blog
aimingoo的专栏
aimingoo的专栏
T
Tor Project blog
P
Privacy & Cybersecurity Law Blog
量子位
C
Cyber Attacks, Cyber Crime and Cyber Security
Forbes - Security
Forbes - Security
S
Secure Thoughts
Simon Willison's Weblog
Simon Willison's Weblog
D
Docker
Recorded Future
Recorded Future
博客园 - 三生石上(FineUI控件)
L
Lohrmann on Cybersecurity
T
Tailwind CSS 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 Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Andrej Karpathy's Neural Networks: Zero to Hero — 1) Intro to Neural Networks and Backpropagation
Jun Bae · 2026-05-30 · via DEV Community

Introduction

Andrej Karpathy uploaded several lecture videos on YouTube and the accompanying code on GitHub. I think they are excellent lectures, even better than many paid online courses. Here's the link: Neural Networks: Zero to Hero. So, I will summarize them and try to get meaningful insights from them. I'm going to cover all of them lecture by lecture (I hope...)

The first lecture is about backpropagation in neural networks.

 

The Spelled-out Intro to Neural Networks and Backpropagation

In the video, Karpathy said that backpropagation is what you need to train neural networks, and everything else is mainly for efficiency. That is why he explained and demonstrated backpropagation in the very first video.

I totally agree with him. Training neural networks and LLMs is essentially about reducing loss. And fundamentally, all methods for reducing loss are related to backpropagation, directly or indirectly.
 

Building Micrograd

Karpathy built a small project called micrograd. You can see the code here. This is made up of just a few simple lines of code, but it shows us how neural networks are built under the hood. In the video, he demonstrated how to build Micrograd and how it works step by step.
 

Differentiation and Derivative

We all learned differentiation and derivatives, right? What do differentiation and derivatives actually mean?

lim⁡h→0f(x+h)−f(x)h \lim_{h \to 0} \frac{f(x + h) - f(x)}{h}

Differentiation and derivatives tell us how much f(x)f(x) changes when xx changes. That is, they show the effect of a variable and the slope or gradient of a function. Then, if the derivative is 0, that point may be a local maximum or minimum of the function—not always, but it can be.

Actually, Karpathy didn't explain differentiation and derivatives in detail in the video. However, I think this is one of the most important aspects for understanding neural networks. So I'm going to explain this in more detail.
 

Linear Regression and Derivative

This concept is fundamental to linear regression as well. What is the core idea of linear regression? The goal is to minimize the residual sum of squares (RSS).

RSS=∑i=1n(yi−y^i)2=∑i=1n(yi−β1xi−β0)2 \begin{align*} RSS &= \sum_{i=1}^{n} \left( y_i - \hat{y}_i \right)^2 \\ &= \sum_{i=1}^{n} \left( y_i - \beta_{1} x_i - \beta_{0} \right)^2 \end{align*}

This is what linear regression is all about: finding the optimal β\beta values. Then, how to find them? This is where the derivative comes in. The RSS formula is a kind of quadratic function, so when it comes to quadratic functions, the minimum point is the point at which the derivative becomes 0. Therefore, if we differentiate the equation and find where the derivative is zero, we can find the best β1\beta_1 and β0\beta_0 .

To find the optimal β0\beta_0 and β1\beta_1 , we take the partial derivatives of RSS with respect to each parameter and set them equal to zero. I will demonstrate how to derive them.

RSS(β0,β1)=∑i=1n(yi−β1xi−β0)2 RSS(\beta_0, \beta_1) = \sum_{i=1}^{n} \left(y_i - \beta_1 x_i - \beta_0 \right)^2

First, differentiate the RSS with respect to β0\beta_0 :

∂RSS∂β0=−2∑i=1n(yi−β1xi−β0) \frac{\partial RSS}{\partial \beta_0} = -2 \sum_{i=1}^{n} \left(y_i - \beta_1 x_i - \beta_0 \right)

Then, differentiate the RSS with respect to β1\beta_1 :

∂RSS∂β1=−2∑i=1nxi(yi−β1xi−β0) \frac{\partial RSS}{\partial \beta_1} = -2 \sum_{i=1}^{n} x_i \left(y_i - \beta_1 x_i - \beta_0 \right)

At the minimum point, both partial derivatives are zero:

∂RSS∂β0=0∂RSS∂β1=0 \begin{align*} \frac{\partial RSS}{\partial \beta_0} &= 0 \\ \frac{\partial RSS}{\partial \beta_1} &= 0 \end{align*}

This gives us the normal equations:

∑i=1nyi=β1∑i=1nxi+nβ0∑i=1nxiyi=β1∑i=1nxi2+β0∑i=1nxi \begin{align*} \sum_{i=1}^{n} y_i &= \beta_1 \sum_{i=1}^{n} x_i + n\beta_0 \\ \sum_{i=1}^{n} x_i y_i &= \beta_1 \sum_{i=1}^{n} x_i^2 + \beta_0 \sum_{i=1}^{n} x_i \end{align*}

Solving these equations gives the optimal values:

β1=∑i=1n(xi−xˉ)(yi−yˉ)∑i=1n(xi−xˉ)2 \beta_1 = \frac{ \sum_{i=1}^{n} (x_i - \bar{x})(y_i - \bar{y}) }{ \sum_{i=1}^{n} (x_i - \bar{x})^2 }

β0=yˉ−β1xˉ \beta_0 = \bar{y} - \beta_1 \bar{x}

Here, xˉ\bar{x} is the mean of the input values, and yˉ\bar{y} is the mean of the target values.

Neural networks are also built from these kinds of linear expressions, usually combined with nonlinear activation functions. However, the way we calculate the parameters is totally different because neural networks are much more complicated and have so many parameters. So it is almost impossible to find the parameters in this way.
 

Finding Your Way in Pitch Darkness

Finding your way in pitch darkness

Assume that while hiking in the mountains, we get lost and trying to get down the mountain. But it is night, so we are in pitch darkness. We can only see a few inches around us. In this case, how can we get down the mountain? The answer is simple: by following the slope downward. At least, if we can see the slope around us, we can tell which way leads downward. This is how we find the optimal point when the equation is so complex that we are not able to solve for the optimum analytically.

def f(x):
  return 3*x**2 - 4*x + 5

f(3.0)

xs = np.arange(-5, 5, 0.25)
ys = f(xs)
plt.plot(xs, ys)

Visualization of the quadratic function

This is an example from Karpathy's code. The function is f(x)=3x2−4x+5f(x) = 3x^2 - 4x + 5 . Its derivative is df(x)dx=6x−4\frac{d f(x)}{d x} = 6x - 4 .

If we solve the equation 6x−4=06x - 4 = 0 , the derivative is 0 at x=2/3x = 2/3 . Then, if xx is at some other point, how can we move xx to find the minimum point of f(x)f(x) ?

The answer is simple. If the derivative value at a certain point is greater than 0, we have to decrease xx ; if it is less than 0, we have to increase xx . Therefore, if we consistently subtract λ(6x−4)\lambda (6x - 4) from xx , with a proper learning rate λ\lambda , f(x)f(x) will converge to its minimum.

This finite-difference approach is useful for building intuition and for gradient checking.

h = 0.000001
x = 2/3
(f(x + h) - f(x))/h

The output is 2.999378523327323e-06, which is almost zero. It is not perfectly exact because floating-point numbers have limited precision, and because this is a finite-difference approximation, but it is close enough for this simple demonstration.

Similarly, when you have an expression with several variables, you can get the slope with respect to a specific variable in this way.

h = 0.0001

# inputs
a = 2.0
b = -3.0
c = 10.0

d1 = a*b + c
c += h
d2 = a*b + c

print('d1', d1)
print('d2', d2)
print('slope', (d2 - d1)/h)

 
Output:

d1 4.0
d2 4.0001
slope 0.9999999999976694

This is also Karpathy's code. This example shows how dd changes when cc changes from 10.0. The gradient is 1.0, of course, since the derivative ddc(ab+c)\frac{d}{dc}(ab + c) is 1.
 

Calculating the Gradient

Karpathy demonstrates a hands-on example of how to calculate the gradients. Let's see one of his examples.

a=−2.0b=3.0d=a×be=a+bf=d×e \begin{align*} a &= -2.0 \\ b &= 3.0 \\ d &= a \times b \\ e &= a + b \\ f &= d \times e \end{align*}

When ff is the final output, we should calculate the gradients with respect to all intermediate values. Let's do this one by one.

The gradient of ff with respect to itself is 1 because ddff=1\frac{d}{df}f = 1 . Easy, right?

The important thing is that addition passes the gradient through. For example, if x=a+bx = a + b and ddxf(x)=k\frac{d}{dx}f(x) = k , the gradients of aa and bb are also kk . For subtraction, the subtracted term receives the negative of the upstream gradient. And when it comes to multiplication, the upstream gradient is multiplied by the other variable. If x=a×bx = a \times b , the gradient of aa is k×bk \times b because the local derivative with respect to aa is bb .

Therefore, the gradient of ee is ddef\frac{d}{de}f . ff is d×ed \times e , so the gradient ee is d=−6.0d=-6.0 . On the other hand, the gradient of dd is 1.0.

Finally, the gradient of aa is the contribution from ee plus the contribution from dd . So it is −6+3=−3-6 + 3 = -3 . The gradient of bb is also the contribution from ee plus the contribution from dd , and that is −6−2=−8-6 - 2 = -8 .

The computation graph for the final output looks like this:

gradient graph

What if we want to minimize ff by tuning the value of aa ? By subtracting the gradient, −3λ-3\lambda , ff will get smaller since the function with respect to aa is an upward-opening quadratic function. If λ\lambda is 0.1, we subtract -0.3 from aa . Then aa becomes -1.7. As a result, ff becomes -6.63, which is smaller.

Now, let's apply this algorithm to a neural network.
 

Neural Networks and Gradient Descent

simple neural network example

I organized another example from Karpathy in the image above. This is a very simple neural network architecture that he made. Actually, this is not the whole story yet. What we want to minimize is the loss function. So, if oo is y^\hat{y} , gradient descent should minimize ∑i=1n(yi−oi)2\sum_{i=1}^{n} \left( y_i - o_i \right)^2

In this way, Karpathy shows hands-on code that runs gradient descent on a simple MLP.

Here's the MLP training loop Karpathy builds in the Micrograd lecture:

class Neuron:

  def __init__(self, nin):
    self.w = [Value(random.uniform(-1,1)) for _ in range(nin)]
    self.b = Value(random.uniform(-1,1))

  def __call__(self, x):
    # w * x + b
    act = sum((wi*xi for wi, xi in zip(self.w, x)), self.b)
    out = act.tanh()
    return out

  def parameters(self):
    return self.w + [self.b]

class Layer:

  def __init__(self, nin, nout):
    self.neurons = [Neuron(nin) for _ in range(nout)]

  def __call__(self, x):
    outs = [n(x) for n in self.neurons]
    return outs[0] if len(outs) == 1 else outs

  def parameters(self):
    return [p for neuron in self.neurons for p in neuron.parameters()]

class MLP:

  def __init__(self, nin, nouts):
    sz = [nin] + nouts
    self.layers = [Layer(sz[i], sz[i+1]) for i in range(len(nouts))]

  def __call__(self, x):
    for layer in self.layers:
      x = layer(x)
    return x

  def parameters(self):
    return [p for layer in self.layers for p in layer.parameters()]

x = [2.0, 3.0, -1.0]
n = MLP(3, [4, 4, 1])
n(x)

xs = [
  [2.0, 3.0, -1.0],
  [3.0, -1.0, 0.5],
  [0.5, 1.0, 1.0],
  [1.0, 1.0, -1.0],
]
ys = [1.0, -1.0, -1.0, 1.0] # desired targets

for k in range(20):

  # forward pass
  ypred = [n(x) for x in xs]
  loss = sum((yout - ygt)**2 for ygt, yout in zip(ys, ypred))

  # backward pass
  for p in n.parameters():
    p.grad = 0.0
  loss.backward()

  # update
  for p in n.parameters():
    p.data += -0.1 * p.grad

  print(k, loss.data)

With his Micrograd code, you can see how the gradient descent algorithm works step by step. You can also calculate the gradient of each variable on your own. I strongly recommend doing these hands-on examples. After watching the video, I was able to clearly understand how gradient descent works, why we should use zero out gradients, why ReLU function is the most efficient, and so on. This is definitely worth your time.


Conclusion

I have shown Karpathy's demonstrations of gradient descent. As he said, this is the core concept for training neural networks. The rest is just for efficiency. Reducing loss using gradients: this is what makes neural network training possible and, ultimately, helped usher in the AI era.