An implementation of Fastformer: Additive Attention Can Be All You Need in TensorFlow
Project description
Fast Transformer ![Twitter](https://pypi-camo.freetls.fastly.net/7625978429848fc5bb5de851bd1a5ec4e6b5595e/68747470733a2f2f696d672e736869656c64732e696f2f747769747465722f75726c3f7374796c653d736f6369616c2675726c3d68747470732533412532462532466769746875622e636f6d2532465269736869742d6461676c69253246466173742d5472616e73666f726d6572)
This repo implements Fastformer: Additive Attention Can Be All You Need by Wu et al. in TensorFlow. Fast Transformer is a Transformer variant based on additive attention that can handle long sequences efficiently with linear complexity. Fastformer is much more efficient than many existing Transformer models and can meanwhile achieve comparable or even better long text modeling performance.
Installation
Run the following to install:
pip install fast-transformer
Developing fast-transformer
To install fast-transformer
, along with tools you need to develop and test, run the following in your virtualenv:
git clone https://github.com/Rishit-dagli/Fast-Transformer.git
# or clone your own fork
cd fast-transformer
pip install -e .[dev]
Usage
import tensorflow as tf
from fast_transformer import FastTransformer
mask = tf.ones([1, 4096], dtype=tf.bool)
model = FastTransformer(
num_tokens = 20000,
dim = 512,
depth = 2,
max_seq_len = 4096,
absolute_pos_emb = True, # Absolute positional embeddings
mask = mask
)
x = tf.experimental.numpy.random.randint(0, 20000, (1, 4096))
logits = model(x) # (1, 4096, 20000)
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{wu2021fastformer,
title = {Fastformer: Additive Attention is All You Need},
author = {Chuhan Wu and Fangzhao Wu and Tao Qi and Yongfeng Huang},
year = {2021},
eprint = {2108.09084},
archivePrefix = {arXiv},
primaryClass = {cs.CL}
}
Yannic Kilcher's video was super helpful while building this.
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
Hashes for fast_transformer-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4eebf17f63b39f28b4878048b871bfcd2d6f6b90b469dbcd6d852d2b12054307 |
|
MD5 | 3390c628f41c3b342809974f658ac06f |
|
BLAKE2b-256 | e770dfb1ca8abaa4031f498a69f2583d524e9c7cc318c509bac00e54afbc6aba |