rouge-chinese

raw JSON →
1.0.3 verified Fri May 01 auth: no python

A Python implementation of ROUGE score specifically designed for Chinese text evaluation. It supports both character-level and word-level ROUGE-1, ROUGE-2, and ROUGE-L metrics. Version 1.0.3 is the latest, with no recent updates (last release likely 2021).

pip install rouge-chinese
error AttributeError: module 'rouge' has no attribute 'Rouge'
cause Wrong import: using 'import rouge' instead of 'from rouge_chinese import Rouge'.
fix
Install rouge-chinese and import as 'from rouge_chinese import Rouge'.
error TypeError: get_scores() takes 3 positional arguments but 4 were given
cause Passing arguments incorrectly; the API expects (hypotheses, references) as lists of strings.
fix
Call as 'rouge.get_scores(hypotheses, references)' with two lists.
error ImportError: No module named 'jieba'
cause Missing dependency jieba required for Chinese word segmentation.
fix
Install jieba: 'pip install jieba'.
breaking The library 'rouge-chinese' is commonly confused with 'rouge' (the general ROUGE implementation). Importing from 'rouge' instead of 'rouge_chinese' will import a different library with different API.
fix Use 'from rouge_chinese import Rouge' instead of 'import rouge'.
gotcha The library returns scores as a dictionary with keys like 'rouge-1', 'rouge-2', 'rouge-l', but the output format differs from the original 'rouge' library. The 'f' key is present but some users expect 'f1-score'.
fix Access scores via scores[0]['rouge-1']['f'] and similar.
deprecated The library has not been updated since 2021 and may have compatibility issues with newer Python versions (e.g., Python 3.10+). It relies on 'jieba' which may change its API.
fix Consider pinning dependencies (jieba==0.42.1) or switching to 'rouge' library with proper Chinese tokenization.

Basic usage computing ROUGE scores for Chinese text.

from rouge_chinese import Rouge

# Example hypotheses and references (Chinese text)
hypotheses = ["这是一个测试句子"]
references = ["这是一个参考句子"]

rouge = Rouge()
scores = rouge.get_scores(hypotheses, references)
print(scores)