def train_regressor(orig_wordvecs, w2v_W, w2v_vocab):
 d = defaultdict((lambda : 0))
 for w in w2v_vocab.keys():
  d[w] = 1
 shared = OrderedDict()
 count = 0
 for w in list(orig_wordvecs.keys())[:(-2)]:
  if (d[w] > 0):
   shared[w] = count
   count += 1
 w2v = np.zeros((len(shared), 300), dtype='float32')
 sg = np.zeros((len(shared), 620), dtype='float32')
 for w in shared.keys():
  w2v[shared[w]] = w2v_W[w2v_vocab[w]]
  sg[shared[w]] = orig_wordvecs[w]
 train_set = ArrayIterator(X=w2v, y=sg, make_onehot=False)
 layers = [Linear(nout=620, init=Gaussian(loc=0.0, scale=0.1)), Bias(init=Constant(0.0))]
 clf = Model(layers=layers)
 cost = GeneralizedCost(costfunc=SumSquared())
 opt = GradientDescentMomentum(0.1, 0.9, gradient_clip_value=5.0)
 callbacks = Callbacks(clf)
 clf.fit(train_set, num_epochs=20, optimizer=opt, cost=cost, callbacks=callbacks)
 return clf

def train_regressor ( orig_wordvecs , w2v_W , w2v_vocab ) : d = defaultdict ( ( lambda : 0 ) ) for w in w2v_vocab . keys ( ) : d [ w ] = 1 shared = OrderedDict ( ) count = 0 for w in list ( orig_wordvecs . keys ( ) ) [ : ( - 2 ) ] : if ( d [ w ] > 0 ) : shared [ w ] = count count += 1 w2v = np . zeros ( ( len ( shared ) , 300 ) , dtype = 'float32' ) sg = np . zeros ( ( len ( shared ) , 620 ) , dtype = 'float32' ) for w in shared . keys ( ) : w2v [ shared [ w ] ] = w2v_W [ w2v_vocab [ w ] ] sg [ shared [ w ] ] = orig_wordvecs [ w ] train_set = ArrayIterator ( X = w2v , y = sg , make_onehot = False ) layers = [ Linear ( nout = 620 , init = Gaussian ( loc = 0.0 , scale = 0.1 ) ) , Bias ( init = Constant ( 0.0 ) ) ] clf = Model ( layers = layers ) cost = GeneralizedCost ( costfunc = SumSquared ( ) ) opt = GradientDescentMomentum ( 0.1 , 0.9 , gradient_clip_value = 5.0 ) callbacks = Callbacks ( clf ) clf . fit ( train_set , num_epochs = 20 , optimizer = opt , cost = cost , callbacks = callbacks ) return clf
return regressor to map word2vec to rnn word space .