--- id: entmax version: "1.3" license: MIT license_treatment: permissive maintenance: dormant --- # entmax — The entmax mapping and its loss, a family of sparse alternatives to softmax. License: permissive · Maintenance: dormant · Downloads: 105.5K/mo ## 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 above — 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 pip install entmax uv add entmax 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_current - Install friction: low - Maintenance: dormant - Downloads: 105.5K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags sparse softmax alternative pytorch, entmax sparsemax implementation, learned sparsity attention, sparse probability mapping, adaptive sparse transformations, entmax loss function, sparse sequence models, sparse-attention, pytorch-extension, research-oriented [View on SkillFed](https://skillfed.io/packages/entmax) · [View on PyPI](https://pypi.org/project/entmax/)