paddlespeech.s2t.decoders.scorers.length_bonus module
Length bonus module.
- class paddlespeech.s2t.decoders.scorers.length_bonus.LengthBonus(n_vocab: int)[source]
Bases:
BatchScorerInterface
Length bonus in beam search.
Methods
batch_init_state
(x)Get an initial state for decoding (optional).
batch_score
(ys, states, xs)Score new token batch.
final_score
(state)Score eos (optional).
init_state
(x)Get an initial state for decoding (optional).
score
(y, state, x)Score new token.
select_state
(state, i[, new_id])Select state with relative ids in the main beam search.
- batch_score(ys: Tensor, states: List[Any], xs: Tensor) Tuple[Tensor, List[Any]] [source]
Score new token batch.
- Args:
ys (paddle.Tensor): paddle.int64 prefix tokens (n_batch, ylen). states (List[Any]): Scorer states for prefix tokens. xs (paddle.Tensor):
The encoder feature that generates ys (n_batch, xlen, n_feat).
- Returns:
- tuple[paddle.Tensor, List[Any]]: Tuple of
batchfied scores for next token with shape of (n_batch, n_vocab) and next state list for ys.