ImplicitRanker
- class rectools.models.rank.ImplicitRanker(distance: Distance, subjects_factors: Union[ndarray, csr_matrix], objects_factors: ndarray)[source]
Bases:
object
Ranker model which uses implicit library matrix factorization topk method.
This ranker is suitable for the following cases of scores calculation: 1. subject_embeddings.dot(objects_embeddings) 2. subject_interactions.dot(item-item-similarities)
- Parameters
distance (Distance) – Distance metric.
subjects_factors (np.ndarray | sparse.csr_matrix) – Array of subjects embeddings, shape (n_subjects, n_factors). For item-item similarity models subjects vectors from ui_csr are viewed as factors.
objects_factors (np.ndarray) – Array with embeddings of all objects, shape (n_objects, n_factors). For item-item similarity models item similarity vectors are viewed as factors.
- Inherited-members
Methods
rank
(subject_ids, k[, filter_pairs_csr, ...])Rank objects to proceed inference using implicit library topk cpu method.
- rank(subject_ids: Union[Sequence[int], ndarray], k: int, filter_pairs_csr: Optional[csr_matrix] = None, sorted_object_whitelist: Optional[ndarray] = None, num_threads: int = 0) Tuple[Union[Sequence[int], ndarray], Union[Sequence[int], ndarray], Union[Sequence[float], ndarray]] [source]
Rank objects to proceed inference using implicit library topk cpu method.
- Parameters
subject_ids (csr_matrix) – Array of ids to recommend for.
k (int) – Derived number of recommendations for every subject id.
filter_pairs_csr (sparse.csr_matrix, optional, default
None
) – Subject-object interactions that should be filtered from recommendations. This is relevant for u2i case.sorted_object_whitelist (sparse.csr_matrix, optional, default
None
) – Whitelist of object ids. If given, only these items will be used for recommendations. Otherwise all items from dataset will be used.num_threads (int, default 0) – Will be used as num_threads parameter for implicit.cpu.topk.topk.
- Returns
Array of subject ids, array of recommended items, sorted by score descending and array of scores.
- Return type
(InternalIds, InternalIds, Scores)