espnet.nets.scorer_interface.ScorerInterface
Less than 1 minute
espnet.nets.scorer_interface.ScorerInterface
class espnet.nets.scorer_interface.ScorerInterface
Bases: object
Scorer interface for beam search.
The scorer performs scoring of the all tokens in vocabulary.
Examples
- Search heuristics : *
espnet.nets.scorers.length_bonus.LengthBonus
- Decoder networks of the sequence-to-sequence models : *
espnet.nets.pytorch_backend.nets.transformer.decoder.Decoder
espnet.nets.pytorch_backend.nets.rnn.decoders.Decoder
- Neural language models : *
espnet.nets.pytorch_backend.lm.transformer.TransformerLM
final_score(state: Any) → float
Score eos (optional).
- Parameters:state – Scorer state for prefix tokens
- Returns: final score
- Return type: float
init_state(x: Tensor) → Any
Get an initial state for decoding (optional).
- Parameters:x (torch.Tensor) – The encoded feature tensor
Returns: initial state
score(y: Tensor, state: Any, x: Tensor) → Tuple[Tensor, Any]
Score new token (required).
- Parameters:
- y (torch.Tensor) – 1D torch.int64 prefix tokens.
- state – Scorer state for prefix tokens
- x (torch.Tensor) – The encoder feature that generates ys.
- Returns: Tuple of : scores for next token that has a shape of (n_vocab) and next state for ys
- Return type: tuple[torch.Tensor, Any]
select_state(state: Any, i: int, new_id: int | None = None) → Any
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 index to select a state if necessary
- Returns: pruned state
- Return type: state