Experience Projects Tech stack About Contact
Back to projects
Python NLP Language Modelling

N-Gram Language Model

A from-scratch n-gram language model trained on the Lord of the Rings trilogy. Built up from bigrams to a full backoff model with Kneser-Ney smoothing, and deployed as an interactive text generator.

Year 2026
Type Personal
Status Completed
Screenshot of the N-gram language model website

Overview

This project is a Python implementation of n-gram language models, trained on the Lord of the Rings trilogy. Starting from the simplest version, a bigram, the project builds up through n-grams, then layers on three important improvements: pruning, backoff and Kneser-Ney smoothing.

The end result is a text generator that produces new Tolkien-like sentences. You can try it yourself at ngram.koenkaandorp.nl.