All Projects → zhaocq-nlp → Attention-Visualization

zhaocq-nlp / Attention-Visualization

Licence: Apache-2.0 License
Visualization for simple attention and Google's multi-head attention.

Programming Languages

java
68154 projects - #9 most used programming language
python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Attention-Visualization

Visual-Transformer-Paper-Summary
Summary of Transformer applications for computer vision tasks.
Stars: ✭ 51 (-5.56%)
Mutual labels:  attention, attention-visualization
Mtbook
《机器翻译:基础与模型》肖桐 朱靖波 著 - Machine Translation: Foundations and Models
Stars: ✭ 2,307 (+4172.22%)
Mutual labels:  machine-translation, neural-machine-translation
Subword Nmt
Unsupervised Word Segmentation for Neural Machine Translation and Text Generation
Stars: ✭ 1,819 (+3268.52%)
Mutual labels:  machine-translation, neural-machine-translation
Opennmt Tf
Neural machine translation and sequence learning using TensorFlow
Stars: ✭ 1,223 (+2164.81%)
Mutual labels:  machine-translation, neural-machine-translation
bergamot-translator
Cross platform C++ library focusing on optimized machine translation on the consumer-grade device.
Stars: ✭ 181 (+235.19%)
Mutual labels:  machine-translation, neural-machine-translation
Mt Paper Lists
MT paper lists (by conference)
Stars: ✭ 105 (+94.44%)
Mutual labels:  machine-translation, neural-machine-translation
RNNSearch
An implementation of attention-based neural machine translation using Pytorch
Stars: ✭ 43 (-20.37%)
Mutual labels:  attention, neural-machine-translation
Opennmt Py
Open Source Neural Machine Translation in PyTorch
Stars: ✭ 5,378 (+9859.26%)
Mutual labels:  machine-translation, neural-machine-translation
Modernmt
Neural Adaptive Machine Translation that adapts to context and learns from corrections.
Stars: ✭ 231 (+327.78%)
Mutual labels:  machine-translation, neural-machine-translation
Opennmt
Open Source Neural Machine Translation in Torch (deprecated)
Stars: ✭ 2,339 (+4231.48%)
Mutual labels:  machine-translation, neural-machine-translation
Sockeye
Sequence-to-sequence framework with a focus on Neural Machine Translation based on Apache MXNet
Stars: ✭ 990 (+1733.33%)
Mutual labels:  machine-translation, neural-machine-translation
dynmt-py
Neural machine translation implementation using dynet's python bindings
Stars: ✭ 17 (-68.52%)
Mutual labels:  machine-translation, neural-machine-translation
Nematus
Open-Source Neural Machine Translation in Tensorflow
Stars: ✭ 730 (+1251.85%)
Mutual labels:  machine-translation, neural-machine-translation
Opus Mt
Open neural machine translation models and web services
Stars: ✭ 111 (+105.56%)
Mutual labels:  machine-translation, neural-machine-translation
Thumt
An open-source neural machine translation toolkit developed by Tsinghua Natural Language Processing Group
Stars: ✭ 550 (+918.52%)
Mutual labels:  machine-translation, neural-machine-translation
Nspm
🤖 Neural SPARQL Machines for Knowledge Graph Question Answering.
Stars: ✭ 156 (+188.89%)
Mutual labels:  machine-translation, neural-machine-translation
Joeynmt
Minimalist NMT for educational purposes
Stars: ✭ 420 (+677.78%)
Mutual labels:  machine-translation, neural-machine-translation
Nmt Keras
Neural Machine Translation with Keras
Stars: ✭ 501 (+827.78%)
Mutual labels:  machine-translation, neural-machine-translation
Npmt
Towards Neural Phrase-based Machine Translation
Stars: ✭ 175 (+224.07%)
Mutual labels:  machine-translation, neural-machine-translation
parallel-corpora-tools
Tools for filtering and cleaning parallel and monolingual corpora for machine translation and other natural language processing tasks.
Stars: ✭ 35 (-35.19%)
Mutual labels:  machine-translation, neural-machine-translation

Attention-Visualization

Visualization for simple attention and Google's multi-head attention.

Requirements

  • python
  • jdk1.8

Usage

1. Python version (for simple attention only):

python exec/plot_heatmap.py --input xxx.attention

2. Java version (for both simple attention and Google's multi-head attention):

java -jar exec/plot_heatmap.jar

then select the attention file on the GUI.

Data Format

The name of the attention file should end with ".attention" extension especially when using exec/plot_heatmap.jar and the file should be json format:

{ "0": {
    "source": " ",       # the source sentence (without <s> and </s> symbols)
    "translation": " ",      # the target sentence (without <s> and </s> symbols)
    "attentions": [         # various attention results
        {
            "name": " ",        # a unique name for this attention
            "type": " ",        # the type of this attention (simple or multihead)
            "value": [...]      # the attention weights, a json array
        },      # end of one attention result
        {...}, ...]     # end of various attention results
    },   # end of the first sample
  "1":{
        ...
    },       # end of the second sample
    ...
}       # end of file

Note that due to the hard coding, the name of each attention should contain "encoder_decoder_attention", "encoder_self_attention" or "decoder_self_attention" substring on the basis of its real meaning.

The value has shape [length_queries, length_keys] when type=simple and has shape [num_heads, length_queries, length_keys] when type=multihead.

For more details, see attention.py.

Demo

The toydata/toy.attention is generated by a NMT model with a self-attention encoder, Bahdanau's attention and a RNN decoder using NJUNMT-tf.

1. Execute the python version (for simple attention only):

python exec/plot_heatmap.py --input toydata/toy.attention

It will plot the traditional attention heatmap:



2. As for java version (for both simple attention and Google's multihead attention), execute

java -jar exec/plot_heatmap.jar

then select the toydata/toy.attention on the GUI.





The words on the left side are attention "queries" and attention "keys" are on the right. Click on the words on the left side to see the heatmap:



Here shows the traditional encoder_decoder_attention of word "obtained". The color depth of lines and squares indicate the degree of attention.

Next, select encoder_self_attention0 under the menu bar. Click on the "获得" on the left.



It shows the multi-head attention of the word "获得". Attention weights of head0 - head7 are displayed on the right.

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].