def main():
    units = 512
    encoding_units = 128
    z_k = 10
    input_units = 28 * 28
    pz_regularizer = BalanceRegularizer(1e-1)
    reg_weight_encoding = 1e-1
    gen_regularizer = L1L2(1e-2, 1e-2)

    ((x, y), (xt, yt)) = mnist.load_data()
    x = np.float32(x) / 255.
    x = np.reshape(x, (x.shape[0], -1))
    initializer = RandomUniform(minval=-0.05, maxval=0.05)
    classifier = MLP(input_units=input_units,
                     hidden_units=units,
                     output_units=z_k,
                     hidden_depth=2,
                     hidden_activation=leaky_relu,
                     initializer=initializer,
                     output_activation=softmax_nd)
    encoder = MLP(input_units=units,
                  hidden_units=units,
                  output_units=encoding_units,
                  hidden_depth=2,
                  hidden_activation=leaky_relu,
                  initializer=initializer,
                  output_activation=leaky_relu)
    generator = MLP(input_units=encoding_units,
                    hidden_units=units,
                    output_units=input_units,
                    hidden_depth=2,
                    hidden_activation=leaky_relu,
                    initializer=initializer,
                    output_activation=T.nnet.sigmoid)

    model = MSEModel(
        z_k=z_k,
        mode=2,
        classifier=classifier,
        encoder=encoder,
        generator=generator,
        units=units,
        encoding_units=encoding_units,
        opt=Adam(1e-3),
        input_units=input_units,
        reg_weight_encoding=reg_weight_encoding,
        activation=leaky_relu,
        initializer=initializer,
        pz_regularizer=pz_regularizer,
        gen_regularizer=gen_regularizer
    )
    model.train(
        x=x,
        output_path='output/mnist_clustering_mse',
        epochs=500,
        batches=10000,
        batch_size=128
    )
def main():
    units = 512
    rng_units = 128
    z_k = 10
    pz_regularizer = BalanceRegularizer(1e-2)
    iwgan_weight = 1e-1

    initializer = RandomUniform(minval=-0.05, maxval=0.05)
    ((x, y), (xt, yt)) = mnist.load_data()
    x = np.float32(x) / 255.
    x = np.reshape(x, (x.shape[0], -1))
    input_units = 28 * 28
    classifier = MLP(input_units=input_units,
                     hidden_units=units,
                     output_units=z_k,
                     hidden_depth=2,
                     hidden_activation=leaky_relu,
                     initializer=initializer,
                     output_activation=softmax_nd)
    generator = MLP(input_units=units,
                    hidden_units=units,
                    output_units=input_units,
                    hidden_depth=2,
                    hidden_activation=leaky_relu,
                    initializer=initializer,
                    output_activation=T.nnet.sigmoid)
    discriminator = MLP(input_units=units,
                        hidden_units=units,
                        output_units=1,
                        hidden_depth=2,
                        initializer=initializer,
                        hidden_activation=leaky_relu)
    model = FCGAN(
        z_k=z_k,
        classifier=classifier,
        generator=generator,
        discriminator=discriminator,
        optd=Adam(1e-3),
        optg=Adam(1e-3),
        input_units=input_units,
        rng_units=rng_units,
        units=units,
        activation=leaky_relu,
        pz_regularizer=pz_regularizer,
        initializer=initializer,
        iwgan_weight=iwgan_weight
    )
    model.train(
        x=x,
        output_path='output/mnist_clustering',
        epochs=500,
        batches=512,
        discriminator_batches=5,
        batch_size=128
    )
Exemplo n.º 3
0
def main():
    epochs = 10
    batches = 4096
    z_k = 1024
    iters = 5
    outputpath = "output/skipgram_flat-b"
    cooccurrence = np.load('output/cooccurrence.npy').astype(np.float32)
    weights = [1e1, 1, 1e-1, 1e-2, 1e-3, 5e-4, 1e-4, 5e-5, 1e-5, 1e-6, 1e-7]
    regularizers = [BalanceRegularizer(w) for w in weights]
    labels = ["b-{:.01e}".format(w) for w in weights]
    train_flat_regularizer_battery(outputpath=outputpath,
                                   cooccurrence=cooccurrence,
                                   epochs=epochs,
                                   batches=batches,
                                   iters=iters,
                                   z_k=z_k,
                                   labels=labels,
                                   regularizers=regularizers,
                                   is_weight_regularizer=False,
                                   kwdata={'weights': np.array(weights)})
def main():
    epochs = 1000
    batches = 4096
    z_k = 256
    outputpath = "output/skipgram_256_m1"
    cooccurrence = np.load('output/cooccurrence.npy').astype(np.float32)
    scale = 1e-2
    opt = Adam(1e-3)
    pz_regularizer = BalanceRegularizer(1e-7)
    model = FlatModel(cooccurrence=cooccurrence,
                      z_k=z_k,
                      opt=opt,
                      mode=1,
                      pz_regularizer=pz_regularizer,
                      scale=scale)
    model.train(outputpath, epochs=epochs, batches=batches)
    return run_flat_validation(input_path=outputpath,
                               output_path=os.path.join(
                                   outputpath, "validate.txt"),
                               cooccurrence=cooccurrence)
Exemplo n.º 5
0
def main():
    epochs = 10
    iters = 1
    batches = 4096
    z_k = 2
    z_depth = 10
    outputpath = "output/skipgram_tree_b"
    betas = [0.5, 0.85, 1.2, 2.0]
    weights = [1, 1e-1, 1e-2, 1e-3, 1e-4, 1e-5]
    labels = ["b-{:.01e}".format(w) for w in weights]
    regularizers = [BalanceRegularizer(w) for w in weights]
    train_tree_regularizer_battery(betas=betas,
                                   epochs=epochs,
                                   iters=iters,
                                   batches=batches,
                                   z_k=z_k,
                                   z_depth=z_depth,
                                   outputpath=outputpath,
                                   labels=labels,
                                   is_weight_regularizer=False,
                                   kwdata={'weights': np.array(weights)},
                                   regularizers=regularizers)