Stack Attention (wip)
For following a line of research that augments attention with a differentiable stack, beginning with DuSell et al. at ETH Zurich
Install
$ pip install stack-attention-pytorch
Usage
StackTransLayer
import torch
from stack_attention import StackTransLayer
tokens = torch.randn(2, 512, 256)
layer = StackTransLayer(256)
out1, state = layer(tokens)
out2, state = layer(
out1,
stack_state = state
)
assert out1.shape == out2.shape == tokens.shape
DataStructureTransLayer
Or declare a custom differentiable data structure
from stack_attention import DataStructureTransLayer, data_structure
counter = data_structure(
init = lambda: torch.zeros(1),
actions = dict(
inc = lambda s: s + 1.,
dec = lambda s: s - 1.,
noop = lambda s: s,
),
readout = lambda s: s
)
layer = DataStructureTransLayer(dim = 256, data_structure = counter)
tokens = torch.randn(2, 512, 256)
out, state = layer(tokens, recurrent = True)
Citations
@misc{dusell2024stackattentionimprovingability,
title = {Stack Attention: Improving the Ability of Transformers to Model Hierarchical Patterns},
author = {Brian DuSell and David Chiang},
year = {2024},
eprint = {2310.01749},
archivePrefix = {arXiv},
primaryClass = {cs.CL},
url = {https://arxiv.org/abs/2310.01749},
}
@misc{zhang2025stacktranslargelanguagemodel,
title = {StackTrans: From Large Language Model to Large Pushdown Automata Model},
author = {Kechi Zhang and Ge Li and Jia Li and Huangzhao Zhang and Yihong Dong and Jia Li and Jingjing Xu and Zhi Jin},
year = {2025},
eprint = {2507.15343},
archivePrefix = {arXiv},
primaryClass = {cs.SE},
url = {https://arxiv.org/abs/2507.15343},
}
@inproceedings{joulin2015inferring,
author = {Armand Joulin and Tom{\'a}{\v{s}} Mikolov},
title = {Inferring Algorithmic Patterns with Stack-Augmented Recurrent Nets},
booktitle = {Advances in Neural Information Processing Systems 28 (NIPS 2015)},
year = {2015}
}
Metadata
Release files for stack-attention-pytorch 0.0.12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| stack_attention_pytorch-0.0.12.tar.gz | 13.8 kB | Without provenance | Details for stack_attention_pytorch-0.0.12.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| stack_attention_pytorch-0.0.12-py3-none-any.whl | Python 3 | none | any | Details for stack_attention_pytorch-0.0.12-py3-none-any.whl |
Total release size: 29.3 kB
Release files / stack_attention_pytorch-0.0.12.tar.gz
| Download URL | stack_attention_pytorch-0.0.12.tar.gz |
|---|---|
| Size | 13.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8f0eb459c2cb6038f1f49145bb5225180d1b22213af4565cf96e25c9b9781b8b
|
|
BLAKE2b-256 checksum How to use checksums |
ea0b800fbcee93bec0d36b12e2c47d84c2f8fc4d25330b7d514bbbc8024b3c23
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|
Release files / stack_attention_pytorch-0.0.12-py3-none-any.whl
| Download URL | stack_attention_pytorch-0.0.12-py3-none-any.whl |
|---|---|
| Size | 15.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
66537b1e95af8ba5cca52247146aee169bfc7ea87d7374d6571da2e9ed2aec9d
|
|
BLAKE2b-256 checksum How to use checksums |
f9b275ca4815e9b9ee0a1aab7768e018a7607d5bb52afc178f6e762983eb3602
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|
Security for stack-attention-pytorch 0.0.12
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.