This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Understand

Know what these models are and how they behave.

What foundation models are, how LLMs actually work, how they’re trained, and where they fail. Breadth over depth — enough to reason about everything that follows.

1 - The AI Landscape

Where GenAI fits — and why, as a builder, you use models rather than train them.

You don’t need to build AI models to build powerful things with them. This page places the key terms so the rest makes sense — no math required.

The nesting: AI ⊃ ML ⊃ DL ⊃ GenAI

  • AI — the broad goal of getting software to do “intelligent” tasks.
  • ML (machine learning) — AI that learns patterns from data instead of hard-coded rules.
  • DL (deep learning) — ML using large neural networks.
  • Generative AI — DL models that create content (text, images, code). Large language models (LLMs) and other foundation models live here.
flowchart TB
    subgraph AI[Artificial Intelligence]
      subgraph ML[Machine Learning]
        subgraph DL[Deep Learning]
          GA[Generative AI - LLMs and foundation models]
        end
      end
    end

What changed with foundation models

They’re pre-trained on huge data, general-purpose, and used through an API or a prompt. You don’t collect data or train them — you use them and adapt their behavior with prompts, your own data (RAG), and tools.

Your role as a builder

The job is orchestration, not training: wiring models into software, tools, and automation, then controlling and evaluating their output. The skills that matter: prompting, context/RAG, tool & agent design, guardrails, evaluation, and cost/latency awareness.

What you don’t need (for now)

Training algorithms, gradient descent, model architecture internals. Useful background later — not required to ship.

Sources

2 - Generative AI

Generative vs. discriminative — the one distinction this page exists to make stick.

Goal

Own one distinction: models that create content versus models that label it. It sounds academic but it decides real architecture: which problems need an LLM at all, and which are cheaper solved another way.

Generative vs. discriminative

  • A discriminative model maps input → label or score: spam / not-spam, fraud risk 0.83, positive / negative.
  • A generative model maps input → new content: text, images, audio, video, code.
flowchart LR
    In[Product review] --> D[Discriminative model]
    D --> L[Label: positive]
    In --> G[Generative model]
    G --> C[New content: a reply to the customer]

Same input, different job: the discriminative model labels the review; the generative model writes the reply.

Why the distinction matters to a builder

  • Not every problem needs generation. Classify tickets, score leads, detect fraud — discriminative tasks. An LLM can do them (and is a fast way to prototype), but a small classifier is often cheaper, faster, and more predictable at scale.
  • Generative output is probabilistic — the same prompt can yield different answers. Great for drafting and brainstorming; a liability where there is exactly one right answer, which is why structured outputs and evaluation exist.
  • Generation is the interface change. Pre-GenAI, ML gave you predictions to build UI around; now the model produces the artifact itself — the email, the code, the summary.

Strengths & limitations

  • Strengths — one model covers drafting, summarizing, translating, coding, brainstorming; no task-specific training needed — a prompt reshapes the behavior.
  • Limitations — output varies run to run; it optimizes for plausible, not true (see Limitations); for pure labeling at scale it can be an expensive way to do a cheap job.

Foundation models are the engines; generative AI is what they do when producing content.

Sources

3 - Foundation Models

Large, general-purpose models pre-trained on broad data and adapted to many tasks.

What it is

A foundation model is a large model pre-trained on a broad range of data, then adapted to many downstream tasks. Instead of training a separate model per task, you start from one general-purpose model and specialize it.

Key points

  • Pre-training learns general patterns from massive data; fine-tuning and prompting specialize it for a task.
  • Parameters — the learned weights; more parameters generally mean more capacity.
  • Context window — how much text the model can consider at once (input + output).
  • Modalities — text, image, audio, or a mix (multimodal).
  • Adaptation options, from cheapest to most involved: prompting → RAG → fine-tuning.

A large language model (LLM) is a foundation model specialized for text.

Example — one model, many tasks

The same foundation model can summarize an email, write SQL, translate French, and answer a support question — with no task-specific training. You just change the prompt.

Strengths & limitations

  • Strengths — one general-purpose model for many tasks; adapt it cheaply along prompting → RAG → fine-tuning.
  • Limitations — knowledge frozen at a cutoff; can hallucinate; capability, cost, and latency all scale with size; behavior is hard to fully predict.

Sources

4 - How LLMs Work

Tokens, next-token prediction, and the context window — the mechanics you build on.

You don’t need the math, but a few mechanics explain most of what you’ll hit as a builder.

Tokens

Models don’t read characters or words — they read tokens, chunks of text (roughly ¾ of a word in English). “Tokenization” is the step that splits text into tokens. Everything is counted and billed in tokens: your input and the model’s output.

Example — the same text, as the model sees it:

"AI is unbelievable"  →  ["AI"][" is"][" un"]["bel"]["iev"]["able"]

Three words become six tokens: common words are one token, rarer or longer words split into pieces. That’s why token count ≠ word count.

Next-token prediction

An LLM does one thing: given the text so far, predict the next token, append it, and repeat. That’s it.

flowchart LR
    T[Text so far] --> M[LLM]
    M --> N[Predict next token]
    N --> A[Append token]
    A --> T

This is why:

  • Output is probabilistic — same prompt can give different answers.
  • Models can be fluent yet wrong (they predict plausible text, not verified truth).

The context window

The context window is the maximum tokens the model can consider at once — and input + output share the same budget. A long prompt leaves less room for the answer. When a conversation outgrows the window you must trim, summarize, or retrieve (see Context engineering).

Knowledge cutoff

A model only knows what it saw during training, up to a cutoff date. It has no live knowledge of your data or recent events — which is exactly what RAG and tools are for.

Why this matters to you

  • You pay per token → concise prompts and caching save money.
  • Context is finite → manage what you put in it.
  • Output is probabilistic → validate, and use evaluation.

Strengths & limitations

  • Strengths — fluent, general language ability; long context; multilingual.
  • Limitations — predicts plausible text, not verified truth; cost grows with tokens; knowledge is frozen at the training cutoff.

The whole pipeline in one line: text → tokens → vectors → transformer → next token → answer.

Sources

5 - Under the Hood

A light look at transformers and attention — just enough to explain why LLMs behave as they do.

Builds on How LLMs work. You don’t need this to build, but a light mental model of what’s inside explains a lot of the behavior you’ll see.

Attention, in one idea

LLMs are transformers. The key trick is attention: to predict the next token, the model looks at all the tokens so far and weighs how much each one matters to the current step. “It” gets linked to the noun it refers to; a question gets linked to the relevant fact earlier in the prompt.

flowchart LR
    In[All tokens so far] --> Att[Attention - weigh how tokens relate]
    Att --> H[Context-aware representation]
    H --> Next[Predict next token]

Example — what attention resolves

“The trophy didn’t fit in the suitcase because it was too big.”

What does it refer to? You instantly know: the trophy — because didn’t fit and too big point there. Swap in too small and it flips to the suitcase. Attention is the mechanism that weighs those relationships between tokens, which is how the model gets this right without any grammar rules.

Why this explains the behavior you see

  • Context is everything — the model has no memory beyond what’s in the window; attention works over exactly that text. More relevant context → better answers (and more cost).
  • Order and phrasing matter — attention is sensitive to how things are worded and placed; that’s why prompting and context engineering work.
  • Cost grows with length — attention compares tokens against each other, so long inputs are disproportionately expensive.
  • No true understanding — it’s pattern prediction, not comprehension, which is why models can be confidently wrong (see Limitations).

Sources

6 - How Models Are Trained

An awareness-level view of pre-training, fine-tuning, and alignment — and why it matters to a builder.

You won’t train a foundation model, but knowing how one is made explains a lot of its behavior. This is awareness-level — no training techniques required.

The two big phases

  • Pre-training — the model learns language and world knowledge by predicting the next token across a huge corpus. The result is a base model: knowledgeable but not good at following instructions.
  • Post-training — the base model is shaped into something useful:
    • Instruction / fine-tuning — taught to follow instructions and answer helpfully.
    • Alignment (e.g. RLHF) — tuned with human feedback to be helpful, honest, and safe.

Why this matters to you as a builder

  • Knowledge cutoff — knowledge is frozen at pre-training time. For fresh or private facts you need RAG, not a newer base model.
  • Why it follows instructions (and refuses) — that behavior comes from post-training, not magic. It’s why prompting works and why models sometimes decline requests.
  • What fine-tuning does — it adjusts behavior and style, and reliably teaches narrow skills; it does not reliably inject fresh knowledge. See Adaptation.

Example — base vs. instruction-tuned

Prompt: “Write a haiku about the sea.”

  • Base model — may reply: Write a haiku about the mountains. Write a haiku about… — it continues text, because predicting the next token is all pre-training taught it.
  • Instruction-tuned model — returns an actual haiku.

Same knowledge, different behavior. That difference is post-training.

What you don’t need

Datasets, GPUs, loss functions, gradient descent. Providers handle all of it; you consume the finished model.

Sources

  • Ouyang et al., Training language models to follow instructions with human feedback (2022) — arXiv:2203.02155
  • Bommasani et al., On the Opportunities and Risks of Foundation Models (2021) — arXiv:2108.07258

7 - Multimodality

Models that handle more than text — images, audio, and video, in and out.

Modern models aren’t text-only. A multimodal model can take — and sometimes produce — images, audio, or video alongside text. Many tools you use (coding agents that read screenshots, chat that “sees” a photo) rely on this.

Input vs output modalities

flowchart LR
    T[Text] --> M[Multimodal model]
    I[Image] --> M
    A[Audio] --> M
    M --> OT[Text out]
    M --> OI[Image out]
  • Vision — image in, text out (describe a chart, read a screenshot, extract from a PDF).
  • Image generation — text in, image out.
  • Speech — audio ↔ text (transcription, voice interfaces).

A model supports a specific set of these — check before you rely on one.

Why it matters to builders

  • Turn a screenshot or design into code.
  • Document / PDF understanding — invoices, forms, diagrams.
  • Chart & table reading for data extraction.
  • Voice interfaces via speech-to-text and text-to-speech.

Practical notes

  • You send images in the same messages as text (see The AI API).
  • Images cost tokens too — often a lot; higher resolution = more tokens.
  • One multimodal model is convenient; specialized models can be better or cheaper for a single modality. This is a model-choice trade-off.

Strengths & limitations

  • Strengths — one interface across text, images, and audio; unlocks screenshots, PDFs, charts, and voice.
  • Limitations — images cost many tokens; resolution is capped; not every model supports every modality.

Sources

8 - Limitations & Failure Modes

What models get wrong and why — so you know when to add RAG, tools, guardrails, or a human.

Knowing how models fail tells you what to add around them. None of these are bugs — they follow from how LLMs work.

The main failure modes

Failure modeWhat it isMitigation
HallucinationConfident but false or unsupported outputRAG + citations; ask for “I don’t know”
Knowledge cutoffNo knowledge of recent or private factsRAG, tools, web search
Bad at exact math / countingPredicts plausible tokens, doesn’t computeGive it tools / code
Non-determinismSame prompt → different answersLower temperature, constrain output, evaluate
Prompt sensitivitySmall wording changes shift resultsTest prompts against an eval set
BiasReflects biases in training dataResponsible AI review, human oversight
Context limitsForgets or drops info beyond the windowContext engineering

The pattern

flowchart LR
    H[Hallucination / cutoff] --> RAG[Ground with RAG + citations]
    M[Bad math / counting] --> Tools[Use tools and code]
    ND[Non-determinism] --> Eval[Constrain + evaluate]
    B[Bias / safety] --> Gov[Guardrails + human oversight]

The takeaway

A model alone is unreliable for facts, math, and consistency. You make it reliable by surrounding it — grounding it in data, giving it tools, constraining its output, and measuring it. That’s what the rest of this stage is about.

Sources

  • Ji et al., Survey of Hallucination in Natural Language Generation (2022) — arXiv:2202.03629