MCPcopy Create free account
hub / github.com/InternScience/InternAgent / calculate_bleu_scores

Function calculate_bleu_scores

tasks/AutoMem/code/utils.py:50–66  ·  view source on GitHub ↗

Calculate BLEU scores with different n-gram settings.

(prediction: str, reference: str)

Source from the content-addressed store, hash-verified

48 }
49
50def calculate_bleu_scores(prediction: str, reference: str) -> Dict[str, float]:
51 """Calculate BLEU scores with different n-gram settings."""
52 pred_tokens = nltk.word_tokenize(prediction.lower())
53 ref_tokens = [nltk.word_tokenize(reference.lower())]
54
55 weights_list = [(1, 0, 0, 0), (0.5, 0.5, 0, 0), (0.33, 0.33, 0.33, 0), (0.25, 0.25, 0.25, 0.25)]
56 smooth = SmoothingFunction().method1
57
58 scores = {}
59 for n, weights in enumerate(weights_list, start=1):
60 try:
61 score = sentence_bleu(ref_tokens, pred_tokens, weights=weights, smoothing_function=smooth)
62 except Exception:
63 score = 0.0
64 scores[f'bleu{n}'] = score
65
66 return scores
67
68def calculate_bert_scores(prediction: str, reference: str) -> Dict[str, float]:
69 """Calculate BERTScore for semantic similarity."""

Callers 1

calculate_metricsFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected