Python 'Implicit' package handleing matrix data differently on Ubuntu vs Manjaro

Viewed 24

environment info:

Ubuntu 22.04 -- Python 3.9.12

Manjaro 5.15.60-1 -- Python 3.9.7

I'm working on an implicit recommendation model using the 'implicit' python package. I recently ran into some dependency issues on my Manjaro file system. so while i figure that out i decided to boot up onto my Ubuntu 22.04 partition and work on it there. Unfortunately the code i had working on Manjaro is not producing the expected outcome on Ubuntu. so as a troubleshooting method i went ahead and used the implicit packages lastfm recommendation tutorial (https://benfred.github.io/implicit/tutorial_lastfm.html) to create a new notebook just to rule out any obvious user error.

'''

from implicit.datasets.lastfm import get_lastfm
artists, users, artist_user_plays = get_lastfm()
    
from implicit.nearest_neighbours import bm25_weight
    
# weight the matrix, both to reduce impact of users that have played the same artist thousands of times
# and to reduce the weight given to popular items
artist_user_plays = bm25_weight(artist_user_plays, K1=100, B=0.8)
    
# get the transpose since the most of the functions in implicit expect (user, item) sparse matrices instead of (item, user)
user_plays = artist_user_plays.T.tocsr()

from implicit.als import AlternatingLeastSquares

model = AlternatingLeastSquares(factors=64, regularization=0.05)
model.fit(user_plays)

model.user_factors.shape

output Manjaro-->(358867,64)

output Ubuntu-->(292385, 64)

import pandas as pd
userid=max(pd.DataFrame.sparse.from_spmatrix(user_plays).index)

ids, scores = model.recommend(userid, user_plays[userid], N=10, filter_already_liked_items=False)

the final line of this code snippet is where the error is. it spits out "ValueError: row index out of bounds for matrix" on Ubuntu but works fine on Manjaro. as you can see when i call model.user_factors.shape the model after training has different parameters on the Manjaro system and Ubuntu system. here is an image of the matrix that is being fed to the model.fit() call and as you can see it looks like implicit is handling the matrix differently on the two systems and seems to be transforming it in Ubuntu for some reason.

can anyone tell me why this might be happening?

0 Answers
Related