def test_pad_lists_to_size(): list_x = [1, 2, 3] list_y = ["a", "b"] list_z = [None, None, None] assert utils.pad_lists_to_size(list_x, list_y) == (list_x, ["a", "b", None]) assert utils.pad_lists_to_size(list_y, list_x, "c") == (["a", "b", "c"], list_x) assert utils.pad_lists_to_size(list_z, list_x) == (list_z, list_x)
def serialise(self) -> Tuple[List[Text], List[Text]]: """Turn targets and predictions to lists of equal size for sklearn.""" targets = (self.action_targets + self.intent_targets + [ MarkdownWriter.generate_entity_md(gold.get("text"), gold) for gold in self.entity_targets ]) predictions = (self.action_predictions + self.intent_predictions + [ MarkdownWriter.generate_entity_md(predicted.get("text"), predicted) for predicted in self.entity_predictions ]) # sklearn does not cope with lists of unequal size, nor None values return pad_lists_to_size(targets, predictions, padding_value="None")