KGE.ns_strategy

Classes

NegativeSampler

A base module for negative sampler.

TypedStrategy

An implementation of typed negative sampling strategy.

UniformStrategy

An implementation of uniform negative sampling

Class Inheritance Diagram

Inheritance diagram of KGE.ns_strategy.NegativeSampler, KGE.ns_strategy.TypedStrategy, KGE.ns_strategy.UniformStrategy
class KGE.ns_strategy.NegativeSampler[source]

Bases: object

A base module for negative sampler.

Methods

__call__()

Confuct negative sampling

__init__()[source]

Initialized negative sampler

class KGE.ns_strategy.TypedStrategy[source]

Bases: KGE.ns_strategy.NegativeSampler

An 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, metadata should contains key 'ind2type' to indicate the entities’ type when calling train().

Methods

__call__(X, negative_ratio, side)

perform negative sampling

__init__(pool, metadata)[source]

Initialize TypedStrategy negative sampler.

Parameters
  • pool (multiprocessing.pool.Pool) – multiprocessing pool for parallel.

  • metadata (dict) – metadata that store the entities’ type information.

class KGE.ns_strategy.UniformStrategy[source]

Bases: KGE.ns_strategy.NegativeSampler

An 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

__init__(sample_pool)[source]

Initialize UniformStrategy negative sampler.

Parameters

sample_pool (tf.Tensor) – entities pool that used to sample.