AIToday
Large Language ModelsAI Coding AssistantsQiita 機械学習Published: Dec 4, 2026, 13:00 JST

Qiita explainer: gradient descent powers AI, from 2 weights to LLMs

Send on LINE
Qiita explainer: gradient descent powers AI, from 2 weights to LLMs

3 Key Points

  1. What happened

    The explainer walks through a minimal Python script with no external libraries that trains y = w*x + b on four samples following y = 2x + 1, using learning_rate = 0.01 and 1,000 epochs of gradient descent.

  2. Why it matters

    The same predict-measure-error-adjust cycle, with two weights here, is the basis of modern deep learning and LLMs (large language models), which differ mainly in scale and optimization tools.

Ask AI

Ask the AI about this article. Questions and answers are published on this page

Context & Analysis

This is a hands-on tutorial rather than a news event. It starts from the idea that machine learning algorithms automatically find optimal weights from data and error, instead of relying on hand-written rules. To make that concrete, it builds a linear regression model y = w * x + b and trains it on four data points that follow y = 2x + 1, using plain Python without any libraries. The code initializes w and b to zero, sets a learning rate of 0.01 and 1,000 epochs, then repeatedly computes predictions, the mean squared error, and the gradients for w and b. After each epoch it updates the parameters in the opposite direction of the gradient. The tutorial highlights four key elements: the model, the loss function, the gradients, and the learning rate. It explains that gradients show how the loss changes when w or b is nudged, and that in multi-layer neural networks these gradients are computed efficiently by backpropagation. The learning rate is described as a step-size hyperparameter: too large and the training can overshoot and diverge, too small and convergence takes a long time. Finally, this toy example connects to real AI development. Modern deep learning and LLMs, such as large language models, follow the same essential loop, but with millions to hundreds of billions of weights handled through matrix operations and attention mechanisms. They also use adaptive optimizers like Adam instead of plain gradient descent, and frameworks such as PyTorch and JAX compute derivatives automatically rather than requiring hand-derived formulas like grad_w.

FAQ
What is the learning rate in the example?
The learning rate is 0.01, set as a hyperparameter that controls the step size for each parameter update in gradient descent.
How many epochs does the example run?
The example runs for 1,000 epochs, meaning the full dataset is used to update the parameters 1,000 times.
Does the example use any external libraries?
No, it uses pure Python without external libraries, implementing linear regression and gradient descent from scratch.
Qiita 機械学習Read Original Article
Send on LINE

AI news that matters for your work, delivered every morning.

Pick your industry and the AI tools you use, and get news related to your work every day.

By signing up you agree to the Terms of Service and Privacy Policy.

Free · 30 seconds with Google · unsubscribe anytimeWhat is AIToday? →

Related Articles

Next articleRuxyTrace feeds brain data into Qwen2.5-7B, recovers 21 of 100 sentences