Skip to main content

Full Python ROUGE Score Implementation (not a wrapper)

Project description

Rouge

A full Python librarie for the ROUGE metric (paper).

Disclaimer

This implementation is independant from the "official" ROUGE script (aka. ROUGE-155).
Results may be slighlty different, see discussions in #2.

Quickstart

Clone & Install

git clone https://github.com/pltrdy/rouge
cd rouge
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.

# 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
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:

[
  {
    "rouge-1": {
      "f": 0.4786324739396596,
      "p": 0.6363636363636364,
      "r": 0.3835616438356164
    },
    "rouge-2": {
      "f": 0.2608695605353498,
      "p": 0.3488372093023256,
      "r": 0.20833333333333334
    },
    "rouge-l": {
      "f": 0.5128205081276938,
      "p": 0.6818181818181818,
      "r": 0.410958904109589
    }
  }
]
Score multiple sentences
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.

from rouge import FilesRouge

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rouge-1.0.0rc2.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

rouge-1.0.0rc2-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file rouge-1.0.0rc2.tar.gz.

File metadata

  • Download URL: rouge-1.0.0rc2.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.4.2 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.35.0 CPython/3.6.9

File hashes

Hashes for rouge-1.0.0rc2.tar.gz
Algorithm Hash digest
SHA256 73e045834356358f9d2e7f1e581cecbbf0e80d564bd7de09c285333529093111
MD5 70537628c478f4b4a8be300567860839
BLAKE2b-256 124927c503e157aaa5fa46f396018404536168dc1937271a536a60caf1fb2b5f

See more details on using hashes here.

File details

Details for the file rouge-1.0.0rc2-py3-none-any.whl.

File metadata

  • Download URL: rouge-1.0.0rc2-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.4.2 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.8.0 tqdm/4.35.0 CPython/3.6.9

File hashes

Hashes for rouge-1.0.0rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 60db7cae4ec92c23d1ed49402377fb4856e7f3f587e21a5464efffb68bb1d588
MD5 0027b91edb8533bf7b099b1693ee402d
BLAKE2b-256 36ed196f6db1ce5074fb8404fe651bcdbbb4f366d09874285d93eb2312f019af

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page