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.

Interactive lesson + applied capstone · 5–10 minutes

Context Before Count

Learning objective: Use keyword-in-context (KWIC) evidence to explain why a word count alone cannot establish a speaker’s attitude.

Choose a term, inspect the highlighted words, and compare the surrounding language. These three passages are invented for instruction. The exercise uses JavaScript to demonstrate the KWIC step of my Python Corpus Explorer; it does not execute Python, spaCy, TF-IDF, or sentiment analysis.



Which conclusion does this evidence support?



Choose an answer, then check your interpretation.

Apply it: write an evidence-based interpretation

Using the examples above, identify the source IDs, quote the words that shape your interpretation, and state one limit of the count. For the full capstone, repeat this process with three short, rights-cleared passages: preserve source IDs, record each occurrence and its context, consider a competing interpretation, and explain what additional evidence your claim would need.


Your response stays in this page’s memory until you leave or reload. This exercise does not transmit or save it. Download a copy to keep it. Use the synthetic passages here; do not enter personal or confidential information.


Capstone assessment rubric

Score each criterion from 0 to 2 (8 points total). Use the descriptors to revise; the page does not automatically grade written work.

Traceable evidence

2: Each quoted context has a matching source ID. 1: Some IDs or quotations are incomplete. 0: Evidence cannot be traced.

Contextual interpretation

2: Explains how contrasting language or negation affects meaning. 1: Notices a difference without explaining it. 0: Treats occurrences as equivalent.

Competing explanation

2: Tests a plausible alternative against the passages. 1: Names an alternative without testing it. 0: Gives no alternative.

Limits of the claim

2: Distinguishes count from interpretation and identifies needed evidence. 1: Gives a general caution. 0: Claims more than the passages support.

Designed by Laura Elizabeth Hand. Adapted from the KWIC routine in 1_corpus_explorer.py (Python Corpus Explorer teaching artifact). Synthetic examples and this assessment are new instructional materials.