TechByteByByte

Types of Machine Learning

Understand supervised, unsupervised, self-supervised, and reinforcement learning, why modern LLMs rely heavily on self-supervised learning, and where reinforcement learning appears in modern AI systems.

#Machine Learning#AI#Supervised Learning#Self-Supervised Learning#Reinforcement Learning#LLMs

Begin with the central question

What changes when the teacher gives answers, gives no answers, or gives only rewards?

This question explains why Types of Machine Learning deserves its own lesson. Each definition, calculation, and code example below will answer a specific part of it.

labeled examples → supervised | unlabeled examples → unsupervised | actions + rewards → reinforcement learning

Before you continue: three tools for this module

  • Label: the expected answer attached to an example.
  • Cluster: a group discovered from similarity rather than provided labels.
  • Reward: a score telling an agent how useful an action was.

You do not need to memorize these yet. Return to this small map whenever a term reappears.


What You Will Understand

  • Five ML Categories: Understand the core differences and use cases for supervised, unsupervised, semi-supervised, self-supervised, and reinforcement learning.
  • Modern LLM Training: Discover why base LLMs commonly learn general language ability through self-supervised next-token prediction, and why later alignment may use supervised instruction tuning, RLHF, DPO, or a combination of methods rather than reinforcement learning alone.
  • Algorithmic Selection: Build a strong foundation for choosing the right learning paradigm based on the availability and nature of your data.

The learning type depends on the feedback available:

correct answers available? ── yes ─→ supervised learning

          no

structure hidden in data? ─────────→ unsupervised learning
data creates its own target? ──────→ self-supervised learning
actions receive rewards over time? → reinforcement learning

These categories describe the training signal, not how intelligent or advanced the final application appears.


Why Several Learning Types Exist

Module 1 assumed you always have labeled data (a feature paired with a known-correct answer). In reality:

  • Sometimes you have labels for everything (supervised).
  • Sometimes you have no labels at all (unsupervised).
  • Sometimes labeling is too expensive to do for all your data, but you have a little (semi-supervised).
  • Sometimes the data can generate its own labels, with no human needed at all (self-supervised) — this turns out to be the key that unlocked LLMs.
  • Sometimes there’s no fixed “correct answer” at all — just a reward signal for good or bad behavior over time (reinforcement learning).

Each type exists because real-world data doesn’t always arrive in the tidy “input, correct output” shape supervised learning needs.


Five Ways a Student Can Learn

Think of five different ways to learn a new skill:

  • Supervised = a teacher grades every practice problem you do, with the correct answer explained each time.
  • Unsupervised = you’re handed a huge pile of unlabeled photos and asked to sort them into groups that “feel similar” — nobody tells you the correct groups.
  • Semi-supervised = the teacher grades your first 10 problems, then you’re on your own for the remaining 1000 — you use the graded ones to guess at patterns for the rest.
  • Self-supervised = you cover up random words in a book and quiz yourself on what word is missing, using the rest of the sentence as the only hint. No teacher required — the text grades itself.
  • Reinforcement learning = you learn a video game by playing it repeatedly, getting points for good moves and losing points for bad ones, gradually learning a strategy — with nobody ever telling you the single “correct” move for every situation.

4. Core Concept

Supervised Learning

Every training example has a known, correct label. The model learns to map inputs to outputs by minimizing the gap between its predictions and the true labels.

Input (features)  →  Model  →  Prediction

                          compared against

                             True Label
  • Problem it solves: “Given this input, predict this specific known kind of output.”
  • Examples: spam detection, house price prediction, image classification, sentiment analysis.

Unsupervised Learning

No labels at all. The model looks for structure, patterns, or groupings in the data on its own.

  • Problem it solves: “What structure exists in this data that I don’t already know about?”
  • Examples: customer segmentation, anomaly detection, topic discovery, clustering similar documents (Module 11).

Semi-Supervised Learning

A small amount of labeled data combined with a large amount of unlabeled data — the model uses the labeled portion to guide how it interprets the unlabeled portion.

  • Problem it solves: “Labeling everything is too expensive, but I have a little labeled data to work with.”
  • Examples: medical imaging (few labeled scans, many unlabeled ones), early-stage fraud detection systems.

Self-Supervised Learning

The data generates its own labels — no human labeling needed at all. A portion of the input itself is hidden, and the model is trained to predict it from the rest.

  • Problem it solves: “I have enormous amounts of raw, unlabeled text (or images, or audio) and need a way to learn from it anyway.”
  • Examples: predicting the next word in a sentence, predicting a masked word, predicting the next frame in a video.

This is the single most important type of learning for this entire course to understand deeply — see Section 10.

Reinforcement Learning (RL)

An agent takes actions in an environment, receiving rewards or penalties, and learns a strategy (policy) that maximizes reward over time. There’s no fixed “correct answer” per input — only feedback on outcomes.

  • Problem it solves: “I need to learn a sequence of decisions, where the quality of a decision often can only be judged much later.”
  • Examples: game-playing agents, robotics, recommendation systems that optimize long-term engagement, and — very relevant here — fine-tuning LLMs with human feedback (RLHF).

5. How It Works — Step by Step

Supervised:

1. Collect labeled examples (input, correct output)
2. Model predicts an output for each input
3. Compare prediction to true label → compute loss (Module 13)
4. Adjust parameters to reduce loss
5. Repeat until performance is good on unseen data

Unsupervised (e.g., clustering):

1. Collect unlabeled examples
2. Model groups similar examples together based on feature similarity
3. No "correct answer" to compare against — success is judged by
   how coherent/useful the discovered groups are

Self-supervised (e.g., next-word prediction):

1. Take a huge amount of raw, naturally-occurring text
2. Automatically construct a supervised-style task from it:
   e.g., hide the last word of a sentence, use the rest as input,
   the hidden word becomes the "label" — generated with zero human effort
3. Train exactly like supervised learning, but the labels were
   manufactured from the data itself
4. Repeat across billions of sentences

Reinforcement learning:

1. Agent observes the current state of the environment
2. Agent takes an action based on its current policy
3. Environment returns a reward (or penalty) and a new state
4. Agent updates its policy to favor actions that led to higher reward
5. Repeat over many episodes until the policy performs well

6. Mathematical Intuition

Read the mathematics as a story

labeled examples → supervised | unlabeled examples → unsupervised | actions + rewards → reinforcement learning

First identify the input, the operation, and the output. Then read the symbols as a shorter way to describe that same journey; do not begin by memorizing the formula.

You don’t need new math beyond Module 1 to understand what’s different across these types — the difference is entirely about where the label comes from, not the underlying training loop.

  • Supervised: label = provided by a human or existing record.
  • Self-supervised: label = automatically extracted from the data itself (e.g., “the actual next word” is just… the next word in the original text — free, no human involved).
  • Unsupervised: no label at all — the “loss” being minimized instead measures something like how tightly grouped similar points are (Module 11 covers this concretely with K-Means).
  • Reinforcement learning: no per-example label — instead, a reward signal R is used, and the model adjusts its policy to maximize expected total future reward, not to match a single correct answer.

7. Small Worked Example

Walk through the example

  1. Identify what each input number represents.
  2. Follow one operation at a time and keep the units or class meanings attached.
  3. Translate the result back into an ordinary sentence about the original problem.

The goal is not merely to obtain the answer; it is to expose the model’s decision process.

Self-supervised, worked by hand:

Take the sentence: "The capital of France is Paris"

A self-supervised training example is automatically constructed:

  • Input: "The capital of France is ___"
  • Label: "Paris" (just the actual next word — no human wrote this label; it was already sitting right there in the original sentence)

Now imagine doing this for every sentence in the entire internet: every single sentence becomes many free (input, label) training pairs, with zero manual labeling work. This is, at its core, exactly how base LLMs are pretrained (see Section 10).


8. Python Example

What the code will demonstrate

The following Types of Machine Learning code turns the worked example into an experiment you can repeat. First predict the result; then prepare the small dataset, apply the technique, inspect the important intermediate values, and compare the actual output with your prediction.

Python and library symbols used below

  • NumPy (np) stores and calculates with numeric arrays.
  • pandas (pd) represents table-shaped data when it is used.
  • scikit-learn provides tested implementations with a consistent .fit(...) and .predict(...) workflow.
# Build a small, inspectable example of Types of Machine Learning.
# Follow the data, learned values, predictions, and evaluation in order.
from sklearn.cluster import KMeans
from sklearn.linear_model import LogisticRegression
import numpy as np

# ---- Supervised example: predicting spam (0) vs not spam (1) ----
# features: [num_links, has_urgent_keyword]
X_supervised = np.array([[5, 1], [0, 0], [8, 1], [1, 0]])
y_supervised = np.array([1, 0, 1, 0])  # 1 = spam, 0 = not spam (LABELS provided)

clf = LogisticRegression()
clf.fit(X_supervised, y_supervised)   # needs labels
print("Supervised prediction:", clf.predict([[6, 1]]))

# ---- Unsupervised example: grouping customers, no labels at all ----
X_unsupervised = np.array([[20, 1], [22, 1], [70, 10], [75, 12]])
# no y at all — there is nothing to label here

kmeans = KMeans(n_clusters=2, n_init=10, random_state=42)
kmeans.fit(X_unsupervised)            # NO labels used
print("Unsupervised cluster assignments:", kmeans.labels_)

Expected Output (approximate):

Supervised prediction: [1]
Unsupervised cluster assignments: [0 0 1 1]

How It Works

  • LogisticRegression.fit(X, y) requires y — the true labels — this is supervised learning, exactly as in Module 1.
  • KMeans.fit(X) takes no label argument at all — it discovers structure (two natural groups of customers) purely from the feature values themselves, which is the defining trait of unsupervised learning.

9. Real-World Example

A streaming platform wants to (a) predict whether a user will cancel their subscription, and (b) discover natural viewer segments for content recommendations.

  • Task (a) is supervised: historical data already has the true label (did this specific past user actually cancel or not) — train a classifier on it.
  • Task (b) is unsupervised: there’s no “correct” segment label for any user — clustering (Module 11) is used to discover groups (e.g., “binge watchers,” “weekend viewers”) that weren’t predefined by anyone.

The same company, same data, two different problem shapes — and two different types of ML applied appropriately to each.


10. How This Is Used in AI

From mechanism to product

Modern AI systems combine learning styles: LLM pretraining is largely self-supervised, preference optimization uses human or model feedback, and application behavior may include non-learning rules.

How this connects to LLMs

request → data or context preparation → model computation → evaluated output

An LLM may use this idea during training, or an AI application may use a separate ML component around the LLM. Those are different locations in the system, and the explanation below identifies which one applies.

🤖 Why modern LLMs rely heavily on self-supervised learning

This is the single most important connection in this module.

Training a supervised model to “understand language” would require humans to manually label an almost unimaginable volume of text — utterly impractical at internet scale. Self-supervised learning sidesteps this entirely: the next word in any naturally occurring sentence is already, for free, a perfectly valid label. No human labeling effort required, at any scale.

Raw internet text (no labels needed)

Automatically construct millions/billions of
"predict the next token" training examples

Train a massive model on this self-generated task

Base LLM — has learned grammar, facts, reasoning patterns,
and world knowledge, purely as a side effect of getting
extremely good at "predict the next word"

This is exactly how GPT-style and Claude-style base models are pretrained — “self-supervised” is not a side detail, it is the foundational training paradigm of modern LLMs.

🤖 Where reinforcement learning appears in modern AI

After self-supervised pretraining produces a base model that predicts plausible next-tokens, that base model is often not yet well-aligned with what makes a response genuinely helpful, honest, and safe. This is where reinforcement learning enters:

  • RLHF (Reinforcement Learning from Human Feedback): humans rank multiple model responses; a reward model is trained to predict those rankings; the LLM is then fine-tuned using RL to produce responses the reward model scores highly. This is a major part of how base LLMs become helpful, aligned chat assistants.
  • RL also appears in agent systems that learn from trial-and-error feedback over multiple steps (e.g., an agent learning which tool-use strategies lead to successful task completion over many attempts).
StageLearning type used
Base LLM pretrainingSelf-supervised learning (next-token prediction)
Instruction tuningSupervised learning (human-written example responses)
Alignment / RLHFReinforcement learning
Small classifiers inside an AI pipeline (e.g., intent routing)Usually supervised learning
Discovering topics/clusters in a document setUnsupervised learning

11. How This Is Used in Agentic AI

Trace one agent step

goal + state → model proposes → runtime validates → tool or response → evaluation

The model produces a prediction or proposal. The agent runtime is ordinary software that manages tools, permissions, state, retries, and execution; it may use this ML concept directly, indirectly through an LLM, or not at all.

🤖 Agentic AI systems often combine multiple learning types within a single pipeline:

  • The core LLM reasoning the agent relies on was self-supervised pretrained, then RL-aligned.
  • A supervised classifier might decide which tool category a user request falls into, before the LLM ever reasons about it (cheaper and faster than asking the LLM to classify every time).
  • Unsupervised clustering might group past agent conversations to discover common failure patterns worth addressing.
  • Some advanced agent training setups use reinforcement learning directly — rewarding an agent for successfully completing multi-step tasks, penalizing wasted or harmful tool calls.

Recognizing which learning type underlies each component helps you reason about why a piece of an agent system behaves the way it does — e.g., an RL-trained component’s behavior is shaped by a reward signal and may behave unexpectedly on reward edge cases, differently from a supervised component that simply mimics labeled examples.


12. Common Beginner Mistakes

⚠️ Mistake

Incorrect idea: Assuming LLMs are trained the same way as a typical supervised classifier

Why it is incorrect: They are not, at the base-model stage. An LLM’s pretraining is self-supervised (next-token prediction on raw text); labeled human data enters later, during instruction-tuning and RLHF — a very different, later, comparatively much smaller stage.

⚠️ Mistake

Incorrect idea: Treating “unsupervised” as meaning “no correctness at all.”

Why it is incorrect: Unsupervised models still have an internal objective (e.g., minimize distance within a cluster) — there’s just no externally-provided label being matched. “No labels” ≠ “no objective.”

⚠️ Mistake

Incorrect idea: Confusing self-supervised with unsupervised

Why it is incorrect: They’re often lumped together casually, but they’re meaningfully different: self-supervised learning does use labels — it just generates them automatically from the data, rather than a human providing them. It’s trained with the same “predict the correct answer” mechanics as supervised learning; unsupervised learning has no such target at all.


13. Important Distinctions

TypeNeeds labels?Where labels come from
SupervisedYesProvided by humans / existing records
UnsupervisedNoN/A — no labels used
Semi-supervisedPartiallyA small human-labeled subset
Self-supervisedYes (technically)Automatically generated from the data itself
Reinforcement learningNo fixed labelsA reward signal, given after actions
Supervised LearningReinforcement Learning
Learns from a fixed dataset of (input, correct output) pairsLearns by interacting with an environment over time
Feedback is immediate and precise (the true label)Feedback (reward) can be delayed and less precise
Goal: match known correct answersGoal: maximize long-term cumulative reward

14. When Should You Use This?

  • Supervised: you have (or can obtain) reliable labels, and the task is “predict this specific known kind of output.”
  • Unsupervised: you want to explore/discover structure in data with no predefined correct answer (segmentation, anomaly detection).
  • Semi-supervised: labeling is expensive, but you can afford to label a meaningful subset.
  • Self-supervised: you have huge volumes of raw, unlabeled data (text, images, audio) and want to learn general-purpose representations from it without manual labeling.
  • Reinforcement learning: the problem is inherently sequential decision-making, where good outcomes may only become clear after many steps, and there’s a meaningful way to define a reward signal.

15. When Should You NOT Use This?

  • Don’t force supervised learning onto a problem where you have no labels and no realistic way to obtain them cheaply.
  • Don’t reach for reinforcement learning just because it sounds advanced — it’s notoriously data-hungry, unstable to train, and often massive overkill for problems a simple supervised classifier would solve more reliably and cheaply.
  • Don’t assume unsupervised clustering will discover groupings that are automatically meaningful to your business — the clusters it finds are mathematically coherent, not necessarily aligned with categories a human would find useful, and often need human interpretation afterward.

16. Production Considerations

  • Self-supervised pretraining is extraordinarily resource-intensive (this is why only a handful of organizations train foundation LLMs from scratch) — most AI engineers will use pretrained models rather than train one.
  • Supervised fine-tuning / small classifiers are far more approachable for an individual team — realistic to train, retrain, and maintain in-house.
  • RL-based systems need careful reward design — a poorly specified reward function can cause a model to “win” by exploiting the reward signal in unintended ways (a real, well-documented failure mode called reward hacking), rather than actually solving the intended problem.

17. AI Engineer Takeaway

🎯 AI Engineer Takeaway: The type of learning a system uses is determined entirely by what kind of feedback is available — a known correct answer (supervised), no feedback at all beyond structure in the data (unsupervised), self-generated correct answers from raw data (self-supervised), or a delayed reward signal (reinforcement learning).

Modern LLMs exist because self-supervised learning made it possible to learn from the internet’s raw text at massive scale without human labeling — and RL (via RLHF) is what turns a raw next-token predictor into a genuinely helpful assistant.


18. Interview Questions

Basic Questions

Q: What’s the difference between supervised and unsupervised learning?

A: Supervised learning trains on data where every example has a known, correct label, and the model learns to predict that label for new inputs. Unsupervised learning has no labels at all — the model instead looks for structure or patterns (like natural groupings) within the data itself.

Q: What is self-supervised learning, and how is it different from unsupervised learning?

A: Self-supervised learning automatically generates its own labels directly from the data — for example, hiding a word in a sentence and using the rest of the sentence to predict it, where the “hidden word” is itself a label extracted for free from raw text. It’s trained just like supervised learning (predicting toward a specific correct answer), but that answer was never provided by a human. Unsupervised learning, by contrast, has no correct-answer target of any kind to predict toward.

Q: What is reinforcement learning, briefly?

A: A learning approach where an agent takes actions in an environment and receives rewards or penalties as feedback, gradually learning a strategy (policy) that maximizes long-term reward — rather than learning to match a single, fixed correct answer per input, as in supervised learning.

Intermediate Questions

Q: Why couldn’t LLMs realistically be trained using only supervised learning?

A: Supervised learning would require humans to manually label a volume of text data that simply isn’t feasible to produce — LLMs are pretrained on a meaningful fraction of the internet’s text. Self-supervised learning solves this by turning raw, already-existing text into training examples automatically: the “next actual word” in any sentence is a free, human-effort-free label. This is precisely why self-supervised learning is the foundation of LLM pretraining, with (far smaller-scale) supervised learning and reinforcement learning applied afterward for instruction tuning and alignment.

Q: Where does reinforcement learning fit into how a chat-style LLM like ChatGPT or Claude is actually built?

A: After self-supervised pretraining produces a base model that can predict plausible next tokens but isn’t necessarily helpful, honest, or safe by default, RLHF (Reinforcement Learning from Human Feedback) is used: humans rank multiple candidate responses, a reward model is trained to predict those human preferences, and the base LLM is then fine-tuned via reinforcement learning to produce outputs the reward model rates highly. This is a distinct, later stage from pretraining, layered on top of it.

Scenario-Based Questions

Q: Your company has 50 million unlabeled support tickets and wants to build a system to automatically route tickets to the right team. You have budget to manually label only about 2,000 tickets. What learning approach would you propose, and why?

A: Thought process: Fully supervised learning on the entire 50 million would require labeling all of it — not feasible with this budget. Fully unsupervised clustering wouldn’t guarantee the discovered groups align with your actual team structure. This is a textbook case for a middle path.

Investigation: With 2,000 labeled examples, semi-supervised learning is a strong fit — train an initial model on the labeled subset, then use it (often combined with clustering or self-training techniques) to leverage the much larger unlabeled pool. Alternatively — increasingly common and often simpler in practice today — an LLM could be used with few-shot prompting or lightly fine-tuned on just the 2,000 labeled examples, sidestepping the need to build a semi-supervised pipeline from scratch.

Correct answer: Recommend either a semi-supervised approach, or (more practically for most teams today) fine-tuning/prompting a pretrained LLM using the 2,000 labeled examples as few-shot examples or a small fine-tuning set — leaning on the LLM’s already-strong self-supervised pretraining rather than trying to learn ticket routing entirely from scratch.

Production consideration: Whichever approach is chosen, plan for ongoing labeling of a small, steady stream of new tickets — both to monitor accuracy over time and to catch data drift (Module 21) as ticket topics and team structures evolve.


Next: Module 03 — Data, Features and Labels — dataset quality, feature engineering, and why “garbage in, garbage out” is especially unforgiving in ML.

Author
TechByteByByte Editorial Team
Reviewed by
TechByteByByte Admin
Published
Last reviewed