def train_step(self, sess, text_batch, sent_batch, sentense_batch, epochs_completed, verbose=True): """ A single train step """ feed_dict = { self.input: text_batch, self.sentiment: sent_batch, self.sentences: sentense_batch } ops = [self.tr_op_set, self.global_step, self.loss, self.out] if hasattr(self, 'train_summary_op'): ops.append(self.train_summary_op) _, step, loss, sentiment, summaries = sess.run(ops, feed_dict) self.train_summary_writer.add_summary(summaries, step) else: _, step, loss, sentiment = sess.run(ops, feed_dict) pco = pearsonr(sentiment, sent_batch) mse = mean_squared_error(sent_batch, sentiment) if verbose: time_str = datetime.datetime.now().isoformat() print("Epoch: {}\tTRAIN {}: Current Step: {}\tLoss: {:g}\t" "PCO: {}\tMSE: {}".format(epochs_completed, time_str, step, loss, pco, mse)) return pco, mse, loss, step
def evaluate_step(self, sess, text_batch, sent_batch, sentense_batch, verbose=True): """ A single evaluation step """ feed_dict = { self.input: text_batch, self.sentiment: sent_batch, self.sentences: sentense_batch } ops = [ self.global_step, self.loss, self.out, self.pco, self.pco_update, self.mse, self.mse_update ] if hasattr(self, 'dev_summary_op'): ops.append(self.dev_summary_op) step, loss, sentiment, pco, _, mse, _, summaries = sess.run( ops, feed_dict) self.dev_summary_writer.add_summary(summaries, step) else: step, loss, sentiment, pco, _, mse, _ = sess.run(ops, feed_dict) time_str = datetime.datetime.now().isoformat() pco = pearsonr(sentiment, sent_batch) mse = mean_squared_error(sent_batch, sentiment) if verbose: print("EVAL: {}\tstep: {}\tloss: {:g}\t pco:{}\tmse: {}".format( time_str, step, loss, pco, mse)) return loss, pco, mse, sentiment
def evaluate_step(self, sess, text_batch, ne_batch, lengths_batch, verbose=True): """ A single evaluation step """ feed_dict = { self.input: text_batch, self.output: ne_batch, self.input_lengths: lengths_batch } ops = [self.global_step, self.loss, self.prediction, self.accuracy] if hasattr(self, 'dev_summary_op'): ops.append(self.dev_summary_op) step, loss, pred, acc, summaries = sess.run(ops, feed_dict) self.dev_summary_writer.add_summary(summaries, step) else: step, loss, pred, acc = sess.run(ops, feed_dict) time_str = datetime.datetime.now().isoformat() if verbose: print("EVAL: {}\tStep: {}\tloss: {:g}\tAcc: {}".format( time_str, step, loss, acc)) return loss, pred, acc
def train_step(self, sess, text_batch, ne_batch, lengths_batch, epochs_completed, verbose=True): """ A single train step """ feed_dict = { self.input: text_batch, self.output: ne_batch, self.input_lengths: lengths_batch } ops = [ self.tr_op_set, self.global_step, self.loss, self.prediction, self.accuracy ] if hasattr(self, 'train_summary_op'): ops.append(self.train_summary_op) _, step, loss, pred, acc, summaries = sess.run(ops, feed_dict) self.train_summary_writer.add_summary(summaries, step) else: _, step, loss, pred, acc = sess.run(ops, feed_dict) if verbose: time_str = datetime.datetime.now().isoformat() print(("Epoch: {}\tTRAIN: {}\tCurrent Step: {}\tLoss {}\tAcc: {}" "").format(epochs_completed, time_str, step, loss, acc)) return pred, loss, step, acc
def train_step(self, sess, text_batch, sentiment_batch, epochs_completed, verbose=True): """ A single train step """ feed_dict = { self.sentence: text_batch, self.sentiment: sentiment_batch, } ops = [ self.tr_op_set, self.global_step, self.loss, self.out, self.accuracy ] if hasattr(self, 'train_summary_op'): ops.append(self.train_summary_op) _, step, loss, out, accuracy, summaries = sess.run(ops, feed_dict) self.train_summary_writer.add_summary(summaries, step) else: _, step, loss, out, accuracy = sess.run(ops, feed_dict) if verbose: time_str = datetime.datetime.now().isoformat() print(("Epoch: {}\tTRAIN: {}\tCurrent Step: {}\tLoss {}\t" "Accuracy: {}").format(epochs_completed, time_str, step, loss, accuracy)) return accuracy, loss, step
def evaluate_step(self, sess, text_batch, sentiment_batch, verbose=True): """ A single evaluation step """ feed_dict = { self.sentence: text_batch, self.sentiment: sentiment_batch } ops = [ self.global_step, self.loss, self.out, self.accuracy, self.correct_preds ] if hasattr(self, 'dev_summary_op'): ops.append(self.dev_summary_op) step, loss, out, accuracy, correct_preds, summaries = sess.run( ops, feed_dict) self.dev_summary_writer.add_summary(summaries, step) else: step, loss, out, accuracy, correct_preds = sess.run(ops, feed_dict) time_str = datetime.datetime.now().isoformat() if verbose: print("EVAL: {}\tStep: {}\tloss: {:g}\t accuracy:{}".format( time_str, step, loss, accuracy)) return loss, accuracy, correct_preds, out
def train_step(self, sess, s1_batch, s2_batch, sim_batch, epochs_completed, verbose=True): """ A single train step """ # Prepare data to feed to the computation graph feed_dict = { self.input_s1: s1_batch, self.input_s2: s2_batch, self.input_sim: sim_batch, } # create a list of operations that you want to run and observe ops = [self.tr_op_set, self.global_step, self.loss, self.distance] # Add summaries if they exist if hasattr(self, 'train_summary_op'): ops.append(self.train_summary_op) _, step, loss, sim, summaries = sess.run(ops, feed_dict) self.train_summary_writer.add_summary(summaries, step) else: _, step, loss, sim = sess.run(ops, feed_dict) # Calculate the pearson correlation and mean squared error pco = pearsonr(sim, sim_batch) mse = mean_squared_error(sim_batch, sim) if verbose: time_str = datetime.datetime.now().isoformat() print("Epoch: {}\tTRAIN {}: Current Step{}\tLoss{:g}\t" "PCO:{}\tMSE={}".format(epochs_completed, time_str, step, loss, pco, mse)) return pco, mse, loss, step
def evaluate_step(self, sess, sents_batch, sim_batch, lens, verbose=True): """ A single evaluation step """ # Prepare the data to be fed to the computation graph feed_dict = { self.input: sents_batch, self.input_sim: sim_batch, self.input_length: lens } # create a list of operations that you want to run and observe ops = [ self.global_step, self.loss, self.output, self.pco, self.pco_update, self.mse, self.mse_update ] # Add summaries if they exist if hasattr(self, 'dev_summary_op'): ops.append(self.dev_summary_op) step, loss, sim, pco, _, mse, _, summaries = sess.run( ops, feed_dict) self.dev_summary_writer.add_summary(summaries, step) else: step, loss, sim, pco, _, mse, _ = sess.run(ops, feed_dict) time_str = datetime.datetime.now().isoformat() # Calculate the pearson correlation and mean squared error pco = pearsonr(sim, sim_batch) mse = mean_squared_error(sim_batch, sim) if verbose: print("EVAL: {}\tStep: {}\tloss: {:g}\t pco:{}\tmse:{}".format( time_str, step, loss, pco, mse)) return loss, pco, mse, sim