Skip to content

catherinesyeh/attention-viz

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

attention-viz

Visualizing query-key interactions in language + vision transformers

abstract

Transformer models are revolutionizing machine learning, but their inner workings remain mysterious. In this work, we present a new visualization technique designed to help researchers understand the self-attention mechanism in transformers that allows these models to learn rich, contextual relationships between elements of a sequence. The main idea behind our method is to visualize a joint embedding of the query and key vectors used by transformer models to compute attention. Unlike previous attention visualization techniques, our approach enables the analysis of global patterns across multiple input sequences. We create an interactive visualization tool, AttentionViz, based on these joint query-key embeddings, and use it to study attention mechanisms in both language and vision transformers. We demonstrate the utility of our approach in improving model understanding and offering new insights about query-key interactions through several application scenarios and expert feedback.

set up instructions

  1. Clone repo and navigate into folder:
git clone https://github.com/catherinesyeh/attention-viz.git
cd attention-viz
  1. Download data folder here and unzip. It should be included in the web folder like so:

image

  1. Navigate to back end:
cd web/back/
  1. Create virtual env and activate:
python3 -m venv env
source env/bin/activate
  1. Install requirements:
pip3 install -r requirements.txt
  1. Start back end:
python3 run.py
  1. Navigate to front end:
cd ../front
  1. Install necessary packages and start front end:
npm i
npm run serve
  1. The interface should be running at: http://localhost:8561

citation

If you find this work helpful, please consider citing our paper:

@article{yeh2023attentionviz,
  title={Attentionviz: A global view of transformer attention},
  author={Yeh, Catherine and Chen, Yida and Wu, Aoyu and Chen, Cynthia and Vi{\'e}gas, Fernanda and Wattenberg, Martin},
  journal={IEEE Transactions on Visualization and Computer Graphics},
  year={2023},
  publisher={IEEE}
}

Thank you for checking out AttentionViz!