예제 #1
0
def run_epoch(sess, m_train, m_valid, training_data, validation_data):
    iters = 0
    # TODO: shuffle and fetch data
    sf_train = SF(training_data, CONFIG.BATCH_SIZE, is_training=True)
    sf_valid = SF(validation_data, CONFIG.BATCH_SIZE, is_training=False)

    for tup in sf_train.get_batch():
        print('Training Batch: ', iters)
        _, doc, summary, docLens, sumLens = tup
        doc_batch = _get_doc_batch(doc)
        summary_batch = _get_summary_batch(summary)
        label_batch = _get_label_batch(summary)
        loss = m_train.run_train_step(sess, doc_batch, summary_batch,
                                      label_batch, np.array(docLens),
                                      np.array(sumLens))
        print('training loss: ', loss)
        it = 0
        for tup_valid in sf_valid.get_batch():
            if (it > 0):
                break
            it += 1
            _, doc_valid, summary_valid, docLens_valid, sumLens_valid = tup
            doc_batch_v = _get_doc_batch(doc_valid)
            summary_batch_v = _get_summary_batch(summary_valid)
            label_batch_v = _get_label_batch(summary_valid)
            m_valid.run_valid_step(sess, doc_batch_v, summary_batch_v,
                                   label_batch_v, np.array(docLens_valid),
                                   np.array(sumLens_valid))
        iters += 1
예제 #2
0
파일: RNNLAST.py 프로젝트: HDG94/dl
    p_valid = tf.nn.softmax(logits = u_valid)
	#####################################

# start session and init
sess = tf.Session()
sess.run(init_op)
sess.run(embedding_init, feed_dict = {embedding_placeholder: np.matrix(Mword)})

ac_train_list = []
ac_validation_list = []
   
outfile = open ('results_rnn_last.txt', 'w')
for i in range(EPOCH):
    print ('------------------running ' + str(i)+ 'th epoch --------------------')
    print ('shuffling batch')
    sf = SF(training_data, BATCH_SIZE)
    sf.shuffle()
    
    for tup in sf.get_batch(): # getting a batch of *documents*
        j, batch_xs, batch_ys, batch_lens = tup  # note: j means the j'th batch
        #print ('training the ', str(j), 'th batch')
        num_sentences = len(batch_xs[0])
        # np_state for initialization at start of doc: [BATCH_SIZE, DIM_WordEmbedding]
        np_state = sess.run(cell.zero_state(BATCH_SIZE, dtype=tf.float32))
        sess.run(init_assign, feed_dict={init_state_placeholder:np_state})
        
        for ns in range(num_sentences):
            # prepare the batch of sentences, label, sentence_lens
            sentences_batch = getSentenceBatch(batch_xs, ns)
            labels_batch = getSentenceLabels(batch_ys, ns)
            lens_batch = getSentenceLength(batch_lens, ns)