Generative AI Tutorials
All tutorials
61 free tutorials, in the order we recommend reading them.
LLM Fundamentals · Generative AI Foundations
What is an LLM? How Large Language Models Actually Work
Learn what an LLM is: tokens, next-token prediction, training vs inference, context windows and temperature, with a runnable bigram text generator in Python.
Tokenization Explained: How LLMs Split Text into Tokens
Learn how LLM tokenization works: subwords, byte-pair encoding, token IDs and why Hindi costs more tokens. Train a tiny BPE tokenizer in Python.
Embeddings Explained: How AI Turns Meaning into Vectors
Embeddings explained simply: words and sentences as vectors, cosine similarity in numpy, a bag-of-words baseline and how semantic search ranks results.
Transformers and Attention Explained: How LLMs Read Context
Understand the transformer behind every LLM: queries, keys and values, the causal mask, multi-head attention and transformer blocks, with numpy code.
How LLMs Are Trained: Pretraining, SFT and RLHF Explained
See how LLMs are trained in stages: pretraining, supervised fine-tuning, RLHF and DPO, and reasoning RL, with the loss behind each stage in Python.
Mixture of Experts (MoE) Explained: How Sparse LLMs Work
Mixture of experts explained: how a router picks experts, total vs active parameters, load balancing, and why MoE LLMs still need lots of memory.
LLM Generation Parameters: Temperature, Top-p, Top-k Guide
A practical guide to LLM generation parameters: temperature, top-k, top-p, min-p, penalties, max tokens and stop sequences, with settings by task.
LLM Decoding Strategies: Greedy, Beam Search and Sampling
Compare LLM decoding strategies: greedy decoding, beam search, sampling, constrained and speculative decoding, with runnable Python toy examples.
How to Run LLMs Locally: Ollama, llama.cpp and LM Studio
Run LLMs locally step by step with Ollama, LM Studio or llama.cpp. Check speed and memory for your laptop and call a local model from Python.
Prompting and Context · Prompt and Context Engineering
Prompt Engineering Guide: Write LLM Prompts That Work Reliably
A practical prompt engineering guide: roles, clear instructions, few-shot examples, JSON output, step-by-step caveats and Python prompt templates you can run.
Prompting Techniques for Reasoning: CoT, Self-Consistency, ToT
Learn reasoning prompting techniques: chain-of-thought, self-consistency voting and Tree of Thoughts, with runnable Python simulations and cost trade-offs.
Structured Output in LLMs: JSON Prompting and Schema Guide
Get reliable JSON from LLMs: JSON mode vs schema-constrained output, schema design rules, Pydantic with the OpenAI SDK, and a validate-and-retry loop.
Context Engineering Explained: What Goes Into an LLM's Context
Context engineering explained: the six kinds of context, the write, select, compress and isolate moves, token budgets and chat history compression in Python.
Prompt Injection Explained: Attacks and How to Defend LLM Apps
Understand direct and indirect prompt injection, why keyword filters fail, and layered defences: least privilege, taint tracking, approvals and link filtering.
RAG Tutorial · Retrieval-Augmented Generation
What is RAG? Retrieval-Augmented Generation Explained Simply
What is RAG? Learn retrieval-augmented generation step by step: chunking, indexing, retrieval and prompt augmentation, with a runnable TF-IDF demo in Python.
Vector Databases Explained: How RAG Stores and Finds Embeddings
What a vector database stores, how IVF and HNSW indexes speed up search, why metadata filters matter, and when numpy, Chroma or pgvector is enough for RAG.
RAG Chunking Strategies: Fixed, Recursive, Semantic and More
Compare five RAG chunking strategies with runnable Python: sentence, recursive, heading-based and semantic splitting, plus a test that measures retrieval hits.
Hybrid Search and Re-ranking for RAG: BM25, RRF, Cross-Encoders
Learn hybrid search for RAG: BM25 written by hand, Reciprocal Rank Fusion, weighted fusion and cross-encoder re-ranking, with runnable Python and a recipe.
Advanced RAG Architectures: Rewriting, Routing, Corrective RAG
Advanced RAG architectures explained: query decomposition, routing, small-to-big retrieval, corrective RAG, GraphRAG and agentic RAG, and when to use each.
HyDE in RAG: Hypothetical Document Embeddings Explained
HyDE explained: search with an LLM-written hypothetical answer instead of the question. See why it works, when it drifts, and how to anchor it in Python.
RAG vs CAG: Cache-Augmented Generation vs Retrieval Explained
RAG vs CAG compared: how cache-augmented generation preloads a KV cache, when the knowledge fits, memory and token maths in Python, and hybrid designs.
RAG Evaluation: Metrics to Test Retrieval and Answer Quality
How to evaluate a RAG system: hit rate, recall@k, MRR, faithfulness and answer relevance, a golden question set, LLM judges and a repeatable test loop.
Hugging Face and Fine-tuning · Hugging Face and Open Models
Hugging Face Tutorial: Hub, Transformers, Pipelines and Spaces
Learn Hugging Face step by step: the Hub, model cards and licences, tokenizers, pipeline(), AutoModel, datasets, hosted inference and Gradio Spaces.
Open-Source LLMs Explained: Sizes, Quantisation and Licences
Open-source LLMs explained: open-weight vs closed models, parameter sizes, what fits on a laptop, 4-bit quantisation maths, GGUF and ONNX, and licences.
Fine-Tuning LLMs with LoRA: When, Why and How It Works
When to fine-tune an LLM instead of prompting or RAG, how LoRA and QLoRA work, how to prepare instruction data, and a transformers plus peft example.
Prompting vs RAG vs Fine-tuning: How to Choose for an LLM App
Prompting vs RAG vs fine-tuning: diagnose failures first, compare cost per month, and learn when to combine them, with runnable Python decision tools.
Instruction Dataset Creation for LLM Fine-tuning: Practical Guide
Build an instruction fine-tuning dataset: coverage grids, synthetic data, quality filters, near-duplicate removal and group splits, with Python and TRL code.
SFT vs RLHF vs GRPO: Choosing an LLM Post-training Method
Compare SFT, RLHF, DPO and GRPO: training signals, data, compute and when to use each, with runnable DPO loss and GRPO advantage code plus TRL examples.
Gradio and Hugging Face Spaces: Build a Streaming LLM Demo
Build an LLM chat demo with Gradio 6 and deploy it on Hugging Face Spaces: streaming replies, chat history, secrets, ZeroGPU and calling it from Python.
Build an LLM from Scratch · Build an LLM: Plan and Data
Build a Small LLM from Scratch: The Complete 2026 Roadmap
A step-by-step roadmap to build a 25M–100M parameter LLM on one GPU: tokenizer, data, architecture, pretraining, SFT, alignment, evaluation and deployment.
Train a BPE Tokenizer for Your LLM: Vocab Size and Chat Tokens
Train a byte-level BPE tokenizer for a small LLM: the merge loop in plain Python, choosing vocab size, chat special tokens and Hugging Face tokenizers code.
LLM Training Data Preparation: Pretraining and Chat Datasets
Prepare LLM training data step by step: token budgets, cleaning and dedup, packing into blocks, uint16 token files, and chat, DPO and RL formats.
Small LLM Architecture in Code: RMSNorm, RoPE, GQA and SwiGLU
Build a small decoder-only LLM in PyTorch: count parameters, then code RMSNorm, RoPE, grouped-query attention and SwiGLU with runnable numpy demos.
Build an LLM from Scratch · Build an LLM: Training
Pretrain an LLM from Scratch: Loss, LR Schedule and Checkpoints
Pretrain a small LLM in PyTorch: next-token loss, warmup and cosine LR, bf16, gradient accumulation, checkpoints, resuming and reading the loss curve.
Supervised Fine-Tuning Tutorial: From Base LLM to Chat Model
Supervised fine-tuning in PyTorch: render chats with a ChatML template, mask the loss to assistant tokens, pick SFT hyperparameters and test your chat model.
LLM Knowledge Distillation: Teacher Data and Reasoning Traces
Distil a small LLM from a bigger teacher: black-box SFT on teacher text, white-box KL with temperature, and clean reasoning data with think tags.
DPO Training Tutorial: Align a Small LLM with Preference Pairs
Train a small LLM with DPO: preference pair format, the loss from log-probs, choosing beta, a PyTorch loop and the reward curves that warn of trouble.
PPO and GRPO for LLMs: Hands-On RL, CISPO and Tool Calling
Hands-on PPO and GRPO for small LLMs: rewards, group advantages, GAE, the CISPO loss tweak and agentic RL for tool calling, with runnable numpy code.
Build an LLM from Scratch · Build an LLM: Evaluate and Ship
How to Evaluate a Small LLM: Loss, Benchmarks and RoPE Tests
Evaluate the small LLM you trained: loss and perplexity checks, a fixed prompt set, lm-evaluation-harness benchmarks and RoPE length extrapolation.
Deploy a Small LLM: Transformers, GGUF, Ollama and OpenAI API
Export your own small LLM to Transformers format, convert it to GGUF, quantise it, run it in Ollama or vLLM and serve an OpenAI-compatible API.
LLMOps and MLOps · MLOps
What is MLOps? A Beginner's Guide to Machine Learning Operations
MLOps explained for beginners: why models fail quietly after launch, what an MLOps system includes, MLOps vs DevOps, and three maturity levels, with Python.
ML Lifecycle: The 8 Stages of a Machine Learning System
The machine learning lifecycle in 8 stages, from metric and baseline to monitoring and retraining, with runnable Python showing why time-based splits matter.
ML Reproducibility and Versioning: Data, Code, Seeds, Models
Make ML models reproducible: version code, data, config, environment and model files. Hash data in Python, fix seeds, and use DVC and the MLflow registry.
Data Pipelines for ML: ETL, Validation and Train/Serve Skew
Build a data pipeline for machine learning: extract, validate, transform, load, idempotent backfills, Airflow scheduling, and a runnable train/serve skew demo.
Feature Stores and Data Leakage: Point-in-Time Correct ML
What a feature store is, how data leakage inflates scores, and how point-in-time joins with pandas merge_asof and Feast keep training and serving consistent.
ML Model Deployment: Serve a Model as a REST API with FastAPI
Deploy an ML model as an API: choose batch or online serving, serialise with joblib, validate input with FastAPI and Pydantic, and release by shadow or canary.
Docker for Machine Learning: Package and Ship a Model API
Docker for machine learning: write a Dockerfile for a FastAPI model, use layer caching, keep images small and safe, tag by model version, and run Compose.
Kubernetes for ML Engineers: Deploy and Scale a Model API
Kubernetes for ML: Deployments, Services, readiness probes and HPA autoscaling for a model API, with YAML, kubectl commands and Python simulations you can run.
ML Model Monitoring and Data Drift: PSI, KS Test and Alerts
Monitor ML models in production: data drift vs concept drift, PSI and KS statistics computed by hand in Python, delayed labels, Evidently and Prometheus alerts.
CI/CD for Machine Learning: Tests, Quality Gates and Releases
CI/CD for machine learning: unit, data and behavioural tests, a quality gate against the champion model, a GitHub Actions workflow, canary release and CT.
LLMOps and MLOps · LLMOps
What is LLMOps? Running LLM Apps in Production, Explained
LLMOps explained: how it differs from MLOps, the lifecycle from prompt change to traced production, token-cost maths and a release gate, with runnable Python.
LLM Evaluation Methods: Metrics, Golden Sets and a Python Harness
Evaluate LLM apps: exact match, token F1 and rubric scoring in Python, building a golden set, a bootstrap check for real gains, and a DeepEval G-Eval example.
LLM-as-a-Judge: Rubrics, Biases and Cohen's Kappa Calibration
LLM-as-a-judge explained: single, pairwise and reference grading, JSON judge prompts, position bias, and calibration against humans with Cohen's kappa.
Red Teaming LLM Apps: Attack Suites, Success Rates and Fixes
Red team an LLM chatbot: build a threat model, generate attacks from seeds and strategies, score attack success rate in Python, and automate with promptfoo.
KV Cache Explained: How LLMs Reuse Attention and Use GPU Memory
What the KV cache is, why it makes LLM generation fast, prefill vs decode, a numpy speed-up demo, and the formula for KV cache memory with GQA and 8-bit caches.
LLM Inference Optimization: Batching, Quantisation and Speed
LLM inference optimization: TTFT and TPOT, why decoding is memory-bound, continuous batching and speculative decoding simulated in Python, and a tuning order.
vLLM Tutorial: Serve LLMs with PagedAttention and an OpenAI API
Serve LLMs with vLLM: how PagedAttention works, vllm serve flags, OpenAI client calls, capacity planning maths, Docker, vllm bench serve and Prometheus metrics.
LLM Observability and Tracing: Spans, Latency, Cost, Feedback
LLM observability explained: traces and spans, what to log, PII masking, p95 latency, cost by prompt version, and OpenTelemetry GenAI and Langfuse tracing code.
LLMOps and MLOps · Career Guide
Generative AI Roadmap: Skills, Projects and Jobs for Freshers
A Generative AI roadmap for freshers: the skills to learn, a six-stage path, three portfolio projects (RAG, MCP, agent) and how to study GenAI in Indore.
Generative AI Projects: 10 Portfolio Ideas with Architecture
Ten Generative AI portfolio projects with architecture outlines, metrics and stretch goals, from a bilingual RAG bot to a vLLM load test and an eval suite.
Generative AI Interview Questions: 30 Questions with Answers
30 Generative AI interview questions with crisp answers on LLMs, prompting, RAG, fine-tuning, agents, evaluation and serving, plus a system design framework.