{"id":29023308,"url":"https://github.com/rish-16/tokenlearner-pytorch","last_synced_at":"2025-06-26T03:06:04.195Z","repository":{"id":57476124,"uuid":"436355729","full_name":"rish-16/tokenlearner-pytorch","owner":"rish-16","description":"Unofficial PyTorch implementation of TokenLearner by Google AI","archived":false,"fork":false,"pushed_at":"2023-01-28T15:02:56.000Z","size":130,"stargazers_count":65,"open_issues_count":4,"forks_count":10,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-06-14T00:41:36.552Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/rish-16.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}},"created_at":"2021-12-08T18:42:30.000Z","updated_at":"2025-05-16T00:42:41.000Z","dependencies_parsed_at":"2023-02-15T17:16:04.842Z","dependency_job_id":null,"html_url":"https://github.com/rish-16/tokenlearner-pytorch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rish-16/tokenlearner-pytorch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rish-16%2Ftokenlearner-pytorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rish-16%2Ftokenlearner-pytorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rish-16%2Ftokenlearner-pytorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rish-16%2Ftokenlearner-pytorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rish-16","download_url":"https://codeload.github.com/rish-16/tokenlearner-pytorch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rish-16%2Ftokenlearner-pytorch/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261990349,"owners_count":23241189,"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":[],"created_at":"2025-06-26T03:06:03.645Z","updated_at":"2025-06-26T03:06:04.182Z","avatar_url":"https://github.com/rish-16.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tokenlearner-pytorch\nUnofficial PyTorch implementation of `TokenLearner` by Ryoo et al. from Google AI ([`abs`](https://arxiv.org/abs/2106.11297), [`pdf`](https://arxiv.org/pdf/2106.11297.pdf))\n\n\u003cimg src=\"https://raw.githubusercontent.com/rish-16/tokenlearner-pytorch/main/tklr.png\" width=650 /\u003e\n\n## Installation\nYou can install TokenLearner via `pip`:\n\n```\npip install tokenlearner-pytorch\n```\n\n## Usage\nYou can access the `TokenLearner` class from the `tokenlearner_pytorch` package. You can use this layer with a Vision Transformer, MLPMixer, or Video Vision Transformer as done in the paper.\n\n```python\nimport torch\nfrom tokenlearner_pytorch import TokenLearner\n\ntklr = TokenLearner(S=8)\nx = torch.rand(512, 32, 32, 3)\ny = tklr(x) # [512, 8, 3]\n```\n\nYou can also use `TokenLearner` and `TokenFuser` together with Multi-head Self-Attention as done in the paper:\n\n```python\nimport torch\nimport torch.nn as nn\nfrom tokenlearner_pytorch import TokenLearner, TokenFuser\n\nmhsa = nn.MultiheadAttention(3, 1)\ntklr = TokenLearner(S=8)\ntkfr = TokenFuser(H=32, W=32, C=3, S=8)\n\nx = torch.rand(512, 32, 32, 3) # a batch of images\n\ny = tklr(x)\ny = y.view(8, 512, 3)\ny, _ = mhsa(y, y, y) # ignore attn weights\ny = y.view(512, 8, 3)\n\nout = tkfr(y, x) # [512, 32, 32, 3]\n```\n\n## TODO\n- [ ] Add support for temporal dimension `T`\n- [ ] Implement `TokenFuser` with `ViT`\n- [ ] Implement `TokenFuser` with `ViViT`\n\n## Contributions\nIf I've made any errors or you have any suggestions, feel free to raise an Issue or PR. All contributions welcome!!\n\n## License\n[MIT](https://github.com/rish-16/tokenlearner-pytorch/blob/main/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frish-16%2Ftokenlearner-pytorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frish-16%2Ftokenlearner-pytorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frish-16%2Ftokenlearner-pytorch/lists"}