Key Error when running supervised training on annotations file saved with MedCATrainer

I am getting the following Key error when calling:

File ~/project/venv/lib/python3.8/site-packages/medcat/, in CAT.train_supervised(self, data_path, reset_cui_count, nepochs, print_stats, use_filters, terminate_last, use_overlaps, use_cui_doc_limit, test_size, devalue_others, use_groups, never_terminate, train_from_false_positives, extra_cui_filter, checkpoint, is_resumed)
866 train_set, test_set, _, _ = make_mc_train_test(data, self.cdb, test_size=test_size)
868 if print_stats > 0:
→ 869 fp, fn, tp, p, r, f1, cui_counts, examples = self._print_stats(test_set,
870 use_project_filters=use_filters,
871 use_cui_doc_limit=use_cui_doc_limit,
872 use_overlaps=use_overlaps,
873 use_groups=use_groups,

22 if ‘irrelevant’ in a and a[‘irrelevant’]:
—> 23 i_cuis.add(a[‘cui’])
24 return i_cuis

KeyError: ‘cui’

The annotations file was saved without text, with MedCATrainer 2.5.3.
I am using a model saved with MedCat 1.5.0 after unsupervised training on local Neurlogy documents, based on a KCL fine tuned model created in v1.2.8.

I am still stuck on this one, any suggestions please?

I’ve upgraded medcat to 1.7.0 but getting the same error.
Could this be a problem with how the annotations file was exported fro MedCATrainer? I used v 2.5.3.

Hi @elenaP - apologies for the delay in response here!

This should have a better error message here. I’ll fix that, but you cannot train medcat on a saved Trainer export without text. The surrounding text each concept is used in the training process to adapt the concept embedding. Can you try and export the data again - with text - and then train?