How AI & Machine Learning Actually Work

13 min read
•Venkat Nithin
AIMachine LearningDeep LearningNeural NetworksTransformers

Modern artificial intelligence can feel like a black box, but underneath the marketing jargon lies an established mathematical pipeline.

Rather than human engineers manually drafting rules for every possible edge case, machine learning algorithms iteratively optimize mathematical formulas by measuring error against historical data.

This post breaks down the structural mechanics of the machine learning training loop, how weights and biases function, and why deep neural networks superseded traditional algorithms for unstructured data.


Table of Contents


01. What is AI? Two Kinds of Automation

At its core, artificial intelligence is about automation—building machines that perform tasks that would otherwise require human intelligence.

However, software engineering automates tasks in two completely different ways:

1. Rule-Based Automation (Traditional Programming)

In traditional programming, a human engineer studies the problem, designs the logic, and writes explicit step-by-step rules using conditional statements (if/else):

if (cartTotal > 100 && userIsMember) {
  applyDiscount(0.15);
}

The computer executes the instructions quickly and reliably, but it learns nothing. It simply follows a recipe written by a human. If an input arrives that falls outside the pre-written rules, the system fails.

2. Learning-Based Automation (Machine Learning)

Machine learning is used when a human cannot write the recipe.

Instead of writing explicit rules, the programmer constructs an open mathematical framework with adjustable parameters. We supply the computer with historical data containing inputs and correct target answers, and the computer calculates its own formula.


02. The Brick Wall: Why We Can't Write Rules for Everything

Why couldn't traditional programming solve tasks like recognizing a handwritten digit "8" or identifying a cat in a photo?

Imagine trying to write explicit rules to detect a cat in an image:

if (hasPointyEars && hasWhiskers && isFurry) {
  return "Cat";
}

The real world breaks this immediately:

  • What if the cat has folded ears (like a Scottish Fold)? The rule fails.
  • What if the photo is taken in low lighting where whiskers aren't visible? The rule fails.
  • What if it is a small dog with pointy ears? The rule produces a false positive.
  • What if the cat is sleeping curled up in a ball?

An image is not a neat spreadsheet. It is a raw grid of 2,000,000 pixel color values. You can write 10,000 manual if/else conditions, and on photo #10,001 the program will still guess incorrectly. The human brain cannot write explicit rules to cover the infinite variations of the physical world.


03. Inverting the Formula: Teaching by Example

Machine learning was born by inverting the software equation:

┌────────────────────────────────────────────────────────┐
│ 1. Traditional Programming (Rules-Based)               │
│    Data + Human-Written Rules   ──>  [ Program ]  ──> Output
└────────────────────────────────────────────────────────┘

┌────────────────────────────────────────────────────────┐
│ 2. Machine Learning (Data-Driven)                      │
│    Data + Correct Answers       ──>  [ Training Loop ]  ──> The Model
└────────────────────────────────────────────────────────┘

Instead of telling the computer how to tell a cat from a dog, we feed it 100,000 photos labeled "cat" and 100,000 photos labeled "dog".

The computer runs statistical optimization across those photos to build a mathematical formula—called a Model. Once trained, you hand the model a brand-new photo it has never seen before, and its formula calculates whether the pixel values align more with a cat or a dog.


04. What is Inside a Model? Weights and Biases

When developers say a model has "parameters" or "knobs", what does that look like in computer memory?

A model is simply an array of decimal numbers stored in memory, categorized into two roles:

  1. Weights (W) — The Importance Multipliers:
    Every input feature (e.g., square footage of a house, number of bedrooms) is multiplied by a Weight:
    Contribution = Feature × Weight
    
    • If a feature is critical (like house size), its weight value is scaled up high.
    • If a feature is irrelevant noise (like the color of the front door), its weight value is driven down toward zero, silencing its effect on the output.
  2. Bias (b) — The Baseline Starting Floor:
    Bias is an additive constant independent of the inputs. Without bias, an input of zero forces the equation to predict zero:
    Prediction = (Input × Weight) + Bias
    
    In a housing cost formula, even an empty plot of land with 0 bedrooms costs money. The bias sets that realistic baseline starting floor so the calculation does not cross the origin (0, 0).

When training starts on day one, all weights and biases are initialized to random decimal values. The initial predictions are completely incorrect.


05. The 4-Step Learning Loop (Zero to One)

To systematically adjust those random numbers into an accurate formula, the computer runs an automated four-phase loop:

        ┌────────────────────────────────────────────────────────┐
        │                  1. FORWARD PASS                       │
        │         Generate prediction:  ŷ = (X * W) + b          │
        └───────────────────────────┬────────────────────────────┘
                                    │
                                    ▼
        ┌────────────────────────────────────────────────────────┐
        │                  2. LOSS COMPUTATION                   │
        │         Quantify error:  MSE = (Real Answer - Guess)²  │
        └───────────────────────────┬────────────────────────────┘
                                    │
                                    ▼
        ┌────────────────────────────────────────────────────────┐
        │                  3. BACKPROPAGATION                    │
        │         Calculate gradients via calculus chain rule    │
        └───────────────────────────┬────────────────────────────┘
                                    │
                                    ▼
        ┌────────────────────────────────────────────────────────┐
        │                  4. PARAMETER UPDATE                   │
        │         Optimizer updates:  W = W - (LR * Gradient)    │
        └───────────────────────────┬────────────────────────────┘
                                    │
                                    └─ (Cycle repeats across batches)

Phase 1: Forward Pass (The Blind Guess)

The model takes the input features (e.g., X = 2,000 sq ft) and runs them through its current numbers:

Prediction (ŷ) = (Input X × Weight W) + Bias b

Because the numbers are random on step one, the initial guess might predict that a 2,000 sq ft home costs $14.

Phase 2: Loss Function (Measuring the Error)

The system compares its guess against the real ground-truth answer from historical data (e.g., real price = $300,000):

  • For numbers (Regression): It uses Mean Squared Error (MSE):

    Loss (MSE) = (Real Answer y - Prediction ŷ)²

    Squaring the error turns negative differences positive and heavily penalizes large blunders.

  • For categories (Classification): It uses Cross-Entropy Loss, measuring the mathematical distance between predicted probability percentages and the true category.

The result is a single number: the Loss Score.

Phase 3: Backpropagation (Finding Who to Blame)

Now the computer knows it made an error. But which parameter caused it? Did it set Weight 1 too high, or Bias 2 too low?

The model passes the error backward through its equations using calculus (the Chain Rule). This computes a partial derivative for every weight (∂L/∂W) and bias (∂L/∂b):

  • This vector of derivatives is called the Gradient.
  • The gradient functions like a compass needle in memory: it indicates the direction of steepest error increase.
  • Negating the gradient tells the machine the exact direction to nudge each parameter to reduce the error.

Interactive Loss OptimizerPLAYGROUND

Adjust the Weight and Bias sliders to make the Prediction match the Target. Watch how the Loss function penalizes mistakes quadratically!

1.0
0.0
Formula:(Input × Weight) + Bias
Calculation:(10 × 1.0) + 0
Prediction (ŷ):10.0
True Target (y)85
MSE Loss Penalty5625.0

Phase 4: Parameter Optimization (The Stepped Update)

An optimization algorithm (such as Stochastic Gradient Descent or Adam) adjusts the numbers:

New Weight = Old Weight - (Learning Rate × Gradient)

The loop immediately restarts with the updated numbers, and the next guess is slightly more accurate.


06. Why Must the Computer Take Tiny Steps? (The Learning Rate)

If the gradient tells the computer which direction to turn a parameter, why not turn it all the way to the right answer in a single step?

The "Whack-A-Mole" Problem

A real dataset contains 50,000 different houses with conflicting noise. If you twist a parameter to make the prediction 100% perfect for House #1, you ruin the predictions for the other 49,999 houses!

The computer must take microscopic steps—scaled down by a tiny multiplier called the Learning Rate (typically 0.001 or 0.0001):

  • If the Learning Rate is too high, the updates overshoot the minimum and ruin the calculation.
  • If the Learning Rate is too low, training takes weeks to make meaningful progress.

With a well-tuned learning rate, all 50,000 examples slowly nudge the parameters toward a balanced middle ground that works best for the entire dataset on average.


07. Spreadsheets vs. Messy Data: Trees vs. Neural Networks

Why can't we use the same machine learning model for every problem?

Different data structures require fundamentally different operational architectures:

1. Clean Tabular Spreadsheets: Decision Trees (XGBoost)

For clean database tables (columns like Age, Salary, Credit Score, Transaction Amount), linear formulas are not always optimal.

The industry standard is Gradient-Boosted Decision Trees (like XGBoost):

  • They do not optimize continuous linear equations with backpropagation.
  • They recursively partition data into binary questions: "Is Income > 60,000? Go left. Is Credit Score > 700? Go right."
  • XGBoost builds one simple tree, checks where it made errors, and builds a second tree specifically designed to correct those errors, repeating across thousands of trees.

2. Messy Sensory Data: Deep Neural Networks

Decision trees fail completely on unstructured data like images, audio, and language. A photo has no clean columns—it is a raw grid of millions of pixel color intensities.

To process unstructured data, we use Deep Neural Networks:

  • We stack parameterized equations into sequential layers.
  • Early layers detect basic low-level features (contrasting edges, curves).
  • Middle layers combine those edges into shapes and textures (corners, circles).
  • Late layers combine shapes into complex objects (ears, eyes, faces).

In natural language processing, this layered architecture evolves into the Transformer, where parameters learn how words relate to each other across long sentences.


Conclusion

Machine learning is not magic. It is an automated numerical pipeline:

  1. Inputs pass forward through weights and biases to produce a prediction.
  2. Loss functions quantify the error against known targets.
  3. Backpropagation calculates the gradient compass via calculus.
  4. Optimizers take stepped updates to minimize error across millions of samples.

In Inside the LLM: How Inference Actually Works, we open the hood of a Transformer to see what happens when these principles scale to 70 billion parameters during real-time text generation.

Enjoyed this article?

Subscribe to get notified when I publish new content.