code: 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
  
imports: from __future__ import division
  from __future__ import print_function
  import numpy
  import copy
  from scipy.stats import pearsonr
  from scipy.stats import spearmanr
  from neon.util.argparser import NeonArgparser
  from neon.util.persist import load_obj
  from neon.initializers import Gaussian
  from neon.layers import GeneralizedCost, Affine
  from neon.data import ArrayIterator
  from neon.models import Model
  from neon.optimizers import Adam
  from neon.transforms import Softmax, CrossEntropyMulti
  from neon.callbacks.callbacks import Callbacks
  from neon.data import SICK
  from neon import logger
  from data_iterator import SentenceEncode
  from data_loader import load_data
  from util import load_sent_encoder, tokenize, get_w2v_vocab
label_desc: Use image node_id 4 for calling a global function with example usage: train_model(lrmodel, opt, cost, X, Y, devX, devY, devscores) and returns: bestlrmodel