Exemplo n.º 1
0
  def test_ngram_op_2_order(self):
    ''' test ngram 2-order op'''
    ground_truth_2 = [0, 0, 0, 0, 0, 0, 0]

    word_ngram = 2
    t_input = tf.placeholder(shape=(4,), dtype=tf.int32)
    t_ngram = py_x_ops.ngram(
        t_input, word_ngrams=word_ngram, vocab_size=5000, bucket_size=100000)
    logging.info("t_ngram: {}".format(t_ngram))
    with tf.Session() as sess:
      sess.run(tf.global_variables_initializer())
      ngram_result = sess.run(t_ngram, feed_dict={t_input: self.testcase[0]})
      self.assertAllEqual(ngram_result, ground_truth_2)
Exemplo n.º 2
0
  def test_batch_ngram_op_2_order(self):
    ''' tset batch 2-order ngram '''
    ground_truth_2 = [[0, 0, 0, 0, 0, 0, 0], [223, 0, 0, 0, 0, 0, 0],
                      [0, 8, 5008, 0, 0, 0, 0], [4, 8, 102492, 0, 0, 0, 0],
                      [0, 0, 10, 5000, 5010, 0, 0],
                      [2, 5, 3, 103747, 51858, 0, 0],
                      [7, 2, 1, 24, 50599, 103743, 54395]]

    word_ngram = 2
    t_input = tf.placeholder(shape=(7, 4), dtype=tf.int32)
    t_ngram = py_x_ops.ngram(
        t_input, word_ngrams=word_ngram, vocab_size=5000, bucket_size=100000)
    logging.info("batch t_ngram: {}".format(t_ngram))
    with tf.Session() as sess:
      sess.run(tf.global_variables_initializer())
      ngram_result = sess.run(t_ngram, feed_dict={t_input: self.testcase})
      ngram_result = [list(res) for res in ngram_result]
      self.assertAllEqual(ngram_result, ground_truth_2)