ImplicitBPRWrapperModel

class rectools.models.implicit_bpr.ImplicitBPRWrapperModel(model: Union[BayesianPersonalizedRanking, BayesianPersonalizedRanking], verbose: int = 0, recommend_n_threads: Optional[int] = None, recommend_use_gpu_ranking: Optional[bool] = None)[source]

Bases: VectorModel[ImplicitBPRWrapperModelConfig]

Wrapper for implicit.bpr.BayesianPersonalizedRanking model.

See https://benfred.github.io/implicit/api/models/cpu/bpr.html for details of the base model.

Please note that implicit BPR model training is not deterministic with num_threads > 1 or use_gpu=True. https://github.com/benfred/implicit/issues/710

Parameters
  • model (BayesianPersonalizedRanking) – Base model to wrap.

  • verbose (int, default 0) – Degree of verbose output. If 0, no output will be provided.

  • recommend_n_threads (Optional[int], default None) – Number of threads to use for recommendation ranking on CPU. Specifying 0 means to default to the number of cores on the machine. If None, then number of threads will be set same as model.num_threads. If you want to change this parameter after model is initialized, you can manually assign new value to model recommend_n_threads attribute.

  • recommend_use_gpu_ranking (Optional[bool], default None) – Flag to use GPU for recommendation ranking. If None, then will be set same as model.use_gpu. implicit.gpu.HAS_CUDA will also be checked before inference. Please note that GPU and CPU ranking may provide different ordering of items with identical scores in recommendation table. If you want to change this parameter after model is initialized, you can manually assign new value to model recommend_use_gpu_ranking attribute.

Inherited-members

Methods

dumps()

Serialize model to bytes.

fit(dataset, *args, **kwargs)

Fit model.

fit_partial(dataset, *args, **kwargs)

Fit model.

from_config(config)

Create model from config.

from_params(params[, sep])

Create model from parameters.

get_config([mode, simple_types])

Return model config.

get_params([simple_types, sep])

Return model parameters.

get_vectors()

Return user and item vector representation from fitted model.

load(f)

Load model from file.

loads(data)

Load model from bytes.

recommend(users, dataset, k, filter_viewed)

Recommend items for users.

recommend_to_items(target_items, dataset, k)

Recommend items for target items.

save(f)

Save model to file.

Attributes

i2i_dist

recommends_for_cold

recommends_for_warm

require_recommend_context

Indicates whether recommendation context is required for predictions.

u2i_dist

config_class

alias of ImplicitBPRWrapperModelConfig

get_vectors() Tuple[ndarray, ndarray][source]

Return user and item vector representation from fitted model.

Returns

User and item vectors. Shapes are (n_users, n_factors) and (n_items, n_factors).

Return type

(np.ndarray, np.ndarray)