#!/usr/bin/env python

from signal import signal, SIGPIPE, SIG_DFL
signal(SIGPIPE, SIG_DFL)

import argparse
import sys
from gensim.models.word2vec import Word2Vec
import csv

parser = argparse.ArgumentParser()
parser.add_argument('--sim', nargs='?', type=float, default=.3)
parser.add_argument('w2v')
args = vars(parser.parse_args())

w2v = Word2Vec.load_word2vec_format(args['w2v'], binary=True, unicode_errors='ignore')
w2v.init_sims(replace=True)
print('Using %d word2vec dimensions from "%s".' % (w2v.layer1_size, sys.argv[1]), file=sys.stderr)

reader = csv.reader(sys.stdin, delimiter='\t', quoting=csv.QUOTE_NONE)

for row in reader:
    word1, word2 = row[0], row[1]

    try:
        similarity = w2v.similarity(word1, word2)
    except KeyError:
        similarity = args['sim']

    print('%s\t%s\t%f' % (word1, word2, similarity))

@@ -728,16 +728,81 @@
 , word2)
+%0A%0A        if similarity %3C 0:%0A            similarity = args%5B'sim'%5D
 %0A    exc

Add a negative similarity crutch