Coder Social home page Coder Social logo

Comments (1)

calyptis avatar calyptis commented on August 21, 2024

Writing my question down helped me find a solution (see below).

The issue is that alignment_rest_12 does not store the entity IDs but rather the indexes of the entity IDs.

Perhaps there's an easier way. Happy to hear it if it exists.

def get_matches(self, remove_dangling: bool = False) -> list:
    candidate_list_kg2 = self.kgs.kg2.entities_set
    if remove_dangling:
        candidate_list_kg2 = (
            candidate_list_kg2
            - set([x for x, _ in self.kgs.train_unlinked_entities2])
            - set([x for x, _ in self.kgs.valid_unlinked_entities2])
        )

    candidate_list_kg1 = sorted(list(self.kgs.kg1.entities_set))
    candidate_list_kg2 = sorted(list(candidate_list_kg2))

    embeds1 = tf.nn.embedding_lookup(self.ent_embeds, candidate_list_kg1).eval(session=self.session)
    embeds2 = tf.nn.embedding_lookup(self.ent_embeds, candidate_list_kg2).eval(session=self.session)
    mapping = self.mapping_mat.eval(session=self.session) if self.mapping_mat is not None else None

    alignment_rest_12, _, _, sim_list = test(
        embeds1, embeds2, mapping, self.args.top_k, self.args.test_threads_num,
        metric=self.args.eval_metric, normalize=self.args.eval_norm, csls_k=0, accurate=True
    )

    candidates_kg1 = np.array(candidate_list_kg1)
    candidates_kg2 = np.array(candidate_list_kg2)
    matches = np.array(list(alignment_rest_12))

    # Map from position (index) to ID
    matches_reindexed = np.dstack((
        candidates_kg1[matches[:, 0]],
        candidates_kg2[matches[:, 1]]
    )).squeeze()

    # Map from ID to name
    mapping_kg1_int_name = {v: k for k, v in self.kgs.kg1.entities_id_dict.items()}
    mapping_kg2_int_name = {v: k for k, v in self.kgs.kg2.entities_id_dict.items()}

    matches_names = np.dstack((
        [mapping_kg1_int_name.get(i) for i in matches_reindexed[:, 0]],
        [mapping_kg2_int_name.get(i) for i in matches_reindexed[:, 1]]
    )).squeeze().tolist()

    return matches_names

from openea.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.