(orig_wordvecs, w2v_W, w2v_vocab)
return clf
Return regressor to map word2vec to RNN word space

    Function modified from:
    https://github.com/ryankiros/skip-thoughts/blob/master/training/tools.py
Return regressor to map word2vec to RNN word space
Return regressor to map word2vec to RNN word space
def train_regressor(orig_wordvecs, w2v_W, w2v_vocab):
    """
    Return regressor to map word2vec to RNN word space

    Function modified from:
    https://github.com/ryankiros/skip-thoughts/blob/master/training/tools.py
    """
    # Gather all words from word2vec that appear in wordvecs
    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

    # Get the vectors for all words in 'shared'
    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)

    # regression model is trained using default global batch size
    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 ) : # Gather all words from word2vec that appear in wordvecs 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 # Get the vectors for all words in 'shared' 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 ) # regression model is trained using default global batch size 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