Area Attention
PyTorch implementation of Area Attention [1]. This module allows to attend to areas of the memory, where each area contains a group of items that are either spatially or temporally adjacent. TensorFlow implementation can be found here.
Setup
$ pip install area_attention
Usage
Single-head Area Attention:
import torch
from area_attention import AreaAttention
area_attention = AreaAttention(
key_query_size=32,
area_key_mode='max',
area_value_mode='mean',
max_area_height=2,
max_area_width=2,
memory_height=4,
memory_width=4,
dropout_rate=0.2,
top_k_areas=0
)
q = torch.rand(4, 8, 32)
k = torch.rand(4, 16, 32)
v = torch.rand(4, 16, 64)
x = area_attention(q, k, v)
x # torch.Tensor with shape (8, 64)
Multi-head Area Attention:
import torch
from area_attention import AreaAttention, MultiHeadAreaAttention
area_attention = AreaAttention(
key_query_size=32,
area_key_mode='max',
area_value_mode='mean',
max_area_height=2,
max_area_width=2,
memory_height=4,
memory_width=4,
dropout_rate=0.2,
top_k_areas=0
)
multi_head_area_attention = MultiHeadAreaAttention(
area_attention=area_attention,
num_heads=2,
key_query_size=32,
key_query_size_hidden=32,
value_size=64,
value_size_hidden=64
)
q = torch.rand(4, 8, 32)
k = torch.rand(4, 16, 32)
v = torch.rand(4, 16, 64)
x = multi_head_area_attention(q, k, v)
x # torch.Tensor with shape (8, 64)
Unit tests
$ python -m pytest tests
Bibliography
[1] Li, Yang, et al. "Area attention." International Conference on Machine Learning. PMLR, 2019.
Citations
@inproceedings{li2019area,
title={Area attention},
author={Li, Yang and Kaiser, Lukasz and Bengio, Samy and Si, Si},
booktitle={International Conference on Machine Learning},
pages={3846--3855},
year={2019},
organization={PMLR}
}
Metadata
Release files for area-attention 0.1.0
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 |
|---|---|---|---|---|
| area_attention-0.1.0.tar.gz | 6.0 kB | Without provenance | Details for area_attention-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| area_attention-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for area_attention-0.1.0-py3-none-any.whl |
Total release size: 12.9 kB
Release files / area_attention-0.1.0.tar.gz
| Download URL | area_attention-0.1.0.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
af249a0ec673338efbe4eecdfa7d131cd46f55fecd4ba8930e259d60f01b7ccb
|
|
BLAKE2b-256 checksum How to use checksums |
91d699c8bd3ba753a55adcfc234100adf0f4515a74414af5135f2c9c7ec93bf6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.9.0
|
Release files / area_attention-0.1.0-py3-none-any.whl
| Download URL | area_attention-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6ae5457f229c2f28f6053016f65ea6b718f0c2dbbfded71d6df833c1383517ce
|
|
BLAKE2b-256 checksum How to use checksums |
1c4095824f37771903f3a593ca3d844485d92fb8a18b93aa63c45fe88b61ef86
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.9.0
|
Security for area-attention 0.1.0
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.