Commit 17ef7c7e authored by Toby Boyd's avatar Toby Boyd
Browse files

Merge branch 'master' of github.com:tensorflow/models

parents 8008e72f a380b4b3
...@@ -34,6 +34,7 @@ the scored human judgement. ...@@ -34,6 +34,7 @@ the scored human judgement.
""" """
from __future__ import print_function
import scipy.stats import scipy.stats
import sys import sys
from getopt import GetoptError, getopt from getopt import GetoptError, getopt
...@@ -42,8 +43,8 @@ from vecs import Vecs ...@@ -42,8 +43,8 @@ from vecs import Vecs
try: try:
opts, args = getopt(sys.argv[1:], '', ['embeddings=', 'vocab=']) opts, args = getopt(sys.argv[1:], '', ['embeddings=', 'vocab='])
except GetoptError, e: except GetoptError as e:
print >> sys.stderr, e print(e, file=sys.stderr)
sys.exit(2) sys.exit(2)
opt_embeddings = None opt_embeddings = None
...@@ -56,19 +57,20 @@ for o, a in opts: ...@@ -56,19 +57,20 @@ for o, a in opts:
opt_vocab = a opt_vocab = a
if not opt_vocab: if not opt_vocab:
print >> sys.stderr, 'please specify a vocabulary file with "--vocab"' print('please specify a vocabulary file with "--vocab"', file=sys.stderr)
sys.exit(2) sys.exit(2)
if not opt_embeddings: if not opt_embeddings:
print >> sys.stderr, 'please specify the embeddings with "--embeddings"' print('please specify the embeddings with "--embeddings"', file=sys.stderr)
sys.exit(2) sys.exit(2)
try: try:
vecs = Vecs(opt_vocab, opt_embeddings) vecs = Vecs(opt_vocab, opt_embeddings)
except IOError, e: except IOError as e:
print >> sys.stderr, e print(e, file=sys.stderr)
sys.exit(1) sys.exit(1)
def evaluate(lines): def evaluate(lines):
acts, preds = [], [] acts, preds = [], []
...@@ -85,6 +87,7 @@ def evaluate(lines): ...@@ -85,6 +87,7 @@ def evaluate(lines):
rho, _ = scipy.stats.spearmanr(acts, preds) rho, _ = scipy.stats.spearmanr(acts, preds)
return rho return rho
for filename in args: for filename in args:
with open(filename, 'r') as lines: with open(filename, 'r') as lines:
print '%0.3f %s' % (evaluate(lines), filename) print('%0.3f %s' % (evaluate(lines), filename))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment