A PyTorch framework for sparse representation learning
Project description
Compresso: A PyTorch Framework for Sparse Representation Learning
Compresso is an open-source PyTorch framework for sparse representation learning. It provides reusable building blocks for learning sparse neural representations, dynamic sparsification, sparse inference, and semantic analysis, enabling researchers to rapidly prototype sparse neural architectures while focusing on models rather than infrastructure.
Why Compresso?
Sparse representations are becoming increasingly important across machine learning due to their efficiency, interpretability, and ability to capture semantically meaningful concepts. Yet building sparse models often requires implementing pruning schedules, sparse kernels, training loops, device management, and visualization from scratch.
Compresso hides this complexity behind a simple, modular API.
The name is inspired by Italian espresso culture: when you order a coffee in Italy, you simply ask for a caffè. The barista handles the beans, pressure, and brewing; you just enjoy the result. Compresso follows the same philosophy: researchers should be able to train and analyze sparse representations without worrying about the underlying engineering.
Install
Using pip:
pip install compresso-pytorch
For local development:
git clone https://github.com/zombak79/compresso.git
cd compresso
pip install -e ".[test]"
Documentation
Documentation is available at https://zombak79.github.io/compresso/.
Minimal Example
You can train a sparse autoencoder through one high-level class TopKSAETrainer with a scikit-learn-style wrapper: fit trains on a dense matrix, transform returns sparse codes, and fit_transform does both. All hyperparameters live in the TopKSAEConfig dataclass.
import numpy as np
from compresso import TopKSAEConfig, TopKSAETrainer
embeddings = np.random.randn(10_000, 512).astype("float32")
trainer = TopKSAETrainer(
TopKSAEConfig(
hidden_dim=4096,
k=32,
batch_size=1024,
epochs=50,
sparsify_score_mode="abs",
sparsify_ste_alpha=0.01,
)
)
srp = trainer.fit_transform(embeddings)
print(srp)
Clustering and cluster labeling can be run through the clustering pipeline:
from compresso import clustering as cc
cluster_graph = cc.ClusteringPipeline(
[
cc.SRPSimilarityClustering(
threshold=0.5, # minimum similarity between items inside a cluster
top_k=None, # None = all pairs above threshold
min_cluster_size=20, # smaller clusters are discarded
normalize_rows=True, # centroids of the cluster will be normalized
min_local_density=None, # optional cleanup
centroid_top_k=8, # how many top features are included in centroid definition
batch_size=32,
show_progress=True,
),
cc.LabelClusters(
entity_metadata=meta, # metadata for srp rows
text_extractor=texts_fn, # function that converts entity metadata into a single string (entity description)
label_fn=label_cluster, # function that converts a list of (cluster members) entity descriptions to one label
cluster_scope="all", # scope of nodes in clustering graph
show_progress=True,
),
]
)(srp)
See full example at https://zombak79.github.io/compresso/clustering.html.
Citation
If you find this project helpful or use it in your academic work, please consider citing it. This helps us continue to maintain and develop this project. You can find the citation format below.
@misc{compresso,
title = {Compresso: A PyTorch Framework for Sparse Representation Learning},
author = {Van{\v{c}}ura, Vojt{\v{e}}ch and Giacomo Medda and Spi{\v{s}}{\'a}k, Martin and Ladislav Pe{\v{s}}ka},
year = {2026},
url = {https://github.com/zombak79/compresso}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file compresso_pytorch-0.1.0.tar.gz.
File metadata
- Download URL: compresso_pytorch-0.1.0.tar.gz
- Upload date:
- Size: 98.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec0762758cb3ede840aae34d1cb9905172a2434b72b8823fa58598b7eb4d59ec
|
|
| MD5 |
5c244629a82b9b30e8f766473e1f2251
|
|
| BLAKE2b-256 |
3bb5dac352ab2911b403db8254608f5ca26203422d4361a5113e92b9875c6027
|
Provenance
The following attestation bundles were made for compresso_pytorch-0.1.0.tar.gz:
Publisher:
publish.yml on zombak79/compresso
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
compresso_pytorch-0.1.0.tar.gz -
Subject digest:
ec0762758cb3ede840aae34d1cb9905172a2434b72b8823fa58598b7eb4d59ec - Sigstore transparency entry: 2108087144
- Sigstore integration time:
-
Permalink:
zombak79/compresso@a17464fd20840cc6ba123fab223e8e5f14e74107 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/zombak79
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a17464fd20840cc6ba123fab223e8e5f14e74107 -
Trigger Event:
push
-
Statement type:
File details
Details for the file compresso_pytorch-0.1.0-py3-none-any.whl.
File metadata
- Download URL: compresso_pytorch-0.1.0-py3-none-any.whl
- Upload date:
- Size: 96.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbec393d2f52f8c64355cf26347913ad9fdc8cf195e749778d7aa734c43ccca4
|
|
| MD5 |
6c1aaf54b98a40ff6b1ff77a39281311
|
|
| BLAKE2b-256 |
153935a8a506b7f782d381998f4d949885fd79d6ca653acb918b3be9e6709c93
|
Provenance
The following attestation bundles were made for compresso_pytorch-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on zombak79/compresso
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
compresso_pytorch-0.1.0-py3-none-any.whl -
Subject digest:
fbec393d2f52f8c64355cf26347913ad9fdc8cf195e749778d7aa734c43ccca4 - Sigstore transparency entry: 2108087257
- Sigstore integration time:
-
Permalink:
zombak79/compresso@a17464fd20840cc6ba123fab223e8e5f14e74107 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/zombak79
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a17464fd20840cc6ba123fab223e8e5f14e74107 -
Trigger Event:
push
-
Statement type: