Initialize Rouge object rouge = Rouge() Check for empty lists or mismatched lengths if…
- User
Initialize Rouge object
rouge = Rouge()
Check for empty lists or mismatched lengths
if not reference_questions or not generated_questions or len(reference_questions) != len(generated_questions): print("Error: Reference questions or generated questions have mismatched lengths or are empty.") else: try: # Calculate ROUGE scores scores = rouge.get_scores(generated_questions, reference_questions)
code# Check if scores are available if scores: # Access ROUGE-L F1 scores (other metrics like ROUGE-N are also available) rouge_l_scores = [score["rouge-l"]["f"] for score in scores] print("ROUGE-L F1 Scores:", rouge_l_scores) else: print("Warning: ROUGE scores could not be computed.") except Exception as e: print(f"Error during ROUGE score calculation: {e}") - Assistant
- User
another way #!pip install --upgrade rouge-score #!pip uninstall rouge-score #!pip install rouge-score !pip install rouge huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks... To disable this warning, you can either: - Avoid using before the fork if possible - Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false) Collecting rouge Downloading rouge-1.0.1-py3-none-any.whl.metadata (4.1 kB) Requirement already satisfied: six in /opt/conda/lib/python3.10/site-packages (from rouge) (1.16.0) Downloading rouge-1.0.1-py3-none-any.whl (13 kB) Installing collected packages: rouge Successfully installed rouge-1.0.1 add Codeadd Markdown import rouge
- Assistant