-
Notifications
You must be signed in to change notification settings - Fork 14
/
evaluation.py
executable file
·30 lines (22 loc) · 1.06 KB
/
evaluation.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
#!/usr/bin/python3
# coding: utf-8
import gensim
import logging
import sys
from evaluate_lemmas import evaluate_synsets
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
logger = logging.getLogger(__name__)
# Loading model and semantic similarity dataset
modelfile, wordnet_scores, static_scores = sys.argv[1:]
model = gensim.models.KeyedVectors.load_word2vec_format(modelfile, binary=False)
# Pre-calculating vector norms
model.init_sims(replace=True)
wordnet_synset_score = model.evaluate_word_pairs(wordnet_scores, dummy4unknown=True)
static_synset_score = model.evaluate_word_pairs(static_scores, dummy4unknown=True)
dynamic_synset_score = evaluate_synsets(model, 'simlex/simlex_original.tsv', logger,
dummy4unknown=True)
name = modelfile.replace('_embeddings_', '_')[:-7]
print('Model\tWordnet\tStatic\tDynamic')
print(name + '\t' + str(round(wordnet_synset_score[1][0], 4)) + '\t'
+ str(round(static_synset_score[1][0], 4)) + '\t'
+ str(round(dynamic_synset_score[1][0], 4)))