espnet.nets.scorers.length_bonus.LengthBonus
Less than 1 minute
espnet.nets.scorers.length_bonus.LengthBonus
class espnet.nets.scorers.length_bonus.LengthBonus(n_vocab: int)
Bases: BatchScorerInterface
Length bonus in beam search.
Initialize class.
- Parameters:n_vocab (int) – The number of tokens in vocabulary for beam search
batch_score(ys: Tensor, states: List[Any], xs: Tensor) → Tuple[Tensor, List[Any]]
Score new token batch.
- Parameters:
- ys (torch.Tensor) – torch.int64 prefix tokens (n_batch, ylen).
- states (List *[*Any ]) – Scorer states for prefix tokens.
- xs (torch.Tensor) – The encoder feature that generates ys (n_batch, xlen, n_feat).
- Returns: Tuple of : batchfied scores for next token with shape of (n_batch, n_vocab) and next state list for ys.
- Return type: tuple[torch.Tensor, List[Any]]
score(y, state, x)
Score new token.
- Parameters:
- y (torch.Tensor) – 1D torch.int64 prefix tokens.
- state – Scorer state for prefix tokens
- x (torch.Tensor) – 2D encoder feature that generates ys.
- Returns: Tuple of : torch.float32 scores for next token (n_vocab) and None
- Return type: tuple[torch.Tensor, Any]