entmax
The entmax mapping and its loss, a family of sparse alternatives to softmax.
What it is and what it does
Entmax is a PyTorch library that implements entmax—a family of sparse probability mappings that generalize softmax by introducing sparsity. Instead of softmax's dense output where all values are non-zero, entmax can produce sparse distributions where many values become exactly zero, useful for attention mechanisms and multi-label classification. The package includes exact partial-sort algorithms for common cases (1.5-entmax and 2-entmax/sparsemax) and a general bisection-based algorithm for arbitrary alpha values, plus support for gradients with respect to alpha itself for learned, adaptive sparsity.
The library depends only on torch and installs as a pure Python wheel with low friction. It is designed for researchers and practitioners building sparse sequence models, adaptive transformers, and other architectures where sparse attention or sparse probability distributions are beneficial. The code is well-documented with examples and academic citations, though maintenance is dormant—the last release was in February 2024.
Use it for:
- Build sparse attention mechanisms in transformer models where only a subset of positions need non-zero attention weights.
- Implement multi-label classification with sparse output distributions instead of dense softmax probabilities.
- Learn adaptive sparsity patterns by computing gradients with respect to the alpha parameter during training.
- Replace softmax in sequence-to-sequence models to reduce computational cost and improve interpretability through explicit sparsity.
- Experiment with sparse transformers and other architectures that benefit from learned, structured sparsity in attention.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Entmax provides PyTorch implementations of entmax and entmax losses—sparse probability mappings that generalize softmax and cross-entropy, including exact algorithms for 1.5-entmax and 2-entmax (sparsemax) and bisection-based methods for adaptive, learned sparsity.
Yes, if you need sparse probability mappings or attention in PyTorch. The package is well-designed, permissively licensed, and has low install friction. Dormant maintenance is a minor concern—check compatibility with your PyTorch version before adopting in production, and verify that the bisection algorithms meet your numerical stability requirements. For research and prototyping, it is a solid choice.
Install
entmax on PyPI
pip
pip install entmaxuv
uv add entmaxpoetry
poetry add entmaxInstalling entmax
Before you install
Low friction: pure Python wheel with only torch as a runtime dependency. Maintenance is dormant (last release February 2024, last commit June 2024), but the repository remains active and unarchived with modest community interest (474 stars).
License in practice
MIT license is permissive; you can use, modify, and distribute entmax freely in commercial and private projects without restriction.
Quickstart
pip install entmax
import torch
from entmax import sparsemax, entmax15, entmax_bisect
x = torch.tensor([-2, 0, 0.5])
result = sparsemax(x, dim=0) # tensor([0.0000, 0.2500, 0.7500])
alpha = torch.tensor(1.33, requires_grad=True)
p = entmax_bisect(x.unsqueeze(0), alpha)
Requires PyTorch >= 1.9; Python >= 3.5.
Verify before relying
- Whether the dormant maintenance status (919 days since last release) affects compatibility with recent PyTorch versions.
- Performance characteristics and numerical stability compared to other sparse attention implementations.
- Whether gradient computation w.r.t. alpha is production-ready or primarily for research.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.5) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — torch |
| Maintenance | dormant — 919 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 105,484/month — #12,696 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: entmax-1.3-py3-none-any.whl
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
cut-cross-entropyComputes cross-entropy loss for…
unclear · top 15,000 on PyPI
captumCaptum provides model interpretability…
permissive · top 15,000 on PyPI
torchmetricsTorchmetrics provides a collection of PyTorch…
permissive · top 5,000 on PyPI
torch-optimizerProvides a collection of alternative…
permissive · top 15,000 on PyPI
rotary-embedding-torchImplements rotary positional embeddings for…
permissive · top 15,000 on PyPI
nvidia-cusparselt-cu13Provides NVIDIA's CUDA library for…
unclear · top 1,000 on PyPI
pytorch-metric-learningProvides metric learning loss functions,…
permissive · top 5,000 on PyPI
nvidia-cusparselt-cu12Provides NVIDIA's cuSPARSELt CUDA library for…
unclear · top 5,000 on PyPI
efficientnet-pytorchLoads and runs pretrained EfficientNet image…
permissive · top 15,000 on PyPI
vit-pytorchProvides PyTorch implementations of Vision…
permissive · top 15,000 on PyPI