Skip to main content

LLM Overview

Large Language Model (LLM) は、大量の text を使って 次の token を予測する ように pretrain された大規模 transformer です。Chat assistant、coding tool、search、reasoning、AI agent の中核として、近年もっとも影響力のある AI 技術の一つになっています。

LLM pipeline map

自作概念図。LLM の典型的なライフサイクル: pretraining → post-training (SFT + RLHF / DPO) → reasoning RL → 推論時の RAG / agent / chat。

何を「学んでいる」のか

LLM の training objective は驚くほどシンプルです。

L=tlogpθ(xtx<t)\mathcal{L} = -\sum_t \log p_\theta(x_t \mid x_{<t})

つまり、文中の各 token xtx_t を、それまでの token x<tx_{<t} から予測するだけです。この単純な目的を web 規模のテキスト + 巨大な transformer に適用することで、文法、知識、推論、コード生成、翻訳など多様な能力が emergent に現れることがわかってきました。

三つの大きな段階

段階目的代表的手法
Pretraining言語と世界知識の獲得Next-token prediction
SFT指示追従の獲得Instruction tuning
Preference alignment人間の好みに合わせるRLHF / DPO
Reasoning RL長い思考の学習GRPO など
Deployment実応用RAG / AI Agents

詳細ページ

ページ内容
Transformer ArchitectureSelf-attention、residual、layer norm
Self-Attention and QKVQuery、Key、Value、causal mask の直感
Token to Logits Transformer Walkthroughtokenization から logits、KV cache、long context までの実行経路
LLM PretrainingNext-token prediction、scaling law
Scaling LawsChinchilla、compute optimal
TokenizationBPE、SentencePiece、語彙設計
Mixture of ExpertsMoE、sparse model、routing
Long Context and Position EncodingRoPE、ALiBi、long context
Supervised Fine-TuningInstruction tuning、chat template
Parameter-Efficient Fine-TuningLoRA、QLoRA、adapter
In-Context Learning and PromptingFew-shot、CoT、prompt engineering
Retrieval-Augmented GenerationRAG architecture、embedding、ranking
Reasoning Modelso1 / R1、long CoT
Sampling Strategiestemperature、top-k、top-p、min-p
Speculative Decodingdraft model と target model による高速化
Model MergingModel Soups、Task Arithmetic、TIES、DARE
LLM Inference OptimizationKV cache、FlashAttention、PagedAttention、quantization
KV Cacheprefill、decode、TTFT、GQA / MQA
LLM EvaluationMMLU、HumanEval、Chatbot Arena

関連カテゴリ

数式で見る LLM の lifecycle

LLM の基礎は next-token prediction です。Sequence x1:Tx_{1:T} の likelihood は autoregressive factorization で書けます。

pθ(x1:T)=t=1Tpθ(xtx<t)p_\theta(x_{1:T})=\prod_{t=1}^{T}p_\theta(x_t\mid x_{<t})

Pretraining ではこの negative log likelihood を最小化します。

Lpre=tlogpθ(xtx<t)\mathcal{L}_{pre}=-\sum_t\log p_\theta(x_t\mid x_{<t})

SFT では、instruction-response pair (x,y)(x,y) の response 部分に対して同じ loss を取ります。

LSFT=tresponselogpθ(ytx,y<t)\mathcal{L}_{SFT}=-\sum_{t\in\mathrm{response}}\log p_\theta(y_t\mid x,y_{<t})

Preference alignment では、chosen response y+y^+ と rejected response yy^- の差を使います。

P(y+yx)=σ(r(x,y+)r(x,y))P(y^+\succ y^-\mid x)=\sigma(r(x,y^+)-r(x,y^-))

この三つの式の気持ちは、「まず言語分布を学び、次に指示形式へ合わせ、最後に人間の好みに合わせる」という lifecycle を表しています。Deployment では、RAG や agent tool use によって xx の中に外部 context や環境観測が入るため、同じ next-token model でも実際の条件付き分布は大きく変わります。

主なソース