Skip to main content

Induced Set Attention Block Twitter

PyPI Run Tests Upload Python Package Code style: black Open In Colab

GitHub License GitHub stars GitHub followers Twitter Follow

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.

Metadata

Release files for isab 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for isab 0.1.0
File Size Uploaded
isab-0.1.0.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for isab 0.1.0
File Interpreter ABI Platform
isab-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.3 kB

Release files / isab-0.1.0.tar.gz

Download URL isab-0.1.0.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c86cb664dbb01743a18702c08fa3d056c4d60c50d77c26e0d9bc9aeb9ca6865f
BLAKE2b-256 checksum
How to use checksums
b384062e38bb753aebf67fd692e247758efabca6a4127b1edaa48ebef7981417
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / isab-0.1.0-py3-none-any.whl

Download URL isab-0.1.0-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
824faa4602037f1f67285d58972672361ac36afc3e612ff81c08b770c8756444
BLAKE2b-256 checksum
How to use checksums
417cb4e35dfc5f4d5eeff6ee7c5e2ba1d97076944cc063e49a85be89d1a758e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page