KGE.ns_strategy
Classes
A base module for negative sampler. |
|
An implementation of typed negative sampling strategy. |
|
An implementation of uniform negative sampling |
Class Inheritance Diagram

- class KGE.ns_strategy.NegativeSampler[source]
Bases:
objectA base module for negative sampler.
Methods
__call__()Confuct negative sampling
- class KGE.ns_strategy.TypedStrategy[source]
Bases:
KGE.ns_strategy.NegativeSamplerAn implementation of typed negative sampling strategy.
Typed negative sampling consider the entities’ type, for example, for the positive triplet \((MonaLisa, is\_in, Louvre)\), we may generate illogical negative triplet such as \((MonaLis, is\_in, DaVinci)\). So Typed negative sampling strategy consider the type of entity to be corrupt, if we want to replace Louvre, we only sample the entities which have same type with Louvre.
Caution
When using
TypedStrategy,metadatashould contains key'ind2type'to indicate the entities’ type when callingtrain().Methods
__call__(X, negative_ratio, side)perform negative sampling
- class KGE.ns_strategy.UniformStrategy[source]
Bases:
KGE.ns_strategy.NegativeSamplerAn implementation of uniform negative sampling
Uniform sampling is the most simple negative sampling strategy, usually is the default setting of knowledge graph embedding models. It sample entities from all entites with uniform distribution, and replaces either head or tail entity.
Methods
__call__(X, negative_ratio, side)perform negative sampling