Пример #1
0
 def test_normalization(self):
   """Test the normalization constant."""
   activations = tf.random.normal(shape=[100, 50000])
   with self.cached_session():
     normalization_constants = loss.compute_normalization(
         activations, 1.01, num_iters=5)
     self.assertEqual(normalization_constants.shape, [100, 1])
     probabilities = tf.reduce_sum(
         loss.exp_t(activations - normalization_constants, 1.01), -1)
     self.assertAllClose(probabilities.eval(), [1.0] * 100, atol=1e-5)
     normalization_constants = loss.compute_normalization(
         activations, 2.0, num_iters=5)
     probabilities = tf.reduce_sum(
         loss.exp_t(activations - normalization_constants, 2.0), -1)
     self.assertAllClose(probabilities.eval(), [1.0] * 100, atol=1e-5)
Пример #2
0
 def test_normalization(self):
     """Test the normalization constant."""
     activations = tf.random.normal(shape=[100, 50000])
     for t in [0.99, 1.01]:
         normalization_constants = loss.compute_normalization(activations,
                                                              t,
                                                              num_iters=20)
         self.assertEqual(normalization_constants.shape, [100, 1])
         probabilities = tf.reduce_sum(
             loss.exp_t(activations - normalization_constants, t), -1)
         self.assertAllClose(probabilities.numpy(), [1.0] * 100, atol=1e-5)
     for t in [0.1, 2.0]:
         normalization_constants = loss.compute_normalization(activations,
                                                              t,
                                                              num_iters=20)
         probabilities = tf.reduce_sum(
             loss.exp_t(activations - normalization_constants, t), -1)
         self.assertAllClose(probabilities.numpy(), [1.0] * 100, atol=1e-5)