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

Update RotatE relation initialization function #38

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions besskge/embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ def init_xavier_norm(embedding_table: torch.Tensor, gain: float = 1.0) -> torch.
)


def init_uniform_rotation(embedding_table: torch.Tensor) -> torch.Tensor:
r"""
Initialize tensor with each entry being a uniformly distributed
phase between 0 and :math:`2 \pi`.
To be used for initialization of relation embedding tables
in RotatE scoring function.

:param embedding_table:
Tensor of embedding parameters to initialize.

:return:
Initialized tensor.
"""
return torch.rand_like(embedding_table) * 2 * np.pi


def init_KGE_uniform(
embedding_table: torch.Tensor, b: float = 1.0, divide_by_embedding_size: bool = True
) -> torch.Tensor:
Expand Down
3 changes: 2 additions & 1 deletion besskge/scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
init_KGE_normal,
init_KGE_uniform,
init_uniform_norm,
init_uniform_rotation,
init_xavier_norm,
initialize_entity_embedding,
initialize_relation_embedding,
Expand Down Expand Up @@ -369,7 +370,7 @@ def __init__(
init_KGE_uniform
],
relation_initializer: Union[torch.Tensor, List[Callable[..., torch.Tensor]]] = [
init_KGE_uniform
init_uniform_rotation
],
inverse_relations: bool = False,
) -> None:
Expand Down