def train_model(lrmodel, X, Y, devX, devY, devscores, feat_train, feat_dev):
#def train_model(lrmodel, X, Y, devX, devY, devscores):

    """
    Train model, using pearsonr on dev for early stopping
    """
    done = False
    best = -1.0
    r = np.arange(1,6)
    num=0
    #print type(X)

    while not done:
        # Every 100 epochs, check Pearson on development set
        lrmodel.fit([X,feat_train], Y, verbose=2, shuffle=False, nb_epoch =2, validation_data=([devX,feat_dev], devY))
        yhat = np.dot(lrmodel.predict([devX,feat_dev] , verbose=2), r)
        #lrmodel.fit(X, Y, verbose=2, shuffle=False, validation_data=(devX, devY))
        #yhat = np.dot(lrmodel.predict_proba(devX , verbose=2), r)
        
        score = pearsonr(yhat, devscores)[0]
        
        if score > best:
            print score,num
            best = score
            #print type(X)
            bestlrmodel = prepare_model(ninputs=X.shape[1],n_feats=feat_train.shape[1])
            weights = lrmodel.get_weights()
            #print type(weights)
            bestlrmodel.set_weights(weights)
            #print 'thois coe'
            #bst_models.append(lrmodel)
            #lrmodel.save('models\\model')
            #print 'here'
            #num+=1
            
        else:
            done = True   
            
    #bestlrmodel = load_model('models\\model'+str(num))
    
    yhat = np.dot(bestlrmodel.predict([devX,feat_dev], verbose=2), r)
    #yhat = np.dot(bestlrmodel.predict_proba(devX, verbose=2), r)
    score = pearsonr(yhat, devscores)[0]
    print 'Dev Pearson: ' + str(score)
    return bestlrmodel

    Train model, using pearsonr on dev for early stopping
    
fake news challenge (FNC-1)/eval_sick.py