GithubHelp home page GithubHelp logo

lukashedegaard / continual-transformers-tf Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 1.0 534 KB

TensorFlow implementation of Continual Transformer building blocks

License: Apache License 2.0

Makefile 13.16% Python 86.84%

continual-transformers-tf's Introduction

Continual Transformers TensorFlow

TensorFlow implementation of Continual Transformer building blocks, which augment regular transformer layers with the ability to compute the attention output per token step.

The layers are modelled on the tf.keras.layers.MultiHeadAttention and should work as drop-in replacements in most cases.

Setup

Continual Transformers and its modules can be installed in in your project using:

pip install git+https://github.com/LukasHedegaard/continual-transformers-tf.git

Layers

from continual_transformers_tf import CoSiMultiHeadAttention

layer = CoSiMultiHeadAttention(seq_len=10, num_heads=2, key_dim=4)

Fig. 1: Continual Single-Output Dot-Product Attention. The key (K) and value (V) matrices are aggregated over time by caching the step vectors k_n and v_n in a FIFO queue. During each step, only the attention output associated with q is computed.

from continual_transformers_tf import CircularPositionalEncoding

layer = CircularPositionalEncoding(max_len=10, embed_dim=4)

Fig. 2: Circular Positional Encoding. At each step, a positional encoding is added in a round-robin fashion.

from continual_transformers_tf import CoSiTransformerEncoder

layer = CoSiTransformerEncoder(
    seq_len=10,
    embed_dim=4,
    num_heads=2,
    ff_dim=16,
    dropout_rate=0.1,
)

Citation

@article{hedegaard2022cotrans,
  title={Continual Transformers: Redundancy-Free Attention for Online Inference},
  author={Lukas Hedegaard and Alexandros Iosifidis},
  journal={preprint, arXiv:2201.06268},
  year={2022}
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.