RNNT¶
- class torchaudio.models.RNNT[source]¶
循环神经网络换能器 (RNN-T) 模型。
注意
要构建模型,请使用其中一个工厂函数。
另请参阅
torchaudio.pipelines.RNNTBundle
: 带有预训练模型的 ASR 流水线。- 参数
transcriber (torch.nn.Module) – 识别网络。
predictor (torch.nn.Module) – 预测网络。
joiner (torch.nn.Module) – 连接网络。
方法¶
forward¶
- RNNT.forward(sources: Tensor, source_lengths: Tensor, targets: Tensor, target_lengths: Tensor, predictor_state: Optional[List[List[Tensor]]] = None) Tuple[Tensor, Tensor, Tensor, List[List[Tensor]]] [source]¶
用于训练的前向传播。
B:批次大小;T:批次中的最大源序列长度;U:批次中的最大目标序列长度;D:每个源序列元素的特征维度。
- 参数
sources (torch.Tensor) – 右填充了右上下文的源帧序列,形状为 (B, T, D)。
source_lengths (torch.Tensor) – 形状为 (B,),其中第 i 个元素表示
sources
中第 i 个批次元素的有效帧数。targets (torch.Tensor) – 目标序列,形状为 (B, U),每个元素映射到一个目标符号。
target_lengths (torch.Tensor) – 形状为 (B,),其中第 i 个元素表示
targets
中第 i 个批次元素的有效帧数。predictor_state (List[List[torch.Tensor]] 或 None, optional) – 预测网络在先前调用
forward
时生成的内部状态的张量列表。 (默认:None
)
- 返回
- torch.Tensor
连接网络输出,形状为 (B, 最大输出源长度, 最大输出目标长度, output_dim (目标符号数))。
- torch.Tensor
输出源长度,形状为 (B,),其中第 i 个元素表示连接网络输出中第 i 个批次元素的第 1 维的有效长度。
- torch.Tensor
输出目标长度,形状为 (B,),其中第 i 个元素表示连接网络输出中第 i 个批次元素的第 2 维的有效长度。
- List[List[torch.Tensor]]
输出状态;预测网络在当前调用
forward
时生成的内部状态的张量列表。
- 返回类型
(torch.Tensor, torch.Tensor, torch.Tensor, List[List[torch.Tensor]])
transcribe_streaming¶
- RNNT.transcribe_streaming(sources: Tensor, source_lengths: Tensor, state: Optional[List[List[Tensor]]]) Tuple[Tensor, Tensor, List[List[Tensor]]] [source]¶
以流式模式将识别网络应用于源。
B:批次大小;T:批次中的最大源序列段长度;D:每个源序列帧的特征维度。
- 参数
sources (torch.Tensor) – 右填充了右上下文的源帧序列段,形状为 (B, T + right context length, D)。
source_lengths (torch.Tensor) – 形状为 (B,),其中第 i 个元素表示
sources
中第 i 个批次元素的有效帧数。state (List[List[torch.Tensor]] 或 None) – 识别网络在先前调用
transcribe_streaming
时生成的内部状态的张量列表。
- 返回
- torch.Tensor
输出帧序列,形状为 (B, T // time_reduction_stride, output_dim)。
- torch.Tensor
输出长度,形状为 (B,),其中第 i 个元素表示输出帧序列中第 i 个批次元素的有效长度。
- List[List[torch.Tensor]]
输出状态;识别网络在当前调用
transcribe_streaming
时生成的内部状态的张量列表。
- 返回类型
(torch.Tensor, torch.Tensor, List[List[torch.Tensor]])
transcribe¶
- RNNT.transcribe(sources: Tensor, source_lengths: Tensor) Tuple[Tensor, Tensor] [source]¶
以非流式模式将识别网络应用于源。
B:批次大小;T:批次中的最大源序列长度;D:每个源序列帧的特征维度。
- 参数
sources (torch.Tensor) – 右填充了右上下文的源帧序列,形状为 (B, T + right context length, D)。
source_lengths (torch.Tensor) – 形状为 (B,),其中第 i 个元素表示
sources
中第 i 个批次元素的有效帧数。
- 返回
- torch.Tensor
输出帧序列,形状为 (B, T // time_reduction_stride, output_dim)。
- torch.Tensor
输出长度,形状为 (B,),其中第 i 个元素表示输出帧序列中第 i 个批次元素的有效长度。
- 返回类型
predict¶
- RNNT.predict(targets: Tensor, target_lengths: Tensor, state: Optional[List[List[Tensor]]]) Tuple[Tensor, Tensor, List[List[Tensor]]] [source]¶
将预测网络应用于目标。
B:批次大小;U:批次中的最大目标序列长度;D:每个目标序列帧的特征维度。
- 参数
targets (torch.Tensor) – 目标序列,形状为 (B, U),每个元素映射到一个目标符号,即在范围 [0, num_symbols) 内。
target_lengths (torch.Tensor) – 形状为 (B,),其中第 i 个元素表示
targets
中第 i 个批次元素的有效帧数。state (List[List[torch.Tensor]] 或 None) – 目标网络在先前调用
predict
时生成的内部状态的张量列表。
- 返回
- torch.Tensor
输出帧序列,形状为 (B, U, output_dim)。
- torch.Tensor
输出长度,形状为 (B,),其中第 i 个元素表示输出帧序列中第 i 个批次元素的有效长度。
- List[List[torch.Tensor]]
输出状态;目标网络在当前调用
predict
时生成的内部状态的张量列表。
- 返回类型
(torch.Tensor, torch.Tensor, List[List[torch.Tensor]])
join¶
- RNNT.join(source_encodings: Tensor, source_lengths: Tensor, target_encodings: Tensor, target_lengths: Tensor) Tuple[Tensor, Tensor, Tensor] [source]¶
将连接网络应用于源和目标编码。
B:批次大小;T:批次中的最大源序列长度;U:批次中的最大目标序列长度;D:每个源和目标序列编码的维度。
- 参数
source_encodings (torch.Tensor) – 源编码序列,形状为 (B, T, D)。
source_lengths (torch.Tensor) – 形状为 (B,),其中第 i 个元素表示
source_encodings
中第 i 个批次元素的有效序列长度。target_encodings (torch.Tensor) – 目标编码序列,形状为 (B, U, D)。
target_lengths (torch.Tensor) – 形状为 (B,),其中第 i 个元素表示
target_encodings
中第 i 个批次元素的有效序列长度。
- 返回
- torch.Tensor
连接网络输出,形状为 (B, T, U, output_dim)。
- torch.Tensor
输出源长度,形状为 (B,),其中第 i 个元素表示连接网络输出中第 i 个批次元素的第 1 维的有效长度。
- torch.Tensor
输出目标长度,形状为 (B,),其中第 i 个元素表示连接网络输出中第 i 个批次元素的第 2 维的有效长度。
- 返回类型
工厂函数¶
构建基于 Emformer 的 |
|
构建基于 Emformer 的 |
Prototype Factory Functions¶
已弃用 |
|
已弃用 |