Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About the 2D plane. #2

Closed
Zawo1995 opened this issue Dec 25, 2019 · 1 comment
Closed

About the 2D plane. #2

Zawo1995 opened this issue Dec 25, 2019 · 1 comment

Comments

@Zawo1995
Copy link

I'm very curious about the 2D pic from the paper.
Could you tell me how you plot them?
1

@zhanqiuzhang
Copy link
Member

zhanqiuzhang commented Dec 25, 2019

We have briefly described how to plot the figures in the Analysis on Entity Embeddings section.

RotatE:
Each dimension of entity embeddings is a complex number---(re, im). Thus, we can regard the embeddings of an entity as a group of 2D points and plot them on a 2D plane.

HAKE:
HAKE maps entities into the polar coordinate system. Therefore, we can also plot the entity embeddings generated by HAKE on a 2D plane based on their polar coordinates. We use the logarithmic scale to better display the differences between entity embeddings.
The figures in the paper are plotted using matlab. The skeleton of the corresponding python code is as follows.

import numpy as np
import matplotlib.pyplot as plt
import os

"""
model_path
embedding_range
head_id 
tail_id 
"""
entity_embedding = np.load(os.path.join(model_path, 'entity_embedding.npy'))

head = entity_embedding[head_id]
tail = entity_embedding[tail_id]

phase_head, mod_head = np.split(head, 2)
phase_tail, mod_tail = np.split(tail, 2)

mod_head = np.log(np.abs(mod_head))  * np.sign(mod_head)
mod_tail = np.log(np.abs(mod_tail))  * np.sign(mod_tail)

phase_head = phase_head / embedding_range * np.pi
phase_tail = phase_tail / embedding_range * np.pi

x_head, y_head = mod_head * np.cos(phase_head), mod_head * np.sin(phase_head)
x_tail, y_tail = mod_tail * np.cos(phase_tail), mod_tail * np.sin(phase_tail)

plt.scatter(x_head, y_head)
plt.scatter(x_tail, y_tail)
plt.axis('equal')
plt.show()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants