Large Language Models (LLMs)

GATE Relevance: Low

Prerequisites

🎯 Learning Objectives

  • Understand scaling laws and why larger models perform better
  • Distinguish pretraining from fine-tuning paradigms
  • Explain emergent abilities that appear at scale
  • Describe in-context learning and how LLMs use examples at inference time
  • Understand RLHF and instruction tuning for alignment

1. What Makes a Language Model “Large”?

A Large Language Model (LLM) is a neural language model with billions of parameters, trained on massive text corpora (hundreds of gigabytes to terabytes). The “large” in LLM refers to three dimensions of scale:

  • Model size: Number of parameters (weights). GPT-3 has 175 billion parameters; GPT-4 is estimated to be even larger.
  • Training data: Volume of text used for pretraining. GPT-3 was trained on ~570 GB of filtered text.
  • Compute: Total floating-point operations during training, often measured in petaFLOP-days.
Key models timeline: GPT-1 (2018, 117M params) → BERT (2018, 340M) → GPT-2 (2019, 1.5B) → GPT-3 (2020, 175B) → PaLM (2022, 540B) → GPT-4 (2023) → Gemini, Claude, Llama series (2023–2025).

2. Scaling Laws

Kaplan et al. (2020) discovered that LLM performance (measured by cross-entropy loss L) follows power-law relationships:

L(N) ∝ N−αN     L(D) ∝ D−αD     L(C) ∝ C−αC

where N = number of parameters, D = dataset size, C = compute budget, and α values are positive constants (~0.076, 0.095, 0.050 respectively).

Key implications:

  • Performance improves smoothly and predictably with scale — no plateau in sight within current ranges.
  • All three factors (N, D, C) must scale together. Increasing model size without proportionally increasing data leads to overfitting.
  • Chinchilla scaling (Hoffmann et al., 2022): The optimal allocation scales N and D equally. A 70B parameter model trained on 1.4 trillion tokens outperforms a 280B model trained on fewer tokens with the same compute budget.

3. Pretraining

Definition: Pretraining is the initial phase where the LLM learns language patterns from a massive unlabeled text corpus using self-supervised objectives.

Common pretraining objectives:

  • Causal language modeling (CLM): Predict the next token given all previous tokens. Used by GPT family. Loss = −∑ log P(wt | w<t).
  • Masked language modeling (MLM): Randomly mask 15% of tokens and predict them from bidirectional context. Used by BERT.
  • Prefix language modeling: Encode a prefix bidirectionally, then generate autoregressively. Used by some encoder-decoder models.

Training data sources: Web crawls (Common Crawl), books, Wikipedia, code repositories (GitHub), scientific papers, forums. Careful filtering and deduplication is critical.

4. Fine-tuning

After pretraining, the model is adapted to specific tasks or behaviors:

4.1 Supervised Fine-tuning (SFT)

Train on a curated dataset of (instruction, response) pairs. The model learns to follow instructions rather than just predict the next word.

LSFT = −∑ log P(responset | instruction, response<t)

4.2 Parameter-Efficient Fine-tuning (PEFT)

Instead of updating all parameters, modify only a small subset:

  • LoRA (Low-Rank Adaptation): Add low-rank matrices ΔW = BA to attention weights, where B ∈ ℝd×r and A ∈ ℝr×d with r ≪ d. Only train A and B (0.1–1% of total parameters).
  • Prefix tuning: Prepend learnable vectors to the key/value matrices in attention.
  • Adapter layers: Insert small trainable bottleneck layers between frozen transformer blocks.

5. Emergent Abilities

Definition: Emergent abilities are capabilities that appear suddenly when a model reaches a certain scale threshold — they are absent in smaller models but present in larger ones, without being explicitly trained.

Examples of emergent abilities:

  • Multi-step reasoning: Chain-of-thought reasoning appears around 100B+ parameters.
  • Arithmetic: 3-digit addition emerges at scale but is absent in smaller models.
  • Word unscrambling: Anagram solving appears spontaneously at sufficient scale.
  • Code generation: Writing functional code from natural language descriptions.

Debate: Some researchers (Schaeffer et al., 2023) argue that emergence may be an artifact of evaluation metrics rather than a fundamental phase transition in capability.

6. In-Context Learning

Definition: In-context learning (ICL) is the ability of LLMs to perform new tasks at inference time by conditioning on a few examples provided in the prompt, without any gradient updates.

Types of in-context learning:

  • Zero-shot: Only a task description is given, no examples. “Translate the following English text to French: …”
  • One-shot: One example is provided before the query.
  • Few-shot: Multiple examples (typically 3–10) are provided in the prompt.

Example: Few-shot Classification

Prompt:

Classify the sentiment:
“I love this movie” → Positive
“Terrible waste of time” → Negative
“It was okay, nothing special” → Neutral
“Absolutely fantastic performance” →

Expected output: Positive

The mechanism behind ICL is still debated. Hypotheses include implicit gradient descent in the forward pass (Dai et al., 2023) and Bayesian inference over pretraining distributions.

7. RLHF (Reinforcement Learning from Human Feedback)

RLHF aligns the model with human preferences through a three-step process:

  1. Step 1 — Supervised Fine-tuning (SFT): Fine-tune the pretrained model on high-quality (prompt, response) pairs.
  2. Step 2 — Reward Model Training: Collect human rankings of model outputs. Given a prompt, humans rank multiple responses from best to worst. Train a reward model R(prompt, response) → scalar score using these preferences.
  3. Step 3 — RL Optimization: Use Proximal Policy Optimization (PPO) to fine-tune the SFT model to maximize the reward R while staying close to the SFT model (KL divergence penalty):

maximize 𝔼[R(x, y)] − β · DKL(πRL ‖ πSFT)

where πRL is the RL-tuned policy and πSFT is the supervised fine-tuned policy.

7.1 Instruction Tuning

A simpler alternative to full RLHF: fine-tune on a diverse collection of tasks formatted as instructions. FLAN (Wei et al., 2022) showed that instruction tuning on 60+ NLP tasks significantly improves zero-shot performance on unseen tasks.

DPO (Direct Preference Optimization): An alternative to PPO that directly optimizes for human preferences without training a separate reward model, simplifying the RLHF pipeline.

8. Summary

  • LLMs are neural LMs with billions of parameters trained on massive corpora.
  • Scaling laws: Loss follows power laws in model size, data, and compute.
  • Pretraining: Self-supervised (CLM or MLM) on unlabeled text.
  • Fine-tuning: SFT on instruction data; PEFT (LoRA) for efficiency.
  • Emergent abilities: Appear at scale thresholds (reasoning, code generation).
  • In-context learning: Zero/few-shot task performance without gradient updates.
  • RLHF: 3-step alignment (SFT → reward model → PPO) to match human preferences.
  • Instruction tuning: Simpler alternative; train on diverse instruction-response pairs.