npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@wlearn/tsetlin

v0.1.0

Published

Tsetlin Machine compiled to WebAssembly -- interpretable ML in browsers and Node.js

Readme

@wlearn/tsetlin

Tsetlin Machine compiled to WebAssembly -- interpretable ML in browsers and Node.js.

Wraps the C core from TMU (Tsetlin Machine Unified) by Ole-Christoffer Granmo. ESM module, zero native dependencies.

Install

npm install @wlearn/tsetlin

Quick start

import { TsetlinModel } from '@wlearn/tsetlin'

// Create model (async -- loads WASM)
const model = await TsetlinModel.create({
  nClauses: 200,
  threshold: 50,
  s: 3.0,
  nEpochs: 100,
})

// Train
model.fit(X_train, y_train)

// Predict
const predictions = model.predict(X_test)
const accuracy = model.score(X_test, y_test)

// Probabilities (classification only)
const proba = model.predictProba(X_test)

// Save / load
const bytes = model.save()
const loaded = await TsetlinModel.load(bytes)

// Release WASM memory
model.dispose()

API

TsetlinModel.create(params?)

Async factory. Returns a Promise<TsetlinModel>.

Parameters:

| Param | Type | Default | Description | |-------|------|---------|-------------| | task | string | 'classification' | 'classification' or 'regression' | | nClauses | number | 100 | Number of clauses (half positive, half negative) | | threshold | number | 50 | T -- voting threshold | | s | number | 3.0 | Specificity parameter | | stateBits | number | 8 | Bits per Tsetlin automaton | | boostTruePositiveFeedback | boolean | false | Boost Type I feedback on true positives | | nThresholdsPerFeature | number | 10 | Max binary thresholds per continuous feature | | nEpochs | number | 100 | Training epochs | | seed | number | 42 | PRNG seed for reproducibility |

model.fit(X, y)

Train on data. Accepts number[][] or { data: Float64Array, rows, cols }. Continuous features are automatically binarized using quantile-based thresholds. Returns this.

model.predict(X)

Returns Float64Array of predictions.

  • Classification: integer class labels
  • Regression: continuous values scaled to original range

model.predictProba(X)

Returns Float64Array of class probabilities (flat, row-major). Classification only. Uses softmax over raw clause vote sums.

model.score(X, y)

Returns accuracy (classification) or R-squared (regression).

model.save()

Returns Uint8Array -- a WLRN v1 bundle containing the TM01 binary blob.

TsetlinModel.load(bytes)

Async. Loads a saved bundle. Returns Promise<TsetlinModel>.

model.dispose()

Frees WASM memory. Must be called when done. Safe to call multiple times.

model.getParams() / model.setParams(p)

Get or update hyperparameters. For AutoML compatibility.

TsetlinModel.defaultSearchSpace()

Returns a search space object for hyperparameter optimization.

How it works

Tsetlin Machines are interpretable ML models based on propositional logic. They learn conjunctive clauses (AND of binary features) that vote for or against each class. Training uses learning automata (Tsetlin automata) to include or exclude literals from each clause.

Continuous input features are automatically binarized: for each feature, quantile-based thresholds are computed, producing binary features of the form x > threshold. Both the original and negated literals are available to the clauses.

For classification, clauses are organized as one-vs-all: each class gets its own set of clauses. Half the clauses have positive polarity (vote for the class) and half have negative polarity (vote against). The class with the highest total vote wins.

For regression, clause votes are summed and scaled back to the original target range.

Resource management

WASM linear memory is not garbage collected. Always call dispose() when done. A FinalizationRegistry safety net logs a warning if a model is garbage collected without being disposed.

Build from source

Requires Emscripten.

git clone --recurse-submodules https://github.com/wlearn-org/tsetlin-wasm
cd tsetlin-wasm
npm install
bash scripts/build-wasm.sh
bash scripts/verify-exports.sh
node test/test.js

License

MIT. Upstream TMU is also MIT licensed.