AlgoInsight

Q&A

What is a Large Language Model (LLM)?

By AlgoInsight Team2026-06-18

Overview

LLMs emerged from scaling the decoder-only Transformer on internet-scale text. The training objective - predict the next word given the previous words - is deceptively simple but, at sufficient scale, forces the model to learn grammar, facts, reasoning patterns, and commonsense. Modern LLMs go further with RLHF (Reinforcement Learning from Human Feedback) or RLAIF to align outputs to human intent and safety.

graph TD
    A["Pretraining<br/>Next-token prediction on trillions of tokens"] --> B["Base LLM<br/>knows language + world knowledge"]
    B --> C["Fine-tuning / RLHF<br/>Align to instructions, helpfulness, safety"]
    C --> D["Deployed LLM<br/>Follows instructions, answers questions, generates code"]
    D --> E["RAG / Tool use / Agents<br/>Access external knowledge and actions"]
    style C fill:#1e1b4b,color:#fff

How LLMs Are Trained

Phase 1: Pretraining

Train a Transformer decoder to minimize cross-entropy loss on next-token prediction over hundreds of billions to trillions of tokens (web text, books, code, Wikipedia):

L = −Σ log P(xₜ | x₁, ..., xₜ₋₁)

This produces a base model with broad capabilities but no instruction-following.

Phase 2: Instruction Fine-tuning (SFT)

Fine-tune on curated (prompt, response) pairs where the response was written or validated by humans. The model learns to respond helpfully to instructions.

Phase 3: RLHF (Reinforcement Learning from Human Feedback)

Human raters compare pairs of model outputs; a reward model is trained on these preferences; the LLM is then fine-tuned with PPO (Proximal Policy Optimization) to maximize the reward model's score. This aligns the model toward helpful, harmless, and honest outputs.

Emergent Abilities

As models scale, qualitatively new capabilities appear without explicit training for them - emergent abilities: multi-step reasoning, arithmetic, in-context learning, code generation. This is why scaling laws (Hoffmann et al., Chinchilla) have driven the field: predictably more capable models from more parameters × more data × more compute.

Key Concepts

In-Context Learning (ICL)

LLMs can perform new tasks described entirely in the prompt, with no weight updates:

Q: Translate to French: "Hello" → A: "Bonjour"
Q: Translate to French: "Goodbye" → A: ?

The model infers the task from examples in the context window.

Chain-of-Thought Prompting

Prompting the model to reason step by step ("Let's think step by step") dramatically improves performance on reasoning and math tasks by making intermediate reasoning explicit.

RAG (Retrieval-Augmented Generation)

Extend the LLM's knowledge beyond its training cutoff by retrieving relevant documents and including them in the context window before generating a response. Reduces hallucinations for knowledge-intensive tasks.

Hallucination

LLMs sometimes generate fluent but factually incorrect text ("hallucinations"). A fundamental challenge: the model predicts plausible token sequences, not verified facts. Mitigations: RAG, tool use, calibrated uncertainty, output verification.

Scaling Laws (Chinchilla)

For a given compute budget, optimal performance comes from a balanced scaling of model size and data - roughly, you should train a model of N parameters on ~20N tokens. Many early large models were undertrained; LLaMA and Mistral demonstrated small-but-efficiently-trained models can outperform large under-trained ones.

Current Landscape (2025–26)

Frontier models: GPT-4, Claude 3.x/4.x, Gemini 1.5/2.x, LLaMA 3.x, Mistral, Qwen. Key trends: long context windows (1M+ tokens), multimodality (text + image + audio), reasoning models (o1-style chain-of-thought at inference), agents (tool use, multi-step planning), open weights (LLaMA, Mistral).

Why This Matters in Interviews

LLM questions are ubiquitous in AI/ML interviews. Cover: pretraining objective (next-token prediction), the three-phase training pipeline (pretrain → SFT → RLHF), emergent abilities from scale, in-context learning, hallucination and RAG as a mitigation, and Chinchilla scaling laws. The ability to distinguish base model / instruction-tuned / RLHF-aligned models shows depth beyond surface familiarity.

Common Pitfalls

References

More answers