# Buggy code
def _find_best(experiment_dir, component):
    accuracies = []
    for epoch_model in experiment_dir.iterdir():
        if epoch_model.is_dir() and epoch_model.parts[-1] != "model-final":
            accs = srsly.read_json(epoch_model / "accuracy.json")
            scores = [accs.get(metric, 0.0) for metric in _get_metrics(component)]
            accuracies.append((scores, epoch_model))
    if accuracies:
        return max(accuracies)[1]
    else:
        return None


# Traceback (TypeError)
root@1c02094b4938:/project# spacy train \
--base-model en_core_oi_lg/en_core_oi_lg-0.0.3 \
--pipeline ner \
--n-iter 30 \
--n-early-stopping 5 \
en \
models \
data/ner/train \
data/ner/eval
✔ Created output directory: models
Training pipeline: ['ner']
Starting with base model 'en_core_oi_lg/en_core_oi_lg-0.0.3'
Extending component from base model 'ner'
Counting training words (limit=0)

Itn  NER Loss   NER P   NER R   NER F   Token %  CPU WPS
---  ---------  ------  ------  ------  -------  -------
1   4857.485  67.342  58.462  62.588   92.721    17608
2   2574.152  74.643  68.901  71.657   92.721    19069
3   1822.187  77.081  74.286  75.658   92.721    19331
…
15    246.849  80.291  78.791  79.534   92.721    19075
16    242.276  80.518  78.571  79.533   92.721    18501
17    217.591  79.911  78.681  79.291   92.721    18839
Early stopping, best iteration is: 11
Best score = 79.919691339363; Final iteration score = 79.29442811710254
✔ Saved model to output directory
models/model-final
⠙ Creating best model...
Traceback (most recent call last):
File "/usr/local/lib/python3.8/runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/local/lib/python3.8/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.8/site-packages/spacy/__main__.py", line 33, in <module>
plac.call(commands[command], sys.argv[1:])
File "/usr/local/lib/python3.8/site-packages/plac_core.py", line 367, in call
cmd, result = parser.consume(arglist)
File "/usr/local/lib/python3.8/site-packages/plac_core.py", line 232, in consume
return cmd, self.func(*(args + varargs + extraopts), **kwargs)
File "/usr/local/lib/python3.8/site-packages/spacy/cli/train.py", line 583, in train
best_model_path = _collate_best_model(final_meta, output_path, best_pipes)
File "/usr/local/lib/python3.8/site-packages/spacy/cli/train.py", line 643, in _collate_best_model
bests[component] = _find_best(output_path, component)
File "/usr/local/lib/python3.8/site-packages/spacy/cli/train.py", line 666, in _find_best
return max(accuracies)[1]
TypeError: '>' not supported between instances of 'dict' and 'dict'

# Fixed code
def _find_best(experiment_dir, component):
    accuracies = []
    for epoch_model in experiment_dir.iterdir():
        if epoch_model.is_dir() and epoch_model.parts[-1] != "model-final":
            accs = srsly.read_json(epoch_model / "accuracy.json")
            scores = [accs.get(metric, 0.0) for metric in _get_metrics(component)]
            # remove per_type dicts from score list for max() comparison
            scores = [score for score in scores if isinstance(score, float)]
            accuracies.append((scores, epoch_model))
    if accuracies:
        return max(accuracies)[1]
    else:
        return None