# Machine Learning

## Introduction

* Machine learning is a tool of training of different kinds of model with different complexity. E.g: NLP , Computer vision, LLM

## Type of Training (Strategies)

### Supervised Learning

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FB3AxPB0w1Yvo6m4h6fq4%2Fimage.png?alt=media&#x26;token=bdc14f1f-dad0-491c-9410-a9c9c53a559d" alt=""><figcaption></figcaption></figure>

* Trained with labelled data including input and expected output
* Try to predict the next output
* Mainly used for classifcation /prediction

### Unsupervised Learning

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FkVEbyoH9gJMYaYYkotBH%2Fimage.png?alt=media&#x26;token=00552117-bdb7-4b3e-bd28-0df670602cae" alt=""><figcaption></figcaption></figure>

* Unlabelled data to feed to the model
* Mainly used for clustering to separate data into dfferent groups and find out the relationship between them

### Reinforcement Learning

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FJkcirReS83bxAmQJ6Oii%2Fimage.png?alt=media&#x26;token=9eb55902-f8d7-4ee7-a568-87bff02e7877" alt=""><figcaption></figcaption></figure>

* Learn from user feedback and keep enhancing the policy to provide the more precise result&#x20;
* E.g: Recommendation system

## Deep Learning (Framework)

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FIsGZg447GVrCQ7anodW9%2Fimage.png?alt=media&#x26;token=83fd431f-3405-4ed1-a204-e9007a347385" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FRvvUCqMxBj3Nsy2Y2OpZ%2Fimage.png?alt=media&#x26;token=29b578d3-9678-46b6-8952-be92c42d7030" alt=""><figcaption></figcaption></figure>

* In some of the case, it requires multiple factors for affecting the output. For example: Is pizza "good"? . The good definition can include multiple factors, E.g: pricing, branding, ingredients.
* There is a overall score(weight) that decided whether it is "good" or not (the result), it is calculated by different nodes within the network
* Each node is called neutron which is used for information processing
* The more layer meaning the more complicated logic, the higher leaning curve to reproduce the output

### Type of Network

#### 1. Artificial Neural Networks (ANN)

*Also called: Feedforward Networks or Multi-Layer Perceptrons (MLP).*

This is the "Vanilla" version. It is the simplest architecture.

* **How it works:** Information flows in **one direction** (Forward). It enters the input, goes through the hidden layers (math happens), and comes out the output. It has no memory of what happened 5 seconds ago.
* **Analogy:** The **Pizza Robot** we discussed earlier. It looks at the ingredients *right now* and makes a decision.
* **Usage:**
  * **Simple Tabular Data:** Predicting house prices based on square footage.
  * **Simple Classification:** Deciding if a loan applicant is "High Risk" or "Low Risk" based on their income numbers.

#### 2. Convolutional Neural Networks (CNN)

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FeqCCBpww9i5turByS6oO%2Fimage.png?alt=media&#x26;token=caa246e8-beab-45f8-aaa1-1370965b3234" alt=""><figcaption></figcaption></figure>

*The "Eyes" of AI.*

This is the network designed specifically for **Computer Vision**.

* **Why ANNs fail here:** An image has millions of pixels. A standard ANN gets overwhelmed by that much data.
* **How CNNs work:** Instead of looking at every pixel at once, it uses a **Filter** (like a magnifying glass). It scans the image grid-by-grid to look for patterns (Lines -> Shapes -> Eyes -> Faces).
* **Analogy:** Looking at a "Where's Waldo?" book. You scan your eyes across the page looking for specific patterns (red and white stripes).
* **Usage:**
  * **Face ID:** Unlocking your iPhone.
  * **Self-Driving Cars:** Detecting lane lines and pedestrians.
  * **Medical Imaging:** Finding tumors in X-rays.

#### 3. Recurrent Neural Networks (RNN) & Transformers

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2Fo9Kt0OzG1RZkOB4hL9Hl%2Fimage.png?alt=media&#x26;token=31246a5d-ccee-46da-93f6-cc82690bf3ee" alt=""><figcaption></figcaption></figure>

*The "Memory" of AI.*

These are the networks designed for **Sequence Data** (Text, Audio, Time).

* **Why ANNs fail here:** Language depends on **order**.
  * Sentence A: "Dog bites Man."
  * Sentence B: "Man bites Dog."
  * These have the same words, but opposite meanings. A simple ANN can't tell the difference because it doesn't understand order.

**A. The Old Way: RNN (Recurrent Neural Network)**

* **How it works:** It processes data one step at a time, but it has a "Feedback Loop." It remembers the word it just read and passes that memory to the next word.
* **The Flaw:** They have short-term memory loss. By the time they finish a long paragraph, they forget the beginning.

**B. The New Way: Transformers (The "T" in ChatGPT)**

* **How it works:** This is the architecture of **LLMs**. Instead of reading left-to-right, it reads the **entire sentence at once**. It uses a mechanism called **"Self-Attention"** to calculate how every word relates to every other word simultaneously.
* **Usage:**
  * **NLP:** Translation (Google Translate), Chatbots (ChatGPT).
  * **Speech:** Siri/Alexa voice recognition.
  * **Time Series:** Predicting the Stock Market (looking at the history of prices to predict the future).

## Deep learning & Strategies&#x20;

* Initially, the bot is stupid, each weight of factor are stupid and random, not be trustable
* The strategies are to adjust the weight of node
* **The Supervised Adjustment:**\
  The Chef screams: **"WRONG! This is labeled as 'BAD PIZZA'!"**
  * **The Logic:** The framework calculates the **Error** (Difference between Robot's guess and the Chef's Label).
  * **The Weight Change:** The algorithm looks at the specific path that caused the error. It sees the "Pineapple" wire was active.
  * **Action:** It forcibly smashes the Pineapple Weight down immediately.
    * *Old Weight:* `0.5`
    * *New Weight:* `-2.0`
  * **Result:** The robot learned **instantly** because the Chef told it exactly what the right answer was.
* **The Reinforcement Adjustment:**\
  The Robot eats the pizza. It tastes okay at first. **One hour later, the Robot vomits.**
  * **The Signal:** **Negative Reward (-10 Points).**
  * **The Logic:** The robot doesn't know *exactly* why it got sick. Was it the dough? The cheese? The pineapple?
    * It looks at what inputs were active recently. "Well, I ate Pineapple."
  * **The Weight Change:** It nudges the weight down **slightly**.
    * *Old Weight:* `0.5`
    * *New Weight:* `0.4`
  * **The Loop:** The robot has to eat 20 more pineapple pizzas and get sick 20 more times before the weight finally drops to `-2.0`.

## Computer Vision

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FePetwoWkLqWqvU1SKu8F%2Fimage.png?alt=media&#x26;token=6f6029db-5077-4484-92e3-c4c5fe49ec08" alt=""><figcaption></figcaption></figure>

* Similar with our eyes, used to identity the properties of image

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2FS9M80g6DvHfNNK6a4SdK%2Fimage.png?alt=media&#x26;token=2768bbc1-2710-4ae1-8282-c428a16721f3" alt=""><figcaption></figcaption></figure>

* The computer vision model is trained by CNN layer by layer, it can help us to identify the image by layers
