當前位置: 首頁>>代碼示例>>Python>>正文


Python common_layers.sru方法代碼示例

本文整理匯總了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 
開發者ID:akzaidi,項目名稱:fine-lm,代碼行數:32,代碼來源:universal_transformer_util.py

示例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 
開發者ID:akzaidi,項目名稱:fine-lm,代碼行數:15,代碼來源:autoencoders.py

示例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)) 
開發者ID:akzaidi,項目名稱:fine-lm,代碼行數:9,代碼來源:common_layers_test.py


注:本文中的tensor2tensor.layers.common_layers.sru方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。