def test_fit_predict_wn18_TransE(): X = load_wn18() model = TransE(batches_count=1, seed=555, epochs=5, k=100, loss='pairwise', loss_params={'margin': 5}, verbose=True, optimizer='adagrad', optimizer_params={'lr': 0.1}) model.fit(X['train']) y, _ = model.predict(X['test'][:1], get_ranks=True) print(y)
def test_fit_predict_TransE_early_stopping_without_filter(): X = load_wn18() model = TransE(batches_count=1, seed=555, epochs=7, k=50, loss='pairwise', loss_params={'margin': 5}, verbose=True, optimizer='adagrad', optimizer_params={'lr':0.1}) model.fit(X['train'], True, {'x_valid': X['valid'][::100], 'criteria':'mrr', 'stop_interval': 2, 'burn_in':1, 'check_interval':2}) y, _ = model.predict(X['test'][:1], get_ranks=True) print(y)
def test_fit_predict_transE(): model = TransE(batches_count=1, seed=555, epochs=20, k=10, loss='pairwise', loss_params={'margin': 5}, optimizer='adagrad', optimizer_params={'lr':0.1}) X = np.array([['a', 'y', 'b'], ['b', 'y', 'a'], ['a', 'y', 'c'], ['c', 'y', 'a'], ['a', 'y', 'd'], ['c', 'y', 'd'], ['b', 'y', 'c'], ['f', 'y', 'e']]) model.fit(X) y_pred, _ = model.predict(np.array([['f', 'y', 'e'], ['b', 'y', 'd']]), get_ranks=True) print(y_pred) assert y_pred[0] > y_pred[1]
["Missandei", 'SPOUSE', 'Grey Worm'], ["Brienne of Tarth", 'SPOUSE', 'Jaime Lannister'] ]) unseen_filter = np.array(list({tuple(i) for i in np.vstack((positives_filter, X_unseen))})) ranks_unseen = evaluate_performance( X_unseen, model=model, filter_triples=unseen_filter, # Corruption strategy filter defined above corrupt_side = 's+o', use_default_protocol=False, # corrupt subj and obj separately while evaluating verbose=True ) scores = model.predict(X_unseen) from scipy.special import expit probs = expit(scores) pd.DataFrame(list(zip([' '.join(x) for x in X_unseen], ranks_unseen, np.squeeze(scores), np.squeeze(probs))), columns=['statement', 'rank', 'score', 'prob']).sort_values("score") """--- # 7. Visualizing Embeddings with Tensorboard projector """ from ampligraph.utils import create_tensorboard_visualizations