本文整理匯總了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
)