C.W.K.
Stream
Lesson 01 of 12 · published

사전학습 objective — next-token vs masked LM

~12 min · pretraining, objectives

Level 0Token
0 XP0/94 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

사전학습 objective가 모델한테 "학습"이 뭘 의미하는지 결정해. objective 하나 골라서 수조 토큰 굴리면 — 나오는 모델이 생태계 전체를 빚어.

Next-Token Prediction (Causal LM)

prefix 주고 다음 토큰 예측. loss는 모든 위치에서 동시에 cross-entropy, causal mask로 미래 토큰 누설 방지. GPT, Llama, Mistral, Claude, Gemini 사용 — 모든 모던 decoder-only LLM. objective가 생성으로 자연스럽게 스케일 — t에서 t+1을 예측하도록 학습된 모델이 샘플링/append로 임의 연속 생산.

Masked Language Model (MLM)

~15% 토큰 랜덤하게 가리고, 양방향 컨텍스트에서 그걸 예측하도록 학습. BERT, RoBERTa, DeBERTa 사용. 분류/검색용 풍부한 텍스트 표현 만드는 데 훌륭하지만, 큰 아키텍처 변경 없이는 autoregressive 생성 불가능.

왜 next-token이 이겼나

이유 셋. (1) objective와 배포 task가 같음 — 생성, train/inference 불일치 없음. (2) 양방향 MLM은 생성용으로 별도 "decoder" 붙여야 함; causal LM은 decoder가 내장. (3) causal LM은 multi-modal(이미지, 오디오) 시퀀스로 직선적으로 스케일, MLM은 텍스트형 mask-and-fill 의미론에 묶임. 2022년 즈음 사실상 모든 프론티어 모양 모델이 decoder-only causal LM.

Code

Causal LM loss in PyTorch·python
import torch.nn.functional as F

def causal_lm_loss(logits, target_ids):
    # logits: (B, L, vocab_size); target_ids: (B, L)
    # Shift: position t predicts target at t+1
    pred = logits[:, :-1, :]
    target = target_ids[:, 1:]
    return F.cross_entropy(
        pred.reshape(-1, pred.size(-1)),
        target.reshape(-1),
        ignore_index=-100,
    )

# This is the entire training loss for GPT, Llama, etc.
# Combined with a causal mask in attention, training in parallel
# is mathematically equivalent to predicting one token at a time.

External links

Exercise

같은 데이터셋에 작은 모델 둘 학습 — 하나는 causal LM(next-token), 하나는 MLM(15% 마스킹 후 예측). 동등 컴퓨트 후 downstream task 점수 비교 — 텍스트 분류, 빈칸 채우기, 자유 생성. 각각이 어느 task에 잘하는지 명확해야. 이게 objective 선택에 대해 뭘 말해주나?

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.