Complete for freeAdvanced

Course 21

Natural Language Processing and Generative AI

This course takes text from raw characters to grounded, checked answers, and every step is something you build and measure. You'll normalize and tokenize text, train a byte-pair-encoding tokenizer from scratch, learn word vectors from co-occurrence counts, and compare one-hot, count, TF-IDF, and embedding representations. Then you'll rank documents by cosine similarity, train naive Bayes and logistic regression classifiers on realistic support tickets, and evaluate them honestly with confusion matrices, cross-validation, and confidence thresholds. Module 4 opens up a real transformer: you'll run a named-entity model from the Hugging Face Hub, combine it with regex rules, and follow a sentence from tokens to ids to logits, then chart its attention heads. Later modules cover attention and context budgets, prompts with structured outputs and validation, retrieval-augmented generation with citations, hallucination checks, the choice between retrieval and fine-tuning, and evaluation before deployment. You work in Google Colab with scikit-learn, NumPy, matplotlib, and Hugging Face transformers. Code that runs on the lesson pages uses small datasets typed into the cell, and the output you see came from actually running it; cells that download models are marked to run in Colab, with their real output shown. Later modules can call a hosted model through the Gemini API's free tier or a local model through Ollama, and include offline stand-ins so they also work without a key. Each core module has a Notes lesson, a Build-along, and a Practice set with hints and worked solutions, and the course ends with a capstone: a grounded question-answering system for documents you choose.

Free completion promise: Every lesson can be completed for $0. Google Colab's free tier runs every notebook, the libraries and models are open and free to download, the datasets are typed into the lessons, and the lessons that can use a hosted language model also run with an offline stand-in, so no paid service or API key is ever required.

What's inside

  • 24hand-written lessons
  • 25videos
  • 4step-through animations
  • 21diagrams, charts & live previews
  • 53quiz questions
  • 193code examples

Before you begin

Requirements & setup for Natural Language Processing and Generative AI

Start with the complete free pathway below. Hardware, subscriptions, paid APIs, and cloud credits are never required.

Start here ยท free path

Your complete $0 setup

Every lesson can be completed for $0. Google Colab's free tier runs every notebook, the libraries and models are open and free to download, the datasets are typed into the lessons, and the lessons that can use a hosted language model also run with an offline stand-in, so no paid service or API key is ever required.

$0 required

Setup checklist

0 of 12 complete

This checklist is a temporary setup aid and resets when the page reloads. Saved course progress begins in the setup lessons below.

  1. Everything required for this course is free. Paid software, APIs, cloud credits, GPUs, and physical equipment are optional.

    About 2 min
  2. Go to colab.research.google.com and sign in with a Google account (a personal account is the safe choice if your school account blocks Colab).

  3. Choose File > New notebook in Drive, then click the Untitled name at the top left and rename the notebook.

    About 5 min
  4. Run the version-check cell from the first lesson; if transformers or scikit-learn is missing or too old, run %pip install -q -U transformers (or scikit-learn) and choose Runtime > Restart session.

    About 5 min
  5. Run the first-lesson check cell, which downloads the dslim/distilbert-NER model and confirms it finds a person and a place in a test sentence.

    About 5 min
  6. Every lesson works in Google Colab (free) with Hugging Face transformers and scikit-learn, so Free Hugging Face account and read token is never required.

  7. If you have Free Hugging Face account and read token, use it where a lesson mentions it and compare your result with the lesson's.

    About 5 min
  8. If it doesn't match, finish that step in Google Colab (free) with Hugging Face transformers and scikit-learn and keep going.

    About 5 min
  9. Every lesson works in Google Colab (free) with Hugging Face transformers and scikit-learn, so Python 3.10+ with JupyterLab on your own computer is never required.

  10. If you have Python 3.10+ with JupyterLab on your own computer, use it where a lesson mentions it and compare your result with the lesson's.

    About 5 min
  11. If it doesn't match, finish that step in Google Colab (free) with Hugging Face transformers and scikit-learn and keep going.

    About 5 min
  12. Google Colab (free) with Hugging Face transformers and scikit-learn: The version cell prints "Ready for the course", and the check cell prints [('PER', 'Ada Lovelace'), ('LOC', 'London')] followed by "Model download and inference: OK". Free Hugging Face account and read token: The version cell prints "Ready for the course", and the check cell prints [('PER', 'Ada Lovelace'), ('LOC', 'London')] followed by "Model download and inference: OK". Python 3.10+ with JupyterLab on your own computer: The version cell prints "Ready for the course", and the check cell prints [('PER', 'Ada Lovelace'), ('LOC', 'London')] followed by "Model download and inference: OK".

    About 5 min

Software

1 item

Google Colab (free) with Hugging Face transformers and scikit-learn

Colab is Google's free hosted Jupyter notebook. Python runs on a Google machine and notebooks save to your own Google Drive, so it works on any computer with a browser, Chromebooks included. transformers, PyTorch, scikit-learn, NumPy, and matplotlib come preinstalled, and models download from the Hugging Face Hub onto the Colab machine. The free CPU runtime is enough for every lesson; a free T4 GPU runtime is optional and only makes transformer cells faster.

Course need
Google Colab (free) with Hugging Face transformers and scikit-learn
Free

Colab is Google's free hosted Jupyter notebook. Python runs on a Google machine and notebooks save to your own Google Drive, so it works on any computer with a browser, Chromebooks included. transformers, PyTorch, scikit-learn, NumPy, and matplotlib come preinstalled, and models download from the Hugging Face Hub onto the Colab machine. The free CPU runtime is enough for every lesson; a free T4 GPU runtime is optional and only makes transformer cells faster. Every lesson is readable text with copyable code, keyboard-friendly quizzes and step-throughs, and videos with YouTube captions.

  1. Go to colab.research.google.com and sign in with a Google account (a personal account is the safe choice if your school account blocks Colab).
  2. Choose File > New notebook in Drive, then click the Untitled name at the top left and rename the notebook.
  3. Run the version-check cell from the first lesson; if transformers or scikit-learn is missing or too old, run %pip install -q -U transformers (or scikit-learn) and choose Runtime > Restart session.
  4. Run the first-lesson check cell, which downloads the dslim/distilbert-NER model and confirms it finds a person and a place in a test sentence.

Hardware

2 items

Free Hugging Face account and read token

Optional. Every model in the course is public; a token stored in Colab Secrets as HF_TOKEN only raises download rate limits and unlocks gated models.

Optional
Google Colab (free) with Hugging Face transformers and scikit-learn
Free

Optional. Every lesson can be completed with Google Colab (free) with Hugging Face transformers and scikit-learn; Free Hugging Face account and read token is an extra for learners who have it. Optional equipment: every assessed outcome can be completed without it.

  1. Every lesson works in Google Colab (free) with Hugging Face transformers and scikit-learn, so Free Hugging Face account and read token is never required.
  2. If you have Free Hugging Face account and read token, use it where a lesson mentions it and compare your result with the lesson's.
  3. If it doesn't match, finish that step in Google Colab (free) with Hugging Face transformers and scikit-learn and keep going.

Python 3.10+ with JupyterLab on your own computer

Optional. A local install works offline and has no session limits; the first lesson has the steps for Windows, macOS, and Linux.

Optional
Google Colab (free) with Hugging Face transformers and scikit-learn
Free

Optional. Every lesson can be completed with Google Colab (free) with Hugging Face transformers and scikit-learn; Python 3.10+ with JupyterLab on your own computer is an extra for learners who have it. Optional equipment: every assessed outcome can be completed without it.

  1. Every lesson works in Google Colab (free) with Hugging Face transformers and scikit-learn, so Python 3.10+ with JupyterLab on your own computer is never required.
  2. If you have Python 3.10+ with JupyterLab on your own computer, use it where a lesson mentions it and compare your result with the lesson's.
  3. If it doesn't match, finish that step in Google Colab (free) with Hugging Face transformers and scikit-learn and keep going.

Accounts

Nothing required

No external account is needed for this course.

What you will be able to do

Learning outcomes

  • Normalize and tokenize text, train a BPE tokenizer from scratch, and explain how subword vocabularies handle words they have never seen.
  • Represent text as counts, TF-IDF vectors, and learned embeddings, and use cosine similarity to search and deduplicate documents.
  • Train and evaluate text classifiers with pipelines, cross-validation, confusion matrices, and confidence thresholds, and explain their mistakes.
  • Extract entities with BIO tagging, combine a transformer NER model with rules, and score extractors at the span level.
  • Inspect a transformer's tokens, logits, and attention weights, and explain attention, masks, and context-window limits.
  • Build and evaluate a privacy-aware, retrieval-grounded question-answering system that validates its output and cites its sources.

Build real work

Assignments & capstone

Free tools accepted

Support-ticket triage tool

In a seeded Colab notebook, train a TF-IDF and logistic regression classifier on labelled support tickets, hold out a test set, prove each improvement with cross-validation, add similar-case search, and send low-confidence tickets to a human.

Every lesson can be completed for $0. Google Colab's free tier runs every notebook, the libraries and models are open and free to download, the datasets are typed into the lessons, and the lessons that can use a hosted language model also run with an offline stand-in, so no paid service or API key is ever required. Submit your project file, or screenshots with descriptions, or a short demo.

Retrieval pipeline with checked citations

Chunk a small set of non-sensitive documents with overlap, retrieve with TF-IDF, pack a grounded prompt with numbered sources into a token budget, and reject any reply that fails its schema or cites a source it was never shown.

Every lesson can be completed for $0. Google Colab's free tier runs every notebook, the libraries and models are open and free to download, the datasets are typed into the lessons, and the lessons that can use a hosted language model also run with an offline stand-in, so no paid service or API key is ever required. Submit your project file, or screenshots with descriptions, or a short demo.

Final assessment

Grounded document Q&A

Build a question-answering system over documents you're allowed to use, such as class syllabi or a club handbook: scrub and chunk them, retrieve with a measured hit rate, answer in a strict schema with citations, and abstain when checks fail. Deliverables: Colab notebook with the full pipeline, Eval set of 25+ questions, a fifth unanswerable, with a launch gate, Unit tests for the checks, Limits statement with real numbers, and Five-minute presentation that shows a failure.

Prerequisites & pacing

Skills assumed

  • Python: functions, lists, dictionaries, loops, and reading a traceback
  • NumPy basics: arrays, shapes, indexing, and matrix multiplication
  • One complete scikit-learn workflow: train_test_split, fit, predict, and score
  • Classification metrics: accuracy, precision, and recall

Recommended prior courses

These are advisory, not locks. If you already have the skills listed above, enroll directly.

Choose your pace

  • self paced: 12 weeks at 5 hours per week
  • weekly: 12 weeks at 5 hours per week

Part of this learning path

Course created by Zafir Shamsi.