def test_generate_corruptions_for_eval(): X = np.array([['a', 'x', 'b'], ['c', 'x', 'd'], ['e', 'x', 'f'], ['b', 'y', 'h'], ['a', 'y', 'l']]) rel_to_idx, ent_to_idx = create_mappings(X) X = to_idx(X, ent_to_idx=ent_to_idx, rel_to_idx=rel_to_idx) with tf.Session() as sess: all_ent = tf.constant(list(ent_to_idx.values()), dtype=tf.int64) x = tf.constant(np.array([X[0]]), dtype=tf.int64) x_n_actual, _ = sess.run(generate_corruptions_for_eval(x, all_ent)) x_n_expected = np.array([[0, 0, 0], [0, 0, 1], [0, 0, 2], [0, 0, 3], [0, 0, 4], [0, 0, 5], [0, 0, 6], [0, 0, 7], [0, 0, 1], [1, 0, 1], [2, 0, 1], [3, 0, 1], [4, 0, 1], [5, 0, 1], [6, 0, 1], [7, 0, 1]]) np.testing.assert_array_equal(x_n_actual, x_n_expected)
def test_to_idx(): X = np.array([['a', 'x', 'b'], ['c', 'y', 'd']]) X_idx_expected = [[0, 0, 1], [2, 1, 3]] rel_to_idx, ent_to_idx = create_mappings(X) X_idx = to_idx(X, ent_to_idx=ent_to_idx, rel_to_idx=rel_to_idx) np.testing.assert_array_equal(X_idx, X_idx_expected)
def test_generate_corruptions_for_fit_curropt_side_s(): tf.reset_default_graph() X = np.array([['a', 'x', 'b'], ['c', 'x', 'd'], ['e', 'x', 'f'], ['b', 'y', 'h'], ['a', 'y', 'l']]) rel_to_idx, ent_to_idx = create_mappings(X) X = to_idx(X, ent_to_idx=ent_to_idx, rel_to_idx=rel_to_idx) eta = 1 with tf.Session() as sess: all_ent = tf.squeeze(tf.constant(list(ent_to_idx.values()), dtype=tf.int32)) dataset = tf.constant(X, dtype=tf.int32) X_corr = sess.run(generate_corruptions_for_fit(dataset, eta=eta, corrupt_side='s', entities_size=len(X), rnd=0)) print(X_corr) # these values occur when seed=0 X_corr_exp = [[1, 0, 1], [3, 0, 3], [3, 0, 5], [0, 1, 6], [3, 1, 7]] np.testing.assert_array_equal(X_corr, X_corr_exp)