Implements layer norm from [Ba et al. 2016] Layer Normalization. See eqn. 4 in (https://arxiv.org/pdf/1607.06450.pdf). Args: layer_inputs (tensor): The inputs to the layer. shape [batch_size, hidden_size] hidden_size (int): Dimensionality of the hidden layer. Returns:
(layer_inputs, hidden_size)
| 27 | |
| 28 | |
| 29 | def layer_norm(layer_inputs, hidden_size): |
| 30 | """Implements layer norm from [Ba et al. 2016] Layer Normalization. |
| 31 | |
| 32 | See eqn. 4 in (https://arxiv.org/pdf/1607.06450.pdf). |
| 33 | |
| 34 | Args: |
| 35 | layer_inputs (tensor): The inputs to the layer. |
| 36 | shape <float32>[batch_size, hidden_size] |
| 37 | hidden_size (int): Dimensionality of the hidden layer. |
| 38 | |
| 39 | Returns: |
| 40 | normalized (tensor): layer_inputs, normalized over all the hidden units in |
| 41 | the layer. |
| 42 | shape <float32>[batch_size, hidden_size] |
| 43 | """ |
| 44 | |
| 45 | mean, var = tf.nn.moments(layer_inputs, [1], keep_dims=True) |
| 46 | with tf.variable_scope("layernorm", reuse=tf.AUTO_REUSE): |
| 47 | gain = tf.get_variable( |
| 48 | "gain", shape=[hidden_size], initializer=tf.constant_initializer(1)) |
| 49 | bias = tf.get_variable( |
| 50 | "bias", shape=[hidden_size], initializer=tf.constant_initializer(0)) |
| 51 | |
| 52 | normalized = gain * (layer_inputs - mean) / tf.sqrt(var + _EPSILON) + bias |
| 53 | return normalized |
| 54 | |
| 55 | |
| 56 | def hamming_loss(preds, targets, sign=False): |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…