{"id":15600979,"url":"https://github.com/lucidrains/axial-positional-embedding","last_synced_at":"2025-04-09T14:13:54.611Z","repository":{"id":57413441,"uuid":"270510215","full_name":"lucidrains/axial-positional-embedding","owner":"lucidrains","description":"Axial Positional Embedding for Pytorch","archived":false,"fork":false,"pushed_at":"2025-02-25T17:05:58.000Z","size":36,"stargazers_count":76,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-02T10:41:42.666Z","etag":null,"topics":["artificial-intelligence","deep-learning","pytorch"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lucidrains.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-08T03:11:23.000Z","updated_at":"2025-03-24T13:12:39.000Z","dependencies_parsed_at":"2025-01-14T15:11:42.483Z","dependency_job_id":"383398eb-abff-4ba5-9b66-dac4d3efbc10","html_url":"https://github.com/lucidrains/axial-positional-embedding","commit_stats":{"total_commits":10,"total_committers":1,"mean_commits":10.0,"dds":0.0,"last_synced_commit":"fa6bee65ae45ce373004e33eea40a3625a126787"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Faxial-positional-embedding","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Faxial-positional-embedding/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Faxial-positional-embedding/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Faxial-positional-embedding/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucidrains","download_url":"https://codeload.github.com/lucidrains/axial-positional-embedding/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248054193,"owners_count":21039952,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["artificial-intelligence","deep-learning","pytorch"],"created_at":"2024-10-03T02:10:52.527Z","updated_at":"2025-04-09T14:13:54.592Z","avatar_url":"https://github.com/lucidrains.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Axial Positional Embedding\n\n[![PyPI version](https://badge.fury.io/py/axial-positional-embedding.svg)](https://badge.fury.io/py/axial-positional-embedding)\n\nA type of positional embedding that is very effective when working with attention networks on multi-dimensional data, or for language models in general.\n\n## Install\n\n```bash\n$ pip install axial-positional-embedding\n```\n\n## Usage\n\n```python\nimport torch\nfrom axial_positional_embedding import AxialPositionalEmbedding\n\npos_emb = AxialPositionalEmbedding(\n    dim = 512,\n    axial_shape = (64, 64),          # axial shape will multiply up to the maximum sequence length allowed (64 * 64 = 4096)\n    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)\n)\n\ntokens = torch.randn(1, 1024, 512)  # assume are tokens\ntokens = pos_emb(tokens) + tokens   # add positional embedding to token embeddings\n```\n\nA continuous version with better extrapolation ability (each axis parameterized by a 2 layer MLP)\n\n```python\nimport torch\nfrom axial_positional_embedding import ContinuousAxialPositionalEmbedding\n\npos_emb = ContinuousAxialPositionalEmbedding(\n    dim = 512,\n    num_axial_dims = 3\n)\n\ntokens = torch.randn(1, 8, 16, 32, 512) # say a video with 8 frames, 16 x 32 image dimension\n\naxial_pos_emb = pos_emb((8, 16, 32)) # pass in the size from above\n\ntokens = axial_pos_emb + tokens   # add positional embedding to token embeddings\n```\n\n## Citations\n\n```bibtex\n@inproceedings{kitaev2020reformer,\n    title       = {Reformer: The Efficient Transformer},\n    author      = {Nikita Kitaev and Lukasz Kaiser and Anselm Levskaya},\n    booktitle   = {International Conference on Learning Representations},\n    year        = {2020},\n    url         = {https://openreview.net/forum?id=rkgNKkHtvB}\n}\n```\n\n```bibtex\n@misc{ho2019axial,\n    title   = {Axial Attention in Multidimensional Transformers},\n    author  = {Jonathan Ho and Nal Kalchbrenner and Dirk Weissenborn and Tim Salimans},\n    year    = {2019},\n    archivePrefix = {arXiv}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidrains%2Faxial-positional-embedding","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucidrains%2Faxial-positional-embedding","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidrains%2Faxial-positional-embedding/lists"}