コード例 #1
0
class Components:
    from openke.module.model import ComplEx
    from openke.module.loss import SoftplusLoss
    from openke.data import TrainDataLoader, TestDataLoader
    from openke.module.strategy import NegativeSampling
    from openke.config import Trainer, Tester

    train_dataloader = TrainDataLoader
    test_dataloader = TestDataLoader
    model = ComplEx
    loss = SoftplusLoss()
    strategy = NegativeSampling
    trainer = Trainer
    tester = Tester
コード例 #2
0
)

# dataloader for test
test_dataloader = TestDataLoader("./benchmarks/WN18RR/", "link")

# define the model
hole = HolE(
	ent_tot = train_dataloader.get_ent_tot(),
	rel_tot = train_dataloader.get_rel_tot(),
	dim = 100
)

# define the loss function
model = NegativeSampling(
	model = hole, 
	loss = SoftplusLoss(),
	batch_size = train_dataloader.get_batch_size(), 
	regul_rate = 1.0
)


# train the model
trainer = Trainer(model = model, data_loader = train_dataloader, train_times = 1000, alpha = 0.5, use_gpu = True, opt_method = "adagrad")
trainer.run()
hole.save_checkpoint('./checkpoint/hole.ckpt')

# test the model
hole.load_checkpoint('./checkpoint/hole.ckpt')
tester = Tester(model = hole, data_loader = test_dataloader, use_gpu = True)
tester.run_link_prediction(type_constrain = False)