Example #1
0
def marius():

    # initialize Marius parameters to those specified in configuration file or default
    # values by calling parseConfig(config_path)
    config_path = "examples/training/configs/fb15k_cpu.ini"
    config = m.parseConfig(config_path)

    # initialize the training and evaluation sets
    train_set, eval_set = m.initializeDatasets(config)

    # initialize the model with the encoder and decoder type specified in the config
    # Note: if encoder and decoder are already initialized, you can initialize the model
    # with a constructor call, i.e. model = m.Model(encoder, decoder). See other Python
    # example file (custom_models_example.py) for how to define custom models
    model = m.initializeModel(config.model.encoder_model,
                              config.model.decoder_model)

    # initialize the trainer and evaluator using the data and model
    trainer = m.SynchronousTrainer(train_set, model)
    evaluator = m.SynchronousEvaluator(eval_set, model)

    # train and evaluate
    for epoch in range(config.training.num_epochs):
        trainer.train(1)
        evaluator.evaluate(True)
Example #2
0
def marius():

    # initialize Marius parameters to those specified in configuration file or default
    # values by calling parseConfig(config_path)
    config_path = "examples/training/configs/fb15k_cpu.ini"
    config = m.parseConfig(config_path)

    # Here we define a custom model to use during the training and evaluation process
    # A Model consists of both 1) Encoder and 2) Decoder
    # A Decoder consists of 1) Comparator, 2) Relation Operator, and 3) Loss Function

    # initialize the encoder to Empty
    encoder = m.EmptyEncoder()

    # initialize the loss function to built-in SoftMax
    loss_function = m.SoftMax()

    # initialize custom Relation Operator and Comparator implemented in Python
    rel_op = translation()
    comp = PyDotCompare()
    # comp = L2()

    # initialize the decoder with our Loss Function and custom Relation Operator and Comparator
    decoder = m.LinkPredictionDecoder(comp, rel_op, loss_function)

    # initialize the custom model with our Encoder and Decoder
    custom_model = transE(encoder, decoder)

    # model instantiation and train for one epoch
    train_set, eval_set = m.initializeDatasets(config)
    trainer = m.SynchronousTrainer(train_set, custom_model)
    evaluator = m.SynchronousEvaluator(eval_set, custom_model)
    trainer.train(1)
    evaluator.evaluate(True)
Example #3
0
    def test_one_epoch(self):
        #preprocess.fb15k(output_dir="output_dir/")
        config_path = "examples/training/configs/fb15k_cpu.ini"
        config = m.parseConfig(config_path)

        train_set, eval_set = m.initializeDatasets(config)

        model = m.initializeModel(config.model.encoder_model,
                                  config.model.decoder_model)

        trainer = m.SynchronousTrainer(train_set, model)
        evaluator = m.SynchronousEvaluator(eval_set, model)

        trainer.train(1)
        evaluator.evaluate(True)
Example #4
0
    def test_comparator(self):
        #preprocess.fb15k(output_dir="output_dir/")
        config_path = "examples/training/configs/fb15k_cpu.ini"
        config = m.parseConfig(config_path)

        encoder = m.EmptyEncoder()
        comp = PyDotCompare()
        rel_op = m.HadamardOperator()
        loss_function = m.SoftMax()
        decoder = m.LinkPredictionDecoder(comp, rel_op, loss_function)

        model = m.Model(encoder, decoder)

        train_set, eval_set = m.initializeDatasets(config)
        trainer = m.SynchronousTrainer(train_set, model)
        evaluator = m.SynchronousEvaluator(eval_set, model)
        trainer.train(1)
        evaluator.evaluate(True)