Train and Evaluate

Here, we explain how to define and run experiments programmatically. This should be done using PyKEEN.

Configure your experiment

To programmatically train (and evaluate) a KGE model, a python dictionary must be created specifying the experiment:

config = dict(
    training_set_path           = 'data/corpora/fb15k/compath.tsv',
    test_set_ratio              = 0.1,
    execution_mode              = 'Training_mode',
    kg_embedding_model_name     = 'TransE',
    embedding_dim               = 50,
    normalization_of_entities   = 2,  # corresponds to L2
    scoring_function            = 1,  # corresponds to L1
    margin_loss                 = 1,
    learning_rate               = 0.01,
    batch_size                  = 32,
    num_epochs                  = 1000,
    filter_negative_triples     = True,
    random_seed                 = 2,
    preferred_device            = 'cpu',
)

Run your experiment

results = pykeen.run(
    config=config,
    output_directory=output_directory,
)

Access your results

Show all keys contained in results:

print('Keys:', *sorted(results.results.keys()), sep='\n  ')

Access trained KGE model

results.results['trained_model']

Access the losses

results.results['losses']

Access evaluation results

results.results['eval_summary']