LeapTextMask
code_loader.contract.visualizer_classes.LeapTextMask
Used to visualize text together with an integer mask. Usually used for token-classification tasks (i.e. NER) visualization
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
Args
mask
an np.ndarray of length N. Provides each token with its class. This mask has C unique values.
text
a list of strings that compose the text (length N)
labels
a list of C str labels for the classes.
Examples
Basic Usage
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)
Last updated
Was this helpful?