recommenders
recommenders copied to clipboard
[ASK] Questions about the construction of user history
Hi, I'm a little confuseds about how to load MIND data.
Description
When initializing user behavior, the code in MINDIterator/MINDAllIterator is like this :
history = [0] * (self.his_size - len(history)) + history[ : self.his_size ]
Padding 0 to the head of the list when the history is insufficient should mean that the News in history are arranged according to time. (The later the position, the newer the time) On the other hand, the first his_size elements are selected in the code.
Solution
Would it be more reasonable to select the latest his_size elements like this to represent the user status?
history = [0] * (self.his_size - len(history)) + history[ -self.his_size : ]
Other Comments
Specific location link : https://github.com/microsoft/recommenders/blob/66e4b6b2220bae6bb97947e1bbe7c5d97cbec979/reco_utils/recommender/newsrec/io/mind_iterator.py#L117
https://github.com/microsoft/recommenders/blob/66e4b6b2220bae6bb97947e1bbe7c5d97cbec979/reco_utils/recommender/newsrec/io/mind_all_iterator.py#L143
Same confusion here. @yjw1029 Could you please have some words on this?
cc @miguelgfierro
Seems like an issue in the previous implementation. Modifying to history[ -self.his_size : ]
would be more reasonable. Will open a PR later to fix this issue.
This is the result when using the solution:
>>> history = [1, 2, 3, 4, 5, 6]
>>> history[-3:]
[4, 5, 6]
>>> history[:3]
[1, 2, 3]
>>> his_size = 10
>>> [0] * (his_size - len(history)) + history[: his_size]
[0, 0, 0, 0, 1, 2, 3, 4, 5, 6]
>>> [0] * (his_size - len(history)) + history[-his_size:]
[0, 0, 0, 0, 1, 2, 3, 4, 5, 6]
>>> his_size = 4
>>> [0] * (his_size - len(history)) + history[: his_size]
[1, 2, 3, 4]
>>> [0] * (his_size - len(history)) + history[-his_size:]
[3, 4, 5, 6]