Skip to content

Commit 43daedc

Browse files
chore(generative_ai): clean up & update code samples (#12754)
1 parent 710a08e commit 43daedc

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

generative_ai/evaluation/get_rouge_score.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,6 @@ def get_rouge_score() -> EvalResult:
2929
# PROJECT_ID = "your-project-id"
3030
vertexai.init(project=PROJECT_ID, location="us-central1")
3131

32-
text_to_summarize = """
33-
The Great Barrier Reef, located off the coast of Queensland in northeastern
34-
Australia, is the world's largest coral reef system. Stretching over 2,300
35-
kilometers, it is composed of over 2,900 individual reefs and 900 islands.
36-
The reef is home to a wide variety of marine life, including many endangered
37-
species. However, climate change, ocean acidification, and coral bleaching
38-
pose significant threats to its ecosystem."""
39-
40-
prompt = f"Summarize the following text:\n\n{text_to_summarize}"
41-
4232
reference_summarization = """
4333
The Great Barrier Reef, the world's largest coral reef system, is
4434
located off the coast of Queensland, Australia. It's a vast
@@ -47,11 +37,9 @@ def get_rouge_score() -> EvalResult:
4737
life, including endangered species, it faces serious threats from
4838
climate change, ocean acidification, and coral bleaching."""
4939

50-
# Use pre-generated model responses to compare different summarization outputs
51-
# against a consistent reference.
40+
# Compare pre-generated model responses against the reference (ground truth).
5241
eval_dataset = pd.DataFrame(
5342
{
54-
"prompt": [prompt] * 3,
5543
"response": [
5644
"""The Great Barrier Reef, the world's largest coral reef system located
5745
in Australia, is a vast and diverse ecosystem. However, it faces serious
@@ -71,7 +59,6 @@ def get_rouge_score() -> EvalResult:
7159
"reference": [reference_summarization] * 3,
7260
}
7361
)
74-
7562
eval_task = EvalTask(
7663
dataset=eval_dataset,
7764
metrics=[
@@ -84,17 +71,26 @@ def get_rouge_score() -> EvalResult:
8471
result = eval_task.evaluate()
8572

8673
print("Summary Metrics:\n")
87-
8874
for key, value in result.summary_metrics.items():
8975
print(f"{key}: \t{value}")
9076

9177
print("\n\nMetrics Table:\n")
9278
print(result.metrics_table)
9379
# Example response:
94-
# prompt ... rouge_1/score rouge_2/score ...
95-
# 0 Summarize the following text:\n\n\n ... 0.659794 0.484211 ...
96-
# 1 Summarize the following text:\n\n\n ... 0.704762 0.524272 ...
80+
#
81+
# Summary Metrics:
82+
#
83+
# row_count: 3
84+
# rouge_1/mean: 0.7191161666666667
85+
# rouge_1/std: 0.06765143922270488
86+
# rouge_2/mean: 0.5441118566666666
9787
# ...
88+
# Metrics Table:
89+
#
90+
# response reference ... rouge_l/score rouge_l_sum/score
91+
# 0 The Great Barrier Reef, the world's ... \n The Great Barrier Reef, the ... ... 0.577320 0.639175
92+
# 1 The Great Barrier Reef, a vast coral... \n The Great Barrier Reef, the ... ... 0.552381 0.666667
93+
# 2 The Great Barrier Reef, the world's ... \n The Great Barrier Reef, the ... ... 0.774775 0.774775
9894
# [END generativeaionvertexai_evaluation_get_rouge_score]
9995
return result
10096

0 commit comments

Comments
 (0)