Code Monkey home page Code Monkey logo

tf_linear_transformers's Introduction

Linear Attention Transformers

  • Linear Attention in this repo is through kernel approximation of the softmax function to avoid O(n^2) cost

$SM(X,Y) = \phi(X)\phi(Y)$ $\phi$ in this case is defined by two papers, the third paper uses a low rank approximation of the softmax attention:

  1. Transformers are RNNs: Fast Autoregressive Transformers with Linear Attention
  2. Rethinking Attention with Performers
  3. Nyströmformer: A Nyström-Based Algorithm for Approximating Self-Attention
  • Causal attention is also implemented through tf.cumsum and tf.einsum
  • Training script for generating MNIST through transformers is added
    import tensorflow as tf
    from Linear_Transformer import Linear_Transformer
    
    Q = tf.random.normal((1,512,256))
    K = tf.random.normal((1,784,256))
    model = Linear_Transformer(n_enc_layers=6,n_dec_layers=6,dim=256,n_heads=8,ffn_dim=1024,dropout=0.2,return_inter = False,causal=False)
    model(Q,K)

tf_linear_transformers's People

Stargazers

 avatar

Watchers

 avatar  avatar

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.