本文整理汇总了Python中rouge.FilesRouge方法的典型用法代码示例。如果您正苦于以下问题:Python rouge.FilesRouge方法的具体用法?Python rouge.FilesRouge怎么用?Python rouge.FilesRouge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rouge
的用法示例。
在下文中一共展示了rouge.FilesRouge方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: score
# 需要导入模块: import rouge [as 别名]
# 或者: from rouge import FilesRouge [as 别名]
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)}
示例2: __call__
# 需要导入模块: import rouge [as 别名]
# 或者: from rouge import FilesRouge [as 别名]
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}
示例3: setUp
# 需要导入模块: import rouge [as 别名]
# 或者: from rouge import FilesRouge [as 别名]
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()
示例4: call
# 需要导入模块: import rouge [as 别名]
# 或者: from rouge import FilesRouge [as 别名]
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)
示例5: main
# 需要导入模块: import rouge [as 别名]
# 或者: from rouge import FilesRouge [as 别名]
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))