def testUniEncoderForwardPass(self): with self.session(use_gpu=False): tf.set_random_seed(8372749040) p = self._UniEncoderParams() mt_enc = encoder.MTEncoderUniRNN(p) batch = py_utils.NestedMap() batch.ids = tf.transpose(tf.reshape(tf.range(0, 8, 1), [4, 2])) batch.paddings = tf.zeros([2, 4]) enc_out = mt_enc.FPropDefaultTheta(batch).encoded tf.global_variables_initializer().run() actual_enc_out = enc_out.eval() expected_enc_out = [[[-1.74790625e-06, -5.04228524e-07], [2.04836829e-06, 1.48639378e-06]], [[-1.10486064e-06, -5.77133278e-07], [4.66779238e-06, 3.72350723e-06]], [[-5.65139544e-07, -1.84634030e-06], [3.99908731e-06, 1.90148887e-06]], [[7.14102157e-07, -2.31352783e-06], [7.05981620e-06, 2.68004328e-06]]] self.assertAllClose(expected_enc_out, actual_enc_out)
def testUniEncoderForwardPass(self): with self.session(use_gpu=False): tf.random.set_seed(8372749040) p = self._UniEncoderParams() mt_enc = encoder.MTEncoderUniRNN(p) batch = py_utils.NestedMap() batch.ids = tf.transpose(tf.reshape(tf.range(0, 8, 1), [4, 2])) batch.paddings = tf.zeros([2, 4]) enc_out = mt_enc.FPropDefaultTheta(batch).encoded self.evaluate(tf.global_variables_initializer()) actual_enc_out = enc_out.eval() expected_enc_out = [[[4.3564430e-07, -2.3954138e-07], [-9.8339186e-08, 8.5873717e-07]], [[1.4911951e-07, -3.4084817e-07], [-7.1341539e-08, 2.1979017e-06]], [[-6.4054962e-07, -1.1942817e-06], [-6.6461860e-07, 1.0963676e-06]], [[-1.3252994e-06, -1.5549912e-06], [-1.4652252e-06, 1.4637867e-06]]] self.assertAllClose(expected_enc_out, actual_enc_out)
def testUniEncoderForwardPass(self): with self.session(use_gpu=False): tf.random.set_seed(8372749040) p = self._UniEncoderParams() mt_enc = encoder.MTEncoderUniRNN(p) batch = py_utils.NestedMap() batch.ids = tf.transpose(tf.reshape(tf.range(0, 8, 1), [4, 2])) batch.paddings = tf.zeros([2, 4]) enc_out = mt_enc.FPropDefaultTheta(batch).encoded self.evaluate(tf.global_variables_initializer()) actual_enc_out = enc_out.eval() tf.logging.info('testUniEncoderForwardPass actual_enc_out %r' % actual_enc_out) expected_enc_out = [[[-4.3304257e-07, 5.4100457e-07], [-4.0170832e-07, -2.6441572e-07]], [[-1.7024040e-07, -1.8555815e-07], [-6.4563977e-07, -3.7835261e-07]], [[-2.4001852e-07, 5.1114228e-07], [-3.4349023e-07, -1.0049351e-06]], [[1.8068013e-07, -6.8982729e-08], [3.3005003e-07, -8.8834116e-07]]] self.assertAllClose(expected_enc_out, actual_enc_out)