> 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/visualizer_classes/leaptextmask.md).

# LeapTextMask

Used to visualize text together with an integer mask. Usually used for token-classification tasks (i.e. NER) visualization

```python
import numpy.typing as npt
from code_loader.contract.enums import LeapDataType

@dataclass
class LeapTextMask:
    mask: npt.NDArray[np.uint8]
    text: List[str]
    labels: List[str]
    type: LeapDataType = LeapDataType.TextMask
```

<table><thead><tr><th width="167.39065467110788">Args</th><th></th></tr></thead><tbody><tr><td><code>mask</code></td><td>an np.ndarray of length N. Provides each token with its class. This mask has C unique values.</td></tr><tr><td><code>text</code></td><td>a list of strings that compose the text (length N)</td></tr><tr><td><code>labels</code></td><td>a list of C str labels for the classes. </td></tr></tbody></table>

## Examples

#### Basic Usage

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

@tensorleap_custom_visualizer(name="mask_visualizer_comb", visualizer_type=LeapDataType.TextMask)
def text_segmentation_visualizer(data: np.ndarray, segmentation_prediction: np.ndarray) -> LeapTextMask:
    labels = ['neutral', 'positive', 'negative']
    tokenizer = leap_binder.custom_tokenizer
    text = tokenizer.sequences_to_texts(data)
    return LeapTextMask(mask=segmentation_prediction.squeeze(0), text=text, labels=labels)
```


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.tensorleap.ai/tensorleap-integration/python-api/code_loader/visualizer_classes/leaptextmask.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
