ArrayAutovisualizer#

class treescope.ArrayAutovisualizer[source]#

Bases: object

An automatic visualizer for arrays.

ArrayAutovisualizer supports any array type registered with an NDArrayAdapter in the global type registry.

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.

  • pixels_per_cell (int | float) – Size of each rendered array element in pixels, between 1 and 21 inclusive. This controls the zoom level of the rendering. Array elements are always drawn at 7 pixels per cell and then rescaled, so out-of-bounds annotations and “digitbox” integer value patterns may not display correctly at fewer than 7 pixels per cell.

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

pixels_per_cell

prefers_column

prefers_row

token_lookup_fn

__call__(value: Any, path: str | None) autovisualize.VisualizationFromTreescopePart | 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.