Exemple #1
0
 def __init__(self, n_i, n_h, activation=tanh):
     self.W_in = theano.shared(initialize_weights(n_i + n_h, n_h))
     self.W_h = theano.shared(initialize_weights(n_h, n_h))
     self.V_h = theano.shared(initialize_weights(n_h, n_h))
     self.W_h_other = theano.shared(initialize_weights(n_h, n_h))
     self.params = [self.W_in, self.W_h, self.V_h, self.W_h_other]
     self.activation = activation
Exemple #2
0
def build_model(args: Namespace, ddi:bool = False) -> nn.Module:
    """
    Builds a MoleculeModel, which is a message passing neural network + feed-forward layers.

    :param args: Arguments.
    :return: A MoleculeModel containing the MPN encoder along with final linear layers with parameters initialized.
    """
    output_size = args.num_tasks
    args.output_size = output_size
    if args.dataset_type == 'multiclass':
        args.output_size *= args.multiclass_num_classes
    if args.dataset_type == 'multilabel':
        args.output_size = args.num_labels

    if not ddi:
        model = MoleculeModel(classification=args.dataset_type == 'classification', multiclass=args.dataset_type == 'multiclass')
    else:
        model = DDIModel(classification=args.dataset_type == 'classification',
                         multiclass=args.dataset_type == 'multiclass',
                         multilabel=args.dataset_type == 'multilabel')
    if args.jt and args.jt_vocab_file is not None:
        vocab = [x.strip("\r\n ") for x in open(args.jt_vocab_file, 'r')]
        vocab = Vocab(vocab)
    else:
        vocab = None
    model.create_encoder(args, vocab=vocab)
    model.create_ffn(args)

    initialize_weights(model)
    return model
Exemple #3
0
def build_model(args: Namespace) -> nn.Module:
    """
    Builds a MoleculeModel, which is a message passing neural network + feed-forward layers.

    :param args: Arguments.
    :return: A MoleculeModel containing the MPN encoder along with final linear layers with parameters initialized.
    """
    output_size = args.num_tasks
    print(f'output_size is {args.num_tasks}')
    model = QSARmodel(args,
                      classification=args.dataset_type == 'classification')
    model.create_encoder(args)
    model.create_ffn(args)
    initialize_weights(model)
    print(f'has initialize_weights')
    return model
Exemple #4
0
    def __init__(self, n_i, n_h, activation=tanh):
        self.WA_in = theano.shared(initialize_weights(n_i + n_h, n_h))
        self.WA_h = theano.shared(initialize_weights(n_h, n_h))
        self.VA_h = theano.shared(initialize_weights(n_h, n_h))

        self.WB_in = theano.shared(initialize_weights(n_i + n_h, n_h))
        self.WB_h = theano.shared(initialize_weights(n_h, n_h))
        self.VB_h = theano.shared(initialize_weights(n_h, n_h))

        self.Wother_in = theano.shared(initialize_weights(n_i + n_h, n_h))
        self.Wother_h = theano.shared(initialize_weights(n_h, n_h))

        self.params = [
            self.WA_in, self.WA_h, self.VA_h, self.WB_in, self.WB_h, self.VB_h,
            self.Wother_in, self.Wother_h
        ]
        self.activation = activation
Exemple #5
0
 def __init__(self, n_i, n_h, activation=tanh):
     self.W_xr = theano.shared(initialize_weights(n_i, n_h))
     self.W_hr = theano.shared(initialize_weights(n_h, n_h))
     self.W_xz = theano.shared(initialize_weights(n_i, n_h))
     self.W_hz = theano.shared(initialize_weights(n_h, n_h))
     self.W_xh = theano.shared(initialize_weights(n_i, n_h))
     self.W_hh = theano.shared(initialize_weights(n_h, n_h))
     self.params = [
         self.W_xr, self.W_hr, self.W_xz, self.W_hz, self.W_xh, self.W_hh
     ]
     self.activation = activation
Exemple #6
0
 def __init__(self, n_h, attention=1):
     if attention == 1:
         self.W1_c = theano.shared(initialize_weights(n_h, n_h))
         self.W2_r = theano.shared(initialize_weights(n_h, n_h))
         self.W1_h = theano.shared(initialize_weights(n_h, n_h))
         self.w = theano.shared(initialize_weights(n_h, ))
         self.f = self.forward
         self.params = [self.W1_c, self.W1_h, self.w, self.W2_r]
     elif attention == 2:
         self.W1_c = theano.shared(initialize_weights(n_h, n_h))
         self.W2_r = theano.shared(initialize_weights(n_h, n_h))
         self.f = self.forward_bi
         self.params = [self.W1_c, self.W2_r]
     elif attention == 3:
         self.W1_c = theano.shared(initialize_weights(n_h, n_h))
         self.W2_r = theano.shared(initialize_weights(2 * n_h, n_h))
         self.W1_h = theano.shared(initialize_weights(n_h, n_h))
         self.w = theano.shared(initialize_weights(n_h, ))
         self.w_b = theano.shared(initialize_weights(n_h, ))
         self.f = self.forward_second_order
         self.params = [self.W1_c, self.W1_h, self.w, self.w_b, self.W2_r]
     else:
         self.W1_c = theano.shared(initialize_weights(n_h, n_h))
         self.W2_r = theano.shared(initialize_weights(n_h, n_h))
         self.W1_h = theano.shared(initialize_weights(n_h, n_h))
         self.W_m = theano.shared(initialize_weights(n_h, n_h))
         self.w = theano.shared(initialize_weights(n_h, ))
         self.f = self.forward_double
         self.params = [self.W1_c, self.W1_h, self.w, self.W2_r, self.W_m]
Exemple #7
0
 def __init__(self, n_i, n_h):
     self.W = theano.shared(initialize_weights(n_i, n_h))
     self.params = [self.W]
Exemple #8
0
    def __init__(self, n_i, n_h, activation=tanh):
        # Parameters for speaker
        self.WA_xr = theano.shared(initialize_weights(n_i + n_h, n_h))
        self.WA_xp = theano.shared(initialize_weights(n_i + n_h, n_h))
        self.WA_xz = theano.shared(initialize_weights(n_i + n_h, n_h))
        self.WA_xh = theano.shared(initialize_weights(n_i + n_h, n_h))

        self.WA_hr = theano.shared(initialize_weights(n_h, n_h))
        self.WA_hp = theano.shared(initialize_weights(n_h, n_h))
        self.WA_hz = theano.shared(initialize_weights(n_h, n_h))
        self.WA_hh = theano.shared(initialize_weights(n_h, n_h))

        self.VA_hr = theano.shared(initialize_weights(n_h, n_h))
        self.VA_hp = theano.shared(initialize_weights(n_h, n_h))
        self.VA_hz = theano.shared(initialize_weights(n_h, n_h))
        self.VA_hh = theano.shared(initialize_weights(n_h, n_h))

        # Parameters for addressee
        self.WB_xr = theano.shared(initialize_weights(n_i + n_h, n_h))
        self.WB_xp = theano.shared(initialize_weights(n_i + n_h, n_h))
        self.WB_xz = theano.shared(initialize_weights(n_i + n_h, n_h))
        self.WB_xh = theano.shared(initialize_weights(n_i + n_h, n_h))

        self.WB_hr = theano.shared(initialize_weights(n_h, n_h))
        self.WB_hp = theano.shared(initialize_weights(n_h, n_h))
        self.WB_hz = theano.shared(initialize_weights(n_h, n_h))
        self.WB_hh = theano.shared(initialize_weights(n_h, n_h))

        self.VB_hr = theano.shared(initialize_weights(n_h, n_h))
        self.VB_hp = theano.shared(initialize_weights(n_h, n_h))
        self.VB_hz = theano.shared(initialize_weights(n_h, n_h))
        self.VB_hh = theano.shared(initialize_weights(n_h, n_h))

        # Parameters for other
        self.Wother_xr = theano.shared(initialize_weights(n_i + n_h, n_h))
        self.Wother_xz = theano.shared(initialize_weights(n_i + n_h, n_h))
        self.Wother_xh = theano.shared(initialize_weights(n_i + n_h, n_h))

        self.Wother_hr = theano.shared(initialize_weights(n_h, n_h))
        self.Wother_hz = theano.shared(initialize_weights(n_h, n_h))
        self.Wother_hh = theano.shared(initialize_weights(n_h, n_h))

        self.params = [
            self.WA_xr, self.WA_xp, self.WA_xz, self.WA_xh, self.WA_hr,
            self.WA_hp, self.WA_hz, self.WA_hh, self.VA_hr, self.VA_hp,
            self.VA_hz, self.VA_hh, self.WB_xr, self.WB_xp, self.WB_xz,
            self.WB_xh, self.WB_hr, self.WB_hp, self.WB_hz, self.WB_hh,
            self.VB_hr, self.VB_hp, self.VB_hz, self.VB_hh, self.Wother_xr,
            self.Wother_xz, self.Wother_xh, self.Wother_hr, self.Wother_hz,
            self.Wother_hh
        ]
        self.activation = activation