Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions lightfm/_lightfm_fast.pyx.template
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ cdef class FastLightFM:
cdef double item_scale
cdef double user_scale

cdef readonly double avg_loss
cdef int avg_loss_ctr

def __init__(self,
flt[:, ::1] item_features,
flt[:, ::1] item_feature_gradients,
Expand Down Expand Up @@ -258,6 +261,9 @@ cdef class FastLightFM:

self.max_sampled = max_sampled

self.avg_loss = 0.0
self.avg_loss_ctr = 0


cdef inline flt sigmoid(flt v) nogil:
"""
Expand Down Expand Up @@ -533,6 +539,9 @@ cdef inline void update(double loss,
lightfm.item_scale *= (1.0 + item_alpha * avg_learning_rate)
lightfm.user_scale *= (1.0 + user_alpha * avg_learning_rate)

lightfm.avg_loss_ctr += 1
lightfm.avg_loss = (lightfm.avg_loss * (lightfm.avg_loss_ctr - 1) + loss) / lightfm.avg_loss_ctr


cdef void warp_update(double loss,
CSRMatrix item_features,
Expand Down Expand Up @@ -648,6 +657,9 @@ cdef void warp_update(double loss,
lightfm.item_scale *= (1.0 + item_alpha * avg_learning_rate)
lightfm.user_scale *= (1.0 + user_alpha * avg_learning_rate)

lightfm.avg_loss_ctr += 1
lightfm.avg_loss = (lightfm.avg_loss * (lightfm.avg_loss_ctr - 1) + loss) / lightfm.avg_loss_ctr


cdef void regularize(FastLightFM lightfm,
double item_alpha,
Expand Down
Loading