Skip to content

Commit 6fb6c16

Browse files
committed
add rouge score tutorial
1 parent eef1f7d commit 6fb6c16

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
6161
- [How to Fine Tune BERT for Semantic Textual Similarity using Transformers in Python](https://www.thepythoncode.com/article/finetune-bert-for-semantic-textual-similarity-in-python). ([code](machine-learning/nlp/semantic-textual-similarity))
6262
- [How to Calculate the BLEU Score in Python](https://www.thepythoncode.com/article/bleu-score-in-python). ([code](machine-learning/nlp/bleu-score))
6363
- [Word Error Rate in Python](https://www.thepythoncode.com/article/calculate-word-error-rate-in-python). ([code](machine-learning/nlp/wer-score))
64+
- [How to Calculate ROUGE Score in Python](https://www.thepythoncode.com/article/calculate-rouge-score-in-python). ([code](machine-learning/nlp/rouge-score))
6465
- ### [Computer Vision](https://www.thepythoncode.com/topic/computer-vision)
6566
- [How to Detect Human Faces in Python using OpenCV](https://www.thepythoncode.com/article/detect-faces-opencv-python). ([code](machine-learning/face_detection))
6667
- [How to Make an Image Classifier in Python using TensorFlow and Keras](https://www.thepythoncode.com/article/image-classification-keras-python). ([code](machine-learning/image-classifier))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# [How to Calculate ROUGE Score in Python](https://www.thepythoncode.com/article/calculate-rouge-score-in-python)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rouge-score
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from rouge_score import rouge_scorer
2+
3+
scorer = rouge_scorer.RougeScorer(['rouge1', 'rouge2', 'rougeL'], use_stemmer=True)
4+
5+
# Single reference
6+
candidate_summary = "the cat was found under the bed"
7+
reference_summary = "the cat was under the bed"
8+
scores = scorer.score(reference_summary, candidate_summary)
9+
for key in scores:
10+
print(f'{key}: {scores[key]}')
11+
12+
# Multiple references
13+
candidate_summary = "the cat was found under the bed"
14+
reference_summaries = ["the cat was under the bed", "found a cat under the bed"]
15+
scores = {key: [] for key in ['rouge1', 'rouge2', 'rougeL']}
16+
for ref in reference_summaries:
17+
temp_scores = scorer.score(ref, candidate_summary)
18+
for key in temp_scores:
19+
scores[key].append(temp_scores[key])
20+
21+
for key in scores:
22+
print(f'{key}:\n{scores[key]}')

0 commit comments

Comments
 (0)