paddlespeech.s2t.utils.ctc_utils module
- paddlespeech.s2t.utils.ctc_utils.forced_align(ctc_probs: Tensor, y: Tensor, blank_id=0) List[int] [source]
ctc forced alignment.
- Args:
ctc_probs (paddle.Tensor): hidden state sequence, 2d tensor (T, D) y (paddle.Tensor): label id sequence tensor, 1d tensor (L) blank_id (int): blank symbol index
- Returns:
List[int]: best alignment result, (T).
- paddlespeech.s2t.utils.ctc_utils.insert_blank(label: ndarray, blank_id: int = 0) ndarray [source]
Insert blank token between every two label token.
"abcdefg" -> "-a-b-c-d-e-f-g-"
- Args:
label ([np.ndarray]): label ids, List[int], (L). blank_id (int, optional): blank id. Defaults to 0.
- Returns:
[np.ndarray]: (2L+1).
- paddlespeech.s2t.utils.ctc_utils.remove_duplicates_and_blank(hyp: List[int], blank_id=0) List[int] [source]
ctc alignment to ctc label ids.
"abaa-acee-" -> "abaace"
- Args:
hyp (List[int]): hypotheses ids, (L) blank_id (int, optional): blank id. Defaults to 0.
- Returns:
List[int]: remove dupicate ids, then remove blank id.