All Projects → hsm207 → bert_attn_viz

hsm207 / bert_attn_viz

Licence: Apache-2.0 license
Visualize BERT's self-attention layers on text classification tasks

Programming Languages

python
139335 projects - #7 most used programming language
Jupyter Notebook
11667 projects

Projects that are alternatives of or similar to bert attn viz

Nlp Tutorial
Natural Language Processing Tutorial for Deep Learning Researchers
Stars: ✭ 9,895 (+24034.15%)
Mutual labels:  attention, bert
classifier multi label seq2seq attention
multi-label,classifier,text classification,多标签文本分类,文本分类,BERT,ALBERT,multi-label-classification,seq2seq,attention,beam search
Stars: ✭ 26 (-36.59%)
Mutual labels:  attention, bert
wisdomify
A BERT-based reverse dictionary of Korean proverbs
Stars: ✭ 95 (+131.71%)
Mutual labels:  bert
embedding study
中文预训练模型生成字向量学习,测试BERT,ELMO的中文效果
Stars: ✭ 94 (+129.27%)
Mutual labels:  bert
AiR
Official Repository for ECCV 2020 paper "AiR: Attention with Reasoning Capability"
Stars: ✭ 41 (+0%)
Mutual labels:  attention
keras-utility-layer-collection
Collection of custom layers and utility functions for Keras which are missing in the main framework.
Stars: ✭ 63 (+53.66%)
Mutual labels:  attention
NLPDataAugmentation
Chinese NLP Data Augmentation, BERT Contextual Augmentation
Stars: ✭ 94 (+129.27%)
Mutual labels:  bert
pytorch-attention-augmented-convolution
A pytorch implementation of https://arxiv.org/abs/1904.09925
Stars: ✭ 20 (-51.22%)
Mutual labels:  attention
DataScience ArtificialIntelligence Utils
Examples of Data Science projects and Artificial Intelligence use cases
Stars: ✭ 302 (+636.59%)
Mutual labels:  explainable-ai
Fill-the-GAP
[ACL-WS] 4th place solution to gendered pronoun resolution challenge on Kaggle
Stars: ✭ 13 (-68.29%)
Mutual labels:  bert
ERNIE-text-classification-pytorch
This repo contains a PyTorch implementation of a pretrained ERNIE model for text classification.
Stars: ✭ 49 (+19.51%)
Mutual labels:  bert
neuro-comma
🇷🇺 Punctuation restoration production-ready model for Russian language 🇷🇺
Stars: ✭ 46 (+12.2%)
Mutual labels:  bert
grasp
Essential NLP & ML, short & fast pure Python code
Stars: ✭ 58 (+41.46%)
Mutual labels:  explainable-ai
sister
SImple SenTence EmbeddeR
Stars: ✭ 66 (+60.98%)
Mutual labels:  bert
neuro-symbolic-sudoku-solver
⚙️ Solving sudoku using Deep Reinforcement learning in combination with powerful symbolic representations.
Stars: ✭ 60 (+46.34%)
Mutual labels:  explainable-ai
AliceMind
ALIbaba's Collection of Encoder-decoders from MinD (Machine IntelligeNce of Damo) Lab
Stars: ✭ 1,479 (+3507.32%)
Mutual labels:  bert
tensorflow-chatbot-chinese
網頁聊天機器人 | tensorflow implementation of seq2seq model with bahdanau attention and Word2Vec pretrained embedding
Stars: ✭ 50 (+21.95%)
Mutual labels:  attention
TwinBert
pytorch implementation of the TwinBert paper
Stars: ✭ 36 (-12.2%)
Mutual labels:  bert
expmrc
ExpMRC: Explainability Evaluation for Machine Reading Comprehension
Stars: ✭ 58 (+41.46%)
Mutual labels:  explainable-ai
BERTOverflow
A Pre-trained BERT on StackOverflow Corpus
Stars: ✭ 40 (-2.44%)
Mutual labels:  bert

Introduction

This repository is an adaptation of the bert repository.

The purpose of this repository is to visualize BERT's self-attention weights after it has been fine-tuned on the IMDb dateset. However, it can be extended to any text classification dataset by creating an appropriate DataProcessor class. See run_classifier.py for details.

Usage

  1. Create a tsv file for each of the IMDB training and test set.

    Refer to the imdb_data repo for instructions.

  2. Fine-tune BERT on the IMBDb training set.

    Refer to the official BERT repo for fine-tuning instructions.

    Alternatively, you can skip this step by downloading the fine-tuned model from here.

    The pre-trained model (BERT base uncased) used to perform the fine-tuning can also be downloaded from here.

  3. Visualize BERT's weights.

    Refer to the BERT_viz_attention_imdb notebook for more details.

How it works

The forward pass has been modified to return a list of {layer_i: layer_i_attention_weights} dictionaries. The shape of layer_i_attention_weights is (batch_size, num_multihead_attn, max_seq_length, max_seq_length).

You can specify a function to process the above list by passing it as a parameter into the load_bert_model function in the explain.model module. The function's output is avaialble as part of the result of the Estimator's predict call under the key named 'attention'.

Currently, only two attention processor functions have been defined, namely average_last_layer_by_head and average_first_layer_by_head. See explain.attention for implementation details.

Model Performance Metrics

The fine-tuned model achieved an accuracy of 0.9407 on the test set.

The fine-tuning process was done with the following hyperparameters:

  • maximum sequence length: 512
  • training batch size: 8
  • learning rate: 3e-5
  • number of epochs: 3
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].