All Projects → minqi → Hnatt

minqi / Hnatt

Licence: mit
Train and visualize Hierarchical Attention Networks

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Hnatt

Fake news detection deep learning
Fake News Detection using Deep Learning models in Tensorflow
Stars: ✭ 74 (-61.46%)
Mutual labels:  deep-neural-networks, attention-mechanism
Image Caption Generator
A neural network to generate captions for an image using CNN and RNN with BEAM Search.
Stars: ✭ 126 (-34.37%)
Mutual labels:  attention-mechanism, attention
Attend infer repeat
A Tensorfflow implementation of Attend, Infer, Repeat
Stars: ✭ 82 (-57.29%)
Mutual labels:  attention-mechanism, attention
Global Self Attention Network
A Pytorch implementation of Global Self-Attention Network, a fully-attention backbone for vision tasks
Stars: ✭ 64 (-66.67%)
Mutual labels:  attention-mechanism, attention
Hey Jetson
Deep Learning based Automatic Speech Recognition with attention for the Nvidia Jetson.
Stars: ✭ 161 (-16.15%)
Mutual labels:  deep-neural-networks, attention
Pytorch Attention Guided Cyclegan
Pytorch implementation of Unsupervised Attention-guided Image-to-Image Translation.
Stars: ✭ 67 (-65.1%)
Mutual labels:  deep-neural-networks, attention-mechanism
Absa keras
Keras Implementation of Aspect based Sentiment Analysis
Stars: ✭ 126 (-34.37%)
Mutual labels:  attention-mechanism, attention
Pytorch Gat
My implementation of the original GAT paper (Veličković et al.). I've additionally included the playground.py file for visualizing the Cora dataset, GAT embeddings, an attention mechanism, and entropy histograms. I've supported both Cora (transductive) and PPI (inductive) examples!
Stars: ✭ 908 (+372.92%)
Mutual labels:  attention-mechanism, attention
Multihead Siamese Nets
Implementation of Siamese Neural Networks built upon multihead attention mechanism for text semantic similarity task.
Stars: ✭ 144 (-25%)
Mutual labels:  deep-neural-networks, attention
Prediction Flow
Deep-Learning based CTR models implemented by PyTorch
Stars: ✭ 138 (-28.12%)
Mutual labels:  attention-mechanism, attention
Time Attention
Implementation of RNN for Time Series prediction from the paper https://arxiv.org/abs/1704.02971
Stars: ✭ 52 (-72.92%)
Mutual labels:  deep-neural-networks, attention
Graph attention pool
Attention over nodes in Graph Neural Networks using PyTorch (NeurIPS 2019)
Stars: ✭ 186 (-3.12%)
Mutual labels:  attention-mechanism, attention
Sockeye
Sequence-to-sequence framework with a focus on Neural Machine Translation based on Apache MXNet
Stars: ✭ 990 (+415.63%)
Mutual labels:  deep-neural-networks, attention-mechanism
Sarcasm Detection
Detecting Sarcasm on Twitter using both traditonal machine learning and deep learning techniques.
Stars: ✭ 73 (-61.98%)
Mutual labels:  deep-neural-networks, attention-mechanism
Isab Pytorch
An implementation of (Induced) Set Attention Block, from the Set Transformers paper
Stars: ✭ 21 (-89.06%)
Mutual labels:  attention-mechanism, attention
Lambda Networks
Implementation of LambdaNetworks, a new approach to image recognition that reaches SOTA with less compute
Stars: ✭ 1,497 (+679.69%)
Mutual labels:  attention-mechanism, attention
Performer Pytorch
An implementation of Performer, a linear attention-based transformer, in Pytorch
Stars: ✭ 546 (+184.38%)
Mutual labels:  attention-mechanism, attention
Keras Attention
Visualizing RNNs using the attention mechanism
Stars: ✭ 697 (+263.02%)
Mutual labels:  deep-neural-networks, attention-mechanism
Adnet
Attention-guided CNN for image denoising(Neural Networks,2020)
Stars: ✭ 135 (-29.69%)
Mutual labels:  deep-neural-networks, attention-mechanism
Multimodal Sentiment Analysis
Attention-based multimodal fusion for sentiment analysis
Stars: ✭ 172 (-10.42%)
Mutual labels:  attention-mechanism, attention

HNATT

This is a Keras implementation of the Hierarchical Network with Attention architecture (Yang et al, 2016), and comes with a webapp for easily interacting with the trained models.

Screenshot of HNATT in action

Overview

HNATT is a deep neural network for document classification. It learns hierarchical hidden representations of documents at word, sentence, and document levels. At both the word and sentence levels, HNATT makes use of an attention mechanism, in which it learns a context vector that determines a relevance weighting for its learned encoding of words and sentences. This model has been shown to outperform hierarchical models without attention, indicating that learning an input-dependent weighting across the various substructures of the document leads to improved performance in classification tasks.

Contents

Module Description
hnatt.py* Main HNATT implementation with custom Attention layer.
util.yelp.py Data loader for Yelp review data used for training and testing.
util.text_util.py Utility function for normalizing review texts.
util.glove.py Utility function for loading GloVe embedding weights from a file. You can download the embeddings here.
main.py Demo that trains HNATT on a subset of Yelp reviews and displays attention activation maps at both sentence and word levels on an example review.
app/ A simple Flask app for exploring a trained HNATT, allowing you to easily make predictions based on a text input and visualize the resulting attention activations at both word and sentence levels.

*A TensorFlow backend is assumed by the Attention layer.

Get started

Install dependencies in a new virtual environement via

virtualenv .venv
source .venv/bin/activate
pip install -r requirements.txt

Download the latest Yelp dataset from https://www.kaggle.com/yelp-dataset/yelp-dataset and move the unzipped folder to data/yelp-dataset in the project directory.

Give it a spin.

python main.py

Train your model

First, load n reviews from yelp for training, with 90/10 training/test split:

import util.yelp as yelp
(train_x, train_y), (test_x, test_y) = yelp.load_data(path=YELP_DATA_PATH, size=1e5, train_ratio=0.9)

You can also choose to polarize the Yelp ratings into binary labels, corresponding to negative and positive sentiment, by passing in an optional argument, binary=true. The resulting training and test sets will be balanced.

Now you're ready to train your model:

from hnatt import HNATT
h = HNATT()	
h.train(train_x, train_y, 
	batch_size=16,
	epochs=16,
	embeddings_path=EMBEDDINGS_PATH, 
	saved_model_dir=SAVED_MODEL_DIR,
	saved_model_filename=SAVED_MODEL_FILENAME)

You can print out sentence and word-level attention activations like so:

activation_maps = h.activation_maps('loved it! will definitely go back again.')
print(activation_maps)

Performance

When trained on random samples of 10,000 Yelp reviews, loaded with binary=true and balanced classes in training and test sets, this implementation of HNATT reaches 100% accuracy on the test set, and consistently around 90% accuracy on the validation set.

Visualizing attention

Once you train an HNATT model and save it locally using the saved_model_dir and saved_model_filename arguments to train, you can easily play with the saved model in an interactive web app by running the following:

python run_hnatt_viewer.py

You can then visit localhost:5000 to interact with your HNATT.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].