Models¶
This module includes neural graph embedding models and support functions.
Knowledge graph embedding models are neural architectures that encode concepts from a knowledge graph (i.e. entities \(\mathcal{E}\) and relation types \(\mathcal{R}\)) into lowdimensional, continuous vectors \(\in \mathcal{R}^k\). Such knowledge graph embeddings have applications in knowledge graph completion, entity resolution, and linkbased clustering, just to cite a few [NMTG16].
Knowledge Graph Embedding Models¶

Random baseline 

Translating Embeddings (TransE) 

The DistMult model 

Complex embeddings (ComplEx) 

Holographic Embeddings 

Convolutionbased model 
Anatomy of a Model¶
Knowledge graph embeddings are learned by training a neural architecture over a graph. Although such architectures vary, the training phase always consists in minimizing a loss function \(\mathcal{L}\) that includes a scoring function \(f_{m}(t)\), i.e. a modelspecific function that assigns a score to a triple \(t=(sub,pred,obj)\).
AmpliGraph models include the following components:
Scoring function \(f(t)\)
Loss function \(\mathcal{L}\)
AmpliGraph comes with a number of such components. They can be used in any combination to come up with a model that performs sufficiently well for the dataset of choice.
AmpliGraph features a number of abstract classes that can be extended to design new models:

Abstract class for embedding models 

Abstract class for loss function. 

Abstract class for Regularizer. 

Abstract class for initializer . 
Scoring functions¶
Existing models propose scoring functions that combine the embeddings \(\mathbf{e}_{s},\mathbf{r}_{p}, \mathbf{e}_{o} \in \mathcal{R}^k\) of the subject, predicate, and object of a triple \(t=(s,p,o)\) according to different intuitions:
TransE
[BUGD+13] relies on distances. The scoring function computes a similarity between the embedding of the subject translated by the embedding of the predicate and the embedding of the object, using the \(L_1\) or \(L_2\) norm \(\cdot\):
Loss Functions¶
AmpliGraph includes a number of loss functions commonly used in literature. Each function can be used with any of the implemented models. Loss functions are passed to models as hyperparameter, and they can be thus used during model selection.

Pairwise, maxmargin loss. 

Absolute margin , maxmargin loss. 

Self adversarial sampling loss. 

Negative loglikelihood loss. 

Multiclass NLL Loss. 
Regularizers¶
AmpliGraph includes a number of regularizers that can be used with the loss function.
LPRegularizer
supports L1, L2, and L3.

Performs LP regularization 
Initializers¶
AmpliGraph includes a number of initializers that can be used to initialize the embeddings. They can be passed as hyperparameter, and they can be thus used during model selection.

Initializes from a normal distribution with specified 

Initializes from a uniform distribution with specified 

Follows the xavier strategy for initialization of layers [GB10]. 
Optimizers¶
The goal of the optimization procedure is learning optimal embeddings, such that the scoring function is able to assign high scores to positive statements and low scores to statements unlikely to be true.
We support SGDbased optimizers provided by TensorFlow, by setting the optimizer
argument in a model initializer.
Best results are currently obtained with Adam.