Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lucidrains/axial-positional-embedding
Axial Positional Embedding for Pytorch
https://github.com/lucidrains/axial-positional-embedding
artificial-intelligence deep-learning pytorch
Last synced: 16 days ago
JSON representation
Axial Positional Embedding for Pytorch
- Host: GitHub
- URL: https://github.com/lucidrains/axial-positional-embedding
- Owner: lucidrains
- License: mit
- Created: 2020-06-08T03:11:23.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-04-30T14:58:56.000Z (over 3 years ago)
- Last Synced: 2024-10-29T16:41:55.056Z (19 days ago)
- Topics: artificial-intelligence, deep-learning, pytorch
- Language: Python
- Homepage:
- Size: 12.7 KB
- Stars: 61
- Watchers: 3
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Axial Positional Embedding
[![PyPI version](https://badge.fury.io/py/axial-positional-embedding.svg)](https://badge.fury.io/py/axial-positional-embedding)
A type of positional embedding that is very effective when working with attention networks on multi-dimensional data, or for language models in general.
## Install
```bash
$ pip install axial-positional-embedding
```## Usage
```python
import torch
from axial_positional_embedding import AxialPositionalEmbeddingpos_emb = AxialPositionalEmbedding(
dim = 512,
axial_shape = (64, 64), # axial shape will multiply up to the maximum sequence length allowed (64 * 64 = 4096)
axial_dims = (256, 256) # if not specified, dimensions will default to 'dim' for all axials and summed at the end. if specified, each axial will have the specified dimension and be concatted together. the concatted dimensions needs to sum up to the `dim` (256 + 256 = 512)
)tokens = torch.randn(1, 1024, 512) # assume are tokens
tokens = pos_emb(tokens) + tokens # add positional embedding to token embeddings
```## Citations
```bibtex
@inproceedings{kitaev2020reformer,
title = {Reformer: The Efficient Transformer},
author = {Nikita Kitaev and Lukasz Kaiser and Anselm Levskaya},
booktitle = {International Conference on Learning Representations},
year = {2020},
url = {https://openreview.net/forum?id=rkgNKkHtvB}
}
``````bibtex
@misc{ho2019axial,
title = {Axial Attention in Multidimensional Transformers},
author = {Jonathan Ho and Nal Kalchbrenner and Dirk Weissenborn and Tim Salimans},
year = {2019},
archivePrefix = {arXiv}
}
```