Applies layer normalization. Args: inputs: A tensor with 2 or more dimensions, where the first dimension has `batch_size`. epsilon: A floating number. A very small number for preventing ZeroDivision Error. scope: Optional scope for `variable_scope`. reuse: Boolea
(inputs,
epsilon=1e-8,
scope="ln",
reuse=None)
| 44 | |
| 45 | |
| 46 | def normalize(inputs, |
| 47 | epsilon=1e-8, |
| 48 | scope="ln", |
| 49 | reuse=None): |
| 50 | '''Applies layer normalization. |
| 51 | |
| 52 | Args: |
| 53 | inputs: A tensor with 2 or more dimensions, where the first dimension has |
| 54 | `batch_size`. |
| 55 | epsilon: A floating number. A very small number for preventing ZeroDivision Error. |
| 56 | scope: Optional scope for `variable_scope`. |
| 57 | reuse: Boolean, whether to reuse the weights of a previous layer |
| 58 | by the same name. |
| 59 | |
| 60 | Returns: |
| 61 | A tensor with the same shape and data dtype as `inputs`. |
| 62 | ''' |
| 63 | with tf.variable_scope(scope, reuse=reuse): |
| 64 | inputs_shape = inputs.get_shape() |
| 65 | params_shape = inputs_shape[-1:] |
| 66 | |
| 67 | mean, variance = tf.nn.moments(inputs, [-1], keep_dims=True) |
| 68 | beta = tf.Variable(tf.zeros(params_shape)) |
| 69 | gamma = tf.Variable(tf.ones(params_shape)) |
| 70 | normalized = (inputs - mean) / ((variance + epsilon) ** (.5)) |
| 71 | outputs = gamma * normalized + beta |
| 72 | |
| 73 | return outputs |
| 74 | |
| 75 | def calculate_hit(sorted_list,topk,true_items,rewards,r_click,total_reward,hit_click,ndcg_click,hit_purchase,ndcg_purchase): |
| 76 | for i in range(len(topk)): |
nothing calls this directly
no outgoing calls
no test coverage detected