Skip to main content

fastslim

PyPI CI Python License

SLIM (Sparse Linear Methods, Ning & Karypis 2011) learns a sparse, non-negative item-item weight matrix W from a user-item matrix X and scores users with one sparse product, X @ W. Every recommendation is explainable: "because you interacted with these items".

fastslim is a Rust implementation behind a small Python API. The solver is exact (the returned weights satisfy the optimality conditions of the objective below), deterministic (bit-identical output for any thread count) and fast: MovieLens 1M fits in about a second.

Install

pip install fastslim  # or: uv add fastslim

Wheels for Linux (x86_64, aarch64), macOS and Windows, Python 3.10 and newer. Runtime dependencies are NumPy and SciPy.

Usage

import numpy as np
from scipy import sparse

import fastslim

rng = np.random.default_rng(0)
X = sparse.csr_matrix((rng.random((2000, 300)) < 0.03).astype(np.float64))  # users x items

W = fastslim.fit(X, lambd=2.0, beta=2.0)      # items x items, sparse, zero diagonal
top = fastslim.recommend(W, X[:5], k=10)       # top-10 unseen items for five users
scores = fastslim.predict(W, X[0])             # raw scores for one user

The same solver as an estimator:

from fastslim import SLIM

model = SLIM(lambd=2.0, beta=2.0).fit(X)
model.recommend(X[0], k=5)
model.weights, model.n_passes, model.converged  # fitted state

fit takes any SciPy sparse matrix or array, or a dense array; values must be finite and non-negative. fastslim.metrics provides precision_at_k, recall_at_k and ndcg_at_k against a held-out sparse matrix. The full reference is in docs/api.md.

Hyperparameters

  • lambd, the L1 penalty, is compared against co-occurrence counts: item k can enter item i's model only if (X.T @ X)[i, k] >= lambd. On MovieLens-sized data useful values are single digits. Raise it for a sparser W.
  • beta, the L2 penalty, shrinks weights and conditions the problem; any beta > 0 makes the solution unique.
  • max_iter and tol stop each item once a full pass moves no weight by tol. The defaults (1000, 1e-4) converge all of MovieLens 1M. Items that run out of budget raise fastslim.ConvergenceWarning; SLIM.converged tells which ones.
  • n_threads changes speed only. The result does not depend on it.

Performance

MovieLens, 80/20 split, k=10, against implicit's ALS with 64 factors. SLIM uses lambd=2, beta=2, max_iter=50.

Dataset Model Fit time precision@10 recall@10 ndcg@10
ML-100k fastslim 0.17 s 0.3391 0.2236 0.4069
ML-100k implicit ALS 0.58 s 0.2878 0.2017 0.3433
ML-1M fastslim 2.55 s 0.3620 0.1652 0.4100
ML-1M implicit ALS 4.45 s 0.3465 0.1621 0.3915

Reproduce with uv sync --group bench and uv run python benchmarks/benchmark.py --dataset 1m --baseline als --markdown.

How it works

For every item i independently, the solver minimises

0.5 * ||x_i - X w||^2 + lambd * sum_k w_k + (beta / 2) * sum_k w_k^2
subject to  w >= 0,  w_i = 0

by non-negative coordinate descent on the Gram matrix P = X.T @ X: only neighbours with P_ik >= lambd can be non-zero, residuals are updated incrementally, and an active set is iterated until a full verification pass confirms optimality. P is accumulated in a fixed order and each item is solved by a single thread, which is what makes the output deterministic. The derivation is in docs/algorithm.md.

Development

uv sync                          # builds the extension, installs dev tools
uv run pytest -q -m "not slow"   # Python tests
cargo test                       # Rust tests

CONTRIBUTING.md covers layout, linting, benchmarks and releases; CHANGELOG.md lists what changed between versions.

License

Apache-2.0. See LICENSE.

Metadata

Release files for fastslim 0.3.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 fastslim 0.3.0
File Size Uploaded
fastslim-0.3.0.tar.gz 71.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for fastslim 0.3.0
File
fastslim-0.3.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
fastslim-0.3.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
fastslim-0.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
fastslim-0.3.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl CPython 3.10 abi3 macOS 11.0+ ARM64, macOS 10.12+ universal2 (ARM64, x86-64), macOS 10.12+ x86-64 Details

Total release size: 1.6 MB

Release files / fastslim-0.3.0.tar.gz

Download URL fastslim-0.3.0.tar.gz
Size 71.1 kB
Tags Source
SHA-256 checksum
How to use checksums
782d6136b33303ebc5ab7cd6a17bdbf9e3765f99211c96759a17df93bc6402c4
BLAKE2b-256 checksum
How to use checksums
1051447d9b4eafdec33041dbbbe58f7c6676340625df7d27031784c3ab9897d0
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 22, 2026.

Transparency log

Release files / fastslim-0.3.0-cp310-abi3-win_amd64.whl

Download URL fastslim-0.3.0-cp310-abi3-win_amd64.whl
Size 234.4 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
960569594b3c67030e099147897a4336b83a66c68331c598b679cca7b2b0cf77
BLAKE2b-256 checksum
How to use checksums
90c7fa8d80948e1cf3154e074ae6818f6fb1387b7b253425485f30d5d511ef3c
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 22, 2026.

Transparency log

Release files / fastslim-0.3.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL fastslim-0.3.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 357.7 kB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
05d85b10bf5b2a8306fc7331f7e46d5dbbbf7fa13608a650ecca4ff087cad7fc
BLAKE2b-256 checksum
How to use checksums
ce548236b533c4ab0aab6521c40b860d8f338bbc135bbd286f4dcf8f55258b21
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 22, 2026.

Transparency log

Release files / fastslim-0.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL fastslim-0.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 351.2 kB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
661e63a2899125bd386c80d1b8f3778c3719e23c4a181a69ea4ddff6f443f8e6
BLAKE2b-256 checksum
How to use checksums
7ecb0f2c291c96b2d7123b99c1aec0f9b718e7d0bbdb47cb962e98c1c42bd8c5
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 22, 2026.

Transparency log

Release files / fastslim-0.3.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Download URL fastslim-0.3.0-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Size 626.5 kB
Tags CPython 3.10 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
5b4c0a8ae8509a5dc4c3d08c32ad47d674435b8bbdf7ef3211adbb79d1ccfc64
BLAKE2b-256 checksum
How to use checksums
bfa12d61dc9fd19d36c72ec751bc9829b3ad377402dc1c7a145ececd2c33427f
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 22, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

5 release files

0.2.0

5 release files

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

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