Ejemplo n.º 1
0
    def _check_configuration(self, dataset: BilinearDataset, model_params: LayeredBilinearModuleParams,
                             activator_params: BilinearActivatorParams):

        model = LayeredBilinearModule(model_params)
        activator = BilinearActivator(model, activator_params, dataset)
        activator.train(show_plot=False)

        return activator.accuracy_train_vec, activator.auc_train_vec, activator.loss_train_vec, \
               activator.accuracy_dev_vec, activator.auc_dev_vec, activator.loss_dev_vec, \
               activator.accuracy_test_vec, activator.auc_test_vec, activator.loss_test_vec
Ejemplo n.º 2
0
def get_activator_mutagen(dev_split, test_split, topological_ftrs=True):
    data_name = "Mutagen"
    ext_train = ExternalData(MutagenAllExternalDataParams())
    ds_params = MutagenDatasetAllParams()
    if not topological_ftrs:
        ds_params.FEATURES = [DEG]
    ds = BilinearDataset(ds_params, external_data=ext_train)
    activator_params = MutagenBilinearActivatorParams()
    activator_params.TEST_SPLIT = test_split
    activator_params.DEV_SPLIT = dev_split
    module_params = MutagenLayeredBilinearModuleParams(
        ftr_len=ds.len_features, embed_vocab_dim=ext_train.len_embed())
    return data_name, BilinearActivator(LayeredBilinearModule(module_params),
                                        activator_params, ds)
Ejemplo n.º 3
0
def run_trial(params, dataset_param_class, module_param_class,
              activator_param_class, ext_data, is_multi_class):
    ds_params = dataset_param_class()
    ds_params.FEATURES = [globals()[ftr] for ftr in params['input_vec']]
    dataset = BilinearDataset(ds_params, external_data=ext_data)

    # model
    layers = []
    if params['layers_config']["_name"] == "2_layers":
        layers.append([None, int(params['layers_config']["h1_dim"])])
        layers.append([
            int(params['layers_config']["h1_dim"]),
            int(params['layers_config']["h2_dim"])
        ])

    elif params['layers_config']["_name"] == "3_layers":
        layers.append([None, int(params['layers_config']["h1_dim"])])
        layers.append([
            int(params['layers_config']["h1_dim"]),
            int(params['layers_config']["h2_dim"])
        ])
        layers.append([
            int(params['layers_config']["h2_dim"]),
            int(params['layers_config']["h3_dim"])
        ])

    model_params = module_param_class(ftr_len=dataset.len_features,
                                      layer_dim=layers,
                                      embed_vocab_dim=ext_data.len_embed())
    model_params.DROPOUT = params['dropout']
    model_params.WEIGHT_DECAY = params['regularization']
    model_params.LR = params['learning_rate']
    model_params.OPTIMIZER = globals()[params['optimizer']]

    # activator
    activator_params = activator_param_class()
    activator_params.BATCH_SIZE = params['batch_size']
    activator_params.EPOCHS = params['epochs']

    model = LayeredBilinearModule(model_params)
    activator = BilinearMultiClassActivator(model, activator_params, dataset, nni=True) if is_multi_class else \
        BilinearActivator(model, activator_params, dataset, nni=True)
    activator.train(show_plot=False, early_stop=True)
Ejemplo n.º 4
0
        self.LOSS = functional.binary_cross_entropy_with_logits  # f.factor_loss  #
        self.BATCH_SIZE = 128
        self.EPOCHS = 250
        self.DATASET = "Aids"


if __name__ == '__main__':
    ALL = True
    if ALL == True:
        ext_train = ExternalData(AidsAllExternalDataParams())
        aids_train_ds = BilinearDataset(AidsDatasetAllParams(),
                                        external_data=ext_train)

        activator = BilinearActivator(
            LayeredBilinearModule(
                AidsLayeredBilinearModuleParams(
                    ftr_len=aids_train_ds.len_features,
                    embed_vocab_dim=ext_train.len_embed())),
            AidsBilinearActivatorParams(), aids_train_ds)
        activator.train()

    if ALL == False:
        ext_train = ExternalData(AidsTrainExternalDataParams())
        ext_dev = ExternalData(AidsDevExternalDataParams(),
                               idx_to_symbol=ext_train.idx_to_symbol_dict)
        ext_test = ExternalData(AidsTestExternalDataParams(),
                                idx_to_symbol=ext_train.idx_to_symbol_dict)

        aids_train_ds = BilinearDataset(AidsDatasetTrainParams(),
                                        external_data=ext_train)
        aids_dev_ds = BilinearDataset(AidsDatasetDevParams(),
                                      external_data=ext_dev)
Ejemplo n.º 5
0
            # calculate total loss
            loss_count += self._loss_func(output.squeeze(dim=1), l)

            true_labels += l.tolist()
            pred_labels += output.squeeze(dim=1).argmax(dim=1).tolist()
            pred_auc_labels += output.squeeze(dim=1).tolist()

        # update loss accuracy
        loss = float(loss_count / len(data_loader))
        # pred_labels = [0 if np.isnan(i) else i for i in pred_labels]
        self._update_loss(loss, job=job)
        self._update_accuracy(pred_labels, true_labels, job=job)
        # self._update_auc(pred_auc_labels, true_labels, job=job) ##### TODO AUC check
        return loss


if __name__ == '__main__':
    ds = BilinearDataset(YanivDatasetParams())
    activator = BilinearActivator(
        LayeredBilinearModule(
            LayeredBilinearModuleParams(ftr_len=ds.len_features)),
        BilinearActivatorParams(), BilinearDataset(YanivDatasetParams()))
    # protein_train_ds = BilinearDataset(ProteinDatasetTrainParams())
    # protein_dev_ds = BilinearDataset(ProteinDatasetDevParams())
    # protein_test_ds = BilinearDataset(ProteinDatasetTestParams())
    # _activator = BilinearActivator(LayeredBilinearModule(LayeredBilinearModuleParams(
    #     ftr_len=protein_train_ds.len_features)), BilinearActivatorParams(), protein_train_ds,
    #     dev_data=protein_dev_ds, test_data=protein_test_ds)

    activator.train()
Ejemplo n.º 6
0
                                   dropout=self.DROPOUT),
            YanivLinearLayerParams(in_dim=50, out_dim=10,
                                   dropout=self.DROPOUT),
            YanivLinearLayerParams(in_dim=50, out_dim=10,
                                   dropout=self.DROPOUT),
            YanivLinearLayerParams(in_dim=200, out_dim=1, dropout=self.DROPOUT)
        ]
        self.BILINEAR_PARAMS = YanivBilinearLayerParams(
            self.LINEAR_PARAMS_LIST[self.NUM_LAYERS - 1].COL_DIM,
            self.LINEAR_PARAMS_LIST[0].ROW_DIM)


class YanivBilinearActivatorParams(BilinearActivatorParams):
    def __init__(self):
        super().__init__()
        self.DEV_SPLIT = 0.15
        self.TEST_SPLIT = 0.15
        self.LOSS = functional.binary_cross_entropy_with_logits  # f.factor_loss  #
        self.BATCH_SIZE = 16
        self.EPOCHS = 100


if __name__ == '__main__':
    refael_train_ds = BilinearDataset(YanivDatasetParams())
    activator = BilinearActivator(
        LayeredBilinearModule(
            YanivLayeredBilinearModuleParams(
                ftr_len=refael_train_ds.len_features)),
        YanivBilinearActivatorParams(), refael_train_ds)
    activator.train()