Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added num_item_blocks and num_user_blocks params to ALSWrap #52

Open
wants to merge 4 commits into
base: sb-main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions replay/models/als.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,31 @@ class ALSWrap(Recommender, ItemVectorModel):
"rank": {"type": "loguniform_int", "args": [8, 256]},
}

# pylint: disable=too-many-arguments
def __init__(
self,
rank: int = 10,
implicit_prefs: bool = True,
seed: Optional[int] = None,
num_item_blocks: Optional[int] = None,
num_user_blocks: Optional[int] = None,
):
"""
:param rank: hidden dimension for the approximate matrix
:param implicit_prefs: flag to use implicit feedback
:param seed: random seed
:param num_item_blocks: number of blocks the items will be partitioned into in order
to parallelize computation.
if None then will be init with number of partitions of log.
:param num_user_blocks: number of blocks the users will be partitioned into in order
to parallelize computation.
if None then will be init with number of partitions of log.
"""
self.rank = rank
self.implicit_prefs = implicit_prefs
self._seed = seed
self._num_item_blocks = num_item_blocks
self._num_user_blocks = num_user_blocks

@property
def _init_args(self):
Expand All @@ -57,8 +68,15 @@ def _fit(
user_features: Optional[DataFrame] = None,
item_features: Optional[DataFrame] = None,
) -> None:
if self._num_item_blocks is None:
self._num_item_blocks = log.rdd.getNumPartitions()
if self._num_user_blocks is None:
self._num_user_blocks = log.rdd.getNumPartitions()

self.model = ALS(
rank=self.rank,
numItemBlocks=self._num_item_blocks,
numUserBlocks=self._num_user_blocks,
userCol="user_idx",
itemCol="item_idx",
ratingCol="relevance",
Expand Down