Wednesday, 30 December 2020

Poincare embeddings: building transitive closures from WordNet

I'd like to replicate Figure 2 in Poincaré Embeddings for Learning Hierarchical Representations, namely: Poincare embeddings from the "mammal" subtree of WordNet.

First, I construct the transitive closure needed to represent the graph. Following these docs and this SO answer, I do the following to construct the relations:

from   nltk.corpus import wordnet as wn

root    = wn.synset('mammal.n.01')
words   = list(set([w for s in root.closure(hyponyms) for w in s.lemma_names()]))
rname   = root.name().split('.')[0]
closure = [(word, rname) for word in words]

Then I am using Gensim's Poincare model to compute the embeddings. Given the example relations in Gensim's documentation, e.g.

relations = [('kangaroo', 'marsupial'), ('kangaroo', 'mammal'), ('gib', 'cat')]

I infer that the hypernym needs to be to the right. Here is the model fitting code:


from   gensim.models.poincare import PoincareModel
from   gensim.viz.poincare import poincare_2d_visualization

model = PoincareModel(relations, size=2, negative=0)
model.train(epochs=50)

fig = poincare_2d_visualization(model, relations, 'WordNet Poincare embeddings')
fig.show()

However, the result is obviously not correct in that it looks nothing like the paper. What am I doing wrong?

Poincare embeddings



from Poincare embeddings: building transitive closures from WordNet

No comments:

Post a Comment