code: def train(
      nonlinearity,
      num_hidden_layers,
      device_id,
      minibatch_size=10,
      num_samples=1000,
  ):
      from cntk.cntk_py import always_allow_setting_default_device
  
      always_allow_setting_default_device()
      C.try_set_default_device(cntk_device(device_id))
      np.random.seed(0)
  
      learning_rate = 0.5
      lr_schedule = C.learning_parameter_schedule(learning_rate)
  
      hidden_layers_dim = 50
  
      inp = C.input_variable((input_dim), np.float32)
      label = C.input_variable((num_output_classes), np.float32)
  
      z = fully_connected_classifier_net(
          inp,
          num_output_classes,
          hidden_layers_dim,
          num_hidden_layers,
          nonlinearity,
      )
  
      loss = C.cross_entropy_with_softmax(z, label)
      eval_error = C.classification_error(z, label)
  
      learner = C.sgd(z.parameters, lr_schedule, minibatch_size=0)
      trainer = C.Trainer(z, (loss, eval_error), [learner])
  
      num_minibatches_to_train = int(num_samples / minibatch_size)
  
      training_progress_output_freq = 20
  
      losses = []
      errors = []
  
      for i in range(num_minibatches_to_train):
          features, labels = generate_random_data_sample(
              minibatch_size, input_dim, num_output_classes
          )
  
          # Specify the input variables mapping in the model to actual minibatch
          # data for training.
          trainer.train_minibatch(
              {inp: features, label: labels},
              device=cntk_device(device_id),
          )
  
          batchsize, loss, error = print_training_progress(
              trainer, i, training_progress_output_freq
          )
  
          if not (loss == "NA" or error == "NA"):
              losses.append(loss)
              errors.append(error)
  
      return losses, errors
  
imports: from __future__ import division, print_function
  import numpy
  import cntk
  from cntk.ops.tests.ops_test_utils import cntk_device, mem_used, os_process
  from cntk.ops.functions import UserFunction
  from cntk import sigmoid
label_desc: Use image node_id 6 for calling a global function with example usage: train(nonlinearity, num_hidden_layers, device_id, minibatch_size, num_samples) and returns: losses,  errors