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

Function predict

a08_EntityNetwork/a3_entity_network.py:325–358  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

323 saver.save(sess, save_path, global_step=i * 300)
324
325def predict():
326 num_classes = 15
327 learning_rate = 0.001
328 batch_size = 8
329 decay_steps = 1000
330 decay_rate = 0.9
331 sequence_length = 10
332 vocab_size = 10000
333 embed_size = 100
334 hidden_size = 100
335 is_training = False
336 story_length = 3
337 dropout_keep_prob = 1
338 model = EntityNetwork(num_classes, learning_rate, batch_size, decay_steps, decay_rate, sequence_length,
339 story_length, vocab_size, embed_size, hidden_size, is_training,
340 multi_label_flag=False, block_size=20)
341 ckpt_dir = 'checkpoint_entity_network/dummy_test/'
342 saver = tf.train.Saver()
343 with tf.Session() as sess:
344 sess.run(tf.global_variables_initializer())
345 saver.restore(sess, tf.train.latest_checkpoint(ckpt_dir))
346 for i in range(1500):
347 story = np.random.randn(batch_size, story_length, sequence_length)
348 story[story > 0] = 1
349 story[story <= 0] = 0
350 query = np.random.randn(batch_size, sequence_length) # [batch_size, sequence_length]
351 query[query > 0] = 1
352 query[query <= 0] = 0
353 answer_single = np.sum(query, axis=1) + np.round(0.1 * np.sum(np.sum(story, axis=1),
354 axis=1)) # [batch_size].e.g. np.array([1, 0, 1, 1, 1, 2, 1, 1])
355 predict = sess.run([model.predictions], feed_dict={model.query: query, model.story: story,
356 model.dropout_keep_prob: dropout_keep_prob})
357 print(i, "query:", query, "=====================>")
358 print(i, "label:", answer_single, "prediction:", predict)
359
360#test()
361#predict()

Callers

nothing calls this directly

Calls 1

EntityNetworkClass · 0.85

Tested by

no test coverage detected