-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(model): keep name pattern of class mapping (#2175)
- Loading branch information
1 parent
4c4878e
commit 0df2759
Showing
9 changed files
with
40 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# Copyright [2023-11-28] <[email protected], Xingchen Song> | ||
import torch | ||
|
||
from wenet.transformer.swish import Swish | ||
from wenet.transformer.subsampling import ( | ||
LinearNoSubsampling, EmbedinigNoSubsampling, | ||
Conv1dSubsampling2, Conv2dSubsampling4, | ||
|
@@ -21,32 +22,20 @@ | |
from wenet.efficient_conformer.attention import GroupedRelPositionMultiHeadedAttention | ||
|
||
|
||
def get_activation(act): | ||
"""Return activation function.""" | ||
# Lazy load to avoid unused import | ||
from wenet.transformer.swish import Swish | ||
|
||
activation_funcs = { | ||
"hardtanh": torch.nn.Hardtanh, | ||
"tanh": torch.nn.Tanh, | ||
"relu": torch.nn.ReLU, | ||
"selu": torch.nn.SELU, | ||
"swish": getattr(torch.nn, "SiLU", Swish), | ||
"gelu": torch.nn.GELU | ||
} | ||
|
||
return activation_funcs[act]() | ||
|
||
|
||
def get_rnn(rnn_type: str) -> torch.nn.Module: | ||
assert rnn_type in ["rnn", "lstm", "gru"] | ||
if rnn_type == "rnn": | ||
return torch.nn.RNN | ||
elif rnn_type == "lstm": | ||
return torch.nn.LSTM | ||
else: | ||
return torch.nn.GRU | ||
WENET_ACTIVATION_CLASSES = { | ||
"hardtanh": torch.nn.Hardtanh, | ||
"tanh": torch.nn.Tanh, | ||
"relu": torch.nn.ReLU, | ||
"selu": torch.nn.SELU, | ||
"swish": getattr(torch.nn, "SiLU", Swish), | ||
"gelu": torch.nn.GELU, | ||
} | ||
|
||
WENET_RNN_CLASSES = { | ||
"rnn": torch.nn.RNN, | ||
"lstm": torch.nn.LSTM, | ||
"gru": torch.nn.GRU, | ||
} | ||
|
||
WENET_SUBSAMPLE_CLASSES = { | ||
"linear": LinearNoSubsampling, | ||
|