if i%100 == 0: train_stories_shuf = [] train_orders_shuf = [] index_shuf = list(range(len(train_stories))) shuffle(index_shuf) for j in index_shuf: train_stories_shuf.append(train_stories[j]) train_orders_shuf.append(train_orders[j]) inst_story = train_stories_shuf[i * BATCH_SIZE: (i + 1) * BATCH_SIZE] inst_order = train_orders_shuf[i * BATCH_SIZE: (i + 1) * BATCH_SIZE] feed_dict = {story: inst_story, order: inst_order} _, current_loss = sess.run([opt_op, loss], feed_dict=feed_dict) total_loss += current_loss print(' Train loss:', total_loss / n) train_feed_dict = {story: train_stories, order: train_orders} train_predicted = sess.run(predict, feed_dict=train_feed_dict) train_accuracy = nn.calculate_accuracy(train_orders, train_predicted) print(' Train accuracy:', train_accuracy) dev_feed_dict = {story: dev_stories, order: dev_orders} dev_predicted = sess.run(predict, feed_dict=dev_feed_dict) dev_accuracy = nn.calculate_accuracy(dev_orders, dev_predicted) print(' Dev accuracy:', dev_accuracy) print(time.time()-t) nn.save_model(sess)
order: cur_batch.as_np_orders(), story_sent_lens: cur_batch.as_np_sent_lens() } _, current_loss = sess.run([opt_op, loss], feed_dict=feed_dict) total_loss += current_loss print(' Train loss:', total_loss / n) t_ords = train_stories.as_np_orders() train_feed_dict = { story: train_stories.as_np_sents(), order: t_ords, story_sent_lens: train_stories.as_np_sent_lens() } train_predicted = sess.run(predict, feed_dict=train_feed_dict) train_accuracy = nn.calculate_accuracy(t_ords, train_predicted) print(' Train accuracy:', train_accuracy) d_ords = dev_stories.as_np_orders() dev_feed_dict = { story: dev_stories.as_np_sents(), order: d_ords, story_sent_lens: dev_stories.as_np_sent_lens() } dev_predicted = sess.run(predict, feed_dict=dev_feed_dict) dev_accuracy = nn.calculate_accuracy(d_ords, dev_predicted) print(' Dev accuracy:', dev_accuracy) model_name = 'e_size' + str(embedding_size) + 'h_size' + str( hidden_size) + 'lr' + str(learning_rate) results_summary = 'embedding size: ' + str(embedding_size) + \