Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

compresso_pytorch-0.1.0.tar.gz (98.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

compresso_pytorch-0.1.0-py3-none-any.whl (96.2 kB view details)

Uploaded Python 3

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

Hashes for compresso_pytorch-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ec0762758cb3ede840aae34d1cb9905172a2434b72b8823fa58598b7eb4d59ec
MD5 5c244629a82b9b30e8f766473e1f2251
BLAKE2b-256 3bb5dac352ab2911b403db8254608f5ca26203422d4361a5113e92b9875c6027

See more details on using hashes here.

Provenance

The following attestation bundles were made for compresso_pytorch-0.1.0.tar.gz:

Publisher: publish.yml on zombak79/compresso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file compresso_pytorch-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for compresso_pytorch-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fbec393d2f52f8c64355cf26347913ad9fdc8cf195e749778d7aa734c43ccca4
MD5 6c1aaf54b98a40ff6b1ff77a39281311
BLAKE2b-256 153935a8a506b7f782d381998f4d949885fd79d6ca653acb918b3be9e6709c93

See more details on using hashes here.

Provenance

The following attestation bundles were made for compresso_pytorch-0.1.0-py3-none-any.whl:

Publisher: publish.yml on zombak79/compresso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page