Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to use Tanh instead of ReLU in RNNT joiner #2319

Closed
wants to merge 4 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions torchaudio/models/rnnt.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,20 @@ class _Joiner(torch.nn.Module):
Args:
input_dim (int): source and target input dimension.
output_dim (int): output dimension.
joiner_activation (str, optional): activation function to use in the joiner
Must be one of ("relu", "tanh"). (Default: "relu")

"""

def __init__(self, input_dim: int, output_dim: int) -> None:
def __init__(self, input_dim: int, output_dim: int, joiner_activation: str = "relu") -> None:
xiaohui-zhang marked this conversation as resolved.
Show resolved Hide resolved
xiaohui-zhang marked this conversation as resolved.
Show resolved Hide resolved
super().__init__()
self.linear = torch.nn.Linear(input_dim, output_dim, bias=True)
self.relu = torch.nn.ReLU()
if joiner_activation == "relu":
self.activation = torch.nn.ReLU()
elif joiner_activation == "tanh":
self.activation = torch.nn.Tanh()
else:
raise ValueError(f"Unsupported activation {joiner_activation}")

def forward(
self,
Expand Down Expand Up @@ -419,8 +427,8 @@ def forward(
number of valid elements along dim 2 for i-th batch element in joint network output.
"""
joint_encodings = source_encodings.unsqueeze(2).contiguous() + target_encodings.unsqueeze(1).contiguous()
relu_out = self.relu(joint_encodings)
output = self.linear(relu_out)
activation_out = self.activation(joint_encodings)
output = self.linear(activation_out)
return output, source_lengths, target_lengths


Expand Down