An implementation of Set Transformer: A Framework for Attention-based Permutation-Invariant Neural Networks in TensorFlow
Project description
Induced Set Attention Block
Set Transformer from the paper "Set Transformer: A Framework for Attention-based Permutation-Invariant Neural Networks" is based on Isab, an attention scheme inspired by inducing point methods from sparse Gaussian process literature and making it permutation invariant. It proposes to reduce attention from O(n²) to O(mn), where m is the number of inducing points (learned latents).
Installation
Run the following to install:
pip install isab
Developing isab
To install isab
, along with tools you need to develop and test, run the following in your virtualenv:
git clone https://github.com/Rishit-dagli/isab.git
# or clone your own fork
cd isab
pip install -e .[dev]
To run rank and shape tests run any of the following:
python -m isab.test_isab
pytest isab --verbose
Usage
import tensorflow as tf
from isab import Isab
attn = Isab(
dim = 512,
heads = 8,
num_latents = 128
)
seq = tf.random.normal((1, 16384, 512)) # (batch, seq, dim)
mask = tf.ones((1, 16384), dtype = tf.bool) # (batch, seq)
out, latents = attn(seq, mask = mask) # (1, 16384, 512), (1, 128, 512)
You can also choose not to set the number of latents, and pass in the latents yourself:
import tensorflow as tf
from isab import Isab
attn = Isab(
dim = 512,
heads = 8
)
seq = tf.random.normal((1, 16384, 512)) # (batch, seq, dim)
latents = tf.Variable(tf.random.normal((128, 512))) # some memory, passed through multiple Isabs
out, new_latents = attn(seq, latents) # (1, 16384, 512), (1, 128, 512)
Want to Contribute 🙋♂️?
Awesome! If you want to contribute to this project, you're always welcome! See Contributing Guidelines. You can also take a look at open issues for getting more information about current or upcoming tasks.
Want to discuss? 💬
Have any questions, doubts or want to present your opinions, views? You're always welcome. You can start discussions.
Citation
@misc{https://doi.org/10.48550/arxiv.1810.00825,
doi = {10.48550/ARXIV.1810.00825},
url = {https://arxiv.org/abs/1810.00825},
author = {Lee, Juho and Lee, Yoonho and Kim, Jungtaek and Kosiorek, Adam R. and Choi, Seungjin and Teh, Yee Whye},
keywords = {Machine Learning (cs.LG), Machine Learning (stat.ML), FOS: Computer and information sciences, FOS: Computer and information sciences},
title = {Set Transformer: A Framework for Attention-based Permutation-Invariant Neural Networks},
publisher = {arXiv},
year = {2018},
copyright = {arXiv.org perpetual, non-exclusive license}
}
@misc{https://doi.org/10.48550/arxiv.2212.11972,
doi = {10.48550/ARXIV.2212.11972},
url = {https://arxiv.org/abs/2212.11972},
author = {Jabri, Allan and Fleet, David and Chen, Ting},
keywords = {Machine Learning (cs.LG), Computer Vision and Pattern Recognition (cs.CV), Neural and Evolutionary Computing (cs.NE), FOS: Computer and information sciences, FOS: Computer and information sciences},
title = {Scalable Adaptive Computation for Iterative Generation},
publisher = {arXiv},
year = {2022},
copyright = {Creative Commons Attribution 4.0 International}
}
License
Copyright 2020 Rishit Dagli
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file isab-0.1.0.tar.gz
.
File metadata
- Download URL: isab-0.1.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c86cb664dbb01743a18702c08fa3d056c4d60c50d77c26e0d9bc9aeb9ca6865f |
|
MD5 | b437d3388a58da8ada9931533189877b |
|
BLAKE2b-256 | b384062e38bb753aebf67fd692e247758efabca6a4127b1edaa48ebef7981417 |
File details
Details for the file isab-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: isab-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 824faa4602037f1f67285d58972672361ac36afc3e612ff81c08b770c8756444 |
|
MD5 | 47e28c7ddd6c0f4c4bf50643d04935a2 |
|
BLAKE2b-256 | 417cb4e35dfc5f4d5eeff6ee7c5e2ba1d97076944cc063e49a85be89d1a758e5 |