-
Notifications
You must be signed in to change notification settings - Fork 3
/
evaluate_corpus.py
40 lines (34 loc) · 1.35 KB
/
evaluate_corpus.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
import glob
import os
import eval_metrics
from langid.langid import LanguageIdentifier, model
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--number_of_grams", "-n", type=str, help='enter number of grams', required=True)
args = parser.parse_args()
"""
update the name of model as you saved it before .
"""
arabic_dialect_model = open('Train_pure_corpus_model_'+args.number_of_grams+'_grams/model').read()
identifier = LanguageIdentifier.from_modelstring(arabic_dialect_model, norm_probs=True)
test_dir = 'Test_Pure_corpus/*.test'
test_files = glob.glob(test_dir)
for test in test_files:
base_name, ext = os.path.basename(test).split('.')
lines = open(test).read().splitlines()
prediction_list = list()
y_list = list()
for line in lines:
if line:
dialect, conf = identifier.classify(line)
prediction_list.append(dialect)
y_list.append(base_name)
#print(dialect, base_name)
print('evaluating ', base_name)
accuracy, precision, recall, f_score = eval_metrics.evaluate_acc_PRF(prediction_list, y_list, base_name)
print('accuracy: {}'.format(accuracy))
print(accuracy)
print('precision: {}'.format(precision))
print('recall: {}'.format(recall))
#print('f-score: {}'.format(f_scorsvm.pygrams.pye))
print('-------------------------------------')