original_docstring: 
          obtains entity pairs and tlink labels from every note passed, and uses them to train the network.
          Arguments:
              notes: timeML files to train on
              epochs: number of training epochs to perform
              training_input: provide processed training matrices directly,
                              instead of rebuilding the matrix from notes every time.
                              Useful for training multipul models with the same data.
                              Formatted as a tuple; (XL, XR, labels)
              weight_classes: whether use class weighting or not
              batch_size: size of training batches to use
              max_len: either an integer specifying the maximum input sequence length, or 'auto',
                      which infer maximum length from the training data
              All other parameters feed directly into get_untrained_model(), and are described there.
          
docstring: obtains entity pairs and tlink labels from every note passed, and uses them to train the network.
  Arguments:
  notes: timeML files to train on
  epochs: number of training epochs to perform
  training_input: provide processed training matrices directly,
  instead of rebuilding the matrix from notes every time.
  Useful for training multipul models with the same data.
  Formatted as a tuple; (XL, XR, labels)
  weight_classes: whether use class weighting or not
  batch_size: size of training batches to use
  max_len: either an integer specifying the maximum input sequence length, or 'auto',
  which infer maximum length from the training data
  All other parameters feed directly into get_untrained_model(), and are described there.
docstring_tokens: obtains entity pairs and tlink labels from every note passed and uses them to train the network . Arguments : notes : timeML files to train on epochs : number of training epochs to perform training_input : provide processed training matrices directly instead of rebuilding the matrix from notes every time . Useful for training multipul models with the same data . Formatted as a tuple ; ( XL XR labels ) weight_classes : whether use class weighting or not batch_size : size of training batches to use max_len : either an integer specifying the maximum input sequence length or ' auto ' which infer maximum length from the training data All other parameters feed directly into get_untrained_model () and are described there .
code: def train_model(self, notes, epochs=5, training_input=None, val_input=None, no_val=False, weight_classes=False, batch_size=256,
          encoder_dropout=0, decoder_dropout=0, input_dropout=0, reg_W=0, reg_B=0, reg_act=0, LSTM_size=32, dense_size=100,
          maxpooling=True, data_dim=300, max_len='auto', nb_classes=13, callbacks=[], ordered=False):
          '''
          obtains entity pairs and tlink labels from every note passed, and uses them to train the network.
          Arguments:
              notes: timeML files to train on
              epochs: number of training epochs to perform
              training_input: provide processed training matrices directly,
                              instead of rebuilding the matrix from notes every time.
                              Useful for training multipul models with the same data.
                              Formatted as a tuple; (XL, XR, labels)
              weight_classes: whether use class weighting or not
              batch_size: size of training batches to use
              max_len: either an integer specifying the maximum input sequence length, or 'auto',
                      which infer maximum length from the training data
              All other parameters feed directly into get_untrained_model(), and are described there.
          '''
          if training_input == None:
              XL, XR, labels = self._get_training_input(notes)
          else:
              XL, XR, labels = training_input
  
          # reformat labels so that they can be used by the NN
          Y = to_categorical(labels,nb_classes)
  
          # use weighting to assist with the imbalanced data set problem
          if weight_classes:
              class_weights = self.get_uniform_class_weights(Y)
          else:
              class_weights = None
  
          # infer maximum sequence length
          if max_len == 'auto':
              max_len = XL.shape[2]
          # pad input to reach max_len
          else:
              filler = np.ones((1,1,max_len))
              XL, _ = Network._pad_to_match_dimensions(XL, filler, 2, pad_left=True)
              XR, _ = Network._pad_to_match_dimensions(XR, filler, 2, pad_left=True)
  
          model = self.get_untrained_model(encoder_dropout=encoder_dropout, decoder_dropout=decoder_dropout,
                                           input_dropout=input_dropout, reg_W=reg_W, reg_B=reg_B, reg_act=reg_act,
                                           LSTM_size=LSTM_size, dense_size=dense_size,
                                           maxpooling=maxpooling, data_dim=data_dim, max_len=max_len, nb_classes=nb_classes)
  
          # train the network
          print 'Training network...'
          if no_val:
              validation_split = 0.0
              validation_data = None
          elif val_input is None:
              # split off validation data with 20 80 split
              # this way we get the same validation data every time
              V_XL = XL[:(XL.shape[0]/5),:,:]
              V_XR = XR[:(XR.shape[0]/5),:,:]
              V_Y  = Y [:( Y.shape[0]/5),:]
              V_labels = labels[:(Y.shape[0]/5)]
  
              XL = XL[(XL.shape[0]/5):,:,:]
              XR = XR[(XR.shape[0]/5):,:,:]
              Y  = Y [( Y.shape[0]/5):,:]
  
              validation_split = 0.2
              validation_data = ([V_XL, V_XR], V_Y)
          else:
              validation_split = 0 # will be overwritten by val data
              V_XL, V_XR, V_labels, V_pair_index = val_input
              V_Y = to_categorical(V_labels, nb_classes)
              filler = np.ones((1, 1, max_len))
              V_XL, _ = Network._pad_to_match_dimensions(V_XL, filler, 2, pad_left=True)
              V_XR, _ = Network._pad_to_match_dimensions(V_XR, filler, 2, pad_left=True)
              validation_data = ([V_XL, V_XR], V_Y)
  
          training_history = model.fit([XL, XR], Y, nb_epoch=epochs, validation_split=validation_split, class_weight=class_weights,
                                           batch_size=batch_size, validation_data=validation_data, callbacks=callbacks)
  
          test = model.predict_classes([V_XL, V_XR])
          Network.class_confusion(test, V_labels, nb_classes)
  
          if val_input is not None and not ordered:
              try:
                  print "Trying smart predict..."
                  probs = model.predict_proba([V_XL, V_XR])
                  smart_test, pair_index = self.smart_predict(test, probs, V_pair_index, type='int')
                  Network.class_confusion(smart_test, V_labels, nb_classes)
              except KeyError:
                  print "cannot perform smart predicting"
  
          return model, training_history.history
code_tokens: def train_model ( self , notes , epochs = 5 , training_input = None , val_input = None , no_val = False , weight_classes = False , batch_size = 256 , encoder_dropout = 0 , decoder_dropout = 0 , input_dropout = 0 , reg_W = 0 , reg_B = 0 , reg_act = 0 , LSTM_size = 32 , dense_size = 100 , maxpooling = True , data_dim = 300 , max_len = 'auto' , nb_classes = 13 , callbacks = [ ] , ordered = False ) : if training_input == None : XL , XR , labels = self . _get_training_input ( notes ) else : XL , XR , labels = training_input Y = to_categorical ( labels , nb_classes ) if weight_classes : class_weights = self . get_uniform_class_weights ( Y ) else : class_weights = None if max_len == 'auto' : max_len = XL . shape [ 2 ] else : filler = np . ones ( ( 1 , 1 , max_len ) ) XL , _ = Network . _pad_to_match_dimensions ( XL , filler , 2 , pad_left = True ) XR , _ = Network . _pad_to_match_dimensions ( XR , filler , 2 , pad_left = True ) model = self . get_untrained_model ( encoder_dropout = encoder_dropout , decoder_dropout = decoder_dropout , input_dropout = input_dropout , reg_W = reg_W , reg_B = reg_B , reg_act = reg_act , LSTM_size = LSTM_size , dense_size = dense_size , maxpooling = maxpooling , data_dim = data_dim , max_len = max_len , nb_classes = nb_classes ) print 'Training network...' if no_val : validation_split = 0.0 validation_data = None elif val_input is None : V_XL = XL [ : ( XL . shape [ 0 ] / 5 ) , : , : ] V_XR = XR [ : ( XR . shape [ 0 ] / 5 ) , : , : ] V_Y = Y [ : ( Y . shape [ 0 ] / 5 ) , : ] V_labels = labels [ : ( Y . shape [ 0 ] / 5 ) ] XL = XL [ ( XL . shape [ 0 ] / 5 ) : , : , : ] XR = XR [ ( XR . shape [ 0 ] / 5 ) : , : , : ] Y = Y [ ( Y . shape [ 0 ] / 5 ) : , : ] validation_split = 0.2 validation_data = ( [ V_XL , V_XR ] , V_Y ) else : validation_split = 0 V_XL , V_XR , V_labels , V_pair_index = val_input V_Y = to_categorical ( V_labels , nb_classes ) filler = np . ones ( ( 1 , 1 , max_len ) ) V_XL , _ = Network . _pad_to_match_dimensions ( V_XL , filler , 2 , pad_left = True ) V_XR , _ = Network . _pad_to_match_dimensions ( V_XR , filler , 2 , pad_left = True ) validation_data = ( [ V_XL , V_XR ] , V_Y ) training_history = model . fit ( [ XL , XR ] , Y , nb_epoch = epochs , validation_split = validation_split , class_weight = class_weights , batch_size = batch_size , validation_data = validation_data , callbacks = callbacks ) test = model . predict_classes ( [ V_XL , V_XR ] ) Network . class_confusion ( test , V_labels , nb_classes ) if val_input is not None and not ordered : try : print "Trying smart predict..." probs = model . predict_proba ( [ V_XL , V_XR ] ) smart_test , pair_index = self . smart_predict ( test , probs , V_pair_index , type = 'int' ) Network . class_confusion ( smart_test , V_labels , nb_classes ) except KeyError : print "cannot perform smart predicting" return model , training_history . history
short_docstring: obtains entity pairs and tlink labels from every note passed, and uses them to train the network.
short_docstring_tokens: obtains entity pairs and tlink labels from every note passed and uses them to train the network .
comment: '''
          obtains entity pairs and tlink labels from every note passed, and uses them to train the network.
          Arguments:
              notes: timeML files to train on
              epochs: number of training epochs to perform
              training_input: provide processed training matrices directly,
                              instead of rebuilding the matrix from notes every time.
                              Useful for training multipul models with the same data.
                              Formatted as a tuple; (XL, XR, labels)
              weight_classes: whether use class weighting or not
              batch_size: size of training batches to use
              max_len: either an integer specifying the maximum input sequence length, or 'auto',
                      which infer maximum length from the training data
              All other parameters feed directly into get_untrained_model(), and are described there.
          '''$SEP$# reformat labels so that they can be used by the NN$SEP$# use weighting to assist with the imbalanced data set problem$SEP$# infer maximum sequence length$SEP$# pad input to reach max_len$SEP$# train the network$SEP$# split off validation data with 20 80 split$SEP$# this way we get the same validation data every time$SEP$# will be overwritten by val data