auto_sf_interaction(h, r, t, coefficients)[source]

Evaluate an AutoSF-style interaction function as described by [zhang2020].

This interaction function is a parametrized way to express bi-linear models with block structure. It divides the entity and relation representations into blocks, and expresses the interaction as a sequence of 4-tuples \((i_h, i_r, i_t, s)\), where \(i_h, i_r, i_t\) index a _block_ of the head, relation, or tail representation, and \(s \in {-1, 1}\) is the sign.

The interaction function is then given as

\[\sum_{(i_h, i_r, i_t, s) \in \mathcal{C}} s \cdot \langle h[i_h], r[i_r], t[i_t] \rangle\]

where \(\langle \cdot, \cdot, \cdot \rangle\) denotes the tri-linear dot product.

This parametrization allows to express several well-known interaction functions, e.g.

  • h (Sequence[FloatTensor]) – each shape: (*batch_dims, rank, dim) The list of head representations.

  • r (Sequence[FloatTensor]) – each shape: (*batch_dims, rank, dim) The list of relation representations.

  • t (Sequence[FloatTensor]) – each shape: (*batch_dims, rank, dim) The list of tail representations.

  • coefficients (Sequence[Tuple[int, int, int, Literal[-1, 1]]]) –

    the coefficients, in order:

    1. head_representation_index,

    2. relation_representation_index,

    3. tail_representation_index,

    4. sign

Return type



The scores