# Optionally, do length normalization. batch_token_counts = [numpy.count_nonzero(s) for s in y_mask.T] if normalization_alpha: adjusted_lens = [n**normalization_alpha for n in batch_token_counts] batch_ce_vals /= numpy.array(adjusted_lens) ce_vals += list(batch_ce_vals) token_counts += batch_token_counts logging.info("Seen {}".format(len(ce_vals))) assert len(ce_vals) == len(token_counts) return ce_vals, token_counts if __name__ == "__main__": # Parse command-line arguments. config = read_config_from_cmdline() logging.info(config) # TensorFlow 2.0 feature needed by ExponentialSmoothing. tf.enable_resource_variables() # Create the TensorFlow session. tf_config = tf.ConfigProto() tf_config.allow_soft_placement = True # Train. with tf.Session(config=tf_config) as sess: train(config, sess)
model.inputs.y_mask: y_mask, model.inputs.training: False} batch_ce_vals = session.run(model.loss_per_sentence, feed_dict=feeds) # Optionally, do length normalization. batch_token_counts = [numpy.count_nonzero(s) for s in y_mask.T] if normalization_alpha: adjusted_lens = [n**normalization_alpha for n in batch_token_counts] batch_ce_vals /= numpy.array(adjusted_lens) ce_vals += list(batch_ce_vals) token_counts += batch_token_counts logging.info("Seen {}".format(len(ce_vals))) assert len(ce_vals) == len(token_counts) return ce_vals, token_counts if __name__ == "__main__": # Parse command-line arguments. config = read_config_from_cmdline() logging.info(config) # Create the TensorFlow session. tf_config = tf.ConfigProto() tf_config.allow_soft_placement = True # Train. with tf.Session(config=tf_config) as sess: train(config, sess)