> For the complete documentation index, see [llms.txt](https://docs.tensorleap.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tensorleap.ai/tensorleap-integration/python-api/code_loader/leap_binder/set_visualizer.md).

# set\_visualizer

code\_loader.leap\_binder.set\_visualizer

The `leap_binder.set_visualizer` binding function points to [**Visualizer Function**](/tensorleap-integration/writing-integration-code/visualizer-function.md). In addition, it defines the `visualizer_type` and `name` for reference.

```python
code_loader.leap_binder.set_visualizer(
    name=str,
    function=VisualizerCallableInterface,
    visualizer_type=LeapDataType,
    heatmap_visualizer=Optional[Callable[[npt.NDArray[np.float32]], npt.NDArray[np.float32]]]
)
```

<table><thead><tr><th width="158.46928201888204">Args</th><th></th></tr></thead><tbody><tr><td><code>function</code></td><td><em>(</em>VisualizerCallableInterface<em>)</em> This parameter points to the <a href="/tensorleap-integration/writing-integration-code/visualizer-function.md"><strong>Visualizer Function</strong></a> mentioned above.</td></tr><tr><td><code>name</code></td><td><em>(str)</em> with the given name of the <strong>input,</strong> e.g. image.</td></tr><tr><td><code>visualizer_type</code></td><td><em>(</em><a href="/tensorleap-integration/python-api/code_loader/enums/leapdatatype.md"><em><strong>LeapDataType</strong></em></a><em>)</em> This property sets the type of the data to be visualized by the visualizer.</td></tr><tr><td><code>heatmap_visualizer</code></td><td><p><em>(optional)</em></p><p><em>Callable[[npt.NDArray[np.float32]], npt.NDArray[np.float32]]</em><br>This parameter points to a <strong>function</strong> that modifies the heatmap data before visualization.</p></td></tr></tbody></table>

### Examples

#### Basic Usage

```python
import numpy as np
from code_loader.contract.visualizer_classes import LeapText
from code_loader import leap_binder
...

def text_visualizer_func(data: np.ndarray) -> LeapText:
    tokenizer = leap_binder.custom_tokenizer
    text = tokenizer.sequences_to_texts(data)
    return LeapText(text)
    
leap_binder.set_visualizer(
    function=text_visualizer_func,
    visualizer_type=LeapText.type,
    name='text_from_token'
)
```

The [**decoder\_classes**](/tensorleap-integration/python-api/code_loader/visualizer_classes.md) pages contain additional, decoder specific, examples. Moreover, full script usage can be found in [**Integration Script**](/tensorleap-integration/writing-integration-code.md#dataset-script).

#### Resize Image and Heatmap

When changing the original data shape in the *visualizer function,* we need to reshape the heatmap data that is projected. `heatmap_visualizer` points to a function that modifies the heatmap data respectively. Consider the following example:

```python
from code_loader.contract.visualizer_classes import LeapImage
from code_loader import le

def resized_image_visualizer(data: npt.NDArray[np.float32]) -> LeapImage:
    return LeapImage(np.resize(data, (256, 512, 3)))

def resized_image_visualizer_heatmap(data: npt.NDArray[np.float32]) -> npt.NDArray[np.float32]:
    # data is the heatmap with original size (origin_W, origin_H)
    return np.resize(data, (256, 512))    # we reshape to the resized shape


leap_binder.set_visualizer(
    function=resized_image_visualizer,
    name='resized_image_visualizer',
    visualizer_type=LeapImage.type,
    heatmap_visualizer=resized_image_visualizer_heatmap
)
```

#### Guides

Full examples can be found in the **Dataset Integration** section of the following guides:

* [**MNIST Guide**](/guides/full-guides/mnist-guide.md)
* [**IMDB Guide**](/guides/full-guides/imdb-guide.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.tensorleap.ai/tensorleap-integration/python-api/code_loader/leap_binder/set_visualizer.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
