for epoch in range(epochs): t0 = time.time() loss_train = 0 loss_test = 0 acc_train = 0 acc_test = 0 #print("epoch: {}\t".format(epoch), end="") # training n_batch = len(X_train) // batch_size #for _ in range(n_batch): for _ in tqdm(range(n_batch), total=n_batch): X_batch, y_batch = utils.get_batch_data(X_train_doc, y_train, batch_size) X_batch_emb = embedding_bert.get_batch_emb(X_batch, doc_len, sen_len, tokenizer, estimator) X_batch_emb = X_batch_emb[:, :, 0, :] X_batch_seq, _ = embedding_bert.get_batch_seq(X_batch, doc_len, sen_len, tokenizer, tol=2) _, loss, acc, atten_w = sess.run( [optimizer, cost, accuracy, soft_atten_weights], feed_dict={ X_emb: X_batch_emb, y: y_batch, seq_length: X_batch_seq,
x = utils.token_sens(xx_clean, sentence_size = 30, word_to_idx = word_to_idx) x.shape # In[ ]: # In[16]: a, b = utils.get_batch_data(X_train, y_train, batch_size = 5) a_clean = utils.replace_contr(a, contractions) a_clean.shape, b.shape # In[17]: a, a_clean, b # In[ ]:
# In[ ]: # ## Predict section # In[30]: with tf.Session() as sess: saver.restore(sess, savepath) X_batch, y_batch = utils.get_batch_data(X_test, y_test, 10) X_batch_emb = embedding_bert.get_batch_emb(X_batch, doc_len, sen_len, tokenizer, estimator) X_batch_emb = np.squeeze(X_batch_emb, axis = 1) _, X_batch_seq = embedding_bert.get_batch_seq(X_batch, doc_len, sen_len, tokenizer, tol = 2) atten_w, y_proba = sess.run([soft_atten_weights, Y_proba], feed_dict={X_emb: X_batch_emb, seq_length: X_batch_seq, is_training:False}) y_pred = np.argmax(y_proba, axis = 1) # In[31]: X_batch, y_batch, y_pred