Natural Language Processing

Follow text from Unicode and token counts to document retrieval and grounded answers.

Follow text from Unicode and token counts to document retrieval and grounded answers.

Before you start. Machine Learning and the attention lesson in Deep Learning.

Use Python 3.12 for the examples. Install the dependencies with python -m pip install numpy scikit-learn torch. Run each week as a separate script. Try the worked example on paper first, then change one assumption in the lab and explain the result. All datasets are small or generated locally.

The 12 weeks

WeekLessonWhat you’ll do
1Text, Unicode, and tokenizationCompare code points, bytes, and tokens before counting text.
2Bag of words and TF–IDFBuild a baseline and inspect the terms that drive its predictions.
3N-grams, smoothing, and perplexityAssign probability to unseen transitions and measure the cost on held-out text.
4Word embeddings and similarityCompare a sparse context vector with a compressed representation.
5Sequence labelling and entity-level F1Measure entity boundaries separately from token accuracy.
6Sequence-to-sequence modelsCompare a decoder trained on the right prefix with its own generated prefix.
7Transformers for languageCompare causal and bidirectional masks on the same sequence.
8Pretraining objectivesCompare predicting the next token with reconstructing a token from both sides.
9Decoding and adaptationCompare greedy and sampled outputs, then measure a small adaptation.
10Search and retrievalCompare keyword and dense retrieval with a known relevance label.
11Grounded answering and abstentionSeparate retrieval misses from unsupported answers.
12Capstone · Answer questions from documents with citationsCompare a naive answerer with a retriever that can abstain.

Further reading · Jurafsky and Martin · Speech and Language Processing