Python torch.nn.Softsign() Examples
The following are 5
code examples of torch.nn.Softsign().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
torch.nn
, or try the search function
.
Example #1
Source File: utils.py From dgl with Apache License 2.0 | 5 votes |
def get_activation(act): """Get the activation based on the act string Parameters ---------- act: str or callable function Returns ------- ret: callable function """ if act is None: return lambda x: x if isinstance(act, str): if act == 'leaky': return nn.LeakyReLU(0.1) elif act == 'relu': return nn.ReLU() elif act == 'tanh': return nn.Tanh() elif act == 'sigmoid': return nn.Sigmoid() elif act == 'softsign': return nn.Softsign() else: raise NotImplementedError else: return act
Example #2
Source File: Base_Network.py From nn_builder with MIT License | 5 votes |
def create_str_to_activations_converter(self): """Creates a dictionary which converts strings to activations""" str_to_activations_converter = {"elu": nn.ELU(), "hardshrink": nn.Hardshrink(), "hardtanh": nn.Hardtanh(), "leakyrelu": nn.LeakyReLU(), "logsigmoid": nn.LogSigmoid(), "prelu": nn.PReLU(), "relu": nn.ReLU(), "relu6": nn.ReLU6(), "rrelu": nn.RReLU(), "selu": nn.SELU(), "sigmoid": nn.Sigmoid(), "softplus": nn.Softplus(), "logsoftmax": nn.LogSoftmax(), "softshrink": nn.Softshrink(), "softsign": nn.Softsign(), "tanh": nn.Tanh(), "tanhshrink": nn.Tanhshrink(), "softmin": nn.Softmin(), "softmax": nn.Softmax(dim=1), "none": None} return str_to_activations_converter
Example #3
Source File: model.py From cnn_vocoder with MIT License | 5 votes |
def __init__(self, n_heads=3, layer_channels=DEFAULT_LAYERS_PARAMS, pre_conv_channels=[64, 32, 16, 8, 4], pre_residuals=64, up_residuals=0, post_residuals=3): super(CNNVocoder, self).__init__() self.head = Head(layer_channels, pre_conv_channels=pre_conv_channels, pre_residuals=pre_residuals, up_residuals=up_residuals, post_residuals=post_residuals) self.linear = nn.Linear(layer_channels[-1], 1) self.act_fn = nn.Softsign()
Example #4
Source File: RewardModel.py From AREL with MIT License | 5 votes |
def __init__(self, opt): super(RewardModel, self).__init__() self.vocab_size = opt.vocab_size self.word_embed_dim = 300 self.feat_size = opt.feat_size self.kernel_num = 512 self.kernels = [2, 3, 4, 5] self.out_dim = len(self.kernels) * self.kernel_num + self.word_embed_dim self.emb = nn.Embedding(self.vocab_size, self.word_embed_dim) self.emb.weight.data.copy_(torch.from_numpy(np.load("VIST/embedding.npy"))) self.proj = nn.Linear(self.feat_size, self.word_embed_dim) self.convs = [nn.Conv2d(1, self.kernel_num, (k, self.word_embed_dim)) for k in self.kernels] self.dropout = nn.Dropout(opt.dropout) self.fc = nn.Linear(self.out_dim, 1, bias=True) if opt.activation.lower() == "linear": self.activation = None elif opt.activation.lower() == "sign": self.activation = nn.Softsign() elif self.activation.lower() == "tahn": self.activation = nn.Tanh()
Example #5
Source File: activation.py From claf with MIT License | 5 votes |
def get_activation_fn(name): """ PyTorch built-in activation functions """ activation_functions = { "linear": lambda: lambda x: x, "relu": nn.ReLU, "relu6": nn.ReLU6, "elu": nn.ELU, "prelu": nn.PReLU, "leaky_relu": nn.LeakyReLU, "threshold": nn.Threshold, "hardtanh": nn.Hardtanh, "sigmoid": nn.Sigmoid, "tanh": nn.Tanh, "log_sigmoid": nn.LogSigmoid, "softplus": nn.Softplus, "softshrink": nn.Softshrink, "softsign": nn.Softsign, "tanhshrink": nn.Tanhshrink, } if name not in activation_functions: raise ValueError( f"'{name}' is not included in activation_functions. use below one. \n {activation_functions.keys()}" ) return activation_functions[name]