Skip to main content

Treescope

Treescope is an interactive HTML pretty-printer and N-dimensional array ("tensor") visualizer, designed for machine learning and neural networks research in IPython notebooks. It's a drop-in replacement for the standard IPython/Colab renderer, and adds support for:

  • Expanding and collapsing subtrees of rendered objects, to let you focus on the parts of your model that you care about,
  • Automatically embedding faceted visualizations of arbitrary-dimensional arrays and tensors directly into the output renderings, so you can quickly understand their shapes and the distribution of their values,
  • Color-coding parts of neural network models to emphasize shared structures,
  • Inserting "copy path" buttons that let you easily copy the path to any part of a rendered object,
  • Customizing the visualization strategy to support rendering your own data structures,
  • And more!

Treescope was originally developed as the pretty-printer for the Penzai neural network library, but it also supports rendering neural networks developed with other libraries, including Equinox, Flax NNX, and PyTorch. You can also use it with basic JAX and Numpy code.

With Treescope, instead of looking at this:

Screenshot of a parameter dictionary without Treescope

You could be looking at this:

Screenshot of a parameter dictionary using Treescope

This is an interactive visualization; try clicking the ▶ buttons to expand parts of the output! (You can also hold shift while scrolling to scroll horizontally instead of vertically.)

Documentation on Treescope can be found at https://treescope.readthedocs.io.

Getting Started

You can install Treescope using:

pip install treescope

and import it using:

import treescope

To render a specific object in an IPython notebook with Treescope, you can use treescope.show, which is like print but produces a rich interactive output.

Alternatively, you can simply configure Treescope as the default pretty printer for your notebook via:

treescope.register_as_default()

To turn on automatic array visualization, you can run:

treescope.active_autovisualizer.set_globally(treescope.ArrayAutovisualizer())

Or, if you'd like to both set up Treescope as the default pretty printer and enable automatic array visualization, you can simply run:

treescope.basic_interactive_setup(autovisualize_arrays=True)

Once you've rendered an object, try clicking on it and pressing the r key! This turns on "roundtrip mode", and adds qualified names to every type in the visualization, making it easier to identify what the types in your object are.

[!TIP] If Treescope's outputs are too verbose, or if you are using a terminal that wraps lines, you can configure Treescope to abbreviate collapsed objects at a given depth using:

treescope.basic_interactive_setup(
    autovisualize_arrays=True,
    abbreviation_threshold=1,  # or a different value
)

You can also configure the abbreviation threshold manually by overriding treescope.abbreviation_threshold using the .set_globally or .set_scoped methods.

For more information on how to use Treescope, check out the Treescope documentation.

Looking for a neural network library with first-class support for Treescope's visualization features? Try Penzai!

Citation

If you have found Treescope to be useful for your research, please consider citing the following writeup (also available on arXiv):

@article{johnson2024penzai,
    author={Daniel D. Johnson},
    title={{Penzai} + {Treescope}: A Toolkit for Interpreting, Visualizing, and Editing Models As Data},
    year={2024},
    journal={ICML 2024 Workshop on Mechanistic Interpretability}
}

This is not an officially supported Google product.

Release files for treescope 0.1.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for treescope 0.1.10
File Size Uploaded
treescope-0.1.10.tar.gz 138.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for treescope 0.1.10
File Interpreter ABI Platform
treescope-0.1.10-py3-none-any.whl Python 3 none any Details

Total release size: 321.1 kB

Release files / treescope-0.1.10.tar.gz

Download URL treescope-0.1.10.tar.gz
Size 138.9 kB
Tags Source
SHA-256 checksum
How to use checksums
20f74656f34ab2d8716715013e8163a0da79bdc2554c16d5023172c50d27ea95
BLAKE2b-256 checksum
How to use checksums
f02ad13d3c38862632742d2fe2f7ae307c431db06538fd05ca03020d207b5dcc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.9

Release files / treescope-0.1.10-py3-none-any.whl

Download URL treescope-0.1.10-py3-none-any.whl
Size 182.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dde52f5314f4c29d22157a6fe4d3bd103f9cae02791c9e672eefa32c9aa1da51
BLAKE2b-256 checksum
How to use checksums
432b36e984399089c026a6499ac8f7401d38487cf0183839a4aa78140d373771
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.9

Release history Release notifications | RSS feed

This release

0.1.10 This release

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page