Commit f5c9223f authored by Bharath Ramsundar's avatar Bharath Ramsundar
Browse files

Multitask tests

parent 2787af7c
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -61,11 +61,17 @@ class SingletaskToMultitask(Model):
    """
    Concatenates results from all singletask models.
    """
    N_tasks = len(self.tasks)
    n_tasks = len(self.tasks)
    n_samples = X.shape[0]
    y_pred = np.zeros((n_samples, N_tasks))
    y_pred = np.zeros((n_samples, n_tasks))
    for ind, task in enumerate(self.tasks):
      task_type = task_types[task]
      if task_type == "classification":
        y_pred[:, ind] = self.models[task].predict_on_batch(X)[:, 0]
      elif task_type == "regression":
        y_pred[:, ind] = self.models[task].predict_on_batch(X)
      else:
        raise ValueError("Invalid task_type")
    return y_pred

  def predict_proba_on_batch(self, X, n_classes=2):
+6 −1
Original line number Diff line number Diff line
@@ -42,7 +42,12 @@ class SklearnModel(Model):
    Fits SKLearn model to data.
    """
    X, y, w, _ = dataset.to_numpy()
    y, w = y.flatten(), w.flatten()
    y, w = np.squeeze(y), np.squeeze(w)
    ######## DEBUG
    print("SklearnModel.fit()")
    print("X.shape, y.shape, w.shape")
    print(X.shape, y.shape, w.shape)
    ######## DEBUG
    self.raw_model.fit(X, y, w)
    y_pred_raw = self.raw_model.predict(X)

+6 −0
Original line number Diff line number Diff line
@@ -139,6 +139,12 @@ class TensorflowGraph(object):
      gradient_costs = []  # costs used for gradient calculation

      with self._shared_name_scope('costs'):
        ######## DEBUG
        print("self.num_tasks")
        print(self.num_tasks)
        print("len(self.output)")
        print(len(self.output))
        ######## DEBUG
        for task in xrange(self.num_tasks):
          task_str = str(task).zfill(len(str(self.num_tasks)))
          with self._shared_name_scope('cost_{}'.format(task_str)):
+1 −1
Original line number Diff line number Diff line
@@ -136,7 +136,7 @@ class TensorflowMultiTaskClassifier(TensorflowClassifier):
        prev_layer_size = layer_sizes[i]

      self.output = model_ops.MultitaskLogits(
          layer, self.model_params["num_classification_tasks"])
          layer, self.num_tasks)

  def construct_feed_dict(self, X_b, y_b=None, w_b=None, ids_b=None):
    """Construct a feed dictionary from minibatch data.
+7 −0
Original line number Diff line number Diff line
@@ -300,6 +300,13 @@ def MultitaskLogits(features, num_tasks, num_classes=2, weight_init=None,
        logits.append(
            Logits(features, num_classes, weight_init=weight_init,
                   bias_init=bias_init, dropout=dropout))
  ###### DEBUG
  print("MultitaskLogits")
  print("num_tasks")
  print(num_tasks)
  print("len(logits)")
  print(len(logits))
  ###### DEBUG
  return logits


Loading