本文整理匯總了Python中tensor2tensor.layers.common_layers.sru方法的典型用法代碼示例。如果您正苦於以下問題:Python common_layers.sru方法的具體用法?Python common_layers.sru怎麽用?Python common_layers.sru使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tensor2tensor.layers.common_layers
的用法示例。
在下文中一共展示了common_layers.sru方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: step_preprocess
# 需要導入模塊: from tensor2tensor.layers import common_layers [as 別名]
# 或者: from tensor2tensor.layers.common_layers import sru [as 別名]
def step_preprocess(x, step, hparams):
"""Preprocess the input at the beginning of each step.
Args:
x: input tensor
step: step
hparams: model hyper-parameters
Returns:
preprocessed input.
"""
original_channel_size = common_layers.shape_list(x)[-1]
if hparams.add_position_timing_signal:
x = add_position_timing_signal(x, step, hparams)
if hparams.add_step_timing_signal:
x = add_step_timing_signal(x, step, hparams)
if ((hparams.add_position_timing_signal or hparams.add_position_timing_signal)
and hparams.add_or_concat_timing_signal == "concat"):
# linear projection to the original dimension of x
x = common_layers.dense(
x, original_channel_size, activation=None, use_bias=False)
if hparams.add_sru:
x = common_layers.sru(x)
return x
示例2: autoencoder_ordered_text
# 需要導入模塊: from tensor2tensor.layers import common_layers [as 別名]
# 或者: from tensor2tensor.layers.common_layers import sru [as 別名]
def autoencoder_ordered_text():
"""Ordered discrete autoencoder model for text."""
hparams = autoencoder_ordered_discrete()
hparams.learning_rate_constant = 2.0
hparams.learning_rate_warmup_steps = 2000
hparams.bottleneck_bits = 1024
hparams.batch_size = 2048
hparams.autoregressive_mode = "sru"
hparams.hidden_size = 256
hparams.max_hidden_size = 4096
hparams.bottleneck_warmup_steps = 10000
hparams.discretize_warmup_steps = 15000
return hparams
示例3: testSRU
# 需要導入模塊: from tensor2tensor.layers import common_layers [as 別名]
# 或者: from tensor2tensor.layers.common_layers import sru [as 別名]
def testSRU(self):
x = np.random.rand(5, 7, 3, 11)
with self.test_session() as session:
y = common_layers.sru(tf.constant(x, dtype=tf.float32))
session.run(tf.global_variables_initializer())
res = session.run(y)
self.assertEqual(res.shape, (5, 7, 3, 11))