From ba7f39f955b625eca784c03bd13d847b3dca14b9 Mon Sep 17 00:00:00 2001 From: "R. Alex Hofer" Date: Thu, 30 Nov 2023 07:55:42 -0800 Subject: [PATCH] Add an option to disable logging all rouge scores calculated. PiperOrigin-RevId: 586675842 --- t5/evaluation/metrics.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/t5/evaluation/metrics.py b/t5/evaluation/metrics.py index e83d9f7e..e042dc97 100644 --- a/t5/evaluation/metrics.py +++ b/t5/evaluation/metrics.py @@ -84,14 +84,16 @@ def rouge( targets, predictions, score_keys=("rouge1", "rouge2", "rougeLsum"), + verbose=True, **kwargs, ): """Computes rouge score nondeterministically using the bootstrap. Args: - targets: list of strings - predictions: list of strings + targets: list of strings. + predictions: list of strings. score_keys: list of strings with the keys to compute. + verbose: whether to enable additional logging. **kwargs: additional keyword arguments for RougeScorer. Returns: @@ -106,14 +108,15 @@ def rouge( prediction = _prepare_summary_rouge(prediction) aggregator.add_scores(scorer.score(target=target, prediction=prediction)) result = aggregator.aggregate() - for key in score_keys: - logging.info( - "%s = %.2f, 95%% confidence [%.2f, %.2f]", - key, - result[key].mid.fmeasure*100, - result[key].low.fmeasure*100, - result[key].high.fmeasure*100, - ) + if verbose: + for key in score_keys: + logging.info( + "%s = %.2f, 95%% confidence [%.2f, %.2f]", + key, + result[key].mid.fmeasure*100, + result[key].low.fmeasure*100, + result[key].high.fmeasure*100, + ) return {key: result[key].mid.fmeasure*100 for key in score_keys}