paddlespeech.s2t.decoders.scorers.ctc module

ScorerInterface implementation for CTC.

class paddlespeech.s2t.decoders.scorers.ctc.CTCPrefixScorer(ctc: Layer, eos: int)[source]

Bases: BatchPartialScorerInterface

Decoder interface wrapper for CTCPrefixScore.

Methods

batch_init_state(x)

Get an initial state for decoding.

batch_score(ys, states, xs)

Score new token batch (required).

batch_score_partial(y, ids, state, x)

Score new token.

extend_prob(x)

Extend probs for decoding.

extend_state(state)

Extend state for decoding.

final_score(state)

Score eos (optional).

init_state(x)

Get an initial state for decoding.

score(y, state, x)

Score new token (required).

score_partial(y, ids, state, x)

Score new token.

select_state(state, i[, new_id])

Select state with relative ids in the main beam search.

batch_init_state(x: Tensor)[source]

Get an initial state for decoding.

Args:

x (paddle.Tensor): The encoded feature tensor

Returns: initial state

batch_score_partial(y, ids, state, x)[source]

Score new token.

Args:

y (paddle.Tensor): 1D prefix token ids (paddle.Tensor): paddle.int64 next token to score state: decoder state for prefix tokens x (paddle.Tensor): 2D encoder feature that generates ys

Returns:
tuple[paddle.Tensor, Any]:

Tuple of a score tensor for y that has a shape (len(next_tokens),) and next state for ys

extend_prob(x: Tensor)[source]

Extend probs for decoding.

This extension is for streaming decoding as in Eq (14) in https://arxiv.org/abs/2006.14941

Args:

x (paddle.Tensor): The encoded feature tensor

extend_state(state)[source]

Extend state for decoding.

This extension is for streaming decoding as in Eq (14) in https://arxiv.org/abs/2006.14941

Args:

state: The states of hyps

Returns: extended state

init_state(x: Tensor)[source]

Get an initial state for decoding.

Args:

x (paddle.Tensor): The encoded feature tensor

Returns: initial state

score_partial(y, ids, state, x)[source]

Score new token.

Args:

y (paddle.Tensor): 1D prefix token next_tokens (paddle.Tensor): paddle.int64 next token to score state: decoder state for prefix tokens x (paddle.Tensor): 2D encoder feature that generates ys

Returns:
tuple[paddle.Tensor, Any]:

Tuple of a score tensor for y that has a shape (len(next_tokens),) and next state for ys

select_state(state, i, new_id=None)[source]

Select state with relative ids in the main beam search.

Args:

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:

state: pruned state