{"id":13578462,"url":"https://github.com/lucidrains/lambda-networks","last_synced_at":"2025-05-15T11:07:00.788Z","repository":{"id":43266464,"uuid":"302436113","full_name":"lucidrains/lambda-networks","owner":"lucidrains","description":"Implementation of LambdaNetworks, a new approach to image recognition that reaches SOTA with less compute","archived":false,"fork":false,"pushed_at":"2020-11-18T19:54:34.000Z","size":226,"stargazers_count":1531,"open_issues_count":13,"forks_count":157,"subscribers_count":45,"default_branch":"main","last_synced_at":"2025-04-14T19:58:56.889Z","etag":null,"topics":["artificial-intelligence","attention","attention-mechanism","computer-vision","deep-learning"],"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}},"created_at":"2020-10-08T19:01:15.000Z","updated_at":"2025-03-19T01:46:46.000Z","dependencies_parsed_at":"2022-07-09T06:30:31.302Z","dependency_job_id":null,"html_url":"https://github.com/lucidrains/lambda-networks","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Flambda-networks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Flambda-networks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Flambda-networks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lucidrains%2Flambda-networks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lucidrains","download_url":"https://codeload.github.com/lucidrains/lambda-networks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254328384,"owners_count":22052632,"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","attention","attention-mechanism","computer-vision","deep-learning"],"created_at":"2024-08-01T15:01:30.869Z","updated_at":"2025-05-15T11:07:00.768Z","avatar_url":"https://github.com/lucidrains.png","language":"Python","readme":"\u003cimg src=\"./λ.png\" width=\"500px\"\u003e\u003c/img\u003e\n\n## Lambda Networks - Pytorch\n\nImplementation of λ Networks, a new approach to image recognition that reaches SOTA on ImageNet. The new method utilizes λ layer, which captures interactions by transforming contexts into linear functions, termed lambdas, and applying these linear functions to each input separately.\n\n\u003ca href=\"https://www.youtube.com/watch?v=3qxJ2WD8p4w\"\u003eYannic Kilcher's paper review\u003c/a\u003e\n\n## Install\n\n```bash\n$ pip install lambda-networks\n```\n\n## Usage\n\nGlobal context\n\n```python\nimport torch\nfrom lambda_networks import LambdaLayer\n\nlayer = LambdaLayer(\n    dim = 32,       # channels going in\n    dim_out = 32,   # channels out\n    n = 64,         # size of the receptive window - max(height, width)\n    dim_k = 16,     # key dimension\n    heads = 4,      # number of heads, for multi-query\n    dim_u = 1       # 'intra-depth' dimension\n)\n\nx = torch.randn(1, 32, 64, 64)\nlayer(x) # (1, 32, 64, 64)\n```\n\nLocalized context\n\n```python\nimport torch\nfrom lambda_networks import LambdaLayer\n\nlayer = LambdaLayer(\n    dim = 32,\n    dim_out = 32,\n    r = 23,         # the receptive field for relative positional encoding (23 x 23)\n    dim_k = 16,\n    heads = 4,\n    dim_u = 4\n)\n\nx = torch.randn(1, 32, 64, 64)\nlayer(x) # (1, 32, 64, 64)\n```\n\nFor fun, you can also import this as follows\n\n```python\nfrom lambda_networks import λLayer\n```\n\n## Tensorflow / Keras version\n\n\u003ca href=\"https://github.com/shinel94\"\u003eShinel94\u003c/a\u003e has added a Keras implementation! It won't be officially supported in this repository, so either copy / paste the code under `./lambda_networks/tfkeras.py` or make sure to install `tensorflow` and `keras` before running the following.\n\n```python\nimport tensorflow as tf\nfrom lambda_networks.tfkeras import LambdaLayer\n\nlayer = LambdaLayer(\n    dim_out = 32,\n    r = 23,\n    dim_k = 16,\n    heads = 4,\n    dim_u = 1\n)\n\nx = tf.random.normal((1, 64, 64, 16)) # channel last format\nlayer(x) # (1, 64, 64, 32)\n```\n\n## Citations\n\n```bibtex\n@inproceedings{\n    anonymous2021lambdanetworks,\n    title={LambdaNetworks: Modeling long-range Interactions without Attention},\n    author={Anonymous},\n    booktitle={Submitted to International Conference on Learning Representations},\n    year={2021},\n    url={https://openreview.net/forum?id=xTJEN-ggl1b},\n    note={under review}\n}\n```\n","funding_links":[],"categories":["Python","Pytorch实用程序"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidrains%2Flambda-networks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flucidrains%2Flambda-networks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flucidrains%2Flambda-networks/lists"}