question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

rouge-score not found by evaluate.load()

See original GitHub issue

Hello, I have a problem loading the rouge metric with evaluate.load(). Apparently, the rouge_scores library (https://github.com/google-research/google-research/tree/master/rouge) is not found by evaluate. I followed your tutorial from https://huggingface.co/course/chapter7/5?fw=pt#preprocessing-the-data (section ‘Metrics for Text Summarization’) and installed the rouge_score library. I got access to two different clusters. On the first one, everything works like a charm, however, the second cluster throws this exception below:

Traceback

Traceback (most recent call last): File “/home/hd/hd_hd/hd_rk435/MA_Thesis/fine-tune/mnli_text/generation_MNLI.py”, line 14, in <module> rouge_score = evaluate.load(“rouge”) #/home/hd/hd_hd/hd_rk435/rouge") # evaluate.load(“rouge”) #/pfs/data5/home/hd/hd_hd/hd_rk435/ma_venv/lib64/python3.8/site-packages/rouge_score/rouge_scorer.py") #“rouge”) File “/pfs/data5/home/hd/hd_hd/hd_rk435/ma_venv/lib64/python3.8/site-packages/evaluate/loading.py”, line 716, in load evaluation_module = evaluation_module_factory( File “/pfs/data5/home/hd/hd_hd/hd_rk435/ma_venv/lib64/python3.8/site-packages/evaluate/loading.py”, line 621, in evaluation_module_factory return LocalEvaluationModuleFactory( File “/pfs/data5/home/hd/hd_hd/hd_rk435/ma_venv/lib64/python3.8/site-packages/evaluate/loading.py”, line 424, in get_module local_imports = _download_additional_modules( File “/pfs/data5/home/hd/hd_hd/hd_rk435/ma_venv/lib64/python3.8/site-packages/evaluate/loading.py”, line 268, in _download_additional_modules raise ImportError( ImportError: To be able to use rouge, you need to install the following dependencies[‘rouge’] using ‘pip install rouge’ for instance’

Also for Python 3.9

Traceback (most recent call last): File “/home/hd/hd_hd/hd_rk435/MA_Thesis/fine-tune/mnli_text/generation_MNLI.py”, line 14, in <module> rouge_score = evaluate.load(“/home/hd/hd_hd/hd_rk435/rouge/rouge.py”) # evaluate.load(“rouge”) #/pfs/data5/home/hd/hd_hd/hd_rk435/ma_venv/lib64/python3.8/site-packages/rouge_score/rouge_scorer.py") #“rouge”) File “/pfs/data5/home/hd/hd_hd/hd_rk435/test_venv/lib64/python3.9/site-packages/evaluate/loading.py”, line 774, in load evaluation_module = evaluation_module_factory( File “/pfs/data5/home/hd/hd_hd/hd_rk435/test_venv/lib64/python3.9/site-packages/evaluate/loading.py”, line 671, in evaluation_module_factory return LocalEvaluationModuleFactory( File “/pfs/data5/home/hd/hd_hd/hd_rk435/test_venv/lib64/python3.9/site-packages/evaluate/loading.py”, line 494, in get_module local_imports = _download_additional_modules( File “/pfs/data5/home/hd/hd_hd/hd_rk435/test_venv/lib64/python3.9/site-packages/evaluate/loading.py”, line 269, in _download_additional_modules raise ImportError( ImportError: To be able to use rouge, you need to install the following dependencies[‘rouge’, ‘rouge’, ‘rouge’] using ‘pip install rouge rouge rouge’ for instance’

Code to reproduce:

import evaluate
rouge_score = evaluate.load("rouge")

Different ways of loading the metric, e.g through a path results in the same exception.

Versions I’ve tried to get the script running in different versions, none of them worked.

  • Python 3.8.6/3.9.2
  • transformers 4.19.2
  • rouge-score 1.0.2/0.0.4
  • evaluate 0.3.0/0.1.2
  • Torch 1.12.1

On the first cluster I’m using the following versions:

  • Python 3.8.10
  • transformers 4.19.2
  • rouge-score 0.0.4
  • evaluate 0.1.2
  • torch 1.12.0

Rouge Score seems to be correctly installed:

(test_venv) [ ~]$ ls test_venv/lib64/python3.9/site-packages/rouge_score/
__init__.py  create_pyrouge_files.py  io_test.py  rouge_scorer.py       scoring.py       test_util.py  tokenize_test.py
__pycache__  io.py                    rouge.py    rouge_scorer_test.py  scoring_test.py  tokenize.py

Thanks for reading!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
lvwerracommented, Oct 25, 2022

I think loading rouge_score before might lead to a namespace clash with the evaluate importer in the last example.

What’s odd in the original message is that it says you should install rouge whereas the import is actually rouge_score. The error comes from here: https://github.com/huggingface/evaluate/blob/960dc92ef6a86e3b11d7b7276b4960135a3129b9/src/evaluate/loading.py#L262-L272

When looking at the library_import_name, and library_import_path I get:

absl # Here to have a nice missing dependency error message early on
datasets datasets
nltk # Here to have a nice missing dependency error message early on
numpy # Here to have a nice missing dependency error message early on
six # Here to have a nice missing dependency error message early on
rouge_score rouge_score
evaluate evaluate

So it is not clear to me where rouge comes from since this is grabbed by scanning the Python files for imports.

Anyway, since it is fixed now I won’t spend more time investigating 😃

1reaction
PhMeiercommented, Oct 25, 2022

I’ve used version 0.3.0 of evaluate and rouge-score 1.2.1 in Python 3.9.2 with this code example:

from rouge_score import rouge_scorer, scoring
import evaluate
from transformers import AutoTokenizer, BartTokenizer

rouge_score = evaluate.load("/home/hd/hd_hd/hd_rk435/evaluate/metrics/rouge")
tokenizer = BartTokenizer.from_pretrained("facebook/bart-large")
generated_summary = "Nearly all the tips useful and. I consider myself an intermediate to advanced user of OneNote."
reference_summary = "Review: Nearly all the tips useful and. I consider myself an intermediate to advanced user of OneNote."

res = rouge_score.compute(predictions=[generated_summary], references=[reference_summary], use_stemmer=True) #, tokenizer=tokenizer)
print(res) 
{'rouge1': 0.9696969696969697, 'rouge2': 0.967741935483871, 'rougeL': 0.9696969696969697, 'rougeLsum': 0.9696969696969697}

Now it works! I’m pretty sure that I’ve tried this combination yesterday.

Anyways thanks again for the fast reply and this great library!

Read more comments on GitHub >

github_iconTop Results From Across the Web

ROUGE - a Hugging Face Space by evaluate-metric
ROUGE, or Recall-Oriented Understudy for Gisting Evaluation, is a set of metrics and a software package used for evaluating automatic summarization and ...
Read more >
can't get ROUGE score with pyrouge - Stack Overflow
This error comes from line 2455 in the ROUGE-1.5.5.pl file. $$score=wlcsWeightInverse($$hit/$$base,$weightFactor);. If some of the test files ...
Read more >
rouge - PyPI
Rouge. A full Python librarie for the ROUGE metric (paper). Disclaimer. This implementation is independant from the "official" ROUGE script (aka.
Read more >
Working with ROUGE 1.5.5 Evaluation Metric in Python - IreneLi
Install Python wrapper. It is natural to choose a Python wrapper, which will help you to calculate ROUGE score form the Perl script....
Read more >
What is the ROUGE metric? - YouTube
The ROUGE metric is often used in summarization tasks, but how is it computed exactly? This video will explain this to you.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found