ArrayAutovisualizer#

class penzai.treescope.arrayviz.array_autovisualizer.ArrayAutovisualizer[source]#

Bases: object

An automatic visualizer for arrays.

Variables:
  • maximum_size (int) – Maximum numer of elements of an array to show. Arrays larger than this will be truncated along one or more axes.

  • cutoff_size_per_axis (int) – Maximum number of elements of each individual axis to show without truncation. Any axis longer than this will be truncated, with their visual size increasing logarithmically with the true axis size beyond this point.

  • edge_items (int) – How many values to keep along each axis for truncated arrays.

  • prefers_column (Collection[str]) – Names that should always be assigned to columns.

  • prefers_row (Collection[str]) – Names that should always be assigned to rows.

  • around_zero (bool) – Whether to center continous data around zero.

  • force_continuous (bool) – Whether to always render integer arrays as continuous.

  • include_repr_line_threshold (int) – A threshold such that, if the repr of the array has fewer than that many lines, we will include that repr in the visualization. Useful for seeing small array values.

  • token_lookup_fn (Callable[[int], str] | None) – Optional function that looks up token IDs and adds them to the visualization on hover.

Methods

__init__([maximum_size, ...])

for_tokenizer(tokenizer)

Builds an autovisualizer for a tokenizer.

__call__(value, path)

Implementation of an autovisualizer, visualizing arrays.

Attributes

around_zero

cutoff_size_per_axis

edge_items

force_continuous

include_repr_line_threshold

maximum_size

prefers_column

prefers_row

token_lookup_fn

__call__(value: Any, path: tuple[Any, ...] | None) CustomTreescopeVisualization | None[source]#

Implementation of an autovisualizer, visualizing arrays.

classmethod for_tokenizer(tokenizer: Any)[source]#

Builds an autovisualizer for a tokenizer.

This method constructs an ArrayAutovisualizer that annotates integer array elements with their token strings. This can then be used to autovisualize tokenized arrays.

Parameters:

tokenizer – A tokenizer to use. Either a callable mapping token IDs to strings, or a SentencePieceProcessor.

Returns:

An ArrayAutovisualizer that annotates integer array elements with their token strings.