How to Use PythonROUGE for Summarization Evaluation

Jan 18, 2024 | Data Science

PythonROUGE is a powerful Python wrapper designed for evaluating various ROUGE metrics without the hassle of creating XML files. If you’re delving into document summarization research, understanding how to utilize this tool effectively can heighten the accuracy of your evaluations. In this guide, you’ll learn how to install, use, and troubleshoot PythonROUGE.

Installation

Installing PythonROUGE can be done in two different ways. Here’s how to get started:

  • Without using pip:
    • Clone the repository:
    • git clone https://github.com/tagucci/pythonrouge.git
      
    • Navigate to the PythonROUGE directory and install:
    • python setup.py install
      
  • Using pip:
  • pip install git+https://github.com/tagucci/pythonrouge.git
    

Usage

Once you’ve installed PythonROUGE, you can start evaluating ROUGE scores using your system and reference summaries. Think of evaluating summaries like comparing the outputs of two chefs. You have the dish (summary) from chef A (your system) and you want to compare it to the ideal dish (reference summary) from chef B. Here’s how you can implement the comparison.

To perform evaluations, you’ll need to specify paths for the ROUGE resources:

from pythonrouge.pythonrouge import Pythonrouge

summary = [[ "Tokyo is one of the biggest cities in the world." ]]
reference = [[["The capital of Japan, Tokyo, is the center of Japanese economy."]]]

rouge = Pythonrouge(summary_file_exist=False,                    
                    summary=summary, 
                    reference=reference,
                    n_gram=2, 
                    ROUGE_SU4=True, 
                    ROUGE_L=False, 
                    recall_only=True, 
                    stemming=True, 
                    stopwords=True, 
                    word_level=True, 
                    length_limit=True, 
                    length=50, 
                    use_cf=False, 
                    cf=95, 
                    scoring_formula=average, 
                    resampling=True, 
                    samples=1000, 
                    favor=True, 
                    p=0.5)

score = rouge.calc_score()
print(score)

The score output will resemble something like this:

ROUGE-1: 0.16667, ROUGE-2: 0.0, ROUGE-SU4: 0.05

This indicates how closely your summary resembles the reference summary based on ROUGE metrics.

Directory Format

If you’d rather evaluate using a standard directory format for summaries, make sure your system and reference summaries are organized correctly, as follows:

  • system summary: summaryA.txt
  • reference summaries:
    • summaryA.1.txt
    • summaryA.2.txt
    • summaryA.3.txt
    • summaryA.4.txt

Then, evaluate similar to before:

rouge = Pythonrouge(summary_file_exist=True,                    
                    peer_path=summary, 
                    model_path=reference, 
                    n_gram=2, 
                    ROUGE_SU4=True, 
                    ROUGE_L=False, 
                    recall_only=True, 
                    stemming=True, 
                    stopwords=True, 
                    word_level=True, 
                    length_limit=True, 
                    length=50, 
                    use_cf=False, 
                    cf=95, 
                    scoring_formula=average, 
                    resampling=True, 
                    samples=1000, 
                    favor=True, 
                    p=0.5)

Troubleshooting

If you encounter the error message:

Cannot open exception db file for reading: home/pythonrouge/pythonrouge/RELEASE-1.5.5/data/WordNet-2.0.exc.db

Follow these steps:

  • Navigate to the PythonROUGE directory you installed:
  • cd pythonrouge/RELEASE-1.5.5/data/
    
  • Remove the problematic file if it exists:
  • rm WordNet-2.0.exc.db
    
  • Run the script to build a new exception database:
  • buildExeptionDB.pl . exc WordNet-2.0.exc.db
    
  • Create a link for the new exception database:
  • ln -s WordNet-2.0-Exceptions/WordNet-2.0.exc.db WordNet-2.0.exc.db
    

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox