def prenet(inputs, num_units=None, dropout_rate=0, is_training=True, scope="prenet", reuse=None):
'''Prenet for Encoder and Decoder.
Args:
inputs: A 3D tensor of shape [N, T, hp.embed_size].
num_units" A list of two integers.
is_training: A boolean.
scope: Optional scope for `variable_scope`.
reuse: Boolean, whether to reuse the weights of a previous layer
by the same name.
Returns:
A 3D tensor of shape [N, T, num_units/2].
'''
if num_units is None:
num_units = [inputs.get_shape()[-1], inputs.get_shape()[-1]]
with tf.variable_scope(scope, reuse=reuse):
outputs = tf.layers.dense(inputs, units=num_units[0], activation=tf.nn.relu, name="dense1")
outputs = tf.layers.dropout(outputs, rate=dropout_rate, training=is_training, name="dropout1")
outputs = tf.layers.dense(outputs, units=num_units[1], activation=tf.nn.relu, name="dense2")
outputs = tf.layers.dropout(outputs, rate=dropout_rate, training=is_training, name="dropout2")
return outputs # (N, T, num_units[1])
评论列表
文章目录