Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{
'x_valid':X['test'][:1000],
'criteria':'mrr', 'x_filter':filter,
'stop_interval': 2,
'burn_in':0,
'check_interval':100
})
# model.fit(np.concatenate((X['train'], X['valid'])))
# Run the evaluation procedure on the test set. Will create filtered rankings.
# To disable filtering: filter_triples=None
ranks = evaluate_performance(X['test'], model=model, filter_triples=filter,
verbose=True)
# compute and print metrics:
mr = mar_score(ranks)
mrr = mrr_score(ranks)
hits_1 = hits_at_n_score(ranks, n=1)
hits_3 = hits_at_n_score(ranks, n=3)
hits_10 = hits_at_n_score(ranks, n=10)
with open("result_{0}_{1}.txt".format(args.dataset, args.model), "w") as fo:
fo.write("mr(test): {0} mrr(test): {1} hits 1: {2} hits 3: {3} hits 10: {4}".format(mr, mrr, hits_1, hits_3, hits_10))
# The entire dataset will be used to filter out false positives statements
# created by the corruption procedure:
filter = np.concatenate((X['train'], X['valid'], X['test']))
print("Start fitting...no early stopping")
model.fit(np.concatenate((X['train'], X['valid'])))
# Run the evaluation procedure on the test set. Will create filtered rankings.
# To disable filtering: filter_triples=None
ranks = evaluate_performance(X['test'], model=model, filter_triples=filter,
verbose=True)
# compute and print metrics:
mr = mar_score(ranks)
mrr = mrr_score(ranks)
hits_1 = hits_at_n_score(ranks, n=1)
hits_3 = hits_at_n_score(ranks, n=3)
hits_10 = hits_at_n_score(ranks, n=10)
with open("result_{0}_{1}.txt".format(args.dataset, args.model), "w") as fo:
fo.write("mr(test): {0} mrr(test): {1} hits 1: {2} hits 3: {3} hits 10: {4}".format(mr, mrr, hits_1, hits_3, hits_10))
{
'x_valid':X['test'][:1000],
'criteria':'mrr', 'x_filter':filter,
'stop_interval': 2,
'burn_in':0,
'check_interval':100
})
# model.fit(np.concatenate((X['train'], X['valid'])))
# Run the evaluation procedure on the test set. Will create filtered rankings.
# To disable filtering: filter_triples=None
ranks = evaluate_performance(X['test'], model=model, filter_triples=filter,
verbose=True)
# compute and print metrics:
mr = mar_score(ranks)
mrr = mrr_score(ranks)
hits_1 = hits_at_n_score(ranks, n=1)
hits_3 = hits_at_n_score(ranks, n=3)
hits_10 = hits_at_n_score(ranks, n=10)
with open("result_{0}_{1}.txt".format(args.dataset, args.model), "w") as fo:
fo.write("mr(test): {0} mrr(test): {1} hits 1: {2} hits 3: {3} hits 10: {4}".format(mr, mrr, hits_1, hits_3, hits_10))
with open(args.hyperparams, "r") as fi:
param_grid = json.load(fi)
print("input param: ", param_grid)
# Train the model on all possibile combinations of hyperparameters.
# Models are validated on the validation set.
# It returnes a model re-trained on training and validation sets.
print("start executing to find the best...")
best_model, best_params, best_mrr_train, \
ranks_test, mrr_test = select_best_model_ranking(model_class, X_dict,
param_grid,
filter_retrain=True,
eval_splits=100,
verbose=True)
mr_test = mar_score(ranks_test)
hits_1 = hits_at_n_score(ranks_test, n=1)
hits_3 = hits_at_n_score(ranks_test, n=3)
hits_10 = hits_at_n_score(ranks_test, n=10)
with open("result_{0}_{1}.txt".format(args.dataset, args.model), "w") as fo:
fo.write("type(best_model).__name__: {0}\n".format(type(best_model).__name__))
fo.write("best_params: {0}\n".format(best_params))
fo.write("mr(test): {0} mrr(test): {1} hits 1: {2} hits 3: {3} hits 10: {4}".format(mr_test, mrr_test, hits_1, hits_3, hits_10))