import json | |
import sys | |
import sacrebleu | |
# Check command-line arguments | |
if len(sys.argv) != 2: | |
print("Usage: python script.py <jsonl_file>") | |
sys.exit(1) | |
# Initialize lists to store targets and predictions | |
targets = [] | |
predictions = [] | |
# Read the JSON lines file | |
filename = sys.argv[1] | |
with open(filename, 'r') as f: | |
for line in f: | |
obj = json.loads(line) | |
targets.append(obj['target']) | |
predictions.append(obj['prediction']) | |
# Joining sentences for BLEU score calculation | |
targets_str = ' '.join(targets) | |
predictions_str = ' '.join(predictions) | |
# Calculate BLEU score | |
bleu = sacrebleu.sentence_bleu(predictions_str, [targets_str]) | |
# Print results | |
print(f"BLEU Score: {bleu.score}") | |