vak.common.labels.multi_char_labels_to_single_char#

vak.common.labels.multi_char_labels_to_single_char(labelmap: dict, skip: tuple[str] = ('unlabeled',)) dict[source]#

Return a copy of a labelmap where any labels that are strings with multiple characters are converted to single characters.

This makes it possible to correctly compute metrics like Levenshtein edit distance.

Labels that are strings with multiple characters are replaced by a single-label character from the constant vak.labels.DUMMY_SINGLE_CHAR_LABELS. The replacement is grabbed with the index of the multi-character label from the sorted dict.

Parameters:
  • labelmap (dict) – That maps human-readable string labels to integers. As returned by vak.labels.to_map.

  • skip (tuple) – Of strings, labels to leave as multiple characters. Default is (‘unlabeled’,).

Returns:

labelmap – Where any keys with multiple characters in string are converted to dummy single characters.

Return type:

dict