Skip to content

Notebooks

End-to-end walkthroughs as Jupyter notebooks. The pages below show the code and the explanations; the notebooks are stored without outputs, so run one to see its results. The easiest way is Google Colab: open a notebook with its badge, and the first cell installs torchtsetlin from PyPI. The datasets download on first use.

Notebook Open Data Model What it is about Runtime
Iris, a readable model Open In Colab Iris (scikit-learn) TsetlinMachine Thermometer encoding, and reading the learned rules back as intervals in centimetres ~1.5 min (CPU)
MNIST on the GPU Open In Colab MNIST (torchvision) TsetlinMachine, ConvTsetlinMachine Convolutional clauses, GPU throughput, and the batch-size / feedback-fidelity trade-off ~1 min
CIFAR-10 Open In Colab CIFAR-10 (torchvision) ConvTsetlinMachine Booleanizing colour photographs, and where the accuracy ceiling is actually set ~2 min
Convolutional regression (C-RTM) Open In Colab synthetic (the paper's Fig. 3) ConvRegressionTsetlinMachine C-RTM (ICMLT 2021): how a TM outputs a number, and what its clauses say afterwards ~6 min
CTM-UNet segmentation Open In Colab synthetic CamVid-like scenes TsetlinMachine (dense per-pixel head) CTM-UNet (ISTM 2025): which of its ingredients carry the result ~1 min
Graph Tsetlin machine Open In Colab synthetic sequences, MNIST GraphTsetlinMachine Granmo et al. (2025): deep clauses over graphs, reading them back, and depth 1 = convolution ~1 min
Semantic segmentation Open In Colab synthetic street scenes SegmentationTsetlinMachine Per-pixel labels: the row-prior floor, context from position literals and a pyramid, explaining a pixel, patches_per_commit ~3 min
Polyp segmentation (Kvasir-SEG) Open In Colab Kvasir-SEG (downloaded) SegmentationTsetlinMachine Real colonoscopy images: a location-prior floor, class-balanced feedback, early stopping, and clauses that expose the model's shortcut ~6 min

Running in Colab

  • For notebooks 2–8 choose Runtime → Change runtime type → T4 GPU before running. A T4 is slower than the RTX 3090 and 3080 the runtimes above were measured on, so expect them to take longer. Notebook 1 runs on the CPU.
  • The Colab links open the notebooks from the main branch on GitHub.
  • Colab already has torch, torchvision, scikit-learn, matplotlib and pandas; the setup cell only adds torchtsetlin.

Running locally

pip install torchtsetlin jupyterlab        # or pip install -e ".[dev]" in a checkout
jupyter lab examples/notebooks

MNIST, CIFAR-10 and Kvasir-SEG download to data/ at the repository root on first run. Every notebook also runs on the CPU, but notebooks 2–8 are written for a GPU and are much slower without one. The source files are in examples/notebooks/.