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]], float]] = None, step_max_tokens: int = 100)[source]¶
RNN-T 模型的 Beam Search 解碼器。
另請參閱
torchaudio.pipelines.RNNTBundle: 使用預訓練模型的 ASR 管道。
- 引數:
model (RNNT) – 要使用的 RNN-T 模型。
blank (int) – 詞彙表中 blank 標記的索引。
temperature (float, 可選) – 應用於聯合網路輸出的溫度。值越大,樣本越均勻。(預設值:1.0)
hypo_sort_key (Callable[[Hypothesis], float] 或 None, 可選) – 用於計算給定假設得分以對假設進行排名的可呼叫物件。如果
None,則預設為根據標記序列長度歸一化假設得分的可呼叫物件。(預設值:None)step_max_tokens (int, 可選) – 每個輸入時間步最多發射的標記數量。(預設值: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 找到的 top-
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]] 或 None, 可選) – 表示前一次呼叫中生成的轉錄網路內部狀態的張量列表的列表。(預設值:
None)hypothesis (List[Hypothesis] 或 None) – 用於種子搜尋的,來自前一次呼叫的假設。(預設值:
None)
- 返回:
- List[Hypothesis]
beam search 找到的 top-
beam_width個假設。- List[List[torch.Tensor]]
表示當前呼叫中生成的轉錄網路內部狀態的張量列表的列表。
- 返回型別:
(List[Hypothesis], List[List[torch.Tensor]])