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_generate_corruptions_for_eval_filtered_object(): x = np.array([0, 0, 1]) idx_entities = np.array([0, 1, 2, 3]) filter_triples = np.array(([1, 0, 1], [2, 0, 1])) x_n_actual = generate_corruptions_for_eval(x, idx_entities=idx_entities, filter=filter_triples, side='o') x_n_expected = np.array([[0, 0, 0], [0, 0, 2], [0, 0, 3]]) np.testing.assert_array_equal(np.sort(x_n_actual, axis=0), np.sort(x_n_expected, axis=0))