Stage 5 track
Track: ML / AI
Capstone: PDF chatbot (RAG) · Tools: scikit-learn, PyTorch, LLM APIs, RAG · Time: ~2 weeks (one step every 2–3 days, ~3 hours a day)
Who this track is for
You're curious about how machine learning and LLMs actually work under the hood, not just how to call an API. You're comfortable with functions, OOP and errors from Stages 1–2, and you're willing to spend real time on the maths-adjacent parts (vectors, probabilities) alongside the code.
Job roles this maps to: ML Engineer, AI/Applied AI Engineer, and roles building LLM-powered features ("AI engineer") on top of product teams. This track is a foundation, not a full data-science or research-scientist path — those usually need more statistics and math depth than one Stage 5 track can give you.
You already have, from earlier stages:
- Functions, OOP, dataclasses (Parts 5, 9)
- Errors and exceptions (Part 6)
- Files and JSON (Part 8)
- HTTP and REST APIs (Part 12) — LLM APIs are REST APIs
Before you start: scikit-learn and PyTorch both expect data as NumPy arrays or pandas DataFrames. If you haven't used NumPy and pandas before, spend a few days on the basics first — see Weeks 1–2 of the Data Analytics track. You don't need the rest of that track, just arrays and DataFrames.
What you'll learn, step by step
Step 1 — scikit-learn (classic machine learning)
Builds on: NumPy/pandas (prerequisite above), Part 9 (OOP — scikit-learn's fit/predict pattern is just method calls on an object).
- The basic ML workflow: split your data into training and test sets, fit a model on training data, evaluate it on data it hasn't seen.
- Try one classification model (e.g. predicting a yes/no outcome) and one regression model (e.g. predicting a number) on a small, well-known dataset.
- Core vocabulary: features, labels, overfitting, accuracy and other basic metrics.
- Pipelines: chaining preprocessing steps and a model together as one object.
Step 2 — PyTorch fundamentals
Builds on: Step 1 (ML vocabulary), NumPy (tensors feel like NumPy arrays).
- Tensors: PyTorch's version of a NumPy array, with the extra ability to track gradients.
- Autograd: how PyTorch computes derivatives automatically — this is what makes training possible.
- Build and train one small neural network on a simple dataset, end to end: define the model, pick a loss function, loop over the data, update the weights.
- You are not trying to become a deep-learning researcher this step — the goal is to understand what "training a model" means in code, since every LLM you'll call in Weeks 3–5 was trained this same way, just at enormous scale.
Step 3 — LLM APIs
Builds on: Part 12 (HTTP, REST, JSON, API keys), Part 6 (errors — handling a failed or rate-limited API call).
- Calling a hosted large language model over its REST API: sending a prompt, reading the response.
- System messages vs. user messages, and why the system message is where you set the assistant's behaviour.
- Getting structured output back (e.g. JSON) instead of free text, so your code can use the response reliably.
- Basic cost and reliability habits: handling timeouts and errors (Part 6 again), and being mindful that every call costs money and takes time — don't call the API in a tight loop while debugging.
Step 4 — RAG (Retrieval-Augmented Generation) concepts
Builds on: Step 3 (LLM calls).
- The problem RAG solves: an LLM only knows what's in its prompt (plus whatever it was trained on, which won't include your PDF). RAG means: find the relevant pieces of your document and put them in the prompt before asking the question.
- Chunking: splitting a long document into smaller pieces that fit in a prompt.
- Embeddings: turning text into a list of numbers (a vector) such that similar meanings end up as similar vectors.
- Retrieval: given a question, find the chunks whose embeddings are closest to the question's embedding (the simplest version is comparing vectors directly; you do not need a dedicated vector database for a capstone-sized PDF).
Step 5 — Build the PDF chatbot
Builds on: everything above.
- Extract text from a PDF.
- Chunk it, embed each chunk, and store the chunks with their embeddings.
- On a user's question: embed the question, find the closest chunks, build a prompt containing those chunks plus the question, call the LLM, return the answer.
Step 6 — Polish (optional buffer)
Error handling for bad PDFs and failed API calls, a simple CLI or minimal web UI, README, stretch goal.
Setup pointers (official docs only)
| Tool | Official docs |
|---|---|
| scikit-learn | https://scikit-learn.org/ |
| PyTorch | https://pytorch.org/ |
| Anthropic API (Claude) | https://docs.anthropic.com/ |
| OpenAI API | https://platform.openai.com/ |
Pick one LLM provider for your capstone — you don't need both. Both providers require an API key and billing set up on their own platform; read their official "getting started" docs for the current signup steps, since this changes over time. Install scikit-learn and PyTorch inside a virtual environment, as in Part 7; follow each library's own install instructions for the current command for your machine (PyTorch's install command depends on your OS and whether you have a GPU).
Capstone brief: PDF chatbot
User stories
- As a user, I can point the chatbot at a PDF file.
- As a user, I can ask a question in plain English and get an answer based on that PDF's content.
- As a user, if I ask something the PDF doesn't cover, the chatbot tells me it doesn't know rather than making something up.
- As a user, I can ask a follow-up question and keep a short conversation going.
- As a developer, I can swap in a different PDF without changing code.
Architecture sketch
PDF file
│ (extract text)
▼
┌───────────────────────────┐
│ chunking │ split extracted text into overlapping chunks
└────────────┬──────────────┘
│ (embed each chunk)
▼
┌───────────────────────────┐
│ chunk store │ chunks + their embeddings, kept in memory
│ │ or a simple file (no server needed for a
│ │ capstone-sized document)
└────────────┬──────────────┘
▲
│ (embed the question, find closest chunks)
┌───────────────────────────┐
│ retriever │ given a question, return the N most
│ │ relevant chunks
└────────────┬──────────────┘
▼
┌───────────────────────────┐
│ LLM call │ prompt = system instructions + retrieved
│ │ chunks + the user's question
└────────────┬──────────────┘
▼
answer to the user
Keep "extract/chunk/embed" (runs once per PDF) separate from "retrieve/ask" (runs once per question) — the same separation of concerns you used between the database layer and the service layer in the library manager project.
Milestones
- Text in — extract plain text from a sample PDF; print the number of characters/pages.
- Chunked and embedded — split the text into chunks and get an embedding for each one; print how many chunks you got.
- Retrieval works — given a hand-written test question, confirm the chunk you'd expect to be most relevant comes back on top.
- End-to-end answer — ask a real question about the PDF and get a correct, grounded answer from the LLM.
- "I don't know" case — ask something unrelated to the PDF and confirm the chatbot says it doesn't know, instead of inventing an answer.
- Conversation — support at least one follow-up question that depends on the previous answer.
Acceptance checklist
- Given a real question answerable from the PDF, the chatbot's answer is correct and references content actually in the PDF
- Given an unrelated question, the chatbot says it can't answer from this document, rather than guessing
- A failed or rate-limited LLM call is caught and shown as a clear message, not a crash (Part 6 discipline)
- Changing the PDF file path is the only change needed to use a different document
- The API key is read from an environment variable, never hard-coded or committed to the repo
- You can explain, in your own words, what an embedding is and why chunking matters
Stretch goals
- 🟡 Show which chunk(s) the answer came from, so the user can verify it ("cite your sources").
- 🟡 A simple web UI (even a basic one) instead of a command-line loop.
- 🔴 Support multiple PDFs at once and let the user pick which one(s) to search.
- 🔴 Compare answer quality with and without retrieval (i.e. asking the LLM the same question with no PDF context) to see RAG's effect for yourself.
How you'll know you're done
- Every item in the acceptance checklist above is ticked
- You can explain the full pipeline out loud: extract → chunk → embed → retrieve → prompt → answer
- You can explain the difference between what scikit-learn/PyTorch taught you (training a model) and what the capstone does (calling an already-trained model and feeding it the right context)
- The repo is on GitHub with a README that states what the chatbot does, how to set the API key, and a sample question-and-answer transcript
- You can demo it live: run it against a real PDF and ask it both an answerable and an unanswerable question