Large Language Models for Developers
A 20-hour course on how large language models work and how to build with them: ten lectures of two
hours, each with the theory, the papers behind it, and a hands-on lab. Taught in English at
Zucchetti in July 2026 by Kamyar Zeinalipour.
The slides run in the browser: open the course site. The labs are Python scripts with a
matching Jupyter notebook and a solutions.py.
Lectures
| # |
Lecture |
Slides |
Lab |
| 1 |
The Transformer Blueprint |
Slides |
Lab 01, embeddings |
| 2 |
Tokenization, Embeddings and Similarity |
Slides |
Lab 01, embeddings |
| 3 |
Prompt Engineering |
Slides |
Lab 02, prompt engineering |
| 4 |
RAG Foundations and the Decision Matrix |
Slides |
Lab 03, inference benchmarking |
| 5 |
Advanced RAG and Intelligent Routing |
Slides |
Lab 04, query router |
| 6 |
Graph RAG and Knowledge Graphs |
Slides |
Lab 05, Graph RAG |
| 7 |
Agentic RAG and Autonomous Systems |
Slides |
Lab 06, SQL agent |
| 8 |
RAG Evaluation and Observability |
Slides |
Lab 07, the RAG mega-lab |
| 9 |
Efficient Fine-Tuning (LoRA and QLoRA) |
Slides |
Lab 08, LoRA fine-tuning |
| 10 |
Modern LLM Architectures and Multimodal AI |
Slides |
Lab 09, vision-language models, Lab 10, production deployment |
What you will learn
- Transformer architecture — the math behind self-attention, multi-head attention, positional encoding
- How LLMs work — next-token prediction, cross-entropy loss, temperature & sampling
- Key concepts — hallucination, perplexity, context windows, RLHF
- Encoder vs Decoder — the 3 architecture families and when to use each
- Scale & emergent abilities — why bigger models develop unexpected capabilities
Papers
| Year |
Paper |
Venue |
| 2013 |
Word2Vec — Efficient Estimation of Word Representations (Mikolov et al.) |
Google |
| 2014 |
GloVe — Global Vectors for Word Representation (Pennington et al.) |
EMNLP |
| 2016 |
BPE — Neural Machine Translation of Rare Words (Sennrich et al.) |
ACL |
| 2017 |
Attention Is All You Need (Vaswani et al.) |
NeurIPS |
| 2021 |
RoPE — Rotary Position Embedding (Su et al.) |
— |
| 2022 |
InstructGPT/RLHF (Ouyang et al.) |
NeurIPS |
| 2023 |
LLaMA (Touvron et al.) |
Meta |
Slides: lecture_01_llm_embeddings.html
Lab: Lab 01, embeddings
Lecture 2: Tokenization, Embeddings and Similarity
Duration: ~1.5 hours
What you will learn
- Tokenization — BPE algorithm step-by-step, vocabulary sizes, why non-English text costs more tokens
- Why numbers break — how tokenization fragments numbers and why LLMs can’t do arithmetic
- Embeddings — from Word2Vec to modern sentence transformers, GPS analogy for meaning
- Similarity metrics — cosine similarity, dot product, Euclidean distance, and how to interpret scores
- Multilingual alignment — cross-lingual search, domain-specific challenges
- Model selection — MiniLM vs BGE-M3 vs OpenAI, when to use each
Papers
| Year |
Paper |
Venue |
| 2013 |
Word2Vec — Efficient Estimation of Word Representations (Mikolov et al.) |
Google |
| 2014 |
GloVe — Global Vectors for Word Representation (Pennington et al.) |
EMNLP |
| 2016 |
BPE — Neural Machine Translation of Rare Words (Sennrich et al.) |
ACL |
Slides: lecture_02_tokenization_embeddings.html
Lab: Lab 01, embeddings
Lecture 3: Prompt Engineering
What you will learn
- Zero-shot, few-shot, chain-of-thought — five prompting strategies from basic to advanced
- Structured output (JSON) — how to make LLMs production-ready
- Temperature, top-p, top-k — the math behind generation control
- Prompt injection — security attacks and defenses
- The language effect — why English prompts work better even for Italian tasks
Papers
| Year |
Paper |
Venue |
| 2020 |
GPT-3 — Language Models are Few-Shot Learners (Brown et al.) |
NeurIPS |
| 2022 |
Chain-of-Thought Prompting Elicits Reasoning (Wei et al.) |
NeurIPS |
| 2022 |
Rethinking the Role of Demonstrations (Min et al.) |
EMNLP |
| 2023 |
Self-Consistency Improves CoT Reasoning (Wang et al.) |
ICLR |
Slides: lecture_03_prompt_engineering.html
Lab: Lab 02, prompt engineering
Lecture 4: RAG Foundations and the Decision Matrix
Duration: 90 minutes · Pure theory — hands-on lab in Lecture 5 (combined Lab 4 + Lab 5)
What you will learn
- The retrieval problem — why LLMs hallucinate and why frozen knowledge isn’t enough
- RAG architecture — the full two-phase pipeline (offline indexing + online retrieval-augmented generation)
- The retrieval evolution — from Boolean search → TF-IDF → BM25 → dense embeddings
- TF-IDF & BM25 — the math behind term frequency, IDF, term saturation (k₁), and length normalization (b)
- Dense retrieval — cosine similarity, how similar meanings point in the same direction in vector space
- Bi-encoders vs Cross-encoders — why bi-encoders are fast (offline precompute) and when cross-encoders are needed
- Sentence-BERT & contrastive learning — how siamese training pushes similar sentences closer in vector space
- Hybrid retrieval — combining BM25 + dense with α-weighted scores; why normalization is required
- Chunking strategies — fixed-size vs recursive vs semantic (with the split condition formula)
- Chunk size trade-offs — the sweet spot (300–500 tokens + 50–100 overlap) and the paint-mixing dilution analogy
- Metadata filtering — (text, embedding, metadata) tuples; hybrid vector + metadata queries
- Vector databases — KNN vs ANN, HNSW algorithm (the world/country/street map analogy), ChromaDB/Qdrant/FAISS landscape
- RAG prompt design — grounding, refusal, and citation instructions (building on L3 prompt engineering)
- RAG failure modes — 6 failure patterns and their fixes; most failures are retrieval failures
- Decision matrix — Prompting vs RAG vs Fine-Tuning across 7 criteria; the decision flowchart
- Cloud vs Local inference — when to use each
| Concept |
Formula |
| TF-IDF |
TF-IDF(t,d) = TF(t,d) × log(N/df(t)) |
| BM25 |
BM25(q,d) = Σ IDF(tᵢ) · TF·(k₁+1) / (TF + k₁·(1−b+b·|d|/avgdl)) |
| Cosine Similarity |
cos(A,B) = A·B / (‖A‖·‖B‖) ∈ [−1, 1] |
| Retrieval (top-k) |
D* = top-k_{d∈D} cos(E_q(q), E_d(d)) |
| Hybrid score |
score(q,d) = α·BM25(q,d) + (1−α)·cos(embed(q), embed(d)) |
| Semantic chunking |
split at i ⟺ cos(emb(sᵢ), emb(sᵢ₊₁)) < θ |
| RAG objective |
P(y\|x) = Σ_d P(d\|x) · P(y\|x, d) |
Papers
| Year |
Paper |
Venue |
| 1972 |
A Statistical Interpretation of Term Specificity (Spärck Jones) |
Journal of Documentation |
| 2009 |
The Probabilistic Relevance Framework: BM25 and Beyond (Robertson & Zaragoza) |
Foundations & Trends in IR |
| 2019 |
Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks (Reimers & Gurevych) |
EMNLP |
| 2020 |
Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks (Lewis et al.) |
NeurIPS |
| 2020 |
Efficient and Robust ANN Search Using HNSW Graphs (Malkov & Yashunin) |
IEEE TPAMI |
| 2021 |
Billion-Scale Similarity Search with GPUs — FAISS (Johnson, Douze & Jégou) |
IEEE Trans. on Big Data |
| 2021 |
MS MARCO: Benchmarking Ranking Models (Craswell et al.) |
SIGIR |
Slides: lecture_04_rag_foundations.html
Lab: Lab 03, inference benchmarking
Lecture 5: Advanced RAG and Intelligent Routing
Duration: 2 hours · Pure theory — hands-on lab in Lecture 6 (combined Lab 4 + Lab 5 + Lab 6)
What you will learn
- Why naive RAG fails — six failure modes you’ll hit in production and how to diagnose them
- Re-ranking — bi-encoder vs cross-encoder, two-stage retrieval pipelines, 15–30% precision boost
- HyDE — Hypothetical Document Embeddings to bridge vocabulary gaps between queries and documents
- Query rewriting — transforming vague user input into precise search queries
- Parent-child chunking — search on small chunks for precision, read the parent for context
- Hybrid search revisited — Reciprocal Rank Fusion (RRF) to combine rankers without normalization headaches
- Hierarchical indexing — multi-level search for large document collections (1,000+ docs)
- Contextual retrieval — prepending document/section context to chunks before embedding (49% fewer failures)
- Lost in the Middle — why LLMs ignore information in the middle of the context window
- Query decomposition — breaking multi-hop questions into sub-queries (sequential, parallel, conditional)
- Semantic routing — embedding-based and LLM-based routers to send queries to the right data source
| Concept |
Formula |
| RRF Score |
RRF(d) = Σ 1/(k + rank_i(d)) where k=60 |
| Embedding Router |
route* = argmax_r cos(embed(query), embed(route_r)) |
| Re-ranking |
score = CrossEncoder(query ⊕ document) → [0, 1] |
Papers
| Year |
Paper |
Venue |
| 2019 |
Sentence-BERT (Reimers & Gurevych) |
EMNLP |
| 2023 |
Precise Zero-Shot Dense Retrieval without Relevance Labels — HyDE (Gao et al.) |
ACL |
| 2023 |
Lost in the Middle (Liu et al.) |
TACL |
| 2024 |
Contextual Retrieval (Anthropic) |
Blog |
Slides: lecture_05_advanced_rag.html
Lab: Lab 04, query router
Lecture 6: Graph RAG and Knowledge Graphs
Duration: 2 hours · Pure theory — hands-on lab in combined mega-lab (Lab 4 + Lab 5 + Lab 6)
What you will learn
- When vector search isn’t enough — the relationship problem and why cosine similarity can’t follow connections
- Knowledge graph fundamentals — nodes, edges, triples, and the formal definition G = (V, E, R)
- LLM-powered KG construction — entity extraction, relation extraction, deduplication, and schema design
- Graph RAG retrieval — four traversal strategies: 1-hop, 2-hop, subgraph extraction, path finding
- Graph + Vector hybrid — running both in parallel, entity-conditional graph traversal
- Microsoft GraphRAG — community detection (Leiden algorithm), global summarization queries
- RAPTOR — tree-based summarization for global queries without a graph
- LightRAG — incremental updates, dual-level retrieval with key-value pairs, five query modes
- HippoRAG — brain-inspired retrieval with Personalized PageRank, one-shot multi-hop
- Framework selection — decision matrix for choosing the right Graph RAG approach
Papers
| Year |
Paper |
Venue |
| 2024 |
From Local to Global: A Graph RAG Approach to Query-Focused Summarization (Edge et al.) |
Microsoft Research |
| 2024 |
RAPTOR: Recursive Abstractive Processing for Tree-Organized Retrieval (Sarthi et al.) |
ICLR 2024 |
| 2024 |
LightRAG: Simple and Fast Retrieval-Augmented Generation (Guo et al.) |
EMNLP 2025 Findings |
| 2024 |
HippoRAG: Neurobiologically Inspired Long-Term Memory for LLMs (Gutiérrez et al.) |
NeurIPS 2024 |
| 2025 |
PathRAG: Pruning Graph-based RAG with Relational Paths (Chen et al.) |
arXiv |
Slides: lecture_06_graph_rag.html
Lab: Lab 05, Graph RAG
Lecture 7: Agentic RAG and Autonomous Systems
Duration: 2 hours · Theory + hands-on lab
What you will learn
- Why RAG needs agency — the autonomy problem, the capability stack, what makes a system “agentic”
- Function calling & tool use — defining tools, the LLM decides, execute & return, parallel/multi-turn calling
- The Toolformer insight — how LLMs learn to use tools through self-supervision
- The ReAct paradigm — Reason + Act loop, bridging L3 chain-of-thought to autonomous agents
- Self-RAG — the model decides when to retrieve, with reflection tokens
- Corrective RAG (CRAG) — confidence scoring, web fallback, knowledge refinement
- Multi-agent systems — sequential (pipeline) and hierarchical (supervisor) patterns
- Guardrails & safety — preventing agent misuse, production considerations
- When NOT to use agents — the cost of agency, decision framework
Papers
| Year |
Paper |
Venue |
| 2023 |
Toolformer: Language Models Can Teach Themselves to Use Tools (Schick et al.) |
NeurIPS 2023 (Oral) |
| 2023 |
ReAct: Synergizing Reasoning and Acting in Language Models (Yao et al.) |
ICLR 2023 |
| 2024 |
Self-RAG: Learning to Retrieve, Generate, and Critique (Asai et al.) |
ICLR 2024 (Oral) |
| 2024 |
Corrective Retrieval Augmented Generation (Yan et al.) |
NAACL 2024 |
| 2024 |
Adaptive-RAG: Learning to Adapt Retrieval-Augmented LLMs through Question Complexity |
arXiv 2024 |
Slides: lecture_07_agentic_rag.html
Lab: Lab 06, SQL agent
Lecture 8: RAG Evaluation and Observability
What you will learn
- The “it looks good” trap — why subjective evaluation fails at scale
- Retrieval metrics — Precision@K, Recall@K, MRR, nDCG, Hit Rate with formulas and worked examples
- Answer quality — faithfulness, relevance, completeness, factual consistency
- RAGAS framework — automated evaluation pipeline (EACL 2024)
- LLM-as-Judge — prompt design, worked examples, biases and limitations
- Production observability — tracing, attribution, cost monitoring (LangSmith, Langfuse)
Slides: lecture_08_rag_evaluation.html
Lab: Lab 07, the RAG mega-lab
Lecture 9: Efficient Fine-Tuning (LoRA and QLoRA)
What you will learn
- When to fine-tune vs RAG — decision matrix revisited with flowchart
- LoRA — the low-rank hypothesis, decomposing weight updates into A × B matrices (ICLR 2022)
- QLoRA — 4-bit quantization for laptop-scale training (NeurIPS 2023)
- Training essentials — chat templates, loss masking, NEFTune, gradient accumulation, Flash Attention
- Overfitting prevention — detection and mitigation strategies
- Beyond SFT — DPO vs RLHF, Thinking SFT (2024–2025)
Slides: lecture_09_finetuning.html
Lab: Lab 08, LoRA fine-tuning
Lecture 10: Modern LLM Architectures and Multimodal AI
What you will learn
- Mixture of Experts (MoE) — replacing FFN with N experts + router, per-token gating, load balancing
- MoE model landscape — Mixtral, DeepSeek-V3, Qwen2-MoE, GPT-4 (rumored)
- Key trade-off — MoE saves compute, not memory
- Multimodal AI — the universal pattern: Signal → Encoder → Projection → Transformer Decoder
- Image (ViT + CLIP), Audio (Whisper), Video — encoders, token costs, and the quadratic explosion
- Production essentials — KV cache with GQA, PagedAttention, continuous batching, speculative decoding
Slides: lecture_10_multimodal_production.html
Lab: Lab 09, vision-language models, Lab 10, production deployment
Running the labs
You need Python 3.10 or newer and a free Google AI Studio key from
aistudio.google.com/apikey. Some labs can also use DeepSeek or a
local Ollama model; the options are listed in .env.example.
git clone https://github.com/KamyarZeinalipour/zucchetti-llm-course.git
cd zucchetti-llm-course
python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env # then add your GOOGLE_API_KEY
Run a lab as a script from its folder, for example cd lab_01_embeddings && python lab_01_embeddings.py,
or open its notebook in Jupyter from the same folder. Labs 04 to 06 and 10 share the client in
common/llm.py, and read the HR policies in lab_07_evaluation/data/policies/. Lab 08 trains a
model and needs a GPU; Google Colab works.
Repository
slides/ the ten lecture decks (HTML) and their images
lab_01 ... 10 one folder per lab: script, notebook, solutions, README, data
common/ the LLM client shared by several labs
Troubleshooting
| Problem |
Fix |
ModuleNotFoundError |
Run pip install -r requirements.txt in the activated environment |
| Rate limit (429) |
The free tier allows about 15 requests a minute; wait 30 seconds and retry |
| API key not accepted |
Check the key at aistudio.google.com/apikey and that .env is in the repository root |
| Slides look broken |
Use Chrome or Firefox |
License
Written by Kamyar Zeinalipour for a course at Zucchetti S.p.A. and shared for teaching and learning.
The lab datasets are small samples prepared for the course; the company policies, patient records
and documents in them are invented.