跳到正文

个人记录

Date 2/24; Topic: 正确认识 ChatGPT -《MACHINE LEARNING (HUNG-YI LEE)》学习笔记

Mubuky约 8 分钟
原文
文章信息与版本

文章信息

发布
2023年9月7日
收录
2025年12月12日
更新
2026年11月17日
篇幅
约 8 分钟

版本

  1. v1当前

(MACHINE LEARNING 2023 SPRING)


Date 2/24; Topic: 正确认识 ChatGPT

Class Material

机器学习2023规则说明

略

ChatGPT 原理剖析 (1/3) —— 对 ChatGPT 的常见误解

ChatGPT 真正在做的事是“文字接龙”。

ChatGPT 原理剖析 (2/3) —— 预训练 (Pre-train)

预训练(自监督式学习)→ \rightarrow\ GPT(基石模型)—监督式学习,指令微调 → \rightarrow\ … —增强式学习 → \rightarrow\ ChatGPT

ChatGPT 原理剖析 (3/3) —— ChatGPT所带来的研究问题

  1. 如何精确提出需求
  2. 如何更正错误
  3. 侦测 AI 生成的物件
  4. 避免泄露秘密

用 ChatGPT 和 Midjourney 来玩文字冒险游戏

略

Extra Material

ChatGPT (可能)是怎么炼成的

GPT = Generative Pre-trained Transformer

  1. 学习文字接龙
  2. 人类老师引导文字接龙的方向
  3. 模仿人类老师的喜好
  4. 用增强式学习向模拟老师学习
  • (1) 想说什么就说什么
  • (2 - 4) 引导 GPT 说人类要他说的

Optional Material

Regression (Case Study: Predicting Pokémon CP)

  • Step 1: Model

    • y=b+∑(wi×xi)y = b + ∑(w_i \times x_i)
    • bb: 偏置;wiw_i: 权重
  • Step 2: Goodness of Function

    • Loss Function: Input a function and output how bad it is.
  • Step 3: Best Function

    • f∗=arg minL(f)f^* = arg\ min L(f)
  • Gradient Descent(梯度下降法):

    • Consider loss function L(w) with one parameter w:
    • (Randomly) Pick an initial value w^0
    • Compute dLdw∣w=w0\dfrac{dL}{dw} \mid_{w=w^0}; w0−ηdLdw∣w=w0→w1w^0 - η\dfrac{dL}{dw} \mid_{w=w^0} \rightarrow w^1
    • Compute dLdw∣w=w1\dfrac{dL}{dw} \mid_{w=w^1}; w1−ηdLdw∣∣w=w1→w2w^1 - η\dfrac{dL}{dw}| \mid_{w=w^1} \rightarrow w^2
    • …Many iteration

How about two parameters?

  • w∗,b∗=arg minw,bL(w,b)w^*, b^* = arg\ min_{w,b} L(w, b)
  • (Randomly) Pick an initial value w0,b0w^0, b^0
  • Compute ∂L∂w∣w=w0,b=b0\dfrac{∂L}{∂w} \mid_{w=w^0,b=b^0},∂L∂w∣w=w0,b=b0\dfrac{∂L}{∂w} \mid_{w=w^0,b=b^0}

w0−η∂L∂w∣w=w0,b=b0→w1w^0 - η\dfrac{∂L}{∂w} \mid_{w=w^0,b=b^0} \rightarrow w^1,b0−η∂L∂w∣w=w0,b=b0→b1b^0 - η\dfrac{∂L}{∂w} \mid_{w=w^0,b=b^0} \rightarrow b^1

  • more…

Gradient:

  • ▽L=[∂L∂w, ∂L∂b]L = [\dfrac{∂L}{∂w},\ \dfrac{∂L}{∂b}]

In linear regression, the loss function LL is convex.

Model Selection

  • 一个更复杂的模型并不总会在测试集上产生更好的结果;
  • Overfitting(过拟合);
  • 选择合适的模型。

Back to step 1: Redesign the Model

  • if xs=Pidgeyx_s = Pidgey: y=b1+w1×xcpy = b_1 + w_1 \times x_cp
  • if xs=Weedlex_s = Weedle: y=b2+w2×xcpy = b_2 + w_2 \times x_cp
  • more…

equal:

  • y=b1×δ(xs=Pidgey)+w1×δ(xs=Pidgey)xcp+b2×δ(xs=Weedle)+w2×δ(ws==Weedle)xcp+...y = b_1 \times δ(x_s = Pidgey) + w_1 \times δ(x_s = Pidgey)x_cp + b_2 \times δ(x_s = Weedle) + w_2 \times δ(w_s == Weedle)x_cp + ...
  • δ(xs=Pidgey)=xs==Pidgey ? 1 : 0δ(x_s = Pidgey) = x_s == Pidgey\ ?\ 1\ :\ 0

Back to step 2: Regularization(正则化)

  • 重新设计 lossloss 函数
  • Training: larger λ, considering the training error less
  • 我们倾向于更平滑的函数,但不要太平滑
  • How smooth? Select λ obtaining the best model.

Classification (Case Study: Pokemon classification)

How to do Classification

  • Training data for Classification

Ideal Alternatives

  • Function (Model)
  • Loss function
  • Find the best function
  • Example: Perceptron, SVM

Generative Model(生成模型)

Gaussian Distribution(正态分布)fμ,∑xf_μ,∑x

  • Input: vector x, output: probability of sampling x The shape of the function determines by mean μ and covariance matrix ∑

Maximum Likelihood(极大似然估计)

  • Likelihood of a Gaussian with mean μ and covariance matrix ∑ = the probability of the Gaussian samples

We assume samples generate from the Gaussian (μ*, ∑*) with the maximum likelihood

Logistic Regression

Step 1: Function Set

  • fw,b(x)=Pw,b(C1∣x)f_{w,b}(x) = P_{w,b}(C_1|x)
  • Including all different ww and bb

Step 2: Goodness of a Function

  • Training Data:
    • x1 x2 x3 ... xNx^1\ x^2\ x^3\ ...\ x^N
    • C1 C1 C2 ... C1C_1\ C_1\ C_2\ ...\ C_1
  • Assume the data is generated based on fw,b(x)=Pw,b(C1∣x)f_{w,b}(x) = P_{w,b}(C_1|x)
  • L(w,b)=fw,b(x1)fw,b(x2)(1−fw,b(x3))...fw,b(xN)L(w,b) = f_{w,b}(x^1)f_{w,b}(x^2)(1 - f_{w,b}(x^3))...f_{w,b}(x^N)
  • The most likely w∗w^* and b∗b^* is the one with the largest L(w,b)L(w,b).
  • w∗,b∗=arg maxw,b L(w,b)w^*, b^* = arg\ max_{w,b}\ L(w,b)
  • w∗,b∗=arg minw,b −lnL(w,b)w^*, b^* = arg\ min_{w,b}\ -lnL(w,b)

Step 3: Find the best function

  • 分类问题,都用 one-hot + Cross-entropy

Generative v.s. Discriminative

  • Benefit of gneerative model
    • 在假设概率分布的情况下,需要的训练数据更少
    • 在假设概率分布的情况下,对噪声的鲁棒性更强
    • 先验概率和类相关概率可以从不同的来源进行估计

Multi-class Classification (3 classes as example)_{(3\ classes\ as\ example)}

  • Softmax

级联逻辑回归模型

  • Feature Transformation + Classification
原文