Skip to main content

Create interactive textual heat maps for Jupiter notebooks

Project description


Create interactive textual heatmaps for Jupiter notebooks.

I originally published this visualization method in my distill paper In this context, it is used as a saliency map for showing which parts of a sentence are used to predict the next word. However, the visualization method is more general-purpose than that and can be used for any kind of textual heatmap purposes.

textualheatmap works with python 3.6 or newer and is distributed under the MIT license.

Gif of textualheatmap


pip install -U textualheatmap



Example of sequential-charecter model with metadata visible

Open In Colab

from textualheatmap import TextualHeatmap

data = [[
    # GRU data
    {"token":" ",
    {"token":" ",
    # ...
    # LSTM data
    # ...

heatmap = TextualHeatmap(
    width = 600,
    show_meta = True,
    facet_titles = ['GRU', 'LSTM']
# Set data and render plot, this can be called again to replace
# the data.
# Focus on the token with the given index. Especially useful when
# `interactive=False` is used in `TextualHeatmap`.

Gif of learning-curve for keras example

Example of sequential-charecter model without metadata

Open In Colab

heatmap = TextualHeatmap(
    show_meta = False,
    facet_titles = ['LSTM', 'GRU'],
    rotate_facet_titles = True

Gif of learning-curve for keras example

Example of non-sequential-word model

Open In Colab

format = True can be set in the data object to inducate tokens that are not directly used by the model. This is useful if word or sub-word tokenization is used.

data = [[
{'token': '[CLR]',
 'meta': ['', '', ''],
 'heat': [1, 0, 0, 0, 0, ...]},
{'token': ' ',
 'format': True},
{'token': 'context',
 'meta': ['today', 'and', 'thus'],
 'heat': [0.13, 0.40, 0.23, 1.0, 0.56, ...]},
{'token': ' ',
 'format': True},
{'token': 'the',
 'meta': ['##ual', 'the', '##ually'],
 'heat': [0.11, 1.0, 0.34, 0.58, 0.59, ...]},
{'token': ' ',
 'format': True},
{'token': 'formal',
 'meta': ['formal', 'academic', 'systematic'],
 'heat': [0.13, 0.74, 0.26, 0.35, 1.0, ...]},
{'token': ' ',
 'format': True},
{'token': 'study',
 'meta': ['##ization', 'study', '##ity'],
 'heat': [0.09, 0.27, 0.19, 1.0, 0.26, ...]}

heatmap = TextualHeatmap(facet_titles = ['BERT'], show_meta=True)


If you use this in a publication, please cite my Distill publication where I first demonstrated this visualization method.

  author = {Madsen, Andreas},
  title = {Visualizing memorization in RNNs},
  journal = {Distill},
  year = {2019},
  note = {},
  doi = {10.23915/distill.00016}


Sponsored by NearForm Research.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for textualheatmap, version 1.1.1
Filename, size File type Python version Upload date Hashes
Filename, size textualheatmap-1.1.1.tar.gz (8.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page