本文整理汇总了Python中mxnet.gluon.rnn.RNN属性的典型用法代码示例。如果您正苦于以下问题:Python rnn.RNN属性的具体用法?Python rnn.RNN怎么用?Python rnn.RNN使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类mxnet.gluon.rnn
的用法示例。
在下文中一共展示了rnn.RNN属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from mxnet.gluon import rnn [as 别名]
# 或者: from mxnet.gluon.rnn import RNN [as 别名]
def __init__(self, mode, vocab_size, num_embed, num_hidden,
num_layers, dropout=0.5, tie_weights=False, **kwargs):
super(RNNModel, self).__init__(**kwargs)
with self.name_scope():
self.drop = nn.Dropout(dropout)
self.encoder = nn.Embedding(vocab_size, num_embed,
weight_initializer=mx.init.Uniform(0.1))
if mode == 'rnn_relu':
self.rnn = rnn.RNN(num_hidden, num_layers, dropout=dropout,
input_size=num_embed)
elif mode == 'rnn_tanh':
self.rnn = rnn.RNN(num_hidden, num_layers, 'tanh', dropout=dropout,
input_size=num_embed)
elif mode == 'lstm':
self.rnn = rnn.LSTM(num_hidden, num_layers, dropout=dropout,
input_size=num_embed)
elif mode == 'gru':
self.rnn = rnn.GRU(num_hidden, num_layers, dropout=dropout,
input_size=num_embed)
else:
raise ValueError("Invalid mode %s. Options are rnn_relu, "
"rnn_tanh, lstm, and gru"%mode)
if tie_weights:
self.decoder = nn.Dense(vocab_size, in_units=num_hidden,
params=self.encoder.params)
else:
self.decoder = nn.Dense(vocab_size, in_units=num_hidden)
self.num_hidden = num_hidden
示例2: __init__
# 需要导入模块: from mxnet.gluon import rnn [as 别名]
# 或者: from mxnet.gluon.rnn import RNN [as 别名]
def __init__(self, mode, vocab_size, num_embed, num_hidden,
num_layers, dropout=0.5, tie_weights=False, **kwargs):
super(RNNModel, self).__init__(**kwargs)
with self.name_scope():
self.drop = nn.Dropout(dropout)
self.encoder = nn.Embedding(vocab_size, num_embed,
weight_initializer=mx.init.Uniform(0.1))
if mode == 'rnn_relu':
self.rnn = rnn.RNN(num_hidden, 'relu', num_layers, dropout=dropout,
input_size=num_embed)
elif mode == 'rnn_tanh':
self.rnn = rnn.RNN(num_hidden, num_layers, dropout=dropout,
input_size=num_embed)
elif mode == 'lstm':
self.rnn = rnn.LSTM(num_hidden, num_layers, dropout=dropout,
input_size=num_embed)
elif mode == 'gru':
self.rnn = rnn.GRU(num_hidden, num_layers, dropout=dropout,
input_size=num_embed)
else:
raise ValueError("Invalid mode %s. Options are rnn_relu, "
"rnn_tanh, lstm, and gru"%mode)
if tie_weights:
self.decoder = nn.Dense(vocab_size, in_units=num_hidden,
params=self.encoder.params)
else:
self.decoder = nn.Dense(vocab_size, in_units=num_hidden)
self.num_hidden = num_hidden
示例3: __init__
# 需要导入模块: from mxnet.gluon import rnn [as 别名]
# 或者: from mxnet.gluon.rnn import RNN [as 别名]
def __init__(
self,
mode: str,
num_hidden: int,
num_layers: int,
bidirectional: bool = False,
**kwargs,
):
super(RNN, self).__init__(**kwargs)
with self.name_scope():
if mode == "rnn_relu":
self.rnn = rnn.RNN(
num_hidden,
num_layers,
bidirectional=bidirectional,
activation="relu",
layout="NTC",
)
elif mode == "rnn_tanh":
self.rnn = rnn.RNN(
num_hidden,
num_layers,
bidirectional=bidirectional,
layout="NTC",
)
elif mode == "lstm":
self.rnn = rnn.LSTM(
num_hidden,
num_layers,
bidirectional=bidirectional,
layout="NTC",
)
elif mode == "gru":
self.rnn = rnn.GRU(
num_hidden,
num_layers,
bidirectional=bidirectional,
layout="NTC",
)
else:
raise ValueError(
"Invalid mode %s. Options are rnn_relu, rnn_tanh, lstm, and gru "
% mode
)