besskge.utils.get_entity_filter
- besskge.utils.get_entity_filter(triples, filter_triples, filter_mode)[source]
Compare two sets of triples: for each triple (h,r,t) in the first set, find the entities e such that (e,r,t) (or (h,r,e), depending on filter_mode) appears in the second set of triples.
- Parameters:
triples (
Tensor
) – shape (x, 3) The set of triples to construct filters for.filter_triples (
Tensor
) – shape (y, 3) The set of triples determining the head/tail entities to filter.filter_mode (
str
) – Set to “h” to look for entities appearing as heads of the same (r,t) pair, or to “t” to look for entities appearing as tails of the same (h,r) pair.
- Return type:
- Returns:
shape (z, 2) The sparse filters. Each row is given by a tuple (i, j), with i the index of the triple in triples to which the filter applies to and j the global ID of the entity to filter.