本文整理汇总了Python中tensor2tensor.layers.common_layers.dropout_no_scaling方法的典型用法代码示例。如果您正苦于以下问题:Python common_layers.dropout_no_scaling方法的具体用法?Python common_layers.dropout_no_scaling怎么用?Python common_layers.dropout_no_scaling使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensor2tensor.layers.common_layers
的用法示例。
在下文中一共展示了common_layers.dropout_no_scaling方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bottom_simple
# 需要导入模块: from tensor2tensor.layers import common_layers [as 别名]
# 或者: from tensor2tensor.layers.common_layers import dropout_no_scaling [as 别名]
def bottom_simple(self, x, name, reuse):
with tf.variable_scope(name, reuse=reuse):
# Ensure the inputs are 3-D
if len(x.get_shape()) == 4:
x = tf.squeeze(x, axis=3)
while len(x.get_shape()) < 3:
x = tf.expand_dims(x, axis=-1)
var = self._get_weights()
x = common_layers.dropout_no_scaling(
x, 1.0 - self._model_hparams.symbol_dropout)
ret = common_layers.gather(var, x)
if self._model_hparams.multiply_embedding_mode == "sqrt_depth":
ret *= self._body_input_depth**0.5
ret *= tf.expand_dims(tf.to_float(tf.not_equal(x, 0)), -1)
return ret
示例2: _symbol_bottom_simple
# 需要导入模块: from tensor2tensor.layers import common_layers [as 别名]
# 或者: from tensor2tensor.layers.common_layers import dropout_no_scaling [as 别名]
def _symbol_bottom_simple(x, model_hparams, vocab_size, name, reuse):
"""Bottom transformation for symbols."""
with tf.variable_scope(name, reuse=reuse):
# Ensure the inputs are 3-D
if len(x.get_shape()) == 4:
x = tf.squeeze(x, axis=3)
while len(x.get_shape()) < 3:
x = tf.expand_dims(x, axis=-1)
var = get_weights(model_hparams, vocab_size)
x = common_layers.dropout_no_scaling(
x, 1.0 - model_hparams.symbol_dropout)
ret = common_layers.gather(var, x)
if model_hparams.multiply_embedding_mode == "sqrt_depth":
ret *= model_hparams.hidden_size**0.5
ret *= tf.expand_dims(
common_layers.cast_like(tf.not_equal(x, 0), ret), -1)
return ret
示例3: bottom_simple
# 需要导入模块: from tensor2tensor.layers import common_layers [as 别名]
# 或者: from tensor2tensor.layers.common_layers import dropout_no_scaling [as 别名]
def bottom_simple(x, model_hparams, vocab_size, name, reuse):
"""Internal bottom transformation."""
with tf.variable_scope(name, reuse=reuse):
var = _get_weights(model_hparams, vocab_size)
x = common_layers.dropout_no_scaling(
x, 1.0 - model_hparams.symbol_dropout)
# Add together the embeddings for each tuple position.
ret = tf.add_n([
tf.gather(var, x[:, :, :, i] + sum(vocab_size[:i])) *
tf.expand_dims(tf.to_float(tf.not_equal(x[:, :, :, i], 0)), -1)
for i in range(len(vocab_size))
])
if model_hparams.multiply_embedding_mode == 'sqrt_depth':
ret *= model_hparams.hidden_size**0.5
return ret