espnet3.systems.esp2_cls.src.scoring_utils.load_class_labels
Less than 1 minute
espnet3.systems.esp2_cls.src.scoring_utils.load_class_labels
espnet3.systems.esp2_cls.src.scoring_utils.load_class_labels(token_list: str | Path) → List[str]
Read a token list and return class labels in classifier output order.
The final entry is dropped to mirror n_classes = len(token_list) - 1 in espnet2/tasks/cls.py, where the trailing <unk> is not a class. A token list that does not end with <unk> is rejected, because dropping its last entry would silently discard a real class.
- Parameters:token_list – Path to the token list written by the
prepare_labelsstage, which must be configured withadd_symbol: ["<unk>:-1"]. - Returns: Class labels ordered to match the score vector.
- Return type: List[str]
- Raises:ValueError – If the token list holds fewer than two entries, or does not end with
<unk>.
Example
>>> load_class_labels("data/token_list")
['neutral', 'joy', 'surprise', 'anger', 'sadness', 'disgust', 'fear']