skillfed

entmax

The entmax mapping and its loss, a family of sparse alternatives to softmax.

entmax v1.3 105.5K downloads/30d#12,696 on PyPI474
Permissive license MIT DORMANT released

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 entmax

uv

uv add entmax

poetry

poetry add entmax

Installing 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

sparse softmax alternative pytorchentmax sparsemax implementationlearned sparsity attentionsparse probability mappingadaptive sparse transformationsentmax loss functionsparse sequence models
sparse-attentionpytorch-extensionresearch-oriented

More Artificial Intelligence packages