-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
35 lines (28 loc) · 1.05 KB
/
Copy pathmain.py
File metadata and controls
35 lines (28 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from testing import Training, test
import evaluate
model = Training.load_trained_model()
input_file = "en_grth.txt"
output_file = "output_test.txt"
model_file = "Helsinki-NLP/opus-mt-en-de"
test.generate_inference(input_file,output_file,model_file)
# Read the content from prediction.txt and groundtruth.txt
with open("output_test.txt", "r", encoding="utf-8") as f:
prediction = f.readlines()
with open("grth.txt", "r", encoding="utf-8") as f:
groundtruth = f.readlines()
# Tokenize the reference and candidate translations
for i in range(len(prediction)):
prediction[i]=prediction[i]
if prediction[i].endswith("\n"):
prediction[i]=prediction[i].rstrip("\n")
grth=[]
for i in range(len(groundtruth)):
groundtruth[i]=groundtruth[i]
if groundtruth[i].endswith("\n"):
groundtruth[i]=groundtruth[i].rstrip("\n")
grth.append([groundtruth[i]])
# Calculate the BLEU score
bleu = evaluate.load("bleu")
bleu_score = bleu.compute(predictions=prediction, references=grth, smooth=True)
# Print the BLEU score
print("BLEU Score:", bleu_score)