Python rouge.FilesRouge() Examples
The following are 5
code examples of rouge.FilesRouge().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
rouge
, or try the search function
.
Example #1
Source File: evaluator.py From DualRL with MIT License | 5 votes |
def score(self, labels_file, predictions_path): from rouge import FilesRouge files_rouge = FilesRouge(predictions_path, labels_file) rouge_scores = files_rouge.get_scores(avg=True) return {k: v["f"] for k, v in six.iteritems(rouge_scores)}
Example #2
Source File: scorers.py From OpenNMT-tf with MIT License | 5 votes |
def __call__(self, ref_path, hyp_path): scorer = FilesRouge(metrics=list(self.scores_name)) rouge_scores = scorer.get_scores(hyp_path, ref_path, avg=True) return {name:rouge_scores[name]["f"] for name in self.scores_name}
Example #3
Source File: test_basic.py From rouge with Apache License 2.0 | 5 votes |
def setUp(self): self.hyp_path = './tests/hyp.txt' self.ref_path = './tests/ref.txt' self.data_path = './tests/data.json' with open(self.data_path) as f: self.data = json.load(f) self.rouge = rouge.Rouge() self.files_rouge = rouge.FilesRouge()
Example #4
Source File: py_metrics.py From delta with Apache License 2.0 | 5 votes |
def call(self, y_true=None, y_pred=None, arguments=None): ref_sents = [] for tgt_path in self.tgt_paths_after_pre_process: with open(tgt_path, "r", encoding='utf8') as tgt_f: ref_sents.extend(tgt_f.readlines()) ref_sents = [sent.strip() for sent in ref_sents] with open(self.ref_path, "w", encoding="utf-8") as in_f: for ref_sent in ref_sents: in_f.write(ref_sent) in_f.write("\n") files_rouge = FilesRouge(self.hyp_path, self.ref_path) scores = files_rouge.get_scores(avg=True) return self.get_scores_output(scores)
Example #5
Source File: rouge_cmd.py From rouge with Apache License 2.0 | 4 votes |
def main(): parser = argparse.ArgumentParser(description='Rouge Metric Calculator') parser.add_argument('-f', '--file', help="File mode", action='store_true') parser.add_argument('-a', '--avg', help="Average mode", action='store_true') parser.add_argument('--ignore_empty', action='store_true', help="Ignore empty hypothesis") parser.add_argument('hypothesis', type=str, help='Text of file path') parser.add_argument('reference', type=str, help='Text or file path') parser.add_argument("--metrics", nargs="+", type=str.upper, choices=METRICS_CHOICES.keys(), help="Metrics to use (default=all)") parser.add_argument("--stats", nargs="+", type=str.upper, choices=STATS_CHOICES, help="Stats to use (default=all)") args = parser.parse_args() metrics = args.metrics stats = args.stats if metrics is not None: metrics = [METRICS_CHOICES[m] for m in args.metrics] if args.file: hyp, ref = args.hypothesis, args.reference assert(os.path.isfile(hyp)) assert(os.path.isfile(ref)) files_rouge = FilesRouge(metrics, stats) scores = files_rouge.get_scores( hyp, ref, avg=args.avg, ignore_empty=args.ignore_empty) print(json.dumps(scores, indent=2)) else: hyp, ref = args.hypothesis, args.reference assert(isinstance(hyp, str)) assert(isinstance(ref, str)) rouge = Rouge(metrics, stats) scores = rouge.get_scores(hyp, ref, avg=args.avg) print(json.dumps(scores, indent=2))