本文整理匯總了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))