espnet2.legacy.nets.batch_beam_search.BatchHypothesis
espnet2.legacy.nets.batch_beam_search.BatchHypothesis
class espnet2.legacy.nets.batch_beam_search.BatchHypothesis(yseq: Tensor = tensor([]), score: Tensor = tensor([]), length: Tensor = tensor([]), scores: Dict[str, Tensor] = {}, states: Dict[str, Dict] = {}, hs: List[Tensor] = [], n_utt: int = 1, active: Tensor | None = None, done: Tensor | None = None)
Bases: NamedTuple
Batchfied/Vectorized hypothesis data type.
The hypotheses of n_utt utterances are held in a single flat batch laid out as utterance-major, i.e. the hypotheses of utterance b occupy b * n_hyp_per_utt .. (b + 1) * n_hyp_per_utt. This is the layout CTCPrefixScoreTH assumes, which recovers the utterance index of a hypothesis as flat_index // n_hyp_per_utt.
When a single utterance is decoded (n_utt == 1) the batch is compacted after every step, so it holds only the hypotheses that are still running. That is not possible with several utterances, because CTCPrefixScoreTH needs the same number of hypotheses for each of them; there, finished hypotheses are flagged in active instead and stay in the batch.
Create new instance of BatchHypothesis(yseq, score, length, scores, states, hs, n_utt, active, done)
active : Tensor | None
Alias for field number 7
active_mask() → Tensor
Return the active flags, materializing the all-active default.
done : Tensor | None
Alias for field number 8
done_mask() → Tensor
Return the done flags, materializing the none-done default.
hs : List[Tensor]
Alias for field number 5
length : Tensor
Alias for field number 2
property n_hyp_per_utt : int
Return H, the number of slots each utterance owns.
n_utt : int
Alias for field number 6
replace(**kwargs) → BatchHypothesis
Return a copy with some fields replaced.
NOTE: NamedTuple._replace cannot be used because this class overrides __len__, which _replace relies on internally.
score : Tensor
Alias for field number 1
scores : Dict[str, Tensor]
Alias for field number 3
states : Dict[str, Dict]
Alias for field number 4
yseq : Tensor
Alias for field number 0
