Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
Torchaudio
Commits
e6fccfda
Commit
e6fccfda
authored
Oct 07, 2021
by
Caroline Chen
Browse files
Update RNNT Loss docs and add example (#1835)
parent
5656d5d4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
9 deletions
+26
-9
torchaudio/functional/functional.py
torchaudio/functional/functional.py
+5
-5
torchaudio/transforms.py
torchaudio/transforms.py
+21
-4
No files found.
torchaudio/functional/functional.py
View file @
e6fccfda
...
@@ -1764,17 +1764,17 @@ def rnnt_loss(
...
@@ -1764,17 +1764,17 @@ def rnnt_loss(
dependencies.
dependencies.
Args:
Args:
logits (Tensor): Tensor of dimension (batch, max seq length, max target length + 1, class)
logits (Tensor): Tensor of dimension
`
(batch, max seq length, max target length + 1, class)
`
containing output from joiner
containing output from joiner
targets (Tensor): Tensor of dimension (batch, max target length) containing targets with zero padded
targets (Tensor): Tensor of dimension
`
(batch, max target length)
`
containing targets with zero padded
logit_lengths (Tensor): Tensor of dimension (batch) containing lengths of each sequence from encoder
logit_lengths (Tensor): Tensor of dimension
`
(batch)
`
containing lengths of each sequence from encoder
target_lengths (Tensor): Tensor of dimension (batch) containing lengths of targets for each sequence
target_lengths (Tensor): Tensor of dimension
`
(batch)
`
containing lengths of targets for each sequence
blank (int, optional): blank label (Default: ``-1``)
blank (int, optional): blank label (Default: ``-1``)
clamp (float, optional): clamp for gradients (Default: ``-1``)
clamp (float, optional): clamp for gradients (Default: ``-1``)
reduction (string, optional): Specifies the reduction to apply to the output:
reduction (string, optional): Specifies the reduction to apply to the output:
``'none'`` | ``'mean'`` | ``'sum'``. (Default: ``'mean'``)
``'none'`` | ``'mean'`` | ``'sum'``. (Default: ``'mean'``)
Returns:
Returns:
Tensor: Loss with the reduction option applied. If ``reduction`` is ``'none'``, then size (batch),
Tensor: Loss with the reduction option applied. If ``reduction`` is ``'none'``, then size
`
(batch)
`
,
otherwise scalar.
otherwise scalar.
"""
"""
if
reduction
not
in
[
'none'
,
'mean'
,
'sum'
]:
if
reduction
not
in
[
'none'
,
'mean'
,
'sum'
]:
...
...
torchaudio/transforms.py
View file @
e6fccfda
...
@@ -1450,6 +1450,23 @@ class RNNTLoss(torch.nn.Module):
...
@@ -1450,6 +1450,23 @@ class RNNTLoss(torch.nn.Module):
clamp (float, optional): clamp for gradients (Default: ``-1``)
clamp (float, optional): clamp for gradients (Default: ``-1``)
reduction (string, optional): Specifies the reduction to apply to the output:
reduction (string, optional): Specifies the reduction to apply to the output:
``'none'`` | ``'mean'`` | ``'sum'``. (Default: ``'mean'``)
``'none'`` | ``'mean'`` | ``'sum'``. (Default: ``'mean'``)
Example
>>> # 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()
"""
"""
def
__init__
(
def
__init__
(
...
@@ -1472,11 +1489,11 @@ class RNNTLoss(torch.nn.Module):
...
@@ -1472,11 +1489,11 @@ class RNNTLoss(torch.nn.Module):
):
):
"""
"""
Args:
Args:
logits (Tensor): Tensor of dimension (batch, max seq length, max target length + 1, class)
logits (Tensor): Tensor of dimension
`
(batch, max seq length, max target length + 1, class)
`
containing output from joiner
containing output from joiner
targets (Tensor): Tensor of dimension (batch, max target length) containing targets with zero padded
targets (Tensor): Tensor of dimension
`
(batch, max target length)
`
containing targets with zero padded
logit_lengths (Tensor): Tensor of dimension (batch) containing lengths of each sequence from encoder
logit_lengths (Tensor): Tensor of dimension
`
(batch)
`
containing lengths of each sequence from encoder
target_lengths (Tensor): Tensor of dimension (batch) containing lengths of targets for each sequence
target_lengths (Tensor): Tensor of dimension
`
(batch)
`
containing lengths of targets for each sequence
Returns:
Returns:
Tensor: Loss with the reduction option applied. If ``reduction`` is ``'none'``, then size (batch),
Tensor: Loss with the reduction option applied. If ``reduction`` is ``'none'``, then size (batch),
otherwise scalar.
otherwise scalar.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment