Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
title: "Reinforcement Learning: Learning through Action"
sidebar_label: Reinforcement Learning
description: "Understanding the Agent-Environment loop, reward signals, and how AI learns to make optimal decisions in dynamic systems."
tags: [machine-learning, reinforcement-learning, robotics, q-learning, autonomous-systems]
---

**Reinforcement Learning (RL)** is a type of machine learning where an **Agent** learns to make decisions by performing actions in an **Environment** to maximize a cumulative **Reward**.

Unlike Supervised Learning, where the model is told the "correct" answer, an RL agent learns from the consequences of its actions. It is a process of trial and error, much like how a human learns to ride a bicycle or how a dog is trained with treats.

## 1. The Core Components

To understand RL, you must understand the five pillars of the "RL Loop":

1. **The Agent:** The AI "learner" or decision-maker (e.g., a self-driving car software).
2. **The Environment:** The world the agent interacts with (e.g., the road and traffic).
3. **State ($S$):** The current situation of the agent (e.g., the car's current speed and position).
4. **Action ($A$):** What the agent does (e.g., steer left, brake, or accelerate).
5. **Reward ($R$):** Feedback from the environment (e.g., $+10$ points for reaching the destination, $-100$ for a collision).

## 2. The Learning Loop

The process is continuous and follows a cycle:

```mermaid
graph TD
A[Agent] -->|Action| E[Environment]
E -->|Reward| A
E -->|New State| A

style A fill:#e1f5fe,stroke:#01579b,color:#333
style E fill:#f3e5f5,stroke:#7b1fa2,color:#333

```

1. The Agent observes the current **State**.
2. The Agent selects an **Action** based on its "Policy" (strategy).
3. The **Environment** changes in response to the action.
4. The Agent receives a **Reward** or penalty.
5. The Agent updates its strategy to prioritize actions that led to rewards.

## 3. Exploration vs. Exploitation

This is the most famous dilemma in Reinforcement Learning:

* **Exploitation:** The agent performs the action it *knows* gives the highest reward. (e.g., going to your favorite restaurant).
* **Exploration:** The agent tries a *new* action to see if it leads to an even better reward. (e.g., trying a new restaurant that might be better or worse).

An effective RL agent must find the perfect balance: exploring early to find high-value strategies and exploiting later to maximize "points."

## 4. Key Concepts: Policy and Value

* **Policy ():** The agent's "brain" or strategy. It defines which action to take in a given state.
* **Value Function ():** The agent's prediction of the *total future reward* it will get from its current state.

$$
G_t = R_{t+1} + \gamma R_{t+2} + \gamma^2 R_{t+3} + ...
$$

*In the formula above, (gamma) is the **discount factor**, which determines how much the agent cares about immediate rewards vs. long-term rewards.*

## 5. Real-World Applications

| Industry | RL Use Case |
| --- | --- |
| **Gaming** | Training AI to beat world champions in Chess, Go, or StarCraft II. |
| **Robotics** | Teaching a robotic arm to pick up fragile objects without breaking them. |
| **Finance** | Algorithmic trading where the agent learns when to buy/sell for max profit. |
| **Healthcare** | Optimizing treatment plans for chronic diseases based on patient reactions. |
| **NLP** | **RLHF** (Reinforcement Learning from Human Feedback)—used to make models like ChatGPT more helpful and safe. |

## 6. Comparison Table

| Feature | Supervised | Unsupervised | Reinforcement |
| --- | --- | --- | --- |
| **Goal** | Mapping | Finding clusters | Maximize rewards |
| **Data** | Labeled | Unlabeled | Interactions/Feedback |
| **Learning** | Passive | Passive | **Active/Interactive** |

## References for More Details

* **[OpenAI Spinning Up in RL](https://spinningup.openai.com/en/latest/):** Practical implementation and code for modern RL algorithms.

---

**You have now explored all the major branches of Machine Learning! You know how models learn from labels, patterns, themselves, and rewards. Now, it's time to learn how to measure if these models are actually doing a good job.**
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
title: "Self-Supervised Learning: The Engine of Modern AI"
sidebar_label: "Self-Supervised Learning"
description: "How AI learns by predicting missing parts of its own input, powering Large Language Models and Computer Vision."
tags: [machine-learning, self-supervised-learning, llm, bert, computer-vision, deep-learning]
---

**Self-Supervised Learning (SSL)** is a paradigm where the model generates its own labels from the data itself. It eliminates the "bottleneck" of human labeling by hiding part of the input and asking the model to predict it.

If Supervised Learning is "Learning with a teacher," and Unsupervised Learning is "Learning alone," Self-Supervised Learning is **"Learning by solving puzzles."**

## 1. How it Works: The Pretext Task

In SSL, we create a **Pretext Task** a synthetic challenge where the "ground truth" is already contained within the data.

### A. In Natural Language Processing (NLP)
This is how models like GPT and BERT are trained. We take a normal sentence and hide words:
* **Original:** "The cat sat on the mat."
* **Input:** "The cat [MASK] on the mat."
* **Target:** "sat"

By predicting the masked word, the model forcedly learns grammar, context, and even world facts.

### B. In Computer Vision
We can take an image and modify it to create a puzzle for the model:
* **Rotation Prediction:** Rotate an image by 90° and ask the model "What is the orientation?" To answer, the model must understand what a "head" or "tree" looks like.
* **Jigsaw Puzzles:** Shuffling patches of an image and asking the model to reassemble them.
* **Colorization:** Giving the model a black-and-white photo and asking it to predict the colors.

## 2. The Two-Stage Pipeline

Self-supervised learning is almost always used as a "pre-training" step before a specific downstream task.

1. **Stage 1: Pre-training (SSL):** Train on a massive, unlabeled dataset (e.g., all of Wikipedia) to learn general representations.
2. **Stage 2: Fine-tuning (Supervised):** Take that "smart" model and train it on a very small, labeled dataset for a specific task (e.g., medical sentiment analysis).

```mermaid
graph TD
Data[Massive Unlabeled Data] --> Pre[Pre-training: SSL]
Pre --> Base[Base Model: Knows 'Context']
Base --> Fine[Fine-tuning: Labeled Data]
Fine --> Final[Specialized Model]

style Pre fill:#f3e5f5,stroke:#7b1fa2,color:#333
style Final fill:#e8f5e9,stroke:#2e7d32,color:#333

```

## 3. Contrastive Learning

A popular modern approach to SSL is **Contrastive Learning**. Instead of predicting a missing part, the model learns to distinguish between "similar" and "different" things.

* **Positive Pair:** Two different crops of the same photo of a dog.
* **Negative Pair:** A photo of a dog and a photo of a car.
* **Goal:** The model learns to pull the "dog" representations together and push the "car" representation away in mathematical space.

## 4. Why SSL is the Future

| Feature | Supervised Learning | Self-Supervised Learning |
| --- | --- | --- |
| **Data Source** | Human-curated labels | Raw, "wild" data (Internet) |
| **Scalability** | Limited by human hours | Unlimited (Scales with compute) |
| **Knowledge** | Narrow/Task-specific | General/Versatile |

## 5. Real-World Impact

* **Large Language Models (LLMs):** Every "GPT" model uses SSL to learn how to predict the next token.
* **Robotics:** Robots learning to understand their environment by predicting the next frame in a video feed.
* **Medical AI:** Pre-training on millions of unlabeled X-rays to understand "anatomy" before learning to spot specific rare diseases.

## References for More Details

* **[Yann LeCun - Self-Supervised Learning](https://ai.meta.com/blog/self-supervised-learning-the-dark-matter-of-intelligence/):** Understanding why the pioneers of AI believe SSL is "the dark matter of intelligence."
* **[Illustrated Word2Vec](https://jalammar.github.io/illustrated-word2vec/):** A visual guide to the earliest successful SSL techniques in NLP.

---

**You've now seen how AI learns from labeled data, patterns, and even itself. There is one final, radical way for AI to learn: by "playing" and receiving rewards.**
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
title: "Semi-Supervised Learning: The Best of Both Worlds"
sidebar_label: Semi-Supervised Learning
description: "Combining small amounts of labeled data with large amounts of unlabeled data to improve model accuracy and reduce labeling costs."
tags: [machine-learning, semi-supervised-learning, data-labeling, pseudo-labeling, active-learning]
---

In the real world, data is plentiful, but **labels are expensive**.

* **Supervised Learning** requires every data point to be labeled by a human expert (expensive and slow).
* **Unsupervised Learning** uses no labels but can't perform specific tasks like classification.

**Semi-Supervised Learning (SSL)** sits in between. It uses a small set of labeled data to "guide" the discovery of patterns in a much larger set of unlabeled data.

## 1. The Core Idea: Self-Training & Pseudo-Labeling

The most common technique in SSL is **Pseudo-labeling**. Instead of a human labeling millions of images, the model does it itself.

1. **Train:** Train a model on the small amount of human-labeled data.
2. **Predict:** Use that model to predict labels for the large unlabeled dataset.
3. **Filter:** Keep only the predictions where the model is highly confident (e.g., probability $> 95\%$). These are your "Pseudo-labels."
4. **Retrain:** Combine the original human labels with the new pseudo-labels and train a final, more robust model.

## 2. Key Assumptions of SSL

For semi-supervised learning to work, the data must satisfy certain mathematical properties:

* **Continuity Assumption:** Points that are close to each other are likely to share the same label.
* **Cluster Assumption:** Data tends to form discrete clusters. Points in the same cluster are likely to share a label.
* **Manifold Assumption:** High-dimensional data lies on a lower-dimensional "manifold" or structure (like a 2D sheet crumpled in 3D space).

## 3. When to Use Semi-Supervised Learning

SSL is the standard approach in industries where expert labeling is prohibitively expensive:

* **Medical Imaging:** You have millions of X-rays, but only 1,000 have been analyzed by a specialized radiologist.
* **Language Translation:** Huge amounts of raw text exist, but human-translated pairs are limited.
* **Speech Analysis:** Thousands of hours of audio recordings, but only a fraction are transcribed.

## 4. SSL vs. Other Types

| Feature | Supervised | Unsupervised | Semi-Supervised |
| :--- | :--- | :--- | :--- |
| **Label Requirement** | 100% Labeled | 0% Labeled | ~1-10% Labeled |
| **Cost** | Very High | Low | Moderate |
| **Common Use Case** | Prediction | Discovery | Scaling Predictions |

```mermaid
graph TD
LD[Small Labeled Dataset] --> M1[Initial Model]
UD[Large Unlabeled Dataset] --> M1
M1 --> PL[Pseudo-Labels]
PL --> M2[Final Robust Model]
LD --> M2

style LD fill:#e8f5e9,stroke:#2e7d32,color:#333
style UD fill:#fff3e0,stroke:#ef6c00,color:#333
style PL fill:#e1f5fe,stroke:#01579b,color:#333

```

## 5. Active Learning: A Related Concept

Sometimes, SSL is combined with **Active Learning**. In this setup, the model identifies the specific unlabeled examples it is most "confused" about and asks a human expert to label *only those* specific points. This maximizes the value of human effort.

## References for More Details

* **[Scikit-Learn: Self Training](https://scikit-learn.org/stable/modules/semi_supervised.html):** Learning about `SelfTrainingClassifier` and `LabelPropagation`.

---

**Semi-supervised learning is about making the most of what you have. But what if there are no labels at all, and the AI must learn by "playing" in an environment?**
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
title: "Unsupervised Learning: Finding Hidden Structure"
sidebar_label: Unsupervised Learning
description: "Discovering patterns in unlabeled data through clustering, association, and dimensionality reduction."
tags: [machine-learning, unsupervised-learning, clustering, dimensionality-reduction, anomaly-detection]
---

In **Unsupervised Learning**, the model is given a dataset without explicit instructions on what to do with it. There are no labels ($y$), and there is no "teacher" to correct the model. Instead, the algorithm explores the data to find inherent structures, patterns, and groupings.

## 1. The Core Objective

The mathematical goal of unsupervised learning is to model the underlying probability distribution or structure of the input data ($X$).

$$
P(X)
$$

Instead of mapping $X \to y$, the model asks: *"How is $X$ organized?"*

## 2. Key Techniques and Use Cases

### A. Clustering
Grouping data points so that objects in the same group (called a **cluster**) are more similar to each other than to those in other groups.
* **Algorithm:** K-Means, DBSCAN, Hierarchical Clustering.
* **Use Case:** **Customer Segmentation**. Grouping users by purchasing behavior to create targeted marketing campaigns.

### B. Dimensionality Reduction
Reducing the number of random variables under consideration by obtaining a set of principal variables.
* **Algorithm:** PCA (Principal Component Analysis), t-SNE.
* **Use Case:** **Data Visualization**. Compressing 100+ features into a 2D plot to see if there are natural groupings in the data.

### C. Association Rule Learning
Discovering interesting relations between variables in large databases.
* **Algorithm:** Apriori, Eclat.
* **Use Case:** **Market Basket Analysis**. Realizing that customers who buy "Diapers" are also highly likely to buy "Beer."

### D. Anomaly Detection
Identifying rare items, events, or observations which raise suspicions by differing significantly from the majority of the data.
* **Algorithm:** Isolation Forest, One-Class SVM.
* **Use Case:** **Fraud Detection**. Spotting a credit card transaction that doesn't fit a user's normal spending profile.

## 3. Comparison: Supervised vs. Unsupervised

| Feature | Supervised Learning | Unsupervised Learning |
| :--- | :--- | :--- |
| **Data** | Labeled ($X, y$) | Unlabeled ($X$) |
| **Goal** | Predict outcomes | Find hidden patterns |
| **Feedback** | Direct (Correct/Incorrect) | None (Evaluation is subjective) |
| **Complexity** | Usually simpler to evaluate | Harder to validate results |

## 4. The Challenge of Evaluation

In Supervised Learning, you can calculate "Accuracy." In Unsupervised Learning, there is no "ground truth" to compare against. Engineers often use internal metrics like:
* **Silhouette Score:** Measures how similar an object is to its own cluster compared to other clusters.
* **Inertia:** Measures how far the points within a cluster are from their center.

```mermaid
graph TD
Data[Unlabeled Data] --> Model[Unsupervised Model]
Model --> Patterns[Discovered Patterns]
Patterns --> Insight1[Segmented Groups]
Patterns --> Insight2[Reduced Dimensions]
Patterns --> Insight3[Anomalies/Outliers]

style Model fill:#fff3e0,stroke:#ef6c00,color:#333
style Patterns fill:#e1f5fe,stroke:#01579b,color:#333

```

## 5. Real-World Applications

1. **Genetics:** Clustering DNA sequences to identify groups with similar genetic properties.
2. **Recommendation Systems:** Finding "neighbor" users who like similar movies (Collaborative Filtering).
3. **Search Engines:** Grouping similar search results or news articles into topics (Topic Modeling).

## References for More Details

* **[Scikit-Learn Unsupervised Learning](https://scikit-learn.org/stable/unsupervised_learning.html):** Technical documentation on clustering and manifold learning.

* **[Clustering Algorithms (Visual Guide)](https://projector.tensorflow.org/):** Playing with high-dimensional data in your browser.



---

**Unsupervised learning reveals the "who" and the "what" in your data. But what if you want an AI to learn how to make decisions through trial and error?**