Skip to content

Commit

Permalink
change RotatE relation initialization (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCatt91 authored Jan 23, 2024
1 parent 4e794d1 commit 47da165
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
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

0 comments on commit 47da165

Please sign in to comment.