espnet.nets.scorers.ctc.CTCPrefixScorer
espnet.nets.scorers.ctc.CTCPrefixScorer
class espnet.nets.scorers.ctc.CTCPrefixScorer(ctc: Module, eos: int)
Bases: BatchPartialScorerInterface
Decoder interface wrapper for CTCPrefixScore.
Initialize class.
- Parameters:
- ctc (torch.nn.Module) – The CTC implementation. For example,
espnet.nets.pytorch_backend.ctc.CTC
- eos (int) – The end-of-sequence id.
- ctc (torch.nn.Module) – The CTC implementation. For example,
batch_init_state(x: Tensor)
Get an initial state for decoding.
- Parameters:x (torch.Tensor) – The encoded feature tensor
Returns: initial state
batch_score_partial(y, ids, state, x)
Score new token.
- Parameters:
- y (torch.Tensor) – 1D prefix token
- ids (torch.Tensor) – torch.int64 next token to score
- state – decoder state for prefix tokens
- x (torch.Tensor) – 2D encoder feature that generates ys
- Returns: Tuple of a score tensor for y that has a shape (len(next_tokens),) and next state for ys
- Return type: tuple[torch.Tensor, Any]
extend_prob(x: Tensor)
Extend probs for decoding.
This extension is for streaming decoding as in Eq (14) in https://arxiv.org/abs/2006.14941
- Parameters:x (torch.Tensor) – The encoded feature tensor
extend_state(state)
Extend state for decoding.
This extension is for streaming decoding as in Eq (14) in https://arxiv.org/abs/2006.14941
- Parameters:state – The states of hyps
Returns: exteded state
init_state(x: Tensor)
Get an initial state for decoding.
- Parameters:x (torch.Tensor) – The encoded feature tensor
Returns: initial state
score_partial(y, ids, state, x)
Score new token.
- Parameters:
- y (torch.Tensor) – 1D prefix token
- next_tokens (torch.Tensor) – torch.int64 next token to score
- state – decoder state for prefix tokens
- x (torch.Tensor) – 2D encoder feature that generates ys
- Returns: Tuple of a score tensor for y that has a shape (len(next_tokens),) and next state for ys
- Return type: tuple[torch.Tensor, Any]
select_state(state, i, new_id=None)
Select state with relative ids in the main beam search.
- Parameters:
- state – Decoder state for prefix tokens
- i (int) – Index to select a state in the main beam search
- new_id (int) – New label id to select a state if necessary
- Returns: pruned state
- Return type: state