MCPcopy Create free account
hub / github.com/brightmart/text_classification / predict

Function predict

a09_DynamicMemoryNet/a8_dynamic_memory_network.py:356–388  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

354 saver.save(sess, save_path, global_step=i * 300)
355
356def predict():
357 num_classes = 15
358 learning_rate = 0.001
359 batch_size = 8
360 decay_steps = 1000
361 decay_rate = 0.9
362 sequence_length = 10
363 vocab_size = 10000
364 embed_size = 100
365 hidden_size = 100
366 is_training = False
367 story_length = 3
368 dropout_keep_prob = 1
369 model = DynamicMemoryNetwork(num_classes, learning_rate, batch_size, decay_steps, decay_rate, sequence_length,
370 story_length, vocab_size, embed_size, hidden_size, is_training,
371 multi_label_flag=False, block_size=20)
372 ckpt_dir = 'checkpoint_dmn/dummy_test/'
373 saver = tf.train.Saver()
374 with tf.Session() as sess:
375 sess.run(tf.global_variables_initializer())
376 saver.restore(sess, tf.train.latest_checkpoint(ckpt_dir))
377 for i in range(100):
378 story = np.random.randn(batch_size, story_length, sequence_length)
379 story[story > 0] = 1
380 story[story <= 0] = 0
381 query = np.random.randn(batch_size, sequence_length) # [batch_size, sequence_length]
382 query[query > 0] = 1
383 query[query <= 0] = 0
384 answer_single = np.sum(query, axis=1) + np.round(0.1 * np.sum(np.sum(story, axis=1),axis=1)) # [batch_size].e.g. np.array([1, 0, 1, 1, 1, 2, 1, 1])
385 predict = sess.run([model.predictions], feed_dict={model.query: query, model.story: story,
386 model.dropout_keep_prob: dropout_keep_prob})
387 print(i, "query:", query, "=====================>")
388 print(i, "label:", answer_single, "prediction:", predict)
389#1.train the model
390#train()
391#2.make a prediction based on the learned model.

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected