Skip to main content
# Rouge
*A full Python librarie for the ROUGE metric [(paper)](http://www.aclweb.org/anthology/W04-1013).*

### Disclaimer
This implementation is independant from the "official" ROUGE script (aka. `ROUGE-155`).
Results may be *slighlty* different, see [discussions in #2](https://github.com/pltrdy/rouge/issues/2).

## Quickstart
#### Clone & Install
```shell
git clone https://github.com/pltrdy/rouge
cd pyrouge
python setup.py install
# or
pip install -U .
```
or from pip:
```
pip install rouge
```
#### Use it from the shell (JSON Output)
```
$rouge -h
usage: rouge [-h] [-f] [-a] hypothesis reference

Rouge Metric Calculator

positional arguments:
hypothesis Text of file path
reference Text or file path

optional arguments:
-h, --help show this help message and exit
-f, --file File mode
-a, --avg Average mode

```

e.g.


```shell
# Single Sentence
rouge "transcript is a written version of each day 's cnn student" \
"this page includes the show transcript use the transcript to help students with"

# Scoring using two files (line by line)
rouge -f ./tests/hyp.txt ./ref.txt

# Avg scoring - 2 files
rouge -f ./tests/hyp.txt ./ref.txt --avg
```

#### As a library

###### Score 1 sentence

```python
from rouge import Rouge

hypothesis = "the #### transcript is a written version of each day 's cnn student news program use this transcript to he lp students with reading comprehension and vocabulary use the weekly newsquiz to test your knowledge of storie s you saw on cnn student news"

reference = "this page includes the show transcript use the transcript to help students with reading comprehension and vocabulary at the bottom of the page , comment for a chance to be mentioned on cnn student news . you must be a teac her or a student age # # or older to request a mention on the cnn student news roll call . the weekly newsquiz tests students ' knowledge of even ts in the news"

rouge = Rouge()
scores = rouge.get_scores(hypothesis, reference)
```

*Output:*

```json
{
"rouge-1": {
"f": 0.5238095189484127,
"p": 0.6285714285714286,
"r": 0.4489795918367347
},
"rouge-2": {
"f": 0.27027026566025497,
"p": 0.375,
"r": 0.2112676056338028
},
"rouge-l": {
"f": 0.28711800978275975,
"p": 0.4418604651162791,
"r": 0.25675675675675674
}
}
```

###### Score multiple sentences
```python
import json
from rouge import Rouge

# Load some sentences
with open('./tests/data.json') as f:
data = json.load(f)

hyps, refs = map(list, zip(*[[d['hyp'], d['ref']] for d in data]))
rouge = Rouge()
scores = rouge.get_scores(hyps, refs)
# or
scores = rouge.get_scores(hyps, refs, avg=True)
```

*Output (`avg=False`)*: a list of `n` dicts:

```
{"rouge-1": {"f": _, "p": _, "r": _}, "rouge-2" : { .. }, "rouge-3": { ... }}
```


*Output (`avg=True`)*: a single dict with average values:

```
{"rouge-1": {"f": _, "p": _, "r": _}, "rouge-2" : { ..     }, "rouge-3": { ... }}
```

###### Score two files (line by line)
Given two files `hyp_path`, `ref_path`, with the same number (`n`) of lines, calculate score for each of this lines, or, the average over the whole file.

```python
from rouge import FilesRouge

files_rouge = FilesRouge(hyp_path, ref_path)
scores = files_rouge.get_scores()
# or
scores = files_rouge.get_scores(avg=True)
```

**Note** that you can avoid consuming too much memory by using `batch_line=l`. This way, the script will read only `l` lines at a time. (otherwise it loads the whole files).


Metadata

Release files for rouge 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rouge 0.3.1
File Size Uploaded Provenance Actions
rouge-0.3.1.tar.gz 10.8 kB Without provenance Details for rouge-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rouge 0.3.1
File Interpreter ABI Platform Actions
rouge-0.3.1-py3-none-any.whl Python 3 none any Details for rouge-0.3.1-py3-none-any.whl

Total release size: 18.2 kB

Release files / rouge-0.3.1.tar.gz

Download URL rouge-0.3.1.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f131c13661f96a048df4d372d83598a65efbbfaeafed491ee96313cc6aa7364b
BLAKE2b-256 checksum
How to use checksums
2f9b0a857f3811f9095ec909cdc513db42ac5dbb983d2a86c0f65d47914cab1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / rouge-0.3.1-py3-none-any.whl

Download URL rouge-0.3.1-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
96948febb4506c5a203c47d55e5f83b82baeb230ff84ae8fcf15331ee0094fc8
BLAKE2b-256 checksum
How to use checksums
8f89af359c22e1d858e0299d4cc9219f36b504817c9797acad23081247867845
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for rouge 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page