# 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: 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:

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

The question should be specific, self-contained, and written in natural language.
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.
