← CS Lab AI & Machine Learning / Gradient Descent Open standalone ↗

Gradient descent is how a model teaches itself: it follows the slope of its own error downhill, one small step at a time. The curve in the tool is a loss function — how wrong the model is — and the ball is the current parameter, rolling toward the bottom.

Where you meet it

What it does

It finds a minimum of the loss by repeatedly nudging the parameters in the direction that makes the loss smaller. It doesn't solve for the answer algebraically — it searches, taking the locally steepest downhill step each time and hoping the steps add up to the bottom.

The learning rate is the whole game: too big and it overshoots, too small and it crawls — there's no right value, only a tuned one.

How it works

One update, repeated until the loss stops dropping:

θ := θ − η · ∇J(θ)

The gradient ∇J(θ) is the vector of slopes of the loss with respect to each parameter. Here's the key fact: of all directions you could step, the gradient is the one of steepest increase. So its negative is the direction of steepest decrease — that's why the minus sign is there. A first-order Taylor expansion makes it precise: for a small step θ − η∇J, the loss changes by about −η · ‖∇J‖², which is negative, so the loss goes down. η (eta) is the learning rate — the step size.

A minimal example, minimizing J(x) = x² (so ∇J = 2x) from x = 1 with η = 0.3:

x = 1.0
x ← 1.0 − 0.3·(2·1.0) = 0.40
x ← 0.40 − 0.3·(2·0.40) = 0.16
x ← 0.16 − 0.3·(2·0.16) = 0.064   # → 0

The steps shrink as the slope flattens near the minimum — that automatic slowdown is built in, not coded.

Watch out

  • η is the whole game. Too large and it overshoots, bounces, or diverges (push the slider past 1 in the tool); too small and it crawls for thousands of steps. There's no universally right value — it's tuned.
  • Local minima and saddle points. On a non-convex loss, the steepest-descent direction can lead into a shallow dip or flatten out on a saddle. In high dimensions saddle points — flat in some directions, downhill in others — are the bigger headache than local minima.
  • Scale your features. If one input ranges 0–1 and another 0–10000, the loss surface is a stretched ravine and descent zig-zags. Standardizing the features makes the bowl round and the path direct.
  • Batch vs. stochastic. Computing the gradient over the whole dataset every step is exact but slow. SGD estimates it from one example (or a mini-batch): noisier steps, but far cheaper — and the noise can even help escape bad spots.

Go deeper

Gradient Descent ist die Art, wie sich ein Modell selbst trainiert: Es folgt der Steigung seines eigenen Fehlers bergab — Schritt für kleinen Schritt. Die Kurve im Tool ist eine Loss-Funktion — wie falsch das Modell liegt — und der Ball ist der aktuelle Parameter, der nach unten rollt.

Wo es vorkommt

Was es tut

Es findet ein Minimum des Loss, indem es die Parameter immer wieder in die Richtung schiebt, die den Loss kleiner macht. Es löst nicht algebraisch nach der Antwort auf — es sucht, macht jedes Mal den lokal steilsten Schritt bergab und hofft, dass die Schritte sich zum Tiefpunkt summieren.

Die Learning Rate ist das Entscheidende: zu groß und es überschießt, zu klein und es kriecht — es gibt keinen richtigen Wert, nur einen getunten.

Wie es funktioniert

Ein Update, wiederholt bis der Loss nicht mehr sinkt:

θ := θ − η · ∇J(θ)

Der Gradient ∇J(θ) ist der Vektor der Steigungen des Loss nach jedem Parameter. Der entscheidende Punkt: Von allen Richtungen, in die du gehen könntest, ist der Gradient die des steilsten Anstiegs. Sein Negatives ist also die Richtung des steilsten Abstiegs — daher das Minuszeichen. Eine Taylor-Entwicklung erster Ordnung macht es präzise: Für einen kleinen Schritt θ − η∇J ändert sich der Loss um etwa −η · ‖∇J‖², also negativ — der Loss sinkt. η (eta) ist die Learning Rate — die Schrittweite.

Ein minimales Beispiel, Minimierung von J(x) = x² (also ∇J = 2x), von x = 1 mit η = 0.3:

x = 1.0
x ← 1.0 − 0.3·(2·1.0) = 0.40
x ← 0.40 − 0.3·(2·0.40) = 0.16
x ← 0.16 − 0.3·(2·0.16) = 0.064   # → 0

Die Schritte werden kleiner, je flacher die Steigung nahe dem Minimum wird — diese automatische Verlangsamung ist eingebaut, nicht codiert.

Worauf achten

  • η ist das Entscheidende. Zu groß und es überschießt, springt oder divergiert (schieb den Slider im Tool über 1); zu klein und es kriecht über tausende Schritte. Es gibt keinen allgemein richtigen Wert — er wird getunt.
  • Lokale Minima und Sattelpunkte. Bei einem nicht-konvexen Loss kann die Richtung des steilsten Abstiegs in eine flache Mulde führen oder auf einem Sattel auslaufen. In hohen Dimensionen sind Sattelpunkte — in manchen Richtungen flach, in anderen bergab — das größere Problem als lokale Minima.
  • Skaliere deine Features. Reicht ein Input von 0–1 und ein anderer von 0–10000, ist die Loss-Fläche eine gestreckte Schlucht und der Abstieg zickzackt. Standardisieren macht die Schüssel rund und den Pfad direkt.
  • Batch vs. stochastisch. Den Gradienten in jedem Schritt über den ganzen Datensatz zu berechnen ist exakt, aber langsam. SGD schätzt ihn aus einem Beispiel (oder einem Mini-Batch): verrauschtere Schritte, aber viel billiger — und das Rauschen kann sogar helfen, schlechten Stellen zu entkommen.

Mehr dazu

Next up
Databases & Data ModelingSQL SELECT & WHERE Databases & Data ModelingSQL GROUP BY & Aggregation All concepts →