<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Ben Kemp</title>
    <description>The latest articles on Forem by Ben Kemp (@benkemp).</description>
    <link>https://forem.com/benkemp</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3820788%2Fb35fdc0c-9049-4ffb-b1f0-f7fb2d306636.jpg</url>
      <title>Forem: Ben Kemp</title>
      <link>https://forem.com/benkemp</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/benkemp"/>
    <language>en</language>
    <item>
      <title>Backpropagation Explained in Plain English (With a PyTorch Example)</title>
      <dc:creator>Ben Kemp</dc:creator>
      <pubDate>Fri, 13 Mar 2026 10:06:31 +0000</pubDate>
      <link>https://forem.com/benkemp/backpropagation-explained-in-plain-english-with-a-pytorch-example-595h</link>
      <guid>https://forem.com/benkemp/backpropagation-explained-in-plain-english-with-a-pytorch-example-595h</guid>
      <description>&lt;p&gt;If neural networks are powerful learning systems, backpropagation is the engine that trains them.&lt;/p&gt;

&lt;p&gt;Without &lt;a href="https://neuralnetworklexicon.com/training-and-optimization/backpropagation/" rel="noopener noreferrer"&gt;backpropagation&lt;/a&gt;, deep learning would not exist.&lt;/p&gt;

&lt;p&gt;It is the algorithm that allows neural networks to learn from mistakes, adjusting millions (or even billions) of parameters so the model gradually improves during training.&lt;/p&gt;

&lt;p&gt;In this article, we’ll explain what backpropagation is, how it works conceptually, and show a small PyTorch example.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Backpropagation?
&lt;/h2&gt;

&lt;p&gt;Backpropagation (short for backward propagation of errors) is the process used to compute how much each weight in a neural network contributed to the model’s error.&lt;/p&gt;

&lt;p&gt;The goal is simple:&lt;/p&gt;

&lt;p&gt;Determine how every parameter should change to reduce prediction error.&lt;/p&gt;

&lt;p&gt;Backpropagation works together with an optimization algorithm like gradient descent.&lt;/p&gt;

&lt;p&gt;The process looks like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The network makes a prediction.&lt;/li&gt;
&lt;li&gt;The prediction is compared to the correct answer.&lt;/li&gt;
&lt;li&gt;The error is measured using a loss function.&lt;/li&gt;
&lt;li&gt;Gradients are calculated.&lt;/li&gt;
&lt;li&gt;Model weights are updated to reduce the loss.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This cycle repeats thousands or millions of times during training.&lt;/p&gt;

&lt;p&gt;The Training Loop of Neural Networks&lt;/p&gt;

&lt;p&gt;A typical neural network training process follows these steps:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Forward Pass
&lt;/h3&gt;

&lt;p&gt;Input data flows through the network to produce a prediction.&lt;/p&gt;

&lt;p&gt;Input → Hidden Layers → Output&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Loss Calculation
&lt;/h3&gt;

&lt;p&gt;The prediction is compared to the true label.&lt;/p&gt;

&lt;p&gt;Example loss functions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mean Squared Error (MSE)&lt;/li&gt;
&lt;li&gt;Cross Entropy Loss&lt;/li&gt;
&lt;li&gt;Hinge Loss&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The result is a numerical measure of error.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Backward Pass (Backpropagation)
&lt;/h3&gt;

&lt;p&gt;The loss is propagated backward through the network.&lt;/p&gt;

&lt;p&gt;Gradients are computed for every weight.&lt;/p&gt;

&lt;p&gt;These gradients tell us:&lt;/p&gt;

&lt;p&gt;How much each parameter influenced the final error.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Weight Update
&lt;/h3&gt;

&lt;p&gt;An optimizer updates the model parameters.&lt;/p&gt;

&lt;p&gt;Example update rule (simplified):&lt;/p&gt;

&lt;p&gt;weight = weight - learning_rate * gradient&lt;/p&gt;

&lt;p&gt;Over time, these updates improve model performance.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Backpropagation Is So Important
&lt;/h3&gt;

&lt;p&gt;Before backpropagation was widely used, training multi-layer neural networks was extremely difficult.&lt;/p&gt;

&lt;p&gt;Backpropagation enabled:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;deep neural networks&lt;/li&gt;
&lt;li&gt;convolutional networks&lt;/li&gt;
&lt;li&gt;transformer models&lt;/li&gt;
&lt;li&gt;large language models&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Without it, modern AI systems like GPT-style models would not be possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Minimal PyTorch Example
&lt;/h2&gt;

&lt;p&gt;Let’s train a tiny neural network using backpropagation.&lt;/p&gt;

&lt;p&gt;import torch&lt;br&gt;
import torch.nn as nn&lt;br&gt;
import torch.optim as optim&lt;/p&gt;

&lt;h1&gt;
  
  
  Simple neural network
&lt;/h1&gt;

&lt;p&gt;model = nn.Sequential(&lt;br&gt;
    nn.Linear(2, 8),&lt;br&gt;
    nn.ReLU(),&lt;br&gt;
    nn.Linear(8, 1)&lt;br&gt;
)&lt;/p&gt;

&lt;h1&gt;
  
  
  Example dataset
&lt;/h1&gt;

&lt;p&gt;X = torch.tensor([[0.,0.],&lt;br&gt;
                  [0.,1.],&lt;br&gt;
                  [1.,0.],&lt;br&gt;
                  [1.,1.]])&lt;/p&gt;

&lt;p&gt;y = torch.tensor([[0.],&lt;br&gt;
                  [1.],&lt;br&gt;
                  [1.],&lt;br&gt;
                  [0.]])&lt;/p&gt;

&lt;h1&gt;
  
  
  Loss function
&lt;/h1&gt;

&lt;p&gt;criterion = nn.MSELoss()&lt;/p&gt;

&lt;h1&gt;
  
  
  Optimizer
&lt;/h1&gt;

&lt;p&gt;optimizer = optim.Adam(model.parameters(), lr=0.01)&lt;/p&gt;

&lt;h1&gt;
  
  
  Training loop
&lt;/h1&gt;

&lt;p&gt;for epoch in range(1000):&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;predictions = model(X)

loss = criterion(predictions, y)

optimizer.zero_grad()

loss.backward()

optimizer.step()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;print("Final loss:", loss.item())&lt;/p&gt;

&lt;p&gt;What Happens When loss.backward() Runs?&lt;/p&gt;

&lt;p&gt;This single line triggers the entire backpropagation process.&lt;/p&gt;

&lt;p&gt;PyTorch automatically:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Computes gradients for each parameter.&lt;/li&gt;
&lt;li&gt;Applies the chain rule from calculus.&lt;/li&gt;
&lt;li&gt;Propagates gradients backward through all layers.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These gradients are then used by the optimizer to update model weights.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Chain Rule Behind Backpropagation
&lt;/h3&gt;

&lt;p&gt;Backpropagation relies on the chain rule from calculus.&lt;/p&gt;

&lt;p&gt;If a function depends on intermediate variables, the chain rule lets us compute the gradient step by step.&lt;/p&gt;

&lt;p&gt;Example conceptually:&lt;/p&gt;

&lt;p&gt;Loss → Output → Hidden Layer → Input&lt;/p&gt;

&lt;p&gt;Gradients flow backward through the network, adjusting weights based on their contribution to the final error.&lt;/p&gt;

&lt;h3&gt;
  
  
  Backpropagation in Large AI Models
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Even the largest modern AI systems still rely on this same principle.&lt;/li&gt;
&lt;li&gt;Training models like large language models involves:&lt;/li&gt;
&lt;li&gt;trillions of gradient updates&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;massive datasets&lt;/p&gt;

&lt;p&gt;distributed GPU training&lt;/p&gt;

&lt;p&gt;But at the core, the algorithm is still backpropagation combined with gradient descent.&lt;/p&gt;

&lt;h3&gt;
  
  
  Related Neural Network Concepts
&lt;/h3&gt;

&lt;p&gt;Backpropagation is closely connected to several other key ideas:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Gradient Descent&lt;/li&gt;
&lt;li&gt;Loss Functions&lt;/li&gt;
&lt;li&gt;Optimization Algorithms&lt;/li&gt;
&lt;li&gt;Vanishing Gradients&lt;/li&gt;
&lt;li&gt;Training Stability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Understanding these concepts helps explain how modern deep learning systems are trained.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Backpropagation is one of the most important algorithms in machine learning.&lt;/p&gt;

&lt;p&gt;It allows neural networks to learn from data by gradually improving their internal parameters.&lt;/p&gt;

&lt;p&gt;Every modern deep learning system—from image recognition models to large language models—depends on this simple but powerful idea.&lt;/p&gt;

&lt;p&gt;If you understand backpropagation, you understand the core mechanism that trains neural networks.&lt;/p&gt;

&lt;p&gt;This article is part of the &lt;a href="https://neuralnetworklexicon.com/" rel="noopener noreferrer"&gt;Neural Network Lexicon project&lt;/a&gt;, a growing resource explaining the most important concepts behind modern AI systems.&lt;/p&gt;

</description>
      <category>ai</category>
    </item>
    <item>
      <title>Understanding Representation Learning in Neural Networks (With PyTorch Example)</title>
      <dc:creator>Ben Kemp</dc:creator>
      <pubDate>Thu, 12 Mar 2026 17:22:16 +0000</pubDate>
      <link>https://forem.com/benkemp/understanding-representation-learning-in-neural-networks-with-pytorch-example-2560</link>
      <guid>https://forem.com/benkemp/understanding-representation-learning-in-neural-networks-with-pytorch-example-2560</guid>
      <description>&lt;p&gt;Deep learning systems are powerful because they learn representations of data automatically.&lt;/p&gt;

&lt;p&gt;Instead of engineers manually designing features, neural networks discover patterns on their own during training. This capability is known as representation learning, and it is one of the core reasons why modern AI models outperform traditional machine learning approaches.&lt;/p&gt;

&lt;p&gt;From image recognition to large language models, representation learning is the engine behind many breakthroughs in artificial intelligence.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Is Representation Learning?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://neuralnetworklexicon.com/architecture-and-representation/representation-learning/" rel="noopener noreferrer"&gt;Representation learning&lt;/a&gt; refers to a model’s ability to transform raw input data into meaningful internal features that help solve a task.&lt;/p&gt;

&lt;p&gt;Traditional machine learning often relied on manually engineered features.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;Problem --- Traditional Features --- Learned Representations&lt;/p&gt;

&lt;p&gt;Image classification --- edges, color histograms --- hierarchical visual features&lt;br&gt;
Speech recognition ---  handcrafted audio features ---  learned phoneme patterns&lt;br&gt;
NLP --- bag-of-words --- contextual embeddings&lt;/p&gt;

&lt;p&gt;Deep neural networks learn these representations automatically through training.&lt;/p&gt;

&lt;p&gt;Each layer transforms the input data into a more abstract representation.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Representations Emerge in Deep Networks
&lt;/h2&gt;

&lt;p&gt;Neural networks process information through multiple layers.&lt;/p&gt;

&lt;p&gt;Each layer applies transformations that progressively refine the data representation.&lt;/p&gt;

&lt;p&gt;For example in computer vision:&lt;/p&gt;

&lt;p&gt;Layer progression might look like:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Edges&lt;/li&gt;
&lt;li&gt;Textures&lt;/li&gt;
&lt;li&gt;Object parts&lt;/li&gt;
&lt;li&gt;Complete objects&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The deeper the network, the more abstract the representation becomes.&lt;/p&gt;

&lt;p&gt;This hierarchical structure is why deep neural networks are effective at modeling complex patterns.&lt;/p&gt;

&lt;h2&gt;
  
  
  Representation Learning in Modern AI
&lt;/h2&gt;

&lt;p&gt;Representation learning plays a major role in several key AI technologies.&lt;/p&gt;

&lt;h3&gt;
  
  
  Computer Vision
&lt;/h3&gt;

&lt;p&gt;Convolutional neural networks learn spatial features from raw pixel data.&lt;/p&gt;

&lt;h3&gt;
  
  
  Natural Language Processing
&lt;/h3&gt;

&lt;p&gt;Transformer models learn contextual token representations.&lt;/p&gt;

&lt;h3&gt;
  
  
  Recommendation Systems
&lt;/h3&gt;

&lt;p&gt;User behavior patterns are encoded into latent feature vectors.&lt;/p&gt;

&lt;h3&gt;
  
  
  Speech Recognition
&lt;/h3&gt;

&lt;p&gt;Acoustic signals are transformed into linguistic representations.&lt;/p&gt;

&lt;p&gt;These internal representations allow neural networks to generalize beyond the training data.&lt;/p&gt;

&lt;h2&gt;
  
  
  A Simple PyTorch Example
&lt;/h2&gt;

&lt;p&gt;Below is a minimal neural network demonstrating how hidden layers transform input data into internal representations.&lt;/p&gt;

&lt;p&gt;import torch&lt;br&gt;
import torch.nn as nn&lt;/p&gt;

&lt;p&gt;class SimpleRepresentationNet(nn.Module):&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def __init__(self):
    super().__init__()
    self.layer1 = nn.Linear(10, 32)
    self.layer2 = nn.Linear(32, 16)
    self.output = nn.Linear(16, 2)

def forward(self, x):
    x = torch.relu(self.layer1(x))
    x = torch.relu(self.layer2(x))
    return self.output(x)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;model = SimpleRepresentationNet()&lt;/p&gt;

&lt;h1&gt;
  
  
  Example input
&lt;/h1&gt;

&lt;p&gt;x = torch.randn(1, 10)&lt;/p&gt;

&lt;h1&gt;
  
  
  Forward pass
&lt;/h1&gt;

&lt;p&gt;prediction = model(x)&lt;/p&gt;

&lt;p&gt;print(prediction)&lt;/p&gt;

&lt;h2&gt;
  
  
  What Happens Inside the Network?
&lt;/h2&gt;

&lt;p&gt;The layers progressively transform the input:&lt;/p&gt;

&lt;p&gt;Layer   Transformation&lt;br&gt;
Input   Raw numeric features&lt;br&gt;
Layer 1 First learned representation&lt;br&gt;
Layer 2 Higher-level abstraction&lt;br&gt;
Output  Task prediction&lt;/p&gt;

&lt;p&gt;During training, the network learns which representations best solve the task.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Representation Learning Matters
&lt;/h2&gt;

&lt;p&gt;Representation learning solved one of the biggest problems in classical machine learning: feature engineering.&lt;/p&gt;

&lt;p&gt;Previously, performance depended heavily on manually designed features.&lt;/p&gt;

&lt;p&gt;Deep learning changed this paradigm.&lt;/p&gt;

&lt;p&gt;Now models can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;discover patterns automatically&lt;/li&gt;
&lt;li&gt;build hierarchical abstractions&lt;/li&gt;
&lt;li&gt;adapt to complex data distributions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is why deep learning works so well in areas like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;computer vision&lt;/li&gt;
&lt;li&gt;speech recognition&lt;/li&gt;
&lt;li&gt;natural language processing&lt;/li&gt;
&lt;li&gt;generative AI&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Representation Learning in Large Language Models
&lt;/h2&gt;

&lt;p&gt;Large language models rely heavily on representation learning.&lt;/p&gt;

&lt;p&gt;The process typically looks like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tokens are converted into embeddings&lt;/li&gt;
&lt;li&gt;Attention layers refine contextual relationships&lt;/li&gt;
&lt;li&gt;Hidden states become rich semantic representations&lt;/li&gt;
&lt;li&gt;Output layers convert these representations into predictions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This allows models to understand relationships like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;semantic similarity&lt;/li&gt;
&lt;li&gt;syntax&lt;/li&gt;
&lt;li&gt;context dependencies&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All without explicit feature engineering.&lt;/p&gt;

&lt;h2&gt;
  
  
  Related Neural Network Concepts
&lt;/h2&gt;

&lt;p&gt;Representation learning connects to several other important deep learning ideas:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://neuralnetworklexicon.com/architecture-and-representation/feature-learning/" rel="noopener noreferrer"&gt;Feature Learning&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://neuralnetworklexicon.com/architecture-and-representation/embeddings/" rel="noopener noreferrer"&gt;Embeddings&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Latent Representations&lt;/li&gt;
&lt;li&gt;Transformer Attention&lt;/li&gt;
&lt;li&gt;Self-Supervised Learning&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Together these form the foundation of modern AI architectures.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Representation learning is one of the key innovations that enabled modern deep learning.&lt;/p&gt;

&lt;p&gt;By allowing models to discover meaningful features automatically, neural networks can scale to complex tasks and large datasets.&lt;/p&gt;

&lt;p&gt;Whether you are building computer vision systems, training language models, or developing recommendation engines, understanding representation learning is essential.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>machinelearning</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
