From 96339f19e02263c0f4157172428012fc8433ba21 Mon Sep 17 00:00:00 2001 From: AlCatt91 <> Date: Wed, 8 Nov 2023 15:58:42 +0000 Subject: [PATCH] AlCatt91 published a site update --- _modules/besskge/embedding.html | 18 + _modules/besskge/scoring.html | 219 ++++++++++- ...besskge.embedding.init_xavier_norm.rst.txt | 6 + _sources/generated/besskge.embedding.rst.txt | 1 + .../generated/besskge.scoring.ConvE.rst.txt | 12 + _sources/generated/besskge.scoring.rst.txt | 1 + generated/besskge.dataset.KGDataset.html | 4 +- generated/besskge.embedding.html | 10 +- .../besskge.embedding.init_KGE_normal.html | 1 + .../besskge.embedding.init_KGE_uniform.html | 1 + .../besskge.embedding.init_uniform_norm.html | 5 +- .../besskge.embedding.init_xavier_norm.html | 160 ++++++++ ...embedding.initialize_entity_embedding.html | 5 +- ...bedding.initialize_relation_embedding.html | 1 + ...embedding.refactor_embedding_sharding.html | 1 + .../besskge.scoring.BaseScoreFunction.html | 1 + generated/besskge.scoring.BoxE.html | 3 +- generated/besskge.scoring.ComplEx.html | 7 +- generated/besskge.scoring.ConvE.html | 367 ++++++++++++++++++ generated/besskge.scoring.DistMult.html | 7 +- ...ge.scoring.DistanceBasedScoreFunction.html | 1 + generated/besskge.scoring.InterHT.html | 3 +- ...ring.MatrixDecompositionScoreFunction.html | 1 + generated/besskge.scoring.PairRE.html | 3 +- generated/besskge.scoring.RotatE.html | 3 +- generated/besskge.scoring.TranS.html | 3 +- generated/besskge.scoring.TransE.html | 3 +- generated/besskge.scoring.TripleRE.html | 3 +- generated/besskge.scoring.html | 36 +- genindex.html | 34 +- index.html | 2 + objects.inv | Bin 4893 -> 5038 bytes searchindex.js | 2 +- 33 files changed, 872 insertions(+), 52 deletions(-) create mode 100644 _sources/generated/besskge.embedding.init_xavier_norm.rst.txt create mode 100644 _sources/generated/besskge.scoring.ConvE.rst.txt create mode 100644 generated/besskge.embedding.init_xavier_norm.html create mode 100644 generated/besskge.scoring.ConvE.html diff --git a/_modules/besskge/embedding.html b/_modules/besskge/embedding.html index 9c3af28..e7e8b24 100644 --- a/_modules/besskge/embedding.html +++ b/_modules/besskge/embedding.html @@ -100,6 +100,24 @@

Source code for besskge.embedding

     return torch.nn.functional.normalize(torch.nn.init.uniform(embedding_table), dim=-1)
+
[docs]def init_xavier_norm(embedding_table: torch.Tensor, gain: float = 1.0) -> torch.Tensor: + """ + Initialize embeddings according to Xavier normal scheme, with + `fan_in = 0`, `fan_out=row_size`. + + :param embedding_table: + Tensor of embedding parameters to initialize. + :param gain: + Scaling factor for standard deviation. Default: 1.0. + + :return: + Initialized tensor. + """ + return torch.nn.init.normal_( + embedding_table, std=gain * np.sqrt(2.0 / embedding_table.shape[-1]) + )
+ +
[docs]def init_KGE_uniform( embedding_table: torch.Tensor, b: float = 1.0, divide_by_embedding_size: bool = True ) -> torch.Tensor: diff --git a/_modules/besskge/scoring.html b/_modules/besskge/scoring.html index bfa52ed..9da5b9d 100644 --- a/_modules/besskge/scoring.html +++ b/_modules/besskge/scoring.html @@ -89,6 +89,7 @@

Source code for besskge.scoring

     init_KGE_normal,
     init_KGE_uniform,
     init_uniform_norm,
+    init_xavier_norm,
     initialize_entity_embedding,
     initialize_relation_embedding,
     refactor_embedding_sharding,
@@ -365,7 +366,7 @@ 

Source code for besskge.scoring

         :param relation_initializer:
             Initialization function or table for relation embeddings.
         :param inverse_relations:
-            If True, learn embeddings for inverse relations. Default: False
+            If True, learn embeddings for inverse relations. Default: False.
         """
         super(TransE, self).__init__(
             negative_sample_sharing=negative_sample_sharing, scoring_norm=scoring_norm
@@ -465,7 +466,7 @@ 

Source code for besskge.scoring

         :param relation_initializer:
             Initialization function or table for relation embeddings.
         :param inverse_relations:
-            If True, learn embeddings for inverse relations. Default: False
+            If True, learn embeddings for inverse relations. Default: False.
         """
         super(RotatE, self).__init__(
             negative_sample_sharing=negative_sample_sharing, scoring_norm=scoring_norm
@@ -576,7 +577,7 @@ 

Source code for besskge.scoring

             If True, L2-normalize head and tail entity embeddings before projecting,
             as in :cite:p:`PairRE`. Default: True.
         :param inverse_relations:
-            If True, learn embeddings for inverse relations. Default: False
+            If True, learn embeddings for inverse relations. Default: False.
         """
         super(PairRE, self).__init__(
             negative_sample_sharing=negative_sample_sharing, scoring_norm=scoring_norm
@@ -711,7 +712,7 @@ 

Source code for besskge.scoring

             Offset factor for head/tail relation projections, as in TripleREv2.
             Default: 0.0 (no offset).
         :param inverse_relations:
-            If True, learn embeddings for inverse relations. Default: False
+            If True, learn embeddings for inverse relations. Default: False.
         """
         super(TripleRE, self).__init__(
             negative_sample_sharing=negative_sample_sharing, scoring_norm=scoring_norm
@@ -850,7 +851,7 @@ 

Source code for besskge.scoring

         :param relation_initializer:
             Initialization function or table for relation embeddings.
         :param inverse_relations:
-            If True, learn embeddings for inverse relations. Default: False
+            If True, learn embeddings for inverse relations. Default: False.
         """
         super(DistMult, self).__init__(negative_sample_sharing=negative_sample_sharing)
 
@@ -944,7 +945,7 @@ 

Source code for besskge.scoring

         :param relation_initializer:
             Initialization function or table for relation embeddings.
         :param inverse_relations:
-            If True, learn embeddings for inverse relations. Default: False
+            If True, learn embeddings for inverse relations. Default: False.
         """
         super(ComplEx, self).__init__(negative_sample_sharing=negative_sample_sharing)
 
@@ -1018,6 +1019,206 @@ 

Source code for besskge.scoring

         )
+
[docs]class ConvE(MatrixDecompositionScoreFunction): + """ + ConvE scoring function :cite:p:`ConvE`. + + Note that, differently from :cite:p:`ConvE`, the scores returned by this class + have not been passed through a final sigmoid layer, as we assume that this is + included in the loss function. + + By design, this scoring function should be used in combination with a + negative/candidate sampler that only corrupts tails (possibly after + including all inverse triples in the dataset, see the `add_inverse_triples` + argument in :func:`besskge.sharding.PartitionedTripleSet.create_from_dataset`). + """ + + def __init__( + self, + negative_sample_sharing: bool, + sharding: Sharding, + n_relation_type: int, + embedding_size: int, + embedding_height: int, + embedding_width: int, + entity_initializer: Union[torch.Tensor, List[Callable[..., torch.Tensor]]] = [ + init_xavier_norm, + torch.nn.init.zeros_, + ], + relation_initializer: Union[torch.Tensor, List[Callable[..., torch.Tensor]]] = [ + init_xavier_norm, + ], + inverse_relations: bool = True, + input_channels: int = 1, + output_channels: int = 32, + kernel_height: int = 3, + kernel_width: int = 3, + input_dropout: float = 0.2, + feature_map_dropout: float = 0.2, + hidden_dropout: float = 0.3, + batch_normalization: bool = True, + ) -> None: + """ + Initialize ConvE model. + + :param negative_sample_sharing: + see :meth:`DistanceBasedScoreFunction.__init__` + :param sharding: + Entity sharding. + :param n_relation_type: + Number of relation types in the knowledge graph. + :param embedding_size: + Size of entity and relation embeddings. + :param embedding_height: + Height of the 2D-reshaping of the concatenation of + head and relation embeddings. + :param embedding_width: + Width of the 2D-reshaping of the concatenation of + head and relation embeddings. + :param entity_initializer: + Initialization functions or table for entity embeddings. + If not passing a table, two functions are needed: the initializer + for entity embeddings and initializer for (scalar) tail biases. + :param relation_initializer: + Initialization function or table for relation embeddings. + :param inverse_relations: + If True, learn embeddings for inverse relations. Default: True. + :param input_channels: + Number of input channels of the Conv2D operator. Default: 1. + :param output_channels: + Number of output channels of the Conv2D operator. Default: 32. + :param kernel_height: + Height of the Conv2D kernel. Default: 3. + :param kernel_width: + Width of the Conv2D kernel. Default: 3. + :param input_dropout: + Rate of Dropout applied before the convolution. Default: 0.2. + :param feature_map_dropout: + Rate of Dropout applied after the convolution. Default: 0.2. + :param hidden_dropout: + Rate of Dropout applied after the Linear layer. Default: 0.3. + :param batch_normalization: + If True, apply batch normalization before and after the + convolution and after the Linear layer. Default: True. + """ + super(ConvE, self).__init__(negative_sample_sharing=negative_sample_sharing) + + self.sharding = sharding + + if input_channels * embedding_width * embedding_height != embedding_size: + raise ValueError( + "`embedding_size` needs to be equal to" + " `input_channels * embedding_width * embedding_height`" + ) + + # self.entity_embedding[..., :embedding_size] entity_embeddings + # self.entity_embedding[..., -1] tail biases + self.entity_embedding = initialize_entity_embedding( + self.sharding, entity_initializer, [embedding_size, 1] + ) + self.relation_embedding = initialize_relation_embedding( + n_relation_type, inverse_relations, relation_initializer, [embedding_size] + ) + assert ( + self.entity_embedding.shape[-1] - 1 + == self.relation_embedding.shape[-1] + == embedding_size + ), ( + "ConvE requires `embedding_size + 1` embedding parameters for each entity" + " and `embedding_size` embedding parameters for each relation" + ) + self.embedding_size = embedding_size + + self.inp_channels = input_channels + self.emb_h = embedding_height + self.emb_w = embedding_width + conv_layers = [ + torch.nn.Dropout(input_dropout), + torch.nn.Conv2d( + in_channels=self.inp_channels, + out_channels=output_channels, + kernel_size=(kernel_height, kernel_width), + ), + torch.nn.ReLU(), + torch.nn.Dropout2d(feature_map_dropout), + ] + fc_layers = [ + torch.nn.Linear( + output_channels + * (2 * self.emb_h - kernel_height + 1) + * (self.emb_w - kernel_width + 1), + embedding_size, + ), + torch.nn.Dropout(hidden_dropout), + torch.nn.ReLU(), + ] + if batch_normalization: + conv_layers.insert(0, torch.nn.BatchNorm2d(input_channels)) + conv_layers.insert(3, torch.nn.BatchNorm2d(output_channels)) + fc_layers.insert(2, torch.nn.BatchNorm1d(embedding_size)) + self.conv_layers = torch.nn.Sequential(*conv_layers) + self.fc_layers = torch.nn.Sequential(*fc_layers) + + # docstr-coverage: inherited +
[docs] def score_triple( + self, + head_emb: torch.Tensor, + relation_id: torch.Tensor, + tail_emb: torch.Tensor, + ) -> torch.Tensor: + relation_emb = torch.index_select( + self.relation_embedding, index=relation_id, dim=0 + ) + # Discard bias for heads + head_emb = head_emb[..., :-1] + tail_emb, tail_bias = torch.split(tail_emb, self.embedding_size, dim=-1) + hr_cat = torch.cat( + [ + head_emb.view(-1, self.inp_channels, self.emb_h, self.emb_w), + relation_emb.view(-1, self.inp_channels, self.emb_h, self.emb_w), + ], + dim=-2, + ) + hr_conv = self.fc_layers(self.conv_layers(hr_cat).flatten(start_dim=1)) + return self.reduce_embedding(hr_conv * tail_emb) + tail_bias.squeeze(-1)
+ + # docstr-coverage: inherited +
[docs] def score_heads( + self, + head_emb: torch.Tensor, + relation_id: torch.Tensor, + tail_emb: torch.Tensor, + ) -> torch.Tensor: + raise NotImplementedError("ConvE should not be used with head corruption")
+ + # docstr-coverage: inherited +
[docs] def score_tails( + self, + head_emb: torch.Tensor, + relation_id: torch.Tensor, + tail_emb: torch.Tensor, + ) -> torch.Tensor: + relation_emb = torch.index_select( + self.relation_embedding, index=relation_id, dim=0 + ) + # Discard bias for heads + head_emb = head_emb[..., :-1] + tail_emb, tail_bias = torch.split(tail_emb, self.embedding_size, dim=-1) + if self.negative_sample_sharing: + tail_bias = tail_bias.view(1, -1) + else: + tail_bias = tail_bias.squeeze(-1) + hr_cat = torch.cat( + [ + head_emb.view(-1, self.inp_channels, self.emb_h, self.emb_w), + relation_emb.view(-1, self.inp_channels, self.emb_h, self.emb_w), + ], + dim=-2, + ) + hr_conv = self.fc_layers(self.conv_layers(hr_cat).flatten(start_dim=1)) + return self.broadcasted_dot_product(hr_conv, tail_emb) + tail_bias
+ +
[docs]class BoxE(DistanceBasedScoreFunction): """ BoxE scoring function :cite:p:`BoxE`. @@ -1074,7 +1275,7 @@

Source code for besskge.scoring

             Softening parameter for geometric normalization of box widths.
             Default: 1e-6.
         :param inverse_relations:
-            If True, learn embeddings for inverse relations. Default: False
+            If True, learn embeddings for inverse relations. Default: False.
         """
         super(BoxE, self).__init__(
             negative_sample_sharing=negative_sample_sharing, scoring_norm=scoring_norm
@@ -1332,7 +1533,7 @@ 

Source code for besskge.scoring

         :param offset:
             Offset applied to auxiliary entity embeddings. Default: 1.0.
         :param inverse_relations:
-            If True, learn embeddings for inverse relations. Default: False
+            If True, learn embeddings for inverse relations. Default: False.
         """
         super(InterHT, self).__init__(
             negative_sample_sharing=negative_sample_sharing, scoring_norm=scoring_norm
@@ -1489,7 +1690,7 @@ 

Source code for besskge.scoring

         :param offset:
             Offset applied to tilde entity embeddings. Default: 1.0.
         :param inverse_relations:
-            If True, learn embeddings for inverse relations. Default: False
+            If True, learn embeddings for inverse relations. Default: False.
         """
         super(TranS, self).__init__(
             negative_sample_sharing=negative_sample_sharing, scoring_norm=scoring_norm
diff --git a/_sources/generated/besskge.embedding.init_xavier_norm.rst.txt b/_sources/generated/besskge.embedding.init_xavier_norm.rst.txt
new file mode 100644
index 0000000..ced220a
--- /dev/null
+++ b/_sources/generated/besskge.embedding.init_xavier_norm.rst.txt
@@ -0,0 +1,6 @@
+besskge.embedding.init\_xavier\_norm
+====================================
+
+.. currentmodule:: besskge.embedding
+
+.. autofunction:: init_xavier_norm
\ No newline at end of file
diff --git a/_sources/generated/besskge.embedding.rst.txt b/_sources/generated/besskge.embedding.rst.txt
index 0f9b9d7..901b5be 100644
--- a/_sources/generated/besskge.embedding.rst.txt
+++ b/_sources/generated/besskge.embedding.rst.txt
@@ -21,6 +21,7 @@ besskge.embedding
       init_KGE_normal
       init_KGE_uniform
       init_uniform_norm
+      init_xavier_norm
       initialize_entity_embedding
       initialize_relation_embedding
       refactor_embedding_sharding
diff --git a/_sources/generated/besskge.scoring.ConvE.rst.txt b/_sources/generated/besskge.scoring.ConvE.rst.txt
new file mode 100644
index 0000000..8240814
--- /dev/null
+++ b/_sources/generated/besskge.scoring.ConvE.rst.txt
@@ -0,0 +1,12 @@
+..
+   # Copyright (c) 2023 Graphcore Ltd. All rights reserved.
+   # Copyright (c) 2007-2023 by the Sphinx team. All rights reserved.
+
+besskge.scoring.ConvE
+=====================
+
+.. currentmodule:: besskge.scoring
+
+.. autoclass:: ConvE
+   :members:
+   :inherited-members: Module
\ No newline at end of file
diff --git a/_sources/generated/besskge.scoring.rst.txt b/_sources/generated/besskge.scoring.rst.txt
index dd39740..0fbbdc5 100644
--- a/_sources/generated/besskge.scoring.rst.txt
+++ b/_sources/generated/besskge.scoring.rst.txt
@@ -26,6 +26,7 @@ besskge.scoring
       BaseScoreFunction
       BoxE
       ComplEx
+      ConvE
       DistMult
       DistanceBasedScoreFunction
       InterHT
diff --git a/generated/besskge.dataset.KGDataset.html b/generated/besskge.dataset.KGDataset.html
index 49baa16..7d5eba9 100644
--- a/generated/besskge.dataset.KGDataset.html
+++ b/generated/besskge.dataset.KGDataset.html
@@ -222,12 +222,12 @@ 

besskge.dataset.KGDataset
Parameters:
  • besskge.embedding.init_uniform_norm
  • +
  • besskge.embedding.init_xavier_norm
  • besskge.embedding.initialize_entity_embedding
  • besskge.embedding.initialize_relation_embedding
  • besskge.embedding.refactor_embedding_sharding
  • diff --git a/generated/besskge.embedding.init_uniform_norm.html b/generated/besskge.embedding.init_uniform_norm.html index 423faae..036d1b5 100644 --- a/generated/besskge.embedding.init_uniform_norm.html +++ b/generated/besskge.embedding.init_uniform_norm.html @@ -18,7 +18,7 @@ - + @@ -62,6 +62,7 @@
  • init_uniform_norm()
  • +
  • besskge.embedding.init_xavier_norm
  • besskge.embedding.initialize_entity_embedding
  • besskge.embedding.initialize_relation_embedding
  • besskge.embedding.refactor_embedding_sharding
  • @@ -127,7 +128,7 @@

    besskge.embedding.init_uniform_norm - +


    diff --git a/generated/besskge.embedding.init_xavier_norm.html b/generated/besskge.embedding.init_xavier_norm.html new file mode 100644 index 0000000..4d22e0f --- /dev/null +++ b/generated/besskge.embedding.init_xavier_norm.html @@ -0,0 +1,160 @@ + + + + + + + besskge.embedding.init_xavier_norm — BESS-KGE documentation + + + + + + + + + + + + + + + + +
    + + +
    + +
    +
    +
    + +
    +
    +
    +
    + +
    +

    besskge.embedding.init_xavier_norm

    +
    +
    +besskge.embedding.init_xavier_norm(embedding_table, gain=1.0)[source]
    +

    Initialize embeddings according to Xavier normal scheme, with +fan_in = 0, fan_out=row_size.

    +
    +
    Parameters:
    +
      +
    • embedding_table (Tensor) – Tensor of embedding parameters to initialize.

    • +
    • gain (float) – Scaling factor for standard deviation. Default: 1.0.

    • +
    +
    +
    Return type:
    +

    Tensor

    +
    +
    Returns:
    +

    Initialized tensor.

    +
    +
    +
    + +
    + + +
    +
    + +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/generated/besskge.embedding.initialize_entity_embedding.html b/generated/besskge.embedding.initialize_entity_embedding.html index 85624e2..a97967b 100644 --- a/generated/besskge.embedding.initialize_entity_embedding.html +++ b/generated/besskge.embedding.initialize_entity_embedding.html @@ -19,7 +19,7 @@ - + @@ -59,6 +59,7 @@
  • besskge.embedding.init_KGE_normal
  • besskge.embedding.init_KGE_uniform
  • besskge.embedding.init_uniform_norm
  • +
  • besskge.embedding.init_xavier_norm
  • besskge.embedding.initialize_entity_embedding @@ -139,7 +140,7 @@

    besskge.embedding.initialize_entity_embedding - +

  • diff --git a/generated/besskge.embedding.initialize_relation_embedding.html b/generated/besskge.embedding.initialize_relation_embedding.html index 0fbc006..e137d13 100644 --- a/generated/besskge.embedding.initialize_relation_embedding.html +++ b/generated/besskge.embedding.initialize_relation_embedding.html @@ -59,6 +59,7 @@
  • besskge.embedding.init_KGE_normal
  • besskge.embedding.init_KGE_uniform
  • besskge.embedding.init_uniform_norm
  • +
  • besskge.embedding.init_xavier_norm
  • besskge.embedding.initialize_entity_embedding
  • besskge.embedding.initialize_relation_embedding diff --git a/generated/besskge.scoring.ComplEx.html b/generated/besskge.scoring.ComplEx.html index 2354795..eceab6d 100644 --- a/generated/besskge.scoring.ComplEx.html +++ b/generated/besskge.scoring.ComplEx.html @@ -18,7 +18,7 @@ - + @@ -59,6 +59,7 @@
  • ComplEx
  • +
  • besskge.scoring.ConvE
  • besskge.scoring.DistMult
  • besskge.scoring.DistanceBasedScoreFunction
  • besskge.scoring.InterHT
  • @@ -122,7 +123,7 @@

    besskge.scoring.ComplEx

    embedding_size (int) – Complex size of entity and relation embeddings.

  • entity_initializer (Union[Tensor, List[Callable[..., Tensor]]]) – Initialization function or table for entity embeddings.

  • relation_initializer (Union[Tensor, List[Callable[..., Tensor]]]) – Initialization function or table for relation embeddings.

  • -
  • inverse_relations (bool) – If True, learn embeddings for inverse relations. Default: False

  • +
  • inverse_relations (bool) – If True, learn embeddings for inverse relations. Default: False.

  • @@ -315,7 +316,7 @@

    besskge.scoring.ComplEx

    diff --git a/generated/besskge.scoring.ConvE.html b/generated/besskge.scoring.ConvE.html new file mode 100644 index 0000000..523e5f4 --- /dev/null +++ b/generated/besskge.scoring.ConvE.html @@ -0,0 +1,367 @@ + + + + + + + besskge.scoring.ConvE — BESS-KGE documentation + + + + + + + + + + + + + + + + +
    + + +
    + +
    +
    +
    + +
    +
    +
    +
    + +
    +

    besskge.scoring.ConvE

    +
    +
    +class besskge.scoring.ConvE(negative_sample_sharing, sharding, n_relation_type, embedding_size, embedding_height, embedding_width, entity_initializer=[<function init_xavier_norm>, <function zeros_>], relation_initializer=[<function init_xavier_norm>], inverse_relations=True, input_channels=1, output_channels=32, kernel_height=3, kernel_width=3, input_dropout=0.2, feature_map_dropout=0.2, hidden_dropout=0.3, batch_normalization=True)[source]
    +

    ConvE scoring function [DPPR18].

    +

    Note that, differently from [DPPR18], the scores returned by this class +have not been passed through a final sigmoid layer, as we assume that this is +included in the loss function.

    +

    By design, this scoring function should be used in combination with a +negative/candidate sampler that only corrupts tails (possibly after +including all inverse triples in the dataset, see the add_inverse_triples +argument in besskge.sharding.PartitionedTripleSet.create_from_dataset()).

    +

    Initialize ConvE model.

    +
    +
    Parameters:
    +
      +
    • negative_sample_sharing (bool) – see DistanceBasedScoreFunction.__init__()

    • +
    • sharding (Sharding) – Entity sharding.

    • +
    • n_relation_type (int) – Number of relation types in the knowledge graph.

    • +
    • embedding_size (int) – Size of entity and relation embeddings.

    • +
    • embedding_height (int) – Height of the 2D-reshaping of the concatenation of +head and relation embeddings.

    • +
    • embedding_width (int) – Width of the 2D-reshaping of the concatenation of +head and relation embeddings.

    • +
    • entity_initializer (Union[Tensor, List[Callable[..., Tensor]]]) – Initialization functions or table for entity embeddings. +If not passing a table, two functions are needed: the initializer +for entity embeddings and initializer for (scalar) tail biases.

    • +
    • relation_initializer (Union[Tensor, List[Callable[..., Tensor]]]) – Initialization function or table for relation embeddings.

    • +
    • inverse_relations (bool) – If True, learn embeddings for inverse relations. Default: True.

    • +
    • input_channels (int) – Number of input channels of the Conv2D operator. Default: 1.

    • +
    • output_channels (int) – Number of output channels of the Conv2D operator. Default: 32.

    • +
    • kernel_height (int) – Height of the Conv2D kernel. Default: 3.

    • +
    • kernel_width (int) – Width of the Conv2D kernel. Default: 3.

    • +
    • input_dropout (float) – Rate of Dropout applied before the convolution. Default: 0.2.

    • +
    • feature_map_dropout (float) – Rate of Dropout applied after the convolution. Default: 0.2.

    • +
    • hidden_dropout (float) – Rate of Dropout applied after the Linear layer. Default: 0.3.

    • +
    • batch_normalization (bool) – If True, apply batch normalization before and after the +convolution and after the Linear layer. Default: True.

    • +
    +
    +
    +
    +
    +broadcasted_dot_product(v1, v2)
    +

    Broadcasted dot product of queries against sets of entities.

    +

    For each query and candidate, computes the dot product of +the embeddings.

    +
    +
    Parameters:
    +
      +
    • v1 (Tensor) – shape: (batch_size, embedding_size) +Batch queries.

    • +
    • v2 (Tensor) – shape: (B, n_neg, embedding_size) with B = 1, batch_size +Negative embeddings to score against queries.

    • +
    +
    +
    Return type:
    +

    Tensor

    +
    +
    Returns:
    +

    shape: (batch_size, B * n_neg) if +BaseScoreFunction.negative_sample_sharing +else (batch_size, n_neg)

    +
    +
    +
    + +
    +
    +entity_embedding: Parameter
    +

    Entity embedding table

    +
    + +
    +
    +forward(head_emb, relation_id, tail_emb)
    +

    see BaseScoreFunction.score_triple()

    +
    +
    Return type:
    +

    Tensor

    +
    +
    Parameters:
    +
    +
    +
    +
    + +
    +
    +negative_sample_sharing: bool
    +

    Share negative entities to construct negative samples

    +
    + +
    +
    +reduce_embedding(v)
    +

    Sum reduction along the embedding dimension.

    +
    +
    Parameters:
    +

    v (Tensor) – shape: (*, embedding_size) +The tensor to reduce.

    +
    +
    Return type:
    +

    Tensor

    +
    +
    Returns:
    +

    shape: (*,) +Sum reduction.

    +
    +
    +
    + +
    +
    +relation_embedding: Parameter
    +

    Relation embedding table

    +
    + +
    +
    +score_heads(head_emb, relation_id, tail_emb)[source]
    +

    Score sets of head entities against fixed (r,t) queries.

    +
    +
    Parameters:
    +
      +
    • head_emb (Tensor) – shape: (B, n_heads, embedding_size) with B = 1, batch_size +Embeddings of head entities.

    • +
    • relation_id (Tensor) – shape: (batch_size,) +IDs of relation types in batch.

    • +
    • tail_emb (Tensor) – shape: (batch_size, embedding_size) +Embedding of tail entities in batch.

    • +
    +
    +
    Return type:
    +

    Tensor

    +
    +
    Returns:
    +

    shape: (batch_size, B * n_heads) +if BaseScoreFunction.negative_sample_sharing +else (batch_size, n_heads). +Scores of broadcasted triples.

    +
    +
    +
    + +
    +
    +score_tails(head_emb, relation_id, tail_emb)[source]
    +

    Score sets of tail entities against fixed (h,r) queries.

    +
    +
    Parameters:
    +
      +
    • head_emb (Tensor) – shape: (batch_size, embedding_size) +Embeddings of head entities in batch.

    • +
    • relation_id (Tensor) – shape: (batch_size,) +IDs of relation types in batch.

    • +
    • tail_emb (Tensor) – shape: (B, n_tails, embedding_size) with B = 1, batch_size +Embedding of tail entities.

    • +
    +
    +
    Return type:
    +

    Tensor

    +
    +
    Returns:
    +

    shape: (batch_size, B * n_tails) +if BaseScoreFunction.negative_sample_sharing +else (batch_size, n_tails) +Scores of broadcasted triples.

    +
    +
    +
    + +
    +
    +score_triple(head_emb, relation_id, tail_emb)[source]
    +

    Score a batch of (h,r,t) triples.

    +
    +
    Parameters:
    +
      +
    • head_emb (Tensor) – shape: (batch_size, embedding_size) +Embeddings of head entities in batch.

    • +
    • relation_id (Tensor) – shape: (batch_size,) +IDs of relation types in batch.

    • +
    • tail_emb (Tensor) – shape: (batch_size, embedding_size) +Embeddings of tail entities in batch.

    • +
    +
    +
    Return type:
    +

    Tensor

    +
    +
    Returns:
    +

    shape: (batch_size,) +Scores of a batch of triples.

    +
    +
    +
    + +
    +
    +sharding: Sharding
    +

    Sharding of entities

    +
    + +
    +
    +update_sharding(new_sharding)
    +

    Change the sharding of the entity embedding table.

    +
    +
    Parameters:
    +

    new_sharding (Sharding) – The new entity sharding.

    +
    +
    Return type:
    +

    None

    +
    +
    +
    + +
    + +
    + + +
    +
    + +
    +
    +
    +
    + + + + \ No newline at end of file diff --git a/generated/besskge.scoring.DistMult.html b/generated/besskge.scoring.DistMult.html index 5e107f8..a133b02 100644 --- a/generated/besskge.scoring.DistMult.html +++ b/generated/besskge.scoring.DistMult.html @@ -19,7 +19,7 @@ - + @@ -56,6 +56,7 @@
  • besskge.scoring.BaseScoreFunction
  • besskge.scoring.BoxE
  • besskge.scoring.ComplEx
  • +
  • besskge.scoring.ConvE
  • besskge.scoring.DistMult @@ -122,7 +123,7 @@

    besskge.scoring.DistMultint) – Size of entity and relation embeddings.

  • entity_initializer (Union[Tensor, List[Callable[..., Tensor]]]) – Initialization function or table for entity embeddings.

  • relation_initializer (Union[Tensor, List[Callable[..., Tensor]]]) – Initialization function or table for relation embeddings.

  • -
  • inverse_relations (bool) – If True, learn embeddings for inverse relations. Default: False

  • +
  • inverse_relations (bool) – If True, learn embeddings for inverse relations. Default: False.

  • @@ -314,7 +315,7 @@

    besskge.scoring.DistMult - +

    diff --git a/generated/besskge.scoring.DistanceBasedScoreFunction.html b/generated/besskge.scoring.DistanceBasedScoreFunction.html index 1a795bd..a32fdf9 100644 --- a/generated/besskge.scoring.DistanceBasedScoreFunction.html +++ b/generated/besskge.scoring.DistanceBasedScoreFunction.html @@ -56,6 +56,7 @@
  • besskge.scoring.BaseScoreFunction
  • besskge.scoring.BoxE
  • besskge.scoring.ComplEx
  • +
  • besskge.scoring.ConvE
  • besskge.scoring.DistMult
  • besskge.scoring.DistanceBasedScoreFunction diff --git a/generated/besskge.scoring.RotatE.html b/generated/besskge.scoring.RotatE.html index 9606fbe..4d010d4 100644 --- a/generated/besskge.scoring.RotatE.html +++ b/generated/besskge.scoring.RotatE.html @@ -56,6 +56,7 @@
  • besskge.scoring.BaseScoreFunction
  • besskge.scoring.BoxE
  • besskge.scoring.ComplEx
  • +
  • besskge.scoring.ConvE
  • besskge.scoring.DistMult
  • besskge.scoring.DistanceBasedScoreFunction
  • besskge.scoring.InterHT
  • @@ -124,7 +125,7 @@

    besskge.scoring.RotatE
  • entity_initializer (Union[Tensor, List[Callable[..., Tensor]]]) – Initialization function or table for entity embeddings.

  • relation_initializer (Union[Tensor, List[Callable[..., Tensor]]]) – Initialization function or table for relation embeddings.

  • -
  • inverse_relations (bool) – If True, learn embeddings for inverse relations. Default: False

  • +
  • inverse_relations (bool) – If True, learn embeddings for inverse relations. Default: False.

  • diff --git a/generated/besskge.scoring.TranS.html b/generated/besskge.scoring.TranS.html index 280e2e1..d9b3571 100644 --- a/generated/besskge.scoring.TranS.html +++ b/generated/besskge.scoring.TranS.html @@ -56,6 +56,7 @@
  • besskge.scoring.BaseScoreFunction
  • besskge.scoring.BoxE
  • besskge.scoring.ComplEx
  • +
  • besskge.scoring.ConvE
  • besskge.scoring.DistMult
  • besskge.scoring.DistanceBasedScoreFunction
  • besskge.scoring.InterHT
  • @@ -126,7 +127,7 @@

    besskge.scoring.TranS

    normalize_entities (bool) – If True, L2-normalize embeddings of head and tail entities as well as tilde head and tail entities before multiplying. Default: True.

  • offset (float) – Offset applied to tilde entity embeddings. Default: 1.0.

  • -
  • inverse_relations (bool) – If True, learn embeddings for inverse relations. Default: False

  • +
  • inverse_relations (bool) – If True, learn embeddings for inverse relations. Default: False.

  • diff --git a/generated/besskge.scoring.TransE.html b/generated/besskge.scoring.TransE.html index 9046559..8a9df7f 100644 --- a/generated/besskge.scoring.TransE.html +++ b/generated/besskge.scoring.TransE.html @@ -56,6 +56,7 @@
  • besskge.scoring.BaseScoreFunction
  • besskge.scoring.BoxE
  • besskge.scoring.ComplEx
  • +
  • besskge.scoring.ConvE
  • besskge.scoring.DistMult
  • besskge.scoring.DistanceBasedScoreFunction
  • besskge.scoring.InterHT
  • @@ -123,7 +124,7 @@

    besskge.scoring.TransE

    embedding_size (int) – Size of entity and relation embeddings.

  • entity_initializer (Union[Tensor, List[Callable[..., Tensor]]]) – Initialization function or table for entity embeddings.

  • relation_initializer (Union[Tensor, List[Callable[..., Tensor]]]) – Initialization function or table for relation embeddings.

  • -
  • inverse_relations (bool) – If True, learn embeddings for inverse relations. Default: False

  • +
  • inverse_relations (bool) – If True, learn embeddings for inverse relations. Default: False.

  • diff --git a/generated/besskge.scoring.TripleRE.html b/generated/besskge.scoring.TripleRE.html index 994fd02..35b2d9c 100644 --- a/generated/besskge.scoring.TripleRE.html +++ b/generated/besskge.scoring.TripleRE.html @@ -56,6 +56,7 @@
  • besskge.scoring.BaseScoreFunction
  • besskge.scoring.BoxE
  • besskge.scoring.ComplEx
  • +
  • besskge.scoring.ConvE
  • besskge.scoring.DistMult
  • besskge.scoring.DistanceBasedScoreFunction
  • besskge.scoring.InterHT
  • @@ -127,7 +128,7 @@

    besskge.scoring.TripleREfloat) – Offset factor for head/tail relation projections, as in TripleREv2. Default: 0.0 (no offset).

    -
  • inverse_relations (bool) – If True, learn embeddings for inverse relations. Default: False

  • +
  • inverse_relations (bool) – If True, learn embeddings for inverse relations. Default: False.

  • diff --git a/generated/besskge.scoring.html b/generated/besskge.scoring.html index 56fcc73..55e0406 100644 --- a/generated/besskge.scoring.html +++ b/generated/besskge.scoring.html @@ -56,6 +56,7 @@
  • besskge.scoring.BaseScoreFunction
  • besskge.scoring.BoxE
  • besskge.scoring.ComplEx
  • +
  • besskge.scoring.ConvE
  • besskge.scoring.DistMult
  • besskge.scoring.DistanceBasedScoreFunction
  • besskge.scoring.InterHT
  • @@ -118,32 +119,35 @@

    ComplEx(negative_sample_sharing, sharding, ...)

    ComplEx scoring function [TWR+16].

    -

    DistMult(negative_sample_sharing, sharding, ...)

    -

    DistMult scoring function [YYH+15].

    +

    ConvE(negative_sample_sharing, sharding, ...)

    +

    ConvE scoring function [DPPR18].

    -

    DistanceBasedScoreFunction(...)

    +

    DistMult(negative_sample_sharing, sharding, ...)

    +

    DistMult scoring function [YYH+15].

    + +

    DistanceBasedScoreFunction(...)

    Base class for distance-based scoring functions.

    -

    InterHT(negative_sample_sharing, ...[, ...])

    -

    InterHT scoring function [WMW+22].

    +

    InterHT(negative_sample_sharing, ...[, ...])

    +

    InterHT scoring function [WMW+22].

    -

    MatrixDecompositionScoreFunction(...)

    +

    MatrixDecompositionScoreFunction(...)

    Base class for matrix-decomposition scoring functions.

    -

    PairRE(negative_sample_sharing, ...[, ...])

    -

    PairRE scoring function [CHWC21].

    +

    PairRE(negative_sample_sharing, ...[, ...])

    +

    PairRE scoring function [CHWC21].

    -

    RotatE(negative_sample_sharing, ...[, ...])

    -

    RotatE scoring function [SDNT19].

    +

    RotatE(negative_sample_sharing, ...[, ...])

    +

    RotatE scoring function [SDNT19].

    -

    TranS(negative_sample_sharing, scoring_norm, ...)

    -

    TranS scoring function [ZYX22].

    +

    TranS(negative_sample_sharing, scoring_norm, ...)

    +

    TranS scoring function [ZYX22].

    -

    TransE(negative_sample_sharing, ...[, ...])

    -

    TransE scoring function [BUGD+13].

    +

    TransE(negative_sample_sharing, ...[, ...])

    +

    TransE scoring function [BUGD+13].

    -

    TripleRE(negative_sample_sharing, ...[, ...])

    -

    TripleRE scoring function [YLL+22].

    +

    TripleRE(negative_sample_sharing, ...[, ...])

    +

    TripleRE scoring function [YLL+22].

    diff --git a/genindex.html b/genindex.html index e3be28c..30d510a 100644 --- a/genindex.html +++ b/genindex.html @@ -181,8 +181,6 @@

    B

  • module
  • - -
    • besskge.scoring @@ -190,6 +188,8 @@

      B

    • module
    + + - +