Models¶
This package implements the knowledge embedding models. Model
is the base model. We have implemented seven classic knowledge embedding models.
models.TransE
models.TransH
models.TransR
models.TransD
models.RESCAL
models.DistMult
models.ComplEx
Base Model¶
-
class
models.
Model
(config)[source]¶ The base model for knowledge embedding
Parameters: config – the instance of class config.Config.Config
-
get_all_instance
()[source]¶ This method gets all samples from batch, including positive samples and negative samples
Returns: [self.batch_h, self.batch_t, self.batch_y], the shape is [batch_size * (1 + negative_ent + negative_rel)] Return type: list
-
get_all_labels
()[source]¶ This method gets all labels for the samples,
1
for positive triples and-1
for negative triplesReturns: self.batch_y, the shape is [batch_size * (1 + negative_ent + negative_rel)] Return type: Variable
-
TransE¶
-
class
models.
TransE
(config)[source]¶ THis class implements TransE model based on
models.Model
Parameters: config – configuration information - Shape:
- Output: loss value which is a scalar
TransH¶
-
class
models.
TransH
(config)[source]¶ THis class implements TransH model based on
models.Model
Parameters: config – configuration information - Shape:
- Output: loss value which is a scalar
TransR¶
-
class
models.
TransR
(config)[source]¶ THis class implements Transr model based on
models.Model
Parameters: config – configuration information - Shape:
- Output: loss value which is a scalar
TransD¶
-
class
models.
TransD
(config)[source]¶ THis class implements TransD model based on
models.Model
Parameters: config – configuration information - Shape:
- Output: loss value which is a scalar
RESCAL¶
-
class
models.
RESCAL
(config)[source]¶ THis class implements RESCAL model based on
models.Model
Parameters: config – configuration information - Shape:
- Output: loss value which is a scalar
DistMult¶
-
class
models.
DistMult
(config)[source]¶ THis class implements DistMult model based on
models.Model
Parameters: config – configuration information - Shape:
- Output: loss value which is a scalar
ComplEx¶
-
class
models.
ComplEx
(config)[source]¶ THis class implements ComplEx model based on
models.Model
Parameters: config – configuration information - Shape:
- Output: loss value which is a scalar