Giter Site home page Giter Site logo

keras_attention's Introduction

Keras Attention Layer

Dead-simple Attention layer implementation in Keras based on the work of Yang et al. "Hierarchical Attention Networks for Document Classification"

Notice: the initial version of this repository was based on the implementation by Christos Baziotis. However, recently this repository was rewritten from scratch with the following features:

  • Compatibility with Keras 2.2 (tested with TensorFlow 1.8.0);
  • Annotations showing dimension transformations and equations;
  • Numerically stable softmax using the exp-normalize trick; (New!)
  • Easy way to recover the attention weights applied to each sample to make nice visualizations (see neat-vision); (Updated!)
  • Example showing differences between vanilla, attention model and attention with masking;
  • Example on the sum toy task showing how attention weights can be distributed across timesteps in a sample; (New!)
  • Example on sentiment analysis of movie reviews (but GitHub does not render notebook markup, you may want to download the notebook to see word highlights, as in the example below); (New!)
  • Allows customizing the attention activation function, since removing it might be beneficial for some tasks, as shown in "A Thorough Examination of the CNN/Daily Mail Reading Comprehension Task" by Chen et al. (New!)

Attention example on a movie review

Example of attention on words for sentiment classification in a movie review in the Keras IMDb dataset. Darker colors mean larger weights and, consequently, more importance is given to those term.

Attention example

Example of attention weights across timesteps during the classification of a sequential sample.

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.