train_mb_count = 0 valid_mb_count = 0 start_epoch = 0 monitor_frequency = 1000 // minibatch_size overall_train_costs = [] overall_valid_costs = [] if args.cont is not None: continue_path = args.cont if not os.path.exists(continue_path): raise ValueError("Continue model %s, path not " "found" % continue_path) saved_checkpoint = load_checkpoint(continue_path) trained_weights = get_values_from_function( saved_checkpoint["train_function"]) set_shared_variables_in_function(train_function, trained_weights) try: overall_train_costs = saved_checkpoint["overall_train_costs"] overall_valid_costs = saved_checkpoint["overall_valid_costs"] start_epoch = len(overall_train_costs) except KeyError: print("Key not found - model structure may have changed.") print("Continuing anyways - statistics may not be correct!") def _loop(function, itr): prev_h1, prev_h2 = [np_zeros((minibatch_size, n_hid)) for i in range(2)] prev_kappa = np_zeros((minibatch_size, att_size)) prev_w = np_zeros((minibatch_size, n_chars)) X_mb, X_mb_mask, c_mb, c_mb_mask = next(itr) n_cuts = len(X_mb) // cut_len + 1
train_mb_count = 0 valid_mb_count = 0 start_epoch = 0 monitor_frequency = 1000 // minibatch_size overall_train_costs = [] overall_valid_costs = [] if args.cont is not None: continue_path = args.cont if not os.path.exists(continue_path): raise ValueError("Continue model %s, path not " "found" % continue_path) saved_checkpoint = load_checkpoint(continue_path) trained_weights = get_values_from_function( saved_checkpoint["train_function"]) set_shared_variables_in_function(train_function, trained_weights) try: overall_train_costs = saved_checkpoint["overall_train_costs"] overall_valid_costs = saved_checkpoint["overall_valid_costs"] start_epoch = len(overall_train_costs) except KeyError: print("Key not found - model structure may have changed.") print("Continuing anyways - statistics may not be correct!") def _loop(function, itr): prev_h1, prev_h2, prev_h3 = [ np_zeros((minibatch_size, n_hid)) for i in range(3) ] prev_kappa = np_zeros((minibatch_size, att_size)) prev_w = np_zeros((minibatch_size, n_chars)) X_mb, X_mb_mask, c_mb, c_mb_mask = next(itr)