JialeGuo / py_rouge_zh

A full Python implementation of the ROUGE metric, especially for Chinese texts processing.
Apache License 2.0
17 stars 4 forks source link

Py-rouge

A full Python implementation of the ROUGE metric, especially for Chinese texts processing. Mainly based on https://github.com/Diego999/py-rouge 中文文本Rouge值相关计算的python实现

欢迎Star :grin:

Important remarks

Installation

git clone https://github.com/JialeGuo/py_rouge_zh
cd py-rouge-zh
python setup.py install

Example

import rouge_zh

evaluator = rouge_zh.Rouge(metrics=['rouge-n'],
                           max_n=4,
                           limit_length=True,
                           length_limit=100,
                           length_limit_type='words',
                           alpha=0.5, # Default F1_score
                           weight_factor=1.2,
                           stemming=True)

all_hypothesis = ["哈 尔 滨 是 黑 龙 江 的 省 会"]
all_references = [["哈 工 大 在 哈 尔 滨", "黑 龙 江 太 冷 了"]]

scores = evaluator.get_scores(all_hypothesis, all_references)
print(scores)

It produces the following output:

{'rouge-2': {'r': 0.1, 'p': 0.1, 'f': 0.10000000000000002}, 'rouge-3': {'r': 0.0, 'p': 0.0, 'f': 0.0}, 'rouge-4': {'r': 0.0, 'p': 0.0, 'f': 0.0}, 'rouge-1': {'r': 0.5, 'p': 0.5, 'f': 0.5}}