(lrmodel, opt, cost, X, Y, devX, devY, devscores)
return bestlrmodel
Train model, using pearsonr on dev for early stopping
Train model, using pearsonr on dev for early stopping
Train model using pearsonr on dev for early stopping
def train_model(lrmodel, opt, cost, X, Y, devX, devY, devscores):
    """
    Train model, using pearsonr on dev for early stopping
    """
    done = False
    best = -1.0
    r = np.arange(1, 6)

    train_set = ArrayIterator(X=X, y=Y, make_onehot=False)
    valid_set = ArrayIterator(X=devX, y=devY, make_onehot=False)

    eval_epoch = 10

    while not done:
        callbacks = Callbacks(lrmodel, eval_set=valid_set)

        lrmodel.fit(train_set, optimizer=opt, num_epochs=eval_epoch,
                    cost=cost, callbacks=callbacks)

        # Every 10 epochs, check Pearson on development set
        yhat = np.dot(lrmodel.get_outputs(valid_set), r)
        score = pearsonr(yhat, devscores)[0]
        if score > best:
            neon_logger.display('Dev Pearson: {}'.format(score))
            best = score
            bestlrmodel = copy.copy(lrmodel)
        else:
            done = True

        eval_epoch += 10

    yhat = np.dot(bestlrmodel.get_outputs(valid_set), r)
    score = pearsonr(yhat, devscores)[0]
    neon_logger.display('Dev Pearson: {}'.format(score))
    return bestlrmodel
def train_model ( lrmodel , opt , cost , X , Y , devX , devY , devscores ) : done = False best = - 1.0 r = np . arange ( 1 , 6 ) train_set = ArrayIterator ( X = X , y = Y , make_onehot = False ) valid_set = ArrayIterator ( X = devX , y = devY , make_onehot = False ) eval_epoch = 10 while not done : callbacks = Callbacks ( lrmodel , eval_set = valid_set ) lrmodel . fit ( train_set , optimizer = opt , num_epochs = eval_epoch , cost = cost , callbacks = callbacks ) # Every 10 epochs, check Pearson on development set yhat = np . dot ( lrmodel . get_outputs ( valid_set ) , r ) score = pearsonr ( yhat , devscores ) [ 0 ] if score > best : neon_logger . display ( 'Dev Pearson: {}' . format ( score ) ) best = score bestlrmodel = copy . copy ( lrmodel ) else : done = True eval_epoch += 10 yhat = np . dot ( bestlrmodel . get_outputs ( valid_set ) , r ) score = pearsonr ( yhat , devscores ) [ 0 ] neon_logger . display ( 'Dev Pearson: {}' . format ( score ) ) return bestlrmodel