Collaborative filtering predictions

Hi, I must be doing something simple wrong here. Any advice on the correct way to get predictions would be appreciated.

I’ve trained a collaborative filtering model and now want to get predictions for combinations of users and items. I’ve tried

learn.predict(df.iloc[0])

and also

learn.get_preds()

with a dataframe and a dataloader to no avail.

This is the error that is being returned.

/usr/local/lib/python3.6/dist-packages/fastcore/foundation.py in __getitem__(self, k)
    110     def __init__(self, items): self.items = items
    111     def __len__(self): return len(self.items)
--> 112     def __getitem__(self, k): return self.items[list(k) if isinstance(k,CollBase) else k]
    113     def __setitem__(self, k, v): self.items[list(k) if isinstance(k,CollBase) else k] = v
    114     def __delitem__(self, i): del(self.items[i])

TypeError: list indices must be integers or slices, not list

Also ran into troubles using the BCELossFlat loss function. I got this error:

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/torch/tensor.py in __torch_function__(cls, func, types, args, kwargs)
    993 
    994         with _C.DisableTorchFunction():
--> 995             ret = func(*args, **kwargs)
    996             return _convert(ret, cls)
    997 

RuntimeError: CUDA error: device-side assert triggered

Is the because you can’t use BCE with collaborative filtering? My label was binary, so I thought that would be better than mse.

Hi!

I probably can’t help too much, but I found this post, maybe you can try it this way (creating a new test dataloader).

I ran the collab filtering notebook from the book, learn.get_preds() worked fine there, learn.predict(df.iloc[0]) gave me the same error as you experienced. This is with the default flattened MSE loss. I could not even get it to train with BCELoss, did that work for you?

Regarding this error:

RuntimeError: CUDA error: device-side assert triggered

I have tried in the past to switch to a non GPU environment. This way, the error messages are sometimes clearer than the generic CUDA error.

Thanks for the suggestions. I’ll give those a try.

Were you able to resolve this issue? I am struggling with TypeError: list indices must be integers or slices, not list without a possible solution.