def update_eval_info(
    directory,
    eval_result,
    higher_is_better = True,
    eval_info_filename = BEST_EVAL_INFO_FILENAME):
  """Updates the eval info if the new result is better.

  Args:
    directory: The directory where the best eval info file is stored.
    eval_result: The new eval result.
    higher_is_better: Whether higher eval numbers are better.
    eval_info_filename: The name of the best eval file.

  Returns:
    Whether the new eval result is better than the previous one.
  """
  # Read the previous eval number and compare it to the current one.
  full_path = os.path.join(directory, eval_info_filename)
  if not tf.io.gfile.exists(full_path):
    is_better = True
  else:
    with tf.io.gfile.GFile(full_path, "r") as eval_file:
      previous_eval_result_str = eval_file.read()
    try:
      previous_eval_result = float(previous_eval_result_str)
      if higher_is_better:
        is_better = eval_result > previous_eval_result
      else:
        is_better = eval_result < previous_eval_result
    except ValueError:
      is_better = True
      tf.logging.info("Skip previous eval info because it is ill-formed.")

  if is_better:
    if not tf.io.gfile.exists(directory):
      tf.io.gfile.makedirs(directory)
    with tf.io.gfile.GFile(full_path, "w") as eval_file:
      eval_file.write("%f\n" % eval_result)

  return is_better
Updates the eval info if the new result is better.

  Args:
    directory: The directory where the best eval info file is stored.
    eval_result: The new eval result.
    higher_is_better: Whether higher eval numbers are better.
    eval_info_filename: The name of the best eval file.

  Returns:
    Whether the new eval result is better than the previous one.
  
language/multivec/models/checkpoint_utils.py