Skip to content

shashwattrivedi/Attention_visualizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

Attention_visualizer

A simple visualization of attention weights on text for notebook using d3.

Usage

The function requires sentence tokens as list with corresponding attention weights as another list.

sentence = [ 'i', 'liked', 'the', 'movie', 'it', 'was', 'entertaining']
attention_weights = [1.5457647e-02, 6.5744676e-02, 1.8066147e-04, 1.2420971e-02, 1.6833000e-03, 4.1709002e-04, 4.4919562e-01]
 
display_attention(sentence,attention_weights)

attention_img

You can hover over the word to get the attention weight value.

attention_hover_img

Another style

display_attention(sentence,attention_weights,
                  scale=40,  #max increase in font-size
                  offset=18, #base font-size for whole text
                  style=0)   #for 2nd style

attention_style2

About

A visualizer to display attention weights on text

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages