MCPcopy Create free account
hub / github.com/chinawithfrank/ChatBotCourse / test

Method test

chatbotv3/encoder_decoder_seq2seq.py:274–302  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

272 saver.save(sess, self.model_dir)
273
274 def test(self):
275 x = tf.placeholder("float", [None, self.max_seq_len * 2, self.word_vec_dim])
276 y = tf.placeholder("float", [None, self.max_seq_len, self.one_hot_word_vectors_dim])
277
278 weights = {
279 'enc2dec': tf.Variable(tf.random_normal([self.word_vec_dim, self.one_hot_word_vectors_dim])),
280 'hid2tar': tf.Variable(tf.random_normal([self.n_hidden, self.one_hot_word_vectors_dim])),
281 }
282 biases = {
283 'enc2dec': tf.Variable(tf.random_normal([self.max_seq_len, self.one_hot_word_vectors_dim])),
284 'hid2tar': tf.Variable(tf.random_normal([self.max_seq_len, self.one_hot_word_vectors_dim])),
285 }
286
287 optimizer, cost, decoder_layer2_outputs = self.model(x, y, weights, biases, training=False)
288
289 init = tf.global_variables_initializer()
290 sess = tf.Session()
291 sess.run(init)
292 saver = tf.train.Saver()
293 saver.restore(sess, self.model_dir)
294
295 XY, Y = self.next_batch()
296 n_steps = len(XY)
297 for step in range(n_steps):
298 train_XY = XY[step:]
299 train_Y = Y[step:]
300 loss = sess.run(cost, feed_dict={x: train_XY, y: train_Y})
301 print sess.run(decoder_layer2_outputs, feed_dict={x: train_XY, y: train_Y})
302 print 'loss=%f' % loss
303
304 def predict(self):
305 x = tf.placeholder("float", [None, self.max_seq_len * 2, self.word_vec_dim])

Callers 1

mainFunction · 0.95

Calls 2

modelMethod · 0.95
next_batchMethod · 0.95

Tested by

no test coverage detected