The expanded size of the tensor must match the existing size
yestoprince opened this issue · 5 comments
RuntimeError Traceback (most recent call last)
in
2 implicit_model = ImplicitFactorizationModel()
3 implicit_model.fit(implicit_interactions)
----> 4 implicit_model.predict(combined_frames["user_id"].values, item_ids=None)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spotlight-0.1.5-py3.7.egg/spotlight/factorization/implicit.py in predict(self, user_ids, item_ids)
305 user_ids, item_ids = _predict_process_ids(user_ids, item_ids,
306 self._num_items,
--> 307 self._use_cuda)
308
309 out = self._net(user_ids, item_ids)
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/spotlight-0.1.5-py3.7.egg/spotlight/factorization/_components.py in _predict_process_ids(user_ids, item_ids, num_items, use_cuda)
18
19 if item_ids.size()[0] != user_ids.size(0):
---> 20 user_ids = user_ids.expand(item_ids.size())
21
22 user_var = gpu(user_ids, use_cuda)
RuntimeError: The expanded size of the tensor (13581) must match the existing size (13561) at non-singleton dimension 0. Target sizes: [13581, 1]. Tensor sizes: [13561, 1]
Here is the code where combined_frames is a data frame
Here is the data:
condition-brand new electronics brand-hewlett packard brand-celestron telephony computers optics brand-at&t gps navigation systems mattresses ... computer interface cards & adapters laptop screen protectors audio players & recorders hailer horns do not use marine accessories audio / video covers remote page_url page_id
0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 https://xyz.com/details/2... 1
1 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 https://xyz.com/details/2... 2
2 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 https://xyz.com/details/1... 3
3 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 https://xyz.com/details/1... 4
4 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 https://xyz.com/details/1... 5
Here is the code:
implicit_interactions = Interactions(combined_frames['user_id'].values, combined_frames['page_id'].values)
explicit_interactions = Interactions(combined_frames['user_id'], combined_frames['page_id'], combined_frames['views'])
from spotlight.factorization.implicit import ImplicitFactorizationModel
implicit_model = ImplicitFactorizationModel()
implicit_model.fit(implicit_interactions)
implicit_model.predict(combined_frames["user_id"].values, item_ids=None)
Could you prepare a short snippet that I could execute that exhibits this problem?
`from spotlight.interactions import Interactions
implicit_interactions = Interactions(combined_frames['user_id'].values,
combined_frames['page_id'].values)
explicit_interactions = Interactions(combined_frames['user_id'], combined_frames['page_id'],
combined_frames['views'])
from spotlight.factorization.implicit import ImplicitFactorizationModel
implicit_model = ImplicitFactorizationModel()
implicit_model.fit(implicit_interactions)
implicit_model.predict(combined_frames["user_id"].values, item_ids=None)
`
Here is the filed attached
It is the data that i am using for combined_frames variable mentioned in above code.
Do you have a snippet that does not rely on me using your data? Please try to generate some random numpy arrays that trigger the same problem.
Also, please learn how to use Github markdown.