(decoding_type_schema: EventSchema,
decoding_format: str,
tokenizer: PreTrainedTokenizer)
| 45 | |
| 46 | |
| 47 | def build_compute_extract_metrics_event_fn(decoding_type_schema: EventSchema, |
| 48 | decoding_format: str, |
| 49 | tokenizer: PreTrainedTokenizer) -> Callable[[EvalPrediction], Dict]: |
| 50 | def non_pad_len(tokens: np.ndarray) -> int: |
| 51 | return np.count_nonzero(tokens != tokenizer.pad_token_id) |
| 52 | |
| 53 | def decode_pred(pred: EvalPrediction) -> Tuple[List[str], List[str]]: |
| 54 | return decode_tree_str(pred.predictions, tokenizer), decode_tree_str(pred.label_ids, tokenizer) |
| 55 | |
| 56 | def extraction_metrics(pred: EvalPrediction) -> Dict: |
| 57 | pred_str, label_str = decode_pred(pred) |
| 58 | extraction = get_extract_metrics(pred_lns=pred_str, tgt_lns=label_str, label_constraint=decoding_type_schema, |
| 59 | decoding_format=decoding_format) |
| 60 | # rouge: Dict = calculate_rouge(pred_str, label_str) |
| 61 | summ_len = np.round(np.mean(lmap(non_pad_len, pred.predictions)), 1) |
| 62 | extraction.update({"gen_len": summ_len}) |
| 63 | # extraction.update( ) |
| 64 | return extraction |
| 65 | |
| 66 | compute_metrics_fn = extraction_metrics |
| 67 | return compute_metrics_fn |
| 68 | |
| 69 | |
| 70 | @dataclass |
nothing calls this directly
no outgoing calls
no test coverage detected