Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 0.2.0 instead.
Reason given by maintainers: missing subpackage, use 0.1.1"

torchtsetlin

GPU-enabled, PyTorch-native Tsetlin machines — models, data preparation, training, evaluation, interpretation and visualisation in one package.

CI docs license

A Tsetlin machine learns propositional rules (IF x0 AND NOT x1 THEN class 1) with teams of learning automata instead of gradients. torchtsetlin implements the family as ordinary torch.nn.Modules: the automata live in tensors, so a model moves between CPU and GPU with .to(device), is saved with state_dict(), and learns from mini-batches with a single model.update(x, y) call.

import torchtsetlin as tt

x_train, y_train = tt.data.make_noisy_xor(5000, noise=0.4)          # Boolean features, int labels
x_test, y_test = tt.data.make_noisy_xor(2000, noise=0.0, seed=1)

model = tt.TsetlinMachine(n_features=12, n_classes=2, n_clauses=20, T=15, s=3.9).to("cuda")

# PyTorch-style loop: update() is the analogue of loss.backward(); optimizer.step()
for epoch in range(50):
    model.train()
    for i in range(0, 5000, 10):
        model.update(x_train[i:i+10].cuda(), y_train[i:i+10].cuda())
    model.eval()
    acc = (model(x_test.cuda()).argmax(1) == y_test.cuda()).float().mean()

print(model.rules()[:2])   # ['IF x0 AND NOT x1 THEN 1', 'IF x1 AND NOT x0 THEN 1']

Or with the built-in trainer:

trainer = tt.Trainer(model, batch_size=10, callbacks=[tt.EarlyStopping(patience=20)])
trainer.fit((x_train, y_train), epochs=100, val_data=(x_test, y_test))
trainer.evaluate((x_test, y_test))          # {'accuracy': 0.99}

Features

Models TsetlinMachine (multi-class, optional integer clause weights), CoalescedTsetlinMachine (shared clauses; multi-class or multi-label), RegressionTsetlinMachine, ConvTsetlinMachine / Conv1dTsetlinMachine and convolutional coalesced / regression variants
Learning vote margin T, specificity s, memory depth, boosted true-positive feedback, clause-size constraint, drop-clause / drop-literal, focused negative sampling, batched (GPU-friendly) or exact sequential feedback
Data thermometer, one-hot, bit-plane, adaptive-threshold, colour-thermometer and hypervector encoders; synthetic datasets; torchvision helpers
Training Trainer for tensors / Dataset / DataLoader, callbacks (early stopping, checkpoints, CSV logs, hyper-parameter schedules), History
Evaluation accuracy, confusion matrix, precision/recall/F1, regression and multi-label metrics, calibration, trustworthiness curves
Interpretation rule extraction, clause activity/precision, closed-form global & local feature importance, per-example explanations
Visualisation memory plots, automata heat-maps, convolutional clause patches, confusion matrices, vote distributions

Installation

pip install torch            # pick the CUDA/CPU build from pytorch.org
pip install torchtsetlin     # + optional extras: [viz] [vision] [sklearn] [docs] [all]

From source: pip install -e ".[dev]", then pytest and mkdocs serve.

How learning works (in one paragraph)

Each clause is an AND of literals (x_k or NOT x_k); every (clause, literal) pair has a Tsetlin automaton whose integer state decides whether the literal is included. For a training example, clauses of the true class receive Type I feedback (memorise the example's True literals, forget the rest) and clauses of a random other class receive Type II feedback (add a False literal so the clause stops matching), each with a probability controlled by the vote margin T. torchtsetlin evaluates a mini-batch with one matrix product, counts the feedback events per (clause, literal) with another, and turns the counts into binomial state transitions — the whole update is a handful of tensor ops. See the concept pages for details and references.

Documentation

  • Getting started, concepts, guides, examples and the full API reference: https://vlbthambawita.github.io/torchtsetlin/ (or mkdocs serve locally).
  • Runnable scripts in examples/: Noisy XOR, MNIST (flat and convolutional), tabular data with thermometer encoding, regression.

Citation

If you use torchtsetlin in research, please cite the Tsetlin machine papers whose algorithms you rely on (see the documentation) and this package:

@software{torchtsetlin,
  author = {Thambawita, Vajira},
  title  = {torchtsetlin: GPU-enabled, PyTorch-native Tsetlin machines},
  year   = {2026},
  url    = {https://github.com/vlbthambawita/torchtsetlin}
}

License

MIT — see LICENSE.

Release files for torchtsetlin 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for torchtsetlin 0.1.0
File Size Uploaded
torchtsetlin-0.1.0.tar.gz 47.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for torchtsetlin 0.1.0
File Interpreter ABI Platform
torchtsetlin-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 95.0 kB

Release files / torchtsetlin-0.1.0.tar.gz

Download URL torchtsetlin-0.1.0.tar.gz
Size 47.5 kB
Tags Source
SHA-256 checksum
How to use checksums
105a0da98c3eec66ea40ae0672b845ae3b9b4b4d161ce0c8e67d7ab8acc865b4
BLAKE2b-256 checksum
How to use checksums
96d71d0b04911dba315c13c2ffbc818704204a3c8a14d84818c9cc96b0fd5454
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Release files / torchtsetlin-0.1.0-py3-none-any.whl

Download URL torchtsetlin-0.1.0-py3-none-any.whl
Size 47.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
622540c553da80337911ac943350330a08a7ebe0210ad6abdf34fc0cd926ff46
BLAKE2b-256 checksum
How to use checksums
cb8575d5fcb37c2b523e02c957cadf14808309d3a87d2adc41c2eb1b891d4682
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 14, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page