Interactive lesson · Python · NLP pedagogy

Teaching NLP with Python

Explore how text moves from raw language to tokens, vectors, search results, and a simple classifier. Each interaction is paired with readable Python so the method stays visible rather than disappearing behind the output.

No setup required. The demonstrations run in this page and mirror the computational steps shown in the accompanying Python examples. Visitors can explore the concepts without installing Python or opening a notebook.

The pipeline students build

Raw text›Clean and tokenize›Vectorize›Model›Evaluate

The next three tabs walk through the middle of this pipeline. Each one runs in your browser as a JavaScript re-creation of what the Python code does, so you can change inputs and see results without installing anything.

Libraries by job

NLTK

The classic teaching library: tokenizers, stemmers, stopword lists and corpora. Good for showing each step by hand.

spaCy

Production-grade pipelines for tokens, lemmas, part-of-speech tags and named entities in a few lines.

scikit-learn

CountVectorizer, TfidfVectorizer and classifiers with one consistent fit/predict interface.

Hugging Face transformers

Pretrained models through pipeline("sentiment-analysis"). Shows students what modern NLP builds on.

gensim

Word embeddings and topic models for exploring meaning as geometry.

Jupyter and Colab

Notebooks mix code, output and notes, and Colab removes install problems for the whole class.

A four-week sample unit

Week 1: Text as data

Strings, regular expressions, re.findall, word counts with collections.Counter. Goal: count words in a short text by hand.

Week 2: Vectors and similarity

Bag of words, TF-IDF, cosine similarity. Goal: build a tiny search engine over ten documents.

Week 3: Classification

Naive Bayes and logistic regression on labeled reviews, with train/test splits and accuracy. Goal: explain why a model made a prediction.

Week 4: Pretrained models and ethics

Run a transformer pipeline, compare it with the week 3 model, and examine bias in training data.

Teaching tip: make students predict which words will matter before they see the model's weights. Wrong guesses make the lesson stick.