Filterer

class Filterer(*args, **kwargs)[source]

Bases: Module

An interface for filtering methods for negative triples.

Initialize internal Module state, shared by both nn.Module and ScriptModule.

Methods Summary

contains(batch)

Check whether a triple is contained.

forward(negative_batch)

Filter all proposed negative samples that are positive in the training dataset.

Methods Documentation

abstract contains(batch: Tensor) Tensor[source]

Check whether a triple is contained.

Supports batching.

Parameters:

batch (Tensor) – shape (batch_size, 3) The batch of triples.

Returns:

shape: (batch_size,) Whether the triples are contained in the training triples.

Return type:

Tensor

forward(negative_batch: Tensor) Tensor[source]

Filter all proposed negative samples that are positive in the training dataset.

Normally there is a low probability that proposed negative samples are positive in the training datasets and thus act as false negatives. This is expected to act as a kind of regularization, since it adds noise signal to the training data. However, the degree of regularization is hard to control since the added noise signal depends on the ratio of true triples for a given entity relation or entity entity pair. Therefore, the effects are hard to control and a researcher might want to exclude the possibility of having false negatives in the proposed negative triples.

Note

Filtering is a very expensive task, since every proposed negative sample has to be checked against the entire training dataset.

Parameters:

negative_batch (Tensor) – shape: (batch_size, num_negatives, 3) The batch of negative triples.

Returns:

shape: (batch_size, num_negatives) A mask, where True indicates that the negative sample is valid.

Return type:

Tensor