AI Foundations¶
The bar: you can explain, in plain English, what a large language model actually does under the hood — how it turns text into tokens, why a transformer beats what came before, and which model to reach for on a real job — without leaning on hype.
Everybody is shipping "AI features" right now, and most of the people building them can't tell you what the model is doing. That's a trap. You end up copying prompt snippets off the internet, blowing your API budget on a task a cheaper model would have nailed, and having no idea why the output went sideways. Before you write a single line of AI code, you need the mental models to reason about it.
This module is the map, not the terrain. No training runs, no fine-tuning yet — just the concepts you'll stand on for everything that follows. Get these right and the rest of the AI track stops feeling like magic and starts feeling like engineering.
14.1 The AI Hierarchy¶
Objective: tell AI, machine learning, deep learning, and LLMs apart instead of using the words interchangeably.
These four terms are nested circles, not synonyms. Artificial Intelligence is the broad outer ring — any system that mimics human cognitive functions, including old-school rule engines with zero learning. Machine Learning sits inside it: systems that learn patterns from data instead of being hand-coded. Deep Learning is a subset of ML built on multi-layered neural networks, and Large Language Models are foundation models — deep networks trained on enormous text corpora — that live inside that innermost ring.
Why this matters on the job: when a stakeholder says "let's add AI," your first job is to figure out which ring they actually need. A regex might solve it. A classic ML classifier might solve it cheaper and faster than an LLM. Reaching for a language model on every problem is the most common and most expensive rookie mistake.
Drill:
- Draw the four nested rings from memory: AI ⊃ ML ⊃ Deep Learning ⊃ LLMs.
- For three real products you use, name which ring their "AI" lives in.
- Explain to a non-technical person why a spam filter is ML but not necessarily deep learning.
14.2 Learning Paradigms¶
Objective: understand the different ways an AI system actually learns.
There are four paradigms worth knowing. Supervised learning trains on labeled data — inputs paired with correct answers — and is how most classifiers and predictors are built. Unsupervised learning finds structure in data with no labels at all, like clustering customers into groups nobody defined in advance. Reinforcement learning trains an agent through reward signals, learning by trial and consequence rather than from a labeled answer key.
The one that trips people up is in-context learning. When you drop a few examples into a prompt and the LLM suddenly follows the pattern, no weights are being updated — the model is learning from context at inference time, not from training. Understanding that distinction is what separates "I gave it examples in the prompt" from "I fine-tuned it," and confusing the two leads to a lot of wasted effort.
Drill:
- Sort five example tasks into supervised, unsupervised, or reinforcement learning.
- Write a prompt that uses in-context learning with two or three examples and watch the pattern hold.
- State plainly why in-context learning does not change the model's weights.
14.3 The Transformer Architecture¶
Objective: understand why transformers set off the current wave of AI.
The transformer's breakthrough is self-attention — the mechanism that lets the model weigh which other words in the input matter when interpreting each word. That's how it keeps track of "it" referring to something twelve words back. Just as important, transformers parallelize: unlike the sequential models before them, they process a whole sequence at once, which maps perfectly onto GPU hardware and makes training at scale actually feasible.
Two more ideas ride on top. Scaling laws are the empirical finding that more compute and data reliably buy better performance — the engine behind the model size arms race. And transfer learning is the payoff: pre-train one massive foundation model, then adapt it to many downstream tasks instead of training from scratch every time. You don't need to derive the math, but you should be able to say why "attention plus parallelism plus scale" changed everything.
Drill:
- Explain self-attention using one sentence with an ambiguous pronoun.
- Describe why parallelization was the practical unlock, not just a nice-to-have.
- State the scaling-law relationship and what transfer learning saves you.
14.4 Tokens and Embeddings¶
Objective: understand how an LLM ingests and represents text.
Models don't read words — they read tokens. Tokenization chops text into chunks (often sub-word pieces) and maps each to a numerical ID. Those IDs become embeddings: dense vectors where distance encodes meaning, so "king" and "queen" land near each other in the space. This is the layer where language becomes math.
Two practical limits fall out of this. The context window is the maximum number of tokens a model can hold at once — prompt plus response — and blowing past it is a real failure mode you'll hit constantly. And token economics is where the money is: APIs bill per token, so a bloated prompt or a chatty system message costs real dollars at scale. Learning to think in tokens instead of characters is what keeps a feature under budget.
Drill:
- Run text through a tokenizer and see how words split into tokens.
- Find a case where a common word is one token and a rare word is several.
- Estimate the token count of a prompt before sending it, then check your guess.
14.5 The LLM Landscape¶
Objective: navigate the ecosystem of available models and pick the right one.
The field is not one model, it's a market. OpenAI ships the GPT-4 family, including GPT-4 Turbo. Anthropic builds the Claude 3 family. Google offers Gemini 1.5 Pro and the lighter, faster Flash. And the open-source camp — Llama, Mistral — lets you self-host and control your own weights instead of renting an API.
The skill isn't memorizing spec sheets, it's matching model to job. A cheap, fast model handles high-volume classification and simple extraction; a top-tier model earns its cost on hard reasoning, long-context work, or anything user-facing where quality shows. Open-source wins when data can't leave your servers or when per-call API costs won't scale. Defaulting to the biggest, most expensive model for everything is the same mistake as 14.1, just one layer up.
Drill:
- Match three task types (bulk tagging, legal summarization, on-prem chat) to a sensible model tier.
- List one concrete reason to choose open-source over a hosted API.
- Explain the cost-versus-quality trade between a Flash-class and a frontier model.
14.6 Hands-On Lab: Token Exploration¶
Objective: explore tokenization, context limits, and cost empirically instead of taking them on faith.
What you ship
A small Python script that makes the abstract concrete. Use tiktoken to tokenize several strings and print both the token IDs and the human-readable pieces, so you can see exactly where words split. Feed it a few different content types — plain English, code, JSON, and text with emoji — and compare how many tokens each burns per character. Push a deliberately oversized input toward a model's context-window limit and observe what happens as you approach it. Finally, take a published per-token price and calculate the real dollar cost of a handful of sample prompts, so "token economics" stops being a phrase and becomes a number you can defend in a planning meeting.
On the VWC codebase
When you bring an AI feature into the Vets Who Code app, remember it currently runs the Next.js Pages Router, so model calls belong in an API handler under src/pages/api/ — never in the browser, where your API key would be exposed. If a page needs model output at load time, fetch it server-side in getServerSideProps (or getStaticProps for content that can be precomputed) rather than reaching for App Router route handlers or Server Components. The token-cost thinking from this lab is exactly what keeps such an endpoint from quietly becoming the most expensive line item in the app.