-
Notifications
You must be signed in to change notification settings - Fork 0
/
eval_spelling.py
46 lines (34 loc) · 869 Bytes
/
eval_spelling.py
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
36
37
38
39
40
41
42
43
44
45
46
from autocorrect import Speller
import evaluate
import json
import random
import time
start = time.time()
spell = Speller(lang='en')
# Opening JSON file and reading model predictions
f = open('generation_output.json')
data = json.load(f)
data.pop(0)
predictions = ""
random.seed = 42
count = 0
for i in data:
if random.random() < 0.99:
continue
count += 1
prompt = i[0]
prediction = i[1]
predictions = predictions + prediction
print('number of predictions to evaluate: ', count)
# Correct spelling
corrected_predictions = spell(predictions)
print('spelling corrected')
# Evaluate spelling
rouge = evaluate.load('rouge')
predictions = [predictions]
references = [corrected_predictions]
print('evaluating')
results = rouge.compute(predictions=predictions, references=references)
print(results)
end = time.time()
print(end - start)