All Projects → bheinzerling → Pyrouge

bheinzerling / Pyrouge

Licence: mit
A Python wrapper for the ROUGE summarization evaluation package

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Pyrouge

Scientificsummarizationdatasets
Datasets I have created for scientific summarization, and a trained BertSum model
Stars: ✭ 100 (-47.92%)
Mutual labels:  summarization
Pytextrank
Python implementation of TextRank for phrase extraction and summarization of text documents
Stars: ✭ 1,675 (+772.4%)
Mutual labels:  summarization
Pythonrouge
Python wrapper for evaluating summarization quality by ROUGE package
Stars: ✭ 155 (-19.27%)
Mutual labels:  summarization
Lexrank
LexRank algorithm for text summarization
Stars: ✭ 108 (-43.75%)
Mutual labels:  summarization
Unified Summarization
Official codes for the paper: A Unified Model for Extractive and Abstractive Summarization using Inconsistency Loss.
Stars: ✭ 114 (-40.62%)
Mutual labels:  summarization
Files2rouge
Calculating ROUGE score between two files (line-by-line)
Stars: ✭ 120 (-37.5%)
Mutual labels:  summarization
Tldr
Text summarizer for golang using LexRank
Stars: ✭ 92 (-52.08%)
Mutual labels:  summarization
Adversarial video summary
Unofficial PyTorch Implementation of SUM-GAN from "Unsupervised Video Summarization with Adversarial LSTM Networks" (CVPR 2017)
Stars: ✭ 187 (-2.6%)
Mutual labels:  summarization
Nlp Models Tensorflow
Gathers machine learning and Tensorflow deep learning models for NLP problems, 1.13 < Tensorflow < 2.0
Stars: ✭ 1,603 (+734.9%)
Mutual labels:  summarization
Neusum
Code for the ACL 2018 paper "Neural Document Summarization by Jointly Learning to Score and Select Sentences"
Stars: ✭ 143 (-25.52%)
Mutual labels:  summarization
Transformersum
Models to perform neural summarization (extractive and abstractive) using machine learning transformers and a tool to convert abstractive summarization datasets to the extractive task.
Stars: ✭ 107 (-44.27%)
Mutual labels:  summarization
Nlp Papers
Papers and Book to look at when starting NLP 📚
Stars: ✭ 111 (-42.19%)
Mutual labels:  summarization
Textrank
😉 🌀 🍓 TextRank implementation in Golang with extendable features (summarization, phrase extraction) and multithreading (goroutine) support (Go 1.8, 1.9, 1.10)
Stars: ✭ 125 (-34.9%)
Mutual labels:  summarization
What I Have Read
Paper Lists, Notes and Slides, Focus on NLP. For summarization, please refer to https://github.com/xcfcode/Summarization-Papers
Stars: ✭ 110 (-42.71%)
Mutual labels:  summarization
Multi News
Large-scale multi-document summarization dataset and code
Stars: ✭ 158 (-17.71%)
Mutual labels:  summarization
Lecture Summarizer
Lecture summarization with BERT
Stars: ✭ 94 (-51.04%)
Mutual labels:  summarization
Haystack
🔍 Haystack is an open source NLP framework that leverages Transformer models. It enables developers to implement production-ready neural search, question answering, semantic document search and summarization for a wide range of applications.
Stars: ✭ 3,409 (+1675.52%)
Mutual labels:  summarization
Textrank
🌀 ⚡️ 🌍 TextRank (automatic text summarization) for PHP8
Stars: ✭ 193 (+0.52%)
Mutual labels:  summarization
Cx db8
a contextual, biasable, word-or-sentence-or-paragraph extractive summarizer powered by the latest in text embeddings (Bert, Universal Sentence Encoder, Flair)
Stars: ✭ 164 (-14.58%)
Mutual labels:  summarization
Onnxt5
Summarization, translation, sentiment-analysis, text-generation and more at blazing speed using a T5 version implemented in ONNX.
Stars: ✭ 143 (-25.52%)
Mutual labels:  summarization

pyrouge

pyrouge is a Python wrapper for the ROUGE summarization evaluation package. Getting ROUGE to work can require quite a bit of time. pyrouge is designed to make getting ROUGE scores easier by automatically converting your summaries into a format ROUGE understands, and automatically generating the ROUGE configuration file.

Usage Examples

I have summaries in plain text format and want to get the ROUGE scores

You can evaluate your plain text summaries like this:

::

from pyrouge import Rouge155

r = Rouge155()
r.system_dir = 'path/to/system_summaries'
r.model_dir = 'path/to/model_summaries'
r.system_filename_pattern = 'some_name.(\d+).txt'
r.model_filename_pattern = 'some_name.[A-Z].#ID#.txt'

output = r.convert_and_evaluate()
print(output)
output_dict = r.output_to_dict(output)

In order to evaluate summaries, ROUGE needs to know where your summaries and the gold standard summaries are, and how to match them. In ROUGE parlance, your summaries are 'system' summaries and the gold standard summaries are 'model' summaries. The summaries should be in separate folders, whose paths are set with the system_dir and model_dir variables. All summaries should contain one sentence per line.

To automatically match a system summary with the corresponding model summaries, pyrouge uses regular expressions. For example, let's assume your system summaries are named with a combination of a fixed name and a variable numeric ID like this:

| some_name.001.txt | some_name.002.txt | some_name.003.txt | ...

and the model summaries like this, with uppercase letters identifying multiple model summaries for a given document:

| some_name.A.001.txt | some_name.B.001.txt | some_name.C.001.txt | some_name.A.002.txt | some_name.B.002.txt | ...

The group in the system_filename_pattern tells pyrouge which part of the filename is the ID -- in this case (\d+). You have to use round brackets to indicate a group, or else pyrouge won't be able to tell apart the ID from the rest of the filename. pyrouge then uses that ID to find all matching model summaries. The special placeholder #ID# tells pyrouge where it should expect the ID in the model_filename_pattern. The [A-Z] part matches multiple model summaries for that ID.

With the configuration done, invoking convert_and_evaluate() gets you the ROUGE scores as a string. If you want to further process the scores, you can parse the output into a dict with output_to_dict(output).

I only want to preprocess my summaries and then run ROUGE on my own

To convert plain text summaries into a format ROUGE understands, do:

::

from pyrouge import Rouge155

Rouge155.convert_summaries_to_rouge_format(system_input_dir, system_output_dir)
Rouge155.convert_summaries_to_rouge_format(model_input_dir, model_output_dir)

This will convert all summaries in system_input_dir and model_input_dir, and save them to their respective output directories.

To generate the configuration file that ROUGE uses to match system and model summaries, do:

::

from pyrouge import Rouge155

Rouge155.write_config_static(
    system_dir, system_filename_pattern,
    model_dir, model_filename_pattern,
    config_file_path)

The first four arguments are explained above. config_file_path specifies where to save the configuration file.

Using pyrouge from the command line

If you prefer the command line to Python and the pyrouge module, you can use the following scripts, which are automatically installed and should be runnable from anywhere on your system:

  • pyrouge_evaluate_plain_text_files gets you ROUGE scores for your plain text summaries. Example:

::

pyrouge_evaluate_plain_text_files -s systems_plain/ -sfp "some_name.(\d+).txt" -m models_plain/ -mfp some_name.[A-Z].#ID#.txt
  • pyrouge_evaluate_rouge_format_files gets you ROUGE scores for summaries already converted to ROUGE format. Example usage for the sample-test/SL2003 data that comes with ROUGE:

::

pyrouge_evaluate_rouge_format_files -s systems -sfp "SL.P.10.R.11.SL062003-(\d+).html" -m models -mfp SL.P.10.R.[A-Z].SL062003-#ID#.html

Note that the system filename pattern is enclosed in quotation marks because it contains special characters.

  • pyrouge_convert_plain_text_to_rouge_format converts plain text files into a format ROUGE understands. If your plain text files do not contain one sentence per line, this script can also split sentences, provided you have nltk and its Punkt sentence splitter installed. Example:

::

pyrouge_convert_plain_text_to_rouge_format -i models_plain/ -o models_rouge
  • pyrouge_write_config_file creates a configuration file you can use to run ROUGE on your own. Example:

::

pyrouge_write_config_file -s systems -sfp "SL.P.10.R.11.SL062003-(\d+).html" -m models -mfp SL.P.10.R.[A-Z].SL062003-#ID#.html -c sl2003_config.xml

Running any of these with the -h option will display a usage message explaining the various command line options.

Installation

Instruction on installing ROUGE can be found here <https://web.archive.org/web/20171107220839/www.summarizerman.com/post/42675198985/figuring-out-rouge>__.

Depending on your system, you might have to run the following commands as root.

To install pyrouge, run:

::

pip install pyrouge

If you have trouble installing pyrouge on Windows, please check this guide by Franck Dernoncourt <https://stackoverflow.com/questions/47045436/how-to-install-the-python-package-pyrouge-on-microsoft-windows/47045437#47045437>_.

Assuming a working ROUGE-1.5.5. installation, tell pyrouge the ROUGE path with this command:

::

pyrouge_set_rouge_path /absolute/path/to/ROUGE-1.5.5/directory

If saving the rouge path using this script doesn't work on your system, you can also supply the rouge path at runtime:

::

r = Rouge155('/absolute/path/to/ROUGE-1.5.5/directory') 

To test if everything is installed correctly, run:

::

python -m pyrouge.test

If everything works, you should see something like:

::

Ran 10 tests in 18.055s

OK

If you want to uninstall pyrouge:

::

pip uninstall pyrouge
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].