AutoSFInteraction
- class AutoSFInteraction(coefficients)[source]
Bases:
FunctionalInteraction
[HeadRepresentation
,RelationRepresentation
,TailRepresentation
]An implementation of the AutoSF interaction as described by [zhang2020].
Initialize the interaction function.
- Parameters
coefficients (
Sequence
[Tuple
[int
,int
,int
,Literal
[-1, 1]]]) –- the coefficients, in order:
head_representation_index,
relation_representation_index,
tail_representation_index,
sign
- Raises
ValueError – if there are duplicate coefficients
Methods Summary
extend
(*new_coefficients)Extend AutoSF function, as described in the greedy search algorithm in the paper.
from_searched_sf
(coefficients)Instantiate AutoSF interaction from the "official" serialization format.
func
(r, t, coefficients)Evaluate an AutoSF-style interaction function as described by [zhang2020].
Create the LaTeX + tikz visualization as shown in the paper.
Methods Documentation
- extend(*new_coefficients)[source]
Extend AutoSF function, as described in the greedy search algorithm in the paper.
- classmethod from_searched_sf(coefficients)[source]
Instantiate AutoSF interaction from the “official” serialization format.
> The first 4 values (a,b,c,d) represent h_1 * r_1 * t_a + h_2 * r_2 * t_b + h_3 * r_3 * t_c + h_4 * r_4 * t_d. > For the others, every 4 values represent one adding block: index of r, index of h, index of t, the sign s.
- func(r, t, coefficients)
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.
pykeen.models.DistMult
: one block, \(\mathcal{C} = \{(0, 0, 0, 1)\}\)pykeen.models.ComplEx
: two blocks, \(\mathcal{C} = \{(0, 0, 0, 1), (0, 1, 1, 1), (1, 0, 1, -1), (1, 0, 1, 1)\}\)pykeen.models.SimplE
: two blocks: \(\mathcal{C} = \{(0, 0, 1, 1), (1, 1, 0, 1)\}\)
- Parameters
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:
head_representation_index,
relation_representation_index,
tail_representation_index,
sign
- Return type
FloatTensor
- Returns
The scores