AbstractScoringLayer¶
- class ampligraph.latent_features.layers.scoring.AbstractScoringLayer.AbstractScoringLayer(*args, **kwargs)¶
Abstract class for scoring layer.
Attributes
Methods
__init__(k)Initializes the scoring layer.
call(triples)Interface to the external world.
compute_output_shape(input_shape)Returns the output shape of the outputs of the call function.
Returns the config of the layer.
get_ranks(triples, ent_matrix, start_ent_id, ...)Computes the ranks of triples against their corruptions.
- __init__(k)¶
Initializes the scoring layer.
- Parameters:
k (int) – Embedding size.
- call(triples)¶
Interface to the external world. Computes the scores of the triples.
- Parameters:
triples (array-like, shape (n, 3)) – Batch of input triples.
- Returns:
scores – Tensor of scores of inputs.
- Return type:
tf.Tensor, shape (n,1)
- compute_output_shape(input_shape)¶
Returns the output shape of the outputs of the call function.
- Parameters:
input_shape (tuple) – Shape of inputs of call function.
- Returns:
output_shape – Shape of outputs of call function.
- Return type:
tuple
- get_config()¶
Returns the config of the layer.
A layer config is a Python dictionary (serializable) containing the configuration of a layer. The same layer can be reinstantiated later (without its trained weights) from this configuration.
The config of a layer does not include connectivity information, nor the layer class name. These are handled by Network (one layer of abstraction above).
Note that get_config() does not guarantee to return a fresh copy of dict every time it is called. The callers should make a copy of the returned dict if they want to modify it.
- Returns:
Python dictionary.
- get_ranks(triples, ent_matrix, start_ent_id, end_ent_id, filters, mapping_dict, corrupt_side='s,o', comparison_type='worst')¶
Computes the ranks of triples against their corruptions.
Ranks are computed by corrupting triple subject and/or object with the embeddings in ent_matrix.
- Parameters:
triples (array-like, shape (n, k)) – Batch of input embeddings.
ent_matrix (array-like, shape (m, k)) – Slice of embedding matrix (corruptions).
start_ent_id (int) – Original id of the first row of embedding matrix (used during partitioned approach).
end_ent_id (int) – Original id of the last row of embedding matrix (used during partitioned approach).
filters (list of lists) – Size of list is either 1 or 2 depending on
corrupt_side. Size of the internal list is equal to the size of the input triples. Each list contains an array of filters (True Positives) related to the specified side of triples to corrupt.corrupt_side (str) – Which side to corrupt during evaluation.
comparison_type (str) – Indicates how to break ties (default: worst, i.e., assigns the worst rank to the test triple). One of the three types can be passed: “best”, “middle”, “worst”.
- Returns:
ranks – Ranks of triple against subject and object corruptions (corruptions defined by ent_embs matrix).
- Return type:
tf.Tensor, shape (n,2)