Esempio n. 1
0
 def testLSTMSeq2Seq(self):
     vocab_size = 9
     x = np.random.randint(1, high=vocab_size, size=(3, 5, 1, 1))
     y = np.random.randint(1, high=vocab_size, size=(3, 6, 1, 1))
     hparams = lstm.lstm_seq2seq()
     p_hparams = problem_hparams.test_problem_hparams(
         vocab_size, vocab_size, hparams)
     with self.test_session() as session:
         features = {
             "inputs": tf.constant(x, dtype=tf.int32),
             "targets": tf.constant(y, dtype=tf.int32),
         }
         model = lstm.LSTMSeq2seq(hparams, tf.estimator.ModeKeys.TRAIN,
                                  p_hparams)
         logits, _ = model(features)
         session.run(tf.global_variables_initializer())
         res = session.run(logits)
     self.assertEqual(res.shape, (3, 6, 1, 1, vocab_size))
Esempio n. 2
0
 def testLSTMSeq2Seq(self):
   vocab_size = 9
   x = np.random.random_integers(1, high=vocab_size - 1, size=(3, 5, 1, 1))
   y = np.random.random_integers(1, high=vocab_size - 1, size=(3, 6, 1, 1))
   hparams = common_hparams.basic_params1()
   p_hparams = problem_hparams.test_problem_hparams(hparams, vocab_size,
                                                    vocab_size)
   with self.test_session() as session:
     features = {
         "inputs": tf.constant(x, dtype=tf.int32),
         "targets": tf.constant(y, dtype=tf.int32),
     }
     model = lstm.LSTMSeq2seq(hparams, tf.contrib.learn.ModeKeys.TRAIN,
                              p_hparams)
     sharded_logits, _ = model.model_fn(features)
     logits = tf.concat(sharded_logits, 0)
     session.run(tf.global_variables_initializer())
     res = session.run(logits)
   self.assertEqual(res.shape, (3, 6, 1, 1, vocab_size))