Skip to content

Commit

Permalink
fare comparison of similarity (test github with my new ubuntu)
Browse files Browse the repository at this point in the history
  • Loading branch information
libofang committed Feb 9, 2018
1 parent 2b5d670 commit 02ab1fd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion vsmlib/benchmarks/similarity/similarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import vsmlib
from scipy.stats.stats import spearmanr
import os
import random

def read_test_set(path):
test = []
Expand All @@ -22,12 +23,15 @@ def read_test_set(path):
def evaluate(m, data):
results = []
for (x, y), sim in data:
x = x.lower()
y = y.lower()
# print(x,y)
if m.has_word(x) and m.has_word(y):
# print(m.get_row(x).dot(m.get_row(y)))
results.append((m.get_row(x).dot(m.get_row(y)), sim))
else:
pass
results.append((-1, sim))
# results.append((0, sim))
actual, expected = zip(*results)
return spearmanr(actual, expected)[0]

Expand Down Expand Up @@ -84,8 +88,10 @@ def main(args=None):
if args.path_dataset is not None:
options["path_dataset"] = args.path_dataset


# get the embeddings
m = vsmlib.model.load_from_dir(options['path_vector'])

if options["normalize"]:
# m.clip_negatives() #make this configurable
m.normalize()
Expand Down

0 comments on commit 02ab1fd

Please sign in to comment.