ImplicitALSWrapperModel

class rectools.models.implicit_als.ImplicitALSWrapperModel(model: Union[AlternatingLeastSquares, AlternatingLeastSquares], fit_features_together: bool = False, recommend_n_threads: Optional[int] = None, recommend_use_gpu_ranking: Optional[bool] = None, verbose: int = 0)[source]

Bases: VectorModel[ImplicitALSWrapperModelConfig]

Wrapper for implicit.als.AlternatingLeastSquares with possibility to use explicit features and GPU support.

See https://implicit.readthedocs.io/en/latest/als.html for details of base model.

Parameters
  • model (AnyAlternatingLeastSquares) – Base model that will be used.

  • fit_features_together (bool, default False) – Whether fit explicit features together with latent features or not. Used only if explicit features are present in dataset. See documentations linked above for details.

  • 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.

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

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.

get_config([mode, simple_types])

Return model config.

get_params([simple_types, sep])

Return model parameters.

get_vectors()

Return user and item vector representations 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

u2i_dist

config_class

alias of ImplicitALSWrapperModelConfig

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

Return user and item vector representations from fitted model.

Returns

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

Return type

(np.ndarray, np.ndarray)