RNNTLoss¶
- class torchaudio.transforms.RNNTLoss(blank: int = -1, clamp: float = -1.0, reduction: str = 'mean', fused_log_softmax: bool = True)[源代码]¶
从使用循环神经网络的序列转导 [Graves, 2012] 计算 RNN Transducer 损失。
RNN Transducer 损失通过定义所有长度的输出序列的分布,并联合建模输入-输出和输出-输出依赖关系,扩展了 CTC 损失。
- 参数:
- 示例
>>> # Hypothetical values >>> logits = torch.tensor([[[[0.1, 0.6, 0.1, 0.1, 0.1], >>> [0.1, 0.1, 0.6, 0.1, 0.1], >>> [0.1, 0.1, 0.2, 0.8, 0.1]], >>> [[0.1, 0.6, 0.1, 0.1, 0.1], >>> [0.1, 0.1, 0.2, 0.1, 0.1], >>> [0.7, 0.1, 0.2, 0.1, 0.1]]]], >>> dtype=torch.float32, >>> requires_grad=True) >>> targets = torch.tensor([[1, 2]], dtype=torch.int) >>> logit_lengths = torch.tensor([2], dtype=torch.int) >>> target_lengths = torch.tensor([2], dtype=torch.int) >>> transform = transforms.RNNTLoss(blank=0) >>> loss = transform(logits, targets, logit_lengths, target_lengths) >>> loss.backward()
- forward(logits: Tensor, targets: Tensor, logit_lengths: Tensor, target_lengths: Tensor)[源代码]¶
- 参数:
logits (Tensor) – 维度为 (batch, max seq length, max target length + 1, class) 的 Tensor,包含来自 joiner 的输出
targets (Tensor) – 维度为 (batch, max target length) 的 Tensor,包含用零填充的目标
logit_lengths (Tensor) – 维度为 (batch) 的 Tensor,包含来自编码器的每个序列的长度
target_lengths (Tensor) – 维度为 (batch) 的 Tensor,包含每个序列的目标长度
- 返回:
应用 reduction 选项的损失。如果
reduction
为"none"
,则大小为 (batch),否则为标量。- 返回类型:
Tensor