in training/run_distillation.py [0:0]
def sorted_best_checkpoints(output_dir=None, checkpoint_prefix="checkpoint"):
"""Helper function to sort saved best checkpoints."""
ordering_and_checkpoint_path = []
glob_checkpoints = [str(x) for x in Path(output_dir).glob(f"{checkpoint_prefix}-*") if os.path.isdir(x)]
for path in glob_checkpoints:
regex_match = re.search(r"val-wer-([0-9]+\.[0-9]+)", path)
if regex_match is not None and regex_match.groups() is not None:
ordering_and_checkpoint_path.append((float(regex_match.groups(1)[0]), path))
checkpoints_sorted = sorted(ordering_and_checkpoint_path, reverse=True)
checkpoints_sorted = [checkpoint[1] for checkpoint in checkpoints_sorted]
return checkpoints_sorted