cross_e_interaction

cross_e_interaction(h, r, c_r, t, bias, activation, dropout=None)[source]

Evaluate the interaction function of CrossE for the given representations from [zhang2019b].

\[Dropout(Activation(c_r \odot h + c_r \odot h \odot r + b))^T t)\]

Note

The representations have to be in a broadcastable shape.

Note

The CrossE paper described an additional sigmoid activation as part of the interaction function. Since using a log-likelihood loss can cause numerical problems (due to explicitly calling sigmoid before log), we do not apply this in our implementation but rather opt for the numerically stable variant. However, the model itself has an option predict_with_sigmoid, which can be used to enforce application of sigmoid during inference. This can also have an impact of rank-based evaluation, since limited numerical precision can lead to exactly equal scores for multiple choices. The definition of a rank is not unambiguous in such case, and there exist multiple competing variants how to break the ties. More information on this can be found in the documentation of rank-based evaluation.

Parameters:
  • h (FloatTensor) – shape: (*batch_dims, dim) The head representations.

  • r (FloatTensor) – shape: (*batch_dims, dim) The relation representations.

  • c_r (FloatTensor) – shape: (*batch_dims, dim) The relation-specific interaction vector.

  • t (FloatTensor) – shape: (*batch_dims, dim) The tail representations.

  • bias (FloatTensor) – shape: (dim,) The combination bias.

  • activation (Module) – The combination activation. Should be torch.nn.Tanh for consistency with the CrossE paper.

  • dropout (Optional[Dropout]) – Dropout applied after the combination.

Return type:

FloatTensor

Returns:

shape: batch_dims The scores.