TypedStrategy

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 Summary

__call__(X, negative_ratio, side)

perform negative sampling

Methods Documentation

__call__(X, negative_ratio, side)[source]

perform negative sampling

Parameters
  • X (tf.Tensor) – positive triplets to be corrupt.

  • negative_ratio (int) – number of negative sample.

  • side (str) – corrup from which side, can be 'h' or 't'

Returns

sampling entities

Return type

tf.Tensor

__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.

__new__(*args, **kwargs)