Small, self-contained examples that go with the attribution-based-control.ai Chapter II tutorial. Each section of the chapter is one directory with one script. cd into it, run the script, and the output matches the chapter line for line.
No dependencies beyond Python's standard library.
section1_ngram_basic/— trigram counts, next-word probabilities. ~30 lines.section2_ngram_attribution/— the same trigram counter, now keyed per author so each prediction comes with a per-author credit breakdown.
More sections will land here as the chapter grows.
python3 section1_ngram_basic/ngram_toy.py
python3 section2_ngram_attribution/ngram_toy.pydata/ holds shakespeare.txt (~1.1 MB) and tinystories.txt (~1.4 MB), used by later sections that actually train a language model. Sections 1 and 2 don't touch it — they use a 5-document movie corpus that lives inline in the script.