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

yapfed

parents 3197649d 2b16a6c1
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -91,8 +91,8 @@ class TensorflowMultiTaskIRVClassifier(TensorflowLogisticRegression):
       
       https://www.ncbi.nlm.nih.gov/pmc/articles/PMC2750043/
    """
    placeholder_scope = TensorflowGraph.get_placeholder_scope(graph,
                                                              name_scopes)
    placeholder_scope = TensorflowGraph.get_placeholder_scope(
        graph, name_scopes)
    K = self.K
    with graph.as_default():
      output = []
@@ -106,8 +106,8 @@ class TensorflowMultiTaskIRVClassifier(TensorflowLogisticRegression):
        b2 = tf.Variable(tf.constant([0.01]), name="b2", dtype=tf.float32)

      label_placeholders = self.add_label_placeholders(graph, name_scopes)
      weight_placeholders = self.add_example_weight_placeholders(graph,
                                                                 name_scopes)
      weight_placeholders = self.add_example_weight_placeholders(
          graph, name_scopes)
      if training:
        graph.queue = tf.FIFOQueue(
            capacity=5,
+2 −4
Original line number Diff line number Diff line
@@ -52,8 +52,7 @@ class TensorflowGraph(object):
  def __init__(self, graph, session, name_scopes, output, labels, weights,
               loss):
    warnings.warn("TensorflowGraph is deprecated. "
                  "Will be removed in DeepChem 1.4.",
                  DeprecationWarning)
                  "Will be removed in DeepChem 1.4.", DeprecationWarning)
    self.graph = graph
    self.session = session
    self.name_scopes = name_scopes
@@ -180,8 +179,7 @@ class TensorflowGraphModel(Model):
      If not none, is used as random seed for tensorflow.
    """
    warnings.warn("TensorflowGraphModel is deprecated. "
                  "Will be removed in DeepChem 1.4.",
                  DeprecationWarning)
                  "Will be removed in DeepChem 1.4.", DeprecationWarning)

    # Save hyperparameters
    self.n_tasks = n_tasks
+72 −37
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ import time
import numpy as np
import tensorflow as tf
import threading
import collections

import deepchem as dc
from deepchem.nn import model_ops
@@ -29,11 +30,12 @@ class TensorGraphMultiTaskClassifier(TensorGraph):
               n_tasks,
               n_features,
               layer_sizes=[1000],
               weight_init_stddevs=[0.02],
               bias_init_consts=[1.0],
               weight_init_stddevs=0.02,
               bias_init_consts=1.0,
               weight_decay_penalty=0.0,
               weight_decay_penalty_type="l2",
               dropouts=[0.5],
               dropouts=0.5,
               activation_fns=tf.nn.relu,
               n_classes=2,
               **kwargs):
    """Create a TensorGraphMultiTaskClassifier.
@@ -49,17 +51,24 @@ class TensorGraphMultiTaskClassifier(TensorGraph):
      number of features
    layer_sizes: list
      the size of each dense layer in the network.  The length of this list determines the number of layers.
    weight_init_stddevs: list
    weight_init_stddevs: list or float
      the standard deviation of the distribution to use for weight initialization of each layer.  The length
      of this list should equal len(layer_sizes).
    bias_init_consts: list
      of this list should equal len(layer_sizes).  Alternatively this may be a single value instead of a list,
      in which case the same value is used for every layer.
    bias_init_consts: list or loat
      the value to initialize the biases in each layer to.  The length of this list should equal len(layer_sizes).
      Alternatively this may be a single value instead of a list, in which case the same value is used for every layer.
    weight_decay_penalty: float
      the magnitude of the weight decay penalty to use
    weight_decay_penalty_type: str
      the type of penalty to use for weight decay, either 'l1' or 'l2'
    dropouts: list
    dropouts: list or float
      the dropout probablity to use for each layer.  The length of this list should equal len(layer_sizes).
      Alternatively this may be a single value instead of a list, in which case the same value is used for every layer.
    activation_fns: list or object
      the Tensorflow activation function to apply to each layer.  The length of this list should equal
      len(layer_sizes).  Alternatively this may be a single value instead of a list, in which case the
      same value is used for every layer.
    n_classes: int
      the number of classes
    """
@@ -68,6 +77,15 @@ class TensorGraphMultiTaskClassifier(TensorGraph):
    self.n_tasks = n_tasks
    self.n_features = n_features
    self.n_classes = n_classes
    n_layers = len(layer_sizes)
    if not isinstance(weight_init_stddevs, collections.Sequence):
      weight_init_stddevs = [weight_init_stddevs] * n_layers
    if not isinstance(bias_init_consts, collections.Sequence):
      bias_init_consts = [bias_init_consts] * n_layers
    if not isinstance(dropouts, collections.Sequence):
      dropouts = [dropouts] * n_layers
    if not isinstance(activation_fns, collections.Sequence):
      activation_fns = [activation_fns] * n_layers

    # Add the input features.

@@ -76,12 +94,13 @@ class TensorGraphMultiTaskClassifier(TensorGraph):

    # Add the dense layers

    for size, weight_stddev, bias_const, dropout in zip(
        layer_sizes, weight_init_stddevs, bias_init_consts, dropouts):
    for size, weight_stddev, bias_const, dropout, activation_fn in zip(
        layer_sizes, weight_init_stddevs, bias_init_consts, dropouts,
        activation_fns):
      layer = Dense(
          in_layers=[prev_layer],
          out_channels=size,
          activation_fn=tf.nn.relu,
          activation_fn=activation_fn,
          weights_initializer=TFWrapper(
              tf.truncated_normal_initializer, stddev=weight_stddev),
          biases_initializer=TFWrapper(
@@ -121,8 +140,9 @@ class TensorGraphMultiTaskClassifier(TensorGraph):
          pad_batches=pad_batches):
        feed_dict = dict()
        if y_b is not None and not predict:
          feed_dict[self.labels[0]] = to_one_hot(
              y_b.flatten(), self.n_classes).reshape(-1, self.n_tasks,
          feed_dict[self.labels[0]] = to_one_hot(y_b.flatten(),
                                                 self.n_classes).reshape(
                                                     -1, self.n_tasks,
                                                     self.n_classes)
        if X_b is not None:
          feed_dict[self.features[0]] = X_b
@@ -137,11 +157,12 @@ class TensorGraphMultiTaskRegressor(TensorGraph):
               n_tasks,
               n_features,
               layer_sizes=[1000],
               weight_init_stddevs=[0.02, 0.02],
               bias_init_consts=[1.0, 1.0],
               weight_init_stddevs=0.02,
               bias_init_consts=1.0,
               weight_decay_penalty=0.0,
               weight_decay_penalty_type="l2",
               dropouts=[0.5],
               dropouts=0.5,
               activation_fns=tf.nn.relu,
               **kwargs):
    """Create a TensorGraphMultiTaskRegressor.

@@ -156,23 +177,39 @@ class TensorGraphMultiTaskRegressor(TensorGraph):
      number of features
    layer_sizes: list
      the size of each dense layer in the network.  The length of this list determines the number of layers.
    weight_init_stddevs: list
    weight_init_stddevs: list or float
      the standard deviation of the distribution to use for weight initialization of each layer.  The length
      of this list should equal len(layer_sizes)+1.  The final element corresponds to the output layer.
    bias_init_consts: list
      Alternatively this may be a single value instead of a list, in which case the same value is used for every layer.
    bias_init_consts: list or float
      the value to initialize the biases in each layer to.  The length of this list should equal len(layer_sizes)+1.
      The final element corresponds to the output layer.
      The final element corresponds to the output layer.  Alternatively this may be a single value instead of a list,
      in which case the same value is used for every layer.
    weight_decay_penalty: float
      the magnitude of the weight decay penalty to use
    weight_decay_penalty_type: str
      the type of penalty to use for weight decay, either 'l1' or 'l2'
    dropouts: list
    dropouts: list or float
      the dropout probablity to use for each layer.  The length of this list should equal len(layer_sizes).
      Alternatively this may be a single value instead of a list, in which case the same value is used for every layer.
    activation_fns: list or object
      the Tensorflow activation function to apply to each layer.  The length of this list should equal
      len(layer_sizes).  Alternatively this may be a single value instead of a list, in which case the
      same value is used for every layer.
    """
    super(TensorGraphMultiTaskRegressor, self).__init__(
        mode='regression', **kwargs)
    self.n_tasks = n_tasks
    self.n_features = n_features
    n_layers = len(layer_sizes)
    if not isinstance(weight_init_stddevs, collections.Sequence):
      weight_init_stddevs = [weight_init_stddevs] * (n_layers + 1)
    if not isinstance(bias_init_consts, collections.Sequence):
      bias_init_consts = [bias_init_consts] * (n_layers + 1)
    if not isinstance(dropouts, collections.Sequence):
      dropouts = [dropouts] * n_layers
    if not isinstance(activation_fns, collections.Sequence):
      activation_fns = [activation_fns] * n_layers

    # Add the input features.

@@ -181,12 +218,13 @@ class TensorGraphMultiTaskRegressor(TensorGraph):

    # Add the dense layers

    for size, weight_stddev, bias_const, dropout in zip(
        layer_sizes, weight_init_stddevs, bias_init_consts, dropouts):
    for size, weight_stddev, bias_const, dropout, activation_fn in zip(
        layer_sizes, weight_init_stddevs, bias_init_consts, dropouts,
        activation_fns):
      layer = Dense(
          in_layers=[prev_layer],
          out_channels=size,
          activation_fn=tf.nn.relu,
          activation_fn=activation_fn,
          weights_initializer=TFWrapper(
              tf.truncated_normal_initializer, stddev=weight_stddev),
          biases_initializer=TFWrapper(
@@ -352,10 +390,9 @@ class TensorflowMultiTaskClassifier(TensorflowClassifier):
        batch_size x n_features.
    """
    warnings.warn("TensorflowMultiTaskClassifier is deprecated. "
                  "Will be removed in DeepChem 1.4.",
                  DeprecationWarning)
    placeholder_scope = TensorflowGraph.get_placeholder_scope(graph,
                                                              name_scopes)
                  "Will be removed in DeepChem 1.4.", DeprecationWarning)
    placeholder_scope = TensorflowGraph.get_placeholder_scope(
        graph, name_scopes)
    n_features = self.n_features
    with graph.as_default():
      with placeholder_scope:
@@ -377,8 +414,8 @@ class TensorflowMultiTaskClassifier(TensorflowClassifier):
      assert n_layers > 0, 'Must have some layers defined.'

      label_placeholders = self.add_label_placeholders(graph, name_scopes)
      weight_placeholders = self.add_example_weight_placeholders(graph,
                                                                 name_scopes)
      weight_placeholders = self.add_example_weight_placeholders(
          graph, name_scopes)
      if training:
        graph.queue = tf.FIFOQueue(
            capacity=5,
@@ -452,11 +489,10 @@ class TensorflowMultiTaskRegressor(TensorflowRegressor):
        batch_size x n_features.
    """
    warnings.warn("TensorflowMultiTaskRegressor is deprecated. "
                  "Will be removed in DeepChem 1.4.",
                  DeprecationWarning)
                  "Will be removed in DeepChem 1.4.", DeprecationWarning)
    n_features = self.n_features
    placeholder_scope = TensorflowGraph.get_placeholder_scope(graph,
                                                              name_scopes)
    placeholder_scope = TensorflowGraph.get_placeholder_scope(
        graph, name_scopes)
    with graph.as_default():
      with placeholder_scope:
        mol_features = tf.placeholder(
@@ -477,8 +513,8 @@ class TensorflowMultiTaskRegressor(TensorflowRegressor):
      assert n_layers > 0, 'Must have some layers defined.'

      label_placeholders = self.add_label_placeholders(graph, name_scopes)
      weight_placeholders = self.add_example_weight_placeholders(graph,
                                                                 name_scopes)
      weight_placeholders = self.add_example_weight_placeholders(
          graph, name_scopes)
      if training:
        graph.queue = tf.FIFOQueue(
            capacity=5,
@@ -633,8 +669,7 @@ class TensorflowMultiTaskFitTransformRegressor(TensorflowMultiTaskRegressor):
    """
    warnings.warn("TensorflowMultiTaskFitTransformRegressor "
                  "is deprecated. "
                  "Will be removed in DeepChem 1.4.",
                  DeprecationWarning)
                  "Will be removed in DeepChem 1.4.", DeprecationWarning)

    self.fit_transformers = fit_transformers
    self.n_evals = n_evals
+9 −10
Original line number Diff line number Diff line
@@ -51,10 +51,9 @@ class TensorflowLogisticRegression(TensorflowGraphModel):
        batch_size x n_features.
    """
    warnings.warn("TensorLogisticRegression is deprecated. "
                  "Will be removed in DeepChem 1.4.",
                  DeprecationWarning)
    placeholder_scope = TensorflowGraph.get_placeholder_scope(graph,
                                                              name_scopes)
                  "Will be removed in DeepChem 1.4.", DeprecationWarning)
    placeholder_scope = TensorflowGraph.get_placeholder_scope(
        graph, name_scopes)
    n_features = self.n_features
    with graph.as_default():
      with placeholder_scope:
@@ -66,8 +65,8 @@ class TensorflowLogisticRegression(TensorflowGraphModel):
      lg_list = []

      label_placeholders = self.add_label_placeholders(graph, name_scopes)
      weight_placeholders = self.add_example_weight_placeholders(graph,
                                                                 name_scopes)
      weight_placeholders = self.add_example_weight_placeholders(
          graph, name_scopes)
      if training:
        graph.queue = tf.FIFOQueue(
            capacity=5,
@@ -98,8 +97,8 @@ class TensorflowLogisticRegression(TensorflowGraphModel):
  def add_label_placeholders(self, graph, name_scopes):
    #label placeholders with size batch_size * 1
    labels = []
    placeholder_scope = TensorflowGraph.get_placeholder_scope(graph,
                                                              name_scopes)
    placeholder_scope = TensorflowGraph.get_placeholder_scope(
        graph, name_scopes)
    with placeholder_scope:
      for task in range(self.n_tasks):
        labels.append(
+5 −6
Original line number Diff line number Diff line
@@ -44,8 +44,7 @@ class ProgressiveJointRegressor(TensorflowMultiTaskRegressor):
      List of standard-deviations for alpha in adapter layers.
    """
    warnings.warn("ProgressiveJointRegressor is deprecated. "
                  "Will be removed in DeepChem 1.4.",
                  DeprecationWarning)
                  "Will be removed in DeepChem 1.4.", DeprecationWarning)
    self.alpha_init_stddevs = alpha_init_stddevs
    super(ProgressiveJointRegressor, self).__init__(n_tasks, n_features,
                                                    **kwargs)
@@ -68,8 +67,8 @@ class ProgressiveJointRegressor(TensorflowMultiTaskRegressor):
        batch_size x n_features.
    """
    n_features = self.n_features
    placeholder_scope = TensorflowGraph.get_placeholder_scope(graph,
                                                              name_scopes)
    placeholder_scope = TensorflowGraph.get_placeholder_scope(
        graph, name_scopes)
    with graph.as_default():
      with placeholder_scope:
        self.mol_features = tf.placeholder(
@@ -94,8 +93,8 @@ class ProgressiveJointRegressor(TensorflowMultiTaskRegressor):
      all_layers = {}
      for i in range(n_layers):
        for task in range(self.n_tasks):
          task_scope = TensorflowGraph.shared_name_scope("task%d" % task, graph,
                                                         name_scopes)
          task_scope = TensorflowGraph.shared_name_scope(
              "task%d" % task, graph, name_scopes)
          print("Adding weights for task %d, layer %d" % (task, i))
          with task_scope as scope:
            if i == 0:
Loading