RNNTBeamSearch¶
- class torchaudio.models.RNNTBeamSearch(model: RNNT, blank: int, temperature: float = 1.0, hypo_sort_key: Optional[Callable[[Tuple[List[int], Tensor, List[List[Tensor]], float]] = None, step_max_tokens: int = 100)[source]¶
RNN-T 模型的 Beam search 解碼器。
另請參閱
torchaudio.pipelines.RNNTBundle
:具有預訓練模型的 ASR pipeline。
- 參數:
model (RNNT) – 要使用的 RNN-T 模型。
blank (int) – 詞彙表中空白符號的索引。
temperature (float, optional) – 應用於聯合網路輸出的溫度。較大的值會產生更均勻的樣本。(預設值:1.0)
hypo_sort_key (Callable[[Hypothesis], float] or None, optional) – 可呼叫物件,用於計算給定假設的分數,以對假設進行排名。如果為 None,則預設為可呼叫物件,該物件返回按符號序列長度正規化的假設分數。(預設值:None)
step_max_tokens (int, optional) – 每個輸入時間步要發出的最大符號數。(預設值:100)
- 使用
RNNTBeamSearch
的教學
方法¶
forward¶
- RNNTBeamSearch.forward(input: Tensor, length: Tensor, beam_width: int) List[Tuple[List[int], Tensor, List[List[Tensor]], float]] [source]¶
為給定的輸入序列執行 beam search。
T:幀數;D:每幀的特徵維度。
- 參數:
input (torch.Tensor) – 輸入幀序列,形狀為 (T, D) 或 (1, T, D)。
length (torch.Tensor) – 輸入序列中有效幀的數量,形狀為 () 或 (1,)。
beam_width (int) – 搜尋期間要使用的 beam 大小。
- 回傳:
beam search 找到的前
beam_width
個假設。- 回傳類型:
List[Hypothesis]
infer¶
- RNNTBeamSearch.infer(input: Tensor, length: Tensor, beam_width: int, state: Optional[List[List[Tensor]]] = None, hypothesis: Optional[List[Tuple[List[int], Tensor, List[List[Tensor]], float]]] = None) Tuple[List[Tuple[List[int], Tensor, List[List[Tensor]], float]], List[List[Tensor]]] [source]¶
在串流模式下,為給定的輸入序列執行 beam search。
T:幀數;D:每幀的特徵維度。
- 參數:
input (torch.Tensor) – 輸入幀序列,形狀為 (T, D) 或 (1, T, D)。
length (torch.Tensor) – 輸入序列中有效幀的數量,形狀為 () 或 (1,)。
beam_width (int) – 搜尋期間要使用的 beam 大小。
state (List[List[torch.Tensor]] or None, optional) – 表示前一次調用中產生的轉錄網路內部狀態的張量列表的列表。(預設值:
None
)hypothesis (List[Hypothesis] or None) – 來自前一次調用的假設,用於為搜尋提供種子。(預設值:
None
)
- 回傳:
- List[Hypothesis]
beam search 找到的前
beam_width
個假設。- List[List[torch.Tensor]]
表示目前調用中產生的轉錄網路內部狀態的張量列表的列表。
- 回傳類型:
(List[Hypothesis], List[List[torch.Tensor]])