def qrnn_forward(self, X, size, n_class, batch_size, conv_size): in_size = int(X.get_shape()[2]) qrnn = QRNN(in_size=in_size, size=size, conv_size=conv_size) hidden = qrnn.forward(X) with tf.name_scope("QRNN-Classifier"): W = tf.Variable(tf.random_normal([size, n_class]), name="W") b = tf.Variable(tf.random_normal([n_class]), name="b") output = tf.add(tf.matmul(hidden, W), b) return output
def test_qrnn_convolution(self): batch_size = 100 sentence_length = 5 word_size = 10 size = 5 data = self.create_test_data(batch_size, sentence_length, word_size) with tf.Graph().as_default() as q_conv: qrnn = QRNN(in_size=word_size, size=size, conv_size=3) X = tf.placeholder(tf.float32, [batch_size, sentence_length, word_size]) forward_graph = qrnn.forward(X) with tf.Session() as sess: sess.run(tf.global_variables_initializer()) hidden = sess.run(forward_graph, feed_dict={X: data}) self.assertEqual((batch_size, size), hidden.shape)