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

Fit callback in BPR model #590

Merged
merged 11 commits into from
Aug 10, 2022
Merged

Fit callback in BPR model #590

merged 11 commits into from
Aug 10, 2022

Conversation

apat1n
Copy link
Contributor

@apat1n apat1n commented Jul 8, 2022

I found fit_callback in ALS implementation, but it can be also useful in BPR model. For example:

def calc_hitrate_callback(model: BayesianPersonalizedRanking, epoch: int) -> dict:
    if (epoch + 1) % VAL_PERIOD != 0:
        return {}
    
    recommendations = prepare_recommendations(model)
    hitrate_list = calc_hitrate(recommendations, val_dataset, K)
    return {f'mean hitrate@{K}': np.mean(hitrate_list).round(5)}

bpr_model.fit(train_dataset, fit_callback=calc_hitrate_callback)

@ita9naiwa
Copy link
Collaborator

Hi. Adding callback looks good to me, but
IMHO, I think it would be better to consider those two followings.

@apat1n
Copy link
Contributor Author

apat1n commented Jul 9, 2022

Hi! IMHO, I found it more useful if callback function will have straight access to model and that may be better for evaluation than ALS callback format. And if it would be in BPR.fit(), it could be found in API docs

@ita9naiwa
Copy link
Collaborator

I think your idea makes sense. however, it looks not good practice that same function (also sharing same name) has different behaviors in a different module.

So, considering that fit_callback is already implemented and being used for ALS, I think fit_callback should follow the same format as used in benchmark_als.py.

@ita9naiwa ita9naiwa self-requested a review July 11, 2022 02:49
Copy link
Collaborator

@ita9naiwa ita9naiwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my one suggestion is that it will be also good if ALS and other recommender models take fit_callback as an argument

implicit/cpu/bpr.pyx Outdated Show resolved Hide resolved
@apat1n apat1n requested a review from ita9naiwa July 12, 2022 07:57
@apat1n
Copy link
Contributor Author

apat1n commented Jul 12, 2022

That sounds good, also I kept backward compatibility in ALS model

Copy link
Collaborator

@ita9naiwa ita9naiwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@ita9naiwa ita9naiwa merged commit 9779c99 into benfred:main Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants