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.

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.

Metadata

Release files for treescope 0.1.11

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.11
File Size Uploaded Provenance Actions
treescope-0.1.11.tar.gz 142.1 kB Without provenance Details for treescope-0.1.11.tar.gz

Built distribution (wheel)

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

Total release size: 328.3 kB

Release files / treescope-0.1.11.tar.gz

Download URL treescope-0.1.11.tar.gz
Size 142.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8ee25a31dd6d74518aeda636ae362ecb8e91469f63915391cf5f23f65418e9ae
BLAKE2b-256 checksum
How to use checksums
5819f7005a24035a9a262406d1025c33e27d1d8cbce736f3a48d22909eacb044
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

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

Download URL treescope-0.1.11-py3-none-any.whl
Size 186.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
40a9f38ac5c799f6b8763e2b35928afb988fe2dac6fb872fadd1e0bbc21f33f7
BLAKE2b-256 checksum
How to use checksums
f3add66cae717f13d5c9e2dccdcced70112e685e2ab477f0186ed448726195af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.1

Security for treescope 0.1.11

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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