Applied Natural Language Processing

August 14, 2026 ยท View on GitHub

Code for the course notes Natural Language Processing: From Corpus Statistics to Grounded LLMs, which you can read in full at https://nlp.jcrlabz.com.

Read the book

Online at https://nlp.jcrlabz.com, or as a PDF: download the latest build. The PDF is republished from the same source every time the site is, so the two never disagree.

What is here

book/worked-examples/ holds one notebook per worked example. Each reproduces a table printed in the book, so you can check any number the text claims rather than take it on trust.

Archive/ holds the demonstration notebooks from earlier runs of the course. They are kept for reference and are not maintained.

Running an example

Click any notebook below and it opens in Colab. Choose Runtime > Run all.

Every notebook is self contained. The first cell defines everything the example needs and runs in the notebook itself, so there is no data file to fetch and nothing to install beyond what the install cell installs.

Colab opens a notebook from GitHub read only. Click Copy to Drive to keep your changes.

Read the chapter first. The notebook is the check, not the explanation.

The worked examples

notebookwhat it showschapter
bridging_the_gapOne request, three answers1. What Natural Language Processing Is
edit_distanceEdit distance, every cell2. Corpora and Preprocessing
empirical_lawsZipf and Heaps, fitted3. The Empirical Laws of Text
weightingtf-idf and PMI, by hand4. Term Weighting and Similarity
bpeBPE, five merges5. Subword Tokenisation
halHAL, ramped and asymmetric7. Count Vectors, PPMI, and SVD
coalsCOALS, all three steps7. Count Vectors, PPMI, and SVD
svdSVD, and what truncation costs7. Count Vectors, PPMI, and SVD
svd_rankChoosing K from the spectrum7. Count Vectors, PPMI, and SVD
word2vecword2vec, one step at a time9. Learned Word Embeddings
factorisationThree methods, one matrix9. Learned Word Embeddings
ngram_lmSmoothing, perplexity and the U-curve10. n-gram Language Models and Perplexity
neural_lmA neural LM, counted and trained11. Neural Language Models
rnnUnrolling, and the vanishing gradient12. Recurrent Networks
gatedThe gradient highway13. Gated Recurrence: LSTM and GRU
classificationAccuracy, F1 and a confusion matrix14. Text Classification and Evaluation
contextualWhat one vector per word costs15. Contextual Embeddings
attentionSelf-attention, one query at a time16. Self-Attention and the Transformer
decodingGreedy, beam, temperature, top-p18. Steering LLMs: Decoding and Prompting
bleuBLEU, ROUGE and their blind spots21. Evaluating Generated Text
ibm_model1EM learning an alignment24. Machine Translation

About this file

This README and the notebooks in book/worked-examples/ are generated from the book source and pushed here on every publish, so edits made to them here are overwritten. Everything else in the repository is edited by hand and is left alone. Report a problem with an example against the book at https://nlp.jcrlabz.com.