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
Usage
import torch
from stack_attention.stack_trans_layer import StackTransLayer
tokens = torch.randn(2, 512, 256)
layer = StackTransLayer(256)
out1, state = layer(
tokens,
stochastic_action = stochastic_action,
hard_action = hard_action
)
out2, state = layer(
tokens,
stochastic_action = stochastic_action,
hard_action = hard_action
)
assert out1.shape == out2.shape == tokens.shape
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}
}
Release files for stack-attention-pytorch 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| stack_attention_pytorch-0.0.3.tar.gz | 6.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| stack_attention_pytorch-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.6 kB
Release files / stack_attention_pytorch-0.0.3.tar.gz
| Download URL | stack_attention_pytorch-0.0.3.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6c327840e42a306e61efa921fb783adab231f62b5c68d82802a815e6407eb35e
|
|
BLAKE2b-256 checksum How to use checksums |
76916e728ed9f877b897363ecf3f8e3be8817f4b73557e3ec9832d4fba9ebce7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|
Release files / stack_attention_pytorch-0.0.3-py3-none-any.whl
| Download URL | stack_attention_pytorch-0.0.3-py3-none-any.whl |
|---|---|
| Size | 6.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a40b27a82b4fab1f11c91abc828c5b7d4c1fa6e8c2b94c8b793c8414ed69426a
|
|
BLAKE2b-256 checksum How to use checksums |
8cd51a76e8d0f80c695e27bceba5712ef4049feecc82d5241aaf53a8191bb306
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|